Пример #1
0
 // Khởi tạo
 public Shape(shapeType selectedType, int selectedWidth, Color selectedColor)
 {
     type         = selectedType;
     lineWidth    = selectedWidth;
     color        = selectedColor;
     rasterPoints = new List <Point>();
 }
Пример #2
0
 public Form1()
 {
     InitializeComponent();
     timer1.Start();
     shapes              = new List <Shape>();
     currColor           = Color.Red;
     currShape           = shapeType.Circle;
     this.DoubleBuffered = true;
 }
Пример #3
0
 public ShapeData(shapeType t, Vector2 sPos, Transform trans, int numSteps, bool pOwned = true)
 {
     type               = t;
     posArr             = new Vector2[numSteps];
     startPos           = sPos;
     transform          = trans;
     playerOwned        = pOwned;
     failed             = false;
     transform.position = startPos;
 }
Пример #4
0
 public void Init(string imgPathName, shapeType _shapeType = shapeType.Line)
 {
     m_showTxt = "";
     inkCanvasMeasure.Children.Clear();
     viewModel.InkStrokes.Clear();
     GetImgSrcWidth(imgPathName);
     m_ShapeType = _shapeType;
     m_ScreenPointList.Clear();
     imgMeasure.Source = new BitmapImage(new Uri(imgPathName, UriKind.RelativeOrAbsolute));
 }
Пример #5
0
 public Shape(Color userColor, float userWidth, shapeType userType)
 {
     color         = userColor;
     width         = userWidth;
     type          = userType;
     listPoints    = new List <Point>();
     controlPoints = new List <Point>();
     extraPoint    = new Point(-1, -1);
     isColored     = false;
     fillColor     = Color.Black;
     fillPoints    = new List <Point>();
 }
 public void addShape(Point clickLocation, Color color, shapeType type)
 {
     if (type == shapeType.CIRCLE)
     {
         Circle newCircle = new Circle(clickLocation, color, Radius);
         shapes.Add(newCircle);
     }
     else
     {
         Square square = new Square(clickLocation, color, Radius, Radius);
         shapes.Add(square);
     }
 }
Пример #7
0
        public void ShowRect(int x1, int y1, int x2, int y2, string inf)
        {
            m_showTxt   = inf;
            m_ShapeType = shapeType.Rectangle;

            m_imgPtStart.X = x1;
            m_imgPtStart.Y = y1;

            m_imgPtEnd.X = x2;
            m_imgPtEnd.Y = y2;

            PtCombine(ImgToScreenPt(m_imgPtStart), ImgToScreenPt(m_imgPtEnd));
            Draw();
        }
Пример #8
0
 private void squareToolStripMenuItem_Click(object sender, EventArgs e)
 {
     currShape = shapeType.Square;
     circleToolStripMenuItem.Checked = false;
     squareToolStripMenuItem.Checked = true;
 }
Пример #9
0
        //This sets the mouse cursor depending on the mouse location and current operation.
        private shapeType SetMouseCursorShape(MouseEventArgs e, out FrameworkElement theShape)
        {
            theShape = prevShape;

            //if dragging, don't change the cursor but return the hit
            if (currentOperation != CurrentOperation.idle)
            {
                if (currentOperation == CurrentOperation.draggingSynapse)
                {
                    return(shapeType.Synapse);
                }
                if (currentOperation == CurrentOperation.movingModule)
                {
                    return(shapeType.Module);
                }
                if (currentOperation == CurrentOperation.draggingNewSelection)
                {
                    return(shapeType.Selection);
                }
                if (currentOperation == CurrentOperation.insertingModule)
                {
                    return(shapeType.None);
                }
                if (!MainWindow.ctrlPressed)
                {
                    if (currentOperation == CurrentOperation.movingSelection)
                    {
                        return(shapeType.Selection);
                    }
                    if (currentOperation == CurrentOperation.sizingModule)
                    {
                        return(shapeType.Module);
                    }
                }
            }

            //don't change the cursor if dragging, panning
            if (theCanvas.Cursor == Cursors.Hand)
            {
                return(shapeType.None);
            }

            //if busy, make sure the cursor is hourglass
            if (MainWindow.Busy())
            {
                theCanvas.Cursor = Cursors.Wait;
                return(shapeType.None);
            }

            //what type of shape is the mouse  over?
            HitTestResult result = VisualTreeHelper.HitTest(theCanvas, e.GetPosition(theCanvas));

            if (result != null && result.VisualHit is FrameworkElement theShape0)
            {
                theShape = theShape0;

                //Get the type of the hit...

                shapeType st = (shapeType)theShape.GetValue(ShapeType);

                //Set the cursor shape based on the type of object the mouse is over
                switch (st)
                {
                case shapeType.None:
                    theCanvas.Cursor = Cursors.Cross;
                    st = shapeType.Canvas;
                    break;

                case shapeType.Synapse:
                    theCanvas.Cursor = Cursors.Arrow;
                    break;

                case shapeType.Neuron:
                    theCanvas.Cursor = Cursors.UpArrow;
                    break;

                case shapeType.Module:     //for a module, set directional stretch arrow cursors
                    if (!MainWindow.ctrlPressed)
                    {
                        theCanvas.Cursor = Cursors.ScrollAll;
                        SetScrollCursor(e.GetPosition(this), theShape);
                    }
                    else     //ctrl pressed
                    {
                        theCanvas.Cursor = Cursors.Cross;
                        st = shapeType.Canvas;
                    }
                    break;

                case shapeType.Selection:     //TODO add directional arrow code
                    theCanvas.Cursor = Cursors.ScrollAll;
                    break;
                }
                prevShape = theShape;
                return(st);
            }
            //mouse is not over anything
            theCanvas.Cursor = Cursors.Cross;
            return(shapeType.Canvas);
        }
Пример #10
0
        public void theCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (MainWindow.theNeuronArray == null)
            {
                return;
            }
            Point currentPosition    = e.GetPosition(theCanvas);
            Point nonlimitedPosition = currentPosition;

            LimitMousePostion(ref currentPosition);
            int currentNeuron = dp.NeuronFromPoint(currentPosition);

            shapeType theShapeType = SetMouseCursorShape(e, out FrameworkElement theShape);

            if (MainWindow.Busy())
            {
                return;
            }

            if (mouseRepeatTimer != null)
            {
                if (mouseRepeatTimer.IsEnabled && mouseRepeatTimer.Interval == new TimeSpan(0, 0, 0, 0, 100))
                {
                    return;
                }
                mouseRepeatTimer.Stop();
            }

            if (MainWindow.IsArrayEmpty())
            {
                return;
            }

            //You can't do any dragging with the right mouse button
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }


            //update the status bar
            if (currentPosition == nonlimitedPosition)
            {
                int    y1          = currentNeuron % Rows;
                int    x1          = currentNeuron / Rows;
                string mouseStatus = "ID: " + currentNeuron + "  Row: " + y1 + " Col: " + x1;
                foreach (ModuleView mv in MainWindow.theNeuronArray.modules)
                {
                    if (currentNeuron >= mv.FirstNeuron && currentNeuron <= mv.LastNeuron)
                    {
                        mv.GetNeuronLocation(currentNeuron, out int x, out int y);
                        mouseStatus += "  " + mv.Label + "(" + x + "," + y + ")";
                    }
                }
                MainWindow.thisWindow.SetStatus(1, mouseStatus, 0);
            }
            else
            {
                MainWindow.thisWindow.SetStatus(1, "Mouse outside neuron array", 1);
            }


            if (e.LeftButton == MouseButtonState.Pressed)
            {
                string oString = (theShape == null) ? "null" : theShape.ToString();
                //Debug.WriteLine("MouseMove  currentNeuron: " + currentNeuron
                //    + " Shape type: " + theShapeType.ToString() + " theShape: " + oString);

                //are we dragging a synapse? rubber-band it
                if ((theCanvas.Cursor == Cursors.Arrow || theCanvas.Cursor == Cursors.UpArrow) &&
                    currentOperation == CurrentOperation.draggingSynapse)
                {
                    DragSynapse(currentNeuron);
                }

                //handle the creation/updating of a dragging selection rectangle
                else if ((theShapeType == shapeType.None || theShapeType == shapeType.Selection) &&
                         currentOperation == CurrentOperation.draggingNewSelection)
                {
                    DragNewSelection(currentNeuron);
                }

                //handle moving an existing  selection
                else if (theShapeType == shapeType.Selection &&
                         theCanvas.Cursor == Cursors.ScrollAll)
                {
                    MoveSelection(currentNeuron);
                }

                //handle moving of a module
                else if (theShapeType == shapeType.Module && currentOperation == CurrentOperation.movingModule)
                {
                    MoveModule(theShape, currentNeuron);
                }

                //handle sizing of a module
                else if (theShapeType == shapeType.Module && currentOperation == CurrentOperation.sizingModule)
                {
                    ResizeModule(theShape, currentNeuron);
                }

                else if (theCanvas.Cursor == Cursors.Hand)
                {
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        ContinuePan(e.GetPosition((UIElement)theCanvas.Parent));
                        //lastPositionOnGrid = e.GetPosition((UIElement)theCanvas.Parent);
                    }
                    else
                    {
                        lastPositionOnCanvas = new Point(0, 0);
                    }
                }
            }    //end of Left-button down
            else //no button pressed
            {
                //handle the special case of no mouse cursor we must be inserting a module inserting a module
                //it's the only thing we drag without a button press
                if (currentOperation == CurrentOperation.insertingModule)
                {
                    DragInsertingModule(currentNeuron);
                }
                else
                {
                    currentOperation = CurrentOperation.idle;
                }
            }
        }
Пример #11
0
        public void theCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            //set the cursor before checking for busy so the wait cursor can be set
            shapeType theShapeType = SetMouseCursorShape(e, out FrameworkElement theShape);

            if (MainWindow.Busy())
            {
                return;
            }

            if (MainWindow.theNeuronArray == null)
            {
                return;
            }
            MainWindow.theNeuronArray.SetUndoPoint();
            Debug.WriteLine("theCanvas_MouseDown" + MainWindow.theNeuronArray.Generation + theShape + theShapeType);
            Point currentPosition = e.GetPosition(theCanvas);

            LimitMousePostion(ref currentPosition);
            mouseDownNeuronIndex = dp.NeuronFromPoint(currentPosition);

            if (e.RightButton == MouseButtonState.Pressed)
            {
                if (sender is Image img) //TODO: fix this, it should be a selection hit
                {
                    int        i  = (int)img.GetValue(ModuleView.AreaNumberProperty);
                    int        i1 = -i - 1;
                    ModuleView nr = new ModuleView
                    {
                        Label         = "new",
                        Width         = theSelection.selectedRectangles[i1].Width,
                        Height        = theSelection.selectedRectangles[i1].Height,
                        Color         = Utils.ColorToInt(Colors.Aquamarine),
                        ModuleTypeStr = ""
                    };
                    img.ContextMenu = new ContextMenu();
                    ModuleView.CreateContextMenu(i, nr, img, img.ContextMenu);
                    img.ContextMenu.IsOpen = true;
                }
                else if (theShapeType == shapeType.Neuron)
                {
                    OpenNeuronContextMenu(theShape);
                }
                else if (theShapeType == shapeType.Synapse)
                {
                    OpenSynapseContextMenu(theShape);
                }
                else if (theShapeType == shapeType.Selection)
                {
                    OpenSelectionContextMenu(theShape);
                }
                else if (theShapeType == shapeType.Module)
                {
                    OpenModuleContextMenu(theShape);
                }
                return;
            } //end of right-button pressed

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (theShapeType == shapeType.Neuron)
                {
                    Neuron n = null;
                    if (mouseDownNeuronIndex >= 0 && mouseDownNeuronIndex < MainWindow.theNeuronArray.arraySize)
                    {
                        n = MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex) as Neuron;
                    }

                    int clickCount = e.ClickCount;
                    n = NeuronMouseDown(n, clickCount);
                }

                if (theShapeType == shapeType.Synapse)
                {
                    StartSynapseDragging(theShape);
                }

                //start a new selection rectangle drag
                if (theShapeType == shapeType.Canvas && labelCursor == null)
                {
                    currentPosition = StartNewSelectionDrag();
                }

                //either a module or a selection, we're dragging it
                if (theShapeType == shapeType.Module && theCanvas.Cursor == Cursors.ScrollAll)
                {
                    StartaMovingModule(theShape, mouseDownNeuronIndex);
                }
                if (theShapeType == shapeType.Module && theCanvas.Cursor != Cursors.ScrollAll)
                {
                    StartaSizingModule(theShape, mouseDownNeuronIndex);
                }

                if (theShapeType == shapeType.Selection)
                {
                    StartMovingSelection(theShape);
                }
                //starting pan
                if (theCanvas.Cursor == Cursors.Hand)
                {
                    StartPan(e.GetPosition((UIElement)theCanvas.Parent));
                }
                if (currentOperation == CurrentOperation.insertingModule)
                {
                    InsertModule(mouseDownNeuronIndex);
                    Mouse.Capture(null);
                }
                else
                {
                    Mouse.Capture(theCanvas); //if you don't do this, you might lose the mouseup event
                }
            }//end of left-button down
        }
Пример #12
0
        //This sets the mouse cursor depending on the mouse location and current operation.
        private shapeType SetMouseCursorShape(MouseEventArgs e, out FrameworkElement theShape)
        {
            theShape = prevShape;

            //if dragging, don't change the cursor but return the hit
            if (currentOperation != CurrentOperation.idle)
            {
                if (currentOperation == CurrentOperation.draggingSynapse)
                {
                    return(shapeType.Synapse);
                }
                if (currentOperation == CurrentOperation.movingModule)
                {
                    return(shapeType.Module);
                }
                if (currentOperation == CurrentOperation.draggingNewSelection)
                {
                    return(shapeType.Selection);
                }
                if (currentOperation == CurrentOperation.movingSelection)
                {
                    return(shapeType.Selection);
                }
                if (currentOperation == CurrentOperation.sizingModule)
                {
                    return(shapeType.Module);
                }
            }

            //don't change the cursor if dragging, panning
            if (theCanvas.Cursor == Cursors.Hand)
            {
                return(shapeType.None);
            }

            //if busy, make sure the cursor is hourglass
            if (MainWindow.Busy())
            {
                theCanvas.Cursor = Cursors.Wait;
                return(shapeType.None);
            }

            //what type of shape is the mouse  over?
            HitTestResult result = VisualTreeHelper.HitTest(theCanvas, e.GetPosition(theCanvas));

            if (result.VisualHit is FrameworkElement theShape0)
            {
                //When you put a Label into a Canvas, you get a hit back on the internal TextBlock
                //or its border
                //So you need to dig up the parent in order to get the original Label
                theShape = theShape0;
                if (theShape0 is TextBlock)
                {
                    ContentPresenter x = (ContentPresenter)VisualTreeHelper.GetParent(result.VisualHit);
                    theShape = (Label)x.TemplatedParent;
                }
                if (theShape0 is Border l)
                {
                    theShape = (Label)VisualTreeHelper.GetParent(result.VisualHit);
                }

                //Get the type of the hit...
                shapeType st = (shapeType)theShape.GetValue(ShapeType);

                //Set the cursor shape based on the type of object the mouse is over
                switch (st)
                {
                case shapeType.None:
                    theCanvas.Cursor = Cursors.Cross;
                    st = shapeType.Canvas;
                    break;

                case shapeType.Synapse:
                    theCanvas.Cursor = Cursors.Arrow;
                    break;

                case shapeType.Neuron:
                    theCanvas.Cursor = Cursors.UpArrow;
                    break;

                case shapeType.Module:     //for a module, set directional stretch arrow cursors
                    theCanvas.Cursor = Cursors.ScrollAll;
                    SetScrollCursor(e.GetPosition(this), theShape);
                    break;

                case shapeType.Selection:     //TODO add directional arrow code
                    theCanvas.Cursor = Cursors.ScrollAll;
                    break;
                }
                prevShape = theShape;
                return(st);
            }
            //mouse is not over anything
            theCanvas.Cursor = Cursors.Cross;
            return(shapeType.Canvas);
        }
Пример #13
0
 protected CHitShape(shapeType shape, Vector2 position)
 {
     _shape        = shape;
     this.position = position;
 }
 public ShapeList()
 {
     shapes = new List <Shape>();
     type   = shapeType.CIRCLE;
 }
Пример #15
0
 protected CHitShape(shapeType shape, Vector2 position)
 {
     _shape = shape;
     this.position = position;
 }