gui_label() now uses slice udata for text color
parent
59dc726038
commit
6c272811ab
14
bind/v4k.lua
14
bind/v4k.lua
|
@ -1546,9 +1546,9 @@ ffi.cdef([[
|
|||
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:STATIC void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in: void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void gui_label_id(int id, const char *text, vec4 rect);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:STATIC void gui_label_id(int id, const char *text, vec4 rect);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in: void gui_label_id(int id, const char *text, vec4 rect);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:STATIC void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in: void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:API bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in:STATIC bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
//lcpp INF [0000] vec4: macro name but used as C declaration in: bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
|
@ -3320,6 +3320,8 @@ vec4 bounds;
|
|||
bool has_9slice;
|
||||
vec4 core;
|
||||
vec2 pivot;
|
||||
unsigned color;
|
||||
char *text;
|
||||
} atlas_slice_frame_t;
|
||||
typedef struct atlas_slice_t {
|
||||
unsigned name;
|
||||
|
@ -3351,7 +3353,7 @@ unsigned play;
|
|||
bool paused;
|
||||
struct atlas_t *a;
|
||||
} sprite_t;
|
||||
enum { OBJTYPE_sprite_t = 10 }; typedef struct { unsigned static_assert_on_L__LINE__ : !!(10 <= 255); } static_assert_on_Lconcat(_L,3975)___COUNTER__; typedef struct { unsigned static_assert_on_L__LINE__ : !!(sizeof(sprite_t)); } static_assert_on_Lconcat(_L,3975)___COUNTER__;;
|
||||
enum { OBJTYPE_sprite_t = 10 }; typedef struct { unsigned static_assert_on_L__LINE__ : !!(10 <= 255); } static_assert_on_Lconcat(_L,3977)___COUNTER__; typedef struct { unsigned static_assert_on_L__LINE__ : !!(sizeof(sprite_t)); } static_assert_on_Lconcat(_L,3977)___COUNTER__;;
|
||||
void sprite_ctor(sprite_t *s);
|
||||
void sprite_dtor(sprite_t *s);
|
||||
void sprite_tick(sprite_t *s);
|
||||
|
@ -3363,6 +3365,7 @@ enum { OBJTYPE_sprite_t = 10 }; typedef struct { unsigned static_assert_on
|
|||
typedef struct guiskin_t {
|
||||
void (*drawrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*getskinsize)(void* userdata, const char *skin, const char *fallback, vec2 *size);
|
||||
void (*getskincolor)(void* userdata, const char *skin, const char *fallback, unsigned *color);
|
||||
void (*getscissorrect)(void* userdata, const char *skin, const char *fallback, vec4 rect, vec4 *dims);
|
||||
bool (*ismouseinrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*free)(void* userdata);
|
||||
|
@ -3371,11 +3374,12 @@ void *userdata;
|
|||
void gui_pushskin(guiskin_t skin);
|
||||
void* gui_userdata();
|
||||
vec2 gui_getskinsize(const char *skin, const char *fallback);
|
||||
unsigned gui_getskincolor(const char *skin, const char *fallback);
|
||||
bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect);
|
||||
vec4 gui_getscissorrect(const char *skin, const char *fallback, vec4 rect);
|
||||
void gui_panel_id(int id, vec4 rect, const char *skin);
|
||||
void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
void gui_label_id(int id, const char *text, vec4 rect);
|
||||
void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin);
|
||||
bool gui_slider_id(int id, vec4 rect, const char *skin, float min, float max, float step, float *value);
|
||||
|
|
|
@ -18094,6 +18094,8 @@ typedef struct atlas_slice_frame_t {
|
|||
bool has_9slice;
|
||||
vec4 core;
|
||||
vec2 pivot;
|
||||
unsigned color;
|
||||
char *text;
|
||||
} atlas_slice_frame_t;
|
||||
|
||||
typedef struct atlas_slice_t {
|
||||
|
@ -18156,6 +18158,7 @@ API void sprite_setanim(sprite_t *s, unsigned name);
|
|||
typedef struct guiskin_t {
|
||||
void (*drawrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*getskinsize)(void* userdata, const char *skin, const char *fallback, vec2 *size);
|
||||
void (*getskincolor)(void* userdata, const char *skin, const char *fallback, unsigned *color);
|
||||
void (*getscissorrect)(void* userdata, const char *skin, const char *fallback, vec4 rect, vec4 *dims);
|
||||
bool (*ismouseinrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*free)(void* userdata);
|
||||
|
@ -18165,12 +18168,13 @@ typedef struct guiskin_t {
|
|||
API void gui_pushskin(guiskin_t skin);
|
||||
API void* gui_userdata();
|
||||
API vec2 gui_getskinsize(const char *skin, const char *fallback);
|
||||
API unsigned gui_getskincolor(const char *skin, const char *fallback);
|
||||
API bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect);
|
||||
API vec4 gui_getscissorrect(const char *skin, const char *fallback, vec4 rect);
|
||||
// --
|
||||
API void gui_panel_id(int id, vec4 rect, const char *skin);
|
||||
API void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
API void gui_label_id(int id, const char *text, vec4 rect);
|
||||
API void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
API bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
API bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin);
|
||||
API bool gui_slider_id(int id, vec4 rect, const char *skin, float min, float max, float step, float *value);
|
||||
|
@ -360941,6 +360945,12 @@ vec2 gui_getskinsize(const char *skin, const char *fallback) {
|
|||
return size;
|
||||
}
|
||||
|
||||
unsigned gui_getskincolor(const char *skin, const char *fallback) {
|
||||
unsigned color = 0xFFFFFFFF;
|
||||
if (last_skin->getskincolor) last_skin->getskincolor(last_skin->userdata, skin, fallback, &color);
|
||||
return color;
|
||||
}
|
||||
|
||||
bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect) {
|
||||
if (last_skin->ismouseinrect) return last_skin->ismouseinrect(last_skin->userdata, skin, fallback, rect);
|
||||
return false;
|
||||
|
@ -361020,11 +361030,10 @@ bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin)
|
|||
buttonsize = gui_getskinsize(btn, skin);
|
||||
|
||||
vec2 textsize = font_rect(text);
|
||||
vec2 pos;
|
||||
vec4 pos;
|
||||
pos.x = rect.x + max(buttonsize.x*.5f, rect.z*.5f) - textsize.x*.5f;
|
||||
pos.y = rect.y + max(buttonsize.y*.5f, rect.w*.5f) - textsize.y*.5f;
|
||||
font_goto(pos.x, pos.y);
|
||||
font_print(text);
|
||||
gui_label(btn, text, pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -361092,11 +361101,10 @@ bool gui_slider_label_id(int id, const char *text, vec4 rect, const char *skin,
|
|||
slidersize = gui_getskinsize(skin, NULL);
|
||||
|
||||
vec2 textsize = font_rect(text);
|
||||
vec2 pos;
|
||||
vec4 pos;
|
||||
pos.x = rect.x + max(slidersize.x, rect.z) + 8 /*padding*/;
|
||||
pos.y = rect.y + max(slidersize.y*.5f, rect.w*.5f) - textsize.y*.5f;
|
||||
font_goto(pos.x, pos.y);
|
||||
font_print(text);
|
||||
gui_label(skin, text, pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -361105,10 +361113,11 @@ void gui_rect_id(int id, vec4 r, const char *skin) {
|
|||
if (last_skin->drawrect) last_skin->drawrect(last_skin->userdata, skin, NULL, r);
|
||||
}
|
||||
|
||||
void gui_label_id(int id, const char *text, vec4 rect) {
|
||||
void gui_label_id(int id, const char *skin, const char *text, vec4 rect) {
|
||||
(void)id;
|
||||
font_color(FONT_COLOR6, gui_getskincolor(skin, NULL));
|
||||
font_goto(rect.x, rect.y);
|
||||
font_print(text);
|
||||
font_print(va(FONT_COLOR6 "%s", text));
|
||||
}
|
||||
|
||||
/* skinned */
|
||||
|
@ -361130,6 +361139,16 @@ atlas_slice_frame_t *skinned_getsliceframe(atlas_t *a, const char *name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void skinned_getskincolor(void *userdata, const char *skin, const char *fallback, unsigned *color) {
|
||||
skinned_t *a = C_CAST(skinned_t*, userdata);
|
||||
atlas_slice_frame_t *f = skinned_getsliceframe(&a->atlas, skin);
|
||||
if (!f && fallback) f = skinned_getsliceframe(&a->atlas, fallback);
|
||||
if (!f) return;
|
||||
|
||||
if (f->text && f->text[0] == '#') *color = atorgba(f->text);
|
||||
}
|
||||
|
||||
static
|
||||
void skinned_draw_missing_rect(vec4 r) {
|
||||
vec4 size = vec4(0, 0, texture_checker().w, texture_checker().h);
|
||||
|
@ -361273,6 +361292,7 @@ guiskin_t gui_skinned(const char *asefile, float scale) {
|
|||
skin.userdata = a;
|
||||
skin.drawrect = skinned_draw_rect;
|
||||
skin.getskinsize = skinned_getskinsize;
|
||||
skin.getskincolor = skinned_getskincolor;
|
||||
skin.ismouseinrect = skinned_ismouseinrect;
|
||||
skin.getscissorrect = skinned_getscissorrect;
|
||||
skin.free = skinned_free;
|
||||
|
@ -373351,7 +373371,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
|||
ini_t kv = ini(inifile);
|
||||
for each_map(kv, char*,k, char*,v ) {
|
||||
unsigned index = atoi(k);
|
||||
// printf("aaa %s=%s\n", k, v);
|
||||
// printf("entry %s=%s\n", k, v);
|
||||
/**/ if( strend(k, ".name") ) {
|
||||
array_reserve_(a.anims, index);
|
||||
|
||||
|
@ -373401,6 +373421,18 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
|||
|
||||
a.slice_frames[index].pivot = vec2(x,y);
|
||||
}
|
||||
else if ( strend(k, ".sl_color") ) {
|
||||
array_reserve_(a.slice_frames, index);
|
||||
|
||||
unsigned color;
|
||||
sscanf(v, "%u", &color);
|
||||
|
||||
a.slice_frames[index].color = color;
|
||||
}
|
||||
else if ( strend(k, ".sl_text") ) {
|
||||
array_reserve_(a.slice_frames, index);
|
||||
a.slice_frames[index].text = STRDUP(v);
|
||||
}
|
||||
else if( strend(k, ".frames") ) {
|
||||
array_reserve_(a.anims, index);
|
||||
|
||||
|
|
|
@ -1149,6 +1149,7 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
|
|||
last_udata->text = s_read_string(s);
|
||||
}
|
||||
if (flags & 2) { //< @zpl-zak: removed else
|
||||
last_udata->has_color = 1;
|
||||
last_udata->color.r = s_read_uint8(s);
|
||||
last_udata->color.g = s_read_uint8(s);
|
||||
last_udata->color.b = s_read_uint8(s);
|
||||
|
|
|
@ -218,6 +218,10 @@ static vec2 atlas__itof2(const s2o_point p)
|
|||
return vec2((float)p.x, (float)p.y);
|
||||
}
|
||||
|
||||
static unsigned atlas__rgba( uint8_t r, uint8_t g, uint8_t b, uint8_t a ) {
|
||||
return (unsigned)a << 24 | b << 16 | g << 8 | r;
|
||||
}
|
||||
|
||||
// modified version of:
|
||||
// https://github.com/anael-seghezzi/Maratis-Tiny-C-library/blob/master/include/m_raster.h
|
||||
static bool atlas__test_line(const uint8_t* buffer, int w, int h, s2o_point p0, s2o_point p1)
|
||||
|
@ -702,6 +706,11 @@ atlas_t* atlas_loadfiles(array(char*) files, atlas_flags flags)
|
|||
strcatf(&atlas_slices, "[%d].sl_core=%d,%d,%d,%d\n", slice_idx, slice->center_x, slice->center_y, slice->center_w, slice->center_h);
|
||||
if (slice->has_pivot)
|
||||
strcatf(&atlas_slices, "[%d].sl_pivot=%d,%d\n", slice_idx, slice->pivot_x, slice->pivot_y);
|
||||
if (slice->udata.has_color)
|
||||
strcatf(&atlas_slices, "[%d].sl_color=%u\n", slice_idx, atlas__rgba(slice->udata.color.r, slice->udata.color.g, slice->udata.color.b, slice->udata.color.a));
|
||||
if (slice->udata.has_text)
|
||||
strcatf(&atlas_slices, "[%d].sl_text=%s\n", slice_idx, slice->udata.text);
|
||||
|
||||
slice_name = slice->name;
|
||||
++slice_frame_idx;
|
||||
}
|
||||
|
|
|
@ -124,6 +124,12 @@ vec2 gui_getskinsize(const char *skin, const char *fallback) {
|
|||
return size;
|
||||
}
|
||||
|
||||
unsigned gui_getskincolor(const char *skin, const char *fallback) {
|
||||
unsigned color = 0xFFFFFFFF;
|
||||
if (last_skin->getskincolor) last_skin->getskincolor(last_skin->userdata, skin, fallback, &color);
|
||||
return color;
|
||||
}
|
||||
|
||||
bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect) {
|
||||
if (last_skin->ismouseinrect) return last_skin->ismouseinrect(last_skin->userdata, skin, fallback, rect);
|
||||
return false;
|
||||
|
@ -203,11 +209,10 @@ bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin)
|
|||
buttonsize = gui_getskinsize(btn, skin);
|
||||
|
||||
vec2 textsize = font_rect(text);
|
||||
vec2 pos;
|
||||
vec4 pos;
|
||||
pos.x = rect.x + max(buttonsize.x*.5f, rect.z*.5f) - textsize.x*.5f;
|
||||
pos.y = rect.y + max(buttonsize.y*.5f, rect.w*.5f) - textsize.y*.5f;
|
||||
font_goto(pos.x, pos.y);
|
||||
font_print(text);
|
||||
gui_label(btn, text, pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -275,11 +280,10 @@ bool gui_slider_label_id(int id, const char *text, vec4 rect, const char *skin,
|
|||
slidersize = gui_getskinsize(skin, NULL);
|
||||
|
||||
vec2 textsize = font_rect(text);
|
||||
vec2 pos;
|
||||
vec4 pos;
|
||||
pos.x = rect.x + max(slidersize.x, rect.z) + 8 /*padding*/;
|
||||
pos.y = rect.y + max(slidersize.y*.5f, rect.w*.5f) - textsize.y*.5f;
|
||||
font_goto(pos.x, pos.y);
|
||||
font_print(text);
|
||||
gui_label(skin, text, pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -288,10 +292,11 @@ void gui_rect_id(int id, vec4 r, const char *skin) {
|
|||
if (last_skin->drawrect) last_skin->drawrect(last_skin->userdata, skin, NULL, r);
|
||||
}
|
||||
|
||||
void gui_label_id(int id, const char *text, vec4 rect) {
|
||||
void gui_label_id(int id, const char *skin, const char *text, vec4 rect) {
|
||||
(void)id;
|
||||
font_color(FONT_COLOR6, gui_getskincolor(skin, NULL));
|
||||
font_goto(rect.x, rect.y);
|
||||
font_print(text);
|
||||
font_print(va(FONT_COLOR6 "%s", text));
|
||||
}
|
||||
|
||||
/* skinned */
|
||||
|
@ -313,6 +318,16 @@ atlas_slice_frame_t *skinned_getsliceframe(atlas_t *a, const char *name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void skinned_getskincolor(void *userdata, const char *skin, const char *fallback, unsigned *color) {
|
||||
skinned_t *a = C_CAST(skinned_t*, userdata);
|
||||
atlas_slice_frame_t *f = skinned_getsliceframe(&a->atlas, skin);
|
||||
if (!f && fallback) f = skinned_getsliceframe(&a->atlas, fallback);
|
||||
if (!f) return;
|
||||
|
||||
if (f->text && f->text[0] == '#') *color = atorgba(f->text);
|
||||
}
|
||||
|
||||
static
|
||||
void skinned_draw_missing_rect(vec4 r) {
|
||||
vec4 size = vec4(0, 0, texture_checker().w, texture_checker().h);
|
||||
|
@ -456,6 +471,7 @@ guiskin_t gui_skinned(const char *asefile, float scale) {
|
|||
skin.userdata = a;
|
||||
skin.drawrect = skinned_draw_rect;
|
||||
skin.getskinsize = skinned_getskinsize;
|
||||
skin.getskincolor = skinned_getskincolor;
|
||||
skin.ismouseinrect = skinned_ismouseinrect;
|
||||
skin.getscissorrect = skinned_getscissorrect;
|
||||
skin.free = skinned_free;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
typedef struct guiskin_t {
|
||||
void (*drawrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*getskinsize)(void* userdata, const char *skin, const char *fallback, vec2 *size);
|
||||
void (*getskincolor)(void* userdata, const char *skin, const char *fallback, unsigned *color);
|
||||
void (*getscissorrect)(void* userdata, const char *skin, const char *fallback, vec4 rect, vec4 *dims);
|
||||
bool (*ismouseinrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*free)(void* userdata);
|
||||
|
@ -13,12 +14,13 @@ typedef struct guiskin_t {
|
|||
API void gui_pushskin(guiskin_t skin);
|
||||
API void* gui_userdata();
|
||||
API vec2 gui_getskinsize(const char *skin, const char *fallback);
|
||||
API unsigned gui_getskincolor(const char *skin, const char *fallback);
|
||||
API bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect);
|
||||
API vec4 gui_getscissorrect(const char *skin, const char *fallback, vec4 rect);
|
||||
// --
|
||||
API void gui_panel_id(int id, vec4 rect, const char *skin);
|
||||
API void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
API void gui_label_id(int id, const char *text, vec4 rect);
|
||||
API void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
API bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
API bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin);
|
||||
API bool gui_slider_id(int id, vec4 rect, const char *skin, float min, float max, float step, float *value);
|
||||
|
|
|
@ -1235,7 +1235,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
|||
ini_t kv = ini(inifile);
|
||||
for each_map(kv, char*,k, char*,v ) {
|
||||
unsigned index = atoi(k);
|
||||
// printf("aaa %s=%s\n", k, v);
|
||||
// printf("entry %s=%s\n", k, v);
|
||||
/**/ if( strend(k, ".name") ) {
|
||||
array_reserve_(a.anims, index);
|
||||
|
||||
|
@ -1285,6 +1285,18 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
|||
|
||||
a.slice_frames[index].pivot = vec2(x,y);
|
||||
}
|
||||
else if ( strend(k, ".sl_color") ) {
|
||||
array_reserve_(a.slice_frames, index);
|
||||
|
||||
unsigned color;
|
||||
sscanf(v, "%u", &color);
|
||||
|
||||
a.slice_frames[index].color = color;
|
||||
}
|
||||
else if ( strend(k, ".sl_text") ) {
|
||||
array_reserve_(a.slice_frames, index);
|
||||
a.slice_frames[index].text = STRDUP(v);
|
||||
}
|
||||
else if( strend(k, ".frames") ) {
|
||||
array_reserve_(a.anims, index);
|
||||
|
||||
|
|
|
@ -102,6 +102,8 @@ typedef struct atlas_slice_frame_t {
|
|||
bool has_9slice;
|
||||
vec4 core;
|
||||
vec2 pivot;
|
||||
unsigned color;
|
||||
char *text;
|
||||
} atlas_slice_frame_t;
|
||||
|
||||
typedef struct atlas_slice_t {
|
||||
|
|
46
engine/v4k.c
46
engine/v4k.c
|
@ -11233,6 +11233,12 @@ vec2 gui_getskinsize(const char *skin, const char *fallback) {
|
|||
return size;
|
||||
}
|
||||
|
||||
unsigned gui_getskincolor(const char *skin, const char *fallback) {
|
||||
unsigned color = 0xFFFFFFFF;
|
||||
if (last_skin->getskincolor) last_skin->getskincolor(last_skin->userdata, skin, fallback, &color);
|
||||
return color;
|
||||
}
|
||||
|
||||
bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect) {
|
||||
if (last_skin->ismouseinrect) return last_skin->ismouseinrect(last_skin->userdata, skin, fallback, rect);
|
||||
return false;
|
||||
|
@ -11312,11 +11318,10 @@ bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin)
|
|||
buttonsize = gui_getskinsize(btn, skin);
|
||||
|
||||
vec2 textsize = font_rect(text);
|
||||
vec2 pos;
|
||||
vec4 pos;
|
||||
pos.x = rect.x + max(buttonsize.x*.5f, rect.z*.5f) - textsize.x*.5f;
|
||||
pos.y = rect.y + max(buttonsize.y*.5f, rect.w*.5f) - textsize.y*.5f;
|
||||
font_goto(pos.x, pos.y);
|
||||
font_print(text);
|
||||
gui_label(btn, text, pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -11384,11 +11389,10 @@ bool gui_slider_label_id(int id, const char *text, vec4 rect, const char *skin,
|
|||
slidersize = gui_getskinsize(skin, NULL);
|
||||
|
||||
vec2 textsize = font_rect(text);
|
||||
vec2 pos;
|
||||
vec4 pos;
|
||||
pos.x = rect.x + max(slidersize.x, rect.z) + 8 /*padding*/;
|
||||
pos.y = rect.y + max(slidersize.y*.5f, rect.w*.5f) - textsize.y*.5f;
|
||||
font_goto(pos.x, pos.y);
|
||||
font_print(text);
|
||||
gui_label(skin, text, pos);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -11397,10 +11401,11 @@ void gui_rect_id(int id, vec4 r, const char *skin) {
|
|||
if (last_skin->drawrect) last_skin->drawrect(last_skin->userdata, skin, NULL, r);
|
||||
}
|
||||
|
||||
void gui_label_id(int id, const char *text, vec4 rect) {
|
||||
void gui_label_id(int id, const char *skin, const char *text, vec4 rect) {
|
||||
(void)id;
|
||||
font_color(FONT_COLOR6, gui_getskincolor(skin, NULL));
|
||||
font_goto(rect.x, rect.y);
|
||||
font_print(text);
|
||||
font_print(va(FONT_COLOR6 "%s", text));
|
||||
}
|
||||
|
||||
/* skinned */
|
||||
|
@ -11422,6 +11427,16 @@ atlas_slice_frame_t *skinned_getsliceframe(atlas_t *a, const char *name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void skinned_getskincolor(void *userdata, const char *skin, const char *fallback, unsigned *color) {
|
||||
skinned_t *a = C_CAST(skinned_t*, userdata);
|
||||
atlas_slice_frame_t *f = skinned_getsliceframe(&a->atlas, skin);
|
||||
if (!f && fallback) f = skinned_getsliceframe(&a->atlas, fallback);
|
||||
if (!f) return;
|
||||
|
||||
if (f->text && f->text[0] == '#') *color = atorgba(f->text);
|
||||
}
|
||||
|
||||
static
|
||||
void skinned_draw_missing_rect(vec4 r) {
|
||||
vec4 size = vec4(0, 0, texture_checker().w, texture_checker().h);
|
||||
|
@ -11565,6 +11580,7 @@ guiskin_t gui_skinned(const char *asefile, float scale) {
|
|||
skin.userdata = a;
|
||||
skin.drawrect = skinned_draw_rect;
|
||||
skin.getskinsize = skinned_getskinsize;
|
||||
skin.getskincolor = skinned_getskincolor;
|
||||
skin.ismouseinrect = skinned_ismouseinrect;
|
||||
skin.getscissorrect = skinned_getscissorrect;
|
||||
skin.free = skinned_free;
|
||||
|
@ -23643,7 +23659,7 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
|||
ini_t kv = ini(inifile);
|
||||
for each_map(kv, char*,k, char*,v ) {
|
||||
unsigned index = atoi(k);
|
||||
// printf("aaa %s=%s\n", k, v);
|
||||
// printf("entry %s=%s\n", k, v);
|
||||
/**/ if( strend(k, ".name") ) {
|
||||
array_reserve_(a.anims, index);
|
||||
|
||||
|
@ -23693,6 +23709,18 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
|
|||
|
||||
a.slice_frames[index].pivot = vec2(x,y);
|
||||
}
|
||||
else if ( strend(k, ".sl_color") ) {
|
||||
array_reserve_(a.slice_frames, index);
|
||||
|
||||
unsigned color;
|
||||
sscanf(v, "%u", &color);
|
||||
|
||||
a.slice_frames[index].color = color;
|
||||
}
|
||||
else if ( strend(k, ".sl_text") ) {
|
||||
array_reserve_(a.slice_frames, index);
|
||||
a.slice_frames[index].text = STRDUP(v);
|
||||
}
|
||||
else if( strend(k, ".frames") ) {
|
||||
array_reserve_(a.anims, index);
|
||||
|
||||
|
|
|
@ -4161,6 +4161,8 @@ typedef struct atlas_slice_frame_t {
|
|||
bool has_9slice;
|
||||
vec4 core;
|
||||
vec2 pivot;
|
||||
unsigned color;
|
||||
char *text;
|
||||
} atlas_slice_frame_t;
|
||||
|
||||
typedef struct atlas_slice_t {
|
||||
|
@ -4223,6 +4225,7 @@ API void sprite_setanim(sprite_t *s, unsigned name);
|
|||
typedef struct guiskin_t {
|
||||
void (*drawrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*getskinsize)(void* userdata, const char *skin, const char *fallback, vec2 *size);
|
||||
void (*getskincolor)(void* userdata, const char *skin, const char *fallback, unsigned *color);
|
||||
void (*getscissorrect)(void* userdata, const char *skin, const char *fallback, vec4 rect, vec4 *dims);
|
||||
bool (*ismouseinrect)(void* userdata, const char *skin, const char *fallback, vec4 rect);
|
||||
void (*free)(void* userdata);
|
||||
|
@ -4232,12 +4235,13 @@ typedef struct guiskin_t {
|
|||
API void gui_pushskin(guiskin_t skin);
|
||||
API void* gui_userdata();
|
||||
API vec2 gui_getskinsize(const char *skin, const char *fallback);
|
||||
API unsigned gui_getskincolor(const char *skin, const char *fallback);
|
||||
API bool gui_ismouseinrect(const char *skin, const char *fallback, vec4 rect);
|
||||
API vec4 gui_getscissorrect(const char *skin, const char *fallback, vec4 rect);
|
||||
// --
|
||||
API void gui_panel_id(int id, vec4 rect, const char *skin);
|
||||
API void gui_rect_id(int id, vec4 rect, const char *skin);
|
||||
API void gui_label_id(int id, const char *text, vec4 rect);
|
||||
API void gui_label_id(int id, const char *skin, const char *text, vec4 rect);
|
||||
API bool gui_button_id(int id, vec4 rect, const char *skin);
|
||||
API bool gui_button_label_id(int id, const char *text, vec4 rect, const char *skin);
|
||||
API bool gui_slider_id(int id, vec4 rect, const char *skin, float min, float max, float step, float *value);
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue