some cleaning up
parent
ee625e60c2
commit
138f6b3af5
|
@ -273,40 +273,40 @@ device_draw(struct device *dev, struct zr_context *ctx, enum zr_anti_aliasing AA
|
|||
}
|
||||
|
||||
static void
|
||||
input_key(struct zr_input *in, ALLEGRO_EVENT *evt, int down)
|
||||
input_key(struct zr_context *ctx, ALLEGRO_EVENT *evt, int down)
|
||||
{
|
||||
int sym = evt->keyboard.keycode;
|
||||
if (sym == ALLEGRO_KEY_RSHIFT || sym == ALLEGRO_KEY_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == ALLEGRO_KEY_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == ALLEGRO_KEY_ENTER)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == ALLEGRO_KEY_TAB)
|
||||
zr_input_key(in, ZR_KEY_TAB, down);
|
||||
zr_input_key(ctx, ZR_KEY_TAB, down);
|
||||
else if (sym == ALLEGRO_KEY_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == ALLEGRO_KEY_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == ALLEGRO_KEY_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == ALLEGRO_KEY_C)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_V)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_X)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
}
|
||||
|
||||
static void
|
||||
input_button(struct zr_input *in, ALLEGRO_EVENT *evt, int down)
|
||||
input_button(struct zr_context *ctx, ALLEGRO_EVENT *evt, int down)
|
||||
{
|
||||
const int x = evt->mouse.x;
|
||||
const int y = evt->mouse.y;
|
||||
if (evt->mouse.button == 1)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
if (evt->mouse.button == 2)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
}
|
||||
|
||||
static void* mem_alloc(zr_handle unused, size_t size)
|
||||
|
@ -360,26 +360,26 @@ main(int argc, char *argv[])
|
|||
while (running) {
|
||||
/* Input */
|
||||
ALLEGRO_EVENT evt;
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
while (al_get_next_event(dev.queue, &evt)) {
|
||||
if (evt.type == ALLEGRO_EVENT_DISPLAY_CLOSE) goto cleanup;
|
||||
else if (evt.type == ALLEGRO_EVENT_KEY_UP && evt.keyboard.display == dev.display)
|
||||
input_key(&gui.ctx.input, &evt, zr_false);
|
||||
input_key(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == ALLEGRO_EVENT_KEY_DOWN && evt.keyboard.display == dev.display)
|
||||
input_key(&gui.ctx.input, &evt, zr_true);
|
||||
input_key(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
|
||||
input_button(&gui.ctx.input, &evt, zr_true);
|
||||
input_button(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
|
||||
input_button(&gui.ctx.input, &evt, zr_false);
|
||||
input_button(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == ALLEGRO_EVENT_MOUSE_AXES) {
|
||||
zr_input_motion(&gui.ctx.input, evt.mouse.x, evt.mouse.y);
|
||||
zr_input_motion(&gui.ctx, evt.mouse.x, evt.mouse.y);
|
||||
} else if (evt.type == ALLEGRO_EVENT_KEY_CHAR) {
|
||||
if (evt.keyboard.display == dev.display)
|
||||
if (evt.keyboard.unichar > 0 && evt.keyboard.unichar < 0x10000)
|
||||
zr_input_unicode(&gui.ctx.input, (zr_rune)evt.keyboard.unichar);
|
||||
zr_input_unicode(&gui.ctx, (zr_rune)evt.keyboard.unichar);
|
||||
}
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
running = run_demo(&gui);
|
||||
|
|
|
@ -119,40 +119,40 @@ font_get_width(zr_handle handle, float height, const char *text, size_t len)
|
|||
}
|
||||
|
||||
static void
|
||||
input_key(struct zr_input *in, ALLEGRO_EVENT *evt, int down)
|
||||
input_key(struct zr_context *ctx, ALLEGRO_EVENT *evt, int down)
|
||||
{
|
||||
int sym = evt->keyboard.keycode;
|
||||
if (sym == ALLEGRO_KEY_RSHIFT || sym == ALLEGRO_KEY_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == ALLEGRO_KEY_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == ALLEGRO_KEY_ENTER)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == ALLEGRO_KEY_TAB)
|
||||
zr_input_key(in, ZR_KEY_TAB, down);
|
||||
zr_input_key(ctx, ZR_KEY_TAB, down);
|
||||
else if (sym == ALLEGRO_KEY_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == ALLEGRO_KEY_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == ALLEGRO_KEY_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == ALLEGRO_KEY_C)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_V)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_X)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
}
|
||||
|
||||
static void
|
||||
input_button(struct zr_input *in, ALLEGRO_EVENT *evt, int down)
|
||||
input_button(struct zr_context *ctx, ALLEGRO_EVENT *evt, int down)
|
||||
{
|
||||
const int x = evt->mouse.x;
|
||||
const int y = evt->mouse.y;
|
||||
if (evt->mouse.button == 1)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
if (evt->mouse.button == 2)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
}
|
||||
|
||||
static void* mem_alloc(zr_handle unused, size_t size)
|
||||
|
@ -211,26 +211,26 @@ main(int argc, char *argv[])
|
|||
while (running) {
|
||||
/* Input */
|
||||
ALLEGRO_EVENT evt;
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
while (al_get_next_event(queue, &evt)) {
|
||||
if (evt.type == ALLEGRO_EVENT_DISPLAY_CLOSE) goto cleanup;
|
||||
else if (evt.type == ALLEGRO_EVENT_KEY_UP && evt.keyboard.display == display)
|
||||
input_key(&gui.ctx.input, &evt, zr_false);
|
||||
input_key(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == ALLEGRO_EVENT_KEY_DOWN && evt.keyboard.display == display)
|
||||
input_key(&gui.ctx.input, &evt, zr_true);
|
||||
input_key(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
|
||||
input_button(&gui.ctx.input, &evt, zr_true);
|
||||
input_button(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
|
||||
input_button(&gui.ctx.input, &evt, zr_false);
|
||||
input_button(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == ALLEGRO_EVENT_MOUSE_AXES) {
|
||||
zr_input_motion(&gui.ctx.input, evt.mouse.x, evt.mouse.y);
|
||||
zr_input_motion(&gui.ctx, evt.mouse.x, evt.mouse.y);
|
||||
} else if (evt.type == ALLEGRO_EVENT_KEY_CHAR) {
|
||||
if (evt.keyboard.display == display)
|
||||
if (evt.keyboard.unichar > 0 && evt.keyboard.unichar < 0x10000)
|
||||
zr_input_unicode(&gui.ctx.input, (zr_rune)evt.keyboard.unichar);
|
||||
zr_input_unicode(&gui.ctx, (zr_rune)evt.keyboard.unichar);
|
||||
}
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
width = al_get_display_width(display);
|
||||
|
|
19
demo/demo.c
19
demo/demo.c
|
@ -79,8 +79,7 @@ set_style(struct zr_context *ctx, enum theme theme)
|
|||
ctx->style.colors[ZR_COLOR_SCALER] = zr_rgba(100, 100, 100, 255);
|
||||
}
|
||||
else {
|
||||
struct zr_user_font fnt = ctx->style.font;
|
||||
zr_style_default(&ctx->style, ZR_DEFAULT_ALL, &fnt);
|
||||
zr_load_default_style(ctx, ZR_DEFAULT_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +203,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
ZR_WINDOW_CLOSEABLE, zr_rect(10, 100, 360, 280)))
|
||||
{
|
||||
zr_layout_row_dynamic(ctx, 30, 2);
|
||||
zr_label(ctx, zr_style_color_name((enum zr_style_colors)color_picker_index), ZR_TEXT_LEFT);
|
||||
zr_label(ctx, zr_get_color_name((enum zr_style_colors)color_picker_index), ZR_TEXT_LEFT);
|
||||
zr_button_color(ctx, color_picker_color, ZR_BUTTON_DEFAULT);
|
||||
|
||||
/* color selection */
|
||||
|
@ -281,7 +280,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
size_t i = 0;
|
||||
zr_layout_row_dynamic(ctx, 30, 3);
|
||||
for (i = 0; i <= ZR_PROPERTY_SCROLLBAR_SIZE; ++i) {
|
||||
zr_label(ctx, zr_style_property_name((enum zr_style_properties)i), ZR_TEXT_LEFT);
|
||||
zr_label(ctx, zr_get_property_name((enum zr_style_properties)i), ZR_TEXT_LEFT);
|
||||
zr_property_float(ctx, "#X:", 0, &ctx->style.properties[i].x, 20, 1, 1);
|
||||
zr_property_float(ctx, "#Y:", 0, &ctx->style.properties[i].y, 20, 1, 1);
|
||||
}
|
||||
|
@ -292,7 +291,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
size_t i = 0;
|
||||
zr_layout_row_dynamic(ctx, 30, 2);
|
||||
for (i = 0; i < ZR_ROUNDING_MAX; ++i) {
|
||||
zr_label(ctx, zr_style_rounding_name((enum zr_style_rounding)i), ZR_TEXT_LEFT);
|
||||
zr_label(ctx, zr_get_rounding_name((enum zr_style_rounding)i), ZR_TEXT_LEFT);
|
||||
zr_property_float(ctx, "#R:", 0, &ctx->style.rounding[i], 20, 1, 1);
|
||||
}
|
||||
zr_layout_pop(ctx);
|
||||
|
@ -307,7 +306,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
if (zr_group_begin(ctx, &tab, "Color_Picker", 0)) {
|
||||
for (i = 0; i < ZR_COLOR_COUNT; ++i) {
|
||||
zr_layout_row_dynamic(ctx, 30, 2);
|
||||
zr_label(ctx, zr_style_color_name((enum zr_style_colors)i), ZR_TEXT_LEFT);
|
||||
zr_label(ctx, zr_get_color_name((enum zr_style_colors)i), ZR_TEXT_LEFT);
|
||||
if (zr_button_color(ctx, ctx->style.colors[i], ZR_BUTTON_DEFAULT)) {
|
||||
show_color_picker_popup = zr_true;
|
||||
color_picker_index = (int)i;
|
||||
|
@ -728,7 +727,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
|
||||
/* tiles */
|
||||
zr_layout_row(ctx, ZR_STATIC, 200, 5, row_layout);
|
||||
zr_style_push_property(&ctx->style, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
|
||||
zr_push_property(ctx, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
|
||||
|
||||
/* left space */
|
||||
if (zr_group_begin(ctx, &sub, "left", ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_BORDER)) {
|
||||
|
@ -770,7 +769,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
zr_group_end(ctx);
|
||||
}
|
||||
|
||||
zr_style_pop_property(&ctx->style);
|
||||
zr_pop_property(ctx);
|
||||
zr_layout_pop(ctx);
|
||||
}
|
||||
|
||||
|
@ -791,7 +790,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
zr_label(ctx, "bottom:", ZR_TEXT_LEFT);
|
||||
zr_slider_float(ctx, 10.0f, &c, 200.0f, 10.0f);
|
||||
|
||||
zr_style_push_property(&ctx->style, ZR_PROPERTY_ITEM_SPACING, zr_vec2(4, 0));
|
||||
zr_push_property(ctx, ZR_PROPERTY_ITEM_SPACING, zr_vec2(4, 0));
|
||||
|
||||
/* top space */
|
||||
zr_layout_row_dynamic(ctx, a, 1);
|
||||
|
@ -838,7 +837,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
zr_group_end(ctx);
|
||||
}
|
||||
|
||||
zr_style_pop_property(&ctx->style);
|
||||
zr_pop_property(ctx);
|
||||
zr_layout_pop(ctx);
|
||||
}
|
||||
zr_layout_pop(ctx);
|
||||
|
|
|
@ -380,25 +380,25 @@ input_key(GLFWwindow *window, int key, int scancode, int action, int mods)
|
|||
UNUSED(window);
|
||||
UNUSED(scancode);
|
||||
if (key == GLFW_KEY_RIGHT_SHIFT || key == GLFW_KEY_LEFT_SHIFT)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_SHIFT, down);
|
||||
else if (key == GLFW_KEY_DELETE)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_DEL, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_DEL, down);
|
||||
else if (key == GLFW_KEY_ENTER)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_ENTER, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_ENTER, down);
|
||||
else if (key == GLFW_KEY_TAB)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_TAB, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_TAB, down);
|
||||
else if (key == GLFW_KEY_BACKSPACE)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (key == GLFW_KEY_LEFT)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_LEFT, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_LEFT, down);
|
||||
else if (key == GLFW_KEY_RIGHT)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(&gui.ctx, ZR_KEY_RIGHT, down);
|
||||
else if (key == GLFW_KEY_C)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_COPY, down && (mods & GLFW_MOD_CONTROL));
|
||||
zr_input_key(&gui.ctx, ZR_KEY_COPY, down && (mods & GLFW_MOD_CONTROL));
|
||||
else if (key == GLFW_KEY_V)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_PASTE, down && (mods & GLFW_MOD_CONTROL));
|
||||
zr_input_key(&gui.ctx, ZR_KEY_PASTE, down && (mods & GLFW_MOD_CONTROL));
|
||||
else if (key == GLFW_KEY_X)
|
||||
zr_input_key(&gui.ctx.input, ZR_KEY_CUT, down && (mods & GLFW_MOD_CONTROL));
|
||||
zr_input_key(&gui.ctx, ZR_KEY_CUT, down && (mods & GLFW_MOD_CONTROL));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -409,28 +409,27 @@ input_motion(GLFWwindow *window, double xpos, double ypos)
|
|||
UNUSED(window);
|
||||
mouse_pos_x = x;
|
||||
mouse_pos_y = y;
|
||||
zr_input_motion(&gui.ctx.input, x, y);
|
||||
zr_input_motion(&gui.ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
input_button(GLFWwindow *window, int button, int action, int mods)
|
||||
{
|
||||
struct zr_input *in = &gui.ctx.input;
|
||||
int x = mouse_pos_x;
|
||||
int y = mouse_pos_y;
|
||||
UNUSED(window);
|
||||
UNUSED(mods);
|
||||
if (button == 0)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, action == GLFW_PRESS);
|
||||
zr_input_button(&gui.ctx, ZR_BUTTON_LEFT, x, y, action == GLFW_PRESS);
|
||||
if (button == 1)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, action == GLFW_PRESS);
|
||||
zr_input_button(&gui.ctx, ZR_BUTTON_RIGHT, x, y, action == GLFW_PRESS);
|
||||
}
|
||||
|
||||
static void
|
||||
input_text(GLFWwindow *window, unsigned int codepoint)
|
||||
{
|
||||
UNUSED(window);
|
||||
zr_input_unicode(&gui.ctx.input, codepoint);
|
||||
zr_input_unicode(&gui.ctx, codepoint);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -438,7 +437,7 @@ input_scroll(GLFWwindow *window, double xoffset, double yoffset)
|
|||
{
|
||||
UNUSED(window);
|
||||
UNUSED(xoffset);
|
||||
zr_input_scroll(&gui.ctx.input, (float)yoffset);
|
||||
zr_input_scroll(&gui.ctx, (float)yoffset);
|
||||
}
|
||||
|
||||
static void* mem_alloc(zr_handle unused, size_t size)
|
||||
|
@ -505,9 +504,9 @@ main(int argc, char *argv[])
|
|||
device_init(&device);
|
||||
while (!glfwWindowShouldClose(win) && running) {
|
||||
/* Input */
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
glfwPollEvents();
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
glfwGetWindowSize(win, &width, &height);
|
||||
|
|
|
@ -544,60 +544,60 @@ device_draw(struct device *dev, struct zr_context *ctx, int width, int height,
|
|||
|
||||
|
||||
static void
|
||||
input_key(struct XWindow *xw, struct zr_input *in, XEvent *evt, int down)
|
||||
input_key(struct XWindow *xw, struct zr_context *ctx, XEvent *evt, int down)
|
||||
{
|
||||
int ret;
|
||||
KeySym *code = XGetKeyboardMapping(xw->dpy, (KeyCode)evt->xkey.keycode, 1, &ret);
|
||||
if (*code == XK_Shift_L || *code == XK_Shift_R)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (*code == XK_Delete)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (*code == XK_Return)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (*code == XK_Tab)
|
||||
zr_input_key(in, ZR_KEY_TAB, down);
|
||||
zr_input_key(ctx, ZR_KEY_TAB, down);
|
||||
else if (*code == XK_space && !down)
|
||||
zr_input_char(in, ' ');
|
||||
zr_input_char(ctx, ' ');
|
||||
else if (*code == XK_Left)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (*code == XK_Right)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (*code == XK_BackSpace)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (*code > 32 && *code < 128) {
|
||||
if (*code == 'c')
|
||||
zr_input_key(in, ZR_KEY_COPY, down && (evt->xkey.state & ControlMask));
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && (evt->xkey.state & ControlMask));
|
||||
else if (*code == 'v')
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && (evt->xkey.state & ControlMask));
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && (evt->xkey.state & ControlMask));
|
||||
else if (*code == 'x')
|
||||
zr_input_key(in, ZR_KEY_CUT, down && (evt->xkey.state & ControlMask));
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && (evt->xkey.state & ControlMask));
|
||||
if (!down)
|
||||
zr_input_unicode(in, (zr_rune)*code);
|
||||
zr_input_unicode(ctx, (zr_rune)*code);
|
||||
}
|
||||
XFree(code);
|
||||
}
|
||||
|
||||
static void
|
||||
input_motion(struct zr_input *in, XEvent *evt)
|
||||
input_motion(struct zr_context *ctx, XEvent *evt)
|
||||
{
|
||||
const int x = evt->xmotion.x;
|
||||
const int y = evt->xmotion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
zr_input_motion(ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
input_button(struct zr_input *in, XEvent *evt, int down)
|
||||
input_button(struct zr_context *ctx, XEvent *evt, int down)
|
||||
{
|
||||
const int x = evt->xbutton.x;
|
||||
const int y = evt->xbutton.y;
|
||||
if (evt->xbutton.button == Button1)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
else if (evt->xbutton.button == Button3)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
else if (evt->xbutton.button == Button4)
|
||||
zr_input_scroll(in, 1.0f);
|
||||
zr_input_scroll(ctx, 1.0f);
|
||||
else if (evt->xbutton.button == Button5)
|
||||
zr_input_scroll(in, -1.0f);
|
||||
zr_input_scroll(ctx, -1.0f);
|
||||
}
|
||||
|
||||
static void* mem_alloc(zr_handle unused, size_t size)
|
||||
|
@ -862,25 +862,25 @@ int main(int argc, char **argv)
|
|||
while (running) {
|
||||
/* input */
|
||||
XEvent evt;
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
while (XCheckWindowEvent(win.dpy, win.win, win.swa.event_mask, &evt)) {
|
||||
if (evt.type == KeyPress)
|
||||
input_key(&win, &gui.ctx.input, &evt, zr_true);
|
||||
input_key(&win, &gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == KeyRelease)
|
||||
input_key(&win, &gui.ctx.input, &evt, zr_false);
|
||||
input_key(&win, &gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == ButtonPress)
|
||||
input_button(&gui.ctx.input, &evt, zr_true);
|
||||
input_button(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == ButtonRelease)
|
||||
input_button(&gui.ctx.input, &evt, zr_false);
|
||||
input_button(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == MotionNotify)
|
||||
input_motion(&gui.ctx.input, &evt);
|
||||
input_motion(&gui.ctx, &evt);
|
||||
else if (evt.type == Expose || evt.type == ConfigureNotify) {
|
||||
XGetWindowAttributes(win.dpy, win.win, &win.attr);
|
||||
win.width = win.attr.width;
|
||||
win.height = win.attr.height;
|
||||
}
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
XGetWindowAttributes(win.dpy, win.win, &win.attr);
|
||||
|
|
|
@ -177,55 +177,57 @@ draw(NVGcontext *nvg, struct zr_context *ctx, int width, int height)
|
|||
}
|
||||
|
||||
static void
|
||||
key(struct zr_input *in, SDL_Event *evt, int down)
|
||||
input_key(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
SDL_Keycode sym = evt->key.keysym.sym;
|
||||
if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == SDLK_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == SDLK_RETURN)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == SDLK_TAB)
|
||||
zr_input_key(ctx, ZR_KEY_TAB, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == SDLK_c)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_v)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_x)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
}
|
||||
|
||||
static void
|
||||
motion(struct zr_input *in, SDL_Event *evt)
|
||||
input_motion(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
const int x = evt->motion.x;
|
||||
const int y = evt->motion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
zr_input_motion(ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
btn(struct zr_input *in, SDL_Event *evt, int down)
|
||||
input_button(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
}
|
||||
|
||||
static void
|
||||
text(struct zr_input *in, SDL_Event *evt)
|
||||
input_text(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
zr_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, ZR_UTF_SIZE);
|
||||
zr_input_glyph(in, glyph);
|
||||
zr_input_glyph(ctx, glyph);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -299,7 +301,7 @@ main(int argc, char *argv[])
|
|||
uint64_t dt, started = SDL_GetTicks();
|
||||
|
||||
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
|
@ -307,17 +309,17 @@ main(int argc, char *argv[])
|
|||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP) key(&gui.ctx.input, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN) key(&gui.ctx.input, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN) btn(&gui.ctx.input, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP) btn(&gui.ctx.input, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION) motion(&gui.ctx.input, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&gui.ctx.input, &evt);
|
||||
else if (evt.type == SDL_KEYUP) input_key(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN) input_key(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN) input_button(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP) input_button(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION) input_motion(&gui.ctx, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) input_text(&gui.ctx, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL)
|
||||
zr_input_scroll(&gui.ctx.input,(float)evt.wheel.y);
|
||||
zr_input_scroll(&gui.ctx,(float)evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
SDL_GetWindowSize(win, &width, &height);
|
||||
|
|
|
@ -359,57 +359,57 @@ device_draw(struct device *dev, struct zr_context *ctx, int width, int height,
|
|||
}
|
||||
|
||||
static void
|
||||
input_key(struct zr_input *in, SDL_Event *evt, int down)
|
||||
input_key(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
SDL_Keycode sym = evt->key.keysym.sym;
|
||||
if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == SDLK_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == SDLK_RETURN)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == SDLK_TAB)
|
||||
zr_input_key(in, ZR_KEY_TAB, down);
|
||||
zr_input_key(ctx, ZR_KEY_TAB, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == SDLK_c)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_v)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_x)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
}
|
||||
|
||||
static void
|
||||
input_motion(struct zr_input *in, SDL_Event *evt)
|
||||
input_motion(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
const int x = evt->motion.x;
|
||||
const int y = evt->motion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
zr_input_motion(ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
input_button(struct zr_input *in, SDL_Event *evt, int down)
|
||||
input_button(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
}
|
||||
|
||||
static void
|
||||
input_text(struct zr_input *in, SDL_Event *evt)
|
||||
input_text(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
zr_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, ZR_UTF_SIZE);
|
||||
zr_input_glyph(in, glyph);
|
||||
zr_input_glyph(ctx, glyph);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -476,26 +476,26 @@ main(int argc, char *argv[])
|
|||
while (running) {
|
||||
/* Input */
|
||||
SDL_Event evt;
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
while (SDL_PollEvent(&evt)) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP)
|
||||
input_key(&gui.ctx.input, &evt, zr_false);
|
||||
input_key(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN)
|
||||
input_key(&gui.ctx.input, &evt, zr_true);
|
||||
input_key(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN)
|
||||
input_button(&gui.ctx.input, &evt, zr_true);
|
||||
input_button(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP)
|
||||
input_button(&gui.ctx.input, &evt, zr_false);
|
||||
input_button(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION)
|
||||
input_motion(&gui.ctx.input, &evt);
|
||||
input_motion(&gui.ctx, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT)
|
||||
input_text(&gui.ctx.input, &evt);
|
||||
input_text(&gui.ctx, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL)
|
||||
zr_input_scroll(&gui.ctx.input,(float)evt.wheel.y);
|
||||
zr_input_scroll(&gui.ctx,(float)evt.wheel.y);
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
SDL_GetWindowSize(win, &width, &height);
|
||||
|
|
|
@ -314,60 +314,60 @@ surface_del(XSurface *surf)
|
|||
}
|
||||
|
||||
static void
|
||||
input_key(struct XWindow *xw, struct zr_input *in, XEvent *evt, int down)
|
||||
input_key(struct XWindow *xw, struct zr_context *ctx, XEvent *evt, int down)
|
||||
{
|
||||
int ret;
|
||||
KeySym *code = XGetKeyboardMapping(xw->dpy, (KeyCode)evt->xkey.keycode, 1, &ret);
|
||||
if (*code == XK_Shift_L || *code == XK_Shift_R)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (*code == XK_Delete)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (*code == XK_Return)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (*code == XK_Tab)
|
||||
zr_input_key(in, ZR_KEY_TAB, down);
|
||||
zr_input_key(ctx, ZR_KEY_TAB, down);
|
||||
else if (*code == XK_space && !down)
|
||||
zr_input_char(in, ' ');
|
||||
zr_input_char(ctx, ' ');
|
||||
else if (*code == XK_Left)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (*code == XK_Right)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (*code == XK_BackSpace)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (*code > 32 && *code < 128) {
|
||||
if (*code == 'c')
|
||||
zr_input_key(in, ZR_KEY_COPY, down && (evt->xkey.state & ControlMask));
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && (evt->xkey.state & ControlMask));
|
||||
else if (*code == 'v')
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && (evt->xkey.state & ControlMask));
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && (evt->xkey.state & ControlMask));
|
||||
else if (*code == 'x')
|
||||
zr_input_key(in, ZR_KEY_CUT, down && (evt->xkey.state & ControlMask));
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && (evt->xkey.state & ControlMask));
|
||||
if (!down)
|
||||
zr_input_unicode(in, (zr_rune)*code);
|
||||
zr_input_unicode(ctx, (zr_rune)*code);
|
||||
}
|
||||
XFree(code);
|
||||
}
|
||||
|
||||
static void
|
||||
input_motion(struct zr_input *in, XEvent *evt)
|
||||
input_motion(struct zr_context *ctx, XEvent *evt)
|
||||
{
|
||||
const int x = evt->xmotion.x;
|
||||
const int y = evt->xmotion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
zr_input_motion(ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
input_button(struct zr_input *in, XEvent *evt, int down)
|
||||
input_button(struct zr_context *ctx, XEvent *evt, int down)
|
||||
{
|
||||
const int x = evt->xbutton.x;
|
||||
const int y = evt->xbutton.y;
|
||||
if (evt->xbutton.button == Button1)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
else if (evt->xbutton.button == Button3)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
else if (evt->xbutton.button == Button4)
|
||||
zr_input_scroll(in, 1.0f);
|
||||
zr_input_scroll(ctx, 1.0f);
|
||||
else if (evt->xbutton.button == Button5)
|
||||
zr_input_scroll(in, -1.0f);
|
||||
zr_input_scroll(ctx, -1.0f);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -426,22 +426,22 @@ main(int argc, char *argv[])
|
|||
/* Input */
|
||||
XEvent evt;
|
||||
started = timestamp();
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
zr_input_begin(&gui.ctx);
|
||||
while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &evt)) {
|
||||
if (evt.type == KeyPress)
|
||||
input_key(&xw, &gui.ctx.input, &evt, zr_true);
|
||||
input_key(&xw, &gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == KeyRelease)
|
||||
input_key(&xw, &gui.ctx.input, &evt, zr_false);
|
||||
input_key(&xw, &gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == ButtonPress)
|
||||
input_button(&gui.ctx.input, &evt, zr_true);
|
||||
input_button(&gui.ctx, &evt, zr_true);
|
||||
else if (evt.type == ButtonRelease)
|
||||
input_button(&gui.ctx.input, &evt, zr_false);
|
||||
input_button(&gui.ctx, &evt, zr_false);
|
||||
else if (evt.type == MotionNotify)
|
||||
input_motion(&gui.ctx.input, &evt);
|
||||
input_motion(&gui.ctx, &evt);
|
||||
else if (evt.type == Expose || evt.type == ConfigureNotify)
|
||||
resize(&xw, xw.surf);
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
zr_input_end(&gui.ctx);
|
||||
|
||||
/* GUI */
|
||||
running = run_demo(&gui);
|
||||
|
|
|
@ -90,8 +90,8 @@ die(const char *fmt, ...)
|
|||
static void
|
||||
ui_header(struct zr_context *ctx, const char *title)
|
||||
{
|
||||
zr_style_reset_font_height(&ctx->style);
|
||||
zr_style_push_font_height(&ctx->style, 18);
|
||||
zr_reset_font_height(ctx);
|
||||
zr_push_font_height(ctx, 18);
|
||||
zr_layout_row_dynamic(ctx, 20, 1);
|
||||
zr_label(ctx, title, ZR_TEXT_LEFT);
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ static void
|
|||
ui_widget(struct zr_context *ctx, float height, float font_height)
|
||||
{
|
||||
static const float ratio[] = {0.15f, 0.85f};
|
||||
zr_style_reset_font_height(&ctx->style);
|
||||
zr_style_push_font_height(&ctx->style, font_height);
|
||||
zr_reset_font_height(ctx);
|
||||
zr_push_font_height(ctx, font_height);
|
||||
zr_layout_row(ctx, ZR_DYNAMIC, height, 2, ratio);
|
||||
zr_spacing(ctx, 1);
|
||||
}
|
||||
|
@ -110,8 +110,8 @@ static void
|
|||
ui_widget_centered(struct zr_context *ctx, float height, float font_height)
|
||||
{
|
||||
static const float ratio[] = {0.15f, 0.50f, 0.35f};
|
||||
zr_style_reset_font_height(&ctx->style);
|
||||
zr_style_push_font_height(&ctx->style, font_height);
|
||||
zr_reset_font_height(ctx);
|
||||
zr_push_font_height(ctx, font_height);
|
||||
zr_layout_row(ctx, ZR_DYNAMIC, height, 3, ratio);
|
||||
zr_spacing(ctx, 1);
|
||||
}
|
||||
|
@ -128,9 +128,9 @@ ui_piemenu(struct zr_context *ctx,
|
|||
|
||||
/* hide popup background */
|
||||
struct zr_color border;
|
||||
zr_style_push_color(&ctx->style, ZR_COLOR_WINDOW, zr_rgba(0,0,0,0));
|
||||
zr_push_color(ctx, ZR_COLOR_WINDOW, zr_rgba(0,0,0,0));
|
||||
border = ctx->style.colors[ZR_COLOR_BORDER];
|
||||
zr_style_push_color(&ctx->style, ZR_COLOR_BORDER, zr_rgba(0,0,0,0));
|
||||
zr_push_color(ctx, ZR_COLOR_BORDER, zr_rgba(0,0,0,0));
|
||||
if (ctx->current != ctx->active) return 0;
|
||||
|
||||
/* pie menu popup */
|
||||
|
@ -213,8 +213,8 @@ ui_piemenu(struct zr_context *ctx,
|
|||
zr_layout_space_end(ctx);
|
||||
zr_popup_end(ctx);
|
||||
|
||||
zr_style_reset_colors(&ctx->style);
|
||||
zr_style_reset_properties(&ctx->style);
|
||||
zr_reset_colors(ctx);
|
||||
zr_reset_properties(ctx);
|
||||
|
||||
if (!zr_input_is_mouse_down(&ctx->input, ZR_BUTTON_RIGHT))
|
||||
return active_item;
|
||||
|
@ -611,57 +611,57 @@ draw(NVGcontext *nvg, struct zr_context *ctx, int width, int height)
|
|||
|
||||
|
||||
static void
|
||||
key(struct zr_input *in, SDL_Event *evt, int down)
|
||||
key(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
SDL_Keycode sym = evt->key.keysym.sym;
|
||||
if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == SDLK_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == SDLK_RETURN)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == SDLK_c)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_v)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_x)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
}
|
||||
|
||||
static void
|
||||
motion(struct zr_input *in, SDL_Event *evt)
|
||||
motion(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
const int x = evt->motion.x;
|
||||
const int y = evt->motion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
zr_input_motion(ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
btn(struct zr_input *in, SDL_Event *evt, int down)
|
||||
btn(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_MIDDLE)
|
||||
zr_input_button(in, ZR_BUTTON_MIDDLE, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_MIDDLE, x, y, down);
|
||||
}
|
||||
|
||||
static void
|
||||
text(struct zr_input *in, SDL_Event *evt)
|
||||
text(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
zr_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, ZR_UTF_SIZE);
|
||||
zr_input_glyph(in, glyph);
|
||||
zr_input_glyph(ctx, glyph);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -765,7 +765,7 @@ main(int argc, char *argv[])
|
|||
int ret;
|
||||
SDL_Event evt;
|
||||
started = SDL_GetTicks();
|
||||
zr_input_begin(&ctx.input);
|
||||
zr_input_begin(&ctx);
|
||||
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
|
@ -778,22 +778,22 @@ main(int argc, char *argv[])
|
|||
glViewport(0, 0, evt.window.data1, evt.window.data2);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP)
|
||||
key(&ctx.input, &evt, zr_false);
|
||||
key(&ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN)
|
||||
key(&ctx.input, &evt, zr_true);
|
||||
key(&ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN)
|
||||
btn(&ctx.input, &evt, zr_true);
|
||||
btn(&ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP)
|
||||
btn(&ctx.input, &evt, zr_false);
|
||||
btn(&ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION)
|
||||
motion(&ctx.input, &evt);
|
||||
motion(&ctx, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT)
|
||||
text(&ctx.input, &evt);
|
||||
text(&ctx, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL)
|
||||
zr_input_scroll(&ctx.input, evt.wheel.y);
|
||||
zr_input_scroll(&ctx, evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&ctx.input);
|
||||
zr_input_end(&ctx);
|
||||
|
||||
/* GUI */
|
||||
button_demo(&ctx, &icons);
|
||||
|
|
|
@ -457,13 +457,14 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
{
|
||||
struct zr_layout sub;
|
||||
float row_layout[3];
|
||||
|
||||
/* output path directory selector in the menubar */
|
||||
zr_menubar_begin(ctx);
|
||||
{
|
||||
char *d = browser->directory;
|
||||
char *begin = d + 1;
|
||||
zr_layout_row_dynamic(ctx, 25, 6);
|
||||
zr_style_push_property(&ctx->style, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
|
||||
zr_push_property(ctx, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
|
||||
while (*d++) {
|
||||
if (*d == '/') {
|
||||
*d = '\0';
|
||||
|
@ -476,7 +477,7 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
begin = d + 1;
|
||||
}
|
||||
}
|
||||
zr_style_pop_property(&ctx->style);
|
||||
zr_pop_property(ctx);
|
||||
}
|
||||
zr_menubar_end(ctx);
|
||||
|
||||
|
@ -486,9 +487,10 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
row_layout[1] = 8;
|
||||
row_layout[2] = (total_space.w - 8) * browser->ratio_dir;
|
||||
zr_layout_row(ctx, ZR_STATIC, total_space.h, 3, row_layout);
|
||||
zr_style_push_property(&ctx->style, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
|
||||
zr_push_property(ctx, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
|
||||
|
||||
/* output special important directory list in own window */
|
||||
/* TODO: maybe allow to add current directory into list? */
|
||||
zr_group_begin(ctx, &sub, "Special", ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_BORDER);
|
||||
{
|
||||
struct zr_image home = icons->home.img;
|
||||
|
@ -496,14 +498,14 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
struct zr_image computer = icons->computer.img;
|
||||
|
||||
zr_layout_row_dynamic(ctx, 40, 1);
|
||||
zr_style_push_property(&ctx->style, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 0));
|
||||
zr_push_property(ctx, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 0));
|
||||
if (zr_button_text_image(ctx, home, "home", ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
|
||||
file_browser_reload_directory_content(browser, browser->home);
|
||||
if (zr_button_text_image(ctx,desktop,"desktop",ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
|
||||
file_browser_reload_directory_content(browser, browser->desktop);
|
||||
if (zr_button_text_image(ctx,computer,"computer",ZR_TEXT_CENTERED,ZR_BUTTON_DEFAULT))
|
||||
file_browser_reload_directory_content(browser, "/");
|
||||
zr_style_pop_property(&ctx->style);
|
||||
zr_pop_property(ctx);
|
||||
zr_group_end(ctx);
|
||||
}
|
||||
|
||||
|
@ -539,8 +541,8 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
/* draw one row of icons */
|
||||
size_t n = j + cols;
|
||||
zr_layout_row_dynamic(ctx, 135, cols);
|
||||
zr_style_push_color(&ctx->style, ZR_COLOR_BUTTON, zr_rgb(45, 45, 45));
|
||||
zr_style_push_color(&ctx->style, ZR_COLOR_BORDER, zr_rgb(45, 45, 45));
|
||||
zr_push_color(ctx, ZR_COLOR_BUTTON, zr_rgb(45, 45, 45));
|
||||
zr_push_color(ctx, ZR_COLOR_BORDER, zr_rgb(45, 45, 45));
|
||||
for (; j < count && j < n; ++j) {
|
||||
if (j < browser->dir_count) {
|
||||
/* draw and execute directory buttons */
|
||||
|
@ -559,8 +561,8 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
}
|
||||
}
|
||||
}
|
||||
zr_style_pop_color(&ctx->style);
|
||||
zr_style_pop_color(&ctx->style);
|
||||
zr_pop_color(ctx);
|
||||
zr_pop_color(ctx);
|
||||
}
|
||||
{
|
||||
/* draw one row of labels */
|
||||
|
@ -589,14 +591,14 @@ file_browser_run(struct file_browser *browser, struct zr_context *ctx, int width
|
|||
}
|
||||
zr_group_end(ctx);
|
||||
}
|
||||
zr_style_pop_property(&ctx->style);
|
||||
zr_pop_property(ctx);
|
||||
}
|
||||
zr_end(ctx);
|
||||
return 1;
|
||||
}
|
||||
/* =================================================================
|
||||
*
|
||||
* APP
|
||||
* BACKEND
|
||||
*
|
||||
* ================================================================= */
|
||||
static size_t
|
||||
|
@ -713,64 +715,49 @@ draw(NVGcontext *nvg, struct zr_context *ctx, int width, int height)
|
|||
}
|
||||
|
||||
static void
|
||||
key(struct zr_input *in, SDL_Event *evt, int down)
|
||||
key(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
SDL_Keycode sym = evt->key.keysym.sym;
|
||||
if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == SDLK_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == SDLK_RETURN)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == SDLK_c)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_v)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_x)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
}
|
||||
|
||||
static void
|
||||
motion(struct zr_input *in, SDL_Event *evt)
|
||||
{
|
||||
const int x = evt->motion.x;
|
||||
const int y = evt->motion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
btn(struct zr_input *in, SDL_Event *evt, int down)
|
||||
btn(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_MIDDLE)
|
||||
zr_input_button(in, ZR_BUTTON_MIDDLE, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_MIDDLE, x, y, down);
|
||||
}
|
||||
|
||||
static void
|
||||
text(struct zr_input *in, SDL_Event *evt)
|
||||
text(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
zr_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, ZR_UTF_SIZE);
|
||||
zr_input_glyph(in, glyph);
|
||||
}
|
||||
|
||||
static void
|
||||
resize(SDL_Event *evt)
|
||||
{
|
||||
if (evt->window.event != SDL_WINDOWEVENT_RESIZED) return;
|
||||
glViewport(0, 0, evt->window.data1, evt->window.data2);
|
||||
zr_input_glyph(ctx, glyph);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -831,25 +818,34 @@ main(int argc, char *argv[])
|
|||
/* Input */
|
||||
int ret;
|
||||
SDL_Event evt;
|
||||
zr_input_begin(&ctx.input);
|
||||
zr_input_begin(&ctx);
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
} else ret = SDL_PollEvent(&evt);
|
||||
|
||||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP) key(&ctx.input, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN) key(&ctx.input, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN) btn(&ctx.input, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP) btn(&ctx.input, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION) motion(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL) zr_input_scroll(&ctx.input, evt.wheel.y);
|
||||
if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_WINDOWEVENT) {
|
||||
if (evt.window.event == SDL_WINDOWEVENT_RESIZED)
|
||||
glViewport(0, 0, evt.window.data1, evt.window.data2);
|
||||
} else if (evt.type == SDL_KEYUP)
|
||||
key(&ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN)
|
||||
key(&ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN)
|
||||
btn(&ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP)
|
||||
btn(&ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION) {
|
||||
zr_input_motion(&ctx, evt.motion.x, evt.motion.y);
|
||||
} else if (evt.type == SDL_TEXTINPUT)
|
||||
text(&ctx, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL)
|
||||
zr_input_scroll(&ctx, evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&ctx.input);
|
||||
zr_input_end(&ctx);
|
||||
|
||||
SDL_GetWindowSize(win, &width, &height);
|
||||
running = file_browser_run(&browser, &ctx, width, height);
|
||||
|
|
|
@ -208,7 +208,7 @@ node_editor_draw(struct zr_context *ctx, struct node_editor *nodedit)
|
|||
}
|
||||
|
||||
/* execute each node as a moveable group */
|
||||
zr_style_push_color(&ctx->style, ZR_COLOR_WINDOW, zr_rgb(48, 48, 48));
|
||||
zr_push_color(ctx, ZR_COLOR_WINDOW, zr_rgb(48, 48, 48));
|
||||
while (it) {
|
||||
|
||||
/* calculate scrolled node window position and size */
|
||||
|
@ -325,7 +325,7 @@ node_editor_draw(struct zr_context *ctx, struct node_editor *nodedit)
|
|||
zr_draw_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y,
|
||||
l1.x - 50.0f, l1.y, l1.x, l1.y, zr_rgb(100, 100, 100));
|
||||
}
|
||||
zr_style_pop_color(&ctx->style);
|
||||
zr_pop_color(ctx);
|
||||
|
||||
if (updated) {
|
||||
/* reshuffle nodes to have last recently selected node on top */
|
||||
|
@ -510,57 +510,57 @@ draw(NVGcontext *nvg, struct zr_context *ctx, int width, int height)
|
|||
}
|
||||
|
||||
static void
|
||||
key(struct zr_input *in, SDL_Event *evt, int down)
|
||||
key(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
SDL_Keycode sym = evt->key.keysym.sym;
|
||||
if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT)
|
||||
zr_input_key(in, ZR_KEY_SHIFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_SHIFT, down);
|
||||
else if (sym == SDLK_DELETE)
|
||||
zr_input_key(in, ZR_KEY_DEL, down);
|
||||
zr_input_key(ctx, ZR_KEY_DEL, down);
|
||||
else if (sym == SDLK_RETURN)
|
||||
zr_input_key(in, ZR_KEY_ENTER, down);
|
||||
zr_input_key(ctx, ZR_KEY_ENTER, down);
|
||||
else if (sym == SDLK_BACKSPACE)
|
||||
zr_input_key(in, ZR_KEY_BACKSPACE, down);
|
||||
zr_input_key(ctx, ZR_KEY_BACKSPACE, down);
|
||||
else if (sym == SDLK_LEFT)
|
||||
zr_input_key(in, ZR_KEY_LEFT, down);
|
||||
zr_input_key(ctx, ZR_KEY_LEFT, down);
|
||||
else if (sym == SDLK_RIGHT)
|
||||
zr_input_key(in, ZR_KEY_RIGHT, down);
|
||||
zr_input_key(ctx, ZR_KEY_RIGHT, down);
|
||||
else if (sym == SDLK_c)
|
||||
zr_input_key(in, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_v)
|
||||
zr_input_key(in, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]);
|
||||
else if (sym == SDLK_x)
|
||||
zr_input_key(in, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
zr_input_key(ctx, ZR_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]);
|
||||
}
|
||||
|
||||
static void
|
||||
motion(struct zr_input *in, SDL_Event *evt)
|
||||
motion(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
const int x = evt->motion.x;
|
||||
const int y = evt->motion.y;
|
||||
zr_input_motion(in, x, y);
|
||||
zr_input_motion(ctx, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
btn(struct zr_input *in, SDL_Event *evt, int down)
|
||||
btn(struct zr_context *ctx, SDL_Event *evt, int down)
|
||||
{
|
||||
const int x = evt->button.x;
|
||||
const int y = evt->button.y;
|
||||
if (evt->button.button == SDL_BUTTON_LEFT)
|
||||
zr_input_button(in, ZR_BUTTON_LEFT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_LEFT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_RIGHT)
|
||||
zr_input_button(in, ZR_BUTTON_RIGHT, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_RIGHT, x, y, down);
|
||||
else if (evt->button.button == SDL_BUTTON_MIDDLE)
|
||||
zr_input_button(in, ZR_BUTTON_MIDDLE, x, y, down);
|
||||
zr_input_button(ctx, ZR_BUTTON_MIDDLE, x, y, down);
|
||||
}
|
||||
|
||||
static void
|
||||
text(struct zr_input *in, SDL_Event *evt)
|
||||
text(struct zr_context *ctx, SDL_Event *evt)
|
||||
{
|
||||
zr_glyph glyph;
|
||||
memcpy(glyph, evt->text.text, ZR_UTF_SIZE);
|
||||
zr_input_glyph(in, glyph);
|
||||
zr_input_glyph(ctx, glyph);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -646,7 +646,7 @@ main(int argc, char *argv[])
|
|||
SDL_Event evt;
|
||||
started = SDL_GetTicks();
|
||||
|
||||
zr_input_begin(&ctx.input);
|
||||
zr_input_begin(&ctx);
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
|
@ -654,16 +654,16 @@ main(int argc, char *argv[])
|
|||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP) key(&ctx.input, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN) key(&ctx.input, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN) btn(&ctx.input, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP) btn(&ctx.input, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION) motion(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL) zr_input_scroll(&ctx.input, evt.wheel.y);
|
||||
else if (evt.type == SDL_KEYUP) key(&ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_KEYDOWN) key(&ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONDOWN) btn(&ctx, &evt, zr_true);
|
||||
else if (evt.type == SDL_MOUSEBUTTONUP) btn(&ctx, &evt, zr_false);
|
||||
else if (evt.type == SDL_MOUSEMOTION) motion(&ctx, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&ctx, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL) zr_input_scroll(&ctx, evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&ctx.input);
|
||||
zr_input_end(&ctx);
|
||||
|
||||
{
|
||||
int incursor;
|
||||
|
|
398
zahnrad.h
398
zahnrad.h
|
@ -168,112 +168,10 @@ struct zr_image zr_subimage_id(int, unsigned short w, unsigned short h, struct z
|
|||
int zr_image_is_subimage(const struct zr_image* img);
|
||||
|
||||
/* ==============================================================
|
||||
* INPUT
|
||||
* ===============================================================*/
|
||||
/* The input API is responsible for holding the input state by keeping track of
|
||||
mouse, key and text. The core of the API is a persistent
|
||||
zr_input struct which holds the input state while running.
|
||||
It is important to note that no direct os or window handling is done by the input
|
||||
API, instead all the input state has to be provided by the user. This in one hand
|
||||
expects more work from the user and complicates the usage but on the other hand
|
||||
provides simple abstraction over a big number of platforms, libraries and other
|
||||
already provided functionality.
|
||||
*/
|
||||
enum zr_keys {
|
||||
ZR_KEY_SHIFT,
|
||||
ZR_KEY_DEL,
|
||||
ZR_KEY_ENTER,
|
||||
ZR_KEY_TAB,
|
||||
ZR_KEY_BACKSPACE,
|
||||
ZR_KEY_COPY,
|
||||
ZR_KEY_CUT,
|
||||
ZR_KEY_PASTE,
|
||||
ZR_KEY_LEFT,
|
||||
ZR_KEY_RIGHT,
|
||||
ZR_KEY_MAX
|
||||
};
|
||||
|
||||
/* every used mouse button */
|
||||
enum zr_buttons {
|
||||
ZR_BUTTON_LEFT,
|
||||
ZR_BUTTON_MIDDLE,
|
||||
ZR_BUTTON_RIGHT,
|
||||
ZR_BUTTON_MAX
|
||||
};
|
||||
|
||||
struct zr_mouse_button {
|
||||
int down;
|
||||
/* current button state */
|
||||
unsigned int clicked;
|
||||
/* button state change */
|
||||
struct zr_vec2 clicked_pos;
|
||||
/* mouse position of last state change */
|
||||
};
|
||||
|
||||
struct zr_mouse {
|
||||
struct zr_mouse_button buttons[ZR_BUTTON_MAX];
|
||||
/* mouse button states */
|
||||
struct zr_vec2 pos;
|
||||
/* current mouse position */
|
||||
struct zr_vec2 prev;
|
||||
/* mouse position in the last frame */
|
||||
struct zr_vec2 delta;
|
||||
/* mouse travelling distance from last to current frame */
|
||||
float scroll_delta;
|
||||
/* number of steps in the up or down scroll direction */
|
||||
};
|
||||
|
||||
struct zr_key {
|
||||
int down;
|
||||
unsigned int clicked;
|
||||
};
|
||||
|
||||
struct zr_keyboard {
|
||||
struct zr_key keys[ZR_KEY_MAX];
|
||||
/* state of every used key */
|
||||
char text[ZR_INPUT_MAX];
|
||||
/* utf8 text input frame buffer */
|
||||
zr_size text_len;
|
||||
/* text input frame buffer length in bytes */
|
||||
};
|
||||
|
||||
struct zr_input {
|
||||
struct zr_keyboard keyboard;
|
||||
/* current keyboard key + text input state */
|
||||
struct zr_mouse mouse;
|
||||
/* current mouse button and position state */
|
||||
};
|
||||
|
||||
/* gathering input state */
|
||||
void zr_input_begin(struct zr_input*);
|
||||
void zr_input_motion(struct zr_input*, int x, int y);
|
||||
void zr_input_key(struct zr_input*, enum zr_keys, int down);
|
||||
void zr_input_button(struct zr_input*, enum zr_buttons, int x, int y, int down);
|
||||
void zr_input_scroll(struct zr_input*, float y);
|
||||
void zr_input_glyph(struct zr_input*, const zr_glyph);
|
||||
void zr_input_char(struct zr_input*, char);
|
||||
void zr_input_unicode(struct zr_input *in, zr_rune unicode);
|
||||
void zr_input_end(struct zr_input*);
|
||||
|
||||
/* query input state */
|
||||
int zr_input_has_mouse_click_in_rect(const struct zr_input*,enum zr_buttons, struct zr_rect);
|
||||
int zr_input_has_mouse_click_down_in_rect(const struct zr_input*, enum zr_buttons,
|
||||
struct zr_rect, int down);
|
||||
int zr_input_is_mouse_click_in_rect(const struct zr_input*, enum zr_buttons, struct zr_rect);
|
||||
int zr_input_any_mouse_click_in_rect(const struct zr_input*, struct zr_rect);
|
||||
int zr_input_is_mouse_prev_hovering_rect(const struct zr_input*, struct zr_rect);
|
||||
int zr_input_is_mouse_hovering_rect(const struct zr_input*, struct zr_rect);
|
||||
int zr_input_mouse_clicked(const struct zr_input*, enum zr_buttons, struct zr_rect);
|
||||
int zr_input_is_mouse_down(const struct zr_input*, enum zr_buttons);
|
||||
int zr_input_is_mouse_pressed(const struct zr_input*, enum zr_buttons);
|
||||
int zr_input_is_mouse_released(const struct zr_input*, enum zr_buttons);
|
||||
int zr_input_is_key_pressed(const struct zr_input*, enum zr_keys);
|
||||
int zr_input_is_key_released(const struct zr_input*, enum zr_keys);
|
||||
int zr_input_is_key_down(const struct zr_input*, enum zr_keys);
|
||||
|
||||
/* ==============================================================
|
||||
*
|
||||
* MEMORY BUFFER
|
||||
* =============================================================== */
|
||||
*
|
||||
* ===============================================================*/
|
||||
/* A basic (double)-buffer API with linear allocation and resetting as only
|
||||
freeing policy. The buffers main purpose is to control all memory management inside
|
||||
the GUI toolkit and still leave memory control as much as possible in the hand
|
||||
|
@ -600,11 +498,25 @@ struct zr_user_font zr_font_ref(struct zr_font*);
|
|||
const struct zr_font_glyph* zr_font_find_glyph(struct zr_font*, zr_rune unicode);
|
||||
|
||||
#endif
|
||||
|
||||
/* ===============================================================
|
||||
*
|
||||
* CANVAS
|
||||
* RENDERING
|
||||
*
|
||||
* ===============================================================*/
|
||||
/* This library was designed to be render backend agnostic so it does
|
||||
not draw anything to the screen. Instead all drawn primitives, widgets
|
||||
are made of, are buffered into memory and make up a command queue.
|
||||
Each frame therefore fills the command buffer with draw commands
|
||||
that than need to be executed by the user and his own render backend.
|
||||
After that the command buffer needs to be cleared and a new frame can be started.
|
||||
|
||||
The reason for buffering simple primitives as draw commands instead of
|
||||
directly buffering a hardware accessible format with vertex and element
|
||||
buffer was to support native render backends like X11 and Win32.
|
||||
That being said it is possible to convert the command buffer into a
|
||||
hardware accessible format to support hardware based rendering as well.
|
||||
*/
|
||||
enum zr_command_type {
|
||||
ZR_COMMAND_NOP,
|
||||
ZR_COMMAND_SCISSOR,
|
||||
|
@ -745,39 +657,7 @@ struct zr_draw_null_texture {
|
|||
/* coordinates to the white pixel in the texture */
|
||||
};
|
||||
|
||||
struct zr_canvas {
|
||||
enum zr_anti_aliasing AA;
|
||||
/* flag indicating if anti-aliasing should be used to render primtives */
|
||||
struct zr_draw_null_texture null;
|
||||
/* texture with white pixel for easy primitive drawing */
|
||||
struct zr_rect clip_rect;
|
||||
/* current clipping rectangle */
|
||||
/* cosine/sine calculation callback since this library does not use libc */
|
||||
struct zr_buffer *buffer;
|
||||
/* buffer to store draw commands and temporarily store path */
|
||||
struct zr_buffer *vertexes;
|
||||
/* buffer to store each draw vertex */
|
||||
struct zr_buffer *elements;
|
||||
/* buffer to store each draw element index */
|
||||
unsigned int element_count;
|
||||
/* total number of elements inside the elements buffer */
|
||||
unsigned int vertex_count;
|
||||
/* total number of vertexes inside the vertex buffer */
|
||||
zr_size cmd_offset;
|
||||
/* offset to the first command in the buffer */
|
||||
unsigned int cmd_count;
|
||||
/* number of commands inside the buffer */
|
||||
unsigned int path_count;
|
||||
/* current number of points inside the path */
|
||||
unsigned int path_offset;
|
||||
/* offset to the first point in the buffer */
|
||||
struct zr_vec2 circle_vtx[12];
|
||||
/* small lookup table for fast circle drawing */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* drawing routines */
|
||||
#define zr_command(t, c) ((const struct zr_command_##t*)c)
|
||||
/* drawing routines for custom widgets */
|
||||
void zr_draw_scissor(struct zr_command_buffer*, struct zr_rect);
|
||||
void zr_draw_line(struct zr_command_buffer*, float, float, float, float, struct zr_color);
|
||||
void zr_draw_curve(struct zr_command_buffer*, float, float, float, float, float, float,
|
||||
|
@ -791,6 +671,94 @@ void zr_draw_image(struct zr_command_buffer*, struct zr_rect, struct zr_image*);
|
|||
void zr_draw_text(struct zr_command_buffer*, struct zr_rect, const char*, zr_size,
|
||||
const struct zr_user_font*, struct zr_color, struct zr_color);
|
||||
|
||||
#endif
|
||||
/* ===============================================================
|
||||
*
|
||||
* GUI
|
||||
*
|
||||
* ===============================================================*/
|
||||
enum zr_keys {
|
||||
ZR_KEY_SHIFT,
|
||||
ZR_KEY_DEL,
|
||||
ZR_KEY_ENTER,
|
||||
ZR_KEY_TAB,
|
||||
ZR_KEY_BACKSPACE,
|
||||
ZR_KEY_COPY,
|
||||
ZR_KEY_CUT,
|
||||
ZR_KEY_PASTE,
|
||||
ZR_KEY_LEFT,
|
||||
ZR_KEY_RIGHT,
|
||||
ZR_KEY_MAX
|
||||
};
|
||||
|
||||
/* every used mouse button */
|
||||
enum zr_buttons {
|
||||
ZR_BUTTON_LEFT,
|
||||
ZR_BUTTON_MIDDLE,
|
||||
ZR_BUTTON_RIGHT,
|
||||
ZR_BUTTON_MAX
|
||||
};
|
||||
|
||||
struct zr_mouse_button {
|
||||
int down;
|
||||
/* current button state */
|
||||
unsigned int clicked;
|
||||
/* button state change */
|
||||
struct zr_vec2 clicked_pos;
|
||||
/* mouse position of last state change */
|
||||
};
|
||||
|
||||
struct zr_mouse {
|
||||
struct zr_mouse_button buttons[ZR_BUTTON_MAX];
|
||||
/* mouse button states */
|
||||
struct zr_vec2 pos;
|
||||
/* current mouse position */
|
||||
struct zr_vec2 prev;
|
||||
/* mouse position in the last frame */
|
||||
struct zr_vec2 delta;
|
||||
/* mouse travelling distance from last to current frame */
|
||||
float scroll_delta;
|
||||
/* number of steps in the up or down scroll direction */
|
||||
};
|
||||
|
||||
struct zr_key {
|
||||
int down;
|
||||
unsigned int clicked;
|
||||
};
|
||||
|
||||
struct zr_keyboard {
|
||||
struct zr_key keys[ZR_KEY_MAX];
|
||||
/* state of every used key */
|
||||
char text[ZR_INPUT_MAX];
|
||||
/* utf8 text input frame buffer */
|
||||
zr_size text_len;
|
||||
/* text input frame buffer length in bytes */
|
||||
};
|
||||
|
||||
struct zr_input {
|
||||
struct zr_keyboard keyboard;
|
||||
/* current keyboard key + text input state */
|
||||
struct zr_mouse mouse;
|
||||
/* current mouse button and position state */
|
||||
};
|
||||
|
||||
/* query input state */
|
||||
int zr_input_has_mouse_click_in_rect(const struct zr_input*,enum zr_buttons, struct zr_rect);
|
||||
int zr_input_has_mouse_click_down_in_rect(const struct zr_input*, enum zr_buttons,
|
||||
struct zr_rect, int down);
|
||||
int zr_input_is_mouse_click_in_rect(const struct zr_input*, enum zr_buttons, struct zr_rect);
|
||||
int zr_input_any_mouse_click_in_rect(const struct zr_input*, struct zr_rect);
|
||||
int zr_input_is_mouse_prev_hovering_rect(const struct zr_input*, struct zr_rect);
|
||||
int zr_input_is_mouse_hovering_rect(const struct zr_input*, struct zr_rect);
|
||||
int zr_input_mouse_clicked(const struct zr_input*, enum zr_buttons, struct zr_rect);
|
||||
int zr_input_is_mouse_down(const struct zr_input*, enum zr_buttons);
|
||||
int zr_input_is_mouse_pressed(const struct zr_input*, enum zr_buttons);
|
||||
int zr_input_is_mouse_released(const struct zr_input*, enum zr_buttons);
|
||||
int zr_input_is_key_pressed(const struct zr_input*, enum zr_keys);
|
||||
int zr_input_is_key_released(const struct zr_input*, enum zr_keys);
|
||||
int zr_input_is_key_down(const struct zr_input*, enum zr_keys);
|
||||
|
||||
|
||||
/* ==============================================================
|
||||
* STYLE
|
||||
* ===============================================================*/
|
||||
|
@ -947,37 +915,6 @@ struct zr_style {
|
|||
/* modification stack */
|
||||
};
|
||||
|
||||
/* style setup and access */
|
||||
struct zr_style;
|
||||
void zr_style_default(struct zr_style*, zr_flags, const struct zr_user_font*);
|
||||
void zr_style_set_font(struct zr_style*, const struct zr_user_font*);
|
||||
struct zr_vec2 zr_style_property(const struct zr_style*, enum zr_style_properties);
|
||||
struct zr_color zr_style_color(const struct zr_style*, enum zr_style_colors);
|
||||
|
||||
/* temporarily modify a style value and save the old value in a stack*/
|
||||
void zr_style_push_property(struct zr_style*, enum zr_style_properties, struct zr_vec2);
|
||||
void zr_style_push_color(struct zr_style*, enum zr_style_colors, struct zr_color);
|
||||
void zr_style_push_font(struct zr_style*, struct zr_user_font font);
|
||||
void zr_style_push_font_height(struct zr_style*, float font_height);
|
||||
|
||||
/* restores a previously saved style value */
|
||||
void zr_style_pop_color(struct zr_style*);
|
||||
void zr_style_pop_property(struct zr_style*);
|
||||
void zr_style_pop_font(struct zr_style*);
|
||||
void zr_style_pop_font_height(struct zr_style*);
|
||||
|
||||
/* resets the style back into the beginning state */
|
||||
void zr_style_reset_colors(struct zr_style*);
|
||||
void zr_style_reset_properties(struct zr_style*);
|
||||
void zr_style_reset_font(struct zr_style*);
|
||||
void zr_style_reset_font_height(struct zr_style*);
|
||||
void zr_style_reset(struct zr_style*);
|
||||
|
||||
/* return string representation of different styles values */
|
||||
const char *zr_style_color_name(enum zr_style_colors);
|
||||
const char *zr_style_rounding_name(enum zr_style_rounding);
|
||||
const char *zr_style_property_name(enum zr_style_properties);
|
||||
|
||||
/*===============================================================
|
||||
* EDIT BOX
|
||||
* ===============================================================*/
|
||||
|
@ -1010,9 +947,7 @@ zr_size zr_edit_box_len_char(struct zr_edit_box*);
|
|||
zr_size zr_edit_box_len(struct zr_edit_box*);
|
||||
|
||||
/*==============================================================
|
||||
*
|
||||
* GUI
|
||||
*
|
||||
* WINDOW
|
||||
* =============================================================*/
|
||||
#define ZR_UNDEFINED (-1.0f)
|
||||
#define ZR_FLAG(x) (1 << (x))
|
||||
|
@ -1038,15 +973,6 @@ enum zr_symbol {
|
|||
ZR_SYMBOL_MAX
|
||||
};
|
||||
|
||||
struct zr_clipboard {
|
||||
zr_handle userdata;
|
||||
/* user memory for callback */
|
||||
zr_paste_f paste;
|
||||
/* paste callback for the edit box */
|
||||
zr_copy_f copy;
|
||||
/* copy callback for the edit box */
|
||||
};
|
||||
|
||||
enum zr_widget_status {
|
||||
ZR_INACTIVE,
|
||||
ZR_HOVERED,
|
||||
|
@ -1265,6 +1191,48 @@ struct zr_layout {
|
|||
struct zr_layout *parent;
|
||||
};
|
||||
|
||||
/*==============================================================
|
||||
* CONTEXT
|
||||
* =============================================================*/
|
||||
struct zr_clipboard {
|
||||
zr_handle userdata;
|
||||
/* user memory for callback */
|
||||
zr_paste_f paste;
|
||||
/* paste callback for the edit box */
|
||||
zr_copy_f copy;
|
||||
/* copy callback for the edit box */
|
||||
};
|
||||
|
||||
struct zr_canvas {
|
||||
enum zr_anti_aliasing AA;
|
||||
/* flag indicating if anti-aliasing should be used to render primtives */
|
||||
struct zr_draw_null_texture null;
|
||||
/* texture with white pixel for easy primitive drawing */
|
||||
struct zr_rect clip_rect;
|
||||
/* current clipping rectangle */
|
||||
/* cosine/sine calculation callback since this library does not use libc */
|
||||
struct zr_buffer *buffer;
|
||||
/* buffer to store draw commands and temporarily store path */
|
||||
struct zr_buffer *vertexes;
|
||||
/* buffer to store each draw vertex */
|
||||
struct zr_buffer *elements;
|
||||
/* buffer to store each draw element index */
|
||||
unsigned int element_count;
|
||||
/* total number of elements inside the elements buffer */
|
||||
unsigned int vertex_count;
|
||||
/* total number of vertexes inside the vertex buffer */
|
||||
zr_size cmd_offset;
|
||||
/* offset to the first command in the buffer */
|
||||
unsigned int cmd_count;
|
||||
/* number of commands inside the buffer */
|
||||
unsigned int path_count;
|
||||
/* current number of points inside the path */
|
||||
unsigned int path_offset;
|
||||
/* offset to the first point in the buffer */
|
||||
struct zr_vec2 circle_vtx[12];
|
||||
/* small lookup table for fast circle drawing */
|
||||
};
|
||||
|
||||
struct zr_context {
|
||||
unsigned int seq;
|
||||
struct zr_input input;
|
||||
|
@ -1293,10 +1261,6 @@ int zr_init_fixed(struct zr_context*, void *memory, zr_size size, const struct z
|
|||
int zr_init_custom(struct zr_context*, struct zr_buffer *cmds,
|
||||
struct zr_buffer *pool, const struct zr_user_font*);
|
||||
int zr_init(struct zr_context*, struct zr_allocator*, const struct zr_user_font*);
|
||||
void zr_convert(struct zr_context*, struct zr_buffer *cmds,
|
||||
struct zr_buffer *vertexes, struct zr_buffer *elements,
|
||||
struct zr_draw_null_texture , enum zr_anti_aliasing,
|
||||
float line_thickness, unsigned int circle_segment_count);
|
||||
void zr_clear(struct zr_context*);
|
||||
void zr_free(struct zr_context*);
|
||||
|
||||
|
@ -1327,20 +1291,71 @@ void zr_window_collapse(struct zr_context *ctx, const char *name, enum zr_collap
|
|||
void zr_window_collapse_if(struct zr_context *ctx, const char *name, enum zr_collapse_states, int cond);
|
||||
void zr_window_set_focus(struct zr_context *ctx, const char *name);
|
||||
|
||||
/* drawing */
|
||||
/*--------------------------------------------------------------
|
||||
* DRAWING
|
||||
* -------------------------------------------------------------*/
|
||||
/* command drawing */
|
||||
#define zr_command(t, c) ((const struct zr_command_##t*)c)
|
||||
#define zr_foreach(c, ctx) for((c)=zr__begin(ctx); (c)!=0; (c)=zr__next(ctx, c))
|
||||
#define zr_draw_foreach(cmd,ctx, b) for((cmd)=zr__draw_begin(ctx, b); (cmd)!=0; (cmd)=zr__draw_next(cmd, b, ctx))
|
||||
const struct zr_command* zr__next(struct zr_context*, const struct zr_command*);
|
||||
const struct zr_command* zr__begin(struct zr_context*);
|
||||
|
||||
/* vertex command drawing */
|
||||
#define zr_draw_foreach(cmd,ctx, b) for((cmd)=zr__draw_begin(ctx, b); (cmd)!=0; (cmd)=zr__draw_next(cmd, b, ctx))
|
||||
void zr_convert(struct zr_context*, struct zr_buffer *cmds,
|
||||
struct zr_buffer *vertexes, struct zr_buffer *elements,
|
||||
struct zr_draw_null_texture , enum zr_anti_aliasing,
|
||||
float line_thickness, unsigned int circle_segment_count);
|
||||
const struct zr_draw_command* zr__draw_begin(const struct zr_context*, const struct zr_buffer*);
|
||||
const struct zr_draw_command* zr__draw_next(const struct zr_draw_command*,
|
||||
const struct zr_buffer*,
|
||||
const struct zr_context*);
|
||||
const struct zr_buffer*, const struct zr_context*);
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
* INPUT
|
||||
* -------------------------------------------------------------*/
|
||||
void zr_input_begin(struct zr_context*);
|
||||
void zr_input_motion(struct zr_context*, int x, int y);
|
||||
void zr_input_key(struct zr_context*, enum zr_keys, int down);
|
||||
void zr_input_button(struct zr_context*, enum zr_buttons, int x, int y, int down);
|
||||
void zr_input_scroll(struct zr_context*, float y);
|
||||
void zr_input_glyph(struct zr_context*, const zr_glyph);
|
||||
void zr_input_char(struct zr_context*, char);
|
||||
void zr_input_unicode(struct zr_context *in, zr_rune unicode);
|
||||
void zr_input_end(struct zr_context*);
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
* STYLE
|
||||
* -------------------------------------------------------------*/
|
||||
void zr_load_default_style(struct zr_context*, zr_flags);
|
||||
void zr_set_font(struct zr_context*, const struct zr_user_font*);
|
||||
struct zr_vec2 zr_get_property(const struct zr_context*, enum zr_style_properties);
|
||||
struct zr_color zr_get_color(const struct zr_context*, enum zr_style_colors);
|
||||
const char *zr_get_color_name(enum zr_style_colors);
|
||||
const char *zr_get_rounding_name(enum zr_style_rounding);
|
||||
const char *zr_get_property_name(enum zr_style_properties);
|
||||
|
||||
/* temporarily modify a style value and save the old value in a stack*/
|
||||
void zr_push_property(struct zr_context*, enum zr_style_properties, struct zr_vec2);
|
||||
void zr_push_color(struct zr_context*, enum zr_style_colors, struct zr_color);
|
||||
void zr_push_font(struct zr_context*, struct zr_user_font font);
|
||||
void zr_push_font_height(struct zr_context*, float font_height);
|
||||
|
||||
/* restores a previously saved style value */
|
||||
void zr_pop_color(struct zr_context*);
|
||||
void zr_pop_property(struct zr_context*);
|
||||
void zr_pop_font(struct zr_context*);
|
||||
void zr_pop_font_height(struct zr_context*);
|
||||
|
||||
/* resets the style back into the beginning state */
|
||||
void zr_reset_colors(struct zr_context*);
|
||||
void zr_reset_properties(struct zr_context*);
|
||||
void zr_reset_font(struct zr_context*);
|
||||
void zr_reset_font_height(struct zr_context*);
|
||||
void zr_reset(struct zr_context*);
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
* Layout
|
||||
* -------------------------------------------------------------*/
|
||||
/* layout query functions */
|
||||
void zr_layout_peek(struct zr_rect *bounds, struct zr_context*);
|
||||
|
||||
/* columns based layouting with generated position and width and fixed height*/
|
||||
|
@ -1378,7 +1393,6 @@ void zr_layout_pop(struct zr_context*);
|
|||
/*--------------------------------------------------------------
|
||||
* Widgets
|
||||
* -------------------------------------------------------------*/
|
||||
/* base function called by all widgets (needs to be called for custom widgets) */
|
||||
enum zr_widget_state zr_widget(struct zr_rect*, const struct zr_context*);
|
||||
enum zr_widget_state zr_widget_fitting(struct zr_rect*, struct zr_context*);
|
||||
void zr_spacing(struct zr_context*, zr_size cols);
|
||||
|
|
Loading…
Reference in New Issue