Class: TT::DrawCache
- Inherits:
-
Object
- Object
- TT::DrawCache
- Defined in:
- TT_Lib2/draw_cache.rb
Overview
Caches drawing instructions so complex calculations for generating the GL data can be reused.
Redirect all Skethcup::View commands to a DrawCache object and call #render in a Tool's #draw event.
Instance Method Summary collapse
-
#clear ⇒ Nil
Clears the cache.
-
#initialize(view) ⇒ DrawCache
constructor
A new instance of DrawCache.
- #inspect ⇒ String
-
#method_missing(*args) ⇒ Object
Pass through methods to Sketchup::View so that the drawing cache object can easily replace Sketchup::View objects in existing codes.
-
#render ⇒ Sketchup::View
Draws the cached drawing instructions.
Constructor Details
#initialize(view) ⇒ DrawCache
Returns a new instance of DrawCache
43 44 45 46 |
# File 'TT_Lib2/draw_cache.rb', line 43 def initialize( view ) @view = view @commands = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
Pass through methods to Sketchup::View so that the drawing cache object can easily replace Sketchup::View objects in existing codes.
94 95 96 97 98 99 100 101 102 |
# File 'TT_Lib2/draw_cache.rb', line 94 def method_missing( *args ) view = @view method = args.first if view.respond_to?( method ) view.send(*args) else raise NoMethodError, "undefined method `#{method}' for #{self.class.name}" end end |
Instance Method Details
#clear ⇒ Nil
Clears the cache. All drawing instructions are removed.
52 53 54 55 |
# File 'TT_Lib2/draw_cache.rb', line 52 def clear @commands.clear nil end |
#inspect ⇒ String
106 107 108 109 |
# File 'TT_Lib2/draw_cache.rb', line 106 def inspect hex_id = TT.object_id_hex( self ) "#<#{self.class.name}:#{hex_id} Commands:#{@commands.size}>" end |
#render ⇒ Sketchup::View
Draws the cached drawing instructions.
61 62 63 64 65 66 67 |
# File 'TT_Lib2/draw_cache.rb', line 61 def render view = @view for command in @commands view.send( *command ) end view end |