Massive rewrite to use DSL conventions

This commit is contained in:
Andy Meneely
2014-07-16 10:39:10 -04:00
parent c2f1a9673b
commit b001da7ba3
18 changed files with 163 additions and 179 deletions
+6 -12
View File
@@ -1,17 +1,11 @@
module Squib
module Graphics
class Card
class Background
def initialize(card, color)
@card=card; @color=color
end
def execute
cc = @card.cairo_context
cc.set_source_rgb(*@color)
cc.paint
end
def background(color)
cc = cairo_context
cc.set_source_rgb(*color)
cc.paint
end
end
end
-21
View File
@@ -1,21 +0,0 @@
module Squib
module Graphics
class Rectangle
def initialize(card, x, y, width, height, x_radius, y_radius)
@card=card; @x=x; @y=y; @width=width; @height=height
@x_radius=x_radius; @y_radius=y_radius
end
def execute
cc = @card.cairo_context
cc.set_source_rgb(0.0,0.0,0.0)
cc.rounded_rectangle(@x, @y, @width, @height, @x_radius, @y_radius)
cc.stroke
end
end
end
end
+14 -20
View File
@@ -1,25 +1,19 @@
module Squib
module Graphics
class SaveDoc
def initialize(format)
@format = format
end
class Deck
def execute
#paper is 8.5x11
# PDF points are 1/72 of an inch
width = 8.5 * 72
height = 11 * 72
cc = Cairo::Context.new(Cairo::PDFSurface.new('_img/deck.pdf', width, height))
x = 10
y = 10
Squib.the_deck.each_with_index do |card, i|
cc.move_to(x,y)
x += 825*i
cc.set_source(card.cairo_surface, 0, 300)
cc.paint
end
def save_pdf
#paper is 8.5x11
# PDF points are 1/72 of an inch
width = 8.5 * 72
height = 11 * 72
cc = Cairo::Context.new(Cairo::PDFSurface.new('_img/deck.pdf', width, height))
x = 10
y = 10
@cards.each_with_index do |card, i|
cc.move_to(x,y)
x += 825*i
cc.set_source(card.cairo_surface, 0, 300)
cc.paint
end
end
+3 -11
View File
@@ -1,16 +1,8 @@
module Squib
module Graphics
class Card
class SaveImages
def initialize(format)
@format = format
end
def execute
Squib.the_deck.each_with_index do |card, i|
card.cairo_context.target.write_to_png("_img/img_#{i}.png")
end
end
def save_png(i, dir: '_img')
cairo_context.target.write_to_png("#{dir}/img_#{i}.png")
end
end
+12
View File
@@ -0,0 +1,12 @@
module Squib
class Card
def draw_rectangle(x, y, width, height, x_radius, y_radius)
cc = cairo_context
cc.set_source_rgb(0.0,0.0,0.0)
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
cc.stroke
end
end
end
+9 -18
View File
@@ -1,22 +1,13 @@
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.text_extents(@str.to_s).height)
cc.show_text(@str.to_s)
end
class Card
def text(str, font, x, y, options)
cc = 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.text_extents(@str.to_s).height)
cc.show_text(str.to_s)
end
end