public override DrawObject Clone() { DrawRectangle drawRectangle = new DrawRectangle(); drawRectangle.rectangle = rectangle; FillDrawObjectFields(drawRectangle); return(drawRectangle); }
public override void Draw(Graphics g) { Pen pen; GraphicsPath gp = new GraphicsPath(); Brush b = new SolidBrush(FillColor); Brush b1 = new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255)); Brush b2 = new HatchBrush(HatchStyle.Cross, Color.Azure); Brush b3 = new TextureBrush(FillImage); if (DrawPen == null) { pen = new Pen(Color, PenWidth); } else { pen = (Pen)DrawPen.Clone(); } Rectangle rect = DrawRectangle.GetNormalizedRectangle(Rectangle); if (ShapeName == SpecialShape.ShapeName.Triangle) { PointF[] ListPoint = { new PointF(rect.X + rect.Width / 2, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), new PointF(rect.X, rect.Y + rect.Height), new PointF(rect.X + rect.Width / 2, rect.Y) }; gp.AddLines(ListPoint); } else if (ShapeName == SpecialShape.ShapeName.RightTriangle) { PointF[] ListPoint = { new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), new PointF(rect.X, rect.Y + rect.Height), new PointF(rect.X, rect.Y) }; gp.AddLines(ListPoint); } else if (ShapeName == SpecialShape.ShapeName.RoundedRectangle) { int rad = 60; gp.AddArc(rect.X, rect.Y, rad, rad, 180, 90); gp.AddArc(rect.X + rect.Width - rad, rect.Y, rad, rad, 270, 90); gp.AddArc(rect.X + rect.Width - rad, rect.Y + rect.Height - rad, rad, rad, 0, 90); gp.AddArc(rect.X, rect.Y + rect.Height - rad, rad, rad, 90, 90); gp.AddLine(rect.X, rect.Y + rect.Height - rad, rect.X, rect.Y + rad / 2); } else if (ShapeName == SpecialShape.ShapeName.Arrow) { PointF[] ListPoint = { new PointF(rect.X + rect.Width / 2, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height / 2), new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height), new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height * 3 / 4), new PointF(rect.X, rect.Y + rect.Height * 3 / 4), new PointF(rect.X, rect.Y + rect.Height / 4), new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 4), new PointF(rect.X + rect.Width / 2, rect.Y) }; gp.AddLines(ListPoint); } else if (ShapeName == SpecialShape.ShapeName.Star) { PointF[] ListPoint = { new PointF(rect.X + rect.Width / 2, rect.Y), new PointF(rect.X + rect.Width * 6 / 10, rect.Y + rect.Height * 4 / 10), new PointF(rect.X + rect.Width, rect.Y + rect.Height * 4 / 10), new PointF(rect.X + rect.Width * 65 / 100, rect.Y + rect.Height * 65 / 100), new PointF(rect.X + rect.Width * 3 / 4, rect.Y + rect.Height), new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height * 78 / 100), new PointF(rect.X + rect.Width / 4, rect.Y + rect.Height), new PointF(rect.X + rect.Width * 35 / 100, rect.Y + rect.Height * 65 / 100), new PointF(rect.X, rect.Y + rect.Height * 4 / 10), new PointF(rect.X + rect.Width * 4 / 10, rect.Y + rect.Height * 4 / 10), new PointF(rect.X + rect.Width / 2, rect.Y) }; gp.AddLines(ListPoint); } if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } g.DrawPath(pen, gp); if (Filled) { g.FillPath(b, gp); } if (Gradient) { g.FillPath(b1, gp); } if (Hatch) { g.FillPath(b2, gp); } if (Texture) { g.FillPath(b3, gp); } gp.Dispose(); pen.Dispose(); b.Dispose(); b1.Dispose(); b2.Dispose(); b3.Dispose(); }
/* --- Phương thức --- */ public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e) { commandChangeState = null; wasMove = false; selectMode = SelectionMode.None; Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y)); // Kiểm tra có phải là đang resize int al = drawArea.TheLayers.ActiveLayerIndex; int n = drawArea.TheLayers[al].Graphics.SelectionCount; for (int i = 0; i < n; i++) { DrawObject o = drawArea.TheLayers[al].Graphics.GetSelectedObject(i); int handleNumber = o.HitTest(point); if (handleNumber > 0) { selectMode = SelectionMode.Size; // Giữ đối tượng cần resize resizedObject = o; resizedObjectHandle = handleNumber; // Khi resize một đối tượng phải unselect các đối tượng khác drawArea.TheLayers[al].Graphics.UnselectAll(); o.Selected = true; commandChangeState = new CommandChangeState(drawArea.TheLayers); break; } } // Kiểm tra có phải là đang move if (selectMode == SelectionMode.None) { int n1 = drawArea.TheLayers[al].Graphics.Count; DrawObject o = null; for (int i = 0; i < n1; i++) { if (drawArea.TheLayers[al].Graphics[i].HitTest(point) == 0) { o = drawArea.TheLayers[al].Graphics[i]; break; } } if (o != null) { selectMode = SelectionMode.Move; // Unselect tất cả nếu Ctrl chưa nhấn và một đối tượng chưa được chọn if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected) { drawArea.TheLayers[al].Graphics.UnselectAll(); } o.Selected = true; commandChangeState = new CommandChangeState(drawArea.TheLayers); drawArea.Cursor = Cursors.SizeAll; } } // Kiểm tra có phải là đang group selection if (selectMode == SelectionMode.None) { if ((Control.ModifierKeys & Keys.Control) == 0) { drawArea.TheLayers[al].Graphics.UnselectAll(); } selectMode = SelectionMode.NetSelection; drawArea.DrawNetRectangle = true; } lastPoint.X = point.X; lastPoint.Y = point.Y; startPoint.X = point.X; startPoint.Y = point.Y; drawArea.Capture = true; drawArea.NetRectangle = DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint); drawArea.Refresh(); }
public override void Normalize() { rectangle = DrawRectangle.GetNormalizedRectangle(rectangle); }
public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e) { Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y)); int al = drawArea.TheLayers.ActiveLayerIndex; wasMove = true; // Set con trỏ khi chưa nhấn chuột if (e.Button == MouseButtons.None) { Cursor cursor = null; if (drawArea.TheLayers[al].Graphics != null) { for (int i = 0; i < drawArea.TheLayers[al].Graphics.Count; i++) { int n = drawArea.TheLayers[al].Graphics[i].HitTest(point); if (n > 0) { cursor = drawArea.TheLayers[al].Graphics[i].GetHandleCursor(n); break; } } } if (cursor == null) { cursor = Cursors.Default; } drawArea.Cursor = cursor; return; } if (e.Button != MouseButtons.Left) { return; } // Khi nhấn trái chuột // Tìm khoảng cách giữa hai điểm trước và sau int dx = point.X - lastPoint.X; int dy = point.Y - lastPoint.Y; lastPoint.X = point.X; lastPoint.Y = point.Y; // Resize if (selectMode == SelectionMode.Size) { if (resizedObject != null) { resizedObject.MoveHandleTo(point, resizedObjectHandle); drawArea.Refresh(); } } // Move if (selectMode == SelectionMode.Move) { int n = drawArea.TheLayers[al].Graphics.SelectionCount; for (int i = 0; i < n; i++) { drawArea.TheLayers[al].Graphics.GetSelectedObject(i).Move(dx, dy); } drawArea.Cursor = Cursors.SizeAll; drawArea.Refresh(); } // Group selection if (selectMode == SelectionMode.NetSelection) { drawArea.NetRectangle = DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint); drawArea.Refresh(); return; } }