[graphics, sdl] text glyphs
This commit is contained in:
parent
b221fff192
commit
c5b22a0175
|
@ -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,
|
SDL_Color c;
|
||||||
(col & 0xff0000) >> 16,
|
c.a = 255;
|
||||||
(col & 0x00ff00) >> 8,
|
c.r = (col & 0xff0000) >> 16;
|
||||||
(col & 0x0000ff) >> 0,
|
c.g = (col & 0x00ff00) >> 8;
|
||||||
255);
|
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)
|
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;
|
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: {
|
default: {
|
||||||
enum ax_glyph_type val = gl->ty;
|
enum ax_glyph_type val = gl->ty;
|
||||||
const char* str;
|
const char* str;
|
||||||
|
|
|
@ -74,4 +74,20 @@ void ax__window_draw_demo(
|
||||||
g->d.rect.w = 150;
|
g->d.rect.w = 150;
|
||||||
g->d.rect.h = 400;
|
g->d.rect.h = 400;
|
||||||
g->d.rect.f = 0x4444ff;
|
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!";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
[glyph (AX_GLYPH_RECT "rect")]
|
[glyph (AX_GLYPH_RECT "rect")
|
||||||
|
(AX_GLYPH_TEXT "text")]
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct rgn;
|
struct rgn;
|
||||||
|
struct ax_font_h;
|
||||||
|
|
||||||
enum ax_glyph_type {
|
enum ax_glyph_type {
|
||||||
AX_GLYPH_RECT = 0,
|
AX_GLYPH_RECT = 0,
|
||||||
|
AX_GLYPH_TEXT,
|
||||||
AX_GLYPH__COUNT,
|
AX_GLYPH__COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,10 +18,18 @@ struct ax_glyph_rect {
|
||||||
uint64_t f;
|
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 {
|
struct ax_glyph {
|
||||||
enum ax_glyph_type ty;
|
enum ax_glyph_type ty;
|
||||||
union {
|
union {
|
||||||
struct ax_glyph_rect rect;
|
struct ax_glyph_rect rect;
|
||||||
|
struct ax_glyph_text text;
|
||||||
} d;
|
} d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue