Color handling handed off to rcairo
parent
f47ab6f4dd
commit
c477432239
|
|
@ -2,8 +2,9 @@ module Squib
|
||||||
class Deck
|
class Deck
|
||||||
#module API
|
#module API
|
||||||
|
|
||||||
def background(range: :all, color: '#000000')
|
def background(range: :all, color: :black)
|
||||||
range = rangeify(range)
|
range = rangeify(range)
|
||||||
|
color = colorify(color)
|
||||||
range.each { |i| @cards[i].background(color) }
|
range.each { |i| @cards[i].background(color) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ module Squib
|
||||||
range = rangeify(range)
|
range = rangeify(range)
|
||||||
str = [str] * @cards.size unless str.respond_to? :each
|
str = [str] * @cards.size unless str.respond_to? :each
|
||||||
font = fontify(font)
|
font = fontify(font)
|
||||||
|
color = colorify(options[:color])
|
||||||
range.each do |i|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ module Squib
|
||||||
file
|
file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def colorify(color)
|
||||||
|
color ||= :black
|
||||||
|
color = Cairo::Color.parse(color)
|
||||||
|
color
|
||||||
|
end
|
||||||
|
|
||||||
##################
|
##################
|
||||||
### PUBLIC API ###
|
### PUBLIC API ###
|
||||||
##################
|
##################
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module Squib
|
||||||
|
|
||||||
def background(color)
|
def background(color)
|
||||||
cc = cairo_context
|
cc = cairo_context
|
||||||
cc.set_source_rgb(*color)
|
cc.set_source_color(color)
|
||||||
cc.paint
|
cc.paint
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ require 'pango'
|
||||||
module Squib
|
module Squib
|
||||||
class Card
|
class Card
|
||||||
|
|
||||||
def text(str, font, x, y, options)
|
def text(str, font, x, y, color, options)
|
||||||
cc = cairo_context
|
cc = cairo_context
|
||||||
cc.set_source_color(:black) #black
|
cc.set_source_color(color)
|
||||||
cc.move_to(x,y)
|
cc.move_to(x,y)
|
||||||
layout = cc.create_pango_layout
|
layout = cc.create_pango_layout
|
||||||
layout.text = str.to_s
|
layout.text = str.to_s
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,16 @@ require 'squib'
|
||||||
|
|
||||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||||
'level' => [1,2,3]}
|
'level' => [1,2,3]}
|
||||||
longtext = "Hello, World! What do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle."
|
|
||||||
|
|
||||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
background color: [1.0,1.0,1.0]
|
background color: :white
|
||||||
rect x: 15, y: 15, width: 795, height: 1095, x_radius: 50, y_radius: 50
|
rect x: 15, y: 15, width: 795, height: 1095, x_radius: 50, y_radius: 50
|
||||||
rect x: 30, y: 30, width: 128, height: 128, x_radius: 25, y_radius: 25
|
rect x: 30, y: 30, width: 128, height: 128, x_radius: 25, y_radius: 25
|
||||||
|
|
||||||
text str: data['name'], x: 250, y: 55, font: 'Arial 54'
|
text str: data['name'], x: 250, y: 55, font: 'Arial 54'
|
||||||
text str: data['level'], x: 65, y: 40, font: 'Arial 72'
|
text str: data['level'], x: 65, y: 40, font: 'Arial 72'
|
||||||
text str: longtext, x: 100, y: 600, font: 'Arial 16'
|
|
||||||
|
|
||||||
png file: 'shiny-purse.png', x: 665, y: 30
|
png range: [0,2], file: 'shiny-purse.png', x: 665, y: 30
|
||||||
svg range: 1..2, file: 'spanner.svg', x: 665, y: 165
|
svg range: 1..2, file: 'spanner.svg', x: 665, y: 165
|
||||||
|
|
||||||
save format: :png
|
save format: :png
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
require 'squib'
|
require 'squib'
|
||||||
|
|
||||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
background color: [1.0,1.0,1.0]
|
background color: :white
|
||||||
|
|
||||||
data = xlsx file: 'sample.xlsx', sheet: 0
|
data = xlsx file: 'sample.xlsx', sheet: 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ describe Squib::Deck do
|
||||||
it "calls text on all cards by default" do
|
it "calls text on all cards by default" do
|
||||||
card1 = instance_double(Squib::Card)
|
card1 = instance_double(Squib::Card)
|
||||||
card2 = instance_double(Squib::Card)
|
card2 = instance_double(Squib::Card)
|
||||||
expect(card1).to receive(:text).with('blah','Arial 36',0,0,{}).once
|
expect(card1).to receive(:text).once
|
||||||
expect(card2).to receive(:text).with('blah','Arial 36',0,0,{}).once
|
expect(card2).to receive(:text).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card1, card2]
|
@cards = [card1, card2]
|
||||||
text str: 'blah'
|
text str: 'blah'
|
||||||
|
|
@ -24,7 +24,7 @@ describe Squib::Deck do
|
||||||
it "calls text on some cards with an integer" do
|
it "calls text on some cards with an integer" do
|
||||||
card1 = instance_double(Squib::Card)
|
card1 = instance_double(Squib::Card)
|
||||||
card2 = instance_double(Squib::Card)
|
card2 = instance_double(Squib::Card)
|
||||||
expect(card2).to receive(:text).with('blah','Arial 36',0,0,{}).once
|
expect(card2).to receive(:text).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card1, card2]
|
@cards = [card1, card2]
|
||||||
text range: 1, str: 'blah'
|
text range: 1, str: 'blah'
|
||||||
|
|
@ -35,8 +35,8 @@ describe Squib::Deck do
|
||||||
card1 = instance_double(Squib::Card)
|
card1 = instance_double(Squib::Card)
|
||||||
card2 = instance_double(Squib::Card)
|
card2 = instance_double(Squib::Card)
|
||||||
card3 = instance_double(Squib::Card)
|
card3 = instance_double(Squib::Card)
|
||||||
expect(card1).to receive(:text).with('blah','Arial 36',0,0,{}).once
|
expect(card1).to receive(:text).once
|
||||||
expect(card2).to receive(:text).with('blah','Arial 36',0,0,{}).once
|
expect(card2).to receive(:text).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card1, card2, card3]
|
@cards = [card1, card2, card3]
|
||||||
text range: 0..1, str: 'blah'
|
text range: 0..1, str: 'blah'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue