Class: TT::Gizmo::ScaleGizmo
- Inherits:
-
Object
- Object
- TT::Gizmo::ScaleGizmo
- Defined in:
- TT_Lib2/gizmo_manipulator.rb
Overview
Constant Summary
- SIZE =
170
Instance Attribute Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #cancel ⇒ Object
- #draw(view) ⇒ Nil
-
#initialize(parent, origin, direction, color, active_color) ⇒ ScaleGizmo
constructor
A new instance of ScaleGizmo.
- #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
- #scale_array(axis, scale, flags) ⇒ Array
- #scale_mask(axis, flags) ⇒ Array
- #tooltip ⇒ Object
Constructor Details
#initialize(parent, origin, direction, color, active_color) ⇒ ScaleGizmo
Returns a new instance of ScaleGizmo
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1329 def initialize( parent, origin, direction, color, active_color ) @parent = parent @origin = origin.clone @direction = direction.clone @color = color @active_color = active_color @selected = false @interacting = false # Cache of the axis origin and orientation. Cached on onLButtonDown @old_origin = nil @old_vector = nil @old_axis = nil # [pt1, pt2] # User InputPoint @pt_screen_start = nil @pt_screen_mouse = nil @pt_start = nil @pt_mouse = nil # Event callbacks @callback = nil @callback_start = nil @callback_end = nil end |
Instance Attribute Details
#direction ⇒ Object
1321 1322 1323 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1321 def direction @direction end |
#origin ⇒ Object
1321 1322 1323 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1321 def origin @origin end |
Instance Method Details
#active? ⇒ Boolean
1374 1375 1376 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1374 def active? @interacting == true end |
#cancel ⇒ Object
1582 1583 1584 1585 1586 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1582 def cancel @selected = false @interacting = false @pt_mouse = nil end |
#draw(view) ⇒ Nil
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1551 def draw( view ) size = view.pixels_to_model( SIZE, @origin ) if @pt_mouse pt = @pt_mouse else pt = @origin.offset( @direction.reverse, size ) end pt1 = view.screen_coords( @origin ) pt2 = view.screen_coords( pt ) color = (@selected) ? @active_color : @color view.drawing_color = color view.line_stipple = '-' view.line_width = 2 view.draw2d( GL_LINE_STRIP, pt1, pt2 ) view.line_stipple = '' view.draw_points( [pt], 8, 1, color ) #if @pt_mouse #view.line_stipple = '' # view.draw_points( [@pt_mouse], 8, 4, @active_color) #end view.draw2d( GL_LINE_STRIP, [-100,-100,0], [-50,-50,0] ) # Hack end |
#mouse_active? ⇒ Boolean
1380 1381 1382 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1380 def mouse_active? @mouse_active == true end |
#on_transform(&block) ⇒ Object
1358 1359 1360 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1358 def on_transform( &block ) @callback = block end |
#on_transform_end(&block) ⇒ Object
1368 1369 1370 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1368 def on_transform_end( &block ) @callback_end = block end |
#on_transform_start(&block) ⇒ Object
1363 1364 1365 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1363 def on_transform_start( &block ) @callback_start = block end |
#onLButtonDown(flags, x, y, view) ⇒ Boolean
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1396 def onLButtonDown( flags, x, y, view ) if @selected # Cache the origin for use in onMouseMove to work out the distance # moved. @old_origin = @origin.clone @old_axis = [ @origin.clone, @direction.clone ] # Line (3D) #@pt_screen_start = Geom::Point3d.new( x, y, 0 ) #@pt_screen_mouse = @pt_screen_start.clone # Find the closest point on the segments from where the mouse is. segments = gripper_segments( view ) @pt_start = project_to_segment( view, x, y, segments, 10.0 ) return true unless @pt_start #@last_vector = @origin.vector_to( @pt_start ) @last_scale = 1.0 @interacting = true @callback_start.call( self, 'Scale' ) unless @callback_start.nil? true else false end end |
#onLButtonUp(flags, x, y, view) ⇒ Boolean
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1429 def onLButtonUp( flags, x, y, view ) @pt_mouse = nil if @interacting @callback_end.call( self, 'Scale' ) unless @callback_end.nil? @interacting = false true else @interacting = false false end end |
#onMouseMove(flags, x, y, view) ⇒ Boolean
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1448 def onMouseMove( flags, x, y, view ) if @interacting @mouse_active = true segments = gripper_segments( view ) screen_point = Geom::Point3d.new( x, y, 0 ) @pt_mouse = project_to_segment( view, x, y, segments ) return false unless @pt_mouse start_vector = @origin.vector_to( @pt_start ) mouse_vector = @origin.vector_to( @pt_mouse ) # Prevent scaling in negative direction. if mouse_vector.valid? && mouse_vector.samedirection?( @direction ) mouse_vector.length = 0 @pt_mouse = @origin.clone end total_scale = mouse_vector.length / start_vector.length if @last_scale == 0 increment_scale = 0 else increment_scale = total_scale / @last_scale end # Increment scaling = scale_array( @parent, increment_scale, flags ) t_increment = Geom::Transformation.scaling( *scaling ) # Total scaling = scale_array( @parent, total_scale, flags ) t_total = Geom::Transformation.scaling( *scaling ) @last_scale = total_scale scale_formatted = TT::Locale.float_to_string( total_scale, 2 ) Sketchup.vcb_label = 'Scale' Sketchup.vcb_value = scale_formatted view.tooltip = "Scale: #{scale_formatted}" mask = scale_mask( @parent, flags ) data = [ :scale, @parent.origin, total_scale, mask ] # Convert the local scaling transformation into global transformation. gizmo = @parent.parent gx, gy, gz = gizmo.axes.map { |axis| axis.direction } go = gizmo.origin gizmo_tr = Geom::Transformation.new( gx, gy, gz, go ) t_increment = gizmo_tr * t_increment * gizmo_tr.inverse t_total = gizmo_tr * t_total * gizmo_tr.inverse @callback.call( self, t_increment, t_total, data ) unless @callback.nil? true else @selected = mouse_over?( x, y, view ) @mouse_active = @selected end end |
#scale_array(axis, scale, flags) ⇒ Array
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1514 def scale_array( axis, scale, flags ) origin_pt = ORIGIN.clone if flags & CONSTRAIN_MODIFIER_MASK == CONSTRAIN_MODIFIER_MASK [ origin_pt, scale, scale, scale ] else case axis.id when :x [ origin_pt, scale, 1, 1 ] when :y [ origin_pt, 1, scale, 1 ] when :z [ origin_pt, 1, 1, scale ] end end end |
#scale_mask(axis, flags) ⇒ Array
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1532 def scale_mask( axis, flags ) if flags & CONSTRAIN_MODIFIER_MASK == CONSTRAIN_MODIFIER_MASK [ true, true, true ] else case axis.id when :x [ true, false, false ] when :y [ false, true, false ] when :z [false, false, true ] end end end |
#tooltip ⇒ Object
1385 1386 1387 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 1385 def tooltip 'Scale' end |