texplay 0.2.981-i386-mswin32 → 0.2.983pre1-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.markdown +1 -1
- data/Rakefile +11 -2
- data/examples/example_blank.rb +19 -2
- data/examples/example_select.rb +25 -17
- data/examples/example_select2.rb +28 -0
- data/examples/example_splice.rb +2 -2
- data/examples/example_tiles.rb +1 -1
- data/examples/example_window_to_blob.rb +39 -0
- data/lib/1.8/texplay.so +0 -0
- data/lib/1.9/texplay.so +0 -0
- data/lib/texplay.rb +34 -12
- data/lib/texplay/patches.rb +4 -0
- data/lib/texplay/version.rb +1 -1
- data/spec/image_spec.rb +7 -0
- data/spec/texplay_spec.rb +80 -0
- metadata +16 -9
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
*27/9/10
|
2
|
+
version 0.2.983pre1
|
3
|
+
* added Window#to_blob(x,y,width,height), grab a screenshot region
|
4
|
+
*24/9/10
|
5
|
+
version 0.2.982pre1
|
6
|
+
* added :default drawing mode (equivalent to :mode => nil)
|
7
|
+
* changed Linux texture size to 512
|
8
|
+
|
1
9
|
16/8/10
|
2
10
|
version 0.2.981
|
3
11
|
* oops, added :caching => false to TexPlay#dup
|
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..')
|
1
2
|
|
2
3
|
require 'rake/clean'
|
3
4
|
require 'rake/gempackagetask'
|
@@ -57,12 +58,20 @@ specification = Gem::Specification.new do |s|
|
|
57
58
|
s.has_rdoc = false
|
58
59
|
|
59
60
|
s.files = ["Rakefile", "README.markdown", "CHANGELOG",
|
60
|
-
"lib/texplay.rb", "lib/texplay-contrib.rb",
|
61
|
+
"lib/texplay.rb", "lib/texplay-contrib.rb",
|
62
|
+
"lib/texplay/version.rb",
|
63
|
+
"lib/texplay/patches.rb",
|
64
|
+
"lib/1.8/texplay.so",
|
61
65
|
"lib/1.9/texplay.so"] +
|
62
|
-
FileList["examples/*.rb", "examples/media/*"].to_a
|
66
|
+
FileList["examples/*.rb", "examples/media/*", "spec/*.rb"].to_a
|
63
67
|
end
|
64
68
|
|
65
69
|
Rake::GemPackageTask.new(specification) do |package|
|
66
70
|
package.need_zip = false
|
67
71
|
package.need_tar = false
|
68
72
|
end
|
73
|
+
|
74
|
+
desc "Run rspec 2.0"
|
75
|
+
task :rspec do
|
76
|
+
system "rspec spec/**/*_spec.rb"
|
77
|
+
end
|
data/examples/example_blank.rb
CHANGED
@@ -7,11 +7,28 @@ require 'texplay'
|
|
7
7
|
class W < Gosu::Window
|
8
8
|
def initialize
|
9
9
|
super(500, 500, false, 20)
|
10
|
-
@img = TexPlay.create_image(self,
|
10
|
+
@img = TexPlay.create_image(self, 50, 50, :color => Gosu::Color::BLUE)
|
11
|
+
@img2 = TexPlay.create_image(self, 50, 50, :color => Gosu::Color::RED)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
|
11
17
|
end
|
12
18
|
|
13
19
|
def draw
|
14
|
-
@img.draw
|
20
|
+
@img.draw 0, 0,1
|
21
|
+
@img2.draw 100, 100,1
|
22
|
+
if button_down?(Gosu::KbEscape)
|
23
|
+
# self.flush
|
24
|
+
@blob = self.to_blob(0,self.height - 70, 50, 50)
|
25
|
+
if @blob
|
26
|
+
@img3 = TexPlay.from_blob(self, @blob,50, 50 )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@img3.draw rand(300), rand(300), 1 if @img3
|
31
|
+
500000.times {}
|
15
32
|
end
|
16
33
|
|
17
34
|
end
|
data/examples/example_select.rb
CHANGED
@@ -5,26 +5,34 @@ require 'texplay'
|
|
5
5
|
|
6
6
|
|
7
7
|
class W < Gosu::Window
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
def initialize
|
9
|
+
super(500, 500, false, 20)
|
10
|
+
|
11
|
+
# draw a filled rect with left region blue, and right region red
|
12
|
+
# at top and yellow at bottom
|
13
|
+
@img = TexPlay.create_image(self, 500, 500, :color => Gosu::Color::BLUE)
|
14
|
+
@img.rect 250,0, 500, 500, :color => :red, :fill => true
|
15
|
+
@img.rect 250, 250, 500, 500, :color => :yellow, :fill => true
|
16
|
+
|
17
|
+
# base rect is green on left and purple on right
|
18
|
+
@base = TexPlay.create_image(self, 500, 500, :color => :green)
|
19
|
+
@base.rect 250,0, 500, 500, :color => :purple, :fill => true
|
20
|
+
|
21
|
+
# splice @img into @base, and select the yellow part of @img to
|
22
|
+
# go into the purple part of @base
|
23
|
+
# a combination of source_select
|
24
|
+
# and dest_select - filtering both source and destination pixels
|
25
|
+
@base.splice @img, 0, 0, :dest_select => :purple, :source_select => :yellow
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
@base.draw 0, 0,1
|
31
|
+
end
|
18
32
|
|
19
|
-
end
|
20
|
-
|
21
|
-
def draw
|
22
|
-
@img.draw 100, 50,1
|
23
|
-
end
|
24
|
-
|
25
33
|
end
|
26
34
|
|
27
35
|
|
28
36
|
w = W.new
|
29
37
|
w.show
|
30
|
-
|
38
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'common'
|
4
|
+
require 'gosu'
|
5
|
+
require 'texplay'
|
6
|
+
require 'benchmark'
|
7
|
+
|
8
|
+
|
9
|
+
class W < Gosu::Window
|
10
|
+
def initialize
|
11
|
+
super(500, 500, false, 20)
|
12
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
13
|
+
@maria = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
|
14
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
15
|
+
@img.splice @maria, 0, 0, :tolerance => 0.70, :source_select => [:brown,:yellow], :crop => [200, 50, 500, 800]
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def draw
|
20
|
+
@img.draw 0, 0,1
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
w = W.new
|
27
|
+
w.show
|
28
|
+
|
data/examples/example_splice.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'rubygems'
|
3
|
-
require 'common'
|
3
|
+
require './common'
|
4
4
|
require 'texplay'
|
5
5
|
|
6
6
|
|
@@ -10,7 +10,7 @@ class W < Gosu::Window
|
|
10
10
|
@img = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
11
11
|
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
12
12
|
|
13
|
-
@img.splice @gosu, 140,20, :alpha_blend => true
|
13
|
+
@img.splice @gosu, 140,20, :alpha_blend => true, :mode => :default
|
14
14
|
@img.rect 140,20, 160, 180, :color => [1,1,1,0.5], :alpha_blend => true, :fill => true
|
15
15
|
|
16
16
|
@img.splice @gosu, 50,20, :chroma_key => :alpha
|
data/examples/example_tiles.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
|
7
|
+
class W < Gosu::Window
|
8
|
+
def initialize
|
9
|
+
super(500, 500, false, 20)
|
10
|
+
@img = TexPlay.create_image(self, 50, 50, :color => Gosu::Color::BLUE)
|
11
|
+
@img2 = TexPlay.create_image(self, 50, 50, :color => Gosu::Color::RED)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def draw
|
20
|
+
@img.draw 0, 0,1
|
21
|
+
@img2.draw 100, 100,1
|
22
|
+
if button_down?(Gosu::KbEscape)
|
23
|
+
# self.flush
|
24
|
+
@blob = self.to_blob(0,self.height - 70, 50, 50)
|
25
|
+
if @blob
|
26
|
+
@img3 = TexPlay.from_blob(self, @blob,50, 50 )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@img3.draw rand(300), rand(300), 1 if @img3
|
31
|
+
500000.times {}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
w = W.new
|
38
|
+
w.show
|
39
|
+
|
data/lib/1.8/texplay.so
CHANGED
Binary file
|
data/lib/1.9/texplay.so
CHANGED
Binary file
|
data/lib/texplay.rb
CHANGED
@@ -12,6 +12,7 @@ direc = File.dirname(__FILE__)
|
|
12
12
|
require 'rbconfig'
|
13
13
|
require 'gosu'
|
14
14
|
require "#{direc}/texplay/version"
|
15
|
+
require "#{direc}/texplay/patches"
|
15
16
|
|
16
17
|
module TexPlay
|
17
18
|
class << self
|
@@ -35,6 +36,8 @@ module TexPlay
|
|
35
36
|
:color => :alpha,
|
36
37
|
:caching => false,
|
37
38
|
}.merge!(options)
|
39
|
+
|
40
|
+
raise ArgumentError, "Height and width must be positive" if height <= 0 or width <= 0
|
38
41
|
|
39
42
|
img = Gosu::Image.new(window, EmptyImageStub.new(width, height), :caching => options[:caching])
|
40
43
|
img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true
|
@@ -44,6 +47,23 @@ module TexPlay
|
|
44
47
|
|
45
48
|
alias_method :create_blank_image, :create_image
|
46
49
|
|
50
|
+
# Image can be :tileable, but it will break if it is tileable AND gets modified after creation.
|
51
|
+
def from_blob(window, blob_data, width, height, options={})
|
52
|
+
options = {
|
53
|
+
:caching => @options[:caching],
|
54
|
+
:tileable => false,
|
55
|
+
}.merge!(options)
|
56
|
+
|
57
|
+
raise ArgumentError, "Height and width must be positive (received #{width}x#{height})" if height <= 0 or width <= 0
|
58
|
+
|
59
|
+
expected_size = height * width * 4
|
60
|
+
if blob_data.size != expected_size
|
61
|
+
raise ArgumentError, "Blob data is not of the correct size (expected #{expected_size} but received #{blob_data.size} bytes)"
|
62
|
+
end
|
63
|
+
|
64
|
+
Gosu::Image.new(window, ImageStub.new(blob_data, width, height), options[:tileable], :caching => options[:caching])
|
65
|
+
end
|
66
|
+
|
47
67
|
def set_options(options = {})
|
48
68
|
@options.merge!(options)
|
49
69
|
end
|
@@ -100,22 +120,24 @@ module TexPlay
|
|
100
120
|
|
101
121
|
end
|
102
122
|
|
103
|
-
#
|
104
|
-
class
|
105
|
-
|
106
|
-
@w, @h = w, h
|
107
|
-
end
|
123
|
+
# Used to create images from blob data.
|
124
|
+
class ImageStub
|
125
|
+
attr_reader :rows, :columns
|
108
126
|
|
109
|
-
def
|
110
|
-
|
127
|
+
def initialize(blob_data, width, height)
|
128
|
+
@data, @columns, @rows = blob_data, width, height
|
111
129
|
end
|
112
130
|
|
113
|
-
def
|
114
|
-
@
|
131
|
+
def to_blob
|
132
|
+
@data
|
115
133
|
end
|
116
|
-
|
117
|
-
|
118
|
-
|
134
|
+
end
|
135
|
+
|
136
|
+
# Used to create blank images.
|
137
|
+
# credit to philomory for this class
|
138
|
+
class EmptyImageStub < ImageStub
|
139
|
+
def initialize(width, height)
|
140
|
+
super("\0" * (width * height * 4), width, height)
|
119
141
|
end
|
120
142
|
end
|
121
143
|
|
data/lib/texplay/version.rb
CHANGED
data/spec/image_spec.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
|
2
|
+
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
describe TexPlay do
|
6
|
+
before :each do
|
7
|
+
@window = Gosu::Window.new(640, 480, false)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#create_image" do
|
11
|
+
it "should create a blank image of the correct size" do
|
12
|
+
width, height = 30, 10
|
13
|
+
image = described_class.create_image(@window, width, height)
|
14
|
+
|
15
|
+
image.width.should == width
|
16
|
+
image.height.should == height
|
17
|
+
|
18
|
+
width.times do |x|
|
19
|
+
height.times do |y|
|
20
|
+
image.get_pixel(x, y).should == [0.0, 0.0, 0.0, 0.0]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create a coloured image of the correct size" do
|
26
|
+
width, height = 10, 30
|
27
|
+
color = [1.0, 1.0, 0.0, 1.0]
|
28
|
+
image = described_class.create_image(@window, width, height, :color => color)
|
29
|
+
|
30
|
+
image.width.should == width
|
31
|
+
image.height.should == height
|
32
|
+
|
33
|
+
width.times do |x|
|
34
|
+
height.times do |y|
|
35
|
+
image.get_pixel(x, y).should == color
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise an error if an image dimension is 0 or less" do
|
41
|
+
lambda { described_class.create_image(@window, 0, 0)}.should raise_error ArgumentError
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: Should probably be an ArgumentError.
|
45
|
+
it "should raise an error if the image would be too large" do
|
46
|
+
too_big = TexPlay::TP_MAX_QUAD_SIZE + 1
|
47
|
+
[[too_big, 5], [10, too_big], [too_big, too_big]].each do |width, height|
|
48
|
+
lambda { described_class.create_image(@window, width, height)}.should raise_error Exception
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#from_blob" do
|
54
|
+
it "should create an image with the requested pixel data and size" do
|
55
|
+
# 4 x 3, with columns of red, blue, green, transparent.
|
56
|
+
gosu_colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0, 0, 0, 0]]
|
57
|
+
texplay_colors = gosu_colors.map {|a| a.map {|c| c / 255.0 } }
|
58
|
+
width, height = gosu_colors.size, 3
|
59
|
+
|
60
|
+
image = described_class.from_blob(@window, (gosu_colors * height).flatten.pack('C*'), width, height)
|
61
|
+
|
62
|
+
image.width.should == width
|
63
|
+
image.height.should == height
|
64
|
+
|
65
|
+
texplay_colors.each_with_index do |color, x|
|
66
|
+
3.times do |y|
|
67
|
+
image.get_pixel(x, y).should == color
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise an error if the image size is not correct for the blob data" do
|
73
|
+
lambda { described_class.from_blob(@window, [1, 1, 1, 1].pack("C*"), 2, 1) }.should raise_error ArgumentError
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise an error if an image dimension is 0 or less" do
|
77
|
+
lambda { described_class.from_blob(@window, '', 0, 0) }.should raise_error ArgumentError
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texplay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: -879410554
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 983pre1
|
10
|
+
version: 0.2.983pre1
|
11
11
|
platform: i386-mswin32
|
12
12
|
authors:
|
13
13
|
- John Mair (banisterfiend)
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-27 00:00:00 +13:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/texplay.rb
|
50
50
|
- lib/texplay-contrib.rb
|
51
51
|
- lib/texplay/version.rb
|
52
|
+
- lib/texplay/patches.rb
|
52
53
|
- lib/1.8/texplay.so
|
53
54
|
- lib/1.9/texplay.so
|
54
55
|
- examples/common.rb
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- examples/example_polyline.rb
|
79
80
|
- examples/example_scale.rb
|
80
81
|
- examples/example_select.rb
|
82
|
+
- examples/example_select2.rb
|
81
83
|
- examples/example_simple.rb
|
82
84
|
- examples/example_splice.rb
|
83
85
|
- examples/example_sync.rb
|
@@ -88,6 +90,7 @@ files:
|
|
88
90
|
- examples/example_transparent3.rb
|
89
91
|
- examples/example_turtle.rb
|
90
92
|
- examples/example_weird.rb
|
93
|
+
- examples/example_window_to_blob.rb
|
91
94
|
- examples/media/bird.png
|
92
95
|
- examples/media/body.png
|
93
96
|
- examples/media/empty2.png
|
@@ -102,6 +105,8 @@ files:
|
|
102
105
|
- examples/media/sand1.png
|
103
106
|
- examples/media/sunset.png
|
104
107
|
- examples/media/texplay.png
|
108
|
+
- spec/image_spec.rb
|
109
|
+
- spec/texplay_spec.rb
|
105
110
|
has_rdoc: true
|
106
111
|
homepage: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
|
107
112
|
licenses: []
|
@@ -123,12 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
129
|
none: false
|
125
130
|
requirements:
|
126
|
-
- - "
|
131
|
+
- - ">"
|
127
132
|
- !ruby/object:Gem::Version
|
128
|
-
hash:
|
133
|
+
hash: 25
|
129
134
|
segments:
|
130
|
-
-
|
131
|
-
|
135
|
+
- 1
|
136
|
+
- 3
|
137
|
+
- 1
|
138
|
+
version: 1.3.1
|
132
139
|
requirements: []
|
133
140
|
|
134
141
|
rubyforge_project:
|