KBS2.Controls.BlueprintPanel.OnMouseDown C# (CSharp) 메소드

OnMouseDown() 보호된 메소드

protected OnMouseDown ( MouseEventArgs e ) : void
e MouseEventArgs
리턴 void
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if(this.ActiveBlueprint == null) return;

            if(e.Button.HasFlag(MouseButtons.Right)) {
                this.LoadContextMenu();
            } else if(e.Button.HasFlag(MouseButtons.Middle)) {
                //Panning
                if(Control.ModifierKeys.HasFlag(Keys.Control)) {
                    this.Size = new Size(this.Parent.ClientSize.Width - 10, this.Parent.ClientSize.Height - 35);
                    this._center = new PointF(this.Size.Width/2, this.Size.Height/2);
                    this.Invalidate();
                } else {
                    this._panOrigin = e.Location;
                }
                return;
            } else if(this._editMode && e.Button.HasFlag(MouseButtons.Left)) {
                if(this._status == Status.CreateCorner) {
                    //New corner
                    PointF mouseLoc = this.PointToClient(Cursor.Position);
                    PointF mouseOffset = new PointF(mouseLoc.X-this._center.X, mouseLoc.Y-this._center.Y);
                    Corner newCorner = new Corner(mouseOffset);
                    if(this._currentRoom != null) {
                        this._currentRoom.AddCorner(newCorner);
                        this._status = Status.CreateRoom;
                        if(this.SelectedCorner != null) {
                            Wall newWall = new Wall(newCorner, this.SelectedCorner);
                            newCorner.AddWall(newWall);
                            this.SelectedCorner.AddWall(newWall);
                        }
                    }
                    this.Cursor = Cursors.Default;
                    this.SelectedCorner = newCorner;
                    this.Invalidate();
                } else if(this._status == Status.ConnectCorners) {
                    //Connect 2 corners
                    PointF mouseLoc = this.PointToClient(Cursor.Position);
                    PointF mouseOffset = new PointF(mouseLoc.X-this._center.X, mouseLoc.Y-this._center.Y);
                    Corner otherCorner = this.ActiveBlueprint.GetCornerAtPoint(mouseOffset, this.Renderer.CornerSizeEdit);
                    if(this.SelectedCorner != null && otherCorner != null && !this.SelectedCorner.Equals(otherCorner)) {
                        Wall newWall = new Wall(otherCorner, this.SelectedCorner);
                        otherCorner.AddWall(newWall);
                        this.SelectedCorner.AddWall(newWall);
                        this._status = (this._currentRoom != null ? Status.CreateRoom : Status.None);
                        if(this._currentRoom != null){
                            if(this._currentRoom.GetCorners().Contains(this.SelectedCorner)
                            && !this._currentRoom.GetCorners().Contains(otherCorner)) {
                                this._currentRoom.AddCorner(otherCorner);
                            } else if(this._currentRoom.GetCorners().Contains(otherCorner)
                            && !this._currentRoom.GetCorners().Contains(this.SelectedCorner)) {
                                this._currentRoom.AddCorner(this.SelectedCorner);
                            }
                        }
                        this.Cursor = Cursors.Default;
                    }
                } else {
                    //Selects
                    if(this.SelectedCorner != null) this.SelectedCorner.SaveChanges = true;
                    if(this.SelectedWall != null) this.SelectedWall.SaveChanges = true;

                    int? state = ((int?)this.SelectedRoom?.GetID() ?? -1) + ((int?)this.SelectedCorner?.GetID() ?? -1) + ((int?)this.SelectedWall?.GetID() ?? -1);
                    this.SelectedRoom = this.HoveredRoom;
                    this.SelectedCorner = this.HoveredCorner;
                    this.SelectedWall = this.HoveredWall;
                    int? newState = ((int?)this.SelectedRoom?.GetID() ?? -1) + ((int?)this.SelectedCorner?.GetID() ?? -1) + ((int?)this.SelectedWall?.GetID() ?? -1);

                    if(this.SelectedCorner != null) {
                        if(this._status == Status.CreateRoomSelect) {
                            this._currentRoom.GetCorners().Add(this.SelectedCorner);
                            this._status = Status.CreateRoom;
                        } else {
                            this.SelectedCorner.SaveChanges = false;
                            this._movingCorner = true;
                        }
                    }
                    if(this.SelectedWall != null) this.SelectedWall.SaveChanges = false;

                    if(state != newState) this.Invalidate();
                }
            }
        }