Class: Graphics::Drawing

Inherits:
AbstractSimulation show all
Defined in:
lib/graphics/simulation.rb

Overview

A drawing. Like a Simulation, but on a canvas that doesn’t have double buffering or clearing on each tick.

See AbstractSimulation for most methods.

Constant Summary

Constants inherited from AbstractSimulation

AbstractSimulation::CLEAR_COLOR, AbstractSimulation::D2R, AbstractSimulation::DEBUG_COLOR, AbstractSimulation::DEFAULT_FONT, AbstractSimulation::FONT_GLOB, AbstractSimulation::LOG_INTERVAL, AbstractSimulation::R2D, AbstractSimulation::SCREEN_FLAGS

Instance Attribute Summary collapse

Attributes inherited from AbstractSimulation

#_bodies, #color, #done, #font, #h, #iter_per_tick, #key_handler, #keydown_handler, #paused, #renderer, #start_time, #w

Instance Method Summary collapse

Methods inherited from AbstractSimulation

#add_key_handler, #add_keydown_handler, #angle, #audio, #bezier, #blit, #circle, #clear, #debug, #draw, #draw_collection, #ellipse, #fast_rect, #find_font, #fps, #from_hsl, #from_hsv, #handle_event, #handle_keys, #hline, #image, #initialize_colors, #initialize_keys, #line, #mouse, #open_mixer, #point, #polygon, #populate, #post_draw, #project, #put, #rect, #register_bodies, #register_body, #register_color, #register_hsla, #register_hsva, #render_text, #run, #save, #sprite, #text, #text_size, #update, #vline

Constructor Details

#initialize(*a) ⇒ Drawing

:nodoc:



737
738
739
740
741
742
743
744
745
746
# File 'lib/graphics/simulation.rb', line 737

def initialize(*a) # :nodoc:
  super

  self.texture = renderer.new_texture

  draw_on texture do
    clear
    yield if block_given?
  end
end

Instance Attribute Details

#textureObject

The canvas used for all drawing.



735
736
737
# File 'lib/graphics/simulation.rb', line 735

def texture
  @texture
end

Instance Method Details

#draw_and_flip(n) ⇒ Object

:nodoc:



766
767
768
769
770
# File 'lib/graphics/simulation.rb', line 766

def draw_and_flip n # :nodoc:
  draw_on texture do
    self.draw n
  end
end

#draw_on(texture) ⇒ Object

Temporarily render to a texture instead of the renderer’s window, then copy that texture to the renderer and present it.



752
753
754
755
756
757
758
759
760
# File 'lib/graphics/simulation.rb', line 752

def draw_on texture
  renderer.target = texture

  yield if block_given?
ensure
  renderer.target = nil
  renderer.copy_texture texture
  renderer.present
end

#pre_draw(n) ⇒ Object

:nodoc:



762
763
764
# File 'lib/graphics/simulation.rb', line 762

def pre_draw n # :nodoc:
  # no clear
end