Class: Scruffy::Components::Background

Inherits:
Base
  • Object
show all
Defined in:
lib/scruffy/components/background.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #options, #position, #size, #visible

Instance Method Summary collapse

Methods inherited from Base

#initialize, #process, #render

Constructor Details

This class inherits a constructor from Scruffy::Components::Base

Instance Method Details

#draw(svg, bounds, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scruffy/components/background.rb', line 4

def draw(svg, bounds, options={})
  fill = "#EEEEEE"
  case options[:theme].background
  when Symbol, String
    fill = options[:theme].background.to_s
  when Array
    fill = "url(#BackgroundGradient)"
    svg.defs {
      svg.linearGradient(:id=>'BackgroundGradient', :x1 => '0%', :y1 => '0%', :x2 => '0%', :y2 => '100%') {
        svg.stop(:offset => '5%', 'stop-color' => options[:theme].background[0])
        svg.stop(:offset => '95%', 'stop-color' => options[:theme].background[1])
      }
    }
  end
  
  # Render background (maybe)
  svg.rect(:width => bounds[:width], :height => bounds[:height], :x => "0", :y => "0", :fill => fill) unless fill.nil?
end