Class: Nuklear::Context::EventSink
- Inherits:
-
Object
- Object
- Nuklear::Context::EventSink
- Defined in:
- ext/nuklear/nkrb_context.c
Instance Method Summary collapse
- #button(buttons, rx, ry, down) ⇒ Object
- #char(chr) ⇒ Object
- #glyph(chr) ⇒ Object
- #initialize(context) ⇒ Object constructor
- #key(keys, down) ⇒ Object
- #motion(rx, ry, rxrel, ryrel) ⇒ Object
- #scroll(x, y) ⇒ Object
Constructor Details
#initialize(context) ⇒ Object
96 97 98 99 |
# File 'ext/nuklear/nkrb_context.c', line 96
VALUE rb_nkrb_event_sink_initialize(VALUE self, VALUE context) {
rb_ivar_set(self, rb_intern("@context"), context);
return self;
}
|
Instance Method Details
#button(buttons, rx, ry, down) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'ext/nuklear/nkrb_context.c', line 159
VALUE nkrb_event_sink_button(VALUE self, VALUE buttons, VALUE rx, VALUE ry, VALUE down) {
VALUE_TO_NK(rb_ivar_get(self, rb_intern("@context")), ctx);
ID buttons_id = SYM2ID(buttons);
int is_down = RTEST(down) ? 1 : 0;
int x = FIX2INT(rx), y = FIX2INT(ry);
if (buttons_id == rb_intern("left")) nk_input_button(ctx, NK_BUTTON_LEFT, x, y, is_down);
if (buttons_id == rb_intern("middle")) nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, is_down);
if (buttons_id == rb_intern("right")) nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, is_down);
if (buttons_id == rb_intern("double")) nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, is_down);
if (buttons_id == rb_intern("max")) nk_input_button(ctx, NK_BUTTON_MAX, x, y, is_down);
return self;
}
|
#char(chr) ⇒ Object
183 184 185 186 187 188 |
# File 'ext/nuklear/nkrb_context.c', line 183
VALUE nkrb_event_sink_char(VALUE self, VALUE chr) {
VALUE_TO_NK(rb_ivar_get(self, rb_intern("@context")), ctx);
int ch = FIX2INT(rb_funcall(chr, rb_intern("ord"), 0));
nk_input_char(ctx, ch);
return self;
}
|
#glyph(chr) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'ext/nuklear/nkrb_context.c', line 190
VALUE nkrb_event_sink_glyph(VALUE self, VALUE chr) {
VALUE_TO_NK(rb_ivar_get(self, rb_intern("@context")), ctx);
nk_glyph glyph;
int len = (int) RSTRING_LEN(chr);
if (len < NK_UTF_SIZE) {
if (len > 0) {
int i;
for (i = 0; i < len; i++) {
int ch = FIX2INT(rb_funcall(rb_funcall(chr, rb_intern("[]"), 1, INT2FIX(i)),
rb_intern("ord"), 0));
nk_input_char(ctx, ch);
}
} else {
rb_raise(rb_eArgError, "input is empty");
}
} else {
memcpy(glyph, StringValuePtr(chr), NK_UTF_SIZE);
nk_input_glyph(ctx, glyph);
}
return self;
}
|
#key(keys, down) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'ext/nuklear/nkrb_context.c', line 112
VALUE nkrb_event_sink_key(VALUE self, VALUE keys, VALUE down) {
VALUE_TO_NK(rb_ivar_get(self, rb_intern("@context")), ctx);
ID keys_id = SYM2ID(keys);
int is_down = RTEST(down) ? 1 : 0;
if (keys_id == rb_intern("shift")) nk_input_key(ctx, NK_KEY_SHIFT, is_down);
else if (keys_id == rb_intern("ctrl")) nk_input_key(ctx, NK_KEY_CTRL, is_down);
else if (keys_id == rb_intern("del")) nk_input_key(ctx, NK_KEY_DEL, is_down);
else if (keys_id == rb_intern("enter")) nk_input_key(ctx, NK_KEY_ENTER, is_down);
else if (keys_id == rb_intern("tab")) nk_input_key(ctx, NK_KEY_TAB, is_down);
else if (keys_id == rb_intern("backspace")) nk_input_key(ctx, NK_KEY_BACKSPACE, is_down);
else if (keys_id == rb_intern("copy")) nk_input_key(ctx, NK_KEY_COPY, is_down);
else if (keys_id == rb_intern("cut")) nk_input_key(ctx, NK_KEY_CUT, is_down);
else if (keys_id == rb_intern("paste")) nk_input_key(ctx, NK_KEY_PASTE, is_down);
else if (keys_id == rb_intern("up")) nk_input_key(ctx, NK_KEY_UP, is_down);
else if (keys_id == rb_intern("down")) nk_input_key(ctx, NK_KEY_DOWN, is_down);
else if (keys_id == rb_intern("left")) nk_input_key(ctx, NK_KEY_LEFT, is_down);
else if (keys_id == rb_intern("right")) nk_input_key(ctx, NK_KEY_RIGHT, is_down);
/* Shortcuts: text field */
else if (keys_id == rb_intern("text_insert_mode")) nk_input_key(ctx, NK_KEY_TEXT_INSERT_MODE, is_down);
else if (keys_id == rb_intern("text_replace_mode")) nk_input_key(ctx, NK_KEY_TEXT_REPLACE_MODE, is_down);
else if (keys_id == rb_intern("text_reset_mode")) nk_input_key(ctx, NK_KEY_TEXT_RESET_MODE, is_down);
else if (keys_id == rb_intern("text_line_start")) nk_input_key(ctx, NK_KEY_TEXT_LINE_START, is_down);
else if (keys_id == rb_intern("text_line_end")) nk_input_key(ctx, NK_KEY_TEXT_LINE_END, is_down);
else if (keys_id == rb_intern("text_start")) nk_input_key(ctx, NK_KEY_TEXT_START, is_down);
else if (keys_id == rb_intern("text_end")) nk_input_key(ctx, NK_KEY_TEXT_END, is_down);
else if (keys_id == rb_intern("text_undo")) nk_input_key(ctx, NK_KEY_TEXT_UNDO, is_down);
else if (keys_id == rb_intern("text_redo")) nk_input_key(ctx, NK_KEY_TEXT_REDO, is_down);
else if (keys_id == rb_intern("text_select_all")) nk_input_key(ctx, NK_KEY_TEXT_SELECT_ALL, is_down);
else if (keys_id == rb_intern("text_word_left")) nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, is_down);
else if (keys_id == rb_intern("text_word_right")) nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, is_down);
/* Shortcuts: scrollbar */
else if (keys_id == rb_intern("scroll_start")) nk_input_key(ctx, NK_KEY_SCROLL_START, is_down);
else if (keys_id == rb_intern("scroll_end")) nk_input_key(ctx, NK_KEY_SCROLL_END, is_down);
else if (keys_id == rb_intern("scroll_down")) nk_input_key(ctx, NK_KEY_SCROLL_DOWN, is_down);
else if (keys_id == rb_intern("scroll_up")) nk_input_key(ctx, NK_KEY_SCROLL_UP, is_down);
else if (keys_id == rb_intern("max")) nk_input_key(ctx, NK_KEY_MAX, is_down);
else {
VALUE s = rb_funcall(keys, rb_intern("inspect"), 0);
rb_raise(rb_eArgError, "Invalid key symbol: %s", StringValueCStr(s));
}
return self;
}
|
#motion(rx, ry, rxrel, ryrel) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'ext/nuklear/nkrb_context.c', line 101
VALUE nkrb_event_sink_motion(VALUE self, VALUE rx, VALUE ry, VALUE rxrel, VALUE ryrel) {
VALUE_TO_NK(rb_ivar_get(self, rb_intern("@context")), ctx);
if (ctx->input.mouse.grabbed) {
int x = (int) ctx->input.mouse.prev.x, y = (int) ctx->input.mouse.prev.y;
nk_input_motion(ctx, x + FIX2INT(rxrel), y + FIX2INT(ryrel));
} else {
nk_input_motion(ctx, FIX2INT(rx), FIX2INT(ry));
}
return self;
}
|
#scroll(x, y) ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'ext/nuklear/nkrb_context.c', line 174
VALUE nkrb_event_sink_scroll(VALUE self, VALUE x, VALUE y) {
VALUE_TO_NK(rb_ivar_get(self, rb_intern("@context")), ctx);
struct nk_vec2 vec;
vec.x = (float) NUM2DBL(x);
vec.y = (float) NUM2DBL(y);
nk_input_scroll(ctx, vec);
return self;
}
|