DJUI: Added drop shadow to text

This commit is contained in:
MysterD 2021-06-19 01:21:25 -07:00
parent b80cc50cd0
commit 63e9621d56
2 changed files with 18 additions and 2 deletions

View File

@ -17,7 +17,7 @@ struct DjuiButton* djui_button_create(struct DjuiBase* parent, const char* messa
struct DjuiRect* rect = djui_rect_create(&button->base);
djui_base_set_size_type(&rect->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&rect->base, 1.0f, 1.0f);
djui_base_set_color(&rect->base, 225, 225, 225, 255);
djui_base_set_color(&rect->base, 200, 200, 200, 255);
button->rect = rect;
struct DjuiText* text = djui_text_create(&rect->base, message);
@ -25,6 +25,7 @@ struct DjuiButton* djui_button_create(struct DjuiBase* parent, const char* messa
djui_base_set_size(&text->base, 1.0f, 1.0f);
djui_base_set_color(&text->base, 11, 11, 11, 255);
djui_text_set_alignment(text, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_text_set_drop_shadow(text, 0, 0, 0, 64);
button->text = text;
return button;

View File

@ -51,7 +51,7 @@ static void djui_text_translate(f32 x, f32 y) {
sTextRenderY += y;
}
static void djui_text_render_char(struct DjuiText* text, u8 d) {
static void djui_text_render_single_char(struct DjuiText* text, u8 d) {
struct DjuiBaseRect* comp = &text->base.comp;
f32 dX = comp->x + sTextRenderX * text->fontSize;
@ -70,6 +70,21 @@ static void djui_text_render_char(struct DjuiText* text, u8 d) {
sTextRenderLastY = sTextRenderY;
}
static void djui_text_render_char(struct DjuiText* text, u8 d) {
if (text->dropShadow.a > 0) {
// render drop shadow
struct DjuiBase* base = &text->base;
sTextRenderX += 0.5f;
sTextRenderY += 0.5f;
gDPSetEnvColor(gDisplayListHead++, text->dropShadow.r, text->dropShadow.g, text->dropShadow.b, text->dropShadow.a);
djui_text_render_single_char(text, d);
gDPSetEnvColor(gDisplayListHead++, base->color.r, base->color.g, base->color.b, base->color.a);
sTextRenderX -= 0.5f;
sTextRenderY -= 0.5f;
}
djui_text_render_single_char(text, d);
}
static f32 djui_text_measure_word_width(char* message) {
f32 width = 0;
while (*message != '\0') {