ashbb / green_shoes

Green Shoes is one of the colorful Shoes written in pure Ruby.
Other
204 stars 37 forks source link

image hover and leave behavior question #62

Closed athom closed 12 years ago

athom commented 12 years ago

I create two images. img1 and img2. when I switch the mouse between img1 and img2. the hover event always happens earlier than leave event. for example: cursor on img1: img1 hover move cursor from img1 to img2: img2 hover, img1 leave. I think img1 leave should happen first, then enter the img2 hover. i have reasonable scenario, but it is a little long,i will post if you are interested. this example code wont expose the strange behavior.

require 'green_shoes'

Shoes.app do
   img1 = image 'ruby2.png'
   img2 = image 'ruby2.png'

   img1.hover do |s|
     puts 'img1 hover'
     s.path = 'ruby3.png'
   end
   img1.leave do |s|
     puts 'img1 leave'
     s.path = 'ruby2.png'
   end
   img2.hover do |s|
     puts 'img2 hover'
     s.path = 'ruby3.png'
   end
   img2.leave do |s|
     puts 'img2 leave'
     s.path = 'ruby2.png'
   end
end
athom commented 12 years ago

update: put some space between the two pictures, problem disappears.

require 'green_shoes'

Shoes.app do
   img1 = image 'ruby2.png'
   para ''
   img2 = image 'ruby2.png'

   img1.hover do |s|
     puts 'img1 hover'
     s.path = 'ruby3.png'
   end
   img1.leave do |s|
     puts 'img1 leave'
     s.path = 'ruby2.png'
   end
   img2.hover do |s|
     puts 'img2 hover'
     s.path = 'ruby3.png'
   end
   img2.leave do |s|
     puts 'img2 leave'
     s.path = 'ruby2.png'
   end
end
ashbb commented 12 years ago

Hi yeer,

Good point. :)

But sorry, this is one of implementation constraints. Because strictly speaking, neither Red Shoes nor Green Shoes are event driven programs. They are periodically doing the functions in order.

athom commented 12 years ago

just one more question, are shoes using the system events or simulating them? in windows, if the two pictures overlap each other, the strange behavior is allowed. So I am wondering maybe the images in the same slot might overlap.

ashbb commented 12 years ago

Good question!

Look at line 64-69 in main.rb : https://github.com/ashbb/green_shoes/blob/master/lib/shoes/main.rb

I couldn't find any system events like "hover_event" or "leave_event" in GTK. So, Green Shoes catches a system event "motion_notify_event" and do the two functions, mouse_hover_control and mouse_leave_control, in this order.

athom commented 12 years ago

hi, ashbb simply exchange the order of mouse_hover_control and mouse_leave_control, it fix the behavior. it works like: img1 hover, img1 leave, img2 hover rather than img1 hover, img2 hover, img1 leave without putting space between the two pictures.

but I dont know the reason why you put "hover" comes before "leave" in the signal_connect block. so I am not sure the change will affect the original design or not.

      win.signal_connect "motion_notify_event" do
        app.mouse_pos = app.win.pointer
        mouse_motion_control app
        mouse_leave_control app
        mouse_hover_control app
      end
ashbb commented 12 years ago

Oh, the order has no reason. I've just used Red Shoes code as a reference. I think you found a good solution. Thanks! :)

athom commented 12 years ago

thanks for your tips, i am enlighten :)