mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Implement first font::print function, fix most fading of colored glyphs
There has always been a mess of different print functions that all had
slightly different specifics and called each other:
Print(x, y, text, r, g, b, cen)
nothing special here, just does what the arguments say
PrintAlpha(x, y, text, r, g, b, a, cen)
just Print but with an alpha argument
PrintWrap(x, y, text, r, g, b, cen, linespacing, maxwidth)
added for wordwrapping, heavily used now
bprint(x, y, text, r, g, b, cen)
prints an outline, then just PrintAlpha
bprintalpha(x, y, text, r, g, b, a, cen)
just bprint but with an alpha argument
bigprint(x, y, text, r, g, b, cen, sc)
nothing special here, just does what the arguments say
bigbprint(x, y, text, r, g, b, cen, sc)
prints an outline, then just bigprint
bigrprint(x, y, text, r, g, b, cen, sc)
right-aligns text, unless cen is given in which case it just
centers text like other functions already do?
bigbrprint(x, y, text, r, g, b, cen, sc)
prints an outline, then just bigrprint
We need even more specifics with the new font system: we need to be
able to specify whether CJK characters should be vertically centered or
stick out on the top/bottom, and we sometimes need to pass in
brightness variables for colored glyphs. And text printing functions
now fit better in Font.cpp anyway. So there's now a big overhaul of
print functions: all these functions will be replaced by font::print
and font::print_wrap (the former of which now exists). These take flags
as their first argument, which can be 0 for a basic left-aligned print,
PR_CEN for centered text (set X to -1!!!) PR_BOR for a border (instead
of functions like bprint and bigbprint), PR_2X, PR_3X etc for scaling,
and these can be combined with |.
Some text, for example [Press ESC to return to editor], fades in/out
using the alpha value, which is passed to the print function. In some
other places (like Press ENTER to teleport, textboxes, trophy text...)
text can fade in or out by direct changes to the RGB values. This means
regular color-adjusted white text can change color, but colored button
glyphs can't, since there's no way to know in the print system what the
maximum RGB values of a specific textbox are supposed to be, so the
only thing it can do is draw the button glyphs at full brightness,
which looks bad. Therefore, you can now also pass in the brightness
value via the flags, with PR_COLORGLYPH_BRI(255).
This commit is contained in:
committed by
Misa Elizabeth Kai
parent
9879fb2809
commit
0475539075
@@ -4,6 +4,7 @@
|
||||
#include <utf8/unchecked.h>
|
||||
|
||||
#include "Alloc.h"
|
||||
#include "Constants.h"
|
||||
#include "FileSystemUtils.h"
|
||||
#include "Graphics.h"
|
||||
#include "UtilityClass.h"
|
||||
@@ -313,21 +314,22 @@ int get_advance(const Font* f, const uint32_t codepoint)
|
||||
return glyph->advance;
|
||||
}
|
||||
|
||||
int print_char(
|
||||
static int print_char(
|
||||
const Font* f,
|
||||
const uint32_t codepoint,
|
||||
const int x,
|
||||
const int y,
|
||||
const int scale,
|
||||
const uint8_t r,
|
||||
const uint8_t g,
|
||||
const uint8_t b,
|
||||
const uint8_t a
|
||||
uint8_t r,
|
||||
uint8_t g,
|
||||
uint8_t b,
|
||||
const uint8_t a,
|
||||
const uint8_t colorglyph_bri
|
||||
)
|
||||
{
|
||||
/* Draws the glyph for a codepoint at x,y.
|
||||
* Returns the amount of pixels to advance the cursor. */
|
||||
GlyphInfo* glyph = find_glyphinfo(f, codepoint);;
|
||||
GlyphInfo* glyph = find_glyphinfo(f, codepoint);
|
||||
if (glyph == NULL)
|
||||
{
|
||||
return f->glyph_w * scale;
|
||||
@@ -335,14 +337,109 @@ int print_char(
|
||||
|
||||
if (glyph->flags & GLYPH_COLOR && (r | g | b) != 0)
|
||||
{
|
||||
graphics.draw_grid_tile(f->image, glyph->image_idx, x, y, f->glyph_w, f->glyph_h, 255, 255, 255, 255, scale, scale * (graphics.flipmode ? -1 : 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
r = g = b = colorglyph_bri;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
return glyph->advance * scale;
|
||||
}
|
||||
|
||||
#define FLAG_PART(start, count) ((flags >> start) % (1 << count))
|
||||
static PrintFlags decode_print_flags(uint32_t flags)
|
||||
{
|
||||
PrintFlags pf;
|
||||
pf.scale = FLAG_PART(0, 3) + 1;
|
||||
pf.font_sel = 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.border = flags & PR_BOR;
|
||||
pf.align_cen = flags & PR_CEN;
|
||||
pf.align_right = flags & PR_RIGHT;
|
||||
pf.cjk_low = flags & PR_CJK_LOW;
|
||||
pf.cjk_high = flags & PR_CJK_HIGH;
|
||||
|
||||
return pf;
|
||||
}
|
||||
#undef FLAG_PART
|
||||
|
||||
void print(
|
||||
const uint32_t flags,
|
||||
int x,
|
||||
int y,
|
||||
const std::string& text,
|
||||
const uint8_t r,
|
||||
const uint8_t g,
|
||||
const uint8_t b
|
||||
)
|
||||
{
|
||||
PrintFlags pf = decode_print_flags(flags);
|
||||
|
||||
// TODO pf.font_sel
|
||||
|
||||
if (pf.align_cen || pf.align_right)
|
||||
{
|
||||
const int textlen = graphics.len(text) * pf.scale;
|
||||
|
||||
if (pf.align_cen)
|
||||
{
|
||||
if (x == -1)
|
||||
{
|
||||
x = SCREEN_WIDTH_PIXELS / 2;
|
||||
}
|
||||
x = SDL_max(x - textlen/2, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
x -= textlen;
|
||||
}
|
||||
}
|
||||
// TODO cjk_low/cjk_high
|
||||
|
||||
if (pf.border && !graphics.notextoutline)
|
||||
{
|
||||
static const int offsets[4][2] = {{0,-1}, {-1,0}, {1,0}, {0,1}};
|
||||
|
||||
for (int offset = 0; offset < 4; offset++)
|
||||
{
|
||||
print(
|
||||
flags & ~PR_BOR & ~PR_CEN & ~PR_RIGHT,
|
||||
x + offsets[offset][0]*pf.scale,
|
||||
y + offsets[offset][1]*pf.scale,
|
||||
text,
|
||||
0, 0, 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int position = 0;
|
||||
std::string::const_iterator iter = text.begin();
|
||||
while (iter != text.end())
|
||||
{
|
||||
const uint32_t character = utf8::unchecked::next(iter);
|
||||
position += font::print_char(
|
||||
&font::temp_bfont,
|
||||
character,
|
||||
x + position,
|
||||
y,
|
||||
pf.scale,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
pf.alpha,
|
||||
pf.colorglyph_bri
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace font
|
||||
|
||||
Reference in New Issue
Block a user