Class: MINTo::Mouse

Inherits:
Pointer
  • Object
show all
Defined in:
lib/MINT-core/model/ir/mouse_old.rb

Defined Under Namespace

Classes: CoordinateTracker

Instance Method Summary collapse

Instance Method Details

#cache_coordinates(x, y) ⇒ Object



43
44
45
46
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 43

def cache_coordinates(x,y)
  @x = x
  @y = y
end

#initialize_statemachineObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 48

def initialize_statemachine
  if @statemachine.blank?

    @pointer_timer = nil
    @wheel_timer = nil

    @statemachine = Statemachine.build do

      trans :disconnected,:connect, :connected
      trans :connected, :disconnect, :disconnected

      superstate :connected do
        parallel :p do
          statemachine :s1 do
            superstate :pointer do
              on_entry :start_coordinates_tracker
              on_exit :stop_coordinates_tracker


              trans :stopped, :move, :moving
              trans :moving,:move, :moving
              trans :moving,:stop,:stopped

              state :moving do
                on_entry :start_timeout_pointer # TODO no support for varibles in on_entry on_exit
                on_exit :stop_timeout_pointer
              end
            end
          end
          statemachine :s2 do
            superstate :right_button do # TODO we still not have name spaces :-(
              trans :right_released, :right_press, :right_pressed
              trans :right_pressed, :right_release, :right_released
            end
          end
          statemachine :s3 do
            superstate :left_button do # TODO we still not have name spaces :-(
              trans :left_released, :left_press, :left_pressed
              trans :left_pressed, :left_release, :left_released
            end
          end
          statemachine :s4 do
            superstate :middle_button do # TODO we still not have name spaces :-(
              trans :middle_released, :middle_press, :middle_pressed
              trans :middle_pressed, :middle_release, :middle_released
            end
          end
          statemachine :s5 do
            superstate :wheel do
              trans :wheel_stopped,:regress, :regressing
              trans :wheel_stopped,:progress, :progressing

              trans :regressing, :regress, :regressing
              trans :regressing, :stop_wheel, :wheel_stopped
              trans :regressing, :progress, :progressing

              trans :progressing, :progress, :progressing
              trans :progressing, :stop_wheel, :wheel_stopped
              trans :progressing, :regress, :regressing

              state :regressing do
                on_entry :start_timeout_wheel
                on_exit :stop_timeout_wheel
              end
              state :progressing do
                on_entry :start_timeout_wheel
                on_exit :stop_timeout_wheel
              end
            end
          end
        end
      end
    end
  end

  def start_timeout_wheel
    if not @wheel_timer
      @wheel_timer = EventMachine::Timer.new(0.3) do
        process_event("stop_wheel")
      end
    else
      puts "wheel timer already started!!!"
    end
  end

  def stop_timeout_wheel
    stop_timeout(@wheel_timer)
  end

  def start_timeout_pointer
#        @tracker  = CoordinateTracker.new(self)
#        @tracker.callback do |x|
#          @tracker.save(state)
#        end

    if not @pointer_timer
      @pointer_timer = EventMachine::Timer.new(0.3) do
        @mouse.x=@x
      @mouse.y=@y
      @mouse.process_event("stop")

#            @tracker.set_deferred_status :succeeded, "stop"
      end
    else
      puts "pointer timer already started!!!"
    end
  end


  def stop_timeout_pointer
    stop_timeout(@pointer_timer)
  end

  def stop_timeout(timer)
    if timer
      timer.cancel
      timer = nil
    end
  end
end

#start_timeout_pointerObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 137

def start_timeout_pointer
#        @tracker  = CoordinateTracker.new(self)
#        @tracker.callback do |x|
#          @tracker.save(state)
#        end

  if not @pointer_timer
    @pointer_timer = EventMachine::Timer.new(0.3) do
      @mouse.x=@x
    @mouse.y=@y
    @mouse.process_event("stop")

#            @tracker.set_deferred_status :succeeded, "stop"
    end
  else
    puts "pointer timer already started!!!"
  end
end

#start_timeout_wheelObject



123
124
125
126
127
128
129
130
131
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 123

def start_timeout_wheel
  if not @wheel_timer
    @wheel_timer = EventMachine::Timer.new(0.3) do
      process_event("stop_wheel")
    end
  else
    puts "wheel timer already started!!!"
  end
end

#stop_timeout(timer) ⇒ Object



161
162
163
164
165
166
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 161

def stop_timeout(timer)
  if timer
    timer.cancel
    timer = nil
  end
end

#stop_timeout_pointerObject



157
158
159
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 157

def stop_timeout_pointer
  stop_timeout(@pointer_timer)
end

#stop_timeout_wheelObject



133
134
135
# File 'lib/MINT-core/model/ir/mouse_old.rb', line 133

def stop_timeout_wheel
  stop_timeout(@wheel_timer)
end