Add a new midend function to reset the tile size to the puzzle's

default (but still counting the <puzzle>_TILESIZE user preference
environment variables, where available).

[originally from svn r9820]
This commit is contained in:
Simon Tatham
2013-04-07 10:24:35 +00:00
parent ea25b606cb
commit c55e954854
3 changed files with 41 additions and 19 deletions

View File

@ -94,6 +94,29 @@ struct midend {
} \
} while (0)
void midend_reset_tilesize(midend *me)
{
me->preferred_tilesize = me->ourgame->preferred_tilesize;
{
/*
* Allow an environment-based override for the default tile
* size by defining a variable along the lines of
* `NET_TILESIZE=15'.
*/
char buf[80], *e;
int j, k, ts;
sprintf(buf, "%s_TILESIZE", me->ourgame->name);
for (j = k = 0; buf[j]; j++)
if (!isspace((unsigned char)buf[j]))
buf[k++] = toupper((unsigned char)buf[j]);
buf[k] = '\0';
if ((e = getenv(buf)) != NULL && sscanf(e, "%d", &ts) == 1 && ts > 0)
me->preferred_tilesize = ts;
}
}
midend *midend_new(frontend *fe, const game *ourgame,
const drawing_api *drapi, void *drhandle)
{
@ -153,25 +176,7 @@ midend *midend_new(frontend *fe, const game *ourgame,
else
me->drawing = NULL;
me->preferred_tilesize = ourgame->preferred_tilesize;
{
/*
* Allow an environment-based override for the default tile
* size by defining a variable along the lines of
* `NET_TILESIZE=15'.
*/
char buf[80], *e;
int j, k, ts;
sprintf(buf, "%s_TILESIZE", me->ourgame->name);
for (j = k = 0; buf[j]; j++)
if (!isspace((unsigned char)buf[j]))
buf[k++] = toupper((unsigned char)buf[j]);
buf[k] = '\0';
if ((e = getenv(buf)) != NULL && sscanf(e, "%d", &ts) == 1 && ts > 0)
me->preferred_tilesize = ts;
}
midend_reset_tilesize(me);
sfree(randseed);