[sdl] draw glyphs in SDL
This commit is contained in:
parent
bf8bcd7017
commit
60a1516215
|
@ -7,6 +7,7 @@
|
||||||
#include "../concurrent/msg.h"
|
#include "../concurrent/msg.h"
|
||||||
#include "../concurrent/msgq.h"
|
#include "../concurrent/msgq.h"
|
||||||
#include "../concurrent/pubsub.h"
|
#include "../concurrent/pubsub.h"
|
||||||
|
#include "../geom/graphics.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
@ -298,17 +299,67 @@ fail:
|
||||||
ASSERT(rv == 0, "error: %s", SDL_GetError());
|
ASSERT(rv == 0, "error: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Rendering
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void draw_clear(SDL_Renderer* r, uint64_t bg);
|
||||||
|
static void draw_glyph(SDL_Renderer* r, const struct ax_glyph* gl);
|
||||||
|
|
||||||
static void render_windows(struct window_list* wl)
|
static void render_windows(struct window_list* wl)
|
||||||
{
|
{
|
||||||
for (; wl != NULL; wl = wl->next) {
|
for (; wl != NULL; wl = wl->next) {
|
||||||
// SDL_Window* sdl_win = wl->handle->win;
|
|
||||||
SDL_Renderer* r = wl->handle->rnd;
|
SDL_Renderer* r = wl->handle->rnd;
|
||||||
SDL_SetRenderDrawColor(r, 255, 255, 255, 255);
|
|
||||||
SDL_RenderClear(r);
|
pthread_mutex_lock(&wl->win->mx);
|
||||||
|
struct ax_graphics* gr = wl->win->graphics;
|
||||||
|
draw_clear(r, gr->bg);
|
||||||
|
for (size_t i = 0; i < ax__graphics_glyph_count(gr); i++) {
|
||||||
|
draw_glyph(r, ax__graphics_glyph(gr, i));
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&wl->win->mx);
|
||||||
|
|
||||||
SDL_RenderPresent(r);
|
SDL_RenderPresent(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void draw_set_color(SDL_Renderer* r, uint64_t col)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(r,
|
||||||
|
(col & 0xff0000) >> 16,
|
||||||
|
(col & 0x00ff00) >> 8,
|
||||||
|
(col & 0x0000ff) >> 0,
|
||||||
|
255);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_clear(SDL_Renderer* r, uint64_t bg)
|
||||||
|
{
|
||||||
|
draw_set_color(r, bg);
|
||||||
|
SDL_RenderClear(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_glyph(SDL_Renderer* r, const struct ax_glyph* gl)
|
||||||
|
{
|
||||||
|
switch (gl->ty) {
|
||||||
|
case AX_GLYPH_RECT:
|
||||||
|
draw_set_color(r, gl->d.rect.f);
|
||||||
|
SDL_RenderFillRect(r, &(SDL_Rect) {
|
||||||
|
.x = gl->d.rect.x,
|
||||||
|
.y = gl->d.rect.y,
|
||||||
|
.w = gl->d.rect.w,
|
||||||
|
.h = gl->d.rect.h
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: {
|
||||||
|
enum ax_glyph_type val = gl->ty;
|
||||||
|
const char* str;
|
||||||
|
#include "../../_build/glyph.printer.inc"
|
||||||
|
ASSERT(0, "unimplemented glyph type `%s'", str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Event handling
|
* Event handling
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
|
@ -35,7 +35,7 @@ static struct ax_window* make_window()
|
||||||
{
|
{
|
||||||
ax_begin_window(ax);
|
ax_begin_window(ax);
|
||||||
ax_set_window_title(ax, "Test App");
|
ax_set_window_title(ax, "Test App");
|
||||||
ax_set_window_size(ax, 1000, 400, false);
|
ax_set_window_size(ax, 800, 600, false);
|
||||||
return ax_end_window(ax);
|
return ax_end_window(ax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue