Esempio n. 1
0
        private void OnCursorTokenChanged(object sender, EventArgs e)
        {
            if (_tileController == null)
            {
                return;
            }

            if (_tileController.CursorToken == null)
            {
                this.Cursor = this.DefaultCursor;

                if (_currentCursorWrapper != null)
                {
                    _currentCursorWrapper.Dispose();
                    _currentCursorWrapper = null;
                }
            }
            else
            {
                try
                {
                    CursorWrapper oldCursorWrapper = _currentCursorWrapper;
                    _currentCursorWrapper = CursorFactory.CreateCursor(_tileController.CursorToken);
                    this.Cursor           = _currentCursorWrapper.Cursor;

                    if (oldCursorWrapper != null)
                    {
                        oldCursorWrapper.Dispose();
                    }
                }
                catch (Exception exception)
                {
                    Platform.Log(LogLevel.Error, exception);
                    this.Cursor           = this.DefaultCursor;
                    _currentCursorWrapper = null;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     項目ラベルマウス移動時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnItemLabelMouseMove(object sender, MouseEventArgs e)
        {
            // ドラッグアンドドロップが無効ならば何もしない
            if (!AllowDragDrop)
            {
                return;
            }

            // ドラッグ中でなければ何もしない
            if (_dragPoint == Point.Empty)
            {
                return;
            }

            Label label = sender as Label;

            if (label == null)
            {
                return;
            }

            // ドラッグ判定サイズを超えていなければ何もしない
            Size      dragSize = SystemInformation.DragSize;
            Rectangle dragRect = new Rectangle(_dragPoint.X - dragSize.Width / 2, _dragPoint.Y - dragSize.Height / 2,
                                               dragSize.Width, dragSize.Height);

            if (dragRect.Contains(label.Left + e.X, label.Top + e.Y))
            {
                return;
            }

            TechLabelInfo info = label.Tag as TechLabelInfo;

            if (info == null)
            {
                return;
            }

            // カーソル画像を作成する
            Bitmap bitmap = new Bitmap(label.Width, label.Height);

            bitmap.MakeTransparent(bitmap.GetPixel(0, 0));
            label.DrawToBitmap(bitmap, new Rectangle(0, 0, label.Width, label.Height));
            if (info.Item is TechItem)
            {
                _dragCursor = CursorFactory.CreateCursor(bitmap, _techLabelMask, _dragPoint.X - label.Left,
                                                         _dragPoint.Y - label.Top);
            }
            else if (info.Item is TechLabel)
            {
                _dragCursor = CursorFactory.CreateCursor(bitmap, _dragPoint.X - label.Left,
                                                         _dragPoint.Y - label.Top);
            }
            else
            {
                _dragCursor = CursorFactory.CreateCursor(bitmap, _eventLabelMask, _dragPoint.X - label.Left,
                                                         _dragPoint.Y - label.Top);
            }

            // ドラッグアンドドロップを開始する
            label.DoDragDrop(sender, DragDropEffects.Move);

            // ドラッグ状態を解除する
            _dragPoint = Point.Empty;
            _dragCursor.Dispose();

            bitmap.Dispose();
        }