/// <summary> /// Initialization /// </summary> /// <param name="owner"></param> /// <param name="docManager"></param> public void Initialize() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); // Keep reference to owner form this.Owner = this.FindForm(); // set default tool activeTool = DrawToolType.Pointer; // create list of graphic objects graphicsList = new GraphicsList(); // Create undo manager undoManager = new UndoManager(graphicsList); // create array of drawing tools tools = new Tool[(int)DrawToolType.NumberOfXImage]; tools[(int)DrawToolType.Pointer] = new ToolPointer(); tools[(int)DrawToolType.Rectangle] = new ToolRectangle(); tools[(int)DrawToolType.Ellipse] = new ToolEllipse(); tools[(int)DrawToolType.Line] = new ToolLine(); tools[(int)DrawToolType.Polygon] = new ToolPolygon(); tools[(int)DrawToolType.Text] = new ToolText(); tools[(int)DrawToolType.Point] = new ToolPoint(); }
public override void Redo(GraphicsList list) { // Delete from list all objects kept in cloneList int n = list.Count; for (int i = n - 1; i >= 0; i--) { bool toDelete = false; DrawObject objectToDelete = list[i]; foreach (DrawObject o in cloneList) { if (objectToDelete.ID == o.ID) { toDelete = true; break; } } if (toDelete) { list.RemoveAt(i); } } }
public override void Redo(GraphicsList list) { // Delete from list all objects kept in cloneList int n = list.Count; for ( int i = n - 1; i >= 0; i-- ) { bool toDelete = false; DrawObject objectToDelete = list[i]; foreach(DrawObject o in cloneList) { if ( objectToDelete.ID == o.ID ) { toDelete = true; break; } } if ( toDelete ) { list.RemoveAt(i); } } }
/// <summary> /// /// </summary> /// <param name="graphicsList"></param> /// <param name="listToFill"></param> private void FillList(GraphicsList graphicsList, ref List <DrawObject> listToFill) { listToFill = new List <DrawObject>(); foreach (DrawObject o in graphicsList.Selection) { listToFill.Add(o.Clone()); } }
public override void Undo(GraphicsList list) { // Add all objects from clone list to list - // opposite to DeleteAll foreach (DrawObject o in cloneList) { list.Add(o); } }
// Fill list from selection private void FillList(GraphicsList graphicsList, ref List<DrawObject> listToFill) { listToFill = new List<DrawObject>(); foreach (DrawObject o in graphicsList.Selection) { listToFill.Add(o.Clone()); } }
public override void Undo(GraphicsList list) { // list.UnselectAll(); // Add all objects from cloneList to list. foreach (DrawObject o in cloneList) { list.Add(o); } }
public override void Undo(GraphicsList list) { list.UnselectAll(); // Add all objects from cloneList to list. foreach(DrawObject o in cloneList) { list.Add(o); } }
public CommandDeleteAll(GraphicsList graphiList) : base(graphiList) { cloneList = new List <DrawObject>(); int n = graphicsList.Count; for (int i = n - 1; i >= 0; i--) { cloneList.Add(graphicsList[i].Clone()); } }
private List <DrawObject> cloneList; // contains selected items which are deleted // Create this command BEFORE applying Delete All function. public CommandDelete(GraphicsList graphicsList) { cloneList = new List <DrawObject>(); // Make clone of the list selection. foreach (DrawObject o in graphicsList.Selection) { cloneList.Add(o.Clone()); } }
List<DrawObject> cloneList; // contains selected items which are deleted // Create this command BEFORE applying Delete All function. public CommandDelete(GraphicsList graphicsList) { cloneList = new List<DrawObject>(); // Make clone of the list selection. foreach(DrawObject o in graphicsList.Selection) { cloneList.Add(o.Clone()); } }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { //var resource = this.Resources["GraphicsData"] as GraphicsList; var resource = new GraphicsList(); resource.Add(new Graphics() { Name = "Some new Collection of data" }); this.GraphicsData = resource; }
// Create this command BEFORE applying Delete All function. public CommandDeleteAll(GraphicsList graphicsList) { cloneList = new List <DrawObject>(); // Make clone of the whole list. // Add objects in reverse order because GraphicsList.Add // insert every object to the beginning. int n = graphicsList.Count; for (int i = n - 1; i >= 0; i--) { cloneList.Add(graphicsList[i].Clone()); } }
// Create this command BEFORE applying Delete All function. public CommandDeleteAll(GraphicsList graphicsList) { cloneList = new List<DrawObject>(); // Make clone of the whole list. // Add objects in reverse order because GraphicsList.Add // insert every object to the beginning. int n = graphicsList.Count; for ( int i = n - 1; i >= 0; i-- ) { cloneList.Add(graphicsList[i].Clone()); } }
public bool TestForPinConnection(Point p, ref long ID, ref long PinID, ref int PinNo, ref string PinName, ref int PinType, ref short PinClass, ref bool PinIsUsed, ref string objectinstansename) { // 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 pin 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 // ID = -1; Rectangle testRectangle = new Rectangle(p.X - 4, p.Y - 4, 9, 9); bool connectionHere = false; Point h = new Point(-1, -1); GraphicsList gl = GraphicPagesList[ActivePageNo]; foreach (DrawLogic obj in GraphicPagesList[ActivePageNo].List) { if (obj is DrawFBDBox) { if (obj.IntersectsWith(testRectangle)) { //DrawObject obj = (DrawObject)gl[i]; for (int j = 0; j < obj.HandleCount; j++) { h = obj.GetHandle(j); bool testMouseOverPin = testRectangle.Contains(h); //Console.WriteLine("h.x = {0} h.y = {1}", h.X, h.Y); if (testMouseOverPin) { obj.GetPinInfo(j, ref PinID, ref PinNo, ref PinName, ref PinType, ref PinClass, ref PinIsUsed, ref objectinstansename); connectionHere = true; p = h; ID = ((DrawFBDBox)obj).tblfbdblock.FBDBlockID; // obj.DrawConnection(drawArea., j); return(true); } } } } if (connectionHere) { break; } } PinNo = 0; PinClass = (short)VarClass.Input; return(false); }
public static void ReloadTexture() { foreach (var kvp in GraphicsList) { foreach (var i in kvp.Value) { i.Dispose(); } } GraphicsList.Clear(); foreach (var p in loadingList) { var i = p.Value; LoadTextures(i.Texture, i.Size.Width, i.Size.Height); } }
/// <summary> /// Right-click handler /// </summary> /// <param name="e"></param> private void OnContextMenu(MouseEventArgs e) { // Change current selection if necessary var point = new Point(e.X, e.Y); int n = GraphicsList.Count; XnaDrawObject o = null; for (int i = 0; i < n; i++) { if (GraphicsList[i].HitTest(point) == 0) { o = GraphicsList[i]; break; } } if (o != null) { if (!o.Selected) { GraphicsList.UnselectAll(); } // Select clicked object o.Selected = true; _bringToFrontToolStripMenuItem.Enabled = true; _sendToBackToolStripMenuItem.Enabled = true; _cutToolStripMenuItem.Enabled = true; _copyToolStripMenuItem.Enabled = true; _deleteToolStripMenuItem.Enabled = true; } else { _bringToFrontToolStripMenuItem.Enabled = false; _sendToBackToolStripMenuItem.Enabled = false; _cutToolStripMenuItem.Enabled = false; _copyToolStripMenuItem.Enabled = false; _deleteToolStripMenuItem.Enabled = false; GraphicsList.UnselectAll(); } _pasteToolStripMenuItem.Enabled = GraphicsList.AreItemsInMemory(); _contextMenuStrip.Show(MousePosition); Refresh(); }
public ZWPictureBox() { // enable double buffering this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); this.laser = new FixedLaser(this); rulers = new Rulers(this); listViewItemArray = new ListViewItemArray(); GraphicsList = new GraphicsList(); this.GraphicsList.DrawObjsChanged += GraphicsList_DrawObjsChanged; Initialize(); InitializeControls(); InitializeImageTracker(); this.PictureBoxPaintedEvent += imageTracker.OnPicturePainted; }
public void LoadFromStream(SerializationInfo info, int orderNumber) { _graphicsList = new GraphicsList(); _name = info.GetString( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryLayerName, orderNumber)); _visible = info.GetBoolean( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryLayerVisible, orderNumber)); _active = info.GetBoolean( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryLayerActive, orderNumber)); int n = info.GetInt32( String.Format(CultureInfo.InvariantCulture, "{0}{1}", entryGraphicsCount, orderNumber)); for (int i = 0; i < n; i++) { string typeName; typeName = info.GetString( String.Format(CultureInfo.InvariantCulture, "{0}{1}-{2}", entryObjectType, orderNumber, i)); object drawObject; drawObject = Assembly.GetExecutingAssembly().CreateInstance(typeName); ((DrawObject)drawObject).LoadFromStream(info, orderNumber, i); // Thanks to Member 3272353 for this fix to object ordering problem. // _graphicsList.Add((DrawObject)drawObject); _graphicsList.Append((DrawObject)drawObject); } }
/// <summary> /// Handles the Paint event /// </summary> /// <param name="pe"></param> protected override void OnPaint(PaintEventArgs e) { try { if (PictureBoxPaintedEvent != null) { Rectangle controlClientRect = ClientRectangle; controlClientRect.X -= OffsetX; controlClientRect.Y -= OffsetY; PictureBoxPaintedEvent(controlClientRect, this.ClientRectangle); } if (this.Image != null) { e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.ScaleTransform(zoom, zoom); e.Graphics.TranslateTransform(OffsetX, OffsetY); e.Graphics.DrawImage(this.Image, 0, 0); } if (GraphicsList != null) { GraphicsList.Draw(e.Graphics, this); } if (rulers != null) { rulers.Draw(e.Graphics); } if (LaserFunction) { if (laser != null) { laser.OnPaint(e); } } } catch (Exception ex) { LogHelper.GetLogger <ZWPictureBox>().Error(ex.Message); LogHelper.GetLogger <ZWPictureBox>().Error(ex.StackTrace); } }
// 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> /// /// </summary> /// <param name="graphicsList"></param> /// <param name="list"></param> 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> /// 指定した画像ファイルを、指定した幅と高さで分割してキャッシュします。 /// </summary> /// <param name="texture"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns>GraphicList 辞書のキーである、テクスチャファイル名のハッシュ。</returns> public static Texture2D[] LoadTextures(string texture, int width, int height) { var xNum = TextureWidth / width; var yNum = TextureHeight / height; var hash = texture.GetHashCode(); if (GraphicsList.ContainsKey(hash) && (GraphicsList[hash] != null)) { logger.Info($"Use cached image {hash}"); return(GraphicsList[hash]); } var buf = LoadAndSplit($"Resources/Graphics/{texture}", xNum, yNum, new VectorInt(width, height)); GraphicsList[hash] = buf; if (loadingList.ContainsKey(hash) && (loadingList[hash] != null)) { return(GraphicsList[hash]); } loadingList[hash] = new TextureLoadingInfo(texture, new Size(width, height)); return(GraphicsList[hash]); }
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); bool connectionHere = false; Point h = new Point(-1, -1); GraphicsList gl = drawArea.Pages.GraphicPagesList[drawArea.PageNo]; 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); }
//public Rectangle ROI { get; set; } //--------------init public void init() { //set modes this.FunctionalMode = FunctionalModeOption.Minimum; this.PanableAndZoomable = false; //this.DoubleBuffered = true; this.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; ActiveTool = DrawToolType.Pointer; // create list of graphic objects GraphicsList = new GraphicsList(); // Create undo manager undoManager = new UndoManager(GraphicsList); //init drawing tools initDrawTools(); //init events initEvents(); this.initialized = true; }
// Call this function AFTER operation. public void NewState(GraphicsList graphicsList) { // Keep objects state after operation. FillList(graphicsList, ref listAfter); }
/// <summary> /// /// </summary> /// <param name="graphicsList"></param> public void NewState(GraphicsList graphicsList) { FillList(graphicsList, ref listAfter); }
/// <summary> /// Initialization /// </summary> /// <param name="owner"></param> /// <param name="docManager"></param> public void Initialize(IMainForm owner, DocManager docManager) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); // Keep reference to owner form this.Owner = owner; this.DocManager = docManager; // set default tool activeTool = DrawToolType.Pointer; // create list of graphic objects graphicsList = new GraphicsList(); // Create undo manager undoManager = new UndoManager(graphicsList); // create array of drawing tools tools = new Tool[(int)DrawToolType.NumberOfDrawTools]; tools[(int)DrawToolType.Pointer] = new ToolPointer(); tools[(int)DrawToolType.Rectangle] = new ToolRectangle(); tools[(int)DrawToolType.Ellipse] = new ToolEllipse(); tools[(int)DrawToolType.Line] = new ToolLine(); tools[(int)DrawToolType.Polygon] = new ToolPolygon(); }
// This command is used to make Redo operation. // It makes original command again. //public abstract void Redo(GraphicsList list); public abstract void Redo(GraphicsList Graphics);
public CommandChangeState(GraphicsList graphicsList) : base(graphicsList) { FillList(graphicsList, ref listBefore); }
/// <summary> /// This function is used to make Undo operation. /// It makes action opposite to the original command. /// </summary> /// <param name="list">Graphics list</param> public void Undo(GraphicsList list) { list.DeleteLastAddedObject(); }
public override void Redo(GraphicsList list) { list.UnselectAll(); list.Add(drawObject); }
public CommandCopy(GraphicsList graphiList) : base(graphiList) { }
public Command(GraphicsList graphicsList) { this.graphicsList = graphicsList; }
/// <summary> /// This command is used to make Redo operation. /// It makes original command again. /// </summary> /// <param name="list">Graphics list</param> public void Redo(GraphicsList list) { list.UnselectAll(); list.Add(_drawObject); }
public CommandAdd(GraphicsList graphiList) : base(graphiList) { this.drawObject = (DrawObject)graphicsList[0].Clone(); }
public override void Redo(GraphicsList list) { // Replace all objects in the list with objects from listAfter ReplaceObjects(list, listAfter); }
// Create this command BEFORE operation. public CommandChangeState(GraphicsList graphicsList) { // Keep objects state before operation. FillList(graphicsList, ref listBefore); }
public override void Undo(GraphicsList list) { // Replace all objects in the list with objects from listBefore ReplaceObjects(list, listBefore); }
// This command is used to make Redo operation. // It makes original command again. public abstract void Redo(GraphicsList list);
public override void Redo(GraphicsList list) { // Clear list - make DeleteAll again list.Clear(); }