devil 0.1.6-x86-mswin32-60 → 0.1.7-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/README +52 -29
- data/Rakefile +8 -9
- data/ext/devil/extconf.rb +6 -2
- data/lib/1.8/devil.so +0 -0
- data/lib/1.9/devil.so +0 -0
- data/lib/devil.rb +235 -226
- data/lib/devil/gosu.rb +22 -6
- data/test/test_clone_and_crop.rb +1 -1
- data/test/test_gosu_load.rb +2 -5
- data/test/test_new_api.rb +1 -1
- data/test/test_screenshot.rb +33 -33
- metadata +3 -6
- data/test/screenshot.png +0 -0
- data/test/tank-modified.png +0 -0
data/README
CHANGED
@@ -1,29 +1,52 @@
|
|
1
|
-
Devil version 0.1.
|
2
|
-
|
3
|
-
|
4
|
-
*
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
For
|
17
|
-
|
18
|
-
*
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
*
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
Ruby Devil version 0.1.7
|
2
|
+
========================
|
3
|
+
|
4
|
+
* Original author: Jaroslaw Tworek <dev.jrx@gmail.com>
|
5
|
+
* Current maintainer: John Mair (banisterfiend) [http://banisterfiend.wordpress.com]
|
6
|
+
|
7
|
+
Ruby bindings for the Developer's Image Library
|
8
|
+
You need DevIL installed to use this extension
|
9
|
+
|
10
|
+
The Ruby Devil Project page is here: [http://github.com/banister/devil]
|
11
|
+
|
12
|
+
|
13
|
+
Installation Instructions:
|
14
|
+
==========================
|
15
|
+
|
16
|
+
For debian:
|
17
|
+
|
18
|
+
* install the libdevil and libdevil-dev packages
|
19
|
+
|
20
|
+
For Gentoo:
|
21
|
+
|
22
|
+
* emerge "media-libs/devil"
|
23
|
+
|
24
|
+
For windows:
|
25
|
+
|
26
|
+
* download devil.dll and ilu.dll from [http://github.com/banister/devil/downloads]
|
27
|
+
* and copy these files to c:\windows\system\
|
28
|
+
|
29
|
+
For macosx:
|
30
|
+
|
31
|
+
* sudo port install libdevil
|
32
|
+
|
33
|
+
For other systems:
|
34
|
+
|
35
|
+
* install libdevil and lib-devil-dev using your package manager
|
36
|
+
* OR download and install the libraries from [http://openil.sourceforge.net]
|
37
|
+
|
38
|
+
After you've installed the DevIL libraries you install the gem by going:
|
39
|
+
|
40
|
+
* gem install devil
|
41
|
+
|
42
|
+
If you wish to use the Gosu and TexPlay extensions, it is necessary to also have:
|
43
|
+
|
44
|
+
* the Gosu gem (gem install gosu)
|
45
|
+
* the TexPlay gem (gem install texplay)
|
46
|
+
* ruby-opengl (gem install ruby-opengl)
|
47
|
+
|
48
|
+
For now, there is support for just a subset of DevIL functions, but it is enough
|
49
|
+
for 95% things you may want to do.
|
50
|
+
|
51
|
+
For example uses, see test/ directory
|
52
|
+
(note: that many of the examples use the Gosu library...this is often just for visualization purposes. Alot of the functionality does not depend on Gosu being present)
|
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rake/clean'
|
2
|
-
|
3
|
-
if RUBY_PLATFORM !~ /win/
|
2
|
+
if RUBY_PLATFORM !~ /win32/
|
4
3
|
require 'rake/extensiontask'
|
5
4
|
end
|
6
5
|
|
@@ -8,7 +7,7 @@ require 'rake/gempackagetask'
|
|
8
7
|
require 'rake/testtask'
|
9
8
|
require 'rake/rdoctask'
|
10
9
|
|
11
|
-
DEVIL_VERSION = "0.1.
|
10
|
+
DEVIL_VERSION = "0.1.7"
|
12
11
|
|
13
12
|
dlext = Config::CONFIG['DLEXT']
|
14
13
|
|
@@ -26,23 +25,23 @@ spec = Gem::Specification.new do |s|
|
|
26
25
|
s.require_path = 'lib'
|
27
26
|
s.homepage = "http://banisterfiend.wordpress.com"
|
28
27
|
|
29
|
-
if RUBY_PLATFORM =~ /
|
28
|
+
if RUBY_PLATFORM =~ /win32/
|
30
29
|
s.platform = Gem::Platform::CURRENT
|
31
30
|
else
|
32
31
|
s.platform = Gem::Platform::RUBY
|
33
32
|
end
|
34
33
|
|
35
|
-
if RUBY_PLATFORM !~ /
|
34
|
+
if RUBY_PLATFORM !~ /win32/
|
36
35
|
s.extensions = FileList["ext/**/extconf.rb"]
|
37
36
|
end
|
38
37
|
|
39
38
|
s.has_rdoc = true
|
40
|
-
s.extra_rdoc_files = ["README"
|
39
|
+
s.extra_rdoc_files = ["README"]
|
41
40
|
s.rdoc_options << '--main' << 'README'
|
42
41
|
s.files = ["Rakefile", "README", "LICENSE", "lib/devil.rb", "lib/devil/gosu.rb"] +
|
43
|
-
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "test/test*.rb", "test/*.
|
42
|
+
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "test/test*.rb", "test/*.png", "test/*.jpg"].to_a
|
44
43
|
|
45
|
-
if RUBY_PLATFORM =~ /
|
44
|
+
if RUBY_PLATFORM =~ /win32/
|
46
45
|
s.files += ["lib/1.8/devil.so", "lib/1.9/devil.so"]
|
47
46
|
end
|
48
47
|
|
@@ -55,7 +54,7 @@ end
|
|
55
54
|
|
56
55
|
task :compile => :clean
|
57
56
|
|
58
|
-
if RUBY_PLATFORM !~ /
|
57
|
+
if RUBY_PLATFORM !~ /win32/
|
59
58
|
Rake::ExtensionTask.new('devil', spec) do |ext|
|
60
59
|
ext.config_script = 'extconf.rb'
|
61
60
|
ext.cross_compile = true
|
data/ext/devil/extconf.rb
CHANGED
@@ -3,10 +3,14 @@ require 'mkmf'
|
|
3
3
|
if RUBY_PLATFORM =~ /mingw/
|
4
4
|
$CFLAGS += ' -I/home/john/.rake-compiler/ruby/ruby-1.8.6-p287/include/'
|
5
5
|
$LDFLAGS += ' -L/home/john/.rake-compiler/ruby/ruby-1.8.6-p287/lib/'
|
6
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
7
|
+
|
8
|
+
# this only works if you install devil via macports
|
9
|
+
$CFLAGS += ' -I/opt/local/include/'
|
10
|
+
$LDFLAGS += ' -L/opt/local/lib/'
|
6
11
|
end
|
7
12
|
|
8
|
-
|
9
|
-
if RUBY_PLATFORM =~ /win/ || RUBY_PLATFORM =~ /mingw/
|
13
|
+
if RUBY_PLATFORM =~ /(win32|mingw)/
|
10
14
|
exit unless have_library("DevIL");
|
11
15
|
else
|
12
16
|
exit unless have_library("IL");
|
data/lib/1.8/devil.so
CHANGED
Binary file
|
data/lib/1.9/devil.so
CHANGED
Binary file
|
data/lib/devil.rb
CHANGED
@@ -1,226 +1,235 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
direc = File.dirname(__FILE__)
|
4
|
-
dlext = Config::CONFIG['DLEXT']
|
5
|
-
begin
|
6
|
-
if RUBY_VERSION && RUBY_VERSION =~ /1.9/
|
7
|
-
require "#{direc}/1.9/devil.#{dlext}"
|
8
|
-
else
|
9
|
-
require "#{direc}/1.8/devil.#{dlext}"
|
10
|
-
end
|
11
|
-
rescue LoadError => e
|
12
|
-
require "#{direc}/devil.#{dlext}"
|
13
|
-
end
|
14
|
-
|
15
|
-
# Provides a high level wrapper for the low-level DevIL Ruby bindings
|
16
|
-
module Devil
|
17
|
-
VERSION = '0.1.
|
18
|
-
|
19
|
-
class << self
|
20
|
-
|
21
|
-
# loads +file+ and returns a new image
|
22
|
-
# Optionally accepts a block and yields the newly created image to the block.
|
23
|
-
def load_image(file, &block)
|
24
|
-
name = IL.GenImages(1).first
|
25
|
-
IL.BindImage(name)
|
26
|
-
IL.LoadImage(file)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
img
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
IL.
|
71
|
-
end
|
72
|
-
|
73
|
-
# returns the
|
74
|
-
def
|
75
|
-
set_binding
|
76
|
-
IL.GetInteger(IL::
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
def
|
116
|
-
set_binding
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
#
|
148
|
-
#
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
direc = File.dirname(__FILE__)
|
4
|
+
dlext = Config::CONFIG['DLEXT']
|
5
|
+
begin
|
6
|
+
if RUBY_VERSION && RUBY_VERSION =~ /1.9/
|
7
|
+
require "#{direc}/1.9/devil.#{dlext}"
|
8
|
+
else
|
9
|
+
require "#{direc}/1.8/devil.#{dlext}"
|
10
|
+
end
|
11
|
+
rescue LoadError => e
|
12
|
+
require "#{direc}/devil.#{dlext}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Provides a high level wrapper for the low-level DevIL Ruby bindings
|
16
|
+
module Devil
|
17
|
+
VERSION = '0.1.7'
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
# loads +file+ and returns a new image
|
22
|
+
# Optionally accepts a block and yields the newly created image to the block.
|
23
|
+
def load_image(file, &block)
|
24
|
+
name = IL.GenImages(1).first
|
25
|
+
IL.BindImage(name)
|
26
|
+
IL.LoadImage(file)
|
27
|
+
|
28
|
+
if (error_code = IL.GetError) != IL::NO_ERROR
|
29
|
+
raise RuntimeError, "an error occured while trying to "+
|
30
|
+
"load the image #{file}. Error code: #{error_code}"
|
31
|
+
end
|
32
|
+
|
33
|
+
img = Image.new(name, file)
|
34
|
+
if block
|
35
|
+
block.call(img)
|
36
|
+
end
|
37
|
+
|
38
|
+
img
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :with_image, :load_image
|
42
|
+
alias_method :load, :load_image
|
43
|
+
|
44
|
+
# convert an image +blob+ with +width+ and +height+
|
45
|
+
# to a bona fide image
|
46
|
+
def from_blob(blob, width, height)
|
47
|
+
Image.new(IL.FromBlob(blob, width, height), nil)
|
48
|
+
end
|
49
|
+
|
50
|
+
# initializes Devil and sets defaults
|
51
|
+
# This method should never need to be called directly.
|
52
|
+
def init
|
53
|
+
# initialize DevIL
|
54
|
+
IL.Init
|
55
|
+
|
56
|
+
# default options
|
57
|
+
IL.Enable(IL::FILE_OVERWRITE)
|
58
|
+
ILU.ImageParameter(ILU::FILTER, ILU::BILINEAR)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class Image
|
64
|
+
attr_reader :name, :file
|
65
|
+
|
66
|
+
def initialize(name, file)
|
67
|
+
@name = name
|
68
|
+
@file = file
|
69
|
+
|
70
|
+
ObjectSpace.define_finalizer( self, proc { IL.DeleteImages(1, [name]) } )
|
71
|
+
end
|
72
|
+
|
73
|
+
# returns the width of the image
|
74
|
+
def width
|
75
|
+
set_binding
|
76
|
+
IL.GetInteger(IL::IMAGE_WIDTH)
|
77
|
+
end
|
78
|
+
|
79
|
+
alias_method :columns, :width
|
80
|
+
|
81
|
+
# returns the height of the image
|
82
|
+
def height
|
83
|
+
set_binding
|
84
|
+
IL.GetInteger(IL::IMAGE_HEIGHT)
|
85
|
+
end
|
86
|
+
|
87
|
+
alias_method :rows, :height
|
88
|
+
|
89
|
+
# saves the image to +file+. If no +file+ is provided default to the opened file.
|
90
|
+
def save(file = @file)
|
91
|
+
set_binding
|
92
|
+
IL.SaveImage(file)
|
93
|
+
self
|
94
|
+
end
|
95
|
+
|
96
|
+
# resize the image to +width+ and +height+. Aspect ratios of the image do not have to be the same.
|
97
|
+
def resize(width, height)
|
98
|
+
set_binding
|
99
|
+
ILU.Scale(width, height, 1)
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
# Creates a proportional thumbnail of the image scaled so its longest
|
104
|
+
# edge is resized to +size+
|
105
|
+
def thumbnail(size)
|
106
|
+
# this thumbnail code from image_science.rb
|
107
|
+
|
108
|
+
w, h = width, height
|
109
|
+
scale = size.to_f / (w > h ? w : h)
|
110
|
+
resize((w * scale).to_i, (h * scale).to_i)
|
111
|
+
self
|
112
|
+
end
|
113
|
+
|
114
|
+
# return a deep copy of the current image
|
115
|
+
def dup
|
116
|
+
set_binding
|
117
|
+
Image.new(IL.CloneCurImage, nil)
|
118
|
+
end
|
119
|
+
|
120
|
+
alias_method :clone, :dup
|
121
|
+
|
122
|
+
# crop the current image
|
123
|
+
# +xoff+ number of pixels to skip in x direction
|
124
|
+
# +yoff+ number of pixels to skip in y direction
|
125
|
+
# +width+ number of pixels to preserve in x direction
|
126
|
+
# +height+ number of pixels to preserve in y direction
|
127
|
+
def crop(xoff, yoff, width, height)
|
128
|
+
set_binding
|
129
|
+
ILU.Crop(xoff, yoff, width, height)
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
# performs a gaussian blur on the image. The blur is performed +iter+ times.
|
134
|
+
def blur(iter)
|
135
|
+
set_binding
|
136
|
+
ILU.BlurGaussian(iter)
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
# 'pixelize' the image using a pixel size of +pixel_size+
|
141
|
+
def pixelize(pixel_size)
|
142
|
+
set_binding
|
143
|
+
ILU.Pixelize(pixel_size)
|
144
|
+
self
|
145
|
+
end
|
146
|
+
|
147
|
+
# add random noise to the image. +factor+ is the tolerance to use.
|
148
|
+
# accepeted values range from 0.0 - 1.0
|
149
|
+
def noisify(factor)
|
150
|
+
set_binding
|
151
|
+
ILU.Noisify(factor)
|
152
|
+
self
|
153
|
+
end
|
154
|
+
|
155
|
+
# The sharpening +factor+ must be in the range of 0.0 - 2.5. A value of 1.0 for the sharpening
|
156
|
+
# factor will have no effect on the image. Values in the range 1.0 - 2.5 will sharpen the
|
157
|
+
# image, with 2.5 having the most pronounced sharpening effect. Values from 0.0 to 1.0 do
|
158
|
+
# a type of reverse sharpening, blurring the image. Values outside of the 0.0 - 2.5 range
|
159
|
+
# produce undefined results.
|
160
|
+
#
|
161
|
+
# The number of +iter+ (iterations) to perform will usually be 1, but to achieve more sharpening,
|
162
|
+
# increase the number of iterations.
|
163
|
+
def sharpen(factor, iter)
|
164
|
+
set_binding
|
165
|
+
ILU.Sharpen(factor, iter)
|
166
|
+
self
|
167
|
+
end
|
168
|
+
|
169
|
+
# applies gamma correction to an image using an exponential curve.
|
170
|
+
# +factor+ is gamma correction factor to use.
|
171
|
+
# A value of 1.0 leaves the image unmodified.
|
172
|
+
# Values in the range 0.0 - 1.0 darken the image
|
173
|
+
# Values above 1.0 brighten the image.
|
174
|
+
def gamma_correct(factor)
|
175
|
+
set_binding
|
176
|
+
ILU.GammaCorrect(factor)
|
177
|
+
self
|
178
|
+
end
|
179
|
+
|
180
|
+
# invert the color of every pixel in the image.
|
181
|
+
def negative
|
182
|
+
set_binding
|
183
|
+
ILU.Negative
|
184
|
+
self
|
185
|
+
end
|
186
|
+
|
187
|
+
# +factor+ describes desired contrast to use
|
188
|
+
# A value of 1.0 has no effect on the image.
|
189
|
+
# Values between 1.0 and 1.7 increase the amount of contrast (values above 1.7 have no effect)
|
190
|
+
# Valid range of +factor+ is 0.0 - 1.7
|
191
|
+
def contrast(factor)
|
192
|
+
set_binding
|
193
|
+
ILU.Contrast(factor)
|
194
|
+
self
|
195
|
+
end
|
196
|
+
|
197
|
+
# darkens the bright colours and lightens the dark
|
198
|
+
# colours, reducing the contrast in an image or 'equalizing' it.
|
199
|
+
def equalize
|
200
|
+
set_binding
|
201
|
+
ILU.Equalize
|
202
|
+
self
|
203
|
+
end
|
204
|
+
|
205
|
+
# returns the image data in the form of a ruby string
|
206
|
+
# The image data is formatted to RGBA / UNSIGNED BYTE
|
207
|
+
def to_blob
|
208
|
+
set_binding
|
209
|
+
IL.ToBlob
|
210
|
+
end
|
211
|
+
|
212
|
+
# flip the image about its x axis
|
213
|
+
def flip
|
214
|
+
set_binding
|
215
|
+
ILU.FlipImage
|
216
|
+
self
|
217
|
+
end
|
218
|
+
|
219
|
+
# rotate an image about its central point by +angle+ degrees
|
220
|
+
def rotate(angle)
|
221
|
+
set_binding
|
222
|
+
ILU.Rotate(angle)
|
223
|
+
self
|
224
|
+
end
|
225
|
+
|
226
|
+
private
|
227
|
+
|
228
|
+
def set_binding
|
229
|
+
IL.BindImage(@name)
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
Devil.init
|
data/lib/devil/gosu.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
require 'texplay'
|
2
2
|
require 'devil'
|
3
3
|
|
4
|
+
# monkey patches for TexPlay module (and by proxy the Gosu::Image class)
|
4
5
|
module TexPlay
|
5
6
|
|
6
7
|
# save a Gosu::Image to +file+
|
7
8
|
# This method is only available if require 'devil/gosu' is used
|
8
9
|
def save(file)
|
9
10
|
capture {
|
10
|
-
|
11
|
-
save_image.flip
|
12
|
-
save_image.save(file)
|
11
|
+
to_devil.save(file)
|
13
12
|
}
|
14
13
|
end
|
15
14
|
|
16
|
-
# convert a Gosu::Image to a Devil::Image
|
15
|
+
# convert a Gosu::Image to a Devil::Image.
|
17
16
|
# This method is only available if require 'devil/gosu' is used
|
18
17
|
def to_devil
|
19
18
|
devil_img = nil
|
@@ -25,9 +24,10 @@ module TexPlay
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
27
|
+
# monkey patches for Gosu::Window class
|
28
28
|
class Gosu::Window
|
29
29
|
|
30
|
-
# return a screenshot of the framebuffer as a Devil::Image
|
30
|
+
# return a screenshot of the framebuffer as a Devil::Image.
|
31
31
|
# This method is only available if require 'devil/gosu' is used
|
32
32
|
def screenshot
|
33
33
|
require 'opengl'
|
@@ -54,10 +54,27 @@ class Gosu::Window
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
class Gosu::Image
|
58
|
+
class << self
|
59
|
+
alias_method :original_new_redux, :new
|
60
|
+
|
61
|
+
# monkey patching to support multiple image formats.
|
62
|
+
# This method is only available if require 'devil/gosu' is used
|
63
|
+
def new(window, file, *args, &block)
|
64
|
+
if file.respond_to?(:to_blob) || file =~ /\.(bmp|png)$/
|
65
|
+
original_new_redux(window, file, *args, &block)
|
66
|
+
else
|
67
|
+
original_new_redux(window, Devil.load(file), *args, &block)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
57
73
|
class Devil::Image
|
58
74
|
|
59
75
|
# convert a Devil::Image to a Gosu::Image.
|
60
76
|
# Must provide a +window+ parameter, as per Gosu::Image#new()
|
77
|
+
# This method is only available if require 'devil/gosu' is used
|
61
78
|
def to_gosu(window)
|
62
79
|
Gosu::Image.new(window, self)
|
63
80
|
end
|
@@ -92,5 +109,4 @@ class Devil::Image
|
|
92
109
|
|
93
110
|
@@window.show_list.push :image => Gosu::Image.new(@@window, self), :x => x, :y => y
|
94
111
|
end
|
95
|
-
|
96
112
|
end
|
data/test/test_clone_and_crop.rb
CHANGED
data/test/test_gosu_load.rb
CHANGED
@@ -3,16 +3,13 @@ $direc = File.dirname(__FILE__)
|
|
3
3
|
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
4
|
|
5
5
|
require 'rubygems'
|
6
|
-
require 'gosu'
|
7
|
-
require 'devil'
|
6
|
+
require 'devil/gosu'
|
8
7
|
|
9
8
|
class W < Gosu::Window
|
10
9
|
def initialize
|
11
10
|
super(1024, 768, false, 20)
|
12
11
|
|
13
|
-
img =
|
14
|
-
|
15
|
-
@img = Gosu::Image.new(self, img)
|
12
|
+
@img = Gosu::Image.new(self, "#{$direc}/texture.jpg")
|
16
13
|
end
|
17
14
|
|
18
15
|
def draw
|
data/test/test_new_api.rb
CHANGED
data/test/test_screenshot.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
$direc = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'devil/gosu'
|
7
|
-
|
8
|
-
class W < Gosu::Window
|
9
|
-
def initialize
|
10
|
-
super(1024, 768, false, 20)
|
11
|
-
|
12
|
-
@img = Gosu::Image.new(self, "tank.png")
|
13
|
-
@img2 = @img.dup
|
14
|
-
@img.circle 100, 100, 50, :color => :purple, :filled => true
|
15
|
-
end
|
16
|
-
|
17
|
-
def draw
|
18
|
-
@img.draw 100, 50,1
|
19
|
-
@img.draw 300, 50, 1
|
20
|
-
@img2.draw 300, 400, 1
|
21
|
-
end
|
22
|
-
|
23
|
-
def update
|
24
|
-
if button_down?(Gosu::KbEscape)
|
25
|
-
screenshot.rotate(45).save("screenshot.png")
|
26
|
-
exit
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
w = W.new
|
32
|
-
w.show
|
33
|
-
|
1
|
+
$direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.push("#{$direc}/../lib/")
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'devil/gosu'
|
7
|
+
|
8
|
+
class W < Gosu::Window
|
9
|
+
def initialize
|
10
|
+
super(1024, 768, false, 20)
|
11
|
+
|
12
|
+
@img = Gosu::Image.new(self, "tank.png")
|
13
|
+
@img2 = @img.dup
|
14
|
+
@img.circle 100, 100, 50, :color => :purple, :filled => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
@img.draw 100, 50,1
|
19
|
+
@img.draw 300, 50, 1
|
20
|
+
@img2.draw 300, 400, 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
if button_down?(Gosu::KbEscape)
|
25
|
+
screenshot.rotate(45).save("screenshot.png")
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
w = W.new
|
32
|
+
w.show
|
33
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: x86-mswin32-60
|
6
6
|
authors:
|
7
7
|
- Jaroslaw Tworek, John Mair (banisterfiend)
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-16 00:00:00 +13:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -21,7 +21,6 @@ extensions: []
|
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README
|
24
|
-
- lib/devil/gosu.rb
|
25
24
|
files:
|
26
25
|
- Rakefile
|
27
26
|
- README
|
@@ -40,11 +39,9 @@ files:
|
|
40
39
|
- test/test_new_api.rb
|
41
40
|
- test/test_screenshot.rb
|
42
41
|
- test/test_thumbnail.rb
|
43
|
-
- test/texture.jpg
|
44
|
-
- test/screenshot.png
|
45
|
-
- test/tank-modified.png
|
46
42
|
- test/tank.png
|
47
43
|
- test/texture.png
|
44
|
+
- test/texture.jpg
|
48
45
|
- lib/1.8/devil.so
|
49
46
|
- lib/1.9/devil.so
|
50
47
|
has_rdoc: true
|
data/test/screenshot.png
DELETED
Binary file
|
data/test/tank-modified.png
DELETED
Binary file
|