Module: Chingu::GFXHelpers

Included in:
GameState, Window
Defined in:
lib/chingu/gfx_helpers.rb

Overview

Various helper-methods to manipulate the screen. All drawings depend on the global variable $window which should be an instance of Gosu::Window or Chingu::Window

Instance Method Summary collapse

Instance Method Details

#fill(color) ⇒ Object

Fills whole window with color ‘color’.



33
34
35
36
37
38
39
# File 'lib/chingu/gfx_helpers.rb', line 33

def fill(color)
  $window.draw_quad(0, 0, color,
                    $window.width, 0, color,
                    $window.width, $window.height, color,
                    0, $window.height, color,
                    0, :default)
end

#fill_gradient(options) ⇒ Object

Fills window or a given rect with a gradient between two colors.

:from         - Start with this color
:to           - End with this color
:rect         - Only fill rectangle :rect with the gradient, either a Rect-instance or [x,y,width,height] Array.
:orientation  - Either :vertical (top to bottom) or :horizontal (left to right)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/chingu/gfx_helpers.rb', line 61

def fill_gradient(options)
  default_options = { :from => Gosu::Color.new(255,0,0,0),
                      :to => Gosu::Color.new(255,255,255,255), 
                      :thickness => 10, 
                      :orientation => :vertical,
                      :rect => Rect.new([0, 0, $window.width, $window.height]),
                      :zorder => 0,
                      :mode => :default
                    }
			options = default_options.merge(options)
  rect = Rect.new(options[:rect])      
  if options[:orientation] == :vertical
    $window.draw_quad(  rect.x, rect.y, options[:from],
                        rect.right, rect.y, options[:from],
                        rect.right, rect.bottom, options[:to],
                        rect.x, rect.bottom, options[:to],
                        options[:zorder], options[:mode]
                      )
  else
    $window.draw_quad(  rect.x, rect.y, options[:from],
                        rect.x, rect.bottom, options[:from],
                        rect.right, rect.bottom, options[:to],
                        rect.right, rect.y, options[:to],
                        options[:zorder], options[:mode]
                      )        
  end
end

#fill_rect(rect, color) ⇒ Object

Fills a given Rect ‘rect’ with Color ‘color’



44
45
46
47
48
49
50
51
# File 'lib/chingu/gfx_helpers.rb', line 44

def fill_rect(rect, color)
  rect = Rect.new(rect)     # Make sure it's a rect
  $window.draw_quad(  rect.x, rect.y, color,
                      rect.right, rect.y, color,
                      rect.right, rect.bottom, color,
                      rect.x, rect.bottom, color,
                      0, :default)
end