//实现的ISerializable接口,序列化时系统会自动调用它 public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("GraphicsCount", _graphicsList.Count); for (int i = 0; i < _graphicsList.Count; i++) { DrawObject w = _graphicsList[i]; info.AddValue("ObjectType" + i, w.GetType().FullName); //调用扩充类中对应的方法 w.LoadSerializdInfo(info, i); } }
//反序列化时系统自动调用的方法(固定参数类型的特殊构造函数) protected GraphicsList(SerializationInfo info, StreamingContext context) { _graphicsList = new List <DrawObject>(); int n = info.GetInt32("GraphicsCount"); for (int i = 0; i < n; i++) { string objectType = info.GetString("ObjectType" + i); DrawObject w = (DrawObject)Assembly.GetExecutingAssembly().CreateInstance(objectType); w.SaveDeserializdInfo(info, i); _graphicsList.Add(w); } }
/// <summary>移动图形对象到指定位置,参数:层号,左上角x坐标,左上角y坐标,对象的ID</summary> public void MoveObject(int dx, int dy, string idString) { string[] ids = idString.Split('@'); for (int i = 0; i < ids.Length; i++) { int index = FindObjectIndex(int.Parse(ids[i])); if (index != -1) { DrawObject w = (DrawObject)CC.palette.graphics[index]; w.Move(dx, dy); w.Selected = false; RefreshPalette(); } } }
public override void OnMouseMove(Palette palette, MouseEventArgs e) { if (isNewObjectAdded == false) { return; } Point point = new Point(e.X, e.Y); int index = CC.myService.FindObjectIndex(CC.ID); if (e.Button == MouseButtons.Left) { DrawObject w = palette.graphics[index]; w.MoveHandleTo(point, 2); } palette.Refresh(); }
public override void OnMouseUp(Palette palette, MouseEventArgs e) { if (selectMode == SelectionMode.NetSelection) { palette.graphics.SelectInRectangle(palette.NetRectangle); selectMode = SelectionMode.None; palette.IsDrawNetRectangle = false; } int dx = (int)(lastPoint.X - startPoint.X); int dy = (int)(lastPoint.Y - startPoint.Y); string s = ""; if (selectMode == SelectionMode.Size) { if (resizedObject != null) { if (CC.userState != UserState.SingleUser) { s = resizedObject.ID.ToString() + "@" + resizedObjectHandle; //x,y,移动对象ID和句柄,IPEndPoint CC.me.SendToServer(string.Format("MoveObjectHandle,{0},{1},{2},{3}", lastPoint.X, lastPoint.Y, s, CC.me.client.Client.LocalEndPoint)); } } } if (selectMode == SelectionMode.Move) { if (CC.userState != UserState.SingleUser) { int n = palette.graphics.SelectionCount; s = ""; for (int i = n - 1; i >= 0; i--) { DrawObject w = palette.graphics.GetSelectedObject(i); s += w.ID + "@"; } //x,y,移动的对象ID集合,IPEndPoint CC.me.SendToServer(string.Format("MoveObject,{0},{1},{2},{3}", dx, dy, s.TrimEnd('@'), CC.me.client.Client.LocalEndPoint)); } } if (resizedObject != null) { resizedObject = null; } palette.Capture = false; palette.Refresh(); }
/// <summary>移动对象手柄到指定位置,参数:左上角x坐标,左上角y坐标,对象的ID和句柄号</summary> public void MoveObjectHandle(int x, int y, string idString) { string[] s = idString.Split('@'); int id = int.Parse(s[0]); int handleNumber = int.Parse(s[1]); int index = FindObjectIndex(id); if (index != -1) { DrawObject w = (DrawObject)CC.palette.graphics[index]; CC.isServerCommand = true; w.MoveHandleTo(new Point(x, y), handleNumber); CC.isServerCommand = false; w.Selected = false; RefreshPalette(); } }
/// <summary> /// 添加图形对象 /// </summary> public void Add(DrawObject w) { _graphicsList.Add(w); }
protected void AddOtherFields(DrawObject w) { w.penColor = this.penColor; w.penWidth = this.penWidth; w.ID = CC.ID; }
public override void OnMouseDown(Palette palette, MouseEventArgs e) { CC.isToolPoint = true; Point p = new Point(e.X, e.Y); selectMode = SelectionMode.None; int n = palette.graphics.SelectionCount; for (int i = n - 1; i >= 0; i--) { DrawObject w = palette.graphics.GetSelectedObject(i); int handleNumber = w.HitTest(p); if (handleNumber > 0) { selectMode = SelectionMode.Size; resizedObject = w; resizedObjectHandle = handleNumber; palette.graphics.UnselectAll(); w.Selected = true; break; } } if (selectMode == SelectionMode.None) { int n1 = palette.graphics.Count; DrawObject w = null; //查找是否有对象被选中 for (int i = n1 - 1; i >= 0; i--) { if (palette.graphics[i].HitTest(p) == 0) { w = palette.graphics[i]; break; } } if (w != null) { selectMode = SelectionMode.Move; if ((Control.ModifierKeys & Keys.Control) == 0 && !w.Selected) { palette.graphics.UnselectAll(); } w.Selected = true; palette.Cursor = Cursors.SizeAll; } } if (selectMode == SelectionMode.None) { if ((Control.ModifierKeys & Keys.Control) == 0) { palette.graphics.UnselectAll(); } selectMode = SelectionMode.NetSelection; palette.IsDrawNetRectangle = true; } lastPoint.X = p.X; lastPoint.Y = p.Y; startPoint.X = p.X; startPoint.Y = p.Y; palette.Capture = true; palette.NetRectangle = CC.GetNormalizedRectangle(startPoint, lastPoint); palette.Refresh(); }