private void _quadControl_ShapeUpdated(QuadWidgetControl sender, EventArgs arg) { //update shape of sprite //transform from original lionBounds to quadPolygon Quad2f quadCorners = _quadControl.GetQuadCorners(); _quadCorners[0] = quadCorners.left_top_x; _quadCorners[1] = quadCorners.left_top_y; _quadCorners[2] = quadCorners.right_top_x; _quadCorners[3] = quadCorners.right_top_y; _quadCorners[4] = quadCorners.right_bottom_x; _quadCorners[5] = quadCorners.right_bottom_y; _quadCorners[6] = quadCorners.left_bottom_x; _quadCorners[7] = quadCorners.left_bottom_y; //this is bilinear transformation if (_useBilinear) { Bilinear txBilinear = Bilinear.RectToQuad( _lionBounds.Left, _lionBounds.Top, _lionBounds.Right, _lionBounds.Bottom, _quadCorners); if (txBilinear.IsValid) { SpriteShape spriteShape = _mySprite.GetSpriteShape(); spriteShape.ResetTransform(); spriteShape.ApplyTransform(txBilinear); } } else { Perspective perspective = new Perspective( _lionBounds.Left, _lionBounds.Top, _lionBounds.Right, _lionBounds.Bottom, _quadCorners); if (perspective.IsValid) { SpriteShape spriteShape = _mySprite.GetSpriteShape(); spriteShape.ResetTransform(); spriteShape.ApplyTransform(perspective); } } }
protected override void OnStart(AppHost host) { _background = new Box(800, 600); _background.BackColor = Color.White; host.AddChild(_background); //--------------------------- _vgVisElem = VgVisualDocHelper.CreateVgVisualDocFromFile(@"Samples\lion.svg").VgRootElem; _mySprite = new MyTestSprite(_vgVisElem); //var evListener = new GeneralEventListener(); //evListener.MouseDrag += (s, e) => //{ // if (e.Ctrl) // { // //TODO: // //classic Agg's move and rotate // } // else // { //just move // _mySprite.SetLocation(_mySprite.Left + e.XDiff, _mySprite.Top + e.YDiff); // } //}; //_mySprite.AttachExternalEventListener(evListener); var rectBounds = _vgVisElem.GetRectBounds(); _quadControl = new QuadWidgetControl(); _quadControl.ShapeUpdated += _quadControl_ShapeUpdated; // _quadControl.SetupCorners( new Quad2f( (float)rectBounds.Left, (float)rectBounds.Bottom, (float)rectBounds.Width, (float)rectBounds.Height)); _lionBounds = new RectangleF((float)rectBounds.Left, (float)rectBounds.Bottom, (float)rectBounds.Width, (float)rectBounds.Height); host.AddChild(_mySprite); host.AddChild(_quadControl); //-------------------- _cmdBiliear = new Box(30, 30); _cmdBiliear.SetLocation(400, 20); _cmdBiliear.BackColor = Color.Yellow; _cmdBiliear.MouseDown += (s, e) => { if (_useBilinear) { _cmdBiliear.BackColor = Color.Yellow; _useBilinear = false; } else { _cmdBiliear.BackColor = Color.Red; _useBilinear = true; } }; host.AddChild(_cmdBiliear); }