Skip to content

Commit

Permalink
Adding non uniform scale through the scaleX and scaleY properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
nockawa committed Jul 28, 2016
1 parent 14ea838 commit 1c0aba0
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/Canvas2d/babylon.ellipse2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
* - id: a text identifier, for information purpose
* - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
* - rotation: the initial rotation (in radian) of the primitive. default is 0
* - scale: the initial scale of the primitive. default is 1
* - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
* - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
* - origin: define the normalized origin point location, default [0.5;0.5]
* - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
Expand Down Expand Up @@ -262,6 +262,8 @@
y ?: number,
rotation ?: number,
scale ?: number,
scaleX ?: number,
scaleY ?: number,
opacity ?: number,
origin ?: Vector2,
size ?: Size,
Expand Down
5 changes: 4 additions & 1 deletion src/Canvas2d/babylon.group2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* - id a text identifier, for information purpose
* - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
* - rotation: the initial rotation (in radian) of the primitive. default is 0
* - scale: the initial scale of the primitive. default is 1
* - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
* - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
* - origin: define the normalized origin point location, default [0.5;0.5]
* - size: the size of the group. Alternatively the width and height properties can be set. If null the size will be computed from its content, default is null.
Expand Down Expand Up @@ -64,6 +64,9 @@
position ?: Vector2,
x ?: number,
y ?: number,
scale ?: number,
scaleX ?: number,
scaleY ?: number,
trackNode ?: Node,
opacity ?: number,
origin ?: Vector2,
Expand Down
4 changes: 3 additions & 1 deletion src/Canvas2d/babylon.lines2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
* - id a text identifier, for information purpose
* - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
* - rotation: the initial rotation (in radian) of the primitive. default is 0
* - scale: the initial scale of the primitive. default is 1
* - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
* - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
* - origin: define the normalized origin point location, default [0.5;0.5]
* - fillThickness: the thickness of the fill part of the line, can be null to draw nothing (but a border brush must be given), default is 1.
Expand Down Expand Up @@ -430,6 +430,8 @@
y ?: number,
rotation ?: number,
scale ?: number,
scaleX ?: number,
scaleY ?: number,
opacity ?: number,
origin ?: Vector2,
fillThickness ?: number,
Expand Down
65 changes: 56 additions & 9 deletions src/Canvas2d/babylon.prim2dBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@
* Base class for a Primitive of the Canvas2D feature
*/
export class Prim2DBase extends SmartPropertyPrim {
static PRIM2DBASE_PROPCOUNT: number = 15;
static PRIM2DBASE_PROPCOUNT: number = 16;
public static _bigInt = Math.pow(2, 30);

constructor(settings: {
Expand All @@ -1302,6 +1302,8 @@
y?: number,
rotation?: number,
scale?: number,
scaleX?: number,
scaleY?: number,
opacity?: number,
origin?: Vector2,
layoutEngine?: LayoutEngineBase | string,
Expand Down Expand Up @@ -1354,6 +1356,7 @@
// Fields initialization
this._layoutEngine = CanvasLayoutEngine.Singleton;
this._size = null; //Size.Zero();
this._scale = new Vector2(1, 1);
this._actualSize = null;
this._boundingSize = Size.Zero();
this._layoutArea = Size.Zero();
Expand Down Expand Up @@ -1429,7 +1432,17 @@
this._position = null;
}
this.rotation = (settings.rotation == null) ? 0 : settings.rotation;
this.scale = (settings.scale == null) ? 1 : settings.scale;

if (settings.scale != null) {
this.scale = settings.scale;
} else {
if (settings.scaleX != null) {
this.scaleX = settings.scaleX;
}
if (settings.scaleY != null) {
this.scaleY = settings.scaleY;
}
}
this.levelVisible = (settings.isVisible == null) ? true : settings.isVisible;
this.origin = settings.origin || new Vector2(0.5, 0.5);

Expand Down Expand Up @@ -1622,6 +1635,16 @@
public static opacityProperty: Prim2DPropInfo;


/**
* Metadata of the scaleX property
*/
public static scaleXProperty: Prim2DPropInfo;

/**
* Metadata of the scaleY property
*/
public static scaleYProperty: Prim2DPropInfo;

@instanceLevelProperty(1, pi => Prim2DBase.actualPositionProperty = pi, false, false, true)
/**
* Return the position where the primitive is rendered in the Canvas, this position may be different than the one returned by the position property due to layout/alignment/margin/padding computing
Expand Down Expand Up @@ -1837,14 +1860,14 @@

@instanceLevelProperty(5, pi => Prim2DBase.scaleProperty = pi, false, true)
/**
* Uniform scale applied on the primitive
* Uniform scale applied on the primitive. If a non-uniform scale is applied through scaleX/scaleY property the getter of this property will return scaleX.
*/
public set scale(value: number) {
this._scale = value;
this._scale.x = this._scale.y = value;
}

public get scale(): number {
return this._scale;
return this._scale.x;
}

/**
Expand Down Expand Up @@ -2060,6 +2083,30 @@
this._spreadActualOpacityChanged();
}

@instanceLevelProperty(14, pi => Prim2DBase.scaleXProperty = pi, false, true)
/**
* Scale applied on the X axis of the primitive
*/
public set scaleX(value: number) {
this._scale.x = value;
}

public get scaleX(): number {
return this._scale.x;
}

@instanceLevelProperty(15, pi => Prim2DBase.scaleYProperty = pi, false, true)
/**
* Scale applied on the Y axis of the primitive
*/
public set scaleY(value: number) {
this._scale.y = value;
}

public get scaleY(): number {
return this._scale.y;
}

public get actualOpacity(): number {
if (this._isFlagSet(SmartPropertyPrim.flagActualOpacityDirty)) {
let cur = this.parent;
Expand Down Expand Up @@ -2548,7 +2595,7 @@
private static _v0: Vector2 = Vector2.Zero(); // Must stay with the value 0,0

private _updateLocalTransform(): boolean {
let tflags = Prim2DBase.actualPositionProperty.flagId | Prim2DBase.rotationProperty.flagId | Prim2DBase.scaleProperty.flagId | Prim2DBase.originProperty.flagId;
let tflags = Prim2DBase.actualPositionProperty.flagId | Prim2DBase.rotationProperty.flagId | Prim2DBase.scaleProperty.flagId | Prim2DBase.scaleXProperty.flagId | Prim2DBase.scaleYProperty.flagId | Prim2DBase.originProperty.flagId;
if (this.checkPropertiesDirty(tflags)) {
if (this.owner) {
this.owner.addupdateLocalTransformCounter(1);
Expand All @@ -2559,7 +2606,7 @@
let pos = this.position;

if (this._origin.x === 0 && this._origin.y === 0) {
local = Matrix.Compose(new Vector3(this._scale, this._scale, 1), rot, new Vector3(pos.x, pos.y, 0));
local = Matrix.Compose(new Vector3(this._scale.x, this._scale.y, 1), rot, new Vector3(pos.x, pos.y, 0));
this._localTransform = local;
} else {
// -Origin offset
Expand All @@ -2571,7 +2618,7 @@
Prim2DBase._t0.multiplyToRef(Prim2DBase._t1, Prim2DBase._t2);

// -Origin * rotation * scale
Matrix.ScalingToRef(this._scale, this._scale, 1, Prim2DBase._t0);
Matrix.ScalingToRef(this._scale.x, this._scale.y, 1, Prim2DBase._t0);
Prim2DBase._t2.multiplyToRef(Prim2DBase._t0, Prim2DBase._t1);

// -Origin * rotation * scale * (Origin + Position)
Expand Down Expand Up @@ -3045,7 +3092,7 @@
private _layoutArea: Size;
private _contentArea: Size;
private _rotation: number;
private _scale: number;
private _scale: Vector2;
private _origin: Vector2;
protected _opacity: number;
private _actualOpacity: number;
Expand Down
4 changes: 3 additions & 1 deletion src/Canvas2d/babylon.rectangle2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
* - id a text identifier, for information purpose
* - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
* - rotation: the initial rotation (in radian) of the primitive. default is 0
* - scale: the initial scale of the primitive. default is 1
* - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
* - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
* - origin: define the normalized origin point location, default [0.5;0.5]
* - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
Expand Down Expand Up @@ -345,6 +345,8 @@
y ?: number,
rotation ?: number,
scale ?: number,
scaleX ?: number,
scaleY ?: number,
opacity ?: number,
origin ?: Vector2,
size ?: Size,
Expand Down
4 changes: 3 additions & 1 deletion src/Canvas2d/babylon.sprite2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
* - id a text identifier, for information purpose
* - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
* - rotation: the initial rotation (in radian) of the primitive. default is 0
* - scale: the initial scale of the primitive. default is 1
* - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
* - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
* - origin: define the normalized origin point location, default [0.5;0.5]
* - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
Expand Down Expand Up @@ -272,6 +272,8 @@
y?: number,
rotation?: number,
scale?: number,
scaleX?: number,
scaleY?: number,
opacity?: number,
origin?: Vector2,
spriteSize?: Size,
Expand Down
4 changes: 3 additions & 1 deletion src/Canvas2d/babylon.text2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
* - id a text identifier, for information purpose
* - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
* - rotation: the initial rotation (in radian) of the primitive. default is 0
* - scale: the initial scale of the primitive. default is 1
* - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
* - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
* - origin: define the normalized origin point location, default [0.5;0.5]
* - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
Expand Down Expand Up @@ -299,6 +299,8 @@
y ?: number,
rotation ?: number,
scale ?: number,
scaleX ?: number,
scaleY ?: number,
opacity ?: number,
origin ?: Vector2,
fontName ?: string,
Expand Down

0 comments on commit 1c0aba0

Please sign in to comment.