mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Refactoring from James H: the highlight and lowlight colour setup
common to Fifteen, Sixteen, Twiddle and Pegs is now a utility function in misc.c. [originally from svn r6076]
This commit is contained in:
21
fifteen.c
21
fifteen.c
@ -584,28 +584,11 @@ static float *game_colours(frontend *fe, game_state *state, int *ncolours)
|
|||||||
{
|
{
|
||||||
float *ret = snewn(3 * NCOLOURS, float);
|
float *ret = snewn(3 * NCOLOURS, float);
|
||||||
int i;
|
int i;
|
||||||
float max;
|
|
||||||
|
|
||||||
frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
|
game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT);
|
||||||
|
|
||||||
/*
|
for (i = 0; i < 3; i++)
|
||||||
* Drop the background colour so that the highlight is
|
|
||||||
* noticeably brighter than it while still being under 1.
|
|
||||||
*/
|
|
||||||
max = ret[COL_BACKGROUND*3];
|
|
||||||
for (i = 1; i < 3; i++)
|
|
||||||
if (ret[COL_BACKGROUND*3+i] > max)
|
|
||||||
max = ret[COL_BACKGROUND*3+i];
|
|
||||||
if (max * 1.2F > 1.0F) {
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
ret[COL_BACKGROUND*3+i] /= (max * 1.2F);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
ret[COL_HIGHLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 1.2F;
|
|
||||||
ret[COL_LOWLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 0.8F;
|
|
||||||
ret[COL_TEXT * 3 + i] = 0.0;
|
ret[COL_TEXT * 3 + i] = 0.0;
|
||||||
}
|
|
||||||
|
|
||||||
*ncolours = NCOLOURS;
|
*ncolours = NCOLOURS;
|
||||||
return ret;
|
return ret;
|
||||||
|
27
misc.c
27
misc.c
@ -169,4 +169,31 @@ unsigned char *hex2bin(const char *in, int outlen)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game_mkhighlight(frontend *fe, float *ret,
|
||||||
|
int background, int highlight, int lowlight)
|
||||||
|
{
|
||||||
|
float max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
frontend_default_colour(fe, &ret[background * 3]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Drop the background colour so that the highlight is
|
||||||
|
* noticeably brighter than it while still being under 1.
|
||||||
|
*/
|
||||||
|
max = ret[background*3];
|
||||||
|
for (i = 1; i < 3; i++)
|
||||||
|
if (ret[background*3+i] > max)
|
||||||
|
max = ret[background*3+i];
|
||||||
|
if (max * 1.2F > 1.0F) {
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
ret[background*3+i] /= (max * 1.2F);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ret[highlight * 3 + i] = ret[background * 3 + i] * 1.2F;
|
||||||
|
ret[lowlight * 3 + i] = ret[background * 3 + i] * 0.8F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* vim: set shiftwidth=4 tabstop=8: */
|
/* vim: set shiftwidth=4 tabstop=8: */
|
||||||
|
22
pegs.c
22
pegs.c
@ -845,28 +845,8 @@ static void game_set_size(game_drawstate *ds, game_params *params,
|
|||||||
static float *game_colours(frontend *fe, game_state *state, int *ncolours)
|
static float *game_colours(frontend *fe, game_state *state, int *ncolours)
|
||||||
{
|
{
|
||||||
float *ret = snewn(3 * NCOLOURS, float);
|
float *ret = snewn(3 * NCOLOURS, float);
|
||||||
int i;
|
|
||||||
float max;
|
|
||||||
|
|
||||||
frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
|
game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT);
|
||||||
|
|
||||||
/*
|
|
||||||
* Drop the background colour so that the highlight is
|
|
||||||
* noticeably brighter than it while still being under 1.
|
|
||||||
*/
|
|
||||||
max = ret[COL_BACKGROUND*3];
|
|
||||||
for (i = 1; i < 3; i++)
|
|
||||||
if (ret[COL_BACKGROUND*3+i] > max)
|
|
||||||
max = ret[COL_BACKGROUND*3+i];
|
|
||||||
if (max * 1.2F > 1.0F) {
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
ret[COL_BACKGROUND*3+i] /= (max * 1.2F);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
ret[COL_HIGHLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 1.2F;
|
|
||||||
ret[COL_LOWLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 0.8F;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret[COL_PEG * 3 + 0] = 0.0F;
|
ret[COL_PEG * 3 + 0] = 0.0F;
|
||||||
ret[COL_PEG * 3 + 1] = 0.0F;
|
ret[COL_PEG * 3 + 1] = 0.0F;
|
||||||
|
@ -218,6 +218,10 @@ void obfuscate_bitmap(unsigned char *bmp, int bits, int decode);
|
|||||||
char *bin2hex(const unsigned char *in, int inlen);
|
char *bin2hex(const unsigned char *in, int inlen);
|
||||||
unsigned char *hex2bin(const char *in, int outlen);
|
unsigned char *hex2bin(const char *in, int outlen);
|
||||||
|
|
||||||
|
/* Sets (and possibly dims) background from frontend default colour,
|
||||||
|
* and auto-generates highlight and lowlight colours too. */
|
||||||
|
void game_mkhighlight(frontend *fe, float *ret,
|
||||||
|
int background, int highlight, int lowlight);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* version.c
|
* version.c
|
||||||
|
21
sixteen.c
21
sixteen.c
@ -706,28 +706,11 @@ static float *game_colours(frontend *fe, game_state *state, int *ncolours)
|
|||||||
{
|
{
|
||||||
float *ret = snewn(3 * NCOLOURS, float);
|
float *ret = snewn(3 * NCOLOURS, float);
|
||||||
int i;
|
int i;
|
||||||
float max;
|
|
||||||
|
|
||||||
frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
|
game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT);
|
||||||
|
|
||||||
/*
|
for (i = 0; i < 3; i++)
|
||||||
* Drop the background colour so that the highlight is
|
|
||||||
* noticeably brighter than it while still being under 1.
|
|
||||||
*/
|
|
||||||
max = ret[COL_BACKGROUND*3];
|
|
||||||
for (i = 1; i < 3; i++)
|
|
||||||
if (ret[COL_BACKGROUND*3+i] > max)
|
|
||||||
max = ret[COL_BACKGROUND*3+i];
|
|
||||||
if (max * 1.2F > 1.0F) {
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
ret[COL_BACKGROUND*3+i] /= (max * 1.2F);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
|
||||||
ret[COL_HIGHLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 1.2F;
|
|
||||||
ret[COL_LOWLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 0.8F;
|
|
||||||
ret[COL_TEXT * 3 + i] = 0.0;
|
ret[COL_TEXT * 3 + i] = 0.0;
|
||||||
}
|
|
||||||
|
|
||||||
*ncolours = NCOLOURS;
|
*ncolours = NCOLOURS;
|
||||||
return ret;
|
return ret;
|
||||||
|
18
twiddle.c
18
twiddle.c
@ -765,27 +765,11 @@ static float *game_colours(frontend *fe, game_state *state, int *ncolours)
|
|||||||
{
|
{
|
||||||
float *ret = snewn(3 * NCOLOURS, float);
|
float *ret = snewn(3 * NCOLOURS, float);
|
||||||
int i;
|
int i;
|
||||||
float max;
|
|
||||||
|
|
||||||
frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
|
game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT);
|
||||||
|
|
||||||
/*
|
|
||||||
* Drop the background colour so that the highlight is
|
|
||||||
* noticeably brighter than it while still being under 1.
|
|
||||||
*/
|
|
||||||
max = ret[COL_BACKGROUND*3];
|
|
||||||
for (i = 1; i < 3; i++)
|
|
||||||
if (ret[COL_BACKGROUND*3+i] > max)
|
|
||||||
max = ret[COL_BACKGROUND*3+i];
|
|
||||||
if (max * 1.2F > 1.0F) {
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
ret[COL_BACKGROUND*3+i] /= (max * 1.2F);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
ret[COL_HIGHLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 1.2F;
|
|
||||||
ret[COL_HIGHLIGHT_GENTLE * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 1.1F;
|
ret[COL_HIGHLIGHT_GENTLE * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 1.1F;
|
||||||
ret[COL_LOWLIGHT * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 0.8F;
|
|
||||||
ret[COL_LOWLIGHT_GENTLE * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 0.9F;
|
ret[COL_LOWLIGHT_GENTLE * 3 + i] = ret[COL_BACKGROUND * 3 + i] * 0.9F;
|
||||||
ret[COL_TEXT * 3 + i] = 0.0;
|
ret[COL_TEXT * 3 + i] = 0.0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user