Class: TT::Gizmo::Axis
- Inherits:
-
Object
- Object
- TT::Gizmo::Axis
- Defined in:
- TT_Lib2/gizmo_manipulator.rb
Overview
Instance Attribute Summary collapse
- #direction ⇒ Object
- #id ⇒ Object readonly
- #origin ⇒ Object
- #parent ⇒ Object readonly
Instance Method Summary collapse
- #active? ⇒ Boolean
- #cancel ⇒ Object
- #draw(view) ⇒ Nil
-
#initialize(parent, origin, direction, color, active_color, axis_id) ⇒ Axis
constructor
A new instance of Axis.
- #inspect ⇒ String
- #mouse_active? ⇒ Boolean
- #on_transform(&block) ⇒ Object
- #on_transform_end(&block) ⇒ Object
- #on_transform_start(&block) ⇒ Object
- #onLButtonDown(flags, x, y, view) ⇒ Boolean
- #onLButtonUp(flags, x, y, view) ⇒ Boolean
- #onMouseMove(flags, x, y, view) ⇒ Boolean
- #tooltip ⇒ Object
Constructor Details
#initialize(parent, origin, direction, color, active_color, axis_id) ⇒ Axis
Returns a new instance of Axis
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 273 def initialize( parent, origin, direction, color, active_color, axis_id ) @id = axis_id @parent = parent @origin = origin.clone @direction = direction.clone @color = color @active_color = active_color # Event callbacks @callback = nil @callback_start = nil @callback_end = nil # MoveGizmo @move_gizmo = MoveGizmo.new( self, origin, direction, color, active_color ) @move_gizmo.on_transform_start { |gizmo, action_name| @callback_start.call( self, action_name ) unless @callback_start.nil? } @move_gizmo.on_transform { |gizmo, t_increment, t_total, data| @origin = gizmo.origin @rotate_gizmo.origin = gizmo.origin @scale_gizmo.origin = gizmo.origin @callback.call( self, t_increment, t_total, data ) unless @callback.nil? } @move_gizmo.on_transform_end { |gizmo, action_name| @callback_end.call( self, action_name ) unless @callback_end.nil? } # RotateGizmo @rotate_gizmo = RotateGizmo.new( self, origin, direction, color, active_color ) @rotate_gizmo.on_transform_start { |gizmo, action_name| @callback_start.call( self, action_name ) unless @callback_start.nil? } @rotate_gizmo.on_transform { |gizmo, t_increment, t_total, data| @callback.call( self, t_increment, t_total, data ) unless @callback.nil? } @rotate_gizmo.on_transform_end { |gizmo, action_name| @callback_end.call( self, action_name ) unless @callback_end.nil? } # ScaleGizmo @scale_gizmo = ScaleGizmo.new( self, origin, direction, color, active_color ) @scale_gizmo.on_transform_start { |gizmo, action_name| @callback_start.call( self, action_name ) unless @callback_start.nil? } @scale_gizmo.on_transform { |gizmo, t_increment, t_total, data| @callback.call( self, t_increment, t_total, data ) unless @callback.nil? } @scale_gizmo.on_transform_end { |gizmo, action_name| @callback_end.call( self, action_name ) unless @callback_end.nil? } end |
Instance Attribute Details
#direction ⇒ Object
264 265 266 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 264 def direction @direction end |
#id ⇒ Object (readonly)
265 266 267 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 265 def id @id end |
#origin ⇒ Object
264 265 266 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 264 def origin @origin end |
#parent ⇒ Object (readonly)
265 266 267 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 265 def parent @parent end |
Instance Method Details
#active? ⇒ Boolean
350 351 352 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 350 def active? @move_gizmo.active? || @rotate_gizmo.active? || @scale_gizmo.active? end |
#cancel ⇒ Object
494 495 496 497 498 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 494 def cancel @move_gizmo.cancel @rotate_gizmo.cancel @scale_gizmo.cancel end |
#draw(view) ⇒ Nil
487 488 489 490 491 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 487 def draw( view ) @move_gizmo.draw( view ) @rotate_gizmo.draw( view ) @scale_gizmo.draw( view ) end |
#inspect ⇒ String
328 329 330 331 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 328 def inspect hex_id = TT.object_id_hex( self ) "#<#{self.class.name}:#{hex_id} #{@direction}>" end |
#mouse_active? ⇒ Boolean
369 370 371 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 369 def mouse_active? @mouse_active == true end |
#on_transform(&block) ⇒ Object
334 335 336 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 334 def on_transform( &block ) @callback = block end |
#on_transform_end(&block) ⇒ Object
344 345 346 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 344 def on_transform_end( &block ) @callback_end = block end |
#on_transform_start(&block) ⇒ Object
339 340 341 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 339 def on_transform_start( &block ) @callback_start = block end |
#onLButtonDown(flags, x, y, view) ⇒ Boolean
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 402 def onLButtonDown( flags, x, y, view ) camera = view.camera perpendicular = !camera.perspective? && camera.direction.perpendicular?( @direction ) can_move = !(@rotate_gizmo.active? || @scale_gizmo.active?) can_rotate = !(@move_gizmo.active? || @scale_gizmo.active?) && !perpendicular can_scale = !(@move_gizmo.active? || @rotate_gizmo.active?) if can_move && @move_gizmo.onLButtonDown( flags, x, y, view ) true elsif can_rotate && @rotate_gizmo.onLButtonDown( flags, x, y, view ) true elsif can_scale && @scale_gizmo.onLButtonDown( flags, x, y, view ) true else false end end |
#onLButtonUp(flags, x, y, view) ⇒ Boolean
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 426 def onLButtonUp( flags, x, y, view ) can_move = !(@rotate_gizmo.active? || @scale_gizmo.active?) can_rotate = !(@move_gizmo.active? || @scale_gizmo.active?) can_scale = !(@move_gizmo.active? || @rotate_gizmo.active?) if can_move && @move_gizmo.onLButtonUp( flags, x, y, view ) true elsif can_rotate && @rotate_gizmo.onLButtonUp( flags, x, y, view ) true elsif can_scale && @scale_gizmo.onLButtonUp( flags, x, y, view ) true elsif @interacting # (!) ... @callback_end.call( self ) unless @callback_end.nil? @interacting = false true else @interacting = false false end end |
#onMouseMove(flags, x, y, view) ⇒ Boolean
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 454 def onMouseMove( flags, x, y, view ) camera = view.camera perpendicular = !camera.perspective? && camera.direction.perpendicular?( @direction ) if @interacting # (!) ... @mouse_active = true true else can_move = !(@rotate_gizmo.active? || @scale_gizmo.active?) can_rotate = !(@move_gizmo.active? || @scale_gizmo.active?) && !perpendicular can_scale = !(@move_gizmo.active? || @rotate_gizmo.active?) if can_move && @move_gizmo.onMouseMove( flags, x, y, view ) @mouse_active = true view.invalidate return true elsif can_rotate && @rotate_gizmo.onMouseMove( flags, x, y, view ) @mouse_active = true view.invalidate return true elsif can_scale && @scale_gizmo.onMouseMove( flags, x, y, view ) @mouse_active = true view.invalidate return true end @mouse_active = false false end end |
#tooltip ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 355 def tooltip if @move_gizmo.mouse_active? @move_gizmo.tooltip elsif @rotate_gizmo.mouse_active? @rotate_gizmo.tooltip elsif @scale_gizmo.mouse_active? @scale_gizmo.tooltip else '' end end |