Class: Squib::Graphics::CairoContextWrapper
- Inherits:
-
Object
- Object
- Squib::Graphics::CairoContextWrapper
- Extended by:
- Forwardable
- Defined in:
- lib/squib/graphics/cairo_context_wrapper.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(cairo_cxt) ⇒ CairoContextWrapper
constructor
A new instance of CairoContextWrapper.
- #set_source_squibcolor(arg) ⇒ Object
Constructor Details
#initialize(cairo_cxt) ⇒ CairoContextWrapper
Returns a new instance of CairoContextWrapper.
10 11 12 |
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 10 def initialize(cairo_cxt) @cairo_cxt = cairo_cxt end |
Instance Attribute Details
#cairo_cxt ⇒ Object
8 9 10 |
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 8 def cairo_cxt @cairo_cxt end |
Instance Method Details
#set_source_squibcolor(arg) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/squib/graphics/cairo_context_wrapper.rb', line 20 def set_source_squibcolor(arg) if match = arg.match(LINEAR_GRADIENT) x1, y1, x2, y2 = match.captures linear = Cairo::LinearPattern.new(x1.to_f, y1.to_f, x2.to_f, y2.to_f) arg.scan(STOPS).each do |color, offset| linear.add_color_stop(offset.to_f, color) end @cairo_cxt.set_source(linear) elsif match = arg.match(RADIAL_GRADIENT) x1, y1, r1, x2, y2, r2 = match.captures linear = Cairo::RadialPattern.new(x1.to_f, y1.to_f, r1.to_f, x2.to_f, y2.to_f, r2.to_f) arg.scan(STOPS).each do |color, offset| linear.add_color_stop(offset.to_f, color) end @cairo_cxt.set_source(linear) else @cairo_cxt.set_source_color(arg) end end |