Parent

Class/Module Index [+]

Quicksearch

Rabbit::Gesture::Handler

Attributes

back_color[RW]
current_color[RW]
line_color[RW]
line_width[RW]
next_color[RW]
next_width[RW]

Public Class Methods

new(conf={}) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 20
def initialize(conf={})
  super()
  conf ||= {}
  @back_color = conf[:back_color] || DEFAULT_BACK_COLOR
  @line_color = conf[:line_color] || DEFAULT_LINE_COLOR
  @next_color = conf[:next_color] || DEFAULT_NEXT_COLOR
  @current_color = conf[:current_color] || DEFAULT_CURRENT_COLOR
  @line_width = conf[:line_width] || DEFAULT_LINE_WIDTH
  @next_width = conf[:next_width] || DEFAULT_NEXT_WIDTH
  @processor = Processor.new(conf[:threshold],
                             conf[:skew_threshold_angle])
  @actions = []
  @locus = []
end

Public Instance Methods

add_action(sequence, action, &block) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 43
def add_action(sequence, action, &block)
  invalid_motion = sequence.find do |motion|
    not @processor.available_motion?(motion)
  end
  raise InvalidMotionError.new(invalid_motion) if invalid_motion
  @actions << [sequence, action, block]
end
button_motion(x, y, width, height) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 63
def button_motion(x, y, width, height)
  new_x = @base_x + x
  new_y = @base_y + y
  @locus << [new_x, new_y]
  @processor.update_position(new_x, new_y)
end
button_release(x, y, width, height) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 59
def button_release(x, y, width, height)
  perform_action
end
clear_actions() click to toggle source
# File lib/rabbit/gesture/handler.rb, line 39
def clear_actions
  @actions.clear
end
draw(renderer) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 79
def draw(renderer)
  if @back_color.alpha == 1.0 or
      (@back_color.alpha < 1.0 and renderer.alpha_available?)
    args = [true, 0, 0, renderer.width, renderer.height]
    args << @back_color
    renderer.draw_rectangle(*args)
  end

  draw_available_marks(renderer, next_available_motions)

  act, = action
  draw_mark(renderer, act, *@processor.position) if act

  draw_locus(renderer)
end
draw_last_locus(renderer) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 70
def draw_last_locus(renderer)
  if @locus.size >= 2
    x1, y1 = @locus[-2]
    x2, y2 = @locus[-1]
    args = [x1, y1, x2, y2, @line_color, {:line_width => @line_width}]
    renderer.draw_line(*args)
  end
end
draw_locus(renderer) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 95
def draw_locus(renderer)
  return if @locus.empty?
  renderer.draw_lines(@locus, @line_color, {:line_width => @line_width})
end
moved?() click to toggle source
# File lib/rabbit/gesture/handler.rb, line 100
def moved?
  @locus.size >= 2
end
processing?() click to toggle source
# File lib/rabbit/gesture/handler.rb, line 35
def processing?
  @processor.started?
end
start(button, x, y, base_x, base_y) click to toggle source
# File lib/rabbit/gesture/handler.rb, line 51
def start(button, x, y, base_x, base_y)
  @button = button
  @processor.start(x, y)
  @base_x = base_x
  @base_y = base_y
  @locus = [[x, y]]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.