Browse Source

Adding in a png method

dev
Andy Meneely 12 years ago
parent
commit
6c1d32a8cd
  1. 4
      lib/squib/api/image.rb
  2. 1
      lib/squib/card.rb
  3. 5
      lib/squib/deck.rb
  4. 12
      lib/squib/graphics/image.rb
  5. 6
      samples/basic.rb
  6. BIN
      samples/shiny-purse.png

4
lib/squib/api/image.rb

@ -2,7 +2,9 @@ module Squib
class Deck
def png(range=:all, file: nil, x: 0, y: 0)
raise 'Not implemented!'
range = rangeify(range)
file = fileify(file)
range.each{ |i| @cards[i].png(file, x, y) }
end
end

1
lib/squib/card.rb

@ -16,6 +16,7 @@ module Squib
### BACKEND GRAPHICS ###
########################
require 'squib/graphics/background'
require 'squib/graphics/image'
require 'squib/graphics/save_doc'
require 'squib/graphics/save_images'
require 'squib/graphics/shapes'

5
lib/squib/deck.rb

@ -30,6 +30,11 @@ module Squib
return range
end
def fileify(file)
raise 'File #{file} does not exist!' unless File.exists? file
file
end
##################
### PUBLIC API ###
##################

12
lib/squib/graphics/image.rb

@ -0,0 +1,12 @@
module Squib
class Card
def png(file, x, y)
cc = cairo_context
png = Cairo::ImageSurface.from_png(file)
cc.set_source(png, x, y)
cc.paint
end
end
end

6
samples/basic.rb

@ -8,12 +8,14 @@ longtext = "Hello, World! What do you know about tweetle beetles? well... \nWhen
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
background color: [1.0,1.0,1.0]
rect x: 15, y: 15, width: 795, height: 1095, x_radius: 50, y_radius: 50
rect x: 30, y: 30, width: 150, height: 150, 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['level'], x: 75, y: 50, 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
save format: :png
end

BIN
samples/shiny-purse.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Loading…
Cancel
Save