Color handling handed off to rcairo

This commit is contained in:
Andy Meneely
2014-07-17 13:11:26 -04:00
parent f47ab6f4dd
commit c477432239
8 changed files with 22 additions and 16 deletions
+2 -1
View File
@@ -2,8 +2,9 @@ module Squib
class Deck
#module API
def background(range: :all, color: '#000000')
def background(range: :all, color: :black)
range = rangeify(range)
color = colorify(color)
range.each { |i| @cards[i].background(color) }
end
+2 -1
View File
@@ -17,8 +17,9 @@ module Squib
range = rangeify(range)
str = [str] * @cards.size unless str.respond_to? :each
font = fontify(font)
color = colorify(options[:color])
range.each do |i|
cards[i].text(str[i], font, x, y, options)
cards[i].text(str[i], font, x, y, color, options)
end
end
+6
View File
@@ -38,6 +38,12 @@ module Squib
file
end
def colorify(color)
color ||= :black
color = Cairo::Color.parse(color)
color
end
##################
### PUBLIC API ###
##################
+1 -1
View File
@@ -3,7 +3,7 @@ module Squib
def background(color)
cc = cairo_context
cc.set_source_rgb(*color)
cc.set_source_color(color)
cc.paint
end
+3 -3
View File
@@ -3,14 +3,14 @@ require 'pango'
module Squib
class Card
def text(str, font, x, y, options)
def text(str, font, x, y, color, options)
cc = cairo_context
cc.set_source_color(:black) #black
cc.set_source_color(color)
cc.move_to(x,y)
layout = cc.create_pango_layout
layout.text = str.to_s
w = options[:width] ; h = options[:height]
w ||= (@width - 2*x) ; h ||= (@height - 2*y) # default centers to x,y
w ||= (@width - 2*x); h ||= (@height - 2*y) # default centers to x,y
w *= Pango::SCALE ; h *= Pango::SCALE
layout.width=w ; layout.height=h
layout.wrap = Pango::WRAP_WORD