cleanup + image + text

This commit is contained in:
vurtun 2015-03-13 20:01:31 +01:00
parent 6df135829c
commit a80f80c141
3 changed files with 718 additions and 431 deletions

1052
gui.c

File diff suppressed because it is too large Load Diff

91
gui.h
View File

@ -8,21 +8,19 @@
/* /*
* ------------- TODO-List ------------ * ------------- TODO-List ------------
* - cleanup
* - widgets * - widgets
* o Text * o Input (1)
* o Text Wrapped
* o Image
* o Counter * o Counter
* o Image Button
* - panel * - panel
* o Group (4)
* o Border (3)
* o Moveable * o Moveable
* o Scaleable * o Scaleable
* o Scrollbar * o Scrollbar (2)
* o Tabs * o Tabs
* o Icon * o Icon
* o combobox * o combobox
* o listView * o listView (5)
* o treeView * o treeView
* o textBox * o textBox
* --------------------------------------- * ---------------------------------------
@ -44,6 +42,7 @@ typedef unsigned long gui_size;
typedef gui_char gui_glyph[GUI_UTF_SIZE]; typedef gui_char gui_glyph[GUI_UTF_SIZE];
enum {gui_false, gui_true}; enum {gui_false, gui_true};
enum gui_direction {GUI_UP, GUI_RIGHT, GUI_DOWN, GUI_LEFT};
struct gui_color {gui_byte r,g,b,a;}; struct gui_color {gui_byte r,g,b,a;};
struct gui_colorf {gui_float r,g,b,a;}; struct gui_colorf {gui_float r,g,b,a;};
struct gui_texCoord {gui_float u,v;}; struct gui_texCoord {gui_float u,v;};
@ -123,15 +122,21 @@ struct gui_text {
gui_size length; gui_size length;
struct gui_color font; struct gui_color font;
struct gui_color background; struct gui_color background;
struct gui_color foreground; };
struct gui_image {
gui_float x, y;
gui_float w, h;
gui_float pad_x, pad_y;
struct gui_texCoord uv[2];
gui_texture texture;
struct gui_color background;
}; };
struct gui_button { struct gui_button {
gui_float x, y; gui_float x, y;
gui_float w, h; gui_float w, h;
gui_float pad_x, pad_y; gui_float pad_x, pad_y;
const char *text;
gui_size length;
struct gui_color font; struct gui_color font;
struct gui_color background; struct gui_color background;
struct gui_color foreground; struct gui_color foreground;
@ -144,7 +149,7 @@ struct gui_toggle {
gui_float pad_x, pad_y; gui_float pad_x, pad_y;
gui_int active; gui_int active;
gui_size length; gui_size length;
const char *text; const gui_char *text;
struct gui_color font; struct gui_color font;
struct gui_color background; struct gui_color background;
struct gui_color foreground; struct gui_color foreground;
@ -182,12 +187,33 @@ struct gui_scroll {
struct gui_color foreground; struct gui_color foreground;
}; };
enum gui_input_flags {
GUI_INPUT_ALL = -1,
GUI_INPUT_INTEGER = 0x01,
GUI_INPUT_FLOAT = 0x02,
GUI_INPUT_LITERALS = 0x04,
};
struct gui_input_field { struct gui_input_field {
gui_float x, y; gui_float x, y;
gui_float w, h; gui_float w, h;
gui_float pad_x, pad_y; gui_float pad_x, pad_y;
gui_size max; gui_size max;
gui_bool active; gui_bool active;
gui_flags flags;
gui_bool password;
struct gui_color background;
struct gui_color foreground;
struct gui_color font;
};
struct gui_spinner {
gui_float x, y;
gui_float w, h;
gui_float pad_x, pad_y;
gui_bool active;
gui_float max;
gui_float min;
struct gui_color background; struct gui_color background;
struct gui_color foreground; struct gui_color foreground;
struct gui_color font; struct gui_color font;
@ -257,9 +283,12 @@ struct gui_config {
}; };
enum gui_panel_flags { enum gui_panel_flags {
GUI_PANEL_MINIMIZABLE = 0x01, GUI_PANEL_GROUP = 0x01,
GUI_PANEL_CLOSEABLE = 0x02, GUI_PANEL_HEADER = 0x02,
GUI_PANEL_SCROLLBAR = 0x04 GUI_PANEL_BORDER = 0x04,
GUI_PANEL_MINIMIZABLE = 0x08,
GUI_PANEL_CLOSEABLE = 0x10,
GUI_PANEL_SCROLLBAR = 0x20
}; };
struct gui_panel { struct gui_panel {
@ -277,11 +306,6 @@ struct gui_panel {
const struct gui_config *config; const struct gui_config *config;
}; };
/* Utility */
struct gui_color gui_make_color(gui_byte r, gui_byte g, gui_byte b, gui_byte a);
struct gui_vec2 gui_make_vec2(gui_float x, gui_float y);
void gui_default_config(struct gui_config *config);
/* Input */ /* Input */
void gui_input_begin(struct gui_input *in); void gui_input_begin(struct gui_input *in);
void gui_input_motion(struct gui_input *in, gui_int x, gui_int y); void gui_input_motion(struct gui_input *in, gui_int x, gui_int y);
@ -297,36 +321,51 @@ gui_size gui_end(struct gui_draw_buffer *buf);
/* Widgets */ /* Widgets */
void gui_text(struct gui_draw_buffer *buf, const struct gui_text *text, void gui_text(struct gui_draw_buffer *buf, const struct gui_text *text,
const struct gui_font *font); const struct gui_font *font);
void gui_text_wrap(struct gui_draw_buffer *buf, const struct gui_text *text, gui_size gui_text_wrap(struct gui_draw_buffer *buf, const struct gui_text *text,
const struct gui_font *font); const struct gui_font *font);
gui_int gui_button(struct gui_draw_buffer *buf, const struct gui_button *button, void gui_image(struct gui_draw_buffer *buf, const struct gui_image *image);
const struct gui_font *font, const struct gui_input *in); gui_int gui_button_text(struct gui_draw_buffer *buf, const struct gui_button *button,
const char *text, gui_size len, const struct gui_font *font,
const struct gui_input *in);
gui_int gui_button_triangle(struct gui_draw_buffer *buffer, struct gui_button* button,
enum gui_direction direction, const struct gui_input *in);
gui_int gui_button_image(struct gui_draw_buffer *buffer, struct gui_button* button,
gui_texture tex, struct gui_texCoord from, struct gui_texCoord to,
const struct gui_input *in);
gui_int gui_toggle(struct gui_draw_buffer *buf, const struct gui_toggle *toggle, gui_int gui_toggle(struct gui_draw_buffer *buf, const struct gui_toggle *toggle,
const struct gui_font *font, const struct gui_input *in); const struct gui_font *font, const struct gui_input *in);
gui_float gui_slider(struct gui_draw_buffer *buf, const struct gui_slider *slider, gui_float gui_slider(struct gui_draw_buffer *buf, const struct gui_slider *slider,
const struct gui_input *in); const struct gui_input *in);
gui_size gui_progress(struct gui_draw_buffer *buf, const struct gui_progress *prog, gui_size gui_progress(struct gui_draw_buffer *buf, const struct gui_progress *prog,
const struct gui_input *in); const struct gui_input *in);
gui_size gui_scroll(struct gui_draw_buffer *buf, const struct gui_scroll *scroll,
const struct gui_input *in);
gui_int gui_input(struct gui_draw_buffer *buf, gui_char *buffer, gui_size *length, gui_int gui_input(struct gui_draw_buffer *buf, gui_char *buffer, gui_size *length,
const struct gui_input_field *input, const struct gui_input_field *input,
const struct gui_font *font, const struct gui_input *in); const struct gui_font *font, const struct gui_input *in);
gui_int gui_spinner(struct gui_draw_buffer *buf, const struct gui_spinner *spinner,
gui_float *value, gui_float *step,
const struct gui_font *font, const struct gui_input *in);
gui_size gui_scroll(struct gui_draw_buffer *buf, const struct gui_scroll *scroll,
const struct gui_input *in);
gui_int gui_histo(struct gui_draw_buffer *buf, const struct gui_histo *histo, gui_int gui_histo(struct gui_draw_buffer *buf, const struct gui_histo *histo,
const struct gui_input *in); const struct gui_input *in);
gui_int gui_plot(struct gui_draw_buffer *buf, const struct gui_plot *plot, gui_int gui_plot(struct gui_draw_buffer *buf, const struct gui_plot *plot,
const struct gui_input *in); const struct gui_input *in);
/* Panel */ /* Panel */
void gui_default_config(struct gui_config *config);
void gui_panel_init(struct gui_panel *panel, const struct gui_config *config, void gui_panel_init(struct gui_panel *panel, const struct gui_config *config,
const struct gui_font *font, const struct gui_input *input); const struct gui_font *font, const struct gui_input *input);
gui_int gui_panel_begin(struct gui_panel *panel, struct gui_draw_buffer *q, gui_int gui_panel_begin(struct gui_panel *panel, struct gui_draw_buffer *q,
const char *t, gui_flags f, const char *t, gui_flags f,
gui_float x, gui_float y, gui_float w, gui_float h); gui_float x, gui_float y, gui_float w, gui_float h);
void gui_panel_row(struct gui_panel *panel, gui_float height, gui_size cols); void gui_panel_row(struct gui_panel *panel, gui_float height, gui_size cols);
void gui_panel_seperator(struct gui_panel *panel, gui_size cols); void gui_panel_seperator(struct gui_panel *panel, gui_size cols);
void gui_panel_text(struct gui_panel *panel, const char *str, gui_size len); void gui_panel_text(struct gui_panel *panel, const char *str, gui_size len);
gui_int gui_panel_button(struct gui_panel *panel, const char *str, gui_size len); gui_size gui_panel_text_wrap(struct gui_panel *panel, const char *str, gui_size len);
gui_int gui_panel_button_text(struct gui_panel *panel, const char *str, gui_size len);
gui_int gui_panel_button_triangle(struct gui_panel *panel, enum gui_direction d);
gui_int gui_panel_button_image(struct gui_panel *panel, gui_texture tex,
struct gui_texCoord from, struct gui_texCoord to);
gui_int gui_panel_toggle(struct gui_panel *panel, const char *str, gui_size len, gui_int gui_panel_toggle(struct gui_panel *panel, const char *str, gui_size len,
gui_int active); gui_int active);
gui_float gui_panel_slider(struct gui_panel *panel, gui_float min, gui_float v, gui_float gui_panel_slider(struct gui_panel *panel, gui_float min, gui_float v,

View File

@ -487,9 +487,11 @@ main(int argc, char *argv[])
/* ------------------------- GUI --------------------------*/ /* ------------------------- GUI --------------------------*/
gui_begin(&gui.out, buffer, MAX_BUFFER); gui_begin(&gui.out, buffer, MAX_BUFFER);
xw.running = gui_panel_begin(&gui.panel, &gui.out, "Demo", xw.running = gui_panel_begin(&gui.panel, &gui.out, "Demo",
GUI_PANEL_CLOSEABLE|GUI_PANEL_MINIMIZABLE, 50, 50, 200, 0); GUI_PANEL_HEADER|GUI_PANEL_CLOSEABLE|GUI_PANEL_MINIMIZABLE,
20, 20, 200, 0);
gui_panel_row(&gui.panel, 30, 1); gui_panel_row(&gui.panel, 30, 1);
if (gui_panel_button(&gui.panel, "button", 6)) gui_panel_text(&gui.panel, "Text", 4);
if (gui_panel_button_text(&gui.panel, "button", 6))
fprintf(stdout, "button pressed!\n"); fprintf(stdout, "button pressed!\n");
slider = gui_panel_slider(&gui.panel, 0.0f, slider, 10.0f, 1.0f); slider = gui_panel_slider(&gui.panel, 0.0f, slider, 10.0f, 1.0f);
prog = gui_panel_progress(&gui.panel, prog, 100, gui_true); prog = gui_panel_progress(&gui.panel, prog, 100, gui_true);