diff --git a/demo/nanovg.c b/demo/nanovg.c index 5dbdb53..f56fb56 100644 --- a/demo/nanovg.c +++ b/demo/nanovg.c @@ -32,8 +32,11 @@ #define LEN(a) (sizeof(a)/sizeof(a)[0]) #define UNUSED(a) ((void)(a)) +#define GUI_USE_FIXED_TYPES +#define GUI_ASSERT(expr) assert(expr) #include "../gui.h" -#include "demo.c" +/*#include "demo.c"*/ +#include "maya.c" static void die(const char *fmt, ...) @@ -220,7 +223,7 @@ text(struct gui_input *in, SDL_Event *evt) { gui_glyph glyph; memcpy(glyph, evt->text.text, GUI_UTF_SIZE); - gui_input_char(in, glyph); + gui_input_glyph(in, glyph); } static void @@ -285,8 +288,18 @@ main(int argc, char *argv[]) font.userdata.ptr = vg; nvgTextMetrics(vg, NULL, NULL, &font.height); font.width = font_get_width; + + gui.width = WINDOW_WIDTH; + gui.height = WINDOW_HEIGHT; init_demo(&gui, &font); + gui.images.select = nvgCreateImage(vg, "icon/select.bmp", 0); + gui.images.lasso = nvgCreateImage(vg, "icon/lasso.bmp", 0); + gui.images.paint = nvgCreateImage(vg, "icon/paint.bmp", 0); + gui.images.move = nvgCreateImage(vg, "icon/move.bmp", 0); + gui.images.rotate = nvgCreateImage(vg, "icon/rotate.bmp", 0); + gui.images.scale = nvgCreateImage(vg, "icon/scale.bmp", 0); + while (gui.running) { /* Input */ SDL_Event evt; @@ -312,6 +325,7 @@ main(int argc, char *argv[]) /* Draw */ glClearColor(0.4f, 0.4f, 0.4f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + draw(vg, &gui.layout.stack, width, height); draw(vg, &gui.stack, width, height); gui.ms = SDL_GetTicks() - started; SDL_GL_SwapWindow(win); diff --git a/demo/opengl.c b/demo/opengl.c index d2c38a3..bc6e44d 100644 --- a/demo/opengl.c +++ b/demo/opengl.c @@ -21,7 +21,7 @@ #include FT_GLYPH_H /* macros */ -#define DTIME 33 +#define DTIME 17 #define FONT_ATLAS_DEPTH 4 #define CIRCLE_SEGMENTS 22 @@ -513,7 +513,7 @@ text(struct gui_input *in, SDL_Event *evt) { gui_glyph glyph; memcpy(glyph, evt->text.text, GUI_UTF_SIZE); - gui_input_char(in, glyph); + gui_input_glyph(in, glyph); } static void diff --git a/demo/win32.c b/demo/win32.c index 2a143c5..441c615 100644 --- a/demo/win32.c +++ b/demo/win32.c @@ -336,9 +336,7 @@ key(struct gui_input *in, MSG *msg, gui_bool down) static void text(struct gui_input *in, MSG *msg) { - gui_glyph glyph; if (msg->wParam < 32 && msg->wParam >= 128) return; - glyph[0] = (gui_char)msg->wParam; gui_input_char(in, glyph); } diff --git a/demo/xlib.c b/demo/xlib.c index 44ec44c..faea48c 100644 --- a/demo/xlib.c +++ b/demo/xlib.c @@ -286,7 +286,7 @@ static void surface_draw_text(XSurface *surf, gui_short x, gui_short y, gui_ushort w, gui_ushort h, const char *text, size_t len, XFont *font, const gui_byte* cbg, const gui_byte *cfg) { - int i, tx, ty, th, olen; + int tx, ty, th; unsigned long bg = color_from_byte(cbg); unsigned long fg = color_from_byte(cfg); @@ -393,9 +393,7 @@ key(struct XWindow *xw, struct gui_input *in, XEvent *evt, gui_bool down) else if (*code == XK_BackSpace) gui_input_key(in, GUI_KEY_BACKSPACE, down); else if (*code > 32 && *code < 128 && !down) { - gui_glyph glyph; - glyph[0] = (gui_char)*code; - gui_input_char(in, glyph); + gui_input_char(in, (char)*code); } XFree(code); } @@ -502,7 +500,6 @@ main(int argc, char *argv[]) sleep_for(DTIME - dt); } -cleanup: free(gui.memory); font_del(xw.dpy, xw.font); surface_del(xw.surf); diff --git a/gui.c b/gui.c index 1e52585..143206e 100644 --- a/gui.c +++ b/gui.c @@ -391,7 +391,7 @@ gui_input_scroll(struct gui_input *in, gui_float y) } void -gui_input_char(struct gui_input *in, const gui_glyph glyph) +gui_input_glyph(struct gui_input *in, const gui_glyph glyph) { gui_size len = 0; gui_long unicode; @@ -404,6 +404,14 @@ gui_input_char(struct gui_input *in, const gui_glyph glyph) } } +void +gui_input_char(struct gui_input *in, char c) +{ + gui_glyph glyph; + glyph[0] = c; + gui_input_glyph(in, glyph); +} + void gui_input_end(struct gui_input *in) { diff --git a/gui.h b/gui.h index 2a9f065..d1606d8 100644 --- a/gui.h +++ b/gui.h @@ -228,11 +228,16 @@ void gui_input_scroll(struct gui_input*, gui_float y); Input: - vector with each direction (< 0 down > 0 up and scroll distance) */ -void gui_input_char(struct gui_input*, const gui_glyph); +void gui_input_glyph(struct gui_input*, const gui_glyph); /* this function adds a utf-8 glpyh into the internal text frame buffer Input: - utf8 glyph to add to the text buffer */ +void gui_input_char(struct gui_input*, char); +/* this function adds char into the internal text frame buffer + Input: + - character to add to the text buffer +*/ void gui_input_end(struct gui_input*); /* this function sets the input state to readable */