parent
d964f03b0b
commit
5d96bf908d
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct rgn;
|
||||
|
||||
struct ax_backend;
|
||||
struct ax_font_h;
|
||||
|
||||
extern const char* ax__backend_impl_name;
|
||||
|
||||
struct ax_backend* ax__backend_new(
|
||||
struct rgn* init_rgn);
|
||||
|
||||
const char* ax__backend_get_error(
|
||||
struct ax_backend* bac);
|
|
@ -0,0 +1,21 @@
|
|||
#include "../backend.h"
|
||||
#include "../util/region.h"
|
||||
|
||||
struct ax_backend {
|
||||
};
|
||||
|
||||
const char* ax__backend_impl_name = "SDL";
|
||||
|
||||
struct ax_backend* ax__backend_new(
|
||||
struct rgn* init_rgn)
|
||||
{
|
||||
struct ax_backend* bac = ralloc_typed(init_rgn, struct ax_backend, 1);
|
||||
return bac;
|
||||
}
|
||||
|
||||
const char* ax__backend_get_error(
|
||||
struct ax_backend* bac)
|
||||
{
|
||||
(void) bac;
|
||||
return NULL;
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
struct ax_theme;
|
||||
struct ax_theme_builder;
|
||||
struct ax_backend;
|
||||
|
||||
struct ax_ctxt {
|
||||
struct rgn* init_rgn;
|
||||
|
@ -18,6 +19,9 @@ struct ax_ctxt {
|
|||
struct rgn err_rgn;
|
||||
const char* err;
|
||||
|
||||
// backend
|
||||
struct ax_backend* bac;
|
||||
|
||||
// theme
|
||||
struct rgn thmb_rgn;
|
||||
struct ax_theme_builder* thmb;
|
||||
|
@ -39,3 +43,5 @@ static inline void ax__set_error(struct ax_ctxt* ax, const char* text)
|
|||
{
|
||||
strcpy(ax__make_error_buf(ax, strlen(text) + 1), text);
|
||||
}
|
||||
|
||||
struct ax_backend* ax__backend(struct ax_ctxt* ax);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "../ax.h"
|
||||
#include "../backend.h"
|
||||
#include "../ctxt.h"
|
||||
#include "../util.h"
|
||||
#include "../ax.h"
|
||||
#include "theme.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
@ -47,6 +48,8 @@ void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* init_rgn)
|
|||
rgn_init(&ax->thmb_rgn, THEME_BUILDER_DESIRED_REGION_SIZE);
|
||||
ax->thmb = NULL;
|
||||
ax->sel_theme = NULL;
|
||||
|
||||
ax->bac = NULL;
|
||||
}
|
||||
|
||||
void ax__ctxt_cleanup(struct ax_ctxt* ax)
|
||||
|
@ -55,6 +58,20 @@ void ax__ctxt_cleanup(struct ax_ctxt* ax)
|
|||
rgn_cleanup(&ax->err_rgn);
|
||||
}
|
||||
|
||||
struct ax_backend* ax__backend(struct ax_ctxt* ax)
|
||||
{
|
||||
if (ax->bac == NULL) {
|
||||
struct rgn msg_rgn;
|
||||
rgn_init(&msg_rgn, SMALL);
|
||||
ax_log(ax, rsprintf(&msg_rgn, "initializing `%s' backend",
|
||||
ax__backend_impl_name));
|
||||
rgn_cleanup(&msg_rgn);
|
||||
|
||||
ax->bac = ax__backend_new(ax->init_rgn);
|
||||
}
|
||||
return ax->bac;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* API functions :: logging
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
@ -89,8 +106,16 @@ void ax_begin_theme(struct ax_ctxt* ax)
|
|||
void ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm)
|
||||
{
|
||||
ASSERT(ax->thmb != NULL, "`ax_end_theme' called while not building a theme");
|
||||
ax__theme_builder_finish(ax->thmb, ax->init_rgn, out_thm);
|
||||
|
||||
struct ax_theme* thm;
|
||||
ax__theme_builder_finish(ax->thmb, ax->init_rgn, &thm);
|
||||
rgn_clear(&ax->thmb_rgn);
|
||||
|
||||
(void) ax__backend(ax); // TODO: tell backend to load this theme
|
||||
|
||||
if (out_thm != NULL) {
|
||||
*out_thm = thm;
|
||||
}
|
||||
}
|
||||
|
||||
void ax_set_theme_color(
|
||||
|
|
|
@ -66,3 +66,11 @@ static inline char* rstrdup(struct rgn* rgn, const char* str)
|
|||
|
||||
#define rmemdup_typed(_rgn, T, _p, _n) \
|
||||
((T*) rmemdup(_rgn, _p, sizeof(T) * (_n)))
|
||||
|
||||
#define rsprintf(_rgn, ...) ({ \
|
||||
size_t sprintf__len = \
|
||||
snprintf(NULL, 0, __VA_ARGS__); \
|
||||
char* sprintf__msg = \
|
||||
ralloc_typed(_rgn, char, sprintf__len + 1); \
|
||||
sprintf(sprintf__msg, __VA_ARGS__); \
|
||||
sprintf__msg; })
|
||||
|
|
Loading…
Reference in New Issue