-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
283 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
/// <reference path="./src/justAnExample"/> | ||
/// <reference path="./declareFiles/coreLib.d.ts"/> | ||
|
||
/// <reference path="./src/justAnExample"/> | ||
/// <reference path="./src/Text.ts"/> | ||
/// <reference path="./src/colors.ts"/> | ||
/// <reference path="./src/position.ts"/> | ||
|
||
module Sanara.Std { | ||
export var dictionary : Sanara.Core.Dictionary = (function() { | ||
var entries = <Sanara.Core.DictionaryEntry[]>[]; | ||
// | ||
entries.push(Sanara.Std.Circle); | ||
entries.push(Sanara.Std.Bitree); | ||
entries.push(Sanara.Std.FillColor); | ||
// | ||
return new Sanara.Core.Dictionary(entries); | ||
})(); | ||
export var dictionary : Core.Dictionary = new Sanara.Core.Dictionary([ | ||
Circle, | ||
Bitree, | ||
Text, | ||
Background, | ||
FillColor | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// <reference path="../declareFiles/coreLib.d.ts" /> | ||
|
||
module Sanara.Std { | ||
export class Text extends Sanara.Core.Fragment { | ||
|
||
private static TEST_CONTEXT = <Sanara.Core.SanaraContext>document.createElement("canvas").getContext("2d"); | ||
|
||
private font : string; // SIZEpx FONT_FAMITY_NAME eg. 18px serif | ||
|
||
private myText; | ||
|
||
constructor (children, parameters : Sanara.Core.Value[]) { | ||
if(parameters.length < 1) { | ||
throw Sanara.Core.Exception.FEW_PARAMETERS; | ||
} | ||
this.font = parameters[0].toString(); | ||
|
||
this.myText = ""; | ||
|
||
super(null,null,[ | ||
{name:"width", value:this.calcWidth()}, | ||
{name:"height", value:this.calcHeight()} | ||
]); | ||
} | ||
|
||
get text() : string { | ||
return this.myText; | ||
} | ||
set text(newText) { | ||
this.myText = newText; | ||
this.setPropertyValue("width",this.calcWidth()); | ||
this.setPropertyValue("height",this.calcHeight()); | ||
} | ||
|
||
private calcHeight() { | ||
if(this.text.length === 0) return Sanara.Core.Value.ZERO; | ||
|
||
return new Sanara.Core.Value(parseInt(this.font)); | ||
} | ||
|
||
private calcWidth() { | ||
if(this.text.length === 0) return Sanara.Core.Value.ZERO; | ||
|
||
var w = 0; | ||
Text.TEST_CONTEXT.save(); { | ||
Text.TEST_CONTEXT.font = this.font; | ||
w = Text.TEST_CONTEXT.measureText(this.text).width; | ||
}; Text.TEST_CONTEXT.restore(); | ||
return new Sanara.Core.Value(w); | ||
} | ||
|
||
paintImplementation(context : Sanara.Core.SanaraContext) { | ||
context.font = this.font; | ||
context.textAlign = 'left' | ||
context.textBaseline = 'top' | ||
context.fillText(this.text,0,0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/// <reference path="../declareFiles/coreLib.d.ts" /> | ||
|
||
|
||
|
||
module Sanara.Std { | ||
export class Background extends Sanara.Core.Fragment { | ||
static doc:Sanara.Core.FragmentClassDoc = { | ||
name: "background", | ||
discription: "Adds background to child", | ||
children : [ | ||
{ | ||
name : "frontground", | ||
discription : "fragment that will have background" | ||
} | ||
], | ||
parameters : [ | ||
{ | ||
name: "color", | ||
discription : "Background color. e.g. \"#f3422e\"" | ||
} | ||
] | ||
} | ||
|
||
private color : Sanara.Core.Value; | ||
private child : Sanara.Core.Fragment; | ||
|
||
constructor(children:Sanara.Core.Fragment[], parameters: Sanara.Core.Value[]) { | ||
if(children.length < 1) { | ||
throw Sanara.Core.Exception.FEW_CHILDREN; | ||
} | ||
if(parameters.length < 1) { | ||
throw Sanara.Core.Exception.FEW_PARAMETERS; | ||
} | ||
this.color = parameters[0]; | ||
this.child = children[0]; | ||
|
||
super(null,null,[ | ||
{name:"width",value:this.calcWidth()}, | ||
{name:"height",value:this.calcHeight()} | ||
]); | ||
} | ||
|
||
private calcWidth() { | ||
return this.child.getPropertyValue("width"); | ||
} | ||
|
||
private calcHeight() { | ||
return this.child.getPropertyValue("height"); | ||
} | ||
|
||
paintImplementation(context: Sanara.Core.SanaraContext) { | ||
context.save(); { | ||
context.fillStyle = this.color.toColor(); | ||
context.fillRect(0,0,this.child.width(), this.child.height()); | ||
}; context.restore(); | ||
this.child.paint(context); | ||
} | ||
} | ||
export class FillColor extends Sanara.Core.Fragment { | ||
static doc:Sanara.Core.FragmentClassDoc = { | ||
name: "fill-color", | ||
discription: "Changes fill color for child environment", | ||
children : [ | ||
{ | ||
name : "colored", | ||
discription : "fragment that will recieve new fill color" | ||
} | ||
], | ||
parameters : [ | ||
{ | ||
name: "color", | ||
discription : "New color. e.g. \"#f3422e\"" | ||
} | ||
] | ||
} | ||
|
||
private color : Sanara.Core.Value; | ||
private child : Sanara.Core.Fragment; | ||
|
||
constructor(children:Sanara.Core.Fragment[], parameters: Sanara.Core.Value[]) { | ||
if(children.length < 1) { | ||
throw Sanara.Core.Exception.FEW_CHILDREN; | ||
} | ||
if(parameters.length < 1) { | ||
throw Sanara.Core.Exception.FEW_PARAMETERS; | ||
} | ||
this.color = parameters[0]; | ||
this.child = children[0]; | ||
|
||
super(null,null,[ | ||
{name:"width",value:this.calcWidth()}, | ||
{name:"height",value:this.calcHeight()} | ||
]); | ||
} | ||
|
||
private calcWidth() { | ||
return this.child.getPropertyValue("width"); | ||
} | ||
|
||
private calcHeight() { | ||
return this.child.getPropertyValue("height"); | ||
} | ||
|
||
paintImplementation(context: Sanara.Core.SanaraContext) { | ||
context.fillStyle = this.color.toColor(); | ||
this.child.paint(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
/// <reference path="../declareFiles/coreLib.d.ts" /> | ||
|
||
module Sanara.Std { | ||
export class Translate extends Sanara.Core.Fragment { | ||
static doc:Sanara.Core.FragmentClassDoc = { | ||
name : "translate", | ||
discription : "Translate a fragment", | ||
parameters : [ | ||
{ | ||
name: "dx", | ||
discription : "translate x" | ||
}, | ||
{ | ||
name: "dy", | ||
discription : "translate y" | ||
} | ||
], | ||
children : [ | ||
{ | ||
name: "translated", | ||
discription : "fragment to be translated", | ||
} | ||
] | ||
} | ||
|
||
private child : Sanara.Core.Fragment; | ||
private dx : Sanara.Core.Value; | ||
private dy : Sanara.Core.Value; | ||
|
||
constructor(children : Sanara.Core.Fragment[] , parameters : Sanara.Core.Value[]) { | ||
if(children.length < 1) { | ||
throw Sanara.Core.Exception.FEW_CHILDREN; | ||
} | ||
if(parameters.length < 2) { | ||
throw Sanara.Core.Exception.FEW_PARAMETERS; | ||
} | ||
this.dx = parameters[0]; | ||
this.dy = parameters[1]; | ||
this.child = children[0]; | ||
|
||
super(null,null,[ | ||
{name:"width",value:this.calcWidth()}, | ||
{name:"height",value:this.calcHeight()} | ||
]); | ||
} | ||
|
||
private calcWidth() : Sanara.Core.Value { | ||
return new Sanara.Core.Value(this.dx.toNumber() + this.child.width()); | ||
} | ||
private calcHeight() : Sanara.Core.Value { | ||
return new Sanara.Core.Value(this.dy.toNumber() + this.child.height()); | ||
} | ||
|
||
paintImplementation(context : Sanara.Core.SanaraContext) { | ||
context.translate(this.dx.toNumber(), this.dy.toNumber()); | ||
this.child.paint(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters