This commit is contained in:
vurtun 2015-04-26 13:30:22 +02:00
parent 25f67a63f8
commit c39233c86e
4 changed files with 48 additions and 48 deletions

View File

@ -75,7 +75,7 @@ gui_panel_init(&panel, 50, 50, 220, 170,
GUI_PANEL_BORDER|GUI_PANEL_MOVEABLE|
GUI_PANEL_CLOSEABLE|GUI_PANEL_SCALEABLE|
GUI_PANEL_MINIMIZABLE, &config, &font);
gui_output_init_fixed(buffer, &memory);
gui_buffer_init_fixed(buffer, &memory);
while (1) {
gui_input_begin(&input);
@ -84,7 +84,7 @@ while (1) {
struct gui_canvas canvas;
struct gui_panel_layout layout;
gui_output_begin(&canvas, &buffer, window_width, window_height);
gui_buffer_begin(&canvas, &buffer, window_width, window_height);
gui_panel_begin(&layout, &panel, "Demo", &canvas, &input);
gui_panel_row(&layout, 30, 1);
if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) {
@ -96,7 +96,7 @@ while (1) {
gui_panel_text(&layout, "input:", 5, GUI_TEXT_LEFT);
len = gui_panel_input(&layout, input, len, 256, &active, GUI_INPUT_DEFAULT);
gui_panel_end(&layout, &panel);
gui_output_end(&list, buffer, &status);
gui_buffer_end(&list, buffer, &status);
struct gui_command *cmd = list.begin;
while (cmd != list.end) {
@ -168,8 +168,8 @@ The second way is extending the fixed size memory block by reallocating at the
end of the frame if the providided memory size was not sufficient.
The final way of memory management is by providing allocator callbacks with alloc,
realloc and free. In true immediate mode fashion the buffering API is based around sequence
points with an begin sequence point `gui_output_begin` and a end sequence
point `gui_output_end` and modification of state between both points. Just
points with an begin sequence point `gui_buffer_begin` and a end sequence
point `gui_buffer_end` and modification of state between both points. Just
like the input API the buffer modification before the beginning or after the end
sequence point is undefined behavior.
@ -178,13 +178,13 @@ struct gui_memory memory = {...};
struct gui_memory_status status = {0};
struct gui_command_list out = {0};
struct gui_command_buffer buffer = {0};
gui_output_init_fixed(buffer, &memory);
gui_buffer_init_fixed(buffer, &memory);
while (1) {
struct gui_canvas canvas;
gui_output_begin(&canvas, &buffer, window_width, window_height);
gui_buffer_begin(&canvas, &buffer, window_width, window_height);
/* add commands by using the canvas */
gui_output_end(&list, buffer, &status);
gui_buffer_end(&list, buffer, &status);
}
```

View File

@ -499,7 +499,7 @@ main(int argc, char *argv[])
memset(&in, 0, sizeof in);
memory.memory = calloc(MAX_MEMORY, 1);
memory.size = MAX_MEMORY;
gui_output_init_fixed(&buffer, &memory);
gui_buffer_init_fixed(&buffer, &memory);
font.userdata = xfont;
font.height = (gui_float)xfont->height;
@ -534,11 +534,11 @@ main(int argc, char *argv[])
gui_input_end(&in);
/* GUI */
gui_output_begin(&canvas, &buffer, xw.width, xw.height);
gui_buffer_begin(&canvas, &buffer, xw.width, xw.height);
running = gui_panel_begin(&layout, &panel , "Demo", &canvas, &in);
demo_panel(&layout, &demo);
gui_panel_end(&layout, &panel);
gui_output_end(&list, &buffer, &canvas, NULL);
gui_buffer_end(&list, &buffer, &canvas, NULL);
/* Draw */
XClearWindow(xw.dpy, xw.win);

50
gui.c
View File

@ -5,7 +5,7 @@
*/
#include "gui.h"
#ifndef NDEBUG
#ifndef GUI_USE_DEBUG_BUILD
#include <assert.h>
#else
#define assert(expr)
@ -921,7 +921,7 @@ gui_scroll(const struct gui_canvas *canvas, gui_float x, gui_float y,
}
void*
gui_output_push(struct gui_command_buffer* buffer,
gui_buffer_push(struct gui_command_buffer* buffer,
enum gui_command_type type, gui_size size)
{
static const gui_size align = ALIGNOF(struct gui_command);
@ -958,12 +958,12 @@ gui_output_push(struct gui_command_buffer* buffer,
}
void
gui_output_push_scissor(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_buffer_push_scissor(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_float w, gui_float h)
{
struct gui_command_scissor *cmd;
if (!buffer) return;
cmd = gui_output_push(buffer, GUI_COMMAND_SCISSOR, sizeof(*cmd));
cmd = gui_buffer_push(buffer, GUI_COMMAND_SCISSOR, sizeof(*cmd));
if (!cmd) return;
cmd->x = x;
cmd->y = y;
@ -972,12 +972,12 @@ gui_output_push_scissor(struct gui_command_buffer *buffer, gui_float x, gui_floa
}
void
gui_output_push_line(struct gui_command_buffer *buffer, gui_float x0, gui_float y0,
gui_buffer_push_line(struct gui_command_buffer *buffer, gui_float x0, gui_float y0,
gui_float x1, gui_float y1, struct gui_color c)
{
struct gui_command_line *cmd;
if (!buffer) return;
cmd = gui_output_push(buffer, GUI_COMMAND_LINE, sizeof(*cmd));
cmd = gui_buffer_push(buffer, GUI_COMMAND_LINE, sizeof(*cmd));
if (!cmd) return;
cmd->begin[0] = x0;
cmd->begin[1] = y0;
@ -987,12 +987,12 @@ gui_output_push_line(struct gui_command_buffer *buffer, gui_float x0, gui_float
}
void
gui_output_push_rect(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_buffer_push_rect(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_float w, gui_float h, struct gui_color c)
{
struct gui_command_rect *cmd;
if (!buffer) return;
cmd = gui_output_push(buffer, GUI_COMMAND_RECT, sizeof(*cmd));
cmd = gui_buffer_push(buffer, GUI_COMMAND_RECT, sizeof(*cmd));
if (!cmd) return;
cmd->x = x;
cmd->y = y;
@ -1002,12 +1002,12 @@ gui_output_push_rect(struct gui_command_buffer *buffer, gui_float x, gui_float y
}
void
gui_output_push_circle(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_buffer_push_circle(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_float w, gui_float h, struct gui_color c)
{
struct gui_command_circle *cmd;
if (!buffer) return;
cmd = gui_output_push(buffer, GUI_COMMAND_CIRCLE, sizeof(*cmd));
cmd = gui_buffer_push(buffer, GUI_COMMAND_CIRCLE, sizeof(*cmd));
if (!cmd) return;
cmd->x = x;
cmd->y = y;
@ -1017,12 +1017,12 @@ gui_output_push_circle(struct gui_command_buffer *buffer, gui_float x, gui_float
}
void
gui_output_push_triangle(struct gui_command_buffer *buffer, gui_float x0, gui_float y0,
gui_buffer_push_triangle(struct gui_command_buffer *buffer, gui_float x0, gui_float y0,
gui_float x1, gui_float y1, gui_float x2, gui_float y2, struct gui_color c)
{
struct gui_command_triangle *cmd;
if (!buffer) return;
cmd = gui_output_push(buffer, GUI_COMMAND_TRIANGLE, sizeof(*cmd));
cmd = gui_buffer_push(buffer, GUI_COMMAND_TRIANGLE, sizeof(*cmd));
if (!cmd) return;
cmd->a[0] = x0;
cmd->a[1] = y0;
@ -1034,14 +1034,14 @@ gui_output_push_triangle(struct gui_command_buffer *buffer, gui_float x0, gui_fl
}
void
gui_output_push_text(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_buffer_push_text(struct gui_command_buffer *buffer, gui_float x, gui_float y,
gui_float w, gui_float h, const gui_char *string, gui_size length,
const struct gui_font *font, struct gui_color bg, struct gui_color fg)
{
struct gui_command_text *cmd;
if (!buffer) return;
if (!string || !length) return;
cmd = gui_output_push(buffer, GUI_COMMAND_TEXT, sizeof(*cmd) + length + 1);
cmd = gui_buffer_push(buffer, GUI_COMMAND_TEXT, sizeof(*cmd) + length + 1);
if (!cmd) return;
cmd->x = x;
cmd->y = y;
@ -1056,7 +1056,7 @@ gui_output_push_text(struct gui_command_buffer *buffer, gui_float x, gui_float y
}
void
gui_output_init_fixed(struct gui_command_buffer *buffer, const struct gui_memory *memory)
gui_buffer_init_fixed(struct gui_command_buffer *buffer, const struct gui_memory *memory)
{
zero(buffer, sizeof(*buffer));
buffer->memory = memory->memory;
@ -1066,7 +1066,7 @@ gui_output_init_fixed(struct gui_command_buffer *buffer, const struct gui_memory
}
void
gui_output_init(struct gui_command_buffer *buffer, const struct gui_allocator *memory,
gui_buffer_init(struct gui_command_buffer *buffer, const struct gui_allocator *memory,
gui_size initial_size, gui_float grow_factor)
{
zero(buffer, sizeof(*buffer));
@ -1079,22 +1079,22 @@ gui_output_init(struct gui_command_buffer *buffer, const struct gui_allocator *m
}
void
gui_output_begin(struct gui_canvas *canvas, struct gui_command_buffer *buffer,
gui_buffer_begin(struct gui_canvas *canvas, struct gui_command_buffer *buffer,
gui_size width, gui_size height)
{
canvas->userdata = buffer;
canvas->width = width;
canvas->height = height;
canvas->scissor = (gui_scissor)gui_output_push_scissor;
canvas->draw_line = (gui_draw_line)gui_output_push_line;
canvas->draw_rect = (gui_draw_rect)gui_output_push_rect;
canvas->draw_circle = (gui_draw_circle)gui_output_push_circle;
canvas->draw_triangle = (gui_draw_triangle)gui_output_push_triangle;
canvas->draw_text = (gui_draw_text)gui_output_push_text;
canvas->scissor = (gui_scissor)gui_buffer_push_scissor;
canvas->draw_line = (gui_draw_line)gui_buffer_push_line;
canvas->draw_rect = (gui_draw_rect)gui_buffer_push_rect;
canvas->draw_circle = (gui_draw_circle)gui_buffer_push_circle;
canvas->draw_triangle = (gui_draw_triangle)gui_buffer_push_triangle;
canvas->draw_text = (gui_draw_text)gui_buffer_push_text;
}
void
gui_output_end(struct gui_command_list *list, struct gui_command_buffer *buffer,
gui_buffer_end(struct gui_command_list *list, struct gui_command_buffer *buffer,
struct gui_canvas *canvas, struct gui_memory_status *status)
{
assert(buffer);
@ -1118,7 +1118,7 @@ gui_output_end(struct gui_command_list *list, struct gui_command_buffer *buffer,
}
void
gui_output_clear(struct gui_command_buffer *buffer)
gui_buffer_clear(struct gui_command_buffer *buffer)
{
assert(buffer);
if (!buffer || !buffer->memory || !buffer->allocator.free) return;

24
gui.h
View File

@ -382,28 +382,28 @@ void gui_input_end(struct gui_input*);
/* Output */
void gui_output_init(struct gui_command_buffer*, const struct gui_allocator*,
void gui_buffer_init(struct gui_command_buffer*, const struct gui_allocator*,
gui_size initial_size, gui_float grow_factor);
void gui_output_init_fixed(struct gui_command_buffer*, const struct gui_memory*);
void gui_output_begin(struct gui_canvas *canvas, struct gui_command_buffer *buffer,
void gui_buffer_init_fixed(struct gui_command_buffer*, const struct gui_memory*);
void gui_buffer_begin(struct gui_canvas *canvas, struct gui_command_buffer *buffer,
gui_size width, gui_size height);
void *gui_output_push(struct gui_command_buffer*,
void *gui_buffer_push(struct gui_command_buffer*,
enum gui_command_type, gui_size size);
void gui_output_push_scissor(struct gui_command_buffer*, gui_float, gui_float,
void gui_buffer_push_scissor(struct gui_command_buffer*, gui_float, gui_float,
gui_float, gui_float);
void gui_output_push_line(struct gui_command_buffer*, gui_float, gui_float,
void gui_buffer_push_line(struct gui_command_buffer*, gui_float, gui_float,
gui_float, gui_float, struct gui_color);
void gui_output_push_rect(struct gui_command_buffer*, gui_float, gui_float,
void gui_buffer_push_rect(struct gui_command_buffer*, gui_float, gui_float,
gui_float, gui_float, struct gui_color);
void gui_output_push_circle(struct gui_command_buffer*, gui_float, gui_float,
void gui_buffer_push_circle(struct gui_command_buffer*, gui_float, gui_float,
gui_float, gui_float, struct gui_color);
void gui_output_push_triangle(struct gui_command_buffer *buffer, gui_float x0, gui_float y0,
void gui_buffer_push_triangle(struct gui_command_buffer *buffer, gui_float x0, gui_float y0,
gui_float x1, gui_float y1, gui_float x2, gui_float y2, struct gui_color c);
void gui_output_push_text(struct gui_command_buffer*, gui_float, gui_float,
void gui_buffer_push_text(struct gui_command_buffer*, gui_float, gui_float,
gui_float, gui_float, const gui_char*, gui_size,
const struct gui_font*, struct gui_color, struct gui_color);
void gui_output_clear(struct gui_command_buffer*);
void gui_output_end(struct gui_command_list*, struct gui_command_buffer*,
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*);