devided text input into char and glyph for usability

This commit is contained in:
vurtun 2015-07-02 11:56:51 +02:00
parent 3b7f93c490
commit 2d79b360f0
6 changed files with 35 additions and 13 deletions

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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);

10
gui.c
View File

@ -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)
{

7
gui.h
View File

@ -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
*/