static void draw(NVGcontext *nvg, struct gui_command_queue *queue, int width, int height) { const struct gui_command *cmd; glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glEnable(GL_TEXTURE_2D); nvgBeginFrame(nvg, width, height, ((float)width/(float)height)); gui_foreach_command(cmd, queue) { switch (cmd->type) { case GUI_COMMAND_NOP: break; case GUI_COMMAND_SCISSOR: { const struct gui_command_scissor *s = gui_command(scissor, cmd); nvgScissor(nvg, s->x, s->y, s->w, s->h); } break; case GUI_COMMAND_LINE: { const struct gui_command_line *l = gui_command(line, cmd); draw_line(nvg, l->begin.x, l->begin.y, l->end.x, l->end.y, l->color); } break; case GUI_COMMAND_RECT: { const struct gui_command_rect *r = gui_command(rect, cmd); draw_rect(nvg, r->x, r->y, r->w, r->h, r->rounding, r->color); } break; case GUI_COMMAND_CIRCLE: { const struct gui_command_circle *c = gui_command(circle, cmd); draw_circle(nvg, c->x, c->y, (float)c->w / 2.0f, c->color); } break; case GUI_COMMAND_TRIANGLE: { const struct gui_command_triangle *t = gui_command(triangle, cmd); draw_triangle(nvg, t->a.x, t->a.y, t->b.x, t->b.y, t->c.x, t->c.y, t->color); } break; case GUI_COMMAND_TEXT: { const struct gui_command_text *t = gui_command(text, cmd); draw_text(nvg, t->x, t->y, t->w, t->h, t->foreground, t->background, t->string, t->length); } break; case GUI_COMMAND_IMAGE: { const struct gui_command_image *i = gui_command(image, cmd); draw_image(nvg, i->img.handle, i->x, i->y, i->w, i->h, 1); } break; case GUI_COMMAND_MAX: default: break; } } gui_command_queue_clear(queue); nvgResetScissor(nvg); nvgEndFrame(nvg); glPopAttrib(); }
static void execute(XSurface *surf, struct gui_command_buffer *buffer) { const struct gui_command *cmd; gui_foreach_command(cmd, buffer) { switch (cmd->type) { case GUI_COMMAND_NOP: break; case GUI_COMMAND_SCISSOR: { const struct gui_command_scissor *s = gui_command(scissor, cmd); surface_scissor(surf, s->x, s->y, s->w, s->h); } break; case GUI_COMMAND_LINE: { const struct gui_command_line *l = gui_command(line, 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: { const struct gui_command_rect *r = gui_command(rect, cmd); if (!r->r) { surface_draw_rect(surf, r->x, r->y, r->w, r->h, r->color.r, r->color.g, r->color.b); } else { surface_draw_rounded_rect(surf, r->x, r->y, r->w, r->h, r->r, r->color.r, r->color.g, r->color.b); } } break; case GUI_COMMAND_CIRCLE: { const struct gui_command_circle *c = gui_command(circle, 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: { const struct gui_command_triangle *t = gui_command(triangle, 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: { const struct gui_command_text *t = gui_command(text, cmd); XWindow *win = t->font.ptr; surface_draw_text(surf, win->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; case GUI_COMMAND_IMAGE: default: break; } } }