示例#1
0
        private void pic_MouseMove(object sender, MouseEventArgs e)
        {
            pointMouse = new Point(e.X, e.Y);

            if (e.Button == System.Windows.Forms.MouseButtons.Middle)
            {
                hScrollBar.Value = Math.Min(hScrollBar.Maximum, Math.Max(hScrollBar.Minimum, prevHScrollValue + (initialPointMouseWithoutDelta.X - pointMouse.X)));
                vScrollBar.Value = Math.Min(valMax, Math.Max(vScrollBar.Minimum, prevVScrollValue + (initialPointMouseWithoutDelta.Y - pointMouse.Y)));

                Common.Delta = new Point(-hScrollBar.Value, valMax - vScrollBar.Value + Common.lineMidScreen.P1.Y);

                DrawScene();
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left && curComponent != null)
            {
                pointMouse.Offset(-Common.Delta.X, -Common.Delta.Y);

                if (curComponent.ModeSelection == ModeSelection.SelectedMove)
                {
                    int gridWidth = 1;
                    int gridHeight = 1;

                    if (btnGrid.Checked)
                    {
                        gridWidth = int.Parse(txtGridWidth.Text);
                        gridHeight = int.Parse(txtGridHeight.Text);
                    }

                    ((IMoveable)curComponent).Location = new Point((prevLocation.X + pointMouse.X - initialPointMouse.X) / gridWidth * gridWidth,
                                                  (prevLocation.Y + pointMouse.Y - initialPointMouse.Y) / gridHeight * gridHeight);

                }
                else if (curComponent.ModeSelection == ModeSelection.SelectedResizeWidth)
                {
                    if (curResizeableWidthComponent != null)
                    {
                        int gridWidth = 1;

                        if (btnGrid.Checked)
                        {
                            gridWidth = int.Parse(txtGridWidth.Text);
                        }

                        curResizeableWidthComponent.Width = (prevWidth + pointMouse.X - initialPointMouse.X) / gridWidth * gridWidth;

                        if (curResizeableWidthComponent.Width <= 0)
                            curResizeableWidthComponent.Width = 1;
                    }
                }
                else if (curComponent.ModeSelection == ModeSelection.SelectedResizeHeight)
                {
                    if (curResizeableHeightComponent != null)
                    {
                        int gridHeight = 1;

                        if (btnGrid.Checked)
                        {
                            gridHeight = int.Parse(txtGridHeight.Text);
                        }

                        curResizeableHeightComponent.Height = (prevHeight + pointMouse.Y - initialPointMouse.Y) / gridHeight * gridHeight; ;

                        if (curResizeableHeightComponent.Height <= 0)
                            curResizeableHeightComponent.Height = 1;
                    }
                }

                //SortCuboid();

                //CalcCuboidIntersections();

                CalcFoldingIntersections();

                DrawScene();
            }
            //--- Calcul des poignées de redimensionnement
            else if (e.Button == System.Windows.Forms.MouseButtons.None)// && Common.CurrentTool == Tools.None)
            {
                int distanceNearestCuboid = int.MaxValue;
                nearestCuboid = null;
                ModeSelection nearestModeSelection = ModeSelection.None;

                List<ComponentBase> listComponentForMove = new List<ComponentBase>();
                List<ComponentBase> listComponentForHResize = new List<ComponentBase>();
                List<ComponentBase> listComponentForWResize = new List<ComponentBase>();

                foreach (ComponentBase component in scene.listComponent)
                {
                    if (component != curComponent)
                        component.ModeSelection = ModeSelection.None;
                    else
                        component.ModeSelection = ModeSelection.Selected;

                    //--- Distance move
                    if (component.RectangleSelection.Contains(pointMouse))
                        listComponentForMove.Add(component);
                    //---

                    //--- Distance resize
                    IResizableWidth resizeableWComponent = component as IResizableWidth;
                    IResizableHeight resizeableHComponent = component as IResizableHeight;

                    if (resizeableWComponent != null)
                    {
                        float distance = float.MaxValue / 2f;

                        //--- Calcul la distance du point à chaque segment limite de redimensionnement
                        foreach (Line lineResizeLimit in resizeableWComponent.LineResizableWidth)
                        {
                            distance = Utils.DistancePaAB(pointMouse, lineResizeLimit.P1, lineResizeLimit.P2);

                            if (distance < 10 && distance < distanceNearestCuboid)
                                listComponentForWResize.Add(component);
                        }
                    }

                    if (resizeableHComponent != null)
                    {
                        float distance = float.MaxValue / 2f;

                        //--- Calcul la distance du point à chaque segment limite de redimensionnement
                        foreach (Line lineResizeLimit in resizeableHComponent.LineResizableHeight)
                        {
                            distance = Utils.DistancePaAB(pointMouse, lineResizeLimit.P1, lineResizeLimit.P2);

                            if (distance < 10 && distance < distanceNearestCuboid)
                                listComponentForHResize.Add(component);
                        }
                    }
                    //---
                }

                //--- Sélection NearMove
                int localLevelSearch = curLevelSearch;

                if (listComponentForMove.Count - 1 < curLevelSearch && listComponentForMove.Count > 0)
                    localLevelSearch = listComponentForMove.Count - 1;

                if (listComponentForMove.Count > localLevelSearch)
                {
                    nearestCuboid = listComponentForMove[localLevelSearch];
                    nearestModeSelection = ModeSelection.NearMove;
                }
                //---

                //--- Sélection NearResizeWidth
                localLevelSearch = curLevelSearch;

                if (listComponentForWResize.Count - 1 < curLevelSearch && listComponentForWResize.Count > 0)
                    localLevelSearch = listComponentForWResize.Count - 1;

                if (listComponentForWResize.Count > localLevelSearch)
                {
                    nearestCuboid = listComponentForWResize[localLevelSearch];
                    nearestModeSelection = ModeSelection.NearResizeWidth;
                }
                //---

                //--- Sélection NearResizeHeight
                localLevelSearch = curLevelSearch;

                if (listComponentForHResize.Count - 1 < curLevelSearch && listComponentForHResize.Count > 0)
                    localLevelSearch = listComponentForHResize.Count - 1;

                if (listComponentForHResize.Count > localLevelSearch)
                {
                    nearestCuboid = listComponentForHResize[localLevelSearch];
                    nearestModeSelection = ModeSelection.NearResizeHeight;
                }
                //---

                if (nearestCuboid != null)
                    nearestCuboid.ModeSelection = nearestModeSelection;

                //if (nearestModeSelection != ModeSelection.None)
                {
                    SortCuboid();

                    DrawScene();
                }

                if (nearestModeSelection == ModeSelection.None)
                    pic.Cursor = Cursors.Default;
                else if (nearestModeSelection == ModeSelection.NearResizeWidth)
                    pic.Cursor = Cursors.SizeWE;
                else if (nearestModeSelection == ModeSelection.NearResizeHeight)
                    pic.Cursor = Cursors.SizeNS;
                else if (nearestModeSelection == ModeSelection.NearMove)
                    pic.Cursor = Cursors.SizeAll;
            }
            //---
        }
示例#2
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //---> Suppression du cuboid courant
            if (e.KeyCode == Keys.Delete && curComponent != null)
            {
                this.scene.listComponent.Remove(curComponent);
                curComponent = null;
                DrawScene();
            }
            else if (e.KeyCode == Keys.X && nearestCuboid != null)
            {
                curLevelSearch++;

                pic_MouseMove(null, new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, pointMouse.X, pointMouse.Y, 0));
            }
            else if (e.KeyCode == Keys.W && nearestCuboid != null)
            {
                if (curLevelSearch > 0)
                    curLevelSearch--;

                pic_MouseMove(null, new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, pointMouse.X, pointMouse.Y, 0));
            }
        }
示例#3
0
        private void pic_MouseDown(object sender, MouseEventArgs e)
        {
            initialPointMouseWithoutDelta = e.Location;
            initialPointMouse = e.Location;
            initialPointMouse.Offset(-Common.Delta.X, -Common.Delta.Y);
            prevVScrollValue = vScrollBar.Value;
            prevHScrollValue = hScrollBar.Value;

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (curComponent != null && curComponent != nearestCuboid)
                {
                    curComponent.ModeSelection = ModeSelection.None;
                    curComponent = null;
                }

                //--- Sélection des éléments pour le déplacement et le redimensionnement
                foreach (ComponentBase component in scene.listComponent)
                {
                    if (component == nearestCuboid && component.ModeSelection == ModeSelection.NearMove)
                    {
                        component.ModeSelection = ModeSelection.SelectedMove;
                        curComponent = component;
                        prevLocation = ((IMoveable)component).Location;
                    }
                    else if (component == nearestCuboid && component.ModeSelection == ModeSelection.NearResizeWidth)
                    {
                        component.ModeSelection = ModeSelection.SelectedResizeWidth;
                        curComponent = component;
                        prevWidth = ((IResizableWidth)component).Width;
                    }
                    else if (component == nearestCuboid && component.ModeSelection == ModeSelection.NearResizeHeight)
                    {
                        component.ModeSelection = ModeSelection.SelectedResizeHeight;
                        curComponent = component;
                        prevHeight = ((IResizableHeight)component).Height;
                    }
                }
                //---

                int gridWidth = int.Parse(txtGridWidth.Text);
                int gridHeight = int.Parse(txtGridHeight.Text);

                //---> Création du pliage
                if (Common.CurrentTool == Tools.Folding && curComponent == null)
                {
                    curComponent = new Folding(initialPointMouse.X, initialPointMouse.Y, gridWidth * 2, 6);
                }

                //---> Création de la zone de pliage H
                if (Common.CurrentTool == Tools.ZoneFoldingH && curComponent == null)
                {
                    curComponent = new ZoneFoldingH(initialPointMouse.X, initialPointMouse.Y, gridHeight * 2);
                }

                //---> Création de la zone de pliage V
                if (Common.CurrentTool == Tools.ZoneFoldingV && curComponent == null)
                {
                    curComponent = new ZoneFoldingV(initialPointMouse.X, initialPointMouse.Y, gridWidth * 2);
                }

                //---> Création de la zone de déplacement H
                if (Common.CurrentTool == Tools.ZoneMovingH && curComponent == null)
                {
                    curComponent = new ZoneMovingH(initialPointMouse.X, initialPointMouse.Y, gridWidth * 3, gridHeight);
                }

                //---> Création de la zone de déplacement V
                if (Common.CurrentTool == Tools.ZoneMovingV && curComponent == null)
                {
                    curComponent = new ZoneMovingV(initialPointMouse.X, initialPointMouse.Y, gridWidth, gridHeight * 3);
                }

                //---> Création de la platforme
                if (Common.CurrentTool == Tools.Platform && curComponent == null)
                {
                    curComponent = new Platform(initialPointMouse.X, initialPointMouse.Y, gridWidth * 3, gridHeight * 2);
                }

                if (Common.CurrentTool == Tools.SensorButton && curComponent == null)
                {
                    curComponent = new Sensor(initialPointMouse.X, initialPointMouse.Y, SensorType.Button);
                }

                if (Common.CurrentTool == Tools.SensorCamera && curComponent == null)
                {
                    curComponent = new Sensor(initialPointMouse.X, initialPointMouse.Y, SensorType.Camera);
                }

                if (Common.CurrentTool == Tools.SensorNearness && curComponent == null)
                {
                    curComponent = new Sensor(initialPointMouse.X, initialPointMouse.Y, SensorType.Nearness);
                }

                if (Common.CurrentTool == Tools.SensorRemoteControl && curComponent == null)
                {
                    curComponent = new Sensor(initialPointMouse.X, initialPointMouse.Y, SensorType.RemoteControl);
                }

                if (Common.CurrentTool == Tools.Hole && curComponent == null)
                {
                    curComponent = new Hole(initialPointMouse.X, initialPointMouse.Y, gridWidth * 3, gridHeight * 3);
                }

                //---> Stockage du nouvel élément
                if (Common.CurrentTool != Tools.None && curComponent != null && curComponent.ModeSelection == ModeSelection.None)
                {
                    prevLocation = ((IMoveable)curComponent).Location;
                    curComponent.ModeSelection = ModeSelection.SelectedMove;
                    curComponent.ColorIndex = Common.CurrentColorIndex;
                    scene.listComponent.Add(curComponent);
                    CalcFoldingIntersections();
                }

                DrawScene();
            }
        }
示例#4
0
        private void pic_MouseUp(object sender, MouseEventArgs e)
        {
            //---> Suppression du cuboid proche
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                for (int i = 0; i < scene.listComponent.Count; i++)
                {
                    if (scene.listComponent[i].ModeSelection == ModeSelection.NearMove)
                    {
                        if (nearestCuboid == scene.listComponent[i])
                            nearestCuboid = null;
                        if (curComponent == scene.listComponent[i])
                            curComponent = null;

                        this.scene.listComponent.RemoveAt(i);
                        i--;
                    }
                }

                CalcFoldingIntersections();
                DrawScene();
            }
        }