Skip to content

Commit

Permalink
for #383 events
Browse files Browse the repository at this point in the history
* better replay timing
* a button press is now :btn_activate for event handler/blocks instead
  of :click. Updated Test/events/* to accomodate - it still calls
  the button proc/block if there is one.
* won't move the cursor on replay - really hard/impossible? to do and
  violates many GUI principles - only one mouse pointer/cursor
  • Loading branch information
Cecil committed Dec 18, 2017
1 parent 6a63313 commit 15d90b6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Tests/events/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
@el = edit_line width: 450
@el.text = "#{DIR}/samples/simple/chipmunk.rb"
button "select app" do
path = ask_file_open
path = ask_open_file
@el.text = path if path
end
end
para "Save events to"
flow do
@sv = edit_line width: 450
@sv.text = "#{DIR}/events.yaml"
@sv.text = "#{Dir.getwd}/event.yaml"
button "Change" do
path = ask_file_save
path = ask_save_file
@sv.text = path if path
end
end
Expand Down
6 changes: 3 additions & 3 deletions Tests/events/event1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
when :click
$stderr.puts "click handler called: #{evt.type} #{evt.button}, #{evt.x} #{evt.y} #{evt.modifiers}"
evt.accept = @ck1.checked?
if evt.object
$stderr.puts "widget #{evt.object} at #{evt.type} #{evt.button} #{evt.x} #{evt.y} #{evt.width} #{evt.height}"
end
when :btn_activate
$stderr.puts "button #{evt.object} at #{evt.type} #{evt.button} #{evt.x} #{evt.y} #{evt.width} #{evt.height}"
evt.accept = @ck1.checked?
else
evt.accept = true
end
Expand Down
21 changes: 15 additions & 6 deletions Tests/events/event4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def click(btn,x,y,mods)
stack do
tagline "Clicks for non-native widgets"
flow do
$ck = check checked: true; para "Pass clicks?"
@ck1 = check checked: true; para "Pass clicks?"
end
flow do
@img = image "#{DIR}/static/shoes-icon-walkabout.png", width: 200, height: 200
Expand All @@ -45,12 +45,21 @@ def click(btn,x,y,mods)
end

event do |evt|
$stderr.puts "event called: #{evt.type} at #{evt.x},#{evt.y} mods: #{evt.modifiers}"
if evt.object
# Note: for Textblocks the evt.obj is the String of the text block
$stderr.puts " for widget: #{evt.object.class} width #{evt.width} height #{evt.height}"
# do not trigger new events here unless you can handle them
case evt.type
when :click
$stderr.puts "click handler called: #{evt.type} #{evt.button}, #{evt.x} #{evt.y} #{evt.modifiers}"
if evt.object
# Note: for Textblocks the evt.obj is the String of the text block
$stderr.puts " non-native widget: #{evt.object.class} width #{evt.width} height #{evt.height}"
end
evt.accept = @ck1.checked?
when :btn_activate
$stderr.puts "button #{evt.object} at #{evt.type} #{evt.button} #{evt.x} #{evt.y} #{evt.width} #{evt.height}"
evt.accept = @ck1.checked?
else
evt.accept = false
end
evt.accept = true #$ck.checked?
end

end
14 changes: 10 additions & 4 deletions Tests/events/event5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
@img1 = image "#{DIR}/static/shoes-icon-walkabout.png", left: 0, top: 0, width: 200, height: 200
@img2 = image "#{DIR}/static/shoes-icon-blue.png", left: 50, top: 50, width: 100, height: 100
event do |evt|
$stderr.puts "event called: #{evt.type} at #{evt.x},#{evt.y} mods: #{evt.modifiers}"
if evt.object
$stderr.puts " for widget: #{evt.object.class} width #{evt.width} height #{evt.height}"
case evt.type
when :click
$stderr.puts "click handler called: #{evt.type} #{evt.button}, #{evt.x} #{evt.y} #{evt.modifiers}"
if evt.object
# Note: for Textblocks the evt.obj is the String of the text block
$stderr.puts " non-native widget: #{evt.object.class} width #{evt.width} height #{evt.height}"
end
evt.accept = true
else
evt.accept = false
end
evt.accept = true
end
end
14 changes: 6 additions & 8 deletions Tests/events/replay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
para "Load events from"
flow do
@sv = edit_line width: 450
@sv.text = "#{DIR}/events.yaml"
@sv.text = "#{Dir.getwd}/chipmunk.yaml"
button "Change" do
path = ask_file_open
path = ask_open_file
@sv.text = path if path
end
end
Expand All @@ -28,19 +28,17 @@
end
end
button "Replay Events" do
# note this creates as many simulaneous timers as events
# not pretty
w2 = Shoes.APPS[-1]
base = 0
@events.each_index do |r|
ev = @events[r]
t = ev[:time]
base = t if r == 0
wait = t - base
timer(wait) do
puts "wait for #{wait}"
timer(t) do
puts "wait for #{t}"
puts " move to #{ev[:x]}, #{ev[:y]} and click "
w2.replay_event(ev)
end
base = t
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions shoes/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,14 @@ shoes_code shoes_app_keyup(shoes_app *app, VALUE key) {
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;
VALUE btn, vx, vy, mods, type, vobj;
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
vobj = shoes_hash_get(evh, rb_intern("object"));
if (SYM2ID(type) == s_click) {// 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;
Expand Down
9 changes: 7 additions & 2 deletions shoes/ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,12 @@ void shoes_ele_remove_all(VALUE);
void shoes_cairo_rect(cairo_t *, double, double, double, double, double);
void shoes_cairo_arc(cairo_t *, double, double, double, double, double, double);

// FIXME: Symbols in Shoes are broken in many ways. For example, the symbol progress is shared amongst types/progress and types/download, which causes Shoes to crash if defined in either ones. It should also be noted that Shoes crashes even if progress is defined here below. It apparently has to be defined on top of ruby{.c,.h}. Image and TextBlock/Text/TextLink are also heavily affected by this.
// FIXME: Symbols in Shoes are broken in many ways. For example, the symbol
// progress is shared amongst types/progress and types/download, which causes
// Shoes to crash if defined in either ones. It should also be noted that
// Shoes crashes even if progress is defined here below. It apparently
// has to be defined on top of ruby{.c,.h}.
// Image and TextBlock/Text/TextLink are also heavily affected by this.
#define SYMBOL_DEFS(f) f(bind); f(gsub); f(keys); f(update); f(merge); \
f(new); f(URI); f(now); f(debug); f(info); f(warn); f(error); f(run); \
f(to_a); f(to_ary); f(to_f); f(to_i); f(to_int); f(to_s); f(to_str); \
Expand All @@ -552,7 +557,7 @@ void shoes_cairo_arc(cairo_t *, double, double, double, double, double, double);
f(shadow); f(arc); f(rect); f(oval); f(line); f(star); f(project); f(round); \
f(square); f(undercolor); f(underline); f(variant); f(weight); f(wrap); \
f(dash); f(nodot); f(onedot); f(donekey); f(volume); f(bg_color); \
f(decorated); f(opacity); f(cache); f(event); f(shift_key); f(control_key)
f(decorated); f(opacity); f(cache); f(event); f(btn_activate)
#define SYMBOL_INTERN(name) s_##name = rb_intern("" # name)
#define SYMBOL_ID(name) ID s_##name
#define SYMBOL_EXTERN(name) extern ID s_##name
Expand Down
6 changes: 4 additions & 2 deletions shoes/types/native.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ void shoes_control_send(VALUE self, ID event) {
y = self_t->place.y;
h = self_t->place.h;
w = self_t->place.w;
VALUE evt = shoes_event_new_widget(cShoesEvent, event, self, 1, x, y, w, h, Qnil, Qnil);
// use
VALUE evt = shoes_event_new_widget(cShoesEvent, s_btn_activate, self, 1, x, y, w, h, Qnil, Qnil);
shoes_safe_block(app->canvas, evtproc, rb_ary_new3(1, evt));
shoes_event *tevent;
Data_Get_Struct(evt, shoes_event, tevent);
sendevt = (tevent->accept == 1) ? Qtrue : Qfalse;
sendevt = tevent->accept;
} else
fprintf(stderr, "shoes_control_send: doesn't have event - but it should\n");
}
if ((sendevt == Qtrue) && !NIL_P(self_t->attr)) {
// TODO: bug here
click = rb_hash_aref(self_t->attr, ID2SYM(event));
if (!NIL_P(click))
shoes_safe_block(self_t->parent, click, rb_ary_new3(1, self));
Expand Down

0 comments on commit 15d90b6

Please sign in to comment.