Class: Rubygoo::GosuRenderAdapter
- Inherits:
-
Object
- Object
- Rubygoo::GosuRenderAdapter
- Defined in:
- lib/rubygoo/adapters/gosu_render_adapter.rb
Constant Summary collapse
- CIRCLE_STEP =
10
Instance Method Summary collapse
- #convert_color(goo_color) ⇒ Object
- #draw_box(x1, y1, x2, y2, color) ⇒ Object
- #draw_circle(cx, cy, r, color) ⇒ Object
- #draw_circle_filled(cx, cy, r, color) ⇒ Object
- #draw_image(img, x, 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
untested in Gosu.
- #fill(x1, y1, x2, y2, color) ⇒ Object
- #fill_screen(color) ⇒ Object
- #finish_drawing ⇒ Object
-
#initialize(window) ⇒ GosuRenderAdapter
constructor
A new instance of GosuRenderAdapter.
- #render_text(text, font_file, font_size, color) ⇒ Object
- #size_text(text, font_file, font_size) ⇒ Object
- #start_drawing ⇒ Object
Constructor Details
#initialize(window) ⇒ GosuRenderAdapter
Returns a new instance of GosuRenderAdapter.
17 18 19 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 17 def initialize(window) @window = window end |
Instance Method Details
#convert_color(goo_color) ⇒ Object
63 64 65 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 63 def convert_color(goo_color) Gosu::Color.new goo_color.a,goo_color.r,goo_color.g,goo_color.b end |
#draw_box(x1, y1, x2, y2, color) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 21 def draw_box(x1,y1,x2,y2,color) c = convert_color(color) @window.draw_line x1, y1, c, x2, y1, c @window.draw_line x2, y1, c, x2, y2, c @window.draw_line x2, y2, c, x1, y2, c @window.draw_line x1, y2, c, x1, y1, c end |
#draw_circle(cx, cy, r, color) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 35 def draw_circle(cx,cy,r,color) c_color = convert_color(color) 0.step(360, CIRCLE_STEP) { |a1| a2 = a1 + CIRCLE_STEP @window.draw_line cx + offset_x(a1, r), cy + offset_y(a1, r), c_color, cx + offset_x(a2, r), cy + offset_y(a2, r), c_color, 0 } end |
#draw_circle_filled(cx, cy, r, color) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 44 def draw_circle_filled(cx,cy,r,color) c_color = convert_color(color) 0.step(360, CIRCLE_STEP) { |a1| a2 = a1 + CIRCLE_STEP @window.draw_triangle cx + offset_x(a1, r), cy + offset_y(a1, r), c_color, cx + offset_x(a2, r), cy + offset_y(a2, r), c_color, cx, cy, c_color, 0 } end |
#draw_image(img, x, y, color = nil) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 71 def draw_image(img, x, y, color=nil) # z is unused here if color img.draw x, y, 0,1,1,convert_color(color) else img.draw x, y, 0 end end |
#draw_line(x1, y1, x2, y2, color) ⇒ Object
29 30 31 32 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 29 def draw_line(x1,y1,x2,y2,color) c = convert_color(color) @window.draw_line x1, y1, c, x1, 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
untested in Gosu
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 81 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] image = Image.new @screen, img, false, from else raise "not supported in gosu" end image.draw x, y, 0 else draw_image img,to_x,to_y,color end end |
#fill(x1, y1, x2, y2, color) ⇒ Object
58 59 60 61 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 58 def fill(x1,y1,x2,y2,color) c = convert_color(color) @window.draw_quad x1, y1, c, x2, y1, c, x1, y2, c, x2, y2, c end |
#fill_screen(color) ⇒ Object
53 54 55 56 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 53 def fill_screen(color) c = convert_color(color) @window.draw_quad 0, 0, c, @window.width, 0, c, 0, @window.height, c, @window.width, @window.height, c end |
#finish_drawing ⇒ Object
69 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 69 def finish_drawing(); end |
#render_text(text, font_file, font_size, color) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 105 def render_text(text, font_file, font_size, color) @font_cache ||= {} @font_cache[font_file] ||= {} font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size) # TODO how do you set the color here? # text_image = Image.from_text(@window, text, font_file, font_size, 2, font.text_width(text).ceil, :left) DelayedText.new font, text # text_image = font.draw(text, 0, 0, 1) end |
#size_text(text, font_file, font_size) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 97 def size_text(text, font_file, font_size) @font_cache ||= {} @font_cache[font_file] ||= {} font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size) return [font.text_width(text),font.height] end |
#start_drawing ⇒ Object
67 |
# File 'lib/rubygoo/adapters/gosu_render_adapter.rb', line 67 def start_drawing(); end |