Example #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (DestinationRect.Contains(Input.X, Input.Y) && Texture != null)
            {
                int texWidth  = SourceRect == null ? Texture.Width : SourceRect.Value.Width;
                int texHeight = SourceRect == null ? Texture.Height : SourceRect.Value.Height;

                if (Input.WheelDelta != 0)
                {
                    Zoom += 10 * Zoom / Input.WheelDelta;
                }
                Zoom = MathUtil.Clamp(Zoom, 0.05f, 1f);

                if (Input.MiddleButton.Down)
                {
                    Position -= new Vector2(Input.XDelta, Input.YDelta) * Zoom;
                }
                Vector2 max = new Vector2((float)(texWidth - DestinationRect.Width * ratioWPixelScreenPicture),
                                          (float)(texHeight - DestinationRect.Height * ratioHPixelScreenPicture));
                max.X    = max.X < 0 ? 0 : max.X;
                max.Y    = max.Y < 0 ? 0 : max.Y;
                Position = DrawHelper.ClampVector(Position, Vector2.Zero, max);

                if (Input.LeftButton.Pressed)
                {
                    if (SelectionMode)
                    {
                        isSelecting         = true;
                        SelectedRectangle   = null;
                        selectionStartPoint = ConvertScreenToPicture(new Vector2(Input.X, Input.Y));
                    }
                }
                if (Input.RightButton.Pressed)
                {
                    if (SelectPointMode)
                    {
                        SelectedPoint = ConvertScreenToPicture(new Vector2(Input.X, Input.Y));
                    }
                }
            }

            if (Input.LeftButton.Released && isSelecting == true)
            {
                isSelecting = false;
                Vector2   selectionEndPoint = ConvertScreenToPicture(new Vector2(Input.X, Input.Y));
                Rectangle selectionRect     = new Rectangle();
                selectionRect.Left   = Math.Min((int)selectionStartPoint.X, (int)selectionEndPoint.X);
                selectionRect.Right  = Math.Max((int)selectionStartPoint.X, (int)selectionEndPoint.X) + 1;
                selectionRect.Top    = Math.Min((int)selectionStartPoint.Y, (int)selectionEndPoint.Y);
                selectionRect.Bottom = Math.Max((int)selectionStartPoint.Y, (int)selectionEndPoint.Y) + 1;
                SelectedRectangle    = selectionRect;
            }
        }