mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-02-03 07:45:31 +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
@@ -1,8 +1,34 @@
|
||||
/*
|
||||
* == SOME TEXT PRINTING EXAMPLES ==
|
||||
*
|
||||
* Standard print
|
||||
* font::print(0, 50, 50, "Hello world!", 255, 255, 255);
|
||||
*
|
||||
* Centered text
|
||||
* font::print(PR_CEN, -1, 50, "Hello world!", 255, 255, 255);
|
||||
* (set X to -1, unless you want to center *around* X)
|
||||
*
|
||||
* 2x scale
|
||||
* font::print(PR_2X, 50, 50, "V", 255, 255, 255);
|
||||
*
|
||||
* Centered 2x scale
|
||||
* font::print(PR_CEN | PR_2X, -1, 50, "V", 255, 255, 255);
|
||||
*
|
||||
* Right-aligned 3x scale with a border around it
|
||||
* font::print(PR_RIGHT | PR_3X | PR_BOR, 320, 50, "V", 255, 255, 255);
|
||||
*
|
||||
* Wordwrapped centered text
|
||||
* font::print_wrap(PR_CEN, -1, 50, "Hello world, this will wordwrap to the screen width", 255, 255, 255);
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#include <SDL.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "GraphicsUtil.h"
|
||||
|
||||
@@ -34,6 +60,43 @@ struct Font
|
||||
GlyphInfo* glyph_page[FONT_N_PAGES];
|
||||
};
|
||||
|
||||
struct PrintFlags
|
||||
{
|
||||
uint8_t scale;
|
||||
uint8_t font_sel;
|
||||
uint8_t alpha;
|
||||
uint8_t colorglyph_bri;
|
||||
bool border;
|
||||
bool align_cen;
|
||||
bool align_right;
|
||||
bool cjk_low;
|
||||
bool cjk_high;
|
||||
};
|
||||
|
||||
#define PR_1X (0 << 0) /* default, 1x scale */
|
||||
#define PR_2X (1 << 0) /* 2x scale */
|
||||
#define PR_3X (2 << 0) /* etc */
|
||||
#define PR_4X (3 << 0)
|
||||
#define PR_5X (4 << 0)
|
||||
#define PR_6X (5 << 0)
|
||||
#define PR_7X (6 << 0)
|
||||
#define PR_8X (7 << 0)
|
||||
#define PR_FONT_INTERFACE (0 << 3) /* default, use interface font */
|
||||
#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_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_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 */
|
||||
#define PR_RIGHT (2 << 18) /* right-align text to X (X is now the right border, not left border) */
|
||||
#define PR_CJK_CEN (0 << 20) /* default, larger fonts should stick out on top and bottom compared to 8x8 font */
|
||||
#define PR_CJK_LOW (1 << 20) /* larger fonts should stick out fully on the bottom (draw at Y) */
|
||||
#define PR_CJK_HIGH (2 << 20) /* larger fonts should stick out fully on the top */
|
||||
|
||||
extern Font temp_bfont;
|
||||
|
||||
void load_main(void);
|
||||
@@ -42,7 +105,8 @@ void unload_custom(void);
|
||||
void destroy(void);
|
||||
|
||||
int get_advance(const Font* f, uint32_t codepoint); // TODO de-api
|
||||
int print_char(const Font* f, uint32_t codepoint, int x, int y, int scale, uint8_t r, uint8_t g, uint8_t b, uint8_t a); // TODO de-api
|
||||
|
||||
void print(uint32_t flags, int x, int y, const std::string& text, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
} // namespace font
|
||||
|
||||
|
||||
Reference in New Issue
Block a user