[gnome-sudoku] centralize calculations of highlight state
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] centralize calculations of highlight state
- Date: Tue, 4 Aug 2020 18:28:17 +0000 (UTC)
commit 8505451338156460a42b421a71d0d822ea7f38e2
Author: Andrey Kutejko <andy128k gmail com>
Date: Tue Aug 4 18:47:13 2020 +0200
centralize calculations of highlight state
src/sudoku-view.vala | 53 ++++++++++++++++++++++++++--------------------------
1 file changed, 27 insertions(+), 26 deletions(-)
---
diff --git a/src/sudoku-view.vala b/src/sudoku-view.vala
index 2a1473c..21909c8 100644
--- a/src/sudoku-view.vala
+++ b/src/sudoku-view.vala
@@ -551,22 +551,7 @@ public class SudokuView : AspectFrame
return false;
this.set_selected (cell_row, cell_col);
- var cell_value = cell.value;
-
- for (var col_tmp = 0; col_tmp < game.board.cols; col_tmp++)
- {
- for (var row_tmp = 0; row_tmp < game.board.rows; row_tmp++)
- {
- cells[row_tmp, col_tmp].highlighted_background = _highlighter && (
- col_tmp == cell_col ||
- row_tmp == cell_row ||
- (col_tmp / game.board.block_cols == cell_col / game.board.block_cols &&
- row_tmp / game.board.block_rows == cell_row / game.board.block_rows)
- );
- cells[row_tmp, col_tmp].highlighted_value = _highlighter && cell_value ==
cells[row_tmp, col_tmp].value;
- }
- }
-
+ this.update_highlights ();
queue_draw ();
return false;
@@ -577,16 +562,7 @@ public class SudokuView : AspectFrame
return false;
this.set_selected (-1, -1);
-
- for (var col_tmp = 0; col_tmp < game.board.cols; col_tmp++)
- {
- for (var row_tmp = 0; row_tmp < game.board.rows; row_tmp++)
- {
- cells[row_tmp, col_tmp].highlighted_background = false;
- cells[row_tmp, col_tmp].highlighted_value = false;
- }
- }
-
+ this.update_highlights ();
queue_draw ();
return false;
@@ -596,6 +572,7 @@ public class SudokuView : AspectFrame
if (_show_possibilities || _show_warnings || game.board.broken ||
previous_board_broken_state)
previous_board_broken_state = game.board.broken;
+ this.update_highlights ();
// Redraw the board
this.queue_draw ();
});
@@ -613,6 +590,30 @@ public class SudokuView : AspectFrame
drawing.hide ();
}
+ private void update_highlights ()
+ {
+ var has_selection = selected_row >= 0 && selected_col >= 0;
+ var cell_value = -1;
+ if (has_selection)
+ cell_value = cells[selected_row, selected_col].value;
+
+ for (var col_tmp = 0; col_tmp < game.board.cols; col_tmp++)
+ {
+ for (var row_tmp = 0; row_tmp < game.board.rows; row_tmp++)
+ {
+ cells[row_tmp, col_tmp].highlighted_background = has_selection && _highlighter && (
+ col_tmp == selected_col ||
+ row_tmp == selected_row ||
+ (col_tmp / game.board.block_cols == selected_col / game.board.block_cols &&
+ row_tmp / game.board.block_rows == selected_row / game.board.block_rows)
+ );
+ cells[row_tmp, col_tmp].highlighted_value = has_selection &&
+ _highlighter &&
+ cell_value == cells[row_tmp, col_tmp].value;
+ }
+ }
+ }
+
private bool draw_board (Cairo.Context c)
{
if (game.paused)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]