chiark / gitweb /
Add a new midend function to reset the tile size to the puzzle's
authorSimon Tatham <anakin@pobox.com>
Sun, 7 Apr 2013 10:24:35 +0000 (10:24 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 7 Apr 2013 10:24:35 +0000 (10:24 +0000)
default (but still counting the <puzzle>_TILESIZE user preference
environment variables, where available).

[originally from svn r9820]

devel.but
midend.c
puzzles.h

index d2bf2e4dc2fa0de6d2d8232dbfcb6e6811d87e7e..30642ead581af087647a923dec958eda3147099e 100644 (file)
--- a/devel.but
+++ b/devel.but
@@ -2812,6 +2812,22 @@ that \e{and} set the \c{user_size} flag, though!
 The midend relies on the frontend calling \cw{midend_new_game()}
 (\k{midend-new-game}) before calling \cw{midend_size()}.
 
+\H{midend-reset-tilesize} \cw{midend_reset_tilesize()}
+
+\c void midend_reset_tilesize(midend *me);
+
+This function resets the midend's preferred tile size to that of the
+standard puzzle.
+
+As discussed in \k{midend-size}, puzzle resizes are typically
+'sticky', in that once the user has dragged the puzzle to a different
+window size, the resulting tile size will be remembered and used when
+the puzzle configuration changes. If you \e{don't} want that, e.g. if
+you want to provide a command to explicitly reset the puzzle size back
+to its default, then you can call this just before calling
+\cw{midend_size()} (which, in turn, you would probably call with
+\c{user_size} set to \cw{FALSE}).
+
 \H{midend-new-game} \cw{midend_new_game()}
 
 \c void midend_new_game(midend *me);
index 41d562aa9e5d18361b27975cd9c9a9a394fa14ca..c36127467b864bb6bc81241d4c4b1efcf01f553b 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -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);
 
index 61d855346b7fa4fc93e4b7c44a483fb96a3bd591..8232692bfe63969d29fc97f4fa852a9f6e6c1d6f 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -232,6 +232,7 @@ const game *midend_which_game(midend *me);
 void midend_set_params(midend *me, game_params *params);
 game_params *midend_get_params(midend *me);
 void midend_size(midend *me, int *x, int *y, int user_size);
+void midend_reset_tilesize(midend *me);
 void midend_new_game(midend *me);
 void midend_restart_game(midend *me);
 void midend_stop_anim(midend *me);