public DrawObject BuildCtrWay() { DrawObject ctrWay = this.Clone(); ctrWay.Shape.Reverse(); ctrWay.Shape.Offset(1); //右手坐标系,右手坐标系跟驾驶习惯有关系 ctrWay.BulidWay(this.WaySetter); ctrWay.Shape.Offset(penWidth - 1); //右手坐标系,右手坐标系跟驾驶习惯有关系 Way.WaysBind(this.Way, ctrWay.Way); return(ctrWay); }
/// <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) { drawArea.Graphics.UnselectAll(); o.Selected = true; drawArea.Graphics.Add(o); drawArea.Capture = true; drawArea.Refresh(); drawArea.SetDirty(); }
// 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> /// Right-click handler /// </summary> /// <param name="e"></param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary Point point = new Point(e.X, e.Y); int n = Graphics.Count; DrawObject o = null; for (int i = 0; i < n; i++) { if (Graphics[i].HitTest(point) == 0) { o = Graphics[i]; break; } } if (o != null) { if (!o.Selected) { Graphics.UnselectAll(); } // Select clicked object o.Selected = true; } else { Graphics.UnselectAll(); } Refresh(); // in the case selection was changed // Show context menu. // Context menu items are filled from owner form Edit menu items. //m_ContextMenu = new ContextMenuStrip(); //int nItems = owner.ContextParent.DropDownItems.Count; //// Read Edit items and move them to context menu. //// Since every move reduces number of items, read them in reverse order. //// To get items in direct order, insert each of them to beginning. //for (int i = nItems - 1; i >= 0; i--) //{ // m_ContextMenu.Items.Insert(0, owner.ContextParent.DropDownItems[i]); //} // Show context menu for owner form, so that it handles items selection. // Convert point from this window coordinates to owner's coordinates. point.X += this.Left; point.Y += this.Top; m_ContextMenu.Show(owner, point); Owner.SetStateOfControls(); // enable/disable menu items // Context menu is shown, but owner's Edit menu is now empty. // Subscribe to context menu Closed event and restore items there. //m_ContextMenu.Closed += delegate(object sender, ToolStripDropDownClosedEventArgs args) //{ // if (m_ContextMenu != null) // precaution // { // nItems = m_ContextMenu.Items.Count; // for (int k = nItems - 1; k >= 0; k--) // { // owner.ContextParent.DropDownItems.Insert(0, m_ContextMenu.Items[k]); // } // } //}; }
/// <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 = new Point(e.X, e.Y); // Test for resizing (only if control is selected, cursor is on the handle) foreach (DrawObject o in drawArea.Graphics.Selection) { int handleNumber = o.HitTest(point); if (handleNumber > 0) { selectMode = SelectionMode.Size; // keep resized object in class member resizedObject = o; resizedObjectHandle = handleNumber; // Since we want to resize only one object, unselect all other objects drawArea.Graphics.UnselectAll(); o.Selected = true; commandChangeState = new CommandChangeState(drawArea.Graphics); break; } } // Test for move (cursor is on the object) if (selectMode == SelectionMode.None) { int n1 = drawArea.Graphics.Count; DrawObject o = null; for (int i = 0; i < n1; i++) { if (drawArea.Graphics[i].HitTest(point) == 0) { o = drawArea.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.Graphics.UnselectAll(); } // Select clicked object o.Selected = true; commandChangeState = new CommandChangeState(drawArea.Graphics); drawArea.Cursor = Cursors.SizeAll; } } // Net selection if (selectMode == SelectionMode.None) { // click on background if ((Control.ModifierKeys & Keys.Control) == 0) { drawArea.Graphics.UnselectAll(); } selectMode = SelectionMode.NetSelection; } lastPoint.X = e.X; lastPoint.Y = e.Y; startPoint.X = e.X; startPoint.Y = e.Y; drawArea.Capture = true; drawArea.Refresh(); if (selectMode == SelectionMode.NetSelection) { // Draw selection rectangle in initial position ControlPaint.DrawReversibleFrame( drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)), Color.Black, FrameStyle.Dashed); } }
public void AddFirst(DrawObject obj) { // insert to the top of z-order graphics.Insert(0, obj); //this.Dirty = true; }
public void Add(DrawObject obj) { // insert to the top of z-order graphics.Insert(0, 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(); }