mirror of
https://github.com/nishiowo/nishbox
synced 2025-04-21 20:24:39 +00:00
add destroy method for gui
This commit is contained in:
parent
cecf28c5d8
commit
8a35bfbf18
@ -17,6 +17,7 @@
|
|||||||
#include <gf_type/draw.h>
|
#include <gf_type/draw.h>
|
||||||
|
|
||||||
/* Standard */
|
/* Standard */
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @~english
|
* @~english
|
||||||
@ -27,6 +28,17 @@
|
|||||||
*/
|
*/
|
||||||
GF_EXPORT gf_font_glyph_t* gf_font_get(gf_font_t* font, int code);
|
GF_EXPORT gf_font_glyph_t* gf_font_get(gf_font_t* font, int code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @~english
|
||||||
|
* @brief Load font
|
||||||
|
* @param draw Drawing interface
|
||||||
|
* @param path Path
|
||||||
|
* @param data Data
|
||||||
|
* @param size Data size
|
||||||
|
* @return Font
|
||||||
|
*/
|
||||||
|
GF_EXPORT gf_font_t* gf_font_create_raw(gf_draw_t* draw, const char* path, const void* data, size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @~english
|
* @~english
|
||||||
* @brief Load font
|
* @brief Load font
|
||||||
@ -36,4 +48,11 @@ GF_EXPORT gf_font_glyph_t* gf_font_get(gf_font_t* font, int code);
|
|||||||
*/
|
*/
|
||||||
GF_EXPORT gf_font_t* gf_font_create(gf_draw_t* draw, const char* path);
|
GF_EXPORT gf_font_t* gf_font_create(gf_draw_t* draw, const char* path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @~english
|
||||||
|
* @brief Destroy font
|
||||||
|
* @param font Font
|
||||||
|
*/
|
||||||
|
GF_EXPORT void gf_font_destroy(gf_font_t* font);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,10 +43,24 @@
|
|||||||
* @param engine Engine instance
|
* @param engine Engine instance
|
||||||
* @param draw Drawing interface
|
* @param draw Drawing interface
|
||||||
* @return GUI
|
* @return GUI
|
||||||
* @note You should not have to call this - simply use gf_draw_t::gui
|
|
||||||
*/
|
*/
|
||||||
GF_EXPORT gf_gui_t* gf_gui_create(gf_engine_t* engine, gf_draw_t* draw);
|
GF_EXPORT gf_gui_t* gf_gui_create(gf_engine_t* engine, gf_draw_t* draw);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @~english
|
||||||
|
* @brief Destroy GUI
|
||||||
|
* @param gui GUI
|
||||||
|
*/
|
||||||
|
GF_EXPORT void gf_gui_destroy(gf_gui_t* gui);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @~english
|
||||||
|
* @brief Destroy GUI component by ID
|
||||||
|
* @param gui GUI
|
||||||
|
* @param id Component ID
|
||||||
|
*/
|
||||||
|
GF_EXPORT void gf_gui_destroy_id(gf_gui_t* gui, gf_gui_id_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @~english
|
* @~english
|
||||||
* @brief Create button component
|
* @brief Create button component
|
||||||
|
@ -22,6 +22,26 @@ typedef struct gf_font_t gf_font_t;
|
|||||||
|
|
||||||
/* Standard */
|
/* Standard */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct gf_font_store_t
|
||||||
|
* @~english
|
||||||
|
* @brief Internal struct used for parsing
|
||||||
|
*
|
||||||
|
* @var gf_font_store_t::glyph_index
|
||||||
|
* @brief Current glyph index
|
||||||
|
*
|
||||||
|
* @var gf_font_store_t::glyph_index
|
||||||
|
* @brief Current line index of glyph
|
||||||
|
*
|
||||||
|
* @var gf_font_store_t::buffer
|
||||||
|
* @brief Glyph buffer
|
||||||
|
*/
|
||||||
|
GF_DECLARE_TYPE(font_store, {
|
||||||
|
int glyph_index;
|
||||||
|
int line_index;
|
||||||
|
unsigned char* buffer;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct gf_font_bbox_t
|
* @struct gf_font_bbox_t
|
||||||
* @~english
|
* @~english
|
||||||
|
@ -128,6 +128,9 @@ int gf_draw_step(gf_draw_t* draw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gf_draw_destroy(gf_draw_t* draw) {
|
void gf_draw_destroy(gf_draw_t* draw) {
|
||||||
|
if(draw->font != NULL) {
|
||||||
|
gf_font_destroy(draw->font);
|
||||||
|
}
|
||||||
if(draw->driver != NULL) gf_draw_driver_destroy(draw->driver);
|
if(draw->driver != NULL) gf_draw_driver_destroy(draw->driver);
|
||||||
if(draw->platform != NULL) gf_draw_platform_destroy(draw->platform);
|
if(draw->platform != NULL) gf_draw_platform_destroy(draw->platform);
|
||||||
gf_log_function(draw->engine, "Destroyed drawing interface", "");
|
gf_log_function(draw->engine, "Destroyed drawing interface", "");
|
||||||
|
@ -34,12 +34,6 @@ gf_font_glyph_t* gf_font_get(gf_font_t* font, int code) {
|
|||||||
#define gf_stat stat
|
#define gf_stat stat
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GF_DECLARE_TYPE(font_store, {
|
|
||||||
int glyph_index;
|
|
||||||
int line_index;
|
|
||||||
unsigned char* buffer;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a private method to parse BDF line
|
* This is a private method to parse BDF line
|
||||||
*/
|
*/
|
||||||
@ -138,27 +132,19 @@ void gf_font_parse_line(gf_draw_t* draw, const char* path, gf_font_store_t* stor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gf_font_t* gf_font_create(gf_draw_t* draw, const char* path) {
|
gf_font_t* gf_font_create_raw(gf_draw_t* draw, const char* path, const void* data, size_t size) {
|
||||||
gf_font_t* font = malloc(sizeof(*font));
|
gf_font_t* font = malloc(sizeof(*font));
|
||||||
struct gf_stat s;
|
|
||||||
char* buf;
|
char* buf;
|
||||||
FILE* f;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int incr = 0;
|
int incr = 0;
|
||||||
gf_font_store_t store;
|
gf_font_store_t store;
|
||||||
store.line_index = -1;
|
store.line_index = -1;
|
||||||
store.glyph_index = 0;
|
store.glyph_index = 0;
|
||||||
memset(font, 0, sizeof(*font));
|
memset(font, 0, sizeof(*font));
|
||||||
if(gf_stat(path, &s) != 0) {
|
|
||||||
free(font);
|
buf = malloc(size + 1);
|
||||||
return NULL;
|
buf[size] = 0;
|
||||||
}
|
memcpy(buf, data, size);
|
||||||
gf_log_function(NULL, "%s: %lu bytes", path, (unsigned long)s.st_size);
|
|
||||||
buf = malloc(s.st_size + 1);
|
|
||||||
buf[s.st_size] = 0;
|
|
||||||
f = fopen(path, "r");
|
|
||||||
fread(buf, s.st_size, 1, f);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
for(i = 0;; i++) {
|
for(i = 0;; i++) {
|
||||||
if(buf[i] == 0 || buf[i] == '\n') {
|
if(buf[i] == 0 || buf[i] == '\n') {
|
||||||
@ -176,3 +162,34 @@ gf_font_t* gf_font_create(gf_draw_t* draw, const char* path) {
|
|||||||
free(buf);
|
free(buf);
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gf_font_t* gf_font_create(gf_draw_t* draw, const char* path) {
|
||||||
|
FILE* f;
|
||||||
|
struct gf_stat s;
|
||||||
|
char* buf;
|
||||||
|
gf_font_t* font;
|
||||||
|
if(gf_stat(path, &s) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
gf_log_function(NULL, "%s: %lu bytes", path, (unsigned long)s.st_size);
|
||||||
|
buf = malloc(s.st_size + 1);
|
||||||
|
buf[s.st_size] = 0;
|
||||||
|
f = fopen(path, "r");
|
||||||
|
fread(buf, s.st_size, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
font = gf_font_create_raw(draw, path, buf, s.st_size);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gf_font_destroy(gf_font_t* font) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < font->count; i++) {
|
||||||
|
gf_texture_destroy(font->glyph[i]->texture);
|
||||||
|
}
|
||||||
|
free(font->glyph);
|
||||||
|
free(font);
|
||||||
|
}
|
||||||
|
@ -40,6 +40,26 @@ gf_gui_t* gf_gui_create(gf_engine_t* engine, gf_draw_t* draw) {
|
|||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gf_gui_destroy(gf_gui_t* gui) {
|
||||||
|
gf_gui_id_t i;
|
||||||
|
for(i = 0; i < GF_GUI_MAX_COMPONENTS; i++) {
|
||||||
|
gf_gui_destroy_id(gui, i);
|
||||||
|
}
|
||||||
|
gf_log_function(gui->engine, "Destroyed GUI", "");
|
||||||
|
free(gui);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gf_gui_destroy_id(gf_gui_t* gui, gf_gui_id_t id) {
|
||||||
|
gf_gui_component_t* c = &gui->area[id];
|
||||||
|
switch(c->type) {
|
||||||
|
case GF_GUI_BUTTON: {
|
||||||
|
if(c->u.button.text != NULL) free(c->u.button.text);
|
||||||
|
c->u.button.text = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c->type = GF_GUI_UNUSED;
|
||||||
|
}
|
||||||
|
|
||||||
/* note... left top should be the lightest in the border */
|
/* note... left top should be the lightest in the border */
|
||||||
|
|
||||||
void gf_gui_draw_box(gf_gui_t* gui, int mul, double x, double y, double w, double h) {
|
void gf_gui_draw_box(gf_gui_t* gui, int mul, double x, double y, double w, double h) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user