mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Move the colour configuration into midend.c so that it becomes
cross-platform, and rename the environment variables so that they follow the puzzle name. Should allow a static environment configuration for each puzzle. Also introduced a <game>_PRESETS variable for people whose favourite configuration isn't on the Type menu by default. [originally from svn r5801]
This commit is contained in:
15
gtk.c
15
gtk.c
@ -1143,25 +1143,10 @@ static frontend *new_window(char *game_id, char **error)
|
|||||||
fe->ncolours = ncolours;
|
fe->ncolours = ncolours;
|
||||||
fe->colours = snewn(ncolours, GdkColor);
|
fe->colours = snewn(ncolours, GdkColor);
|
||||||
for (i = 0; i < ncolours; i++) {
|
for (i = 0; i < ncolours; i++) {
|
||||||
/*
|
|
||||||
* Just for Gareth: if you dislike any of the standard
|
|
||||||
* colours, here's your chance to configure them in a
|
|
||||||
* really hacky way.
|
|
||||||
*/
|
|
||||||
char buf[80], *e;
|
|
||||||
unsigned int r, g, b;
|
|
||||||
sprintf(buf, "PUZZLE_COLOUR_%d", i);
|
|
||||||
if ((e = getenv(buf)) != NULL &&
|
|
||||||
sscanf(e, "%2x%2x%2x", &r, &g, &b) == 3) {
|
|
||||||
fe->colours[i].red = r * 0x101;
|
|
||||||
fe->colours[i].green = g * 0x101;
|
|
||||||
fe->colours[i].blue = b * 0x101;
|
|
||||||
} else {
|
|
||||||
fe->colours[i].red = colours[i*3] * 0xFFFF;
|
fe->colours[i].red = colours[i*3] * 0xFFFF;
|
||||||
fe->colours[i].green = colours[i*3+1] * 0xFFFF;
|
fe->colours[i].green = colours[i*3+1] * 0xFFFF;
|
||||||
fe->colours[i].blue = colours[i*3+2] * 0xFFFF;
|
fe->colours[i].blue = colours[i*3+2] * 0xFFFF;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
success = snewn(ncolours, gboolean);
|
success = snewn(ncolours, gboolean);
|
||||||
gdk_colormap_alloc_colors(fe->colmap, fe->colours, ncolours,
|
gdk_colormap_alloc_colors(fe->colmap, fe->colours, ncolours,
|
||||||
FALSE, FALSE, success);
|
FALSE, FALSE, success);
|
||||||
|
75
midend.c
75
midend.c
@ -8,6 +8,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "puzzles.h"
|
#include "puzzles.h"
|
||||||
|
|
||||||
@ -498,6 +500,32 @@ float *midend_colours(midend_data *me, int *ncolours)
|
|||||||
|
|
||||||
ret = me->ourgame->colours(me->frontend, state, ncolours);
|
ret = me->ourgame->colours(me->frontend, state, ncolours);
|
||||||
|
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allow environment-based overrides for the standard
|
||||||
|
* colours by defining variables along the lines of
|
||||||
|
* `NET_COLOUR_4=6000c0'.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < *ncolours; i++) {
|
||||||
|
char buf[80], *e;
|
||||||
|
unsigned int r, g, b;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
sprintf(buf, "%s_COLOUR_%d", me->ourgame->name, i);
|
||||||
|
for (j = 0; buf[j]; j++)
|
||||||
|
buf[j] = toupper((unsigned char)buf[j]);
|
||||||
|
if ((e = getenv(buf)) != NULL &&
|
||||||
|
sscanf(e, "%2x%2x%2x", &r, &g, &b) == 3) {
|
||||||
|
ret[i*3 + 0] = r / 255.0;
|
||||||
|
ret[i*3 + 1] = g / 255.0;
|
||||||
|
ret[i*3 + 2] = b / 255.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (me->nstates == 0)
|
if (me->nstates == 0)
|
||||||
me->ourgame->free_game(state);
|
me->ourgame->free_game(state);
|
||||||
|
|
||||||
@ -525,6 +553,53 @@ int midend_num_presets(midend_data *me)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Allow environment-based extensions to the preset list by
|
||||||
|
* defining a variable along the lines of `SOLO_PRESETS=2x3
|
||||||
|
* Advanced:2x3da'. Colon-separated list of items,
|
||||||
|
* alternating between textual titles in the menu and
|
||||||
|
* encoded parameter strings.
|
||||||
|
*/
|
||||||
|
char buf[80], *e, *p;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
sprintf(buf, "%s_PRESETS", me->ourgame->name);
|
||||||
|
for (j = 0; buf[j]; j++)
|
||||||
|
buf[j] = toupper((unsigned char)buf[j]);
|
||||||
|
|
||||||
|
if ((e = getenv(buf)) != NULL) {
|
||||||
|
p = e = dupstr(e);
|
||||||
|
|
||||||
|
while (*p) {
|
||||||
|
char *name, *val;
|
||||||
|
game_params *preset;
|
||||||
|
|
||||||
|
name = p;
|
||||||
|
while (*p && *p != ':') p++;
|
||||||
|
if (*p) *p++ = '\0';
|
||||||
|
val = p;
|
||||||
|
while (*p && *p != ':') p++;
|
||||||
|
if (*p) *p++ = '\0';
|
||||||
|
|
||||||
|
preset = me->ourgame->default_params();
|
||||||
|
me->ourgame->decode_params(preset, val);
|
||||||
|
|
||||||
|
if (me->presetsize <= me->npresets) {
|
||||||
|
me->presetsize = me->npresets + 10;
|
||||||
|
me->presets = sresize(me->presets, me->presetsize,
|
||||||
|
game_params *);
|
||||||
|
me->preset_names = sresize(me->preset_names,
|
||||||
|
me->presetsize, char *);
|
||||||
|
}
|
||||||
|
|
||||||
|
me->presets[me->npresets] = preset;
|
||||||
|
me->preset_names[me->npresets] = name;
|
||||||
|
me->npresets++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return me->npresets;
|
return me->npresets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user