public void Setup() { if (painter.HasBufferAlternate) { // the Setup() method was already executed for creating the alternate buffer this.Invalidate(); return; } if (settingsData != null) { this.TakeParametersFrom(settingsData); return; } #region Set up the painter. painter.Setup(); MazePainter.SuggestWidths(painter.GridWidth, painter.VisibleWalls, out int squareWidth, out int pathWidth, out int wallWidth); this.Setup(squareWidth, wallWidth, pathWidth); #endregion }
/// <summary> /// Creates a new maze. /// </summary> public void OnNew(object sender, EventArgs e) { #region Set up the painter. painter.Setup(); int squareWidth; int pathWidth; int wallWidth; MazePainter.SuggestWidths(painter.GridWidth, painter.VisibleWalls, out squareWidth, out pathWidth, out wallWidth); painter.Setup(squareWidth, wallWidth, pathWidth); #endregion painter.Reset(); painter.BlinkingCounter = 0; // Create and display a maze. painter.CreateMaze(null); painter.PaintMaze(null); }
/// <summary> /// Update the other controls to reflect the derived changes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDataChanged(object sender, EventArgs e) { // Avoid an infinite recursion if (_busyOnDataChanged) { return; } try { _busyOnDataChanged = true; #region Layout data if (data.AutoGridWidthModified) { if (!data.AutoGridWidth) { data.AutoSquareWidth = true; data.AutoPathWidth = true; data.AutoWallWidth = true; } } if (data.AutoSquareWidthModified || data.AutoPathWidthModified || data.AutoWallWidthModified) { if (!data.AutoSquareWidth || !data.AutoPathWidth || !data.AutoWallWidth) { data.AutoGridWidth = true; } } bool gridWithModifiedManually = data.GridWidthModified; if (data.GridWidthModified) { data.AutoGridWidth = false; int squareWidth, pathWidth, wallWidth; bool visibleWalls = (data.WallVisibility != AriadneSettingsData.WallVisibilityEnum.Never); MazePainter.SuggestWidths(data.GridWidth, visibleWalls, out squareWidth, out pathWidth, out wallWidth); data.WallWidth = wallWidth; data.SquareWidth = squareWidth; data.PathWidth = pathWidth; } if (data.PathWidthModified) { data.AutoPathWidth = gridWithModifiedManually; data.SquareWidth = Math.Max(data.PathWidth, data.SquareWidth); } if (data.SquareWidthModified) { data.AutoSquareWidth = gridWithModifiedManually; data.PathWidth = Math.Min(data.PathWidth, data.SquareWidth); data.GridWidth = Math.Min(data.SquareWidth + data.WallWidth, MazePainter.MaxGridWidth); data.WallWidth = data.GridWidth - data.SquareWidth; } if (data.WallWidthModified) { data.AutoWallWidth = gridWithModifiedManually; data.GridWidth = Math.Min(data.SquareWidth + data.WallWidth, MazePainter.MaxGridWidth); data.SquareWidth = data.GridWidth - data.WallWidth; } if (gridWithModifiedManually || (data.AutoGridWidthModified && !data.AutoGridWidth)) { data.AutoSquareWidth = true; data.AutoPathWidth = true; data.AutoWallWidth = true; } if (!data.AutoSquareWidth || !data.AutoPathWidth || !data.AutoWallWidth) { data.AutoGridWidth = true; } #endregion #region Shape data if (data.MazeWidthModified) { data.AutoMazeWidth = false; } if (data.MazeHeightModified) { data.AutoMazeHeight = false; } if (data.SeedModified) { data.AutoSeed = false; } #endregion CalculateResultingArea(); data.ClearModifedFlags(); dataBindingSource.ResetCurrentItem(); } finally { _busyOnDataChanged = false; } }