From 027ae073cb0f90d9b077c94aa3c839311d6efe45 Mon Sep 17 00:00:00 2001 From: vurtun Date: Mon, 4 May 2015 11:03:15 +0200 Subject: [PATCH] fixed opengl, win32 example --- demo/opengl.c | 20 ++++++++++---------- demo/win32.c | 20 ++++++++++---------- gui.c | 7 ++++--- gui.h | 6 ++++-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/demo/opengl.c b/demo/opengl.c index 5188b0f..abd1166 100644 --- a/demo/opengl.c +++ b/demo/opengl.c @@ -460,7 +460,7 @@ static void draw(struct gui_command_list *list, int width, int height) { static const struct gui_color col = {255, 0, 0, 255}; - struct gui_command *cmd; + const struct gui_command *cmd; if (!list->count) return; glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT|GL_TRANSFORM_BIT); @@ -479,29 +479,29 @@ draw(struct gui_command_list *list, int width, int height) glPushMatrix(); glLoadIdentity(); - cmd = list->begin; - while (cmd != list->end) { + cmd = gui_list_begin(list); + while (cmd) { switch (cmd->type) { case GUI_COMMAND_NOP: break; case GUI_COMMAND_SCISSOR: { - struct gui_command_scissor *s = (void*)cmd; + const struct gui_command_scissor *s = (const void*)cmd; glScissor(s->x, height - (s->y + s->h), s->w, s->h); } break; case GUI_COMMAND_LINE: { - struct gui_command_line *l = (void*)cmd; + const struct gui_command_line *l = (const void*)cmd; draw_line(l->begin[0], l->begin[1], l->end[0], l->end[1], l->color); } break; case GUI_COMMAND_RECT: { - struct gui_command_rect *r = (void*)cmd; + const struct gui_command_rect *r = (const void*)cmd; draw_rect(r->x, r->y, r->w, r->h, r->color); } break; case GUI_COMMAND_CIRCLE: { unsigned i; - struct gui_command_circle *c = (void*)cmd; + const struct gui_command_circle *c = (const void*)cmd; draw_circle(c->x, c->y, (float)c->w / 2.0f, c->color); } break; case GUI_COMMAND_TRIANGLE: { - struct gui_command_triangle *t = (void*)cmd; + const struct gui_command_triangle *t = (const void*)cmd; glColor4ub(t->color.r, t->color.g, t->color.b, t->color.a); glBegin(GL_TRIANGLES); glVertex2f(t->a[0], t->a[1]); @@ -510,12 +510,12 @@ draw(struct gui_command_list *list, int width, int height) glEnd(); } break; case GUI_COMMAND_TEXT: { - struct gui_command_text *t = (void*)cmd; + const struct gui_command_text *t = (const void*)cmd; font_draw_text(t->font, t->x, t->y, t->h, t->fg, t->string, t->length); } break; default: break; } - cmd = cmd->next; + cmd = gui_list_next(list, cmd); } glBindTexture(GL_TEXTURE_2D, 0); diff --git a/demo/win32.c b/demo/win32.c index 7c756ae..dc6c8b4 100644 --- a/demo/win32.c +++ b/demo/win32.c @@ -287,45 +287,45 @@ surface_end(XSurface *surf, HDC hdc) static void draw(XSurface *surf, struct gui_command_list *list) { - struct gui_command *cmd; + const struct gui_command *cmd; if (!list->count) return; - cmd = list->begin; - while (cmd != list->end) { + cmd = gui_list_begin(list); + while (cmd) { switch (cmd->type) { case GUI_COMMAND_NOP: break; case GUI_COMMAND_SCISSOR: { - struct gui_command_scissor *s = (void*)cmd; + const struct gui_command_scissor *s = (const void*)cmd; surface_scissor(surf, s->x, s->y, s->w, s->h); } break; case GUI_COMMAND_LINE: { - struct gui_command_line *l = (void*)cmd; + const struct gui_command_line *l = (const void*)cmd; surface_draw_line(surf, l->begin[0], l->begin[1], l->end[0], l->end[1], l->color.r, l->color.g, l->color.b); } break; case GUI_COMMAND_RECT: { - struct gui_command_rect *r = (void*)cmd; + const struct gui_command_rect *r = (const void*)cmd; surface_draw_rect(surf, r->x, r->y, r->w, r->h, r->color.r, r->color.g, r->color.b); } break; case GUI_COMMAND_CIRCLE: { - struct gui_command_circle *c = (void*)cmd; + const struct gui_command_circle *c = (const void*)cmd; surface_draw_circle(surf, c->x, c->y, c->w, c->h, c->color.r, c->color.g, c->color.b); } break; case GUI_COMMAND_TRIANGLE: { - struct gui_command_triangle *t = (void*)cmd; + const struct gui_command_triangle *t = (const void*)cmd; surface_draw_triangle(surf, t->a[0], t->a[1], t->b[0], t->b[1], t->c[0], t->c[1], t->color.r, t->color.g, t->color.b); } break; case GUI_COMMAND_TEXT: { - struct gui_command_text *t = (void*)cmd; + const struct gui_command_text *t = (const void*)cmd; XWindow *xw = t->font; surface_draw_text(surf, xw->font, t->x, t->y, t->w, t->h, (const char*)t->string, t->length, t->bg.r, t->bg.g, t->bg.b, t->fg.r, t->fg.g, t->fg.b); } break; default: break; } - cmd = cmd->next; + cmd = gui_list_next(list, cmd); } } diff --git a/gui.c b/gui.c index 1259483..fc7fa08 100644 --- a/gui.c +++ b/gui.c @@ -451,7 +451,6 @@ gui_button_image(const struct gui_canvas *canvas, gui_float x, gui_float y, return gui_false; pressed = gui_do_button(canvas, x, y, w, h, button, in, b); - img_x = x + button->padding.x; img_y = y + button->padding.y; img_w = w - 2 * button->padding.x; @@ -1116,6 +1115,7 @@ gui_buffer_unlock(struct gui_command_buffer *buffer, struct gui_command_buffer * assert(buffer); assert(sub); if (!buffer || !sub) return; + buffer->flags &= (gui_flags)~GUI_BUFFER_LOCKED; buffer->memory = sub->memory; buffer->end = sub->end; @@ -1531,7 +1531,6 @@ void gui_panel_seperator(struct gui_panel_layout *layout, gui_size cols) { const struct gui_config *config; - assert(layout); assert(layout->config); assert(layout->canvas); @@ -2261,10 +2260,10 @@ gui_panel_graph_push_histo(struct gui_panel_layout *layout, const struct gui_input *in = layout->input; struct gui_color color; + gui_float ratio; gui_bool selected = gui_false; gui_float item_x, item_y; gui_float item_w = 0.0f, item_h = 0.0f; - gui_float ratio; if (graph->index >= graph->count) return gui_false; @@ -2342,6 +2341,7 @@ gui_panel_graph(struct gui_panel_layout *layout, enum gui_graph_type type, if (values[i] < min_value) min_value = values[i]; } + gui_panel_graph_begin(layout, &graph, type, count, min_value, max_value); for (i = 0; i < count; ++i) { if (gui_panel_graph_push(layout, &graph, values[i])) @@ -2409,6 +2409,7 @@ gui_panel_table_vline(struct gui_panel_layout *layout, gui_size cols) for (i = 0; i < cols - 1; ++i) { gui_float y, h; struct gui_rect bounds; + gui_panel_alloc_space(&bounds, layout); y = layout->at_y + layout->row_height; h = layout->row_height; diff --git a/gui.h b/gui.h index 51eb482..e3a2854 100644 --- a/gui.h +++ b/gui.h @@ -471,11 +471,13 @@ void gui_buffer_clear(struct gui_command_buffer*); void gui_buffer_end(struct gui_command_list*, struct gui_command_buffer*, struct gui_canvas*, struct gui_memory_status*); + /* List */ const struct gui_command* gui_list_begin(const struct gui_command_list*); const struct gui_command* gui_list_next(const struct gui_command_list*, const struct gui_command*); + /* Widgets */ void gui_text(const struct gui_canvas*, gui_float x, gui_float y, gui_float w, gui_float h, const char *text, gui_size len, const struct gui_text*, enum gui_text_align, @@ -508,8 +510,8 @@ gui_float gui_scroll(const struct gui_canvas*, gui_float x, gui_float y, /* Panel */ void gui_default_config(struct gui_config*); -void gui_panel_init(struct gui_panel*, gui_float x, gui_float y, gui_float w, gui_float h, gui_flags, - const struct gui_config *config, const struct gui_font*); +void gui_panel_init(struct gui_panel*, gui_float x, gui_float y, gui_float w, gui_float h, + gui_flags, const struct gui_config *config, const struct gui_font*); gui_bool gui_panel_begin(struct gui_panel_layout *layout, struct gui_panel*, const char *title, const struct gui_canvas*, const struct gui_input*); gui_bool gui_panel_begin_stacked(struct gui_panel_layout *layout, struct gui_panel*,