Class: Rubygoo::RubygameRenderAdapter
- Inherits:
-
Object
- Object
- Rubygoo::RubygameRenderAdapter
- Defined in:
- lib/rubygoo/adapters/rubygame_render_adapter.rb
Instance Method Summary collapse
- #convert_color(goo_color) ⇒ Object
- #draw_box(x1, y1, x2, y2, color) ⇒ Object
- #draw_image(img, x, y, color = nil) ⇒ Object
-
#fill(color, rect = nil) ⇒ Object
fill in a rect with color or full screen if no color.
- #finish_drawing ⇒ Object
-
#initialize(screen) ⇒ RubygameRenderAdapter
constructor
A new instance of RubygameRenderAdapter.
- #render_text(text, font_file, font_size, color) ⇒ Object
- #size_text(text, font_file, font_size) ⇒ Object
- #start_drawing ⇒ Object
Constructor Details
#initialize(screen) ⇒ RubygameRenderAdapter
Returns a new instance of RubygameRenderAdapter.
4 5 6 7 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 4 def initialize(screen) @screen = screen TTF.setup end |
Instance Method Details
#convert_color(goo_color) ⇒ Object
22 23 24 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 22 def convert_color(goo_color) [goo_color.r,goo_color.g,goo_color.b,goo_color.a] end |
#draw_box(x1, y1, x2, y2, color) ⇒ Object
9 10 11 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 9 def draw_box(x1,y1,x2,y2,color) @screen.draw_box [x1,y1], [x2,y2], convert_color(color) end |
#draw_image(img, x, y, color = nil) ⇒ Object
32 33 34 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 32 def draw_image(img, x, y, color=nil) img.blit @screen, [x,y] end |
#fill(color, rect = nil) ⇒ Object
fill in a rect with color or full screen if no color
14 15 16 17 18 19 20 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 14 def fill(color,rect=nil) if rect.nil? @screen.fill convert_color(color) else @screen.fill convert_color(color), rect end end |
#finish_drawing ⇒ Object
28 29 30 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 28 def finish_drawing() @screen.flip end |
#render_text(text, font_file, font_size, color) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 44 def render_text(text, font_file, font_size, color) @font_cache ||= {} @font_cache[font_file] ||= {} font = @font_cache[font_file][font_size] ||= TTF.new(font_file, font_size) text_image = font.render text, true, convert_color(color) end |
#size_text(text, font_file, font_size) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 36 def size_text(text, font_file, font_size) @font_cache ||= {} @font_cache[font_file] ||= {} font = @font_cache[font_file][font_size] ||= TTF.new(font_file, font_size) font.size_text text end |
#start_drawing ⇒ Object
26 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 26 def start_drawing(); end |