Color handling handed off to rcairo
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -38,6 +38,12 @@ module Squib
|
||||
file
|
||||
end
|
||||
|
||||
def colorify(color)
|
||||
color ||= :black
|
||||
color = Cairo::Color.parse(color)
|
||||
color
|
||||
end
|
||||
|
||||
##################
|
||||
### PUBLIC API ###
|
||||
##################
|
||||
|
||||
@@ -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,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
|
||||
|
||||
Reference in New Issue
Block a user