Exemplo n.º 1
0
    public BoardPiece(CanvasGroup group, BoardPiece [] board, int x, int y, int i)
        : base(group, CanvasGroup.GType)
    {
        this.X        = (x * PIECE_SIZE);
        this.Y        = (y * PIECE_SIZE);
        this.Board    = board;
        this.Number   = i;
        this.Position = i;

        CanvasRect rect = new CanvasRect(this);

        rect.X1           = 0.0;
        rect.Y2           = 0.0;
        rect.X2           = PIECE_SIZE;
        rect.Y2           = PIECE_SIZE;
        rect.FillColor    = Color;
        rect.OutlineColor = "black";
        rect.WidthPixels  = 0;

        CanvasText text = new CanvasText(this);

        text.Text      = (i + 1).ToString();
        text.X         = PIECE_SIZE / 2.0;
        text.Y         = PIECE_SIZE / 2.0;
        text.Font      = "Sans Bold 24";
        text.Anchor    = AnchorType.Center;
        text.FillColor = "black";

        this.Text         = text;
        this.CanvasEvent += new Gnome.CanvasEventHandler(Piece_Event);
    }
Exemplo n.º 2
0
 public UMLBox(UMLDiagram ownerDiagram, DI.GraphNode graphNode)
     : base(ownerDiagram, graphNode)
 {
     _outerBox = new CanvasRect (ChildrensRoot);
     _outerBox.X1 = _outerBox.Y1 = 0;
     _outerBox.X2 = Width;
     _outerBox.Y2 = Height;
     _outerBox.FillColor = DEFAULT_FILL_COLOR;
     _outerBox.OutlineColor = DEFAULT_OUTLINE_COLOR;
     Width = graphNode.Size.Width;
     Height = graphNode.Size.Height;
     // gets the corresponding model element
     Uml2SemanticModelBridge bridge = (Uml2SemanticModelBridge) graphNode.SemanticModel;
     _modelElement = (UML.NamedElement) bridge.Element;
     DI.GraphElement nestedDiagElem;
     DI.SimpleSemanticModelElement nestedBridge;
     // looks for the Name compartment
     foreach (DI.DiagramElement elem in GraphNode.Contained)
     {
         nestedDiagElem = elem as DI.GraphElement;
         if (nestedDiagElem != null)
         {
             nestedBridge = nestedDiagElem.SemanticModel as DI.SimpleSemanticModelElement;
             if (nestedBridge.TypeInfo == "NameCompartment")
             {
                 // widget for the property Name
                 _name = new UMLEntry (this, (DI.GraphNode)nestedDiagElem, ChildrensRoot, false, _modelElement.Name);
                 _name.Show();
                 break;
             }
         }
     }
     Redraw ();
 }
		void AddObject (object obj, EventArgs args)
		{
			double x1 = random.Next (width);
			double y1 = random.Next (height);
			double x2 = random.Next (width);
			double y2 = random.Next (height);

			if (x1 > x2)
				Swap (ref x1, ref x2);
			
			if (y1 > y2)
				Swap (ref y1, ref y2);

			if ((x2 - x1) < 10)
				x2 += 10;

			if ((y2 - y1) < 10)
				y2 += 10;

			CanvasRE item = null;
			if (random.Next (2) > 0)
				item = new CanvasRect (canvas.Root ());
			else
				item = new CanvasEllipse (canvas.Root ());

			item.X1 = x1;
			item.Y1 = y1;
			item.X2 = x2;
			item.Y2 = y2;
			item.FillColor = "white";
			item.OutlineColor = "black";
			item.WidthUnits = 1.0;

			item.CanvasEvent += new Gnome.CanvasEventHandler (Item_Event);
		}
 /// <summary>
 /// Update image source transform.
 /// </summary>
 private void UpdateImageLayout(bool animate = false)
 {
     if (SourceImage != null && CanvasRect.IsValid())
     {
         var uniformSelectedRect = CanvasRect.GetUniformRect(_currentCroppedRect.Width / _currentCroppedRect.Height);
         UpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate);
     }
 }
Exemplo n.º 5
0
        public UMLSelector(CanvasGroup group)
        {
            _selected_elements =new ArrayList();
            _rectangle = new CanvasRect(group);

            _rectangle.FillColorRgba = DefaultFillColor;
            _rectangle.OutlineColor = DefaultOutlineColor;
        }
Exemplo n.º 6
0
 public void PresentContent()
 {
     dcRenderView.ClearRenderTarget();
     lock (dcRenderView)
     {
         if (CanvasRect != null)
         {
             CanvasRect.SetRefTexture(CanvasCase.RenderTarget[0], 0);
             CanvasRect.Render();
         }
         dcRenderView.Present();
     }
 }
Exemplo n.º 7
0
        void AddObject(object obj, EventArgs args)
        {
            double x1 = random.Next(width);
            double y1 = random.Next(height);
            double x2 = random.Next(width);
            double y2 = random.Next(height);

            if (x1 > x2)
            {
                Swap(ref x1, ref x2);
            }

            if (y1 > y2)
            {
                Swap(ref y1, ref y2);
            }

            if ((x2 - x1) < 10)
            {
                x2 += 10;
            }

            if ((y2 - y1) < 10)
            {
                y2 += 10;
            }

            CanvasRE item = null;

            if (random.Next(2) > 0)
            {
                item = new CanvasRect(canvas.Root());
            }
            else
            {
                item = new CanvasEllipse(canvas.Root());
            }

            item.X1           = x1;
            item.Y1           = y1;
            item.X2           = x2;
            item.Y2           = y2;
            item.FillColor    = "white";
            item.OutlineColor = "black";
            item.WidthUnits   = 1.0;

            item.CanvasEvent += new Gnome.CanvasEventHandler(Item_Event);
        }
Exemplo n.º 8
0
    public CurveWidget(Curve _curve)
        : base()
    {
        PixelsPerUnit = 300;

        CanvasRect rect = new CanvasRect(Root());
        rect.X1 = 0;
        rect.Y1 = 0;
        rect.X2 = 1;
        rect.Y2 = 1;
        rect.FillColor = "white";
        rect.OutlineColor = null;
        rect.WidthUnits = 0.0;

        CenterScrollRegion = true;
        SetScrollRegion(0.0, 0.0, 1.0, 1.0);

        curve = _curve;

        bpath = new MyBPath(Root());
        bpath.WidthPixels = 0;
        bpath.OutlineColor = "blue";

        MakeLine(0,0.25, 1,0.25);
        MakeLine(0,0.5, 1,0.5);
        MakeLine(0,0.75, 1,0.75);

        MakeLine(0.25,0, 0.25,1);
        MakeLine(0.5,0, 0.5,1);
        MakeLine(0.75,0, 0.75,1);

        points = new ArrayList();

        for (uint i = 0; i < curve.NumPoints(); ++i) {
            float x, y;
            curve.GetPoint (i, out x, out y);
            points.Add (new CurvePoint(x, y, this));
        }

        bpath.SetPathDef(MakePathDef());

        marker = new CurveMarker(0, 0, this, "dark grey");
        marker.Active = false;

        ButtonPressEvent += new ButtonPressEventHandler(OnButtonPress);
    }
Exemplo n.º 9
0
    public void Init(string Content, string Title, UiDialogType DialogType, UnityAction OnOkPress = null,
                     UnityAction OnCancelPress = null, UiDialogInputInterface OnSubmit = null)
    {
        if (DialogType == UiDialogType.UI_DIALOG_CONFIRM || DialogType == UiDialogType.UI_DIALOG_INPUT)
        {
            CancelButton.gameObject.SetActive(true);
        }
        OkButton.gameObject.SetActive(true);
        if (OnOkPress != null)
        {
            OkButton.onClick.AddListener(OnOkPress);
        }
        else
        {
            OkButton.onClick.AddListener(delegate { CloseDialog(); });
        }
        if (OnCancelPress != null)
        {
            CancelButton.onClick.AddListener(OnCancelPress);
        }
        else
        {
            CancelButton.onClick.AddListener(delegate { CloseDialog(); });
        }
        if (DialogType == UiDialogType.UI_DIALOG_INPUT)
        {
            DialogInputField.gameObject.SetActive(true);
            if (OnSubmit != null)
            {
                DialogInputField.onEndEdit.AddListener(delegate { OnSubmit.OnEndEdit(DialogInputField); });
            }
            else
            {
                DialogInputField.onEndEdit.AddListener(delegate { CloseDialog(); });
            }
        }

        RectTransform CanvasRect;

        //Make it show on top.
        CanvasRect = transform as RectTransform;
        CanvasRect.SetAsLastSibling();
        DialogTitle.text   = Title;
        DialogContent.text = Content;
    }
Exemplo n.º 10
0
        //public UMLControlPointGroup (UMLNode group) : base ((CanvasGroup) group)
        public UMLControlPointGroup(UMLElement group)
            : base((CanvasGroup) group)
        {
            _element = group;
            _p = new UMLControlPoint [4];
            _frame = new CanvasRect (this);
            _frame.OutlineColor = DEFAULT_OUTLINE_COLOR;
            _frame.FillColorRgba = 0xfbfbfb15;
            _frame.WidthUnits = 1;
            _frame.Show ();

            for (int i = 0; i < ((int) Location.Total); i++)
            {
                _p[i] = new UMLControlPoint (this);
                _p[i].Moved += PointMoved;
            }
            Redraw ();
        }
Exemplo n.º 11
0
	public BoardPiece (CanvasGroup group, BoardPiece [] board, int x, int y, int i)
		: base (group, CanvasGroup.GType)
	{
		this.X = (x * PIECE_SIZE);
		this.Y = (y * PIECE_SIZE);
		this.Board = board;
		this.Number = i;
		this.Position = i;		

		CanvasRect rect = new CanvasRect (this);
		rect.X1 = 0.0;
		rect.Y2 = 0.0;
		rect.X2 = PIECE_SIZE;
		rect.Y2 = PIECE_SIZE;
		rect.FillColor = Color;
		rect.OutlineColor = "black";
		rect.WidthPixels = 0;
		
		CanvasText text = new CanvasText (this);
		text.Text = (i + 1).ToString ();
		text.X = PIECE_SIZE / 2.0;
		text.Y = PIECE_SIZE / 2.0;
		text.Font = "Sans Bold 24";
		text.Anchor = AnchorType.Center;
		text.FillColor = "black";

		this.Text = text;
		this.CanvasEvent += new Gnome.CanvasEventHandler (Piece_Event);
	}
Exemplo n.º 12
0
 public CurveMarker(double _x, double _y, CurveWidget _curveWidget, string color)
 {
     x = _x;
     y = _y;
     curveWidget = _curveWidget;
     rect = new CanvasRect(curveWidget.Root());
     rect.FillColor = color;
     rect.OutlineColor = color;
     rect.WidthUnits = 0.0;
     SetRectBounds();
     active = true;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Grows the canvas to include the rect
 /// </summary>
 /// <param name="r">a rect in canvas space</param>
 public void EnlargeCanvasFor(Rect r)
 {
     //if (CurvyGUI.IsLayout)
     CanvasRect = CanvasRect.Include(r);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Update cropped area.
        /// </summary>
        /// <param name="dragPosition">The control point</param>
        /// <param name="diffPos">Position offset</param>
        private void UpdateCroppedRectWithAspectRatio(DragPosition dragPosition, Point diffPos)
        {
            if (diffPos == default(Point) || !CanvasRect.IsValid())
            {
                return;
            }

            double radian = 0d, diffPointRadian = 0d, effectiveLength = 0d;

            if (KeepAspectRatio)
            {
                radian          = Math.Atan(UsedAspectRatio);
                diffPointRadian = Math.Atan(diffPos.X / diffPos.Y);
            }

            var startPoint          = new Point(_startX, _startY);
            var endPoint            = new Point(_endX, _endY);
            var currentSelectedRect = new Rect(startPoint, endPoint);

            switch (dragPosition)
            {
            case DragPosition.Top:
                if (KeepAspectRatio)
                {
                    var originSizeChange = new Point(-diffPos.Y * UsedAspectRatio, -diffPos.Y);
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    startPoint.X += -safeChange.X / 2;
                    endPoint.X   -= -safeChange.X / 2;
                    startPoint.Y += -safeChange.Y;
                }
                else
                {
                    startPoint.Y += diffPos.Y;
                }

                break;

            case DragPosition.Bottom:
                if (KeepAspectRatio)
                {
                    var originSizeChange = new Point(diffPos.Y * UsedAspectRatio, diffPos.Y);
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    startPoint.X -= safeChange.X / 2;
                    endPoint.X   += safeChange.X / 2;
                    endPoint.Y   += safeChange.Y;
                }
                else
                {
                    endPoint.Y += diffPos.Y;
                }

                break;

            case DragPosition.Left:
                if (KeepAspectRatio)
                {
                    var originSizeChange = new Point(-diffPos.X, -diffPos.X / UsedAspectRatio);
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    startPoint.Y += -safeChange.Y / 2;
                    endPoint.Y   -= -safeChange.Y / 2;
                    startPoint.X += -safeChange.X;
                }
                else
                {
                    startPoint.X += diffPos.X;
                }

                break;

            case DragPosition.Right:
                if (KeepAspectRatio)
                {
                    var originSizeChange = new Point(diffPos.X, diffPos.X / UsedAspectRatio);
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    startPoint.Y -= safeChange.Y / 2;
                    endPoint.Y   += safeChange.Y / 2;
                    endPoint.X   += safeChange.X;
                }
                else
                {
                    endPoint.X += diffPos.X;
                }

                break;

            case DragPosition.UpperLeft:
                if (KeepAspectRatio)
                {
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    var originSizeChange = new Point(-effectiveLength * Math.Sin(radian), -effectiveLength * Math.Cos(radian));
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    diffPos.X = -safeChange.X;
                    diffPos.Y = -safeChange.Y;
                }

                startPoint.X += diffPos.X;
                startPoint.Y += diffPos.Y;
                break;

            case DragPosition.UpperRight:
                if (KeepAspectRatio)
                {
                    diffPointRadian = -diffPointRadian;
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    var originSizeChange = new Point(-effectiveLength * Math.Sin(radian), -effectiveLength * Math.Cos(radian));
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    diffPos.X = safeChange.X;
                    diffPos.Y = -safeChange.Y;
                }

                endPoint.X   += diffPos.X;
                startPoint.Y += diffPos.Y;
                break;

            case DragPosition.LowerLeft:
                if (KeepAspectRatio)
                {
                    diffPointRadian = -diffPointRadian;
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    var originSizeChange = new Point(effectiveLength * Math.Sin(radian), effectiveLength * Math.Cos(radian));
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    diffPos.X = -safeChange.X;
                    diffPos.Y = safeChange.Y;
                }

                startPoint.X += diffPos.X;
                endPoint.Y   += diffPos.Y;
                break;

            case DragPosition.LowerRight:
                if (KeepAspectRatio)
                {
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    var originSizeChange = new Point(effectiveLength * Math.Sin(radian), effectiveLength * Math.Cos(radian));
                    var safeChange       = _restrictedSelectRect.GetSafeSizeChangeWhenKeepAspectRatio(dragPosition, currentSelectedRect, originSizeChange, UsedAspectRatio);
                    diffPos.X = safeChange.X;
                    diffPos.Y = safeChange.Y;
                }

                endPoint.X += diffPos.X;
                endPoint.Y += diffPos.Y;
                break;
            }

            if (!RectExtensions.IsSafeRect(startPoint, endPoint, MinSelectSize))
            {
                if (KeepAspectRatio)
                {
                    if ((endPoint.Y - startPoint.Y) < (_endY - _startY) ||
                        (endPoint.X - startPoint.X) < (_endX - _startX))
                    {
                        return;
                    }
                }
                else
                {
                    var safeRect = RectExtensions.GetSafeRect(startPoint, endPoint, MinSelectSize, dragPosition);
                    safeRect.Intersect(_restrictedSelectRect);
                    startPoint = new Point(safeRect.X, safeRect.Y);
                    endPoint   = new Point(safeRect.X + safeRect.Width, safeRect.Y + safeRect.Height);
                }
            }

            var isEffectiveRegion = _restrictedSelectRect.IsSafePoint(startPoint) &&
                                    _restrictedSelectRect.IsSafePoint(endPoint);
            var selectedRect = new Rect(startPoint, endPoint);

            if (!isEffectiveRegion)
            {
                if (_restrictedSelectRect.GetContainsRect(ref selectedRect))
                {
                    startPoint = new Point(selectedRect.Left, selectedRect.Top);
                    endPoint   = new Point(selectedRect.Right, selectedRect.Bottom);
                }
                else
                {
                    return;
                }
            }
            selectedRect.Union(CanvasRect);
            if (selectedRect != CanvasRect)
            {
                var croppedRect = _inverseImageTransform.TransformBounds(
                    new Rect(startPoint, endPoint));
                croppedRect.Intersect(_restrictedCropRect);
                _currentCroppedRect = croppedRect;
                var viewportRect    = CanvasRect.GetUniformRect(selectedRect.Width / selectedRect.Height);
                var viewportImgRect = _inverseImageTransform.TransformBounds(selectedRect);
                UpdateImageLayoutWithViewport(viewportRect, viewportImgRect);
            }
            else
            {
                UpdateSelectedRect(startPoint, endPoint);
            }
        }
Exemplo n.º 15
0
        private void VisualizeLogisim(LogisimConverter.LogisimModel model)
        {
            canvasControl1.RemoveAllItems();

            // Comps

            foreach (var comp in model.comps)
            {
                CanvasRect rect = new CanvasRect((PointF)comp.loc,
                                                 LogisimConverter.CompSize, LogisimConverter.CompSize, Color.Gold);

                rect.Text = comp.name;

                if (comp.name == "Text")
                {
                    // Skip labels
                    continue;
                }
                else if (comp.name == "1")
                {
                    rect.FrontColor = Color.Tomato;
                }
                else if (comp.name == "0")
                {
                    rect.FrontColor = Color.LimeGreen;
                }

#if DEBUG
                rect.Text += " #" + comp.id.ToString();
#endif

                canvasControl1.AddItem(rect);
            }

            // Wires

            foreach (var wire in model.wires)
            {
                List <PointF> path = new List <PointF>();

                foreach (var p in wire.path)
                {
                    path.Add(p);
                }

                CanvasPolyLine line = new CanvasPolyLine(path, 1, Color.Black);
                line.Text = wire.name;

                WireMeta meta = new WireMeta();

                meta.wire     = wire;
                line.UserData = meta;

                canvasControl1.AddItem(line);
                WireDirection(wire, meta);
            }

            // Vias

            foreach (var vias in model.viases)
            {
                CanvasPoint point = new CanvasPoint(vias.loc, 5, Color.Gold);
#if DEBUG
                //point.Text = vias.id.ToString();
                //point.TextColor = Color.DeepPink;
#endif
                canvasControl1.AddItem(point);
            }

            canvasControl1.Invalidate();
        }
Exemplo n.º 16
0
		private void InitBackGroup ()
		{
			_back_group = new CanvasGroup (_canvas.Root ());
			_back_group.X = 0;
			_back_group.Y = 0;
			
			//Nicer appearence with a drawn background
			_bg = new CanvasRect (_back_group);
			_bg.X1 = _bg.Y1 = 0;
			/*_bg.X2 = _canvas.Width;
			_bg.Y2 = _canvas.Height;*/
			_bg.FillColor = DEFAULT_FILL_COLOR;

			_grid = false;
			_snap_to_grid = false;

			_grid_components = new ArrayList ();
		}
Exemplo n.º 17
0
        /// <summary>
        /// Update image source transform.
        /// </summary>
        private void UpdateImageLayout()
        {
            var uniformSelectedRect = CanvasRect.GetUniformRect(_currentCroppedRect.Width / _currentCroppedRect.Height);

            UpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Update cropped area.
        /// </summary>
        /// <param name="dragPosition">The control point</param>
        /// <param name="diffPos">Position offset</param>
        private void UpdateCroppedRectWithAspectRatio(DragPosition dragPosition, Point diffPos)
        {
            double radian = 0d, diffPointRadian = 0d, effectiveLength = 0d;

            if (KeepAspectRatio)
            {
                radian          = Math.Atan(UsedAspectRatio);
                diffPointRadian = Math.Atan(diffPos.X / diffPos.Y);
            }

            var startPoint = new Point(_startX, _startY);
            var endPoint   = new Point(_endX, _endY);

            switch (dragPosition)
            {
            case DragPosition.Top:
                startPoint.Y += diffPos.Y;
                if (KeepAspectRatio)
                {
                    var changeX = diffPos.Y * UsedAspectRatio;
                    startPoint.X += changeX / 2;
                    endPoint.X   -= changeX / 2;
                }

                break;

            case DragPosition.Bottom:
                endPoint.Y += diffPos.Y;
                if (KeepAspectRatio)
                {
                    var changeX = diffPos.Y * UsedAspectRatio;
                    startPoint.X -= changeX / 2;
                    endPoint.X   += changeX / 2;
                }

                break;

            case DragPosition.Left:
                startPoint.X += diffPos.X;
                if (KeepAspectRatio)
                {
                    var changeY = diffPos.X / UsedAspectRatio;
                    startPoint.Y += changeY / 2;
                    endPoint.Y   -= changeY / 2;
                }

                break;

            case DragPosition.Right:
                endPoint.X += diffPos.X;
                if (KeepAspectRatio)
                {
                    var changeY = diffPos.X / UsedAspectRatio;
                    startPoint.Y -= changeY / 2;
                    endPoint.Y   += changeY / 2;
                }

                break;

            case DragPosition.UpperLeft:
                if (KeepAspectRatio)
                {
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    diffPos.X       = effectiveLength * Math.Sin(radian);
                    diffPos.Y       = effectiveLength * Math.Cos(radian);
                }

                startPoint.X += diffPos.X;
                startPoint.Y += diffPos.Y;
                break;

            case DragPosition.UpperRight:
                if (KeepAspectRatio)
                {
                    diffPointRadian = -diffPointRadian;
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    diffPos.X       = -effectiveLength *Math.Sin(radian);

                    diffPos.Y = effectiveLength * Math.Cos(radian);
                }

                endPoint.X   += diffPos.X;
                startPoint.Y += diffPos.Y;
                break;

            case DragPosition.LowerLeft:
                if (KeepAspectRatio)
                {
                    diffPointRadian = -diffPointRadian;
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    diffPos.X       = -effectiveLength *Math.Sin(radian);

                    diffPos.Y = effectiveLength * Math.Cos(radian);
                }

                startPoint.X += diffPos.X;
                endPoint.Y   += diffPos.Y;
                break;

            case DragPosition.LowerRight:
                if (KeepAspectRatio)
                {
                    effectiveLength = diffPos.Y / Math.Cos(diffPointRadian) * Math.Cos(diffPointRadian - radian);
                    diffPos.X       = effectiveLength * Math.Sin(radian);
                    diffPos.Y       = effectiveLength * Math.Cos(radian);
                }

                endPoint.X += diffPos.X;
                endPoint.Y += diffPos.Y;
                break;
            }

            if (!RectExtensions.IsSafeRect(startPoint, endPoint, MinSelectSize))
            {
                if (KeepAspectRatio)
                {
                    if ((endPoint.Y - startPoint.Y) < (_endY - _startY) ||
                        (endPoint.X - startPoint.X) < (_endX - _startX))
                    {
                        return;
                    }
                }
                else
                {
                    var safeRect = RectExtensions.GetSafeRect(startPoint, endPoint, MinSelectSize, dragPosition);
                    safeRect.Intersect(_restrictedSelectRect);
                    startPoint = new Point(safeRect.X, safeRect.Y);
                    endPoint   = new Point(safeRect.X + safeRect.Width, safeRect.Y + safeRect.Height);
                }
            }

            var isEffectiveRegion = _restrictedSelectRect.IsSafePoint(startPoint) &&
                                    _restrictedSelectRect.IsSafePoint(endPoint);

            if (!isEffectiveRegion)
            {
                return;
            }
            var selectedRect = new Rect(startPoint, endPoint);

            selectedRect.Union(CanvasRect);
            if (selectedRect != CanvasRect)
            {
                var inverseImageTransform = _imageTransform.Inverse;
                if (inverseImageTransform == null)
                {
                    return;
                }
                var croppedRect = inverseImageTransform.TransformBounds(
                    new Rect(startPoint, endPoint));
                croppedRect.Intersect(_restrictedCropRect);
                _currentCroppedRect = croppedRect;
                var viewportRect    = CanvasRect.GetUniformRect(selectedRect.Width / selectedRect.Height);
                var viewportImgRect = inverseImageTransform.TransformBounds(selectedRect);
                UpdateImageLayoutWithViewport(viewportRect, viewportImgRect);
            }
            else
            {
                UpdateSelectedRect(startPoint, endPoint);
            }
        }