78 lines
1.8 KiB
C
78 lines
1.8 KiB
C
#include "window.h"
|
|
#include "../concurrent/msg.h"
|
|
#include "../concurrent/msgq.h"
|
|
#include "../geom/graphics.h"
|
|
#include "../ctxt/theme.h"
|
|
|
|
static inline const char* default_title(struct rgn* rgn)
|
|
{
|
|
return "Ax App";
|
|
}
|
|
|
|
static inline void default_size(uint64_t* out_w, uint64_t* out_h)
|
|
{
|
|
*out_w = 600;
|
|
*out_h = 400;
|
|
}
|
|
|
|
struct ax_window_builder* ax__window_builder_new(struct rgn* rgn)
|
|
{
|
|
struct ax_window_builder* winb =
|
|
ralloc_typed(rgn, struct ax_window_builder, 1);
|
|
winb->rgn = rgn;
|
|
winb->title = default_title(rgn);
|
|
default_size(&winb->w, &winb->h);
|
|
winb->flags = 0;
|
|
return winb;
|
|
}
|
|
|
|
struct ax_window* ax__window_builder_finish(
|
|
struct ax_window_builder* winb,
|
|
struct rgn* dst_rgn,
|
|
struct msgq* req_window_mq)
|
|
{
|
|
struct ax_window* win =
|
|
ralloc_typed(dst_rgn, struct ax_window, 1);
|
|
pthread_mutex_init(&win->mx, NULL);
|
|
rgn_pin(dst_rgn, &win->mx, (void*) pthread_mutex_destroy);
|
|
win->graphics = ax__graphics_new(dst_rgn);
|
|
// draw_demo(win->graphics);
|
|
|
|
struct ax_msg_make_window* m =
|
|
msgq_begin_send_typed(req_window_mq, ax_msg_make_window);
|
|
m->dst_win = win;
|
|
m->title = rstrdup(req_window_mq->msg_rgn, winb->title);
|
|
m->width = winb->w;
|
|
m->height = winb->h;
|
|
m->flags = winb->flags;
|
|
msgq_end_send(req_window_mq);
|
|
|
|
return win;
|
|
}
|
|
|
|
void ax__window_draw_demo(
|
|
struct ax_window* win,
|
|
struct ax_theme* thm)
|
|
{
|
|
struct ax_graphics* gr = win->graphics;
|
|
struct ax_glyph* g;
|
|
|
|
ax__graphics_clear(gr, 0xffffff);
|
|
|
|
g = ax__graphics_push(gr);
|
|
g->ty = AX_GLYPH_RECT;
|
|
g->d.rect.x = 5;
|
|
g->d.rect.y = 5;
|
|
g->d.rect.w = 300;
|
|
g->d.rect.h = 200;
|
|
g->d.rect.f = 0xcc0044;
|
|
|
|
g = ax__graphics_push(gr);
|
|
g->ty = AX_GLYPH_RECT;
|
|
g->d.rect.x = 75;
|
|
g->d.rect.y = 23;
|
|
g->d.rect.w = 150;
|
|
g->d.rect.h = 400;
|
|
g->d.rect.f = 0x4444ff;
|
|
}
|