update examples

This commit is contained in:
vurtun 2015-11-19 21:39:23 +01:00
parent 69e3bb332f
commit b1f35976ca
2 changed files with 38 additions and 40 deletions

View File

@ -397,8 +397,8 @@ struct file_browser {
struct zr_window window; struct zr_window window;
struct zr_vec2 dir; struct zr_vec2 dir;
struct zr_vec2 sel; struct zr_vec2 sel;
zr_float ratio_dir; float ratio_dir;
zr_float ratio_sel; float ratio_sel;
}; };
static void static void
@ -473,7 +473,7 @@ file_browser_run(struct file_browser *browser, int width, int height)
zr_begin(&context, &browser->window); zr_begin(&context, &browser->window);
{ {
struct zr_context sub; struct zr_context sub;
zr_float row_layout[3]; float row_layout[3];
/* output path directory selector in the menubar */ /* output path directory selector in the menubar */
zr_menubar_begin(&context); zr_menubar_begin(&context);
{ {
@ -534,8 +534,8 @@ file_browser_run(struct file_browser *browser, int width, int height)
zr_input_is_mouse_prev_hovering_rect(in, bounds)) && zr_input_is_mouse_prev_hovering_rect(in, bounds)) &&
zr_input_is_mouse_down(in, ZR_BUTTON_LEFT)) zr_input_is_mouse_down(in, ZR_BUTTON_LEFT))
{ {
zr_float sel = row_layout[0] + in->mouse.delta.x; float sel = row_layout[0] + in->mouse.delta.x;
zr_float dir = row_layout[2] - in->mouse.delta.x; float dir = row_layout[2] - in->mouse.delta.x;
browser->ratio_sel = sel / (total_space.w - 8); browser->ratio_sel = sel / (total_space.w - 8);
browser->ratio_dir = dir / (total_space.w - 8); browser->ratio_dir = dir / (total_space.w - 8);
} }
@ -555,7 +555,7 @@ file_browser_run(struct file_browser *browser, int width, int height)
{ {
/* draw one row of icons */ /* draw one row of icons */
size_t n = j + cols; size_t n = j + cols;
zr_layout_row_dynamic(&sub, 130, cols); zr_layout_row_dynamic(&sub, 135, cols);
zr_style_push_color(&browser->config, ZR_COLOR_BUTTON, zr_rgb(45, 45, 45)); zr_style_push_color(&browser->config, ZR_COLOR_BUTTON, zr_rgb(45, 45, 45));
zr_style_push_color(&browser->config, ZR_COLOR_BORDER, zr_rgb(45, 45, 45)); zr_style_push_color(&browser->config, ZR_COLOR_BORDER, zr_rgb(45, 45, 45));
for (; j < count && j < n; ++j) { for (; j < count && j < n; ++j) {
@ -581,7 +581,6 @@ file_browser_run(struct file_browser *browser, int width, int height)
} }
{ {
/* draw one row of labels */ /* draw one row of labels */
zr_style_push_property(&browser->config, ZR_PROPERTY_ITEM_SPACING, zr_vec2(4, 4));
size_t n = k + cols; size_t n = k + cols;
zr_layout_row_dynamic(&sub, 20, cols); zr_layout_row_dynamic(&sub, 20, cols);
for (; k < count && k < n; k++) { for (; k < count && k < n; k++) {
@ -592,7 +591,6 @@ file_browser_run(struct file_browser *browser, int width, int height)
zr_label(&sub,browser->files[t],ZR_TEXT_CENTERED); zr_label(&sub,browser->files[t],ZR_TEXT_CENTERED);
} }
} }
zr_style_pop_property(&browser->config);
} }
} }
@ -619,7 +617,7 @@ file_browser_run(struct file_browser *browser, int width, int height)
* *
* ================================================================= */ * ================================================================= */
static zr_size static zr_size
font_get_width(zr_handle handle, const zr_char *text, zr_size len) font_get_width(zr_handle handle, const char *text, zr_size len)
{ {
zr_size width; zr_size width;
float bounds[4]; float bounds[4];
@ -730,7 +728,7 @@ draw(NVGcontext *nvg, struct zr_command_queue *queue, int width, int height)
} }
static void static void
key(struct zr_input *in, SDL_Event *evt, zr_bool down) key(struct zr_input *in, SDL_Event *evt, int down)
{ {
const Uint8* state = SDL_GetKeyboardState(NULL); const Uint8* state = SDL_GetKeyboardState(NULL);
SDL_Keycode sym = evt->key.keysym.sym; SDL_Keycode sym = evt->key.keysym.sym;
@ -757,16 +755,16 @@ key(struct zr_input *in, SDL_Event *evt, zr_bool down)
static void static void
motion(struct zr_input *in, SDL_Event *evt) motion(struct zr_input *in, SDL_Event *evt)
{ {
const zr_int x = evt->motion.x; const int x = evt->motion.x;
const zr_int y = evt->motion.y; const int y = evt->motion.y;
zr_input_motion(in, x, y); zr_input_motion(in, x, y);
} }
static void static void
btn(struct zr_input *in, SDL_Event *evt, zr_bool down) btn(struct zr_input *in, SDL_Event *evt, int down)
{ {
const zr_int x = evt->button.x; const int x = evt->button.x;
const zr_int y = evt->button.y; const int y = evt->button.y;
if (evt->button.button == SDL_BUTTON_LEFT) if (evt->button.button == SDL_BUTTON_LEFT)
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down); zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
else if (evt->button.button == SDL_BUTTON_RIGHT) else if (evt->button.button == SDL_BUTTON_RIGHT)

View File

@ -59,10 +59,10 @@ struct node {
int ID; int ID;
char name[32]; char name[32];
struct zr_rect bounds; struct zr_rect bounds;
zr_float value; float value;
struct zr_color color; struct zr_color color;
zr_int input_count; int input_count;
zr_int output_count; int output_count;
struct node *next; struct node *next;
struct node *prev; struct node *prev;
}; };
@ -77,7 +77,7 @@ struct node_link {
}; };
struct node_linking { struct node_linking {
zr_bool active; int active;
struct node *node; struct node *node;
int input_id; int input_id;
int input_slot; int input_slot;
@ -90,10 +90,10 @@ struct node_editor {
struct node *end; struct node *end;
int node_count; int node_count;
int link_count; int link_count;
zr_state menu; int menu;
struct zr_rect bounds; struct zr_rect bounds;
struct node *selected; struct node *selected;
zr_bool show_grid; int show_grid;
struct zr_vec2 scrolling; struct zr_vec2 scrolling;
struct node_linking linking; struct node_linking linking;
}; };
@ -210,12 +210,12 @@ node_editor_draw(struct zr_context *layout, struct node_editor *nodedit,
if (nodedit->show_grid) { if (nodedit->show_grid) {
/* display grid */ /* display grid */
zr_float x, y; float x, y;
const zr_float grid_size = 32.0f; const float grid_size = 32.0f;
const struct zr_color grid_color = zr_rgb(50, 50, 50); const struct zr_color grid_color = zr_rgb(50, 50, 50);
for (x = fmod(size.x - nodedit->scrolling.x, grid_size); x < size.w; x += grid_size) for (x = (float)fmod(size.x - nodedit->scrolling.x, grid_size); x < size.w; x += grid_size)
zr_command_buffer_push_line(canvas, x+size.x, size.y, x+size.x, size.y+size.h, grid_color); zr_command_buffer_push_line(canvas, x+size.x, size.y, x+size.x, size.y+size.h, grid_color);
for (y = fmod(size.y - nodedit->scrolling.y, grid_size); y < size.h; y += grid_size) for (y = (float)fmod(size.y - nodedit->scrolling.y, grid_size); y < size.h; y += grid_size)
zr_command_buffer_push_line(canvas, size.x, y+size.y, size.x+size.w, y+size.y, grid_color); zr_command_buffer_push_line(canvas, size.x, y+size.y, size.x+size.w, y+size.y, grid_color);
} }
@ -230,8 +230,8 @@ node_editor_draw(struct zr_context *layout, struct node_editor *nodedit,
zr_group_begin(layout, &node, it->name, zr_group_begin(layout, &node, it->name,
ZR_WINDOW_MOVEABLE|ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_BORDER, zr_vec2(0,0)); ZR_WINDOW_MOVEABLE|ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_BORDER, zr_vec2(0,0));
{ {
zr_int r,g,b; int r,g,b;
zr_float ratio[] = {0.25f, 0.75f}; float ratio[] = {0.25f, 0.75f};
/* always have last selected node on top */ /* always have last selected node on top */
if (zr_input_mouse_clicked(in, ZR_BUTTON_LEFT, node.bounds) && if (zr_input_mouse_clicked(in, ZR_BUTTON_LEFT, node.bounds) &&
@ -254,14 +254,14 @@ node_editor_draw(struct zr_context *layout, struct node_editor *nodedit,
zr_slider_int(&node, 0, &g, 255, 10); zr_slider_int(&node, 0, &g, 255, 10);
zr_label(&node, "B:", ZR_TEXT_LEFT); zr_label(&node, "B:", ZR_TEXT_LEFT);
zr_slider_int(&node, 0, &b, 255, 10); zr_slider_int(&node, 0, &b, 255, 10);
it->color.r = r; it->color.g = g; it->color.b = b; it->color.r = (zr_byte)r; it->color.g = (zr_byte)g; it->color.b = (zr_byte)b;
/* ====================================================*/ /* ====================================================*/
} }
zr_group_end(layout, &node, NULL); zr_group_end(layout, &node, NULL);
{ {
/* node connector and linking */ /* node connector and linking */
zr_float space; float space;
struct zr_rect bounds; struct zr_rect bounds;
bounds = zr_layout_row_space_rect_to_local(layout, node.bounds); bounds = zr_layout_row_space_rect_to_local(layout, node.bounds);
bounds.x += nodedit->scrolling.x; bounds.x += nodedit->scrolling.x;
@ -327,8 +327,8 @@ node_editor_draw(struct zr_context *layout, struct node_editor *nodedit,
struct node_link *link = &nodedit->links[n]; struct node_link *link = &nodedit->links[n];
struct node *ni = node_editor_find(nodedit, link->input_id); struct node *ni = node_editor_find(nodedit, link->input_id);
struct node *no = node_editor_find(nodedit, link->output_id); struct node *no = node_editor_find(nodedit, link->output_id);
zr_float spacei = node.bounds.h / ((ni->output_count) + 1); float spacei = node.bounds.h / ((ni->output_count) + 1);
zr_float spaceo = node.bounds.h / ((no->input_count) + 1); float spaceo = node.bounds.h / ((no->input_count) + 1);
struct zr_vec2 l0 = zr_layout_row_space_to_screen(layout, struct zr_vec2 l0 = zr_layout_row_space_to_screen(layout,
zr_vec2(ni->bounds.x + ni->bounds.w, 3+ni->bounds.y + spacei * (link->input_slot+1))); zr_vec2(ni->bounds.x + ni->bounds.w, 3+ni->bounds.y + spacei * (link->input_slot+1)));
struct zr_vec2 l1 = zr_layout_row_space_to_screen(layout, struct zr_vec2 l1 = zr_layout_row_space_to_screen(layout,
@ -436,7 +436,7 @@ die(const char *fmt, ...)
} }
static zr_size static zr_size
font_get_width(zr_handle handle, const zr_char *text, zr_size len) font_get_width(zr_handle handle, const char *text, zr_size len)
{ {
zr_size width; zr_size width;
float bounds[4]; float bounds[4];
@ -543,7 +543,7 @@ draw(NVGcontext *nvg, struct zr_command_queue *queue, int width, int height)
} }
static void static void
key(struct zr_input *in, SDL_Event *evt, zr_bool down) key(struct zr_input *in, SDL_Event *evt, int down)
{ {
const Uint8* state = SDL_GetKeyboardState(NULL); const Uint8* state = SDL_GetKeyboardState(NULL);
SDL_Keycode sym = evt->key.keysym.sym; SDL_Keycode sym = evt->key.keysym.sym;
@ -570,16 +570,16 @@ key(struct zr_input *in, SDL_Event *evt, zr_bool down)
static void static void
motion(struct zr_input *in, SDL_Event *evt) motion(struct zr_input *in, SDL_Event *evt)
{ {
const zr_int x = evt->motion.x; const int x = evt->motion.x;
const zr_int y = evt->motion.y; const int y = evt->motion.y;
zr_input_motion(in, x, y); zr_input_motion(in, x, y);
} }
static void static void
btn(struct zr_input *in, SDL_Event *evt, zr_bool down) btn(struct zr_input *in, SDL_Event *evt, int down)
{ {
const zr_int x = evt->button.x; const int x = evt->button.x;
const zr_int y = evt->button.y; const int y = evt->button.y;
if (evt->button.button == SDL_BUTTON_LEFT) if (evt->button.button == SDL_BUTTON_LEFT)
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down); zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
else if (evt->button.button == SDL_BUTTON_RIGHT) else if (evt->button.button == SDL_BUTTON_RIGHT)
@ -614,7 +614,7 @@ main(int argc, char *argv[])
SDL_Window *win; SDL_Window *win;
SDL_GLContext glContext; SDL_GLContext glContext;
NVGcontext *vg = NULL; NVGcontext *vg = NULL;
zr_bool running = zr_true; int running = zr_true;
unsigned int started; unsigned int started;
unsigned int dt; unsigned int dt;
@ -689,7 +689,7 @@ main(int argc, char *argv[])
zr_input_end(&gui.input); zr_input_end(&gui.input);
{ {
zr_bool incursor; int incursor;
struct zr_context layout; struct zr_context layout;
struct zr_rect bounds = gui.window.bounds; struct zr_rect bounds = gui.window.bounds;