示例#1
0
        public VariableThumb(Canvas parentCanvas, Color bgColor, double width, double height) : base(bgColor)
        {
            ParentCanvas = parentCanvas;
            this.Width   = width;
            this.Height  = height;

            //8つの■作成
            //配列の位置で配置する位置に対応
            //┏━┓ 3,4,5
            //┃  ┃ 2   6
            //┗━┛ 1,0,7
            //順番は下から時計回りで、下、左下、左、左上、上、右上、右、右下
            //Tagに目印のindex番号を入れる
            Thumbs8 = new FlatThumb[8];
            for (int i = 0; i < 8; i++)
            {
                var ft = new FlatThumb(Colors.DarkOrange)
                {
                    Width = 20, Height = 20, Tag = i
                };
                Thumbs8[i]    = ft;
                ft.DragDelta += DirectionThumb_DragDelta;
            }

            this.DragDelta += VariableThumb_DragDelta;
        }
示例#2
0
        private void DirectionThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            FlatThumb flatThumb = (FlatThumb)sender;
            double    w         = this.Width;
            double    h         = this.Height;
            double    l         = Canvas.GetLeft(this);
            double    t         = Canvas.GetTop(this);
            double    xMove     = e.HorizontalChange;
            double    yMove     = e.VerticalChange;

            //Thumbの横幅と横位置を計算
            void yoko()
            {
                if (w - xMove < 1) //幅1ピクセル未満になる場合
                {
                    l = l + w - 1; //幅1ピクセルの位置で固定
                    w = 1;         //幅1ピクセルを指定
                }
                else
                {
                    l += xMove;
                    w -= xMove;
                }
            }

            //縦幅と位置を修正
            void tate()
            {
                if (h - yMove < 1)
                {
                    t = t + h - 1;
                    h = 1;
                }
                else
                {
                    t += yMove;
                    h -= yMove;
                }
            }

            //自身の位置とサイズ変更する
            switch (flatThumb.Tag)
            {
            case 0:    //下
                h += yMove;
                break;

            case 1:
                yoko();
                h += yMove;
                break;

            case 2:    //左
                yoko();
                break;

            case 3:    //左上
                yoko();
                tate();
                break;

            case 4:    //上
                tate();
                break;

            case 5:
                w += xMove;
                tate();
                break;

            case 6:    //右
                w += xMove;
                break;

            case 7:
                w += xMove;
                h += yMove;
                break;

            default:
                break;
            }

            if (w < 0)
            {
                w = 1;
            }
            if (h < 0)
            {
                h = 1;
            }

            //Thumbのサイズと位置を指定
            this.Width  = w;
            this.Height = h;
            Canvas.SetLeft(this, l);
            Canvas.SetTop(this, t);

            //8つのThumbの位置変更
            Thumbs8SetLocate();
        }