Pivot point implementation

This commit is contained in:
vakrilov
2015-11-24 14:44:00 +02:00
parent 5a63071242
commit 6500170699
4 changed files with 66 additions and 0 deletions

View File

@@ -148,6 +148,18 @@ var scaleYProperty = new dependencyObservable.Property(
"View",
new proxy.PropertyMetadata(1)
);
var pivotXProperty = new dependencyObservable.Property(
"pivotX",
"View",
new proxy.PropertyMetadata(0.5)
);
var pivotYProperty = new dependencyObservable.Property(
"pivotY",
"View",
new proxy.PropertyMetadata(0.5)
);
var rotateProperty = new dependencyObservable.Property(
"rotate",
@@ -178,6 +190,8 @@ export class View extends proxy.ProxyObject implements definition.View {
public static translateYProperty = translateYProperty;
public static scaleXProperty = scaleXProperty;
public static scaleYProperty = scaleYProperty;
public static pivotXProperty = pivotXProperty;
public static pivotYProperty = pivotYProperty;
public static rotateProperty = rotateProperty;
public static isEnabledProperty = isEnabledProperty;
public static isUserInteractionEnabledProperty = isUserInteractionEnabledProperty;
@@ -470,6 +484,20 @@ export class View extends proxy.ProxyObject implements definition.View {
this._setValue(View.scaleYProperty, value);
}
get pivotX(): number {
return this._getValue(View.pivotXProperty);
}
set pivotX(value: number) {
this._setValue(View.pivotXProperty, value);
}
get pivotY(): number {
return this._getValue(View.pivotYProperty);
}
set pivotY(value: number) {
this._setValue(View.pivotYProperty, value);
}
get rotate(): number {
return this._getValue(View.rotateProperty);
}

View File

@@ -44,6 +44,20 @@ function onScaleYPropertyChanged(data: dependencyObservable.PropertyChangeData)
}
(<proxy.PropertyMetadata>viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged;
function onPivotXPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var view = <View>data.object;
var width = view._nativeView.getWidth();
view._nativeView.setPivotX(data.newValue * width);
}
(<proxy.PropertyMetadata>viewCommon.View.pivotXProperty.metadata).onSetNativeValue = onPivotXPropertyChanged;
function onPivotYPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var view = <View>data.object;
var height = view._nativeView.getHeight();
view._nativeView.setPivotY(data.newValue * height);
}
(<proxy.PropertyMetadata>viewCommon.View.pivotYProperty.metadata).onSetNativeValue = onPivotYPropertyChanged;
function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) {
var view = <View>data.object;
view._nativeView.setRotation(data.newValue);

10
ui/core/view.d.ts vendored
View File

@@ -259,6 +259,16 @@ declare module "ui/core/view" {
*/
scaleY: number;
/**
* Gets or sets the X component of the pivot point around which the view will be transformed. The deafault value is 0.5 representing the center of the view.
*/
pivotX: number;
/**
* Gets or sets the Y component of the pivot point around which the view will be transformed. The deafault value is 0.5 representing the center of the view.
*/
pivotY: number;
/**
* Gets or sets the rotate affine transform of the view.
*/

View File

@@ -66,6 +66,20 @@ function onScaleYPropertyChanged(data: dependencyObservable.PropertyChangeData)
}
(<proxy.PropertyMetadata>viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged;
function onPivotXPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var view = <View>data.object;
var current = view._nativeView.layer.anchorPoint;
view._nativeView.layer.anchorPoint = CGPointMake(data.newValue, current.y);
}
(<proxy.PropertyMetadata>viewCommon.View.pivotXProperty.metadata).onSetNativeValue = onPivotXPropertyChanged;
function onPivotYPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var view = <View>data.object;
var current = view._nativeView.layer.anchorPoint;
view._nativeView.layer.anchorPoint = CGPointMake(current.x, data.newValue);
}
(<proxy.PropertyMetadata>viewCommon.View.pivotYProperty.metadata).onSetNativeValue = onPivotYPropertyChanged;
function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) {
var view = <View>data.object;
var newTransform = CGAffineTransformIdentity;