texplay 0.2.975 → 0.2.980

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 16/8/10
2
+ version 0.2.980
3
+ * added :caching option to TexPlay.set_options, and Gosu::Image.new. For
4
+ control over whether images are cached or not. (accepts true and
5
+ false values)
6
+ * TexPlay.create_image() no longer calls refresh_cache
7
+ * added new TexPlay#clear() method, just draws a filled rect over image.
8
+
1
9
  14/8/10
2
10
  version 0.2.975
3
11
  * fixed :tolerance bug (was in special_cmp_color_with_tolerance, was checking color1.alpha <= tolerance instead of color2.alpha <= tolerance)
data/README.markdown CHANGED
@@ -5,7 +5,7 @@
5
5
  INSTRUCTIONS
6
6
  ============
7
7
 
8
- **TexPlay version 0.2.975**
8
+ **TexPlay version 0.2.980**
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
@@ -31,12 +31,12 @@ specification = Gem::Specification.new do |s|
31
31
  FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "examples/*.rb", "examples/media/*"].to_a
32
32
  end
33
33
 
34
- #Rake::ExtensionTask.new('texplay', specification) do |ext|
35
- # ext.config_script = 'extconf.rb'
36
- # ext.cross_compile = true
37
- #ext.cross_platform = 'i386-mswin32'
34
+ # Rake::ExtensionTask.new('texplay', specification) do |ext|
35
+ # ext.config_script = 'extconf.rb'
36
+ # ext.cross_compile = true
37
+ # ext.cross_platform = 'i386-mswin32'
38
38
  # ext.platform = 'i386-mswin32'
39
- #end
39
+ # end
40
40
 
41
41
 
42
42
  #comment this when want to build normal gems.
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(400, 300, false, 20)
9
+ TexPlay.set_options :caching => true
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/object.png", :caching => false)
11
+
12
+ @img.clear :color => :red, :dest_select => :transparent, :tolerance => 0.9
13
+ end
14
+
15
+ def draw
16
+ @img.draw 100, 100, 1
17
+ end
18
+
19
+ end
20
+
21
+
22
+ w = W.new
23
+ w.show
@@ -2,55 +2,17 @@ require 'rubygems'
2
2
  require 'common'
3
3
  require 'gosu'
4
4
  require 'texplay'
5
- #require 'devil/gosu'
6
5
 
7
6
  class W < Gosu::Window
8
7
  def initialize
9
- super(500, 500, false, 20)
10
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
11
- @x = 100
12
- @y = 100
13
-
14
- @x2 = 400
15
- @y2 = 100
16
- @rad = 70
17
- @s = true
18
-
19
- @copy = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
20
- @copy2 = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
8
+ super(500, 300, false, 20)
9
+ @spritesheet = Gosu::Image.new(self, "body.png", false)
10
+ @spritesheet.splice(Gosu::Image.new(self, "face.png", false), 0,0, :alpha_blend => true)
11
+ @sprite_array = Gosu::Image::load_tiles(self, @spritesheet, 40, 80, false)
21
12
  end
22
13
 
23
14
  def draw
24
-
25
-
26
- @x += 3
27
- @y += 3
28
-
29
- @x2 -= 3
30
- @y2 += 3
31
-
32
- @copy2.splice @img, 0, 0, :crop => [@x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad], :sync_mode => :no_sync
33
- @copy.splice @img, 0, 0, :crop => [@x - @rad, @y - @rad, @x + @rad, @y + @rad], :sync_mode => :no_sync
34
-
35
- @img.circle @x, @y, @rad, :fill => true, :mode => :overlay, :color => :red
36
-
37
- @img.rect @x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad, :fill => true, :mode => :overlay, :color => :blue
38
-
39
- # @img.force_sync [0,0, @img.width, @img.height]
40
-
41
- @img.draw 10, 10,1
42
-
43
- if button_down?(Gosu::KbEscape)
44
- exit
45
- end
46
-
47
- end
48
-
49
- def update
50
- @img.splice @copy, @x - @rad, @y - @rad if !@s
51
- @img.splice @copy2, @x2 - @rad, @y2 - @rad if !@s
52
- @s = nil if @s
53
-
15
+ @sprite_array[0].draw(200,200,0)
54
16
  end
55
17
 
56
18
  end
@@ -59,3 +21,16 @@ end
59
21
  w = W.new
60
22
  w.show
61
23
 
24
+
25
+ # require 'rubygems'
26
+ # require 'gosu'
27
+ # require 'texplay'
28
+ # class Game_Window < Gosu::Window
29
+ # def initialize
30
+ # super(500, 400, false)
31
+ # self.caption = "Image Test"
32
+ # end
33
+
34
+ # def draw
35
+ # end
36
+ # end
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+ class Gosu::Image
7
+ # so we can use the old TexPlay to_blob -- appears to segfault?!
8
+ remove_method :to_blob
9
+ end
10
+
11
+ class W < Gosu::Window
12
+ def initialize
13
+ super(500, 300, false, 20)
14
+ @spritesheet = Gosu::Image.new(self, "#{Common::MEDIA}/body.png", false)
15
+ @spritesheet.splice(Gosu::Image.new(self, "#{Common::MEDIA}/face.png", false), 0,0, :alpha_blend => true)
16
+ @sprite_array = Gosu::Image::load_tiles(self, @spritesheet, 40, 80, false)
17
+ end
18
+
19
+ def draw
20
+ @spritesheet.draw(200,200,0)
21
+ # @sprite_array[0].draw(200,200,0)
22
+ end
23
+
24
+ end
25
+
26
+
27
+ w = W.new
28
+ w.show
29
+
30
+
31
+ # require 'rubygems'
32
+ # require 'gosu'
33
+ # require 'texplay'
34
+ # class Game_Window < Gosu::Window
35
+ # def initialize
36
+ # super(500, 400, false)
37
+ # self.caption = "Image Test"
38
+ # end
39
+
40
+ # def draw
41
+ # end
42
+
43
+ # end
Binary file
Binary file
@@ -729,7 +729,7 @@ m_clear(int argc, VALUE * argv, VALUE self)
729
729
  parms[2] = INT2NUM(XMAX_OOB);
730
730
  parms[3] = INT2NUM(YMAX_OOB);
731
731
 
732
- // m_box(ARY_SIZE(parms), parms, self);
732
+ // m_box(ARY_SIZE(parms), parms, self);
733
733
 
734
734
  return self;
735
735
  }
@@ -43,7 +43,6 @@ Init_texplay() {
43
43
  rb_define_method(jm_Module, "circle", m_circle, -1);
44
44
  rb_define_method(jm_Module, "line", m_line, -1);
45
45
  rb_define_method(jm_Module, "rect", m_rect, -1);
46
- rb_define_method(jm_Module, "clear", m_clear, -1);
47
46
  rb_define_method(jm_Module, "pixel", m_pixel, -1);
48
47
  rb_define_method(jm_Module, "fill", m_flood_fill, -1);
49
48
  rb_define_method(jm_Module, "bezier", m_bezier, -1);
@@ -89,7 +88,8 @@ Init_texplay() {
89
88
  rb_define_method(jm_Module, "colour", m_color, -1);
90
89
  rb_define_method(jm_Module, "composite", m_splice, -1);
91
90
  rb_define_method(jm_Module, "set_pixel", m_pixel, -1);
92
- rb_define_method(jm_Module, "[]", m_getpixel, 2);
91
+ rb_define_method(jm_Module, "[]", m_getpixel, -1);
92
+ rb_define_method(jm_Module, "cache", m_cache_refresh, 0);
93
93
  /** end of aliases **/
94
94
 
95
95
  /** associated with gen_eval **/
data/lib/texplay.rb CHANGED
@@ -30,15 +30,38 @@ module TexPlay
30
30
  end
31
31
  end
32
32
 
33
- def create_blank_image(window, width, height, options={})
33
+ def create_image(window, width, height, options={})
34
+ options = {
35
+ :color => :alpha,
36
+ :caching => false,
37
+ }.merge!(options)
34
38
 
35
- img = Gosu::Image.new(window, EmptyImageStub.new(width, height))
36
- img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true if options[:color]
39
+ img = Gosu::Image.new(window, EmptyImageStub.new(width, height), :caching => options[:caching])
40
+ img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true
37
41
 
38
42
  img
39
43
  end
40
44
 
41
- alias_method :create_image, :create_blank_image
45
+ alias_method :create_blank_image, :create_image
46
+
47
+ def set_options(options = {})
48
+ @options.merge!(options)
49
+ end
50
+
51
+ def get_options
52
+ @options
53
+ end
54
+
55
+ # default values defined here
56
+ def set_defaults
57
+ @options = {
58
+ :caching => true
59
+ }
60
+ end
61
+
62
+ def init
63
+ set_defaults
64
+ end
42
65
  end
43
66
 
44
67
  module Colors
@@ -58,6 +81,23 @@ module TexPlay
58
81
  Tyrian = [0.4, 0.007, 0.235, 1]
59
82
  end
60
83
  include Colors
84
+
85
+ # extra instance methods defined in Ruby
86
+
87
+ # clear an image (with an optional clear color)
88
+ def clear(options = {})
89
+ options = {
90
+ :color => :alpha,
91
+ :fill => true
92
+ }.merge!(options)
93
+
94
+ capture {
95
+ rect 0, 0, width - 1, height - 1, options
96
+ }
97
+
98
+ self
99
+ end
100
+
61
101
  end
62
102
 
63
103
  # credit to philomory for this class
@@ -108,35 +148,39 @@ module Gosu
108
148
 
109
149
  def new(*args, &block)
110
150
 
151
+ options = args.last.is_a?(Hash) ? args.pop : {}
111
152
  # invoke old behaviour
112
153
  obj = original_new(*args, &block)
113
154
 
114
- prepare_image(obj, *args)
155
+ prepare_image(obj, args.first, options)
115
156
  end
116
157
 
117
158
  alias_method :original_from_text, :from_text
118
159
 
119
160
  def from_text(*args, &block)
120
161
 
162
+ options = args.last.is_a?(Hash) ? args.pop : {}
121
163
  # invoke old behaviour
122
164
  obj = original_from_text(*args, &block)
123
165
 
124
- prepare_image(obj, *args)
166
+ prepare_image(obj, args.first, options)
125
167
  end
126
168
 
127
- def prepare_image(obj, *args)
128
-
169
+ def prepare_image(obj, window, options={})
170
+ options = {
171
+ :caching => TexPlay.get_options[:caching]
172
+ }.merge!(options)
173
+
129
174
  # refresh the TexPlay image cache
130
175
  if obj.width <= (TexPlay::TP_MAX_QUAD_SIZE) &&
131
- obj.height <= (TexPlay::TP_MAX_QUAD_SIZE) && obj.quad_cached? then
132
-
133
- obj.refresh_cache
176
+ obj.height <= (TexPlay::TP_MAX_QUAD_SIZE) && obj.quad_cached? then
177
+ obj.refresh_cache if options[:caching]
134
178
  end
135
-
179
+
136
180
  # run custom setup
137
181
  TexPlay.setup(obj)
138
-
139
- obj.instance_variable_set(:@__window__, args.first)
182
+
183
+ obj.instance_variable_set(:@__window__, window)
140
184
 
141
185
  obj
142
186
  end
@@ -157,5 +201,6 @@ class Proc
157
201
  end
158
202
 
159
203
 
160
-
204
+ # initialize TP (at the moment just setting some default settings)
205
+ TexPlay.init
161
206
 
@@ -1,3 +1,3 @@
1
1
  module TexPlay
2
- VERSION = "0.2.975"
2
+ VERSION = "0.2.980"
3
3
  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: 1929
4
+ hash: 1983
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 975
10
- version: 0.2.975
9
+ - 980
10
+ version: 0.2.980
11
11
  platform: ruby
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-14 00:00:00 +12:00
18
+ date: 2010-08-16 00:00:00 +12:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,7 @@ files:
71
71
  - examples/example_alpha_blend.rb
72
72
  - examples/example_bezier.rb
73
73
  - examples/example_blank.rb
74
+ - examples/example_cache.rb
74
75
  - examples/example_color_control.rb
75
76
  - examples/example_color_transform.rb
76
77
  - examples/example_color_transform_circle.rb
@@ -96,6 +97,7 @@ files:
96
97
  - examples/example_simple.rb
97
98
  - examples/example_splice.rb
98
99
  - examples/example_sync.rb
100
+ - examples/example_tiles.rb
99
101
  - examples/example_trace.rb
100
102
  - examples/example_transparent.rb
101
103
  - examples/example_transparent2.rb
@@ -103,7 +105,9 @@ files:
103
105
  - examples/example_turtle.rb
104
106
  - examples/example_weird.rb
105
107
  - examples/media/bird.png
108
+ - examples/media/body.png
106
109
  - examples/media/empty2.png
110
+ - examples/media/face.png
107
111
  - examples/media/gob.png
108
112
  - examples/media/gosu.png
109
113
  - examples/media/green.png