diff --git a/src/backend/sdl.c b/src/backend/sdl.c index 1cccd76..abd579e 100644 --- a/src/backend/sdl.c +++ b/src/backend/sdl.c @@ -330,13 +330,20 @@ static void render_windows(struct window_list* wl) } } -static void draw_set_color(SDL_Renderer* r, uint64_t col) +static SDL_Color uint64_to_color(uint64_t col) { - SDL_SetRenderDrawColor(r, - (col & 0xff0000) >> 16, - (col & 0x00ff00) >> 8, - (col & 0x0000ff) >> 0, - 255); + SDL_Color c; + c.a = 255; + c.r = (col & 0xff0000) >> 16; + c.g = (col & 0x00ff00) >> 8; + c.b = (col & 0x0000ff) >> 0; + return c; +} + +static void draw_set_color(SDL_Renderer* r, uint64_t col_u64) +{ + SDL_Color col = uint64_to_color(col_u64); + SDL_SetRenderDrawColor(r, col.r, col.g, col.b, col.a); } static void draw_clear(SDL_Renderer* r, uint64_t bg) @@ -358,6 +365,25 @@ static void draw_glyph(SDL_Renderer* r, const struct ax_glyph* gl) }); break; + case AX_GLYPH_TEXT: { + SDL_Surface* surf = + TTF_RenderText_Blended( + gl->d.text.h->font, + gl->d.text.t, + uint64_to_color(gl->d.text.f)); + SDL_Texture* text = + SDL_CreateTextureFromSurface(r, surf); + SDL_Rect dst; + dst.x = gl->d.text.x; + dst.y = gl->d.text.y; + dst.w = surf->w; + dst.h = surf->h; + SDL_RenderCopy(r, text, NULL, &dst); + SDL_DestroyTexture(text); + SDL_FreeSurface(surf); + break; + } + default: { enum ax_glyph_type val = gl->ty; const char* str; diff --git a/src/ctxt/window.c b/src/ctxt/window.c index e718107..d3c5255 100644 --- a/src/ctxt/window.c +++ b/src/ctxt/window.c @@ -74,4 +74,20 @@ void ax__window_draw_demo( g->d.rect.w = 150; g->d.rect.h = 400; g->d.rect.f = 0x4444ff; + + g = ax__graphics_push(gr); + g->ty = AX_GLYPH_TEXT; + g->d.text.x = 40; + g->d.text.y = 40; + g->d.text.f = 0x000000; + g->d.text.h = ax__theme_font_handle(thm, AX_FONT_H1); + g->d.text.t = "Hello,"; + + g = ax__graphics_push(gr); + g->ty = AX_GLYPH_TEXT; + g->d.text.x = 100; + g->d.text.y = 200; + g->d.text.f = 0x000000; + g->d.text.h = ax__theme_font_handle(thm, AX_FONT_H2); + g->d.text.t = "world!"; } diff --git a/src/geom/graphics.enums b/src/geom/graphics.enums index 2e2cbf2..21be88d 100644 --- a/src/geom/graphics.enums +++ b/src/geom/graphics.enums @@ -1 +1,2 @@ -[glyph (AX_GLYPH_RECT "rect")] \ No newline at end of file +[glyph (AX_GLYPH_RECT "rect") + (AX_GLYPH_TEXT "text")] diff --git a/src/geom/graphics.h b/src/geom/graphics.h index dbddb95..04c8756 100644 --- a/src/geom/graphics.h +++ b/src/geom/graphics.h @@ -4,9 +4,11 @@ #include struct rgn; +struct ax_font_h; enum ax_glyph_type { AX_GLYPH_RECT = 0, + AX_GLYPH_TEXT, AX_GLYPH__COUNT, }; @@ -16,10 +18,18 @@ struct ax_glyph_rect { uint64_t f; }; +struct ax_glyph_text { + int32_t x, y; + struct ax_font_h* h; + const char* t; + uint64_t f; +}; + struct ax_glyph { enum ax_glyph_type ty; union { struct ax_glyph_rect rect; + struct ax_glyph_text text; } d; };