private System.Windows.Point _mousePoint;                                                             // Initial point of drag
        public bool TriggerMouseWheel(System.Windows.Input.MouseEventArgs e, System.Windows.UIElement sender) // Were not overriding OnMouseWheel anymore because it's better to override it in mainform
        {
            lock (this)
            {
                if (!this.DeviceReady)
                {
                    return(false);
                }

                System.Windows.Point newMousePoint = e.MouseDevice.GetPosition(sender);

                double oldvalue    = vScrollBar.Value;
                var    delta       = _mousePoint - newMousePoint;
                double scrollValue = (delta.Length / 10) * vScrollBar.LargeChange;

                this._mousePoint = newMousePoint;

                if (vScrollBar.Value - scrollValue < vScrollBar.Minimum)
                {
                    vScrollBar.Value = vScrollBar.Minimum;
                }
                else if (vScrollBar.Value - scrollValue > vScrollBar.Maximum)
                {
                    vScrollBar.Value = vScrollBar.Maximum;
                }
                else
                {
                    vScrollBar.Value -= (int)scrollValue;
                }
                VScrollBar_Scroll(null, null);

                return(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Drag drop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DxContainer_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            lock (this)
            {
                if (!e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    return;
                }
                if (!AssertLayerSelected())
                    return;

                string[] data = (string[])e.Data.GetData(DataFormats.FileDrop);

                // be warned when run under visual studio. it inherits VS's scaling and VS's window location
                System.Windows.Point p = PointToScreen(new System.Windows.Point(e.X, e.Y));
                foreach (string file in data)
                {
                    System.Drawing.Bitmap bmp;
                    try
                    {
                        bmp = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(file);
                    }
                    catch
                    {
                        continue;
                    }
                    if (ImageDropped != null)
                        ImageDropped.Invoke(selectedBoard, bmp, Path.GetFileNameWithoutExtension(file), 
                            new Point(PhysicalToVirtual((int) p.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual((int) p.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0)));
                }
            }
        }
Beispiel #3
0
        private void sheetCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Check if there is brush selected and tile set selected.
            if (tilesetsViewModel.Selected == null)
            {
                return;
            }
            if (brushesViewModel.Selected == null)
            {
                return;
            }

            // Get mouse position
            System.Windows.Point position = Mouse.GetPosition(gridBorder);
            int positionX = (int)position.X / tilesetsViewModel.Selected.TileWidth;
            int positionY = (int)position.Y / tilesetsViewModel.Selected.TileHeight;

            // Get bucket.
            BrushBucket brushBucket = editor.GetBrushBucketForSelectedTileset();

            // Keep selected brush in bounds.
            TileBrush brush = brushBucket.SelectedBrush;

            if (positionX + brush.DisplayWidth > tilesetsViewModel.Selected.Columns)
            {
                positionX = tilesetsViewModel.Selected.Columns - brush.DisplayWidth;
            }
            if (positionY + brush.DisplayHeight > tilesetsViewModel.Selected.Rows)
            {
                positionY = tilesetsViewModel.Selected.Rows - brush.DisplayHeight;
            }

            // Select wanted index.
            brush.SelectIndex(positionX, positionY);

            // Reconstruct selection grid.
            ReconstructSelectionGrid();
        }