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_circle(cx, cy, radius, color) ⇒ Object
- #draw_circle_filled(cx, cy, radius, color) ⇒ Object
- #draw_image(img, to_x, to_y, color = nil) ⇒ Object
- #draw_line(x1, y1, x2, y2, color) ⇒ Object
- #draw_partial_image(img, to_x, to_y, from_x = nil, from_y = nil, from_w = nil, from_h = nil, color = nil) ⇒ Object
- #fill(x1, y1, x2, y2, color) ⇒ Object
- #fill_screen(color) ⇒ Object
- #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
34 35 36 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 34 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_circle(cx, cy, radius, color) ⇒ Object
18 19 20 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 18 def draw_circle(cx,cy,radius,color) @screen.draw_circle_a [cx,cy],radius,convert_color(color) end |
#draw_circle_filled(cx, cy, radius, color) ⇒ Object
22 23 24 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 22 def draw_circle_filled(cx,cy,radius,color) @screen.draw_circle_s [cx,cy],radius,convert_color(color) end |
#draw_image(img, to_x, to_y, color = nil) ⇒ Object
44 45 46 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 44 def draw_image(img, to_x, to_y, color=nil) img.blit @screen, [to_x,to_y] end |
#draw_line(x1, y1, x2, y2, color) ⇒ Object
13 14 15 16 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 13 def draw_line(x1,y1,x2,y2,color) c = convert_color(color) @screen.draw_line_a [x1, y1], [x2, y2], c end |
#draw_partial_image(img, to_x, to_y, from_x = nil, from_y = nil, from_w = nil, from_h = nil, color = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 48 def draw_partial_image(img, to_x, to_y, from_x=nil,from_y=nil,from_w=nil,from_h=nil, color=nil) if from_x if from_w from = [from_x,from_y,from_w,from_h] else from = [from_x,from_y] end img.blit @screen, [to_x,to_y], from else img.blit @screen, [to_x,to_y] end end |
#fill(x1, y1, x2, y2, color) ⇒ Object
30 31 32 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 30 def fill(x1,y1,x2,y2,color) @screen.draw_box_s [x1,y1], [x2,y2], convert_color(color) end |
#fill_screen(color) ⇒ Object
26 27 28 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 26 def fill_screen(color) @screen.draw_box_s [0,0], [@screen.width,@screen.height], convert_color(color) end |
#finish_drawing ⇒ Object
40 41 42 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 40 def finish_drawing() @screen.flip end |
#render_text(text, font_file, font_size, color) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 70 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
62 63 64 65 66 67 68 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 62 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
38 |
# File 'lib/rubygoo/adapters/rubygame_render_adapter.rb', line 38 def start_drawing(); end |