// private /// <summary> /// Copy fields from this instance to cloned instance drawObject. /// Called from Clone functions of derived classes. /// </summary> /// <param name="drawObject">Object being cloned</param> protected void FillDrawObjectFields(DrawObject drawObject) { drawObject.selected = selected; drawObject.color = color; drawObject.penWidth = penWidth; drawObject._endCap = _endCap; drawObject.ID = ID; drawObject._brushType = _brushType; drawObject._penType = _penType; drawObject.drawBrush = drawBrush; drawObject.drawpen = drawpen; drawObject.filled = filled; drawObject.fillColor = fillColor; drawObject._rotation = _rotation; drawObject._center = _center; drawObject.tipText = tipText; }
private static Point TestForConnection(DrawArea drawArea, Point p, out int objectID) { // Determine if within 5 pixels of a connection point // Step 1: see if a 5 x 5 rectangle centered on the mouse cursor intersects with an object // Step 2: If it does, then see if there is a connection point within the rectangle // Step 3: If there is, move the point to the connection point, record the object's id in the connector // objectID = -1; Rectangle testRectangle = new Rectangle(p.X - 2, p.Y - 2, 5, 5); int al = drawArea.TheLayers.ActiveLayerIndex; bool connectionHere = false; Point h = new Point(-1, -1); GraphicsList gl = drawArea.TheLayers[al].Graphics; for (int i = 1; i < gl.Count; i++) { if (gl[i].IntersectsWith(testRectangle)) { DrawObject obj = (DrawObject)gl[i]; for (int j = 1; j < obj.HandleCount + 1; j++) { h = obj.GetHandle(j); if (testRectangle.Contains(h)) { connectionHere = true; p = h; objectID = obj.ID; // obj.DrawConnection(drawArea., j); break; } } } if (connectionHere) { break; } } return(p); }
// Replace objects in graphicsList with objects from list private void ReplaceObjects(GraphicsList graphicsList, List <DrawObject> list) { for (int i = 0; i < graphicsList.Count; i++) { DrawObject replacement = null; foreach (DrawObject o in list) { if (o.ID == graphicsList[i].ID) { replacement = o; break; } } if (replacement != null) { graphicsList.Replace(i, replacement); } } }
/// <summary> /// Add new object to draw area. /// Function is called when user left-clicks draw area, /// and one of ToolObject-derived tools is active. /// </summary> /// <param name="drawArea"></param> /// <param name="o"></param> protected void AddNewObject(DrawArea drawArea, DrawObject o) { int al = drawArea.TheLayers.ActiveLayerIndex; drawArea.TheLayers[al].Graphics.UnselectAll(); o.Selected = true; o.Dirty = true; int objectID = 0; // Set the object id now for (int i = 0; i < drawArea.TheLayers.Count; i++) { objectID = +drawArea.TheLayers[i].Graphics.Count; } objectID++; o.ID = objectID; drawArea.TheLayers[al].Graphics.Add(o); drawArea.Capture = true; drawArea.Refresh(); }
/// <summary> /// Returns (-1), (0), (+1) to represent the relative Z-order of the object being compared with this object /// </summary> /// <param name="obj">DrawObject that is compared to this object</param> /// <returns> (-1) if the object is less (further back) than this object. /// (0) if the object is equal to this object (same level graphically). /// (1) if the object is greater (closer to the front) than this object.</returns> public int CompareTo(object obj) { DrawObject d = obj as DrawObject; int x = 0; if (d != null) { if (d.ZOrder == ZOrder) { x = 0; } else if (d.ZOrder > ZOrder) { x = -1; } else { x = 1; } } return(x); }
/// <summary> /// Right-click handler /// </summary> /// <param name="e"></param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary Point point = BackTrackMouse(new Point(e.X, e.Y)); Point menuPoint = new Point(e.X, e.Y); int al = _layers.ActiveLayerIndex; int n = _layers[al].Graphics.Count; DrawObject o = null; for (int i = 0; i < n; i++) { if (_layers[al].Graphics[i].HitTest(point) == 0) { o = _layers[al].Graphics[i]; break; } } if (o != null) { if (!o.Selected) { _layers[al].Graphics.UnselectAll(); } // Select clicked object o.Selected = true; } else { _layers[al].Graphics.UnselectAll(); } Refresh(); Owner.ctxtMenu.Show(this, menuPoint); }
/// <summary> /// Thanks to Member 3272353 for this fix to object ordering problem. /// </summary> /// <param name="obj"></param> public void Append(DrawObject obj) { graphicsList.Add(obj); }
public void AddAsInitialGraphic(DrawObject obj) { graphicsList.Add(obj); }
// Create this command with DrawObject instance added to the list public CommandAdd(DrawObject drawObject) : base() { // Keep copy of added object this.drawObject = drawObject.Clone(); }
/// <summary> /// Left mouse button is pressed /// </summary> /// <param name="drawArea"></param> /// <param name="e"></param> 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)); // Test for resizing (only if control is selected, cursor is on the handle) 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; // keep resized object in class members resizedObject = o; resizedObjectHandle = handleNumber; // Since we want to resize only one object, unselect all other objects drawArea.TheLayers[al].Graphics.UnselectAll(); o.Selected = true; commandChangeState = new CommandChangeState(drawArea.TheLayers); break; } } // Test for move (cursor is on the object) 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 all if Ctrl is not pressed and clicked object is not selected yet if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected) { drawArea.TheLayers[al].Graphics.UnselectAll(); } // Select clicked object o.Selected = true; commandChangeState = new CommandChangeState(drawArea.TheLayers); drawArea.Cursor = Cursors.SizeAll; } } // Net selection if (selectMode == SelectionMode.None) { // click on background 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(); }