Class: DXRubySDL::Image
- Inherits:
-
Object
- Object
- DXRubySDL::Image
- Includes:
- Color
- Defined in:
- lib/dxruby_sdl/image.rb
Instance Attribute Summary collapse
-
#_surface ⇒ Object
readonly
Returns the value of attribute _surface.
Class Method Summary collapse
Instance Method Summary collapse
- #box(x1, y1, x2, y2, color) ⇒ Object
- #circle(x, y, r, color) ⇒ Object
- #height ⇒ Object
-
#initialize(width, height, color = [0, 0, 0, 0]) ⇒ Image
constructor
A new instance of Image.
- #line(x1, y1, x2, y2, color) ⇒ Object
- #width ⇒ Object
Methods included from Color
Constructor Details
#initialize(width, height, color = [0, 0, 0, 0]) ⇒ Image
Returns a new instance of Image.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dxruby_sdl/image.rb', line 9 def initialize(width, height, color = [0, 0, 0, 0]) @color = color if width == 0 && height == 0 return end @_surface = SDL::Surface.new(SDL::SWSURFACE, width, height, Window._screen) @_surface.fill_rect(0, 0, width, height, @color) end |
Instance Attribute Details
#_surface ⇒ Object (readonly)
Returns the value of attribute _surface.
7 8 9 |
# File 'lib/dxruby_sdl/image.rb', line 7 def _surface @_surface end |
Class Method Details
.load(filename, x = nil, y = nil, width = nil, height = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/dxruby_sdl/image.rb', line 47 def self.load(filename, x = nil, y = nil, width = nil, height = nil) image = new(0, 0) surface = SDL::Surface.load(filename) image.instance_variable_set('@_surface', surface) return image end |
Instance Method Details
#box(x1, y1, x2, y2, color) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/dxruby_sdl/image.rb', line 39 def box(x1, y1, x2, y2, color) x = x1 < x2 ? x1 : x2 w = (x2 - x1).abs y = y1 < y2 ? y1 : y2 h = (y2 - y1).abs @_surface.draw_rect(x, y, w, h, to_sdl_color(color)) end |
#circle(x, y, r, color) ⇒ Object
34 35 36 37 |
# File 'lib/dxruby_sdl/image.rb', line 34 def circle(x, y, r, color) @_surface.draw_circle(x, y, r, to_sdl_color(color), false, true, to_sdl_alpha(color)) end |
#height ⇒ Object
25 26 27 |
# File 'lib/dxruby_sdl/image.rb', line 25 def height return @_surface.h end |
#line(x1, y1, x2, y2, color) ⇒ Object
29 30 31 32 |
# File 'lib/dxruby_sdl/image.rb', line 29 def line(x1, y1, x2, y2, color) @_surface.draw_line(x1, y1, x2, y2, to_sdl_color(color), true, to_sdl_alpha(color)) end |
#width ⇒ Object
21 22 23 |
# File 'lib/dxruby_sdl/image.rb', line 21 def width return @_surface.w end |