コード例 #1
0
        private void OnPreviewMouseDown(object sender, MouseEventArgs mouseEventArgs)
        {
            if (mouseEventArgs.Button == MouseButtons.Left)
            {
                switch (m_previewMode)
                {
                case PreviewMode.Preview:
                    m_previewMouseDown = true;
                    m_previewGrip.X    = mouseEventArgs.X;
                    m_previewGrip.Y    = mouseEventArgs.Y;
                    break;

                case PreviewMode.PickFirst:
                {
                    Location pixelLocation = new Location(mouseEventArgs.X, mouseEventArgs.Y);
                    pixelLocation.X /= m_trackBarZoom.Value;
                    pixelLocation.Y /= m_trackBarZoom.Value;
                    pixelLocation.X -= (int)m_previewOffset.X;
                    pixelLocation.Y -= (int)m_previewOffset.Y;
                    m_swapTileIndex1 = m_tileSheet.GetTileIndex(pixelLocation);
                    m_previewMode    = PreviewMode.PickSecond;
                    m_panelImage.Invalidate();
                }
                break;

                case PreviewMode.PickSecond:
                {
                    Cursor oldCursor = this.Cursor;
                    this.Cursor = Cursors.WaitCursor;

                    Location pixelLocation = new Location(mouseEventArgs.X, mouseEventArgs.Y);
                    pixelLocation.X /= m_trackBarZoom.Value;
                    pixelLocation.Y /= m_trackBarZoom.Value;
                    pixelLocation.X -= (int)m_previewOffset.X;
                    pixelLocation.Y -= (int)m_previewOffset.Y;
                    m_swapTileIndex2 = m_tileSheet.GetTileIndex(pixelLocation);

                    if (m_swapTileIndex1 != m_swapTileIndex2)
                    {
                        Command command = new TileSheetSwapTilesCommand(m_tileSheet, m_swapTileIndex1, m_swapTileIndex2);
                        CommandHistory.Instance.Do(command);
                        m_bitmapImageSource = LoadUnlockedBitmap(m_tileSheet.ImageSource);
                    }

                    this.Cursor = oldCursor;

                    m_previewMode = PreviewMode.PickFirst;
                    m_panelImage.Invalidate();
                }
                break;
                }
            }
        }