Example #1
0
 /// <summary>
 /// Copy fields from this instance to cloned instance drawObject.
 /// Called from Clone functions of derived classes.
 /// </summary>
 protected void FillDrawObjectFields(DrawObject drawObject)
 {
     drawObject.selected   = this.selected;
     drawObject.color      = this.color;
     drawObject.penWidth   = this.penWidth;
     drawObject.ID         = this.ID;
     drawObject._brushType = this._brushType;
     drawObject._penType   = this._penType;
     drawObject.drawBrush  = this.drawBrush;
     drawObject.drawpen    = this.drawpen;
     drawObject.fillColor  = this.fillColor;
 }
Example #2
0
		/// <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;
			if(drawArea.TheLayers[al].Graphics != null)
				drawArea.TheLayers[al].Graphics.UnselectAll();

			o.Selected = true;
			o.Dirty = true;
			drawArea.TheLayers[al].Graphics.Add(o);

			drawArea.Capture = true;
			drawArea.Refresh();
		}
Example #3
0
        /// <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;

            if (drawArea.TheLayers[al].Graphics != null)
            {
                drawArea.TheLayers[al].Graphics.UnselectAll();
            }

            o.Selected = true;
            o.Dirty    = true;
            drawArea.TheLayers[al].Graphics.Add(o);

            drawArea.Capture = true;
            drawArea.Refresh();
        }
Example #4
0
        /// <summary>
        /// Returns -1, 0, +1 to represent the relative order of the object being compared with this object
        /// </summary>
        /// <param name="obj">DrawObject being compared</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.ZOrder == this.ZOrder)
            {
                x = 0;
            }
            else if (d.ZOrder > this.ZOrder)
            {
                x = -1;
            }
            else
            {
                x = 1;
            }

            return(x);
        }
Example #5
0
        // 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);
                }
            }
        }
Example #6
0
		/// <summary>
		/// Copy fields from this instance to cloned instance drawObject.
		/// Called from Clone functions of derived classes.
		/// </summary>
		protected void FillDrawObjectFields(DrawObject drawObject)
		{
			drawObject.selected = this.selected;
			drawObject.color = this.color;
			drawObject.penWidth = this.penWidth;
			drawObject.ID = this.ID;
			drawObject._brushType = this._brushType;
			drawObject._penType = this._penType;
			drawObject.drawBrush = this.drawBrush;
			drawObject.drawpen = this.drawpen;
			drawObject.fillColor = this.fillColor;
		}
Example #7
0
		/// <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();
		}
Example #8
0
		/// <summary>
		/// Right mouse button is released
		/// </summary>
		/// <param name="drawArea"></param>
		/// <param name="e"></param>
		public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
		{
			int al = drawArea.TheLayers.ActiveLayerIndex;
			if (selectMode == SelectionMode.NetSelection)
			{
				// Group selection
				drawArea.TheLayers[al].Graphics.SelectInRectangle(drawArea.NetRectangle);

				selectMode = SelectionMode.None;
				drawArea.DrawNetRectangle = false;
			}

			if (resizedObject != null)
			{
				// after resizing
				resizedObject.Normalize();
				resizedObject = null;
			}

			drawArea.Capture = false;
			drawArea.Refresh();

			if (commandChangeState != null && wasMove)
			{
				// Keep state after moving/resizing and add command to history
				commandChangeState.NewState(drawArea.TheLayers);
				drawArea.AddCommandToHistory(commandChangeState);
				commandChangeState = null;
			}
			lastPoint = drawArea.BackTrackMouse(e.Location);
		}
Example #9
0
		/// <summary>
		/// Replace object in specified place.
		/// Used for Undo.
		/// </summary>
		public void Replace(int index, DrawObject obj)
		{
			if (index >= 0 && index < graphicsList.Count)
			{
				graphicsList.RemoveAt(index);
				graphicsList.Insert(index, obj);
			}
		}
Example #10
0
		public void Add(DrawObject obj)
		{
			graphicsList.Sort();
			foreach(DrawObject o in graphicsList)
				o.ZOrder++;

			graphicsList.Insert(0, obj);
		}
Example #11
0
        /// <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();
        }
Example #12
0
 // Create this command with DrawObject instance added to the list
 public CommandAdd(DrawObject drawObject) : base()
 {
     // Keep copy of added object
     this.drawObject = drawObject.Clone();
 }
Example #13
0
 // Create this command with DrawObject instance added to the list
 public CommandAdd(DrawObject drawObject) : base()
 {
     // Keep copy of added object
     this.drawObject = drawObject.Clone();
 }
Example #14
0
        /// <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));
            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();

            // Show context menu.
            // Make ugly trick which saves a lot of code.
            // Get menu items from Edit menu in main form and
            // make context menu from them.
            // These menu items are handled in the parent form without
            // any additional efforts.

            //MainMenu mainMenu = Owner.Menu;    // Main menu
            //MenuItem editItem = mainMenu.MenuItems[1];            // Edit submenu

            //// Make array of items for ContextMenu constructor
            //// taking them from the Edit submenu
            //MenuItem[] items = new MenuItem[editItem.MenuItems.Count];

            //for ( int i = 0; i < editItem.MenuItems.Count; i++ )
            //{
            //    items[i] = editItem.MenuItems[i];
            //}

            //Owner.SetStateOfControls();  // enable/disable menu items

            //// Create and show context menu
            //ContextMenu menu = new ContextMenu(items);
            //menu.Show(this, point);

            //// Restore items in the Edit menu (without this line Edit menu
            //// is empty after forst right-click)
            //editItem.MergeMenu(menu);
        }