class EventAxesDemo

Touch and Drawing Tablets ↑

Demonstrates advanced handling of event information from exotic
input devices.

On one hand, this snippet demonstrates management of drawing tablets,
those contain additional information for the pointer other than
X/Y coordinates. Tablet pads events are mapped to actions, which
are both defined and interpreted by the application.

Input axes are dependent on hardware devices, on linux/unix you
can see the device axes through xinput list <device>. Each time
a different hardware device is used to move the pointer, the
master device will be updated to match the axes it provides,
these changes can be tracked through GdkDevice::changed, or
checking gdk_event_get_source_device().

On the other hand, this demo handles basic multitouch events,
each event coming from an specific touchpoint will contain a
GdkEventSequence that's unique for its lifetime, so multiple
touchpoints can be tracked.

Constants

AXES_INFO
COLORS
EVENT_DATA
PAD_ACTIONS

type index mode label action_name

PAD_ACTION_RESULTS

Public Class Methods

new(main_window) click to toggle source
# File gtk3/sample/gtk-demo/event_axes.rb, line 53
def initialize(main_window)
  @cur_color = 0
  @window = Gtk::Window.new(:toplevel)
  @window.screen = main_window.screen
  @window.title = "Event Axes"
  @window.set_default_size(400, 400)

  box = Gtk::EventBox.new
  @window.add(box)
  box.support_multidevice = true
  box.add_events([:pointer_motion_mask, :button_press_mask,
                  :button_release_mask, :smooth_scroll_mask,
                  :enter_notify_mask, :leave_notify_mask,
                  :touch_mask])

  @event_data = EVENT_DATA.new({}, {})

  box.signal_connect "event" do |widget, event|
    update_axes_from_event(event)
    widget.queue_draw
    false
  end

  box.signal_connect "draw" do |widget, cr|
    y = 0
    allocation = widget.allocation

    # Draw Abs info
    @event_data.pointer_info.each do |_key, value|
      draw_axes_info(cr, value, allocation)
    end

    @event_data.touch_info.each do |_key, value|
      draw_axes_info(cr, value, allocation)
    end

    # Draw name, color legend and misc data
    @event_data.pointer_info.each do |_key, value|
      y = draw_device_info(widget, cr, nil, y, value)
    end

    @event_data.touch_info.each do |key, value|
      y = draw_device_info(widget, cr, key, y, value)
    end

    false
  end

  @label = Gtk::Label.new("")
  @label.use_markup = true
  box.add(@label)
  init_pad_controller
end

Public Instance Methods

run() click to toggle source
# File gtk3/sample/gtk-demo/event_axes.rb, line 107
def run
  if !@window.visible?
    @window.show_all
  else
    @window.destroy
  end
  @window
end