8 changed files with 90 additions and 34 deletions
@ -1,11 +1,12 @@ |
|||||||
#!/usr/bin/env ruby |
#!/usr/bin/env ruby |
||||||
|
|
||||||
require 'squib' |
require 'squib' |
||||||
|
|
||||||
deck width: 825, height: 1125, 3 |
deck width: 825, height: 1125, cards: 3 |
||||||
|
|
||||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'], |
data = {'name' => ['Thief', 'Grifter', 'Mastermind'], |
||||||
'level' => [1,2,3]} |
'level' => [1,2,3]} |
||||||
|
|
||||||
text str: data['name'], x: 10, y: 250 |
text str: data['name'], x: 10, y: 250 |
||||||
text str: data['level'], x: 10, y:10 |
text str: data['level'], x: 10, y:10 |
||||||
|
|
||||||
|
save format: :png |
||||||
@ -1,46 +1,58 @@ |
|||||||
require 'squib/commands/text_cmd' |
require 'squib/graphics/text' |
||||||
|
require 'squib/graphics/save' |
||||||
|
require 'squib/deck' |
||||||
|
require 'squib/card' |
||||||
|
require 'singleton' |
||||||
|
|
||||||
class Squib |
module Squib |
||||||
attr_accessor :the_deck |
@@the_deck = nil |
||||||
|
|
||||||
|
def self.the_deck=(d) |
||||||
|
@@the_deck = d |
||||||
|
end |
||||||
|
|
||||||
|
def self.the_deck |
||||||
|
@@the_deck |
||||||
|
end |
||||||
end |
end |
||||||
|
|
||||||
################## |
################## |
||||||
### PUBLIC API ### |
### PUBLIC API ### |
||||||
################## |
################## |
||||||
|
|
||||||
def deck(width:, height:, cards: 1) |
def deck(width: , height: , cards: 1) |
||||||
Squib.the_deck = Deck.new(width, height, cards) |
Squib::the_deck = Squib::Deck.new(width, height, cards) |
||||||
end |
end |
||||||
|
|
||||||
def font(type: , size: 12, **options) |
def font(type: , size: 12, **options) |
||||||
Font.new() |
|
||||||
end |
end |
||||||
|
|
||||||
def set_font(type: 'Arial', size: 12, **options) |
def set_font(type: 'Arial', size: 12, **options) |
||||||
Squib::queue_command Squib::Commands::SetFont.new(type,size,options) |
Squib::queue_command Squib::Graphics::SetFont.new(type,size,options) |
||||||
end |
end |
||||||
|
|
||||||
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 = 0..cards-1 if range == :all |
deck = Squib::the_deck |
||||||
str = [str] * cards unless str.respond_to? :each |
range = 0..(deck.num_cards-1) if range == :all |
||||||
#TODO define a singleton or something for the deck we're working on. |
str = [str] * deck.num_cards unless str.respond_to? :each |
||||||
str.each{ |s| Squib::Graphics::Text.new(card, s, font, x, y, options) } |
range.each do |i| |
||||||
|
Squib::Graphics::Text.new(deck[i], str[i], font, x, y, options).execute |
||||||
end |
end |
||||||
end |
end |
||||||
|
|
||||||
def image(range=:all, file: , x: 0, y: 0) |
def image(range=:all, file: , x: 0, y: 0) |
||||||
end |
end |
||||||
|
|
||||||
|
def rect(x: , y: width: , height: , x_radius: 0, y_radius: 0) |
||||||
|
|
||||||
|
end |
||||||
|
|
||||||
def load_csv(file:, header: true) |
def load_csv(file:, header: true) |
||||||
end |
end |
||||||
|
|
||||||
def data(field) |
def data(field) |
||||||
end |
end |
||||||
|
|
||||||
def render |
def save(format: :png) |
||||||
vv = VerifyVisitor.new |
Squib::Graphics::Save.new(format).execute |
||||||
CMDS.each do |cmd| |
|
||||||
cmd.accept(vv) |
|
||||||
end |
|
||||||
end |
end |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
module Squib |
||||||
|
module Graphics |
||||||
|
|
||||||
|
class Save |
||||||
|
def initialize(format) |
||||||
|
@format = format |
||||||
|
end |
||||||
|
|
||||||
|
def execute |
||||||
|
puts "Here!" |
||||||
|
Squib.the_deck.each_with_index do |card, i| |
||||||
|
card.cairo_context.target.write_to_png("_img/img_#{i}.png") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
module Squib |
||||||
|
module Graphics |
||||||
|
|
||||||
|
class Text |
||||||
|
def initialize(card, str, font, x, y, options) |
||||||
|
@card=card |
||||||
|
@str=str |
||||||
|
@font=font |
||||||
|
@x=x; @y=y |
||||||
|
end |
||||||
|
|
||||||
|
def execute |
||||||
|
cc = @card.cairo_context |
||||||
|
cc.set_source_rgb(0.0,0.0,0.0) |
||||||
|
cc.select_font_face ("Helvetica"); |
||||||
|
cc.set_font_size(36) |
||||||
|
cc.move_to(@x,@y) |
||||||
|
cc.show_text(@str.to_s) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue