texplay 0.2.981-i386-mingw32 → 0.2.983pre1-i386-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -5,7 +5,7 @@
5
5
  INSTRUCTIONS
6
6
  ============
7
7
 
8
- **TexPlay version 0.2.981**
8
+ **TexPlay version 0.2.983pre1**
9
9
 
10
10
  [Read The Documentation](http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/)
11
11
 
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", "lib/texplay/version.rb", "lib/1.8/texplay.so",
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
@@ -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, 500, 500, :color => Gosu::Color::BLUE)
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 100, 50,1
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
@@ -5,26 +5,34 @@ require 'texplay'
5
5
 
6
6
 
7
7
  class W < Gosu::Window
8
- def initialize
9
- super(500, 500, false, 20)
10
- @img = TexPlay.create_image(self, 500, 500)
11
- @img.rect 100, 100, 200, 300, :color => :red, :fill => true
12
- @img.rect 200, 100, 300, 300, :color_control => proc { [0, 0, 1 - (0.5 * rand), 1.0] }, :fill => true
13
-
14
-
15
- @img.line 0, 0, 500, 500, :dest_ignore => :red, :dest_select => :blue, :tolerance => 1
16
-
17
- @img.circle 200, 100, 50, :fill => true, :dest_select => [:red, :blue], :color => :transparent
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
+
@@ -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
@@ -5,7 +5,7 @@ require 'texplay'
5
5
 
6
6
  class Gosu::Image
7
7
  # so we can use the old TexPlay to_blob -- appears to segfault?!
8
- remove_method :to_blob
8
+ undef_method :to_blob
9
9
  end
10
10
 
11
11
  class W < Gosu::Window
@@ -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
- # credit to philomory for this class
104
- class EmptyImageStub
105
- def initialize(w, h)
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 to_blob
110
- "\0" * @w * @h * 4
127
+ def initialize(blob_data, width, height)
128
+ @data, @columns, @rows = blob_data, width, height
111
129
  end
112
130
 
113
- def rows
114
- @h
131
+ def to_blob
132
+ @data
115
133
  end
116
-
117
- def columns
118
- @w
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
 
@@ -0,0 +1,4 @@
1
+ # 1.9.2 path fix
2
+
3
+ $LOAD_PATH.push File.dirname(File.expand_path(__FILE__))
4
+
@@ -1,3 +1,3 @@
1
1
  module TexPlay
2
- VERSION = "0.2.981"
2
+ VERSION = "0.2.983pre1"
3
3
  end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
2
+
3
+ require 'texplay'
4
+
5
+ describe Gosu::Image do
6
+ it "should do all sorts of things"
7
+ end
@@ -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: 1981
5
- prerelease: false
4
+ hash: 1071479877
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 981
10
- version: 0.2.981
9
+ - 983pre1
10
+ version: 0.2.983pre1
11
11
  platform: i386-mingw32
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-08-16 00:00:00 +12:00
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: 3
133
+ hash: 25
129
134
  segments:
130
- - 0
131
- version: "0"
135
+ - 1
136
+ - 3
137
+ - 1
138
+ version: 1.3.1
132
139
  requirements: []
133
140
 
134
141
  rubyforge_project: