Class: Gosu::Image

Inherits:
Object
  • Object
show all
Includes:
TexPlay
Defined in:
lib/texplay.rb,
lib/texplay/live.rb

Constant Summary

Constants included from TexPlay

TexPlay::RENDER_CLEAR_COLOR, TexPlay::TP_MAX_QUAD_SIZE, TexPlay::VERSION, TexPlay::Win

Constants included from TexPlay::Colors

TexPlay::Colors::Alpha, TexPlay::Colors::Black, TexPlay::Colors::Blue, TexPlay::Colors::Brown, TexPlay::Colors::Cyan, TexPlay::Colors::Green, TexPlay::Colors::Grey, TexPlay::Colors::Orange, TexPlay::Colors::Purple, TexPlay::Colors::Red, TexPlay::Colors::Turquoise, TexPlay::Colors::Tyrian, TexPlay::Colors::White, TexPlay::Colors::Yellow

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TexPlay

#[], #bezier, #cache, #circle, #clear, #clone, #color, #colour, create_blank_image, create_image, create_macro, #delete_options, #dup, #each, #fill, #force_sync, from_blob, get_options, #get_options, #get_pixel, init, #line, load, #method_missing, #ngon, #offset, on_setup, original_create_image, #paint, #polyline, #quad_cached?, #rect, #refresh_cache, refresh_cache_all, remove_macro, set_defaults, set_options, #set_options, #set_pixel, setup, #splice, #to_blob

Constructor Details

#initialize(*args) ⇒ Image

Returns a new instance of Image.



13
14
15
16
17
# File 'lib/texplay/live.rb', line 13

def initialize(*args)
  @x = WIDTH / 2
  @y = HEIGHT / 2
  orig_init(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class TexPlay

Instance Attribute Details

#xObject

Returns the value of attribute x.



10
11
12
# File 'lib/texplay/live.rb', line 10

def x
  @x
end

#yObject

Returns the value of attribute y.



10
11
12
# File 'lib/texplay/live.rb', line 10

def y
  @y
end

Class Method Details

.from_text(*args, &block) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/texplay.rb', line 183

def from_text(*args, &block)

  options = args.last.is_a?(Hash) ? args.pop : {}
  # invoke old behaviour
  obj = original_from_text(*args, &block)

  prepare_image(obj, args.first, options)
end

.new(*args, &block) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/texplay.rb', line 172

def new(*args, &block)

  options = args.last.is_a?(Hash) ? args.pop : {}
  # invoke old behaviour
  obj = original_new(*args, &block)

  prepare_image(obj, args.first, options)
end

.original_from_textObject



181
# File 'lib/texplay.rb', line 181

alias_method :original_from_text, :from_text

.original_newObject



170
# File 'lib/texplay.rb', line 170

alias_method :original_new, :new

.prepare_image(obj, window, options = {}) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/texplay.rb', line 192

def prepare_image(obj, window, options={})
  options = {
    :caching => TexPlay.get_options[:caching]
  }.merge!(options)

  caching_mode = options[:caching]

  # we can't manipulate large images, so skip them.
  if obj.width <= (TexPlay::TP_MAX_QUAD_SIZE) &&
      obj.height <= (TexPlay::TP_MAX_QUAD_SIZE)
    
    if caching_mode
      if caching_mode == :lazy

        # only cache if quad already cached (to refresh old data)
        # otherwise cache lazily at point of first TexPlay call
        obj.refresh_cache if obj.quad_cached?

      else
        
        # force a cache - this obviates the need for a
        # potentialy expensive runtime cache of the image by
        # moving the cache to load-time
        obj.refresh_cache
      end
    end
  end
  
  # run custom setup
  TexPlay.setup(obj)

  obj.instance_variable_set(:@__window__, window)

  obj
end

Instance Method Details

#orig_initObject



12
# File 'lib/texplay/live.rb', line 12

alias_method :orig_init, :initialize