added some docu + fixed nanovg demo
This commit is contained in:
parent
85da49d348
commit
b14ee62c42
16
demo/demo.c
16
demo/demo.c
|
@ -199,10 +199,9 @@ init_show(struct show_window *win, struct gui_config *config,
|
|||
win->nodes[0].state = 0;
|
||||
win->nodes[0].name = "Boxes";
|
||||
win->nodes[0].parent = &tree->root;
|
||||
win->nodes[0].count = 3;
|
||||
win->nodes[0].count = 2;
|
||||
win->nodes[0].children[0] = &win->nodes[1];
|
||||
win->nodes[0].children[1] = &win->nodes[2];
|
||||
win->nodes[0].children[2] = &win->nodes[3];
|
||||
|
||||
win->nodes[1].state = 0;
|
||||
win->nodes[1].name = "Box0";
|
||||
|
@ -214,18 +213,12 @@ init_show(struct show_window *win, struct gui_config *config,
|
|||
win->nodes[2].parent = &win->nodes[0];
|
||||
win->nodes[2].count = 0;
|
||||
|
||||
win->nodes[3].state = 0;
|
||||
win->nodes[3].name = "Box2";
|
||||
win->nodes[3].parent = &win->nodes[0];
|
||||
win->nodes[3].count = 0;
|
||||
|
||||
win->nodes[4].state = GUI_NODE_ACTIVE;
|
||||
win->nodes[4].name = "Cylinders";
|
||||
win->nodes[4].parent = &tree->root;
|
||||
win->nodes[4].count = 3;
|
||||
win->nodes[4].count = 2;
|
||||
win->nodes[4].children[0] = &win->nodes[5];
|
||||
win->nodes[4].children[1] = &win->nodes[6];
|
||||
win->nodes[4].children[2] = &win->nodes[7];
|
||||
|
||||
win->nodes[5].state = 0;
|
||||
win->nodes[5].name = "Cylinder0";
|
||||
|
@ -236,11 +229,6 @@ init_show(struct show_window *win, struct gui_config *config,
|
|||
win->nodes[6].name = "Cylinder1";
|
||||
win->nodes[6].parent = &win->nodes[4];
|
||||
win->nodes[6].count = 0;
|
||||
|
||||
win->nodes[7].state = 0;
|
||||
win->nodes[7].name = "Cylinder2";
|
||||
win->nodes[7].parent = &win->nodes[4];
|
||||
win->nodes[7].count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,8 @@
|
|||
#define LEN(a) (sizeof(a)/sizeof(a)[0])
|
||||
#define UNUSED(a) ((void)(a))
|
||||
|
||||
#define GUI_USE_FIXED_TYPES
|
||||
#define GUI_ASSERT(expr) assert(expr)
|
||||
#include "../gui.h"
|
||||
/*#include "demo.c"*/
|
||||
#include "maya.c"
|
||||
#include "demo.c"
|
||||
|
||||
static void
|
||||
die(const char *fmt, ...)
|
||||
|
@ -61,14 +58,23 @@ font_get_width(gui_handle handle, const gui_char *text, gui_size len)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_text(NVGcontext *ctx, float x, float y, const gui_byte *c,
|
||||
const gui_char *string, gui_size len)
|
||||
draw_rect(NVGcontext *ctx, float x, float y, float w, float h, float r, const gui_byte* c)
|
||||
{
|
||||
gui_float height = 0;
|
||||
nvgBeginPath(ctx);
|
||||
nvgTextMetrics(ctx, NULL, NULL, &height);
|
||||
nvgRoundedRect(ctx, x, y, w, h, r);
|
||||
nvgFillColor(ctx, nvgRGBA(c[0], c[1], c[2], c[3]));
|
||||
nvgText(ctx, x, y + height, string, &string[len]);
|
||||
nvgFill(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_text(NVGcontext *ctx, float x, float y, float w, float h,
|
||||
const gui_byte *c, const gui_byte *bg, const gui_char *string, gui_size len)
|
||||
{
|
||||
draw_rect(ctx, x,y,w,h,0, bg);
|
||||
nvgBeginPath(ctx);
|
||||
nvgFillColor(ctx, nvgRGBA(c[0], c[1], c[2], c[3]));
|
||||
nvgTextAlign(ctx, NVG_ALIGN_MIDDLE);
|
||||
nvgText(ctx, x, y + h * 0.5f, string, &string[len]);
|
||||
nvgFill(ctx);
|
||||
}
|
||||
|
||||
|
@ -82,15 +88,6 @@ draw_line(NVGcontext *ctx, float x0, float y0, float x1, float y1, const gui_byt
|
|||
nvgFill(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_rect(NVGcontext *ctx, float x, float y, float w, float h, float r, const gui_byte* c)
|
||||
{
|
||||
nvgBeginPath(ctx);
|
||||
nvgRoundedRect(ctx, x, y, w, h, r);
|
||||
nvgFillColor(ctx, nvgRGBA(c[0], c[1], c[2], c[3]));
|
||||
nvgFill(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_circle(NVGcontext *ctx, float x, float y, float r, const gui_byte *c)
|
||||
{
|
||||
|
@ -162,7 +159,7 @@ execute(NVGcontext *nvg, struct gui_command_buffer *list, int width, int height)
|
|||
} break;
|
||||
case GUI_COMMAND_TEXT: {
|
||||
const struct gui_command_text *t = gui_command(text, cmd);
|
||||
draw_text(nvg, t->x, t->y, t->fg, t->string, t->length);
|
||||
draw_text(nvg, t->x, t->y, t->w, t->h, t->fg, t->bg, t->string, t->length);
|
||||
} break;
|
||||
case GUI_COMMAND_IMAGE: {
|
||||
const struct gui_command_image *i = gui_command(image, cmd);
|
||||
|
@ -188,6 +185,7 @@ draw(NVGcontext *nvg,struct gui_stack *stack, int width, int height)
|
|||
static void
|
||||
key(struct gui_input *in, SDL_Event *evt, gui_bool down)
|
||||
{
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
SDL_Keycode sym = evt->key.keysym.sym;
|
||||
if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT)
|
||||
gui_input_key(in, GUI_KEY_SHIFT, down);
|
||||
|
@ -199,6 +197,16 @@ key(struct gui_input *in, SDL_Event *evt, gui_bool down)
|
|||
gui_input_key(in, GUI_KEY_SPACE, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
gui_input_key(in, GUI_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
gui_input_key(in, GUI_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
gui_input_key(in, GUI_KEY_RIGHT, down);
|
||||
else if (sym == SDLK_c)
|
||||
gui_input_key(in, GUI_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_v)
|
||||
gui_input_key(in, GUI_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_x)
|
||||
gui_input_key(in, GUI_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -288,18 +296,8 @@ main(int argc, char *argv[])
|
|||
font.userdata.ptr = vg;
|
||||
nvgTextMetrics(vg, NULL, NULL, &font.height);
|
||||
font.width = font_get_width;
|
||||
|
||||
gui.width = WINDOW_WIDTH;
|
||||
gui.height = WINDOW_HEIGHT;
|
||||
init_demo(&gui, &font);
|
||||
|
||||
gui.images.select = nvgCreateImage(vg, "icon/select.bmp", 0);
|
||||
gui.images.lasso = nvgCreateImage(vg, "icon/lasso.bmp", 0);
|
||||
gui.images.paint = nvgCreateImage(vg, "icon/paint.bmp", 0);
|
||||
gui.images.move = nvgCreateImage(vg, "icon/move.bmp", 0);
|
||||
gui.images.rotate = nvgCreateImage(vg, "icon/rotate.bmp", 0);
|
||||
gui.images.scale = nvgCreateImage(vg, "icon/scale.bmp", 0);
|
||||
|
||||
while (gui.running) {
|
||||
/* Input */
|
||||
SDL_Event evt;
|
||||
|
@ -325,7 +323,6 @@ main(int argc, char *argv[])
|
|||
/* Draw */
|
||||
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
draw(vg, &gui.layout.stack, width, height);
|
||||
draw(vg, &gui.stack, width, height);
|
||||
gui.ms = SDL_GetTicks() - started;
|
||||
SDL_GL_SwapWindow(win);
|
||||
|
|
8
gui.c
8
gui.c
|
@ -4170,12 +4170,10 @@ gui_panel_tree_node(struct gui_tree *tree, enum gui_tree_node_symbol symbol,
|
|||
if (!tree->depth) tree->at_x = bounds.x;
|
||||
return op;
|
||||
}
|
||||
if (!tree->depth){
|
||||
tree->at_x = bounds.x;
|
||||
} else {
|
||||
if (tree->depth){
|
||||
bounds.w = (bounds.x + bounds.w) - tree->at_x;
|
||||
bounds.x = tree->at_x;
|
||||
}
|
||||
} else tree->at_x = bounds.x;
|
||||
|
||||
/* fetch some configuration constants */
|
||||
i = layout->input;
|
||||
|
@ -4214,7 +4212,7 @@ gui_panel_tree_node(struct gui_tree *tree, enum gui_tree_node_symbol symbol,
|
|||
gui_command_buffer_push_circle(layout->buffer, sym.x, sym.y, sym.w, sym.h, col);
|
||||
}
|
||||
|
||||
/* selection */
|
||||
/* node selection */
|
||||
if (gui_input_clicked(i, &label)) {
|
||||
if (*state & GUI_NODE_SELECTED)
|
||||
*state &= ~(gui_flags)GUI_NODE_SELECTED;
|
||||
|
|
45
gui.h
45
gui.h
|
@ -1514,6 +1514,7 @@ void gui_config_reset(struct gui_config*);
|
|||
gui_panel_begin_stacked -- extends gui_panel_begin by adding the panel into a panel stack
|
||||
gui_panel_begin_tiled -- extends gui_panel_begin by adding the panel into a tiled layout
|
||||
gui_panel_row -- defines the current row layout with row height and number of columns
|
||||
gui_panel_row_templated -- defines the row layout as a nother of panel space ratios
|
||||
gui_panel_row_begin -- begins the row build up process
|
||||
gui_panel_row_push_widget-- pushes the next added widget width as a ratio of the provided space
|
||||
gui_panel_row_end -- ends the row build up process
|
||||
|
@ -1533,6 +1534,8 @@ void gui_config_reset(struct gui_config*);
|
|||
gui_panel_button_triangle --button with triangle pointing either up-/down-/left- or right
|
||||
gui_panel_button_image -- button widget width icon content
|
||||
gui_panel_button_toggle -- toggle button with either active or inactive state
|
||||
gui_panel_button_text_image -- button widget with text and icon
|
||||
gui_panel_button_text_triangle --button widget with text and a triangle
|
||||
gui_panel_slider -- slider widget with min and max value as well as stepping range
|
||||
gui_panel_progress -- either modifyable or static progressbar
|
||||
gui_panel_editbox -- edit textbox for text input with cursor, clipboard and filter
|
||||
|
@ -1545,6 +1548,17 @@ void gui_config_reset(struct gui_config*);
|
|||
gui_panel_graph_end -- immediate mode graph building end sequence point
|
||||
gui_panel_graph -- retained mode graph with array of values
|
||||
gui_panel_graph_ex -- ratained mode graph with getter callback
|
||||
gui_panel_tab_begin -- begins a minimizable growing space inside the panel
|
||||
gui_panel_tab_end -- ends the minimizable space
|
||||
gui_panel_group_begin -- adds a scrollable fixed space inside the panel
|
||||
gui_panel_group_end -- ends the scrollable space
|
||||
gui_panel_shelf_begin -- begins a shelf with a number of selectable tabs
|
||||
gui_panel_shelf_end -- ends a previously started shelf build up process
|
||||
gui_panel_tree_begin -- begin a new tree build up process
|
||||
gui_panel_tree_begin_node -- begins a new parent node
|
||||
gui_panel_tree_end_node -- ends the previously started parent node
|
||||
gui_panel_tree_leaf -- adds a leaf node
|
||||
gui_panel_tree_end -- ends the previously started tree build up process
|
||||
gui_panel_end -- end squeunce point which finializes the panel build up
|
||||
*/
|
||||
enum gui_table_lines {
|
||||
|
@ -2114,7 +2128,7 @@ void gui_panel_table_end(struct gui_panel_layout*);
|
|||
to its normal state.
|
||||
*/
|
||||
gui_bool gui_panel_tab_begin(struct gui_panel_layout*, struct gui_panel_layout *tab,
|
||||
const char*, gui_bool);
|
||||
const char*, gui_bool minimized);
|
||||
/* this function adds a tab subpanel into the parent panel
|
||||
Input:
|
||||
- tab title to write into the header
|
||||
|
@ -2165,15 +2179,38 @@ gui_float gui_panel_shelf_end(struct gui_panel_layout*, struct gui_panel_layout*
|
|||
*/
|
||||
void gui_panel_tree_begin(struct gui_panel_layout*, struct gui_tree*,
|
||||
const char*, gui_float row_height, gui_float offset);
|
||||
/* this function begins the tree building process
|
||||
Input:
|
||||
- title describing the tree or NULL
|
||||
- height of every node inside the panel
|
||||
- scrollbar offset
|
||||
Output:
|
||||
- tree build up state structure
|
||||
*/
|
||||
enum gui_tree_node_operation gui_panel_tree_begin_node(struct gui_tree*, const char*,
|
||||
enum gui_tree_node_state*);
|
||||
/* this function begins a parent node
|
||||
Input:
|
||||
- title of the node
|
||||
- current node state
|
||||
Output:
|
||||
- operation identifier what should be done with this node
|
||||
*/
|
||||
void gui_panel_tree_end_node(struct gui_tree*);
|
||||
/* this function ends a parent node */
|
||||
enum gui_tree_node_operation gui_panel_tree_leaf(struct gui_tree*, const char*,
|
||||
enum gui_tree_node_state*);
|
||||
gui_float gui_panel_tree_end(struct gui_panel_layout*, struct gui_tree*);
|
||||
void gui_panel_end(struct gui_panel_layout*, struct gui_panel*);
|
||||
/* this function ends the panel layout build up process and updates the panel
|
||||
/* this function pushes a leaf node to the tree
|
||||
Input:
|
||||
- title of the node
|
||||
- current leaf node state
|
||||
Output:
|
||||
- operation identifier what should be done with this node
|
||||
*/
|
||||
gui_float gui_panel_tree_end(struct gui_panel_layout*, struct gui_tree*);
|
||||
/* this function ends a the tree building process */
|
||||
void gui_panel_end(struct gui_panel_layout*, struct gui_panel*);
|
||||
/* this function ends the panel layout build up process and updates the panel */
|
||||
/*
|
||||
* ==============================================================
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue