Skip to content

Commit

Permalink
for #383 proof of concept - capture and replay events
Browse files Browse the repository at this point in the history
* replay wait times are wrong but, It Works!
  • Loading branch information
Cecil committed Dec 17, 2017
1 parent 8e1d885 commit 6a63313
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Tests/events/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
when :click
#$stderr.puts "click handler2 with #{evt.type}"
events << { time: (Time.now - base_t), button: evt.button, x: evt.x, y: evt.y,
modifiers: evt.modifiers, object: evt.object}
modifiers: evt.modifiers, object: evt.object, type: evt.type}
evt.accept = true
else
evt.accept = true
Expand Down
15 changes: 7 additions & 8 deletions Tests/events/replay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,23 @@
y = w2.top
w2.move x+80, y-40
@events = evtflhash[:events]
puts @events
#puts @events
end
end
button "Replay Events" do
w2 = Shoes.APPS[-1]
delay = 0
base = 0
@events.each_index do |r|
ev = @events[r]
t = ev[:time]
delay = t if r == 0
wait = t - delay
base = t if r == 0
wait = t - base
timer(wait) do
puts "waited for #{wait}"
puts "wait for #{wait}"
puts " move to #{ev[:x]}, #{ev[:y]} and click "
# want to call: w2.replay_event(:click, ev)
# need native move_cursor ability
w2.replay_event(ev)
end
delay = t
base = t
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions shoes/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,24 @@ shoes_code shoes_app_keyup(shoes_app *app, VALUE key) {
return SHOES_OK;
}

// replay -- testing - just clicks
VALUE shoes_app_replay_event(VALUE self, VALUE evh) {
shoes_app *self_t;
Data_Get_Struct(self, shoes_app, self_t);
VALUE btn, vx, vy, mods, type;
btn = shoes_hash_get(evh, rb_intern("button"));
vx = shoes_hash_get(evh, rb_intern("x"));
vy = shoes_hash_get(evh, rb_intern("y"));
mods = shoes_hash_get(evh, rb_intern("modifiers"));
type = shoes_hash_get(evh, rb_intern("type"));
if (1) {// TODO: figure symbol/id for type == click
// using app->canvas
shoes_canvas_send_click(self_t->canvas, NUM2INT(btn), NUM2INT(vx), NUM2INT(vy), mods);
return Qtrue;
} else
return Qnil;
}

VALUE shoes_sys(char *cmd, int detach) {
if (detach)
return rb_funcall(rb_mKernel, rb_intern("system"), 1, rb_str_new2(cmd));
Expand Down
1 change: 1 addition & 0 deletions shoes/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ VALUE shoes_app_get_cache(VALUE app);
VALUE shoes_app_clear_cache(VALUE app, VALUE opts);
VALUE shoes_app_get_handler(VALUE app);
VALUE shoes_app_set_event_handler(VALUE app, VALUE opt);
VALUE shoes_app_replay_event(VALUE app, VALUE evh);
// 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 @@ -806,6 +806,7 @@ void shoes_ruby_init() {
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, "event=", CASTHOOK(shoes_app_set_event_handler), 1);
rb_define_method(cApp, "replay_event", CASTHOOK(shoes_app_replay_event), 1);


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

0 comments on commit 6a63313

Please sign in to comment.