Class: MSPhysics::BodyContext
- Inherits:
-
CommonContext
- Object
- Entity
- CommonContext
- MSPhysics::BodyContext
- Defined in:
- RubyExtension/MSPhysics/body_context.rb
Overview
BodyContext contains Body events and event-related functions.
Simulation Events collapse
-
#onClick {|point| ... } ⇒ Object
Assign a block of code to the onClick event.
-
#onDrag { ... } ⇒ Object
Assign a block of code to the onDrag event.
-
#onDraw {|view, bb| ... } ⇒ Object
Assign a block of code to the onDraw event.
-
#onEnd { ... } ⇒ Object
Assign a block of code to the onEnd event.
-
#onPause { ... } ⇒ Object
Assign a block of code to the onPause event.
-
#onPlay { ... } ⇒ Object
Assign a block of code to the onPlay event.
-
#onPostFrame { ... } ⇒ Object
Assign a block of code to the onPostFrame event.
-
#onPostUpdate { ... } ⇒ Object
Assign a block of code to the onUpdate event.
-
#onPreFrame { ... } ⇒ Object
Assign a block of code to the onPreFrame event.
-
#onPreUpdate { ... } ⇒ Object
Assign a block of code to the onPreUpdate event.
-
#onStart { ... } ⇒ Object
Assign a block of code to the onStart event.
-
#onTick { ... } ⇒ Object
Assign a block of code to the onTick event.
-
#onTouch {|toucher, point, normal, force, speed| ... } ⇒ Object
Assign a block of code to the onTouch event.
-
#onTouching {|toucher| ... } ⇒ Object
Assign a block of code to the onTouching event.
-
#onUnclick { ... } ⇒ Object
Assign a block of code to the onUnclick event.
-
#onUntouch {|toucher| ... } ⇒ Object
Assign a block of code to the onUntouch event.
-
#onUpdate { ... } ⇒ Object
Assign a block of code to the onUpdate event.
User Input Events collapse
-
#onKeyDown {|key, val, char| ... } ⇒ Object
Assign a block of code to the onKeyDown event.
-
#onKeyExtended {|key, val, char| ... } ⇒ Object
Assign a block of code to the onKeyExtended event.
-
#onKeyUp {|key, val, char| ... } ⇒ Object
Assign a block of code to the onKeyUp event.
-
#onLButtonDoubleClick {|x, y| ... } ⇒ Object
Assign a block of code to the onLButtonDoubleClick event.
-
#onLButtonDown {|x, y| ... } ⇒ Object
Assign a block of code to the onLButtonDown event.
-
#onLButtonUp {|x, y| ... } ⇒ Object
Assign a block of code to the onLButtonUp event.
-
#onMButtonDoubleClick {|x, y| ... } ⇒ Object
Assign a block of code to the onMButtonDoubleClick event.
-
#onMButtonDown {|x, y| ... } ⇒ Object
Assign a block of code to the onMButtonDown event.
-
#onMButtonUp {|x, y| ... } ⇒ Object
Assign a block of code to the onMButtonUp event.
-
#onMouseMove {|x, y, view| ... } ⇒ Object
Assign a block of code to the onMouseMove event.
-
#onMouseWheelRotate {|x, y, dir| ... } ⇒ Object
Assign a block of code to the onMouseWheelRotate event.
-
#onMouseWheelTilt {|x, y, dir| ... } ⇒ Object
Assign a block of code to the onMouseWheelTilt event.
-
#onRButtonDoubleClick {|x, y| ... } ⇒ Object
Assign a block of code to the onRButtonDoubleClick event.
-
#onRButtonDown {|x, y| ... } ⇒ Object
Assign a block of code to the onRButtonDown event.
-
#onRButtonUp {|x, y| ... } ⇒ Object
Assign a block of code to the onRButtonUp event.
-
#onXButton1DoubleClick {|x, y| ... } ⇒ Object
Assign a block of code to the onXButton1DoubleClick event.
-
#onXButton1Down {|x, y| ... } ⇒ Object
Assign a block of code to the onXButton1Down event.
-
#onXButton1Up {|x, y| ... } ⇒ Object
Assign a block of code to the onXButton1Up event.
-
#onXButton2DoubleClick {|x, y| ... } ⇒ Object
Assign a block of code to the onXButton2DoubleClick event.
-
#onXButton2Down {|x, y| ... } ⇒ Object
Assign a block of code to the onXButton2Down event.
-
#onXButton2Up {|x, y| ... } ⇒ Object
Assign a block of code to the onXButton2Up event.
Instance Method Summary collapse
-
#call_event(event, *args) ⇒ Boolean
private
Trigger an event.
- #eval_script(script, script_name, line) ⇒ Object private
-
#event_proc_assigned?(event) ⇒ Boolean
Determine whether particular event has a Proc object.
-
#get_event_proc(event) ⇒ Proc?
Get a Proc object assigned to an event.
-
#initialize(body) ⇒ BodyContext
constructor
A new instance of BodyContext.
-
#on(*events) { ... } ⇒ Integer
Assign a block of code to an event or a list of events.
-
#set_event_proc(event, proc) ⇒ Boolean
Assign a Proc object to an event.
-
#this ⇒ Body
Get the associated body.
Methods inherited from CommonContext
#accumulator, #delete_global_var, #delete_var, #frame, #get_global_var, #get_set_global_var, #get_set_var, #get_var, #joybutton, #joypad, #joystick, #key, #key_slider, #leftx, #lefty, #leftz, #numx, #numy, #oscillator, #oscillator2, #oscillator2_slope, #oscillator_slope, #repeater, #rightx, #righty, #rightz, #set_global_var, #set_var, #simulation, #singular_repeater, #slider, #toggle_key, #world
Methods inherited from Entity
Constructor Details
#initialize(body) ⇒ BodyContext
Returns a new instance of BodyContext.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 6 def initialize(body) @__body = body @__events = { :onStart => nil, :onUpdate => nil, :onPreUpdate => nil, :onPostUpdate => nil, :onTick => nil, :onPreFrame => nil, :onPostFrame => nil, :onEnd => nil, :onDraw => nil, :onPlay => nil, :onPause => nil, :onTouch => nil, :onTouching => nil, :onUntouch => nil, :onClick => nil, :onDrag => nil, :onUnclick => nil, :onKeyDown => nil, :onKeyUp => nil, :onKeyExtended => nil, :onMouseMove => nil, :onLButtonDown => nil, :onLButtonUp => nil, :onLButtonDoubleClick => nil, :onRButtonDown => nil, :onRButtonUp => nil, :onRButtonDoubleClick => nil, :onMButtonDown => nil, :onMButtonUp => nil, :onMButtonDoubleClick => nil, :onXButton1Down => nil, :onXButton1Up => nil, :onXButton1DoubleClick => nil, :onXButton2Down => nil, :onXButton2Up => nil, :onXButton2DoubleClick => nil, :onMouseWheelRotate => nil, :onMouseWheelTilt => nil } super() end |
Instance Method Details
#call_event(event, *args) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Trigger an event.
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 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 131 def call_event(event, *args) evt = @__events[event.to_sym] return false unless evt begin evt.call(*args) rescue Exception => err ref = nil test = MSPhysics::SCRIPT_NAME + ':' = err. err_backtrace = err.backtrace unless AMS::IS_RUBY_VERSION_18 .force_encoding('UTF-8') err_backtrace.each { |i| i.force_encoding('UTF-8') } end err_backtrace.each { |location| if location.include?(test) ref = location break end } ref = if !ref && .include?(test) line = ref ? ref.split(test, 2)[1].split(/\:/, 2)[0].to_i : nil msg = "#{err.class.to_s[0] =~ /a|e|i|o|u/i ? 'An' : 'A'} #{err.class} has occurred while calling body #{event} event#{line ? ', line ' + line.to_s : nil}:\n#{}" raise MSPhysics::ScriptException.new(msg, err_backtrace, @__body.group, line) end true end |
#eval_script(script, script_name, line) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 56 def eval_script(script, script_name, line) eval(script, binding, script_name, line) end |
#event_proc_assigned?(event) ⇒ Boolean
Determine whether particular event has a Proc object.
122 123 124 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 122 def event_proc_assigned?(event) @__events[event.to_sym] != nil end |
#get_event_proc(event) ⇒ Proc?
Get a Proc object assigned to an event.
99 100 101 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 99 def get_event_proc(event) @__events[event.to_sym] end |
#on(*events) { ... } ⇒ Integer
Assign a block of code to an event or a list of events.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 74 def on(*events, &block) count = 0 events.flatten.each { |evt| evt = evt.to_s.downcase evt.insert(0, 'on') if evt[0..1] != 'on' found = false @__events.each { |key, val| next if key.to_s.downcase != evt evt = key found = true break } next unless found @__events[evt] = block count += 1 } state = @__events[:onTouch] || @__events[:onTouching] || @__events[:onUntouch] MSPhysics::Newton::Body.set_record_touch_data_state(@__body.address, state) count end |
#onClick {|point| ... } ⇒ Object
Assign a block of code to the onClick event.
294 295 296 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 294 def onClick(&block) set_event_proc(:onClick, block) end |
#onDrag { ... } ⇒ Object
Assign a block of code to the onDrag event.
300 301 302 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 300 def onDrag(&block) set_event_proc(:onDrag, block) end |
#onDraw {|view, bb| ... } ⇒ Object
Assign a block of code to the onDraw event.
239 240 241 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 239 def onDraw(&block) set_event_proc(:onDraw, block) end |
#onEnd { ... } ⇒ Object
Assign a block of code to the onEnd event.
220 221 222 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 220 def onEnd(&block) set_event_proc(:onEnd, block) end |
#onKeyDown {|key, val, char| ... } ⇒ Object
Windows only!
Assign a block of code to the onKeyDown event.
320 321 322 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 320 def onKeyDown(&block) set_event_proc(:onKeyDown, block) end |
#onKeyExtended {|key, val, char| ... } ⇒ Object
Windows only!
Assign a block of code to the onKeyExtended event.
342 343 344 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 342 def onKeyExtended(&block) set_event_proc(:onKeyExtended, block) end |
#onKeyUp {|key, val, char| ... } ⇒ Object
Windows only!
Assign a block of code to the onKeyUp event.
331 332 333 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 331 def onKeyUp(&block) set_event_proc(:onKeyUp, block) end |
#onLButtonDoubleClick {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onLButtonDoubleClick event.
378 379 380 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 378 def onLButtonDoubleClick(&block) set_event_proc(:onLButtonDoubleClick, block) end |
#onLButtonDown {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onLButtonDown event.
360 361 362 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 360 def onLButtonDown(&block) set_event_proc(:onLButtonDown, block) end |
#onLButtonUp {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onLButtonUp event.
369 370 371 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 369 def onLButtonUp(&block) set_event_proc(:onLButtonUp, block) end |
#onMButtonDoubleClick {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onMButtonDoubleClick event.
432 433 434 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 432 def onMButtonDoubleClick(&block) set_event_proc(:onMButtonDoubleClick, block) end |
#onMButtonDown {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onMButtonDown event.
414 415 416 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 414 def onMButtonDown(&block) set_event_proc(:onMButtonDown, block) end |
#onMButtonUp {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onMButtonUp event.
423 424 425 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 423 def onMButtonUp(&block) set_event_proc(:onMButtonUp, block) end |
#onMouseMove {|x, y, view| ... } ⇒ Object
Assign a block of code to the onMouseMove event.
351 352 353 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 351 def onMouseMove(&block) set_event_proc(:onMouseMove, block) end |
#onMouseWheelRotate {|x, y, dir| ... } ⇒ Object
Windows only!
Assign a block of code to the onMouseWheelRotate event.
496 497 498 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 496 def onMouseWheelRotate(&block) set_event_proc(:onMouseWheelRotate, block) end |
#onMouseWheelTilt {|x, y, dir| ... } ⇒ Object
Windows only!
Assign a block of code to the onMouseWheelTilt event.
506 507 508 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 506 def onMouseWheelTilt(&block) set_event_proc(:onMouseWheelTilt, block) end |
#onPause { ... } ⇒ Object
Assign a block of code to the onPause event.
252 253 254 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 252 def onPause(&block) set_event_proc(:onPause, block) end |
#onPlay { ... } ⇒ Object
Assign a block of code to the onPlay event.
246 247 248 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 246 def onPlay(&block) set_event_proc(:onPlay, block) end |
#onPostFrame { ... } ⇒ Object
Assign a block of code to the onPostFrame event.
213 214 215 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 213 def onPostFrame(&block) set_event_proc(:onPostFrame, block) end |
#onPostUpdate { ... } ⇒ Object
Assign a block of code to the onUpdate event.
191 192 193 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 191 def onPostUpdate(&block) set_event_proc(:onPostUpdate, block) end |
#onPreFrame { ... } ⇒ Object
Assign a block of code to the onPreFrame event.
206 207 208 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 206 def onPreFrame(&block) set_event_proc(:onPreFrame, block) end |
#onPreUpdate { ... } ⇒ Object
Assign a block of code to the onPreUpdate event.
183 184 185 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 183 def onPreUpdate(&block) set_event_proc(:onPreUpdate, block) end |
#onRButtonDoubleClick {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onRButtonDoubleClick event.
405 406 407 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 405 def onRButtonDoubleClick(&block) set_event_proc(:onRButtonDoubleClick, block) end |
#onRButtonDown {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onRButtonDown event.
387 388 389 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 387 def onRButtonDown(&block) set_event_proc(:onRButtonDown, block) end |
#onRButtonUp {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onRButtonUp event.
396 397 398 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 396 def onRButtonUp(&block) set_event_proc(:onRButtonUp, block) end |
#onStart { ... } ⇒ Object
Assign a block of code to the onStart event.
164 165 166 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 164 def onStart(&block) set_event_proc(:onStart, block) end |
#onTick { ... } ⇒ Object
Assign a block of code to the onTick event.
199 200 201 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 199 def onTick(&block) set_event_proc(:onTick, block) end |
#onTouch {|toucher, point, normal, force, speed| ... } ⇒ Object
Assign a block of code to the onTouch event.
264 265 266 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 264 def onTouch(&block) set_event_proc(:onTouch, block) end |
#onTouching {|toucher| ... } ⇒ Object
Assign a block of code to the onTouching event.
272 273 274 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 272 def onTouching(&block) set_event_proc(:onTouching, block) end |
#onUnclick { ... } ⇒ Object
Assign a block of code to the onUnclick event.
306 307 308 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 306 def onUnclick(&block) set_event_proc(:onUnclick, block) end |
#onUntouch {|toucher| ... } ⇒ Object
Sometimes you may want to know whether particular body is in contact with another body. Relying on events is not always the best technique. To determine whether this body is in contact with another body, use this.touching_with?(some_other_body)
or this.touching_bodies
.
Assign a block of code to the onUntouch event.
287 288 289 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 287 def onUntouch(&block) set_event_proc(:onUntouch, block) end |
#onUpdate { ... } ⇒ Object
Assign a block of code to the onUpdate event.
175 176 177 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 175 def onUpdate(&block) set_event_proc(:onUpdate, block) end |
#onXButton1DoubleClick {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onXButton1DoubleClick event.
459 460 461 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 459 def onXButton1DoubleClick(&block) set_event_proc(:onXButton1DoubleClick, block) end |
#onXButton1Down {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onXButton1Down event.
441 442 443 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 441 def onXButton1Down(&block) set_event_proc(:onXButton1Down, block) end |
#onXButton1Up {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onXButton1Up event.
450 451 452 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 450 def onXButton1Up(&block) set_event_proc(:onXButton1Up, block) end |
#onXButton2DoubleClick {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onXButton2DoubleClick event.
486 487 488 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 486 def onXButton2DoubleClick(&block) set_event_proc(:onXButton2DoubleClick, block) end |
#onXButton2Down {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onXButton2Down event.
468 469 470 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 468 def onXButton2Down(&block) set_event_proc(:onXButton2Down, block) end |
#onXButton2Up {|x, y| ... } ⇒ Object
Windows only!
Assign a block of code to the onXButton2Up event.
477 478 479 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 477 def onXButton2Up(&block) set_event_proc(:onXButton2Up, block) end |
#set_event_proc(event, proc) ⇒ Boolean
Assign a Proc object to an event.
108 109 110 111 112 113 114 115 116 117 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 108 def set_event_proc(event, proc) AMS.validate_type(proc, Proc, NilClass) return false unless @__events.keys.include?(event.to_sym) @__events[event.to_sym] = proc if event.to_s =~ /onTouch|onTouching|onUntouch/ state = @__events[:onTouch] || @__events[:onTouching] || @__events[:onUntouch] MSPhysics::Newton::Body.set_record_touch_data_state(@__body.address, state) end true end |
#this ⇒ Body
Get the associated body.
62 63 64 |
# File 'RubyExtension/MSPhysics/body_context.rb', line 62 def this @__body end |