Better default handling, more samples
parent
9da4d0a499
commit
06cf063126
|
|
@ -8,6 +8,12 @@ module Squib
|
||||||
raise 'Not implemented!'
|
raise 'Not implemented!'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# font: description string, including family, styles, and size.
|
||||||
|
#
|
||||||
|
# => e.g. 'Arial bold italic 12'
|
||||||
|
# For the official documentation the string, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
|
||||||
|
# This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
|
||||||
def text(range: :all, str: '', font: :use_set, x: 0, y: 0, **options)
|
def text(range: :all, str: '', font: :use_set, x: 0, y: 0, **options)
|
||||||
range = rangeify(range)
|
range = rangeify(range)
|
||||||
str = [str] * @cards.size unless str.respond_to? :each
|
str = [str] * @cards.size unless str.respond_to? :each
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
module Squib
|
||||||
|
module Constants
|
||||||
|
|
||||||
|
DEFAULT_FONT = 'Arial 36'
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
require 'squib/card'
|
require 'squib/card'
|
||||||
require 'squib/input_helpers'
|
require 'squib/input_helpers'
|
||||||
|
require 'squib/constants'
|
||||||
|
|
||||||
module Squib
|
module Squib
|
||||||
class Deck
|
class Deck
|
||||||
include Enumerable
|
include Enumerable
|
||||||
include Squib::InputHelpers
|
include Squib::InputHelpers
|
||||||
|
include Squib::Constants
|
||||||
attr_reader :width, :height
|
attr_reader :width, :height
|
||||||
attr_reader :cards
|
attr_reader :cards
|
||||||
attr_reader :text_hint
|
attr_reader :text_hint
|
||||||
|
|
||||||
def initialize(width: 825, height: 1125, cards: 1, &block)
|
def initialize(width: 825, height: 1125, cards: 1, &block)
|
||||||
@width=width; @height=height
|
@width=width; @height=height
|
||||||
|
@font = 'Sans 36'
|
||||||
@cards = []
|
@cards = []
|
||||||
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
||||||
if block_given?
|
if block_given?
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ module Squib
|
||||||
module_function :colorify
|
module_function :colorify
|
||||||
|
|
||||||
def fontify (font)
|
def fontify (font)
|
||||||
font = 'Arial 36' if font==:use_set
|
font = @font if font==:use_set
|
||||||
|
font = Squib::DEFAULT_FONT if font==:default
|
||||||
font
|
font
|
||||||
end
|
end
|
||||||
module_function :fontify
|
module_function :fontify
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,25 @@ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||||
'level' => [1,2,3]}
|
'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."
|
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
|
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
background color: :white
|
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 weight=900 54'
|
||||||
text str: data['level'], x: 65, y: 40, font: 'Arial 72', color: :burnt_orange
|
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",
|
text str: "Font strings are expressive!", x:65, y: 200,
|
||||||
|
font: 'Impact bold italic 36'
|
||||||
|
|
||||||
|
text str: "Font strings are expressive!", x:65, y: 300,
|
||||||
|
font: 'Arial,Verdana weight=900 style=oblique 36'
|
||||||
|
|
||||||
|
text str: "This text has fixed width, fixed height, center-aligned, and has a red hint",
|
||||||
hint: :red,
|
hint: :red,
|
||||||
x: 65, y: 400,
|
x: 65, y: 400,
|
||||||
width: 300, height: 200,
|
width: 300, height: 200,
|
||||||
|
align: :center,
|
||||||
font: 'Arial 24'
|
font: 'Arial 24'
|
||||||
|
|
||||||
text str: "Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42",
|
text str: "Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue