Skip to content

Commit

Permalink
for #384, 383 - modifiers for click, motion, release
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecil committed Nov 21, 2017
1 parent 8928c24 commit f6c122b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 38 deletions.
12 changes: 11 additions & 1 deletion Tests/events/event1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
@eb = edit_box width: 500, height: 350
end
click do |btn, x, y, mods|
@eb.append "app btn: #{btn} x: #{x} y: #{y} mods: #{mods}\n"
@eb.append "app click: #{btn} x: #{x} y: #{y} mods: #{mods}\n"
end
release do |btn, x, y, mods|
@eb.append "app unlclck: #{btn} x: #{x} y: #{y} mods: #{mods}\n"
end
keypress do |key|
$stderr.puts key
@eb.append "#{key} "
end
motion do |x, y, mods|
@eb.append "modtion #{x},#{y} #{mods} "
end
end
56 changes: 43 additions & 13 deletions shoes/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,22 +513,35 @@ VALUE shoes_app_set_event_handler(VALUE self, VALUE blk) {
}


shoes_code shoes_app_motion(shoes_app *app, int x, int y) {
shoes_code shoes_app_motion(shoes_app *app, int x, int y, int mods) {
app->mousex = x;
app->mousey = y;
shoes_canvas_send_motion(app->canvas, x, y, Qnil);
VALUE modifiers = Qnil;
if (mods & SHOES_MODIFY_CTRL) {
if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("control_shift");
else
modifiers = rb_utf8_str_new_cstr("control");
}
else if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("shift");
shoes_canvas_send_motion(app->canvas, x, y, Qnil, modifiers);
return SHOES_OK;
}
EXTERN ID s_shift_key, s_control_key;

shoes_code shoes_app_click(shoes_app *app, int button, int x, int y, int mods) {
app->mouseb = button;
VALUE sendevt = Qtrue;
VALUE modifiers = rb_ary_new2(4);
if (mods & SHOES_MODIFY_SHIFT)
rb_ary_push(modifiers, ID2SYM(s_shift_key));
if (mods & SHOES_MODIFY_CTRL)
rb_ary_push(modifiers, ID2SYM(s_control_key));
VALUE modifiers = Qnil;
if (mods & SHOES_MODIFY_CTRL) {
if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("control_shift");
else
modifiers = rb_utf8_str_new_cstr("control");
}
else if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("shift");
/*
if (mods & SHOES_MODIFY_ALT)
rb_ary_push(modifiers, rb_str_new_cstr("alt"));
Expand All @@ -555,18 +568,35 @@ shoes_code shoes_app_click(shoes_app *app, int button, int x, int y, int mods) {
return SHOES_OK;
}

shoes_code shoes_app_release(shoes_app *app, int button, int x, int y) {
shoes_code shoes_app_release(shoes_app *app, int button, int x, int y, int mods) {
app->mouseb = 0;
shoes_canvas_send_release(app->canvas, button, x, y);
VALUE modifiers = Qnil;
if (mods & SHOES_MODIFY_CTRL) {
if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("control_shift");
else
modifiers = rb_utf8_str_new_cstr("control");
}
else if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("shift");
shoes_canvas_send_release(app->canvas, button, x, y, modifiers);
return SHOES_OK;
}

shoes_code shoes_app_wheel(shoes_app *app, ID dir, int x, int y) {
shoes_code shoes_app_wheel(shoes_app *app, ID dir, int x, int y, int mods) {
shoes_canvas *canvas;
Data_Get_Struct(app->canvas, shoes_canvas, canvas);
if (canvas->slot->vscroll) shoes_canvas_wheel_way(canvas, dir);

shoes_canvas_send_wheel(app->canvas, dir, x, y);
VALUE modifiers = Qnil;
if (mods & SHOES_MODIFY_CTRL) {
if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("control_shift");
else
modifiers = rb_utf8_str_new_cstr("control");
}
else if (mods & SHOES_MODIFY_SHIFT)
modifiers = rb_utf8_str_new_cstr("shift");
shoes_canvas_send_wheel(app->canvas, dir, x, y, modifiers) ;
return SHOES_OK;
}

Expand Down Expand Up @@ -615,7 +645,7 @@ shoes_code shoes_app_goto(shoes_app *app, char *path) {
} else {
code = shoes_app_visit(app, path);
if (code == SHOES_OK) {
shoes_app_motion(app, app->mousex, app->mousey);
shoes_app_motion(app, app->mousex, app->mousey, Qnil);
shoes_slot_repaint(app->slot);
}
}
Expand Down
6 changes: 3 additions & 3 deletions shoes/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ shoes_code shoes_app_open(shoes_app *, char *);
shoes_code shoes_app_loop(void);
shoes_code shoes_app_visit(shoes_app *, char *);
shoes_code shoes_app_paint(shoes_app *);
shoes_code shoes_app_motion(shoes_app *, int, int);
shoes_code shoes_app_motion(shoes_app *, int, int, int);
shoes_code shoes_app_click(shoes_app *, int, int, int, int);
shoes_code shoes_app_release(shoes_app *, int, int, int);
shoes_code shoes_app_wheel(shoes_app *, ID, int, int);
shoes_code shoes_app_release(shoes_app *, int, int, int, int);
shoes_code shoes_app_wheel(shoes_app *, ID, int, int, int);
shoes_code shoes_app_keydown(shoes_app *, VALUE);
shoes_code shoes_app_keypress(shoes_app *, VALUE);
shoes_code shoes_app_keyup(shoes_app *, VALUE);
Expand Down
14 changes: 7 additions & 7 deletions shoes/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ VALUE shoes_canvas_send_click(VALUE self, int button, int x, int y, VALUE mods)
return Qnil;
}

void shoes_canvas_send_release(VALUE self, int button, int x, int y) {
void shoes_canvas_send_release(VALUE self, int button, int x, int y, VALUE mods) {
long i;
int ox = x, oy = y;
shoes_canvas *self_t;
Expand All @@ -1136,14 +1136,14 @@ void shoes_canvas_send_release(VALUE self, int button, int x, int y) {
if (!NIL_P(release)) {
if (ORIGIN(self_t->place))
y += self_t->slot->scrolly;
shoes_safe_block(self, release, rb_ary_new3(3, INT2NUM(button), INT2NUM(x), INT2NUM(y)));
shoes_safe_block(self, release, rb_ary_new3(4, INT2NUM(button), INT2NUM(x), INT2NUM(y), mods));
}
}

for (i = RARRAY_LEN(self_t->contents) - 1; i >= 0; i--) {
VALUE ele = rb_ary_entry(self_t->contents, i);
if (rb_obj_is_kind_of(ele, cCanvas)) {
shoes_canvas_send_release(ele, button, ox, oy);
shoes_canvas_send_release(ele, button, ox, oy, mods);
} else if (rb_obj_is_kind_of(ele, cTextBlock)) {
shoes_textblock_send_release(ele, button, ox, oy);
} else if (rb_obj_is_kind_of(ele, cImage)) {
Expand All @@ -1159,7 +1159,7 @@ void shoes_canvas_send_release(VALUE self, int button, int x, int y) {
}
}

VALUE shoes_canvas_send_motion(VALUE self, int x, int y, VALUE url) {
VALUE shoes_canvas_send_motion(VALUE self, int x, int y, VALUE url, VALUE mods) {
char oh, ch = 0, h = 0, *n = 0;
long i;
int ox = x, oy = y;
Expand All @@ -1182,14 +1182,14 @@ VALUE shoes_canvas_send_motion(VALUE self, int x, int y, VALUE url) {
if (ATTR(self_t->attr, hidden) != Qtrue) {
VALUE motion = ATTR(self_t->attr, motion);
if (!NIL_P(motion)) {
shoes_safe_block(self, motion, rb_ary_new3(2, INT2NUM(x), INT2NUM(y)));
shoes_safe_block(self, motion, rb_ary_new3(3, INT2NUM(x), INT2NUM(y), mods));
}

for (i = RARRAY_LEN(self_t->contents) - 1; i >= 0; i--) {
VALUE urll = Qnil;
VALUE ele = rb_ary_entry(self_t->contents, i);
if (rb_obj_is_kind_of(ele, cCanvas)) {
urll = shoes_canvas_send_motion(ele, ox, oy, url);
urll = shoes_canvas_send_motion(ele, ox, oy, url, mods);
} else if (rb_obj_is_kind_of(ele, cTextBlock)) {
urll = shoes_textblock_motion(ele, ox, oy, &h);
} else if (rb_obj_is_kind_of(ele, cImage)) {
Expand Down Expand Up @@ -1227,7 +1227,7 @@ void shoes_canvas_wheel_way(shoes_canvas *self_t, ID dir) {
shoes_slot_scroll_to(self_t, 32, 1);
}

void shoes_canvas_send_wheel(VALUE self, ID dir, int x, int y) {
void shoes_canvas_send_wheel(VALUE self, ID dir, int x, int y, VALUE mods) {
long i;
shoes_canvas *self_t;
Data_Get_Struct(self, shoes_canvas, self_t);
Expand Down
6 changes: 3 additions & 3 deletions shoes/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ void shoes_canvas_compute(VALUE);
VALUE shoes_canvas_goto(VALUE, VALUE);
VALUE shoes_canvas_send_click(VALUE, int, int, int, VALUE mods);
VALUE shoes_canvas_send_click2(VALUE self, int button, int x, int y, VALUE mods, VALUE *clicked);
void shoes_canvas_send_release(VALUE, int, int, int);
VALUE shoes_canvas_send_motion(VALUE, int, int, VALUE);
void shoes_canvas_send_wheel(VALUE, ID, int, int);
void shoes_canvas_send_release(VALUE, int, int, int, VALUE mods);
VALUE shoes_canvas_send_motion(VALUE, int, int, VALUE, VALUE);
void shoes_canvas_send_wheel(VALUE, ID, int, int, VALUE);
void shoes_canvas_wheel_way(shoes_canvas *, ID);
void shoes_canvas_send_keydown(VALUE, VALUE);
void shoes_canvas_send_keypress(VALUE, VALUE);
Expand Down
16 changes: 10 additions & 6 deletions shoes/native/cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ - (void)sendMotion: (NSEvent *)e ofType: (ID)type withButton: (int)b
shoes_app *a;
shoes_canvas *canvas;
int modify = 0;
if ([e.modifierFlags] & NSShiftKeyMask)
if ([e modifierFlags] & NSShiftKeyMask)
modify = modify | SHOES_MODIFY_SHIFT
if ([e.modifierFlags] & NSControlKeyMask)
if ([e modifierFlags] & NSControlKeyMask)
modify = modify | SHOES_MODIFY_CTRL
/* platform and theme specific
if ([e.modifierFlags] & NSAlternateKeyMask)
Expand All @@ -141,11 +141,11 @@ - (void)sendMotion: (NSEvent *)e ofType: (ID)type withButton: (int)b
Data_Get_Struct(app, shoes_app, a);
Data_Get_Struct(a->canvas, shoes_canvas, canvas);
if (type == s_motion)
shoes_app_motion(a, ROUND(p.x), (canvas->height - ROUND(p.y)) + canvas->slot->scrolly);
shoes_app_motion(a, ROUND(p.x), (canvas->height - ROUND(p.y)) + canvas->slot->scrolly, modify);
else if (type == s_click)
shoes_app_click(a, b, ROUND(p.x), (canvas->height - ROUND(p.y)) + canvas->slot->scrolly, modify);
else if (type == s_release)
shoes_app_release(a, b, ROUND(p.x), (canvas->height - ROUND(p.y)) + canvas->slot->scrolly);
shoes_app_release(a, b, ROUND(p.x), (canvas->height - ROUND(p.y)) + canvas->slot->scrolly, modify);
}
- (void)mouseDown: (NSEvent *)e
{
Expand Down Expand Up @@ -203,10 +203,14 @@ - (void)scrollWheel: (NSEvent *)e
wheel = s_down;
dy = -dy;
}

int modify = 0;
if ([e modifierFlags] & NSShiftKeyMask)
modify = modify | SHOES_MODIFY_SHIFT
if ([e modifierFlags] & NSControlKeyMask)
modify = modify | SHOES_MODIFY_CTRL
Data_Get_Struct(app, shoes_app, a);
for (; dy > 0.; dy--)
shoes_app_wheel(a, wheel, ROUND(p.x), ROUND(p.y));
shoes_app_wheel(a, wheel, ROUND(p.x), ROUND(p.y), modify);
}
- (void)keyDown: (NSEvent *)e
{
Expand Down
20 changes: 15 additions & 5 deletions shoes/native/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ static gboolean shoes_app_gtk_motion(GtkWidget *widget, GdkEventMotion *event, g
shoes_canvas *canvas;
Data_Get_Struct(app->canvas, shoes_canvas, canvas);
state = (GdkModifierType)event->state;
shoes_app_motion(app, (int)event->x, (int)event->y + canvas->slot->scrolly);
int mods = 0;
if (event->state & GDK_SHIFT_MASK)
mods = mods | SHOES_MODIFY_SHIFT;
if (event->state & GDK_CONTROL_MASK)
mods = mods | SHOES_MODIFY_CTRL;
shoes_app_motion(app, (int)event->x, (int)event->y + canvas->slot->scrolly, mods);
}
return TRUE;
}
Expand Down Expand Up @@ -311,7 +316,7 @@ static gboolean shoes_app_gtk_button(GtkWidget *widget, GdkEventButton *event, g
mods = mods | SHOES_MODIFY_SHIFT;
if (event->state & GDK_CONTROL_MASK)
mods = mods | SHOES_MODIFY_CTRL;
/* never get these on Linux or its themeable
/* never get these on Linux or its a themeable thing
if (event->state & GDK_MOD1_MASK)
mods = mods | SHOES_MODIFY_ALT;
if (event->state & GDK_SUPER_MASK)
Expand All @@ -324,7 +329,7 @@ static gboolean shoes_app_gtk_button(GtkWidget *widget, GdkEventButton *event, g
if (event->type == GDK_BUTTON_PRESS) {
shoes_app_click(app, event->button, event->x, event->y + canvas->slot->scrolly, mods);
} else if (event->type == GDK_BUTTON_RELEASE) {
shoes_app_release(app, event->button, event->x, event->y + canvas->slot->scrolly);
shoes_app_release(app, event->button, event->x, event->y + canvas->slot->scrolly, mods);
}
return TRUE;
}
Expand All @@ -350,8 +355,13 @@ static gboolean shoes_app_gtk_wheel(GtkWidget *widget, GdkEventScroll *event, gp
default:
return TRUE;
}

shoes_app_wheel(app, wheel, event->x, event->y);
// process modifiers
int mods = 0;
if (event->state & GDK_SHIFT_MASK)
mods = mods | SHOES_MODIFY_SHIFT;
if (event->state & GDK_CONTROL_MASK)
mods = mods | SHOES_MODIFY_CTRL;
shoes_app_wheel(app, wheel, event->x, event->y, mods);
return TRUE;
}

Expand Down

0 comments on commit f6c122b

Please sign in to comment.