1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Replace PR_COLORGLYPH_BRI(a) and PR_ALPHA(a) with PR_BRIGHTNESS(a)

There used to be two ways of fading in/out text in VVVVVV:
- Local code that modifies the R, G and B values of the text
- Keeping the RGB values the same and using the alpha channel

The latter approach is only used once, for [Press ENTER to return to
editor]. The former approach causes problems with colored (button)
glyphs: there's no way for the print function to tell from the RGB
values whether a color is "full Viridian-cyan" or "Viridian-cyan faded
out 50%", so I added the flag PR_COLORGLYPH_BRI(value) to tell the
print function that the color brightness is reduced to match the
brightness of colored glyphs to the brightness of the rest of the text.

However, there were already plans to make the single use of alpha
consistent with the rest of the game and the style, so PR_ALPHA(value)
could be removed, as well as the bit signifying whether the brightness
or alpha value is used. For the editor text, I simply copied the "Press
{button} to teleport" behavior of hiding the text completely if it
becomes darker than 100/255.

Another simplification is to make the print function handle not just
the brightness of the color glyphs while local code handled the
brightness of the normal text color, but to make the print function
handle both. That way, the callsite can simply pass in the full colors
and the brightness flag, and the flag name can be made a lot simpler as
well: PR_BRIGHTNESS(value).
This commit is contained in:
Dav999-v 2023-01-31 02:22:43 +01:00 committed by Misa Elizabeth Kai
parent d1f6c1adf2
commit 716a241b79
5 changed files with 40 additions and 52 deletions

View file

@ -53,7 +53,8 @@ A not-technically-exhaustive list of all flags (which are defined in Font.h):
- PR_FONT_LEVEL Use level-specific font (room names, cutscenes, etc)
- PR_FONT_8X8 Use 8x8 font no matter what
- PR_BRIGHTNESS(value) Use this brightness 0-255 (this value is mixed with
r, g and b for an alpha effect)
r, g and b for an alpha effect, and accounts for
colored glyphs correctly)
- PR_BOR Draw a black border around the text
- PR_LEFT [DEFAULT] Left-align text/place at X coordinate
- PR_CEN Center-align text relative to X (X is center)

View file

@ -58,8 +58,7 @@ struct PrintFlags
{
uint8_t scale;
Font* font_sel;
uint8_t alpha;
uint8_t colorglyph_bri;
uint8_t brightness;
bool border;
bool align_cen;
bool align_right;
@ -657,18 +656,7 @@ static PrintFlags decode_print_flags(uint32_t flags)
PrintFlags pf;
pf.scale = FLAG_PART(0, 3) + 1;
pf.font_sel = fontsel_to_font(FLAG_PART(3, 5));
if (flags & PR_AB_IS_BRI)
{
pf.alpha = 255;
pf.colorglyph_bri = ~FLAG_PART(8, 8) & 0xff;
}
else
{
pf.alpha = ~FLAG_PART(8, 8) & 0xff;
pf.colorglyph_bri = 255;
}
pf.brightness = ~FLAG_PART(8, 8) & 0xff;
pf.border = flags & PR_BOR;
pf.align_cen = flags & PR_CEN;
pf.align_right = flags & PR_RIGHT;
@ -929,8 +917,7 @@ static int print_char(
uint8_t r,
uint8_t g,
uint8_t b,
const uint8_t a,
const uint8_t colorglyph_bri
const uint8_t brightness
)
{
/* Draws the glyph for a codepoint at x,y.
@ -943,10 +930,17 @@ static int print_char(
if (glyph->flags & GLYPH_COLOR && (r | g | b) != 0)
{
r = g = b = colorglyph_bri;
r = g = b = brightness;
}
else if (brightness < 255)
{
float bri_factor = brightness / (float) 255;
r *= bri_factor;
g *= bri_factor;
b *= bri_factor;
}
graphics.draw_grid_tile(f->image, glyph->image_idx, x, y, f->glyph_w, f->glyph_h, r, g, b, a, scale, scale * (graphics.flipmode ? -1 : 1));
graphics.draw_grid_tile(f->image, glyph->image_idx, x, y, f->glyph_w, f->glyph_h, r, g, b, scale, scale * (graphics.flipmode ? -1 : 1));
return glyph->advance * scale;
}
@ -1137,8 +1131,7 @@ void print(
r,
g,
b,
pf.alpha,
pf.colorglyph_bri
pf.brightness
);
}
}

View file

@ -43,11 +43,8 @@
#define PR_FONT_LEVEL (1 << 3) /* use level-specific font (room names, cutscene dialogue, etc) */
#define PR_FONT_8X8 (2 << 3) /* use 8x8 font no matter what */
#define PR_FONT_IDX(idx) ((SDL_clamp(idx, 0, 28) + 3) << 3) /* use given font index */
#define PR_AB_IS_BRI (1 << 16)
#define PR_ALPHA(value) /* use this alpha value 0-255 (incompatible with PR_COLORGLYPH_BRI) */\
((~SDL_clamp((int)(value), 0, 255) & 0xff) << 8)
#define PR_COLORGLYPH_BRI(value) /* use this brightness 0-255 for colored glyphs (button icons) */\
(((~SDL_clamp((int)(value), 0, 255) & 0xff) << 8) | PR_AB_IS_BRI)
#define PR_BRIGHTNESS(value) /* use this brightness 0-255 for the text (accounts for button glyphs correctly) */\
(((~SDL_clamp((int)(value), 0, 255) & 0xff) << 8))
#define PR_BOR (1 << 17) /* draw a black border around the text (was bprint/bigbprint) */
#define PR_LEFT (0 << 18) /* default, left-align text/place at x coordinate */
#define PR_CEN (1 << 18) /* center-align text relative to X (X is center) or to screen if X == -1 */

View file

@ -843,11 +843,11 @@ void Graphics::drawgui(void)
for (j = 0; j < textboxes[i].lines.size(); j++)
{
font::print(
textboxes[i].print_flags | PR_COLORGLYPH_BRI(tl_lerp*255) | PR_CJK_LOW,
textboxes[i].print_flags | PR_BRIGHTNESS(tl_lerp*255) | PR_CJK_LOW,
textboxes[i].xp + 8,
yp + text_yoff + text_sign * (j * font_height),
textboxes[i].lines[j],
r, g, b
textboxes[i].r, textboxes[i].g, textboxes[i].b
);
}
}
@ -1696,22 +1696,15 @@ void Graphics::drawgravityline( int t )
void Graphics::drawtrophytext(void)
{
int temp, temp2, temp3;
int brightness;
if (obj.trophytext < 15)
{
const int usethismult = lerp(obj.oldtrophytext, obj.trophytext);
temp = (196 * usethismult) / 15;
temp2 = (196 * usethismult) / 15;
temp3 = ((255 - help.glow) * usethismult) / 15;
brightness = (usethismult/15.0)*255;
}
else
{
temp = 196;
temp2 = 196;
temp3 = 255 - help.glow;
brightness = 255;
}
@ -1795,12 +1788,12 @@ void Graphics::drawtrophytext(void)
if (top_text != NULL)
{
font::string_wordwrap(0, top_text, 304, &lines);
font::print_wrap(PR_CEN | PR_COLORGLYPH_BRI(brightness) | PR_BOR, -1, 11-(lines-1)*5, top_text, temp, temp2, temp3);
font::print_wrap(PR_CEN | PR_BRIGHTNESS(brightness) | PR_BOR, -1, 11-(lines-1)*5, top_text, 196, 196, 255 - help.glow);
}
if (bottom_text != NULL)
{
font::string_wordwrap(0, bottom_text, 304, &lines);
font::print_wrap(PR_CEN | PR_COLORGLYPH_BRI(brightness) | PR_BOR, -1, 221-(lines-1)*5, bottom_text, temp, temp2, temp3);
font::print_wrap(PR_CEN | PR_BRIGHTNESS(brightness) | PR_BOR, -1, 221-(lines-1)*5, bottom_text, 196, 196, 255 - help.glow);
}
}

View file

@ -1961,11 +1961,15 @@ void gamerender(void)
}
#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR)
if(map.custommode && !map.custommodeforreal && !game.advancetext){
if(map.custommode && !map.custommodeforreal && !game.advancetext){
//Return to level editor
int alpha = graphics.lerp(ed.oldreturneditoralpha, ed.returneditoralpha);
font::print(PR_ALPHA(alpha) | PR_BOR, 5, 5, loc::gettext("[Press ENTER to return to editor]"), 220 - (help.glow), 220 - (help.glow), 255 - (help.glow / 2));
}
if (alpha > 100)
{
font::print(PR_BRIGHTNESS(alpha) | PR_BOR, 5, 5, loc::gettext("[Press ENTER to return to editor]"), 220 - (help.glow), 220 - (help.glow), 255 - (help.glow / 2));
}
}
#endif
@ -1997,13 +2001,13 @@ void gamerender(void)
int alpha = graphics.lerp(game.oldreadytotele, game.readytotele);
font::print(
PR_COLORGLYPH_BRI(alpha) | PR_CEN | PR_BOR,
PR_BRIGHTNESS(alpha) | PR_CEN | PR_BOR,
-1,
graphics.flipmode ? 20 : 210,
final_string,
alpha - 20 - (help.glow / 2),
alpha - 20 - (help.glow / 2),
alpha
235 - (help.glow / 2),
235 - (help.glow / 2),
255
);
}
@ -2223,13 +2227,13 @@ void gamerender(void)
if (game.activity_r == 0 && game.activity_g == 0 && game.activity_b == 0)
{
font::print(
game.activity_print_flags | PR_COLORGLYPH_BRI(act_alpha*255),
game.activity_print_flags | PR_BRIGHTNESS(act_alpha*255),
centered_x + game.activity_x,
game.activity_y + 12,
final_string,
196*act_alpha,
196*act_alpha,
(255 - help.glow)*act_alpha
196,
196,
255 - help.glow
);
}
else
@ -2244,13 +2248,13 @@ void gamerender(void)
game.activity_b*act_alpha
);
font::print(
game.activity_print_flags | PR_COLORGLYPH_BRI(act_alpha*255) | PR_CJK_LOW,
game.activity_print_flags | PR_BRIGHTNESS(act_alpha*255) | PR_CJK_LOW,
centered_x + game.activity_x,
game.activity_y + 12,
final_string,
game.activity_r*act_alpha,
game.activity_g*act_alpha,
game.activity_b*act_alpha
game.activity_r,
game.activity_g,
game.activity_b
);
}
}