9 changed files with 183 additions and 43 deletions
@ -0,0 +1,9 @@
|
||||
module Squib |
||||
class Deck |
||||
|
||||
def hint(text: nil) |
||||
@text_hint = colorify(text, nillable: true) |
||||
end |
||||
|
||||
end |
||||
end |
||||
@ -0,0 +1,38 @@
|
||||
module Squib |
||||
module InputHelpers |
||||
|
||||
def rangeify (range) |
||||
range = 0..(@cards.size-1) if range == :all |
||||
range = range..range if range.is_a? Integer |
||||
if range.max > (@cards.size-1) |
||||
raise "#{range} is outside of deck range of 0..#{@card.size-1}" |
||||
end |
||||
return range |
||||
end |
||||
module_function :rangeify |
||||
|
||||
def fileify(file) |
||||
raise 'File #{file} does not exist!' unless File.exists? file |
||||
file |
||||
end |
||||
module_function :fileify |
||||
|
||||
def colorify(color, nillable: false) |
||||
if nillable # for optional color arguments like text hints |
||||
color = Cairo::Color.parse(color) unless color.nil? |
||||
else |
||||
color ||= :black |
||||
color = Cairo::Color.parse(color) |
||||
end |
||||
color |
||||
end |
||||
module_function :colorify |
||||
|
||||
def fontify (font) |
||||
font = 'Arial 36' if font==:use_set |
||||
font |
||||
end |
||||
module_function :fontify |
||||
|
||||
end |
||||
end |
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env ruby |
||||
require 'squib' |
||||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'], |
||||
'level' => [1,2,3]} |
||||
longtext = "This is left-justified text centered on the card based on x and y.\nWhat 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: 128) do |
||||
background color: :white |
||||
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 |
||||
|
||||
text str: data['name'], x: 250, y: 55, font: 'Arial 54' |
||||
text str: data['level'], x: 65, y: 40, font: 'Arial 72', color: :burnt_orange |
||||
|
||||
text str: "This text has a hint, fixed width, and fixed height", |
||||
hint: :red, |
||||
x: 65, y: 400, |
||||
width: 300, height: 200, |
||||
font: 'Arial 24' |
||||
|
||||
text str: "Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42", |
||||
hint: :green, font: 'Arial 22', |
||||
x: 450, y: 400, |
||||
width: 280, height: 180, |
||||
ellipsize: true |
||||
|
||||
hint text: :cyan |
||||
text str: "Text hints are also globally togglable!", |
||||
x: 65, y: 625, |
||||
font: 'Arial 22' |
||||
hint text: nil |
||||
text str: "See? No hint here.", |
||||
x: 565, y: 625, |
||||
font: 'Arial 22' |
||||
|
||||
text str: longtext, font: 'Arial 16', |
||||
x: 65, y: 700, |
||||
fitxy: true, justify: true |
||||
|
||||
text str: "<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome", |
||||
markup: true, |
||||
x: 50, y: 1000, |
||||
font: 'Arial 32' |
||||
|
||||
save prefix: 'text_', format: :png |
||||
end |
||||
|
||||
puts "Done!" |
||||
|
||||
|
||||
Loading…
Reference in new issue