Sha256: 6b5bde4ba4d8b4b2342b30c13d660bc331e9fb8a418f230007af6e30a7edc88b

Contents?: true

Size: 1.45 KB

Versions: 36

Compression:

Stored size: 1.45 KB

Contents

=begin
  eventbox.rb - Ruby/GTK sample script.

  Copyright (c) 2015-2020 Ruby-GNOME Project Team
  This program is licenced under the same licence as Ruby-GNOME.
=end

# https://developer.gnome.org/gtk3/unstable/GtkEventBox.html
# https://developer.gnome.org/gtk3/stable/GtkImage.html

# Gtk::EventBox are widgets container used to catch events for widgets that
# do not have their own window (Gdk::Window) like Gtk::Image for example.

require "gtk3"

window = Gtk::Window.new("Event Box example")

surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, 265, 95)
cr = Cairo::Context.new(surface)
r1 = [10, 10, 75, 75]
r2 = [95, 10, 75, 75]
r3 = [180, 10, 75, 75]

cr.set_source_rgb(1, 0, 0)
cr.rectangle(*r1)
cr.fill
cr.set_source_rgb(0, 1, 0)
cr.rectangle(*r2)
cr.fill
cr.set_source_rgb(0, 0, 1)
cr.rectangle(*r3)
cr.fill

image = Gtk::Image.new(
  pixbuf: surface.to_pixbuf(src_x: 0, src_y: 0, width: 265, height: 95)
)

event_box = Gtk::EventBox.new

event_box.add(image)

event_box.signal_connect "button-press-event" do |_widget, event|
  if event.y >= 10 && event.y <= 85
    if event.x >= 10 && event.x <= 85
      puts "red   x = #{event.x} \t y = #{event.y}"
    elsif event.x >= 95 && event.x <= 180
      puts "green x = #{event.x} \t y = #{event.y}"
    elsif event.x >= 190 && event.x <= 255
      puts "blue  x = #{event.x} \t y = #{event.y}"
    end
  end
end

window.add(event_box)

window.show_all

window.signal_connect("delete-event") { Gtk.main_quit }

Gtk.main

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
gtk3-4.2.5 sample/misc/eventbox.rb
gtk3-4.2.4 sample/misc/eventbox.rb
gtk3-4.2.3 sample/misc/eventbox.rb
gtk3-4.2.2 sample/misc/eventbox.rb
gtk3-4.2.1 sample/misc/eventbox.rb
gtk3-4.2.0 sample/misc/eventbox.rb
gtk3-4.1.9 sample/misc/eventbox.rb
gtk3-4.1.8 sample/misc/eventbox.rb
gtk3-4.1.7 sample/misc/eventbox.rb
gtk3-4.1.6 sample/misc/eventbox.rb
gtk3-4.1.5 sample/misc/eventbox.rb
gtk3-4.1.4 sample/misc/eventbox.rb
gtk3-4.1.3 sample/misc/eventbox.rb
gtk3-4.1.2 sample/misc/eventbox.rb
gtk3-4.1.1 sample/misc/eventbox.rb
gtk3-4.1.0 sample/misc/eventbox.rb
gtk3-4.0.9 sample/misc/eventbox.rb
gtk3-4.0.8 sample/misc/eventbox.rb
gtk3-4.0.7 sample/misc/eventbox.rb
gtk3-4.0.6 sample/misc/eventbox.rb