Пример #1
0
 /// <summary>
 /// 右下リサイズハンドルの生成
 /// </summary>
 /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
 /// <param name="handleSize">ハンドルのサイズ</param>
 /// <returns>リサイズハンドルのインスタンス</returns>
 public static ResizeHandle CreateBottomRightHandle(this Shape shape, Size handleSize)
 {
     var result
     = new ResizeHandle(shape.Color, Cursors.SizeNWSE, handleSize,
                    () => new Point(shape.Bounds.Right, shape.Bounds.Bottom),
                    ResizeHandle.HandleAlignment.BottomRight);
       result.Draged += (_, e) =>
     shape.Bounds = new Rectangle(shape.Bounds.Left,
                              shape.Bounds.Top,
                              e.Location.X - shape.Bounds.Left,
                              e.Location.Y - shape.Bounds.Top);
       result.SetLocation();
       return result;
 }
Пример #2
0
        /// <summary>
        /// 左辺中央リサイズハンドルの生成
        /// </summary>
        /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
        /// <param name="handleSize">ハンドルのサイズ</param>
        /// <returns>リサイズハンドルのインスタンス</returns>
        public static ResizeHandle CreateCenterLeftHandle(this Shape shape, Size handleSize)
        {
            var result
                = new ResizeHandle(shape.Color, Cursors.SizeWE, handleSize,
                                   () => new Point(shape.Bounds.Left, (shape.Bounds.Top + shape.Bounds.Bottom) / 2),
                                   ResizeHandle.HandleAlignment.CenterLeft);

            result.Draged += (_, e) =>
                             shape.Bounds = new Rectangle(e.Location.X,
                                                          shape.Bounds.Top,
                                                          shape.Bounds.Right - e.Location.X,
                                                          shape.Bounds.Height);
            result.SetLocation();
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 右上リサイズハンドルの生成
        /// </summary>
        /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
        /// <param name="handleSize">ハンドルのサイズ</param>
        /// <returns>リサイズハンドルのインスタンス</returns>
        public static ResizeHandle CreateTopRightHandle(this Shape shape, Size handleSize)
        {
            var result
                = new ResizeHandle(shape.Color, Cursors.SizeNESW, handleSize,
                                   () => new Point(shape.Bounds.Right, shape.Bounds.Top),
                                   ResizeHandle.HandleAlignment.TopRight);

            result.Draged += (_, e) =>
                             shape.Bounds = new Rectangle(shape.Bounds.Left,
                                                          e.Location.Y,
                                                          e.Location.X - shape.Bounds.Left,
                                                          shape.Bounds.Bottom - e.Location.Y);
            result.SetLocation();
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 左上リサイズハンドルの生成
        /// </summary>
        /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
        /// <param name="handleSize">ハンドルのサイズ</param>
        /// <returns>リサイズハンドルのインスタンス</returns>
        public static ResizeHandle CreateTopLeftHandle(this Shape shape, Size handleSize)
        {
            var result
                = new ResizeHandle(shape.Color, Cursors.SizeNWSE, handleSize,
                                   () => shape.Bounds.Location,
                                   ResizeHandle.HandleAlignment.TopLeft);

            result.Draged += (_, e) =>
                             shape.Bounds = new Rectangle(e.Location.X,
                                                          e.Location.Y,
                                                          shape.Bounds.Right - e.Location.X,
                                                          shape.Bounds.Bottom - e.Location.Y);
            result.SetLocation();
            return(result);
        }
Пример #5
0
        /// <summary>
        /// 下辺中央リサイズハンドルの生成
        /// </summary>
        /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
        /// <param name="handleSize">ハンドルのサイズ</param>
        /// <returns>リサイズハンドルのインスタンス</returns>
        public static ResizeHandle CreateBottomCenterHandle(this Shape shape, Size handleSize)
        {
            var result
                = new ResizeHandle(shape.Color, Cursors.SizeNS, handleSize,
                                   () => new Point((shape.Bounds.Left + shape.Bounds.Right) / 2, shape.Bounds.Bottom),
                                   ResizeHandle.HandleAlignment.BottomCenter);

            result.Draged += (_, e) =>
                             shape.Bounds = new Rectangle(shape.Bounds.Left,
                                                          shape.Bounds.Top,
                                                          shape.Bounds.Width,
                                                          e.Location.Y - shape.Bounds.Top);
            result.SetLocation();
            return(result);
        }
Пример #6
0
        /// <summary>
        /// ドラッグ
        /// </summary>
        /// <param name="e">マウスドラッグイベント引数</param>
        public void Drag(MouseDragEventArgs e)
        {
            var          act          = Active as Shape;
            ResizeHandle activeHandle = null;

            if (act != null)
            {
                activeHandle = act.ActiveHandle;
            }
            if (activeHandle == null)
            {
                foreach (IDraggable draggable in this.Items)
                {
                    draggable.Drag(e);
                }
                return;
            }

            var actAnchor = activeHandle.GetAnchor();

            foreach (IDraggable draggable in this.Items)
            {
                var shape = draggable as Shape;
                if (shape == null)
                {
                    continue;
                }
                shape.ActiveateHandle(activeHandle.Alignment);
                var anchor = shape.ActiveHandle.GetAnchor();
                var delta  = (Size)(anchor - (Size)actAnchor);
                var args   = new MouseDragEventArgs(e.StartLocation + delta,
                                                    e.LastLocation + delta,
                                                    e.Location + delta);
                shape.Drag(args);
            }
        }
Пример #7
0
 /// <summary>
 /// 指定ハンドルをアクティブにする
 /// </summary>
 /// <param name="alignment">アクティブにするハンドルを指定</param>
 public void ActiveateHandle(ResizeHandle.HandleAlignment alignment)
 {
     this.ActiveHandle = this.Handles.Where(h => h.Alignment == alignment)
                               .FirstOrDefault();
 }
Пример #8
0
 /// <summary>
 /// 左辺中央リサイズハンドルの生成
 /// </summary>
 /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
 /// <param name="handleSize">ハンドルのサイズ</param>
 /// <returns>リサイズハンドルのインスタンス</returns>
 public static ResizeHandle CreateCenterLeftHandle(this Shape shape, Size handleSize)
 {
     var result
     = new ResizeHandle(shape.Color, Cursors.SizeWE, handleSize,
                    () => new Point(shape.Bounds.Left, (shape.Bounds.Top + shape.Bounds.Bottom) / 2),
                    ResizeHandle.HandleAlignment.CenterLeft);
       result.Draged += (_, e) =>
     shape.Bounds = new Rectangle(e.Location.X,
                              shape.Bounds.Top,
                              shape.Bounds.Right - e.Location.X,
                              shape.Bounds.Height);
       result.SetLocation();
       return result;
 }
Пример #9
0
 /// <summary>
 /// 左上リサイズハンドルの生成
 /// </summary>
 /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
 /// <param name="handleSize">ハンドルのサイズ</param>
 /// <returns>リサイズハンドルのインスタンス</returns>
 public static ResizeHandle CreateTopLeftHandle(this Shape shape, Size handleSize)
 {
     var result
     = new ResizeHandle(shape.Color, Cursors.SizeNWSE, handleSize,
                    () => shape.Bounds.Location,
                    ResizeHandle.HandleAlignment.TopLeft);
       result.Draged += (_, e) =>
     shape.Bounds = new Rectangle(e.Location.X,
                              e.Location.Y,
                              shape.Bounds.Right - e.Location.X,
                              shape.Bounds.Bottom - e.Location.Y);
       result.SetLocation();
       return result;
 }
Пример #10
0
 /// <summary>
 /// 上辺中央リサイズハンドルの生成
 /// </summary>
 /// <param name="shape">ハンドルを保持するShapeオブジェクト</param>
 /// <param name="handleSize">ハンドルのサイズ</param>
 /// <returns>リサイズハンドルのインスタンス</returns>
 public static ResizeHandle CreateTopCenterHandle(this Shape shape, Size handleSize)
 {
     var result
     = new ResizeHandle(shape.Color, Cursors.SizeNS, handleSize,
                    () => new Point((shape.Bounds.Left + shape.Bounds.Right) / 2, shape.Bounds.Top),
                    ResizeHandle.HandleAlignment.TopCenter);
       result.Draged += (_, e) =>
     shape.Bounds = new Rectangle(shape.Bounds.Left,
                              e.Location.Y,
                              shape.Bounds.Width,
                              shape.Bounds.Bottom - e.Location.Y);
       result.SetLocation();
       return result;
 }