aboutsummaryrefslogtreecommitdiff
path: root/untangle.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2023-11-18 13:56:42 +0000
committerSimon Tatham <anakin@pobox.com>2023-11-18 13:56:42 +0000
commitcb8dcc34f7c656b8603a510617e35492a0d16b8c (patch)
tree8295c6694f3fc62775954745f94e0e9a49a436d5 /untangle.c
parent96d65e852cea8a95001fa70e3ec2996d4ea5e2b4 (diff)
downloadpuzzles-cb8dcc34f7c656b8603a510617e35492a0d16b8c.zip
puzzles-cb8dcc34f7c656b8603a510617e35492a0d16b8c.tar.gz
puzzles-cb8dcc34f7c656b8603a510617e35492a0d16b8c.tar.bz2
puzzles-cb8dcc34f7c656b8603a510617e35492a0d16b8c.tar.xz
Untangle: turn #define VERTEX_NUMBERS into a preference.
This compile-time definition switches the game into showing a distinct non-negative integer for each vertex, instead of indistinguishable blobs. Its main use to me in the past has been when I'm trying to planarise 'real' graphs, that is, graphs I got from outside the game and wanted a planar embedding of. Having made one in Untangle's UI I could then read off which vertex was which. That's an unusual use of the game, but _might_ be useful to someone else. Perhaps a more interesting use of this feature would be to direct someone else's play verbally - it would be much easier to tell them which vertex to click on that way!
Diffstat (limited to 'untangle.c')
-rw-r--r--untangle.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/untangle.c b/untangle.c
index 9290585..88f2cda 100644
--- a/untangle.c
+++ b/untangle.c
@@ -1054,6 +1054,12 @@ struct game_ui {
* crossing.
*/
bool show_crossed_edges;
+
+ /*
+ * User preference option to show vertices as numbers instead of
+ * circular blobs, so you can easily tell them apart.
+ */
+ bool vertex_numbers;
};
static game_ui *new_ui(const game_state *state)
@@ -1063,6 +1069,7 @@ static game_ui *new_ui(const game_state *state)
ui->just_moved = ui->just_dragged = false;
ui->snap_to_grid = false;
ui->show_crossed_edges = false;
+ ui->vertex_numbers = false;
return ui;
}
@@ -1070,7 +1077,7 @@ static config_item *get_prefs(game_ui *ui)
{
config_item *cfg;
- cfg = snewn(3, config_item);
+ cfg = snewn(4, config_item);
cfg[0].name = "Snap points to a grid";
cfg[0].kw = "snap-to-grid";
@@ -1082,8 +1089,15 @@ static config_item *get_prefs(game_ui *ui)
cfg[1].type = C_BOOLEAN;
cfg[1].u.boolean.bval = ui->show_crossed_edges;
- cfg[2].name = NULL;
- cfg[2].type = C_END;
+ cfg[2].name = "Display style for vertices";
+ cfg[2].kw = "vertex-style";
+ cfg[2].type = C_CHOICES;
+ cfg[2].u.choices.choicenames = ":Circles:Numbers";
+ cfg[2].u.choices.choicekws = ":circle:number";
+ cfg[2].u.choices.selected = ui->vertex_numbers;
+
+ cfg[3].name = NULL;
+ cfg[3].type = C_END;
return cfg;
}
@@ -1092,6 +1106,7 @@ static void set_prefs(game_ui *ui, const config_item *cfg)
{
ui->snap_to_grid = cfg[0].u.boolean.bval;
ui->show_crossed_edges = cfg[1].u.boolean.bval;
+ ui->vertex_numbers = cfg[2].u.choices.selected;
}
static void free_ui(game_ui *ui)
@@ -1472,19 +1487,17 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
}
if (c == thisc) {
-#ifdef VERTEX_NUMBERS
- draw_circle(dr, ds->x[i], ds->y[i], DRAG_THRESHOLD, bg, bg);
- {
- char buf[80];
- sprintf(buf, "%d", i);
- draw_text(dr, ds->x[i], ds->y[i], FONT_VARIABLE,
+ if (ui->vertex_numbers) {
+ char buf[80];
+ draw_circle(dr, ds->x[i], ds->y[i], DRAG_THRESHOLD, bg, bg);
+ sprintf(buf, "%d", i);
+ draw_text(dr, ds->x[i], ds->y[i], FONT_VARIABLE,
DRAG_THRESHOLD*3/2,
- ALIGN_VCENTRE|ALIGN_HCENTRE, c, buf);
- }
-#else
- draw_circle(dr, ds->x[i], ds->y[i], CIRCLE_RADIUS,
- c, COL_OUTLINE);
-#endif
+ ALIGN_VCENTRE|ALIGN_HCENTRE, c, buf);
+ } else {
+ draw_circle(dr, ds->x[i], ds->y[i], CIRCLE_RADIUS,
+ c, COL_OUTLINE);
+ }
}
}
}