aboutsummaryrefslogtreecommitdiff
path: root/nk_pugl
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-02-24 16:27:07 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-02-24 16:27:07 +0100
commit63d1c664d80f96028a4665b4d33c1ce98df0e1ab (patch)
treeb5c17fe57ebb0d8829588a7393d74b59c91738f3 /nk_pugl
parent1ca28cfda085096fce492995a7291b6c2518f33a (diff)
parenteed4cf47c507c23aeec81fcb76050f8f3a36fdaa (diff)
downloadsherlock.lv2-63d1c664d80f96028a4665b4d33c1ce98df0e1ab.tar.xz
Merge commit 'eed4cf47c507c23aeec81fcb76050f8f3a36fdaa'
Diffstat (limited to 'nk_pugl')
-rw-r--r--nk_pugl/nk_pugl.h70
1 files changed, 50 insertions, 20 deletions
diff --git a/nk_pugl/nk_pugl.h b/nk_pugl/nk_pugl.h
index 93909c7..5e89338 100644
--- a/nk_pugl/nk_pugl.h
+++ b/nk_pugl/nk_pugl.h
@@ -146,6 +146,9 @@ nk_pugl_icon_load(nk_pugl_window_t *win, const char *filename);
static void
nk_pugl_icon_unload(nk_pugl_window_t *win, struct nk_image img);
+static bool
+nk_pugl_is_shortcut_pressed(struct nk_input *in, char letter, bool clear);
+
#ifdef __cplusplus
}
#endif
@@ -480,7 +483,7 @@ _nk_pugl_special_key_down(nk_pugl_window_t *win, const PuglEventKey *ev)
} break;
case PUGL_KEY_INSERT:
{
- //TODO
+ _nk_pugl_key_press(ctx, NK_KEY_TEXT_INSERT_MODE);
} break;
case PUGL_KEY_SHIFT:
{
@@ -565,8 +568,12 @@ _nk_pugl_other_key_down(nk_pugl_window_t *win, const PuglEventKey *ev)
struct nk_context *ctx = &win->ctx;
const bool control = ev->state & PUGL_MOD_CTRL;
+ // automatically enter insert mode upon non-special key press
+ _nk_pugl_key_press(ctx, NK_KEY_TEXT_INSERT_MODE);
+
switch(ev->character)
{
+ case '\n':
case '\r':
{
_nk_pugl_key_press(ctx, NK_KEY_ENTER);
@@ -577,11 +584,19 @@ _nk_pugl_other_key_down(nk_pugl_window_t *win, const PuglEventKey *ev)
} break;
case PUGL_CHAR_DELETE:
{
+#if defined(__APPLE__) // quirk around Apple's Delete key strangeness
+ _nk_pugl_key_press(ctx, NK_KEY_BACKSPACE);
+#else
_nk_pugl_key_press(ctx, NK_KEY_DEL);
+#endif
} break;
case PUGL_CHAR_BACKSPACE:
{
+#if defined(__APPLE__) // quirk around Apple's Delete key strangeness
+ _nk_pugl_key_press(ctx, NK_KEY_DEL);
+#else
_nk_pugl_key_press(ctx, NK_KEY_BACKSPACE);
+#endif
} break;
case PUGL_CHAR_ESCAPE:
{
@@ -592,7 +607,9 @@ _nk_pugl_other_key_down(nk_pugl_window_t *win, const PuglEventKey *ev)
{
if(control)
{
- const uint32_t character = ev->character + 96; //FIXME why +96?
+ // unescape ASCII control chars + Control
+ const uint32_t character = ev->character | 0x60;
+
switch(character)
{
case 'c':
@@ -618,25 +635,12 @@ _nk_pugl_other_key_down(nk_pugl_window_t *win, const PuglEventKey *ev)
default:
{
- if(isprint(character))
- nk_input_char(ctx, character);
+ nk_input_glyph(ctx, (const char *)ev->utf8);
} break;
}
}
- else // !control
+ else
{
- switch(ev->character)
- {
- case 'i':
- {
- _nk_pugl_key_press(ctx, NK_KEY_TEXT_INSERT_MODE);
- } break;
- case 'r':
- {
- _nk_pugl_key_press(ctx, NK_KEY_TEXT_REPLACE_MODE);
- } break;
- }
-
nk_input_glyph(ctx, (const char *)ev->utf8);
}
} break;
@@ -659,10 +663,14 @@ _nk_pugl_modifiers(nk_pugl_window_t *win, PuglMod state)
nk_input_key(ctx, NK_KEY_CTRL, (state & PUGL_MOD_CTRL) == PUGL_MOD_CTRL);
if( (win->state & PUGL_MOD_ALT) != (state & PUGL_MOD_ALT))
- ; // not yet supported in nuklear
+ {
+ // not yet supported in nuklear
+ }
if( (win->state & PUGL_MOD_SUPER) != (state & PUGL_MOD_SUPER))
- ; // not yet supported in nuklear
+ {
+ // not yet supported in nuklear
+ }
win->state = state; // switch old and new modifier states
}
@@ -970,10 +978,10 @@ nk_pugl_shutdown(nk_pugl_window_t *win)
glDeleteTextures(1, &win->font_tex);
// shutdown nuklear
- nk_free(&win->ctx);
nk_buffer_free(&win->cmds);
nk_buffer_free(&win->vbuf);
nk_buffer_free(&win->ebuf);
+ nk_free(&win->ctx);
}
puglLeaveContext(win->view, false);
@@ -1112,6 +1120,28 @@ nk_pugl_icon_unload(nk_pugl_window_t *win, struct nk_image img)
}
}
+static bool
+nk_pugl_is_shortcut_pressed(struct nk_input *in, char letter, bool clear)
+{
+ const bool control = nk_input_is_key_down(in, NK_KEY_CTRL);
+
+ if(control && (in->keyboard.text_len == 1) )
+ {
+ // unescape ASCII control chars + Control
+ const char ch = in->keyboard.text[0] | 0x60;
+
+ if(isalpha(ch) && (ch == letter) ) // pass non-alpha characters through
+ {
+ if(clear)
+ in->keyboard.text_len = 0;
+
+ return true; // matching shortcut
+ }
+ }
+
+ return false;
+}
+
#ifdef __cplusplus
}
#endif