Class: TT::Gizmo::Manipulator
- Inherits:
-
Object
- Object
- TT::Gizmo::Manipulator
- Defined in:
- TT_Lib2/gizmo_manipulator.rb
Overview
Constant Summary
- CLR_X_AXIS =
Sketchup::Color.new( 255, 0, 0 )
- CLR_Y_AXIS =
Sketchup::Color.new( 0, 128, 0 )
- CLR_Z_AXIS =
Sketchup::Color.new( 0, 0, 255 )
- CLR_SELECTED =
Sketchup::Color.new( 255, 255, 0 )
Instance Attribute Summary collapse
- #axes ⇒ Object readonly
- #callback ⇒ Object readonly
- #callback_end ⇒ Object readonly
- #callback_start ⇒ Object readonly
- #origin ⇒ Object
- #size ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #cancel ⇒ Object
- #draw(view) ⇒ Nil
-
#initialize(origin, xaxis, yaxis, zaxis) ⇒ Manipulator
constructor
A new instance of Manipulator.
- #mouse_over? ⇒ Boolean
- #normal ⇒ Geom::Vector3d
- #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
- #xaxis=(vector) ⇒ Boolean
- #yaxis=(vector) ⇒ Boolean
- #zaxis=(vector) ⇒ Boolean
Constructor Details
#initialize(origin, xaxis, yaxis, zaxis) ⇒ Manipulator
Returns a new instance of Manipulator
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 35 def initialize( origin, xaxis, yaxis, zaxis ) # Event callbacks @callback = nil @callback_start = nil @callback_end = nil @size = 150 # pixels # Origin @origin = origin # Set up axis and events @axes = [] @axes << TT::Gizmo::Axis.new( self, @origin, xaxis, CLR_X_AXIS, CLR_SELECTED, :x ) @axes << TT::Gizmo::Axis.new( self, @origin, yaxis, CLR_Y_AXIS, CLR_SELECTED, :y ) @axes << TT::Gizmo::Axis.new( self, @origin, zaxis, CLR_Z_AXIS, CLR_SELECTED, :z ) @active_axis = nil # Current Axis active due to a mouse down event. @mouse_axis = nil # Current Axis the mouse hovers over. for axis in @axes axis.on_transform_start { |axis, action_name| @callback_start.call( action_name ) unless @callback_start.nil? } axis.on_transform_end { |axis, action_name| @callback_end.call( action_name ) unless @callback_end.nil? } axis.on_transform { |axis, t_increment, t_total, data| @origin = axis.origin update_axes( axis.origin, axis ) @callback.call( t_increment, t_total, data ) unless @callback.nil? } end end |
Instance Attribute Details
#axes ⇒ Object (readonly)
25 26 27 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 25 def axes @axes end |
#callback ⇒ Object (readonly)
27 28 29 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 27 def callback @callback end |
#callback_end ⇒ Object (readonly)
27 28 29 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 27 def callback_end @callback_end end |
#callback_start ⇒ Object (readonly)
27 28 29 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 27 def callback_start @callback_start end |
#origin ⇒ Object
25 26 27 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 25 def origin @origin end |
#size ⇒ Object
26 27 28 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 26 def size @size end |
Instance Method Details
#active? ⇒ Boolean
90 91 92 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 90 def active? !@active_axis.nil? end |
#cancel ⇒ Object
230 231 232 233 234 235 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 230 def cancel for axis in @axes axis.cancel end reset() end |
#draw(view) ⇒ Nil
217 218 219 220 221 222 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 217 def draw( view ) for axis in @axes axis.draw( view ) end nil end |
#mouse_over? ⇒ Boolean
225 226 227 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 225 def mouse_over? !@mouse_axis.nil? end |
#normal ⇒ Geom::Vector3d
104 105 106 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 104 def normal @axes.z.direction end |
#on_transform(&block) ⇒ Object
109 110 111 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 109 def on_transform( &block ) @callback = block end |
#on_transform_end(&block) ⇒ Object
119 120 121 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 119 def on_transform_end( &block ) @callback_end = block end |
#on_transform_start(&block) ⇒ Object
114 115 116 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 114 def on_transform_start( &block ) @callback_start = block end |
#onLButtonDown(flags, x, y, view) ⇒ Boolean
186 187 188 189 190 191 192 193 194 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 186 def onLButtonDown( flags, x, y, view ) for axis in @axes if axis.onLButtonDown( flags, x, y, view ) @active_axis = axis return true end end false end |
#onLButtonUp(flags, x, y, view) ⇒ Boolean
203 204 205 206 207 208 209 210 211 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 203 def onLButtonUp( flags, x, y, view ) for axis in @axes if axis.onLButtonUp( flags, x, y, view ) @active_axis = nil return true end end false end |
#onMouseMove(flags, x, y, view) ⇒ Boolean
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 168 169 170 171 172 173 174 175 176 177 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 142 def onMouseMove( flags, x, y, view ) # (!) Hotfix. Some times it appear that button up event is not detected # and the gizmo thinks an axis is active. Some times due to cursor # being released outside SketchUp's viewport or - it appear - with # glitch that occur with quick clicks and released. if @active_axis && flags & MK_LBUTTON != MK_LBUTTON #puts 'Out of state!' #puts flags #puts @active_axis.id #puts '> Restore!' @active_axis = nil end if @active_axis @active_axis.onMouseMove( flags, x, y, view ) return true else # Prioritise last axis the mouse hovered over. if @mouse_axis && @mouse_axis.onMouseMove( flags, x, y, view ) return true else @mouse_axis = nil end # If the mouse doesn't interact with the last axis any more, check the # rest. for axis in @axes if axis.onMouseMove( flags, x, y, view ) @mouse_axis = axis return true end end end @mouse_axis = nil false end |
#tooltip ⇒ Object
95 96 97 98 99 100 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 95 def tooltip for axis in @axes return axis.tooltip if axis.mouse_active? end '' end |
#xaxis=(vector) ⇒ Boolean
72 73 74 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 72 def xaxis=( vector ) @axes.x.direction = vector end |
#yaxis=(vector) ⇒ Boolean
78 79 80 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 78 def yaxis=( vector ) @axes.y.direction = vector end |
#zaxis=(vector) ⇒ Boolean
84 85 86 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 84 def zaxis=( vector ) @axes.z.direction = vector end |