Skip to content

Commit

Permalink
begin work on #383 - far far awwy from complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecil committed Nov 8, 2017
1 parent 235fe96 commit 068d2d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions shoes/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ shoes_code shoes_app_motion(shoes_app *app, int x, int y) {

shoes_code shoes_app_click(shoes_app *app, int button, int x, int y) {
app->mouseb = button;
if (! NIL_P(app->event_handler)) {
fprintf(stderr, "have event_handler, invoking...\n");
}
shoes_canvas_send_click(app->canvas, button, x, y);
return SHOES_OK;
}
Expand Down Expand Up @@ -726,3 +729,16 @@ VALUE shoes_app_terminal(int argc, VALUE *argv, VALUE self) {
}
return shoes_global_terminal ? Qtrue : Qfalse;
}

VALUE shoes_app_set_event_handler(VALUE self,VALUE blk) {
shoes_app *app;
Data_Get_Struct(self, shoes_app, app);
if (rb_obj_is_kind_of(blk, rb_cProc)) {
fprintf(stderr, "setting app event handler\n");
app->event_handler = blk;
return Qtrue;
} else {
rb_raise(rb_eArgError, "events must be be a proc");
}
return Qnil;
}
2 changes: 2 additions & 0 deletions shoes/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef struct _shoes_app {
VALUE title;
VALUE location;
VALUE owner;
VALUE event_handler; // must be a proc
} shoes_app;

//
Expand Down Expand Up @@ -101,6 +102,7 @@ VALUE shoes_app_set_resizable(VALUE, VALUE);
VALUE shoes_app_set_cache(VALUE app, VALUE setting);
VALUE shoes_app_get_cache(VALUE app);
VALUE shoes_app_clear_cache(VALUE app, VALUE opts);
VALUE shoes_app_set_event_handler(VALUE app, VALUE blk);
// global var for image cache - declared in types/image.c
extern int shoes_cache_setting;
// global var for console up and running
Expand Down
1 change: 1 addition & 0 deletions shoes/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ void shoes_ruby_init() {
rb_define_method(cApp, "cache", CASTHOOK(shoes_app_get_cache), 0);
rb_define_method(cApp, "cache=", CASTHOOK(shoes_app_set_cache), 1);
rb_define_method(cApp, "cache_clear", CASTHOOK(shoes_app_clear_cache), 1);
rb_define_method(cApp, "events=", CASTHOOK(shoes_app_set_event_handler), 1);

cDialog = rb_define_class_under(cTypes, "Dialog", cApp);

Expand Down

0 comments on commit 068d2d3

Please sign in to comment.