aboutsummaryrefslogtreecommitdiff
path: root/midend.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2008-04-08 16:25:39 +0000
committerSimon Tatham <anakin@pobox.com>2008-04-08 16:25:39 +0000
commitae6c7381272f84c0fd398f6d3e496f571ba42ec8 (patch)
treeec91cb5e52dbbdcd8097c0fc02ee250f245edf19 /midend.c
parentea13d39a1780406421d2e9aa01c4caeca100c9eb (diff)
downloadpuzzles-ae6c7381272f84c0fd398f6d3e496f571ba42ec8.zip
puzzles-ae6c7381272f84c0fd398f6d3e496f571ba42ec8.tar.gz
puzzles-ae6c7381272f84c0fd398f6d3e496f571ba42ec8.tar.bz2
puzzles-ae6c7381272f84c0fd398f6d3e496f571ba42ec8.tar.xz
New feature in midend.c which allows us to ask for the number of the
currently selected preset, if any. I've used this in the GTK front end to have the Type menu mark the currently selected menu item. (After considerable beating of GTK with sticks, I might add. Grr.) Currently the same UI feature is not yet supported on Windows or MacOS, but I hope to do those too at some point if it's feasible. [originally from svn r7980]
Diffstat (limited to 'midend.c')
-rw-r--r--midend.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/midend.c b/midend.c
index 250a479..87df28a 100644
--- a/midend.c
+++ b/midend.c
@@ -31,7 +31,7 @@ struct midend {
const game *ourgame;
game_params **presets;
- char **preset_names;
+ char **preset_names, **preset_encodings;
int npresets, presetsize;
/*
@@ -115,6 +115,7 @@ midend *midend_new(frontend *fe, const game *ourgame,
me->oldstate = NULL;
me->presets = NULL;
me->preset_names = NULL;
+ me->preset_encodings = NULL;
me->npresets = me->presetsize = 0;
me->anim_time = me->anim_pos = 0.0F;
me->flash_time = me->flash_pos = 0.0F;
@@ -186,9 +187,11 @@ void midend_free(midend *me)
for (i = 0; i < me->npresets; i++) {
sfree(me->presets[i]);
sfree(me->preset_names[i]);
+ sfree(me->preset_encodings[i]);
}
sfree(me->presets);
sfree(me->preset_names);
+ sfree(me->preset_encodings);
}
if (me->ui)
me->ourgame->free_ui(me->ui);
@@ -836,10 +839,14 @@ int midend_num_presets(midend *me)
game_params *);
me->preset_names = sresize(me->preset_names, me->presetsize,
char *);
+ me->preset_encodings = sresize(me->preset_encodings,
+ me->presetsize, char *);
}
me->presets[me->npresets] = preset;
me->preset_names[me->npresets] = name;
+ me->preset_encodings[me->npresets] =
+ me->ourgame->encode_params(preset, TRUE);;
me->npresets++;
}
}
@@ -890,10 +897,14 @@ int midend_num_presets(midend *me)
game_params *);
me->preset_names = sresize(me->preset_names,
me->presetsize, char *);
+ me->preset_encodings = sresize(me->preset_encodings,
+ me->presetsize, char *);
}
me->presets[me->npresets] = preset;
me->preset_names[me->npresets] = dupstr(name);
+ me->preset_encodings[me->npresets] =
+ me->ourgame->encode_params(preset, TRUE);
me->npresets++;
}
}
@@ -910,6 +921,22 @@ void midend_fetch_preset(midend *me, int n,
*params = me->presets[n];
}
+int midend_which_preset(midend *me)
+{
+ char *encoding = me->ourgame->encode_params(me->params, TRUE);
+ int i, ret;
+
+ ret = -1;
+ for (i = 0; i < me->npresets; i++)
+ if (!strcmp(encoding, me->preset_encodings[i])) {
+ ret = i;
+ break;
+ }
+
+ sfree(encoding);
+ return ret;
+}
+
int midend_wants_statusbar(midend *me)
{
return me->ourgame->wants_statusbar;