/** * \brief Draws text in a color specified by hue and value. * * A '~' in the text is not drawn but instead toggles highlighting which * increases \c value by 4. * * \li like JE_outText() with (brightness >= 0) * \li like JE_outTextAdjust() without shadow * * @param surface destination surface * @param x initial x-position in pixels; which direction(s) the text is drawn * from this position depends on the alignment * @param y initial upper y-position in pixels * @param text text to be drawn * @param font style/size of text * @param alignment left_aligned, centered, or right_aligned * @param hue hue component of text color * @param value value component of text color */ void draw_font_hv( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, Uint8 hue, Sint8 value ) { switch (alignment) { case left_aligned: break; case centered: x -= JE_textWidth(text, font) / 2; break; case right_aligned: x -= JE_textWidth(text, font); break; } bool highlight = false; for (; *text != '\0'; ++text) { int sprite_id = font_ascii[(unsigned char)*text]; switch (*text) { case ' ': x += 6; break; case '~': highlight = !highlight; if (highlight) value += 4; else value -= 4; break; default: if (sprite_id != -1 && sprite_exists(font, sprite_id)) { blit_sprite_hv(surface, x, y, font, sprite_id, hue, value); x += sprite(font, sprite_id)->width + 1; } break; } } }
/** * \brief Draws darkened text. * * Corresponds to blit_sprite_dark() * * \li like JE_outText() with (brightness < 0) if (black == true) * * @param surface destination surface * @param x initial x-position in pixels; which direction(s) the text is drawn * from this position depends on the alignment * @param y initial upper y-position in pixels * @param text text to be drawn * @param font style/size of text * @param alignment left_aligned, centered, or right_aligned * @param black if true text is drawn as solid black, if false text is drawn by * darkening the pixels of the destination surface */ void draw_font_dark( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, bool black ) { switch (alignment) { case left_aligned: break; case centered: x -= JE_textWidth(text, font) / 2; break; case right_aligned: x -= JE_textWidth(text, font); break; } for (; *text != '\0'; ++text) { int sprite_id = font_ascii[(unsigned char)*text]; switch (*text) { case ' ': x += 6; break; case '~': break; default: if (sprite_id != -1 && sprite_exists(font, sprite_id)) { blit_sprite_dark(surface, x, y, font, sprite_id, black); x += sprite(font, sprite_id)->width + 1; } break; } } }
int JE_fontCenter( const char *s, uint32_t font ) { return 160 - (JE_textWidth(s, font) / 2); }