Ejemplo n.º 1
0
        private void OnMainWindowKeyUp(object sender, KeyEventArgs e)
        {
            // Set the IsSpec property to false if the shift buttin is not being held any more
            if (e.KeyCode == Keys.ShiftKey)
            {
                IsSpec = false;
            }
            else if (State == PadStates.DrawingShape && SelectedShapeType == SelectedShapeType.Polygon &&
                     (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Enter))
            {
                // When drawing a polygon, the user can finish by pressing the enter or esc keys as oppse to clicking up like with other shapes
                if (CurrentPolygonLine != null)
                {
                    Panel.Shapes.Remove(CurrentPolygonLine);
                }
                if (OriginMarker != null)
                {
                    Panel.Shapes.Remove(OriginMarker);
                }

                // Add new polygon to list
                ListViewItem item = new ListViewItem(Convert.ToString(CurrentShape.ID));
                item.SubItems.Add("Polygon");
                item.SubItems.Add(SelectedColor.ToString().Split('[')[1].Split(']')[0]);
                item.SubItems.Add(((LineCompositeShape)CurrentShape).Origin.X + "," + ((LineCompositeShape)CurrentShape).Origin.Y);
                ShapesLv.Items.Add(item);

                // Go back to ready to draw
                CurrentShape       = null;
                CurrentPolygonLine = null;
                OriginMarker       = null;
                State = PadStates.ReadyToDraw;
                Panel.Invalidate(); // Clear the temp line drawn for the polygon since it is now null
            }
            else if (e.KeyCode == Keys.M)
            {
                // M is a hot key for toggling the mode
                ToggleMode();
            }
            else if (e.KeyCode == Keys.ControlKey)
            {
                IsCtrlKeyHeld = false;
            }
        }
Ejemplo n.º 2
0
 // Toggles the operating mode between drawing and selecting
 private void ToggleMode()
 {
     if (State == PadStates.DrawingShape)
     {
         return; // Can't toggle modes while drawing
     }
     else if (State == PadStates.ReadyToDraw)
     {
         State        = PadStates.Selecting;
         ModeLbl.Text = SelectingModeDisplay;
         ShowHelpText();
     }
     else if (State == PadStates.Selecting)
     {
         State        = PadStates.ReadyToDraw;
         ModeLbl.Text = DrawingModeDisplay;
         ShowHelpText();
     }
 }
Ejemplo n.º 3
0
        private void OnPanelMouseDown(object sender, MouseEventArgs e)
        {
            switch (State)
            {
            case PadStates.ReadyToDraw:
                // Set the initial points and let mouse move handle actually drawing the shape
                x0    = e.X;
                y0    = e.Y;
                State = PadStates.DrawingShape;
                break;

            case PadStates.Selecting:
                if (SelectedShapes.Count != 0)
                {
                    State            = PadStates.Moving;
                    OldMouseLocation = e.Location;
                }
                break;
            }
        }
Ejemplo n.º 4
0
 private void OnShapeSelectorCbIndexChanged(object sender, EventArgs e)
 {
     // Change the selected shape property based on the new value of the combo box. Assume user wants to draw a shape now.
     if (ShapeSelectorCb.SelectedIndex == (int)ShapeSelectorCbSelectedIndex.Rectangle)
     {
         SelectedShapeType = SelectedShapeType.Rectangle;
         State             = PadStates.ReadyToDraw;
         ModeLbl.Text      = DrawingModeDisplay;
         ShowHelpText();
     }
     else if (ShapeSelectorCb.SelectedIndex == (int)ShapeSelectorCbSelectedIndex.Ellipse)
     {
         SelectedShapeType = SelectedShapeType.Ellipse;
         State             = PadStates.ReadyToDraw;
         ModeLbl.Text      = DrawingModeDisplay;
         ShowHelpText();
     }
     else if (ShapeSelectorCb.SelectedIndex == (int)ShapeSelectorCbSelectedIndex.Line)
     {
         SelectedShapeType = SelectedShapeType.Line;
         State             = PadStates.ReadyToDraw;
         ModeLbl.Text      = DrawingModeDisplay;
         ShowHelpText();
     }
     else if (ShapeSelectorCb.SelectedIndex == (int)ShapeSelectorCbSelectedIndex.Polygon)
     {
         SelectedShapeType = SelectedShapeType.Polygon;
         State             = PadStates.ReadyToDraw;
         ModeLbl.Text      = DrawingModeDisplay;
         ShowHelpText();
     }
     else if (ShapeSelectorCb.SelectedIndex == (int)ShapeSelectorCbSelectedIndex.FreeHand)
     {
         SelectedShapeType = SelectedShapeType.FreeHand;
         State             = PadStates.ReadyToDraw;
         ModeLbl.Text      = DrawingModeDisplay;
         ShowHelpText();
     }
 }
Ejemplo n.º 5
0
        private void OnPanelMouseUp(object sender, MouseEventArgs e)
        {
            switch (State)
            {
            case PadStates.DrawingShape:
                if (SelectedShapeType == SelectedShapeType.Polygon)
                {
                    // Mouse up is when we add the current line to the polygon and set the new origin points
                    if (CurrentShape == null)
                    {
                        if (CurrentPolygonLine == null)
                        {
                            // There is no line yet (it is still being made, this can happen when the user clicks down and up quickly without moving the mouse)
                            // This allows user to start a polygon with a drag or a click.
                            return;
                        }
                        // There is no polygon yet so create it and add it to the panel
                        CurrentShape    = new LineCompositeShape(CurrentPolygonLine.p0, CurrentPolygonLine.p1, new Pen(SelectedColor));
                        CurrentShape.ID = ID++;
                        Panel.Shapes.Remove(CurrentPolygonLine);
                        Panel.Shapes.Add(CurrentShape);
                        x0 = CurrentPolygonLine.p1.X;
                        y0 = CurrentPolygonLine.p1.Y;
                        Panel.Invalidate();
                    }
                    else
                    {
                        // There is already a polygon in the panel so just add the current line to it
                        ((LineCompositeShape)CurrentShape).AddLine(CurrentPolygonLine.p1);
                        Panel.Shapes.Remove(CurrentPolygonLine);
                        x0 = CurrentPolygonLine.p1.X;
                        y0 = CurrentPolygonLine.p1.Y;
                        Panel.Invalidate();
                    }
                }
                else
                {
                    // The shape is not a polygon so it is done being drawn and is already in Shapes so just add it to the ListView of Shapes
                    ListViewItem item = new ListViewItem(Convert.ToString(CurrentShape.ID));
                    switch (SelectedShapeType)
                    {
                    case SelectedShapeType.Rectangle:
                        item.SubItems.Add("Rectangle");
                        item.SubItems.Add(SelectedColor.ToString().Split('[')[1].Split(']')[0]);
                        item.SubItems.Add(((RectangleBasedShape)CurrentShape).x0 + "," + ((RectangleBasedShape)CurrentShape).y0);
                        ShapesLv.Items.Add(item);
                        break;

                    case SelectedShapeType.Ellipse:
                        item.SubItems.Add("Ellipse");
                        item.SubItems.Add(SelectedColor.ToString().Split('[')[1].Split(']')[0]);
                        item.SubItems.Add(((RectangleBasedShape)CurrentShape).x0 + "," + ((RectangleBasedShape)CurrentShape).y0);
                        ShapesLv.Items.Add(item);
                        break;

                    case SelectedShapeType.Line:
                        item.SubItems.Add("Line");
                        item.SubItems.Add(SelectedColor.ToString().Split('[')[1].Split(']')[0]);
                        item.SubItems.Add(((Line)CurrentShape).p0.X + "," + ((Line)CurrentShape).p0.Y);
                        ShapesLv.Items.Add(item);
                        break;

                    case SelectedShapeType.FreeHand:
                        item.SubItems.Add("Free-Hand");
                        item.SubItems.Add(SelectedColor.ToString().Split('[')[1].Split(']')[0]);
                        item.SubItems.Add(((LineCompositeShape)CurrentShape).Origin.X + "," + ((LineCompositeShape)CurrentShape).Origin.Y);
                        ShapesLv.Items.Add(item);
                        break;
                    }

                    //Set the current shape to null and go back to ready.
                    CurrentShape = null;
                    State        = PadStates.ReadyToDraw;
                }
                break;

            case PadStates.Moving:
                State = PadStates.Selecting;
                break;
            }
        }