void ApplyRotation(EvasMap map, ERect geometry, ref bool changed) { var rotationX = Element.RotationX; var rotationY = Element.RotationY; var rotationZ = Element.Rotation; var anchorX = Element.AnchorX; var anchorY = Element.AnchorY; // apply rotations if (rotationX != 0 || rotationY != 0 || rotationZ != 0) { map.Rotate3D(rotationX, rotationY, rotationZ, (int)(geometry.X + geometry.Width * anchorX), (int)(geometry.Y + geometry.Height * anchorY), 0); changed = true; } }
void ApplyRotation(EvasMap map, ERect geometry, ref bool changed) { var rotationX = Element.RotationX; var rotationY = Element.RotationY; var rotationZ = Element.Rotation; var anchorX = Element.AnchorX; var anchorY = Element.AnchorY; // apply rotations if (rotationX != 0 || rotationY != 0 || rotationZ != 0) { map.Rotate3D(rotationX, rotationY, rotationZ, (int)(geometry.X + geometry.Width * anchorX), (int)(geometry.Y + geometry.Height * anchorY), 0); // the last argument is focal length, it determine the strength of distortion. We compared it with the Android implementation map.Perspective3D(geometry.X + geometry.Width / 2, geometry.Y + geometry.Height / 2, 0, (int)(1.3 * Math.Max(geometry.Height, geometry.Width))); // Need to unset clip because perspective 3d rotation is going beyond the container bound NativeView.SetClip(null); changed = true; } }
void ApplyTransformation() { EvasMap map = new EvasMap(4); Rect geometry = _box1.Geometry; map.PopulatePoints(geometry, 0); map.Rotate3D(0, 0, _angle, (int)(geometry.X + geometry.Width * 0.5), (int)(geometry.Y + geometry.Height * 0.5), 0); Point3D p; for (int i = 0; i < 4; i++) { p = map.GetPointCoordinate(i); p.X += _totalX; p.Y += _totalY; map.SetPointCoordinate(i, p); } _box1.EvasMap = map; _box1.IsMapEnabled = true; }
public override void Run(Window window) { var square = window.GetInnerSquare(); var box = new Box(window) { Geometry = new Rect(square.X, square.Y, square.Width, square.Height / 2), BackgroundColor = Color.Gray }; box.Show(); var text = new Label(box) { Text = "<span color=#ffffff font_size=30>Target</span>", AlignmentX = -1.0, AlignmentY = -1.0, WeightX = 1.0, WeightY = 1.0, }; text.Show(); box.PackEnd(text); double angle = 0.0; var reset = new Button(box) { Text = "Reset", Geometry = new Rect(square.X, square.Y + square.Height / 2, square.Width, square.Height / 6) }; reset.Show(); double zx = 1.0; double zy = 1.0; reset.Clicked += (object sender, EventArgs e) => { text.IsMapEnabled = false; angle = 0.0; zx = 1.0; zy = 1.0; }; var zoom = new Button(box) { Text = "Zoom Target", Geometry = new Rect(square.X, square.Y + square.Height / 2 + square.Height / 6, square.Width, square.Height / 6) }; zoom.Show(); zoom.Clicked += (object sender, EventArgs e) => { zx += 0.1; zy += 0.1; var map = new EvasMap(4); var g = text.Geometry; map.PopulatePoints(g, 0); map.Rotate3D(0, 0, angle, g.X + g.Width / 2, g.Y + g.Height / 2, 0); map.Zoom(zx, zy, g.X, g.Y); text.EvasMap = map; text.IsMapEnabled = true; }; var rotate = new Button(box) { Text = "Rotate Target", Geometry = new Rect(square.X, square.Y + square.Height / 2 + square.Height * 2 / 6, square.Width, square.Height / 6) }; rotate.Show(); rotate.Clicked += (object sender, EventArgs e) => { angle += 5.0; var map = new EvasMap(4); var g = text.Geometry; map.PopulatePoints(g, 0); map.Rotate3D(0, 0, angle, g.X + g.Width / 2, g.Y + g.Height / 2, 0); map.Zoom(zx, zy, g.X, g.Y); text.EvasMap = map; text.IsMapEnabled = true; }; }
public override void Run(Window window) { var square = window.GetInnerSquare(); var box = new Box(window) { Geometry = new Rect(square.X, square.Y, square.Width, square.Height / 2), BackgroundColor = Color.Gray }; box.Show(); var group = new Box(box) { IsHorizontal = true, BackgroundColor = Color.White, }; group.Show(); var x = new Label(group) { Text = "X", }; x.Show(); var y = new Label(group) { Text = "Y", }; y.Show(); var z = new Label(group) { Text = "Z", }; z.Show(); group.PackEnd(x); group.PackEnd(y); group.PackEnd(z); var top = new Rectangle(box) { Color = Color.Red, }; top.SetAlignment(-1.0, -1.0); // fill top.SetWeight(1.0, 1.0); // expand top.Show(); var bottom = new Rectangle(box) { Color = Color.Green, }; bottom.SetAlignment(-1.0, -1.0); // fill bottom.SetWeight(1.0, 1.0); // expand bottom.Show(); double angle = 0.0; var reset = new Button(box) { Text = "Reset", Geometry = new Rect(square.X, square.Y + square.Height / 2, square.Width, square.Height / 6) }; reset.Show(); reset.Clicked += (object sender, EventArgs e) => { group.IsMapEnabled = false; x.IsMapEnabled = false; angle = 0.0; }; var zoom = new Button(box) { Text = "Zoom group", Geometry = new Rect(square.X, square.Y + square.Height / 2 + square.Height / 6, square.Width, square.Height / 6) }; zoom.Show(); zoom.Clicked += (object sender, EventArgs e) => { var map = new EvasMap(4); var g = group.Geometry; map.PopulatePoints(g, 0); map.Zoom(3.0, 3.0, g.X + g.Width / 2, g.Y + g.Height / 2); group.EvasMap = map; group.IsMapEnabled = true; }; var rotate = new Button(box) { Text = "Rotate X", Geometry = new Rect(square.X, square.Y + square.Height / 2 + square.Height * 2 / 6, square.Width, square.Height / 6) }; rotate.Show(); rotate.Clicked += (object sender, EventArgs e) => { angle += 5.0; var map = new EvasMap(4); var g = x.Geometry; map.PopulatePoints(g, 0); map.Rotate3D(0, 0, angle, g.X + g.Width / 2, g.Y + g.Height / 2, 0); x.EvasMap = map; x.IsMapEnabled = true; }; box.PackEnd(top); box.PackEnd(group); box.PackEnd(bottom); }
public override void Run(Window window) { var box = new Box(window) { IsHorizontal = false, }; box.SetAlignment(-1.0, -1.0); box.SetWeight(1.0, 1.0); box.Show(); var text = new Label(box) { Text = "<span color=#ffffff font_size=30>Target</span>", AlignmentX = -1.0, AlignmentY = -1.0, WeightX = 1.0, WeightY = 1.0, }; text.Show(); var textBox = new Box(box) { AlignmentX = -1.0, WeightX = 1.0, WeightY = 0.7, }; textBox.PackEnd(text); textBox.Show(); double angle = 0.0; var reset = new Button(box) { Text = "Reset", AlignmentX = -1.0, WeightX = 1.0, WeightY = 0.1, }; reset.Show(); double zx = 1.0; double zy = 1.0; reset.Clicked += (object sender, EventArgs e) => { text.IsMapEnabled = false; angle = 0.0; zx = 1.0; zy = 1.0; }; var zoom = new Button(box) { Text = "Zoom Target", AlignmentX = -1.0, WeightX = 1.0, WeightY = 0.1, }; zoom.Show(); zoom.Clicked += (object sender, EventArgs e) => { zx += 0.1; zy += 0.1; var map = new EvasMap(4); var g = text.Geometry; map.PopulatePoints(g, 0); map.Rotate3D(0, 0, angle, g.X + g.Width / 2, g.Y + g.Height / 2, 0); map.Zoom(zx, zy, g.X, g.Y); text.EvasMap = map; text.IsMapEnabled = true; }; var rotate = new Button(box) { Text = "Rotate Target", AlignmentX = -1.0, WeightX = 1.0, WeightY = 0.1, }; rotate.Show(); rotate.Clicked += (object sender, EventArgs e) => { angle += 5.0; var map = new EvasMap(4); var g = text.Geometry; map.PopulatePoints(g, 0); map.Rotate3D(0, 0, angle, g.X + g.Width / 2, g.Y + g.Height / 2, 0); map.Zoom(zx, zy, g.X, g.Y); text.EvasMap = map; text.IsMapEnabled = true; }; box.PackEnd(textBox); box.PackEnd(reset); box.PackEnd(zoom); box.PackEnd(rotate); box.Resize(window.ScreenSize.Width, window.ScreenSize.Height); box.Move(0, 0); }
/* * void ApplyRotation(EvasMap map, Rect geometry, ref bool changed) * { * var rotationX = Element.RotationX; * var rotationY = Element.RotationY; * var rotationZ = Element.Rotation; * var anchorX = Element.AnchorX; * var anchorY = Element.AnchorY; * * // apply rotations * if (rotationX != 0 || rotationY != 0 || rotationZ != 0) * { * map.Rotate3D(rotationX, rotationY, rotationZ, (int)(geometry.X + geometry.Width * anchorX), * (int)(geometry.Y + geometry.Height * anchorY), 0); * changed = true; * } * } * * void ApplyScale(EvasMap map, Rect geometry, ref bool changed) * { * var scale = Element.Scale; * * // apply scale factor * if (scale != 1.0) * { * map.Zoom(scale, scale, * geometry.X + (int)(geometry.Width * view.AnchorX), * geometry.Y + (int)(geometry.Height * Element.AnchorY)); * changed = true; * } * } * * void ApplyTranslation(EvasMap map, Rect geometry, ref bool changed) * { * var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX); * var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY); * * // apply translation, i.e. move/shift the object a little * if (shiftX != 0 || shiftY != 0) * { * if (changed) * { * // special care is taken to apply the translation last * Point3D p; * for (int i = 0; i < 4; i++) * { * p = map.GetPointCoordinate(i); * p.X += shiftX; * p.Y += shiftY; * map.SetPointCoordinate(i, p); * } * } * else * { * // in case when we only need translation, then construct the map in a simpler way * geometry.X += shiftX; * geometry.Y += shiftY; * map.PopulatePoints(geometry, 0); * * changed = true; * } * } * } */ /// <summary> /// Set Matrix of view instance. /// </summary> internal static void SetMatrix(this EvasObject view, ReactNative.UIManager.MatrixMathHelper.MatrixDecompositionContext matrix, bool reset) { if (view == null) { throw new ArgumentNullException(nameof(view)); } double TranslationX = 0; double TranslationY = 0; double rotationX = 0; double rotationY = 0; double rotationZ = 0; double ScaleX = 1; double ScaleY = 1; if (matrix != null) { TranslationX = matrix.translation[0]; TranslationY = matrix.translation[1]; rotationX = matrix.rotationDegrees[0]; rotationY = matrix.rotationDegrees[1]; rotationZ = matrix.rotationDegrees[2]; ScaleX = matrix.scale[0]; ScaleY = matrix.scale[1]; } var map = new EvasMap(4); var g = view.Geometry; map.PopulatePoints(g, 0); //setScale map.Zoom(ScaleX, ScaleY, view.Geometry.X + (int)(view.Geometry.Width * 0.5), view.Geometry.Y + (int)(view.Geometry.Height * 0.5)); //setRotation map.Rotate3D(rotationX, rotationY, rotationZ, (int)(view.Geometry.X + view.Geometry.Width * 0.5), (int)(view.Geometry.Y + view.Geometry.Height * 0.5), 0); //setTranslation var shiftX = TranslationX; var shiftY = TranslationY; Point3D p; for (int i = 0; i < 4; i++) { p = map.GetPointCoordinate(i); p.X += (int)shiftX; p.Y += (int)shiftY; map.SetPointCoordinate(i, p); } view.EvasMap = map; view.IsMapEnabled = true; if (!reset) { if (matrix != null) { s_properties.GetOrCreateValue(view).matrix = matrix.Clone(); } } }