Class: Rabbit::Gesture::Handler
- Inherits:
-
Object
- Object
- Rabbit::Gesture::Handler
- Defined in:
- lib/rabbit/gesture/handler.rb
Constant Summary collapse
- DEFAULT_BACK_COLOR =
Renderer::Color.parse("#3333337f")
- DEFAULT_LINE_COLOR =
Renderer::Color.parse("#f00f")
- DEFAULT_NEXT_COLOR =
Renderer::Color.parse("#0f0c")
- DEFAULT_CURRENT_COLOR =
Renderer::Color.parse("#f0fc")
- DEFAULT_LINE_WIDTH =
3
- DEFAULT_NEXT_WIDTH =
10
Instance Attribute Summary collapse
-
#back_color ⇒ Object
Returns the value of attribute back_color.
-
#current_color ⇒ Object
Returns the value of attribute current_color.
-
#line_color ⇒ Object
Returns the value of attribute line_color.
-
#line_width ⇒ Object
Returns the value of attribute line_width.
-
#next_color ⇒ Object
Returns the value of attribute next_color.
-
#next_width ⇒ Object
Returns the value of attribute next_width.
Instance Method Summary collapse
- #add_action(sequence, action, &block) ⇒ Object
- #button_motion(x, y, width, height) ⇒ Object
- #button_release(x, y, width, height) ⇒ Object
- #clear_actions ⇒ Object
- #draw(renderer) ⇒ Object
- #draw_last_locus(renderer) ⇒ Object
- #draw_locus(renderer) ⇒ Object
-
#initialize(conf = {}) ⇒ Handler
constructor
A new instance of Handler.
- #moved? ⇒ Boolean
- #processing? ⇒ Boolean
- #start(button, x, y, base_x, base_y) ⇒ Object
Constructor Details
#initialize(conf = {}) ⇒ Handler
Returns a new instance of Handler.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |
Instance Attribute Details
#back_color ⇒ Object
Returns the value of attribute back_color.
18 19 20 |
# File 'lib/rabbit/gesture/handler.rb', line 18 def back_color @back_color end |
#current_color ⇒ Object
Returns the value of attribute current_color.
18 19 20 |
# File 'lib/rabbit/gesture/handler.rb', line 18 def current_color @current_color end |
#line_color ⇒ Object
Returns the value of attribute line_color.
18 19 20 |
# File 'lib/rabbit/gesture/handler.rb', line 18 def line_color @line_color end |
#line_width ⇒ Object
Returns the value of attribute line_width.
19 20 21 |
# File 'lib/rabbit/gesture/handler.rb', line 19 def line_width @line_width end |
#next_color ⇒ Object
Returns the value of attribute next_color.
18 19 20 |
# File 'lib/rabbit/gesture/handler.rb', line 18 def next_color @next_color end |
#next_width ⇒ Object
Returns the value of attribute next_width.
19 20 21 |
# File 'lib/rabbit/gesture/handler.rb', line 19 def next_width @next_width end |
Instance Method Details
#add_action(sequence, action, &block) ⇒ Object
43 44 45 46 47 48 49 |
# 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) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/rabbit/gesture/handler.rb', line 63 def (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) ⇒ Object
59 60 61 |
# File 'lib/rabbit/gesture/handler.rb', line 59 def (x, y, width, height) perform_action end |
#clear_actions ⇒ Object
39 40 41 |
# File 'lib/rabbit/gesture/handler.rb', line 39 def clear_actions @actions.clear end |
#draw(renderer) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
70 71 72 73 74 75 76 77 |
# 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) ⇒ Object
95 96 97 98 |
# 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? ⇒ Boolean
100 101 102 |
# File 'lib/rabbit/gesture/handler.rb', line 100 def moved? @locus.size >= 2 end |
#processing? ⇒ Boolean
35 36 37 |
# File 'lib/rabbit/gesture/handler.rb', line 35 def processing? @processor.started? end |
#start(button, x, y, base_x, base_y) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rabbit/gesture/handler.rb', line 51 def start(, x, y, base_x, base_y) @button = @processor.start(x, y) @base_x = base_x @base_y = base_y @locus = [[x, y]] end |