devil 0.1.9.1 → 0.1.9.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,122 +1,122 @@
1
- # (C) John Mair 2009, under the MIT licence
2
-
3
- require 'texplay'
4
- require 'devil'
5
-
6
- # monkey patches for TexPlay module (and by proxy the Gosu::Image class)
7
- module TexPlay
8
-
9
- # save a Gosu::Image to +file+
10
- # This method is only available if require 'devil/gosu' is used
11
- def save(file)
12
- capture {
13
- img = to_devil
14
- img.save(file)
15
- img.free
16
- }
17
- self
18
- end
19
-
20
- # convert a Gosu::Image to a Devil::Image.
21
- # This method is only available if require 'devil/gosu' is used
22
- def to_devil
23
- devil_img = nil
24
- capture {
25
- devil_img = Devil.from_blob(self.to_blob, self.width, self.height).flip
26
- devil_img
27
- }
28
- devil_img
29
- end
30
- end
31
-
32
- # monkey patches for Gosu::Window class
33
- class Gosu::Window
34
-
35
- # return a screenshot of the framebuffer as a Devil::Image.
36
- # This method is only available if require 'devil/gosu' is used
37
- def screenshot
38
- require 'opengl'
39
-
40
- img = nil
41
- self.gl do
42
- data = glReadPixels(0, 0, self.width, self.height, GL_RGBA, GL_UNSIGNED_BYTE)
43
- img = Devil.from_blob(data, self.width, self.height)
44
- end
45
-
46
- img
47
- end
48
- end
49
-
50
- class Gosu::Image
51
- class << self
52
- alias_method :original_new_redux, :new
53
-
54
- # monkey patching to support multiple image formats.
55
- # This method is only available if require 'devil/gosu' is used
56
- def new(window, file, *args, &block)
57
- if file.respond_to?(:to_blob) || file =~ /\.(bmp|png)$/
58
- original_new_redux(window, file, *args, &block)
59
- else
60
- img = Devil.load(file).flip
61
- begin
62
- gosu_img = original_new_redux(window, img, *args, &block)
63
- ensure
64
- img.free
65
- end
66
-
67
- gosu_img
68
- end
69
- end
70
- end
71
- end
72
-
73
- class Devil::Image
74
-
75
- # convert a Devil::Image to a Gosu::Image.
76
- # Must provide a +window+ parameter, as per Gosu::Image#new()
77
- # This method is only available if require 'devil/gosu' is used
78
- def to_gosu(window)
79
- Gosu::Image.new(window, self)
80
- end
81
-
82
- # display the Devil images on screen utilizing the Gosu library for visualization
83
- # if +x+ and +y+ are specified then show the image centered at this location, otherwise
84
- # draw the image at the center of the screen
85
- # This method is only available if require 'devil/gosu' is used
86
- def show(x = Devil.get_options[:window_size][0] / 2,
87
- y = Devil.get_options[:window_size][1] / 2)
88
-
89
- if !Devil.const_defined?(:Window)
90
- c = Class.new(Gosu::Window) do
91
- attr_accessor :show_list
92
-
93
- def initialize
94
- super(Devil.get_options[:window_size][0], Devil.get_options[:window_size][1], false)
95
- @show_list = []
96
- end
97
-
98
- def draw # :nodoc:
99
- @show_list.each { |v| v[:image].draw_rot(v[:x], v[:y], 1, 0) }
100
-
101
- exit if button_down?(Gosu::KbEscape)
102
- end
103
- end
104
-
105
- Devil.const_set :Window, c
106
- end
107
-
108
- if !defined? @@window
109
- @@window ||= Devil::Window.new
110
-
111
- at_exit { @@window.show }
112
- end
113
-
114
- # note we dup the image so the displayed image is a snapshot taken at the time #show is invoked
115
-
116
- img = self.dup.flip
117
- @@window.show_list.push :image => Gosu::Image.new(@@window, img), :x => x, :y => y
118
- img.free
119
-
120
- self
121
- end
122
- end
1
+ # (C) John Mair 2009, under the MIT licence
2
+
3
+ require 'texplay'
4
+ require 'devil'
5
+
6
+ # monkey patches for TexPlay module (and by proxy the Gosu::Image class)
7
+ module TexPlay
8
+
9
+ # save a Gosu::Image to +file+
10
+ # This method is only available if require 'devil/gosu' is used
11
+ def save(file)
12
+ capture {
13
+ img = to_devil
14
+ img.save(file)
15
+ img.free
16
+ }
17
+ self
18
+ end
19
+
20
+ # convert a Gosu::Image to a Devil::Image.
21
+ # This method is only available if require 'devil/gosu' is used
22
+ def to_devil
23
+ devil_img = nil
24
+ capture {
25
+ devil_img = Devil.from_blob(self.to_blob, self.width, self.height).flip
26
+ devil_img
27
+ }
28
+ devil_img
29
+ end
30
+ end
31
+
32
+ # monkey patches for Gosu::Window class
33
+ class Gosu::Window
34
+
35
+ # return a screenshot of the framebuffer as a Devil::Image.
36
+ # This method is only available if require 'devil/gosu' is used
37
+ def screenshot
38
+ require 'opengl'
39
+
40
+ img = nil
41
+ self.gl do
42
+ data = glReadPixels(0, 0, self.width, self.height, GL_RGBA, GL_UNSIGNED_BYTE)
43
+ img = Devil.from_blob(data, self.width, self.height)
44
+ end
45
+
46
+ img
47
+ end
48
+ end
49
+
50
+ class Gosu::Image
51
+ class << self
52
+ alias_method :original_new_redux, :new
53
+
54
+ # monkey patching to support multiple image formats.
55
+ # This method is only available if require 'devil/gosu' is used
56
+ def new(window, file, *args, &block)
57
+ if file.respond_to?(:to_blob) || file =~ /\.(bmp|png)$/
58
+ original_new_redux(window, file, *args, &block)
59
+ else
60
+ img = Devil.load(file).flip
61
+ begin
62
+ gosu_img = original_new_redux(window, img, *args, &block)
63
+ ensure
64
+ img.free
65
+ end
66
+
67
+ gosu_img
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ class Devil::Image
74
+
75
+ # convert a Devil::Image to a Gosu::Image.
76
+ # Must provide a +window+ parameter, as per Gosu::Image#new()
77
+ # This method is only available if require 'devil/gosu' is used
78
+ def to_gosu(window)
79
+ Gosu::Image.new(window, self)
80
+ end
81
+
82
+ # display the Devil images on screen utilizing the Gosu library for visualization
83
+ # if +x+ and +y+ are specified then show the image centered at this location, otherwise
84
+ # draw the image at the center of the screen
85
+ # This method is only available if require 'devil/gosu' is used
86
+ def show(x = Devil.get_options[:window_size][0] / 2,
87
+ y = Devil.get_options[:window_size][1] / 2)
88
+
89
+ if !Devil.const_defined?(:Window)
90
+ c = Class.new(Gosu::Window) do
91
+ attr_accessor :show_list
92
+
93
+ def initialize
94
+ super(Devil.get_options[:window_size][0], Devil.get_options[:window_size][1], false)
95
+ @show_list = []
96
+ end
97
+
98
+ def draw # :nodoc:
99
+ @show_list.each { |v| v[:image].draw_rot(v[:x], v[:y], 1, 0) }
100
+
101
+ exit if button_down?(Gosu::KbEscape)
102
+ end
103
+ end
104
+
105
+ Devil.const_set :Window, c
106
+ end
107
+
108
+ if !defined? @@window
109
+ @@window ||= Devil::Window.new
110
+
111
+ at_exit { @@window.show }
112
+ end
113
+
114
+ # note we dup the image so the displayed image is a snapshot taken at the time #show is invoked
115
+
116
+ img = self.dup.flip
117
+ @@window.show_list.push :image => Gosu::Image.new(@@window, img), :x => x, :y => y
118
+ img.free
119
+
120
+ self
121
+ end
122
+ end
@@ -1,3 +1,3 @@
1
- module Devil
2
- VERSION = "0.1.9.1"
3
- end
1
+ module Devil
2
+ VERSION = "0.1.9.5"
3
+ end
@@ -1,21 +1,21 @@
1
- $direc = File.dirname(__FILE__)
2
-
3
- $LOAD_PATH.push("#{$direc}/../lib/")
4
-
5
- require 'rubygems'
6
- require 'devil/gosu'
7
-
8
- Devil.create_image(500, 500, :color => [255, 255, 0, 255]) do |img|
9
- source1 = Devil.load("texture.png").thumbnail(100)
10
- img.blit source1, 100, 100
11
- img.blit source1, 400, 100
12
-
13
- source1_dup = source1.dup
14
- img.blit source1_dup.rotate(45), 100, 300
15
-
16
- img.show
17
-
18
- source1.free
19
- source1_dup.free
20
- end
21
-
1
+ $direc = File.dirname(__FILE__)
2
+
3
+ $LOAD_PATH.push("#{$direc}/../lib/")
4
+
5
+ require 'rubygems'
6
+ require 'devil/gosu'
7
+
8
+ Devil.create_image(500, 500, :color => [255, 255, 0, 255]) do |img|
9
+ source1 = Devil.load("texture.png").thumbnail(100)
10
+ img.blit source1, 100, 100
11
+ img.blit source1, 400, 100
12
+
13
+ source1_dup = source1.dup
14
+ img.blit source1_dup.rotate(45), 100, 300
15
+
16
+ img.show
17
+
18
+ source1.free
19
+ source1_dup.free
20
+ end
21
+
@@ -1,21 +1,21 @@
1
- $direc = File.dirname(__FILE__)
2
-
3
- $LOAD_PATH.push("#{$direc}/../lib/")
4
-
5
- require 'rubygems'
6
- require 'devil/gosu'
7
-
8
- Devil.with_image("#{$direc}/texture.png") do |img|
9
- img2 = Devil.load("#{$direc}/red.png")
10
-
11
- img.blit img2, 100, 100, :crop => [0, 0, img2.width / 2, img2.height / 2]
12
- img2.free
13
-
14
- img.show
15
- end
16
-
17
-
18
-
19
-
20
-
21
-
1
+ $direc = File.dirname(__FILE__)
2
+
3
+ $LOAD_PATH.push("#{$direc}/../lib/")
4
+
5
+ require 'rubygems'
6
+ require 'devil/gosu'
7
+
8
+ Devil.with_image("#{$direc}/texture.png") do |img|
9
+ img2 = Devil.load("#{$direc}/red.png")
10
+
11
+ img.blit img2, 100, 100, :crop => [0, 0, img2.width / 2, img2.height / 2]
12
+ img2.free
13
+
14
+ img.show
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
@@ -1,28 +1,28 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- $LOAD_PATH.push("#{direc}/../lib/")
4
-
5
- require 'rubygems'
6
- require "devil/gosu"
7
-
8
- img = Devil.load_image("#{direc}/texture.png")
9
-
10
- img.crop(100,100, 200, 200)
11
- img_dup = img.dup
12
-
13
- img.rotate(rand(360))
14
-
15
- img.show(200,200)
16
- img_dup.show(450, 200)
17
-
18
- img.free
19
- img_dup.free
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
1
+ direc = File.dirname(__FILE__)
2
+
3
+ $LOAD_PATH.push("#{direc}/../lib/")
4
+
5
+ require 'rubygems'
6
+ require "devil/gosu"
7
+
8
+ img = Devil.load_image("#{direc}/texture.png")
9
+
10
+ img.crop(100,100, 200, 200)
11
+ img_dup = img.dup
12
+
13
+ img.rotate(rand(360))
14
+
15
+ img.show(200,200)
16
+ img_dup.show(450, 200)
17
+
18
+ img.free
19
+ img_dup.free
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
@@ -1,23 +1,23 @@
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, "#{$direc}/texture.jpg")
13
- end
14
-
15
- def draw
16
- @img.draw 100, 50,1
17
- end
18
-
19
- end
20
-
21
- w = W.new
22
- w.show
23
-
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, "#{$direc}/texture.jpg")
13
+ end
14
+
15
+ def draw
16
+ @img.draw 100, 50,1
17
+ end
18
+
19
+ end
20
+
21
+ w = W.new
22
+ w.show
23
+
@@ -1,29 +1,29 @@
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, "#{$direc}/texture.jpg")
13
- dimg = @img.to_devil
14
- @img = dimg.emboss.
15
- rotate(45).
16
- to_gosu(self)
17
-
18
- dimg.free
19
- end
20
-
21
- def draw
22
- @img.draw 100, 50,1
23
- end
24
-
25
- end
26
-
27
- w = W.new
28
- w.show
29
-
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, "#{$direc}/texture.jpg")
13
+ dimg = @img.to_devil
14
+ @img = dimg.emboss.
15
+ rotate(45).
16
+ to_gosu(self)
17
+
18
+ dimg.free
19
+ end
20
+
21
+ def draw
22
+ @img.draw 100, 50,1
23
+ end
24
+
25
+ end
26
+
27
+ w = W.new
28
+ w.show
29
+