115 lines
2.5 KiB
C
115 lines
2.5 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <pthread.h>
|
|
|
|
struct rgn;
|
|
struct msgq;
|
|
|
|
#define THEME_BUILDER_DESIRED_REGION_SIZE (16*1024)
|
|
|
|
enum ax_color_cat {
|
|
AX_COLOR_BACKGROUND = 0,
|
|
AX_COLOR_SURFACE,
|
|
AX_COLOR_PRIMARY,
|
|
AX_COLOR_PRIMARY_ALT,
|
|
AX_COLOR_SECONDARY,
|
|
AX_COLOR_SECONDARY_ALT,
|
|
AX_COLOR_ON_BACKGROUND,
|
|
AX_COLOR_ON_SURFACE,
|
|
AX_COLOR_ON_PRIMARY,
|
|
AX_COLOR_ON_SECONDARY,
|
|
AX_COLOR__COUNT,
|
|
};
|
|
|
|
enum ax_font_cat {
|
|
AX_FONT_H1 = 0,
|
|
AX_FONT_H2,
|
|
AX_FONT_H3,
|
|
AX_FONT_H4,
|
|
AX_FONT_BODY,
|
|
AX_FONT_BUTTON,
|
|
AX_FONT__COUNT,
|
|
AX_FONT__DEFAULT,
|
|
};
|
|
|
|
struct ax_font_h; // defined by backend
|
|
|
|
struct ax_theme {
|
|
const char* err;
|
|
int64_t color[AX_COLOR__COUNT];
|
|
size_t font_size[AX_FONT__COUNT];
|
|
const char* font_path[AX_FONT__COUNT];
|
|
struct ax_font_h* font_handle[AX_FONT__COUNT];
|
|
pthread_mutex_t handles_mx;
|
|
};
|
|
|
|
struct ax_theme_builder {
|
|
struct rgn* rgn;
|
|
const char* err;
|
|
const char* dflt_font_path;
|
|
int64_t color[AX_COLOR__COUNT];
|
|
size_t font_size[AX_FONT__COUNT];
|
|
const char* font_path[AX_FONT__COUNT];
|
|
};
|
|
|
|
int ax__string_to_color_cat(const char* str, enum ax_color_cat* out_cat);
|
|
int ax__string_to_font_cat(const char* str, enum ax_font_cat* out_cat);
|
|
|
|
struct ax_theme_builder* ax__theme_builder_new(struct rgn* rgn);
|
|
|
|
void ax__theme_set_color(
|
|
struct ax_theme_builder* thmb,
|
|
enum ax_color_cat cat,
|
|
int64_t val);
|
|
|
|
void ax__theme_set_font(
|
|
struct ax_theme_builder* thmb,
|
|
enum ax_font_cat cat,
|
|
const char* path, size_t size);
|
|
|
|
struct ax_theme* ax__theme_builder_finish(
|
|
struct ax_theme_builder* thmb,
|
|
struct rgn* dst_rgn);
|
|
|
|
static inline int64_t ax__theme_color(
|
|
struct ax_theme* thm,
|
|
enum ax_color_cat i)
|
|
{
|
|
return thm->color[i];
|
|
}
|
|
|
|
static inline const char* ax__theme_font(
|
|
struct ax_theme* thm,
|
|
enum ax_font_cat i,
|
|
size_t* out_size)
|
|
{
|
|
if (out_size != NULL) {
|
|
*out_size = thm->font_size[i];
|
|
}
|
|
return thm->font_path[i];
|
|
}
|
|
|
|
struct ax_font_h* ax__theme_font_handle(
|
|
struct ax_theme* thm,
|
|
enum ax_font_cat i);
|
|
|
|
bool ax__theme_is_loaded(
|
|
struct ax_theme* thm);
|
|
|
|
bool ax__theme_set_font_handle( // returns `true` if the font is now loaded
|
|
struct ax_theme* thm,
|
|
enum ax_font_cat i,
|
|
struct ax_font_h* h);
|
|
|
|
void ax__theme_request_load(
|
|
struct ax_theme* thm,
|
|
struct msgq* req_mq,
|
|
struct msgq* res_mq);
|
|
|
|
/*
|
|
void ax__debug_theme(struct ax_theme* thm);
|
|
*/
|