/** * Voegt een deur toe (dmv het inkleuren van een grid point) */ private void AddDoor(Frame frame, Position position = null) { Position pos = position ?? new Position(frame.X, frame.Y); if (!RectangleDictionary.ContainsKey(pos) && frame.Type == FrameTypes.Door) { return; } RectangleDictionary[pos].Fill = Brushes.Brown; RectangleDictionary[pos].Opacity = 1.0; }
/** * Kleurt alle grid points opnieuw in op basis van de opgeslagen punten */ public void PaintRoom() { foreach (Position pos in Points) { if (SelectedPoints.Contains(pos)) { RectangleDictionary[pos].Fill = Brushes.DarkMagenta; RectangleDictionary[pos].Opacity = 1; } else if (BorderPoints.Contains(pos)) { RectangleDictionary[pos].Fill = Brushes.DarkMagenta; RectangleDictionary[pos].Opacity = 0.5; } else { RectangleDictionary[pos].Fill = Brushes.White; RectangleDictionary[pos].Opacity = 1; } } foreach (Position pos in Points) { if (FramePoints.Exists(p => p.X == pos.X && p.Y == pos.Y)) { // Zet de kleuren van de frames op basis van de types Frame frameFound = FramePoints.Where(p => p.X == pos.X && p.Y == pos.Y).First(); if (frameFound != null && frameFound.Type == FrameTypes.Door) { RectangleDictionary[pos].Fill = Brushes.Brown; if (frameFound.AttachedPosition != null && RectangleDictionary.ContainsKey(frameFound.AttachedPosition)) { RectangleDictionary[frameFound.AttachedPosition].Fill = Brushes.Brown; } } else if (frameFound.Type == FrameTypes.Window) { RectangleDictionary[pos].Fill = Brushes.DarkBlue; } RectangleDictionary[pos].Opacity = 1; } } }
/** * Roteert de deur op basis van een angle en xy coordinaten, kleurt vervolgens de point in die bij de deur hoort */ public void RotateDoor(int angle, int x, int y) { if (_activeFrame != null) { Position doorOpenPos = CalculateNextPositionFromAngle(angle, x, y); if (!FramePoints.Contains(_activeFrame)) { _activeFrame.AttachedPosition = doorOpenPos; // Als de positie niet in de editor bestaat wordt er niks ingekleurd if (RectangleDictionary.ContainsKey(doorOpenPos)) { RectangleDictionary[doorOpenPos].Fill = Brushes.Brown; } } } }
/** * Mousemove event gebruikt om room placements te plaatsen en voor het hoveren van grid points */ public void MouseMove(object sender, MouseEventArgs e) { Point mousePosition = e.GetPosition(Editor); int y = (int)(mousePosition.Y - mousePosition.Y % 25); int x = (int)(mousePosition.X - mousePosition.X % 25); Position point = new Position(x, y); // Sets hovered item (simplistic version of a hover) if (_selectedPosition != null && RectangleDictionary.ContainsKey(_selectedPosition) && !OnBorder(_selectedPosition)) { RectangleDictionary[_selectedPosition].Fill = Brushes.White; } if (RectangleDictionary.ContainsKey(point) && RectangleDictionary[point].Fill == Brushes.White && !OnBorder(point)) { _selectedPosition = point; RectangleDictionary[point].Fill = Brushes.Bisque; } // Als de vorige positie is gezet wordt dit vervangen door de standaard kleur if (_previousCanvasPosition != null && !FramePoints.Exists( p => p.X == _previousCanvasPosition.X && p.Y == _previousCanvasPosition.Y )) { RectangleDictionary[_previousCanvasPosition].Fill = Brushes.DarkMagenta; RectangleDictionary[_previousCanvasPosition].Opacity = 0.5; if (_activeFrame != null && _activeFrame.AttachedPosition != null && RectangleDictionary.ContainsKey(_activeFrame.AttachedPosition)) { RectangleDictionary[_activeFrame.AttachedPosition].Fill = Brushes.White; int nextRotation = _activeFrame.Rotation + (_activeFrame.Rotation >= 180 ? -180 : 180); Position oppositeSide = CalculateNextPositionFromAngle( nextRotation, _previousCanvasPosition.X, _previousCanvasPosition.Y ); if (RectangleDictionary.ContainsKey(oppositeSide)) { RectangleDictionary[oppositeSide].Fill = Brushes.White; } _activeFrame.AttachedPosition = null; } _previousCanvasPosition = null; } if (AddDoorsChecked || AddWindowsChecked) { if (WithinSelectedPoints(x, y)) { // Kopieert de point naar een variable _previousCanvasPosition = point; // Berekend de horizontale posities links en rechts van het geplaatste object Position horiLeft = new Position(x - 25, y); Position horiRight = new Position(x + 25, y); // Als het object locaties naast zich heeft wordt de rotatie naar 0 gezet en anders 90 int rotation = RectangleDictionary.ContainsKey(horiLeft) && RectangleDictionary[horiLeft].Fill != Brushes.White || RectangleDictionary.ContainsKey(horiRight) && RectangleDictionary[horiRight].Fill != Brushes.White ? 0 : 90; // Haalt de positie uit de lijst als die daar bestaat if (AddWindowsChecked) { Frame window = new Frame(point.X, point.Y, FrameTypes.Window); _activeFrame = window; if (FramePoints.Contains(window)) { return; } window.Rotation = rotation; AddWindow(window, point); } if (AddDoorsChecked) { Frame door = new Frame(point.X, point.Y, FrameTypes.Door); _activeFrame = door; if (FramePoints.Contains(door)) { return; } // Als de focus van horizontaal naar verticaal gaat moet de rotatie veranderen, anders mag de opgeslagen rotatie gebruikt worden. Dit is ook vice versa door.Rotation = _angle == rotation || _angle == rotation + 180 ? _angle : rotation; AddDoor(door, point); RotateDoor(door.Rotation, x, y); } } } }