Exemplo n.º 1
0
        /// <summary>
        /// Lorsqu'un bouton souris est pressé
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainSurface_MouseDown(object sender, MouseEventArgs e)
        {
            //Mode de dessin
            if (EditorHelper.Instance.CurrentStageState >= Enums.StagePanelState.HotSpots && EditorHelper.Instance.CurrentDrawingTool != Enums.DrawingTools.Pointer)
            {
                Point mousePosition = _Service.GetDragStageCoords(this.PointToClient(Cursor.Position));
                //Mode édition
                if (EditorHelper.Instance.SelectedHotSpot != null && EditorHelper.Instance.HotSpotEditionMode)
                {
                    if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                    {
                        if (!_Service.IsOnTheSelectedPolygon(mousePosition, true))
                        {
                            _Service.CreateNewPointToTheCurrentSelectedHotSpot(mousePosition, EditorHelper.Instance.SelectedHotSpot.Points.Length);
                        }
                        MainSurface.Refresh();
                    }
                    else if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
                    {
                        if (_Service.RemovePointOfTheCurrentSelectedHotSpot(mousePosition))
                        {
                            MainSurface.Refresh();
                        }
                    }
                    else
                    {
                        EditorHelper.Instance.SelectedHotSpotPoint = _Service.GetVectorPoint(mousePosition);
                        _MouseDown = true;
                    }
                }
                //Mode création
                else if (EditorHelper.Instance.SelectedHotSpot == null)
                {
                    DeselectStageObjects();
                    switch (EditorHelper.Instance.CurrentStageState)
                    {
                    case Enums.StagePanelState.HotSpots:
                        EditorHelper.Instance.SelectedHotSpot = _Service.CreateHotSpot(mousePosition);
                        break;

                    case Enums.StagePanelState.WalkableAreas:
                        EditorHelper.Instance.SelectedHotSpot = _Service.CreateWalkableArea(mousePosition);
                        break;

                    case Enums.StagePanelState.Regions:
                        EditorHelper.Instance.SelectedHotSpot = _Service.CreateRegion(mousePosition);
                        break;
                    }
                    if (EditorHelper.Instance.SelectedHotSpot != null)
                    {
                        _MouseDown = true;
                        EditorHelper.Instance.SelectedHotSpotPoint = 0;
                        MainSurface.Refresh();
                    }
                }
                else
                {
                    _MouseDown = true;
                }
            }

            //Mode sélection d'objets
            if (EditorHelper.Instance.SelectedObjects.Count > 0)
            {
                Point mousePosition = _Service.GetDragStageCoords(this.PointToClient(Cursor.Position));
                foreach (VO_StageObject vObject in EditorHelper.Instance.SelectedObjects)
                {
                    Rectangle rect = new Rectangle(vObject.Location, vObject.Size);
                    if (rect.IntersectsWith(new Rectangle(mousePosition, new Size(1, 1))))
                    {
                        _MouseDown = true;
                        _Service.StartObjectDrag(e.Location);
                        return;
                    }
                }
            }
        }