openrgss 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,82 +1,82 @@
1
- class Viewport
2
- #The box (Rect) defining the viewport.
3
- attr_accessor :rect
4
-
5
- # The viewport's visibility. If TRUE, the viewport is visible. The default is TRUE.
6
- attr_accessor :visible
7
-
8
- # The viewport's z-coordinate. The larger the value, the closer to the player the plane will be displayed.
9
- #
10
- # If multiple objects share the same z-coordinate, the more recently created object will be displayed closest to the player.
11
-
12
- attr_accessor :z
13
-
14
- # The x-coordinate of the viewport's starting point. Change this value to shake the screen, etc.
15
- attr_accessor :ox
16
-
17
- # The y-coordinate of the viewport's starting point. Change this value to shake the screen, etc.
18
- attr_accessor :oy
19
-
20
- # The color (Color) to be blended with the viewport. Alpha values are used in the blending ratio.
21
- #
22
- # Handled separately from the color blended into a flash effect.
23
- attr_accessor :color
24
-
25
- # The viewport's color tone (Tone).
26
- attr_accessor :tone
27
-
28
- attr_accessor :created_at
29
-
30
- # :call-seq:
31
- # Viewport.new(x, y, width, height)
32
- # Viewport.new(rect)
33
- # Viewport.new (RGSS3)
34
- #
35
- # Creates a viewport object.
36
- #
37
- # Same size as the screen if no argument is specified.
38
-
39
- def initialize(*args)
40
- @tone = Tone.new
41
- @color = Color.new
42
- @rect = args.empty? ? Rect.new(0, 0, Graphics.width, Graphics.height) : Rect.new(*args)
43
- @created_at = Time.now
44
- @z = 0
45
- @ox = 0
46
- @oy = 0
47
- end
48
-
49
- # Frees the viewport. If the viewport has already been freed, does nothing.
50
- #
51
- # This operation will not result in a separate associated object being automatically freed.
52
-
53
- def dispose
54
- @disposed = true
55
- end
56
-
57
- # Returns TRUE if the viewport has been freed.
58
-
59
- def disposed?
60
- @disposed
61
- end
62
-
63
- # Begins flashing the viewport. duration specifies the number of frames the flash will last.
64
- #
65
- # If color is set to nil, the viewport will disappear while flashing.
66
-
67
- def flash(color, duration)
68
-
69
- end
70
- # Refreshes the viewport flash. As a rule, this method is called once per frame.
71
- #
72
- # It is not necessary to call this method if no flash effect is needed.
73
-
74
- def update
75
-
76
- end
77
-
78
- def z=(z)
79
- @z = z
80
- RGSS.resources.select { |resource| resource.viewport == self }.each { |resource| resource.visible = resource.visible }
81
- end
1
+ class Viewport
2
+ #The box (Rect) defining the viewport.
3
+ attr_accessor :rect
4
+
5
+ # The viewport's visibility. If TRUE, the viewport is visible. The default is TRUE.
6
+ attr_accessor :visible
7
+
8
+ # The viewport's z-coordinate. The larger the value, the closer to the player the plane will be displayed.
9
+ #
10
+ # If multiple objects share the same z-coordinate, the more recently created object will be displayed closest to the player.
11
+
12
+ attr_accessor :z
13
+
14
+ # The x-coordinate of the viewport's starting point. Change this value to shake the screen, etc.
15
+ attr_accessor :ox
16
+
17
+ # The y-coordinate of the viewport's starting point. Change this value to shake the screen, etc.
18
+ attr_accessor :oy
19
+
20
+ # The color (Color) to be blended with the viewport. Alpha values are used in the blending ratio.
21
+ #
22
+ # Handled separately from the color blended into a flash effect.
23
+ attr_accessor :color
24
+
25
+ # The viewport's color tone (Tone).
26
+ attr_accessor :tone
27
+
28
+ attr_accessor :created_at
29
+
30
+ # :call-seq:
31
+ # Viewport.new(x, y, width, height)
32
+ # Viewport.new(rect)
33
+ # Viewport.new (RGSS3)
34
+ #
35
+ # Creates a viewport object.
36
+ #
37
+ # Same size as the screen if no argument is specified.
38
+
39
+ def initialize(*args)
40
+ @tone = Tone.new
41
+ @color = Color.new
42
+ @rect = args.empty? ? Rect.new(0, 0, Graphics.width, Graphics.height) : Rect.new(*args)
43
+ @created_at = Time.now
44
+ @z = 0
45
+ @ox = 0
46
+ @oy = 0
47
+ end
48
+
49
+ # Frees the viewport. If the viewport has already been freed, does nothing.
50
+ #
51
+ # This operation will not result in a separate associated object being automatically freed.
52
+
53
+ def dispose
54
+ @disposed = true
55
+ end
56
+
57
+ # Returns TRUE if the viewport has been freed.
58
+
59
+ def disposed?
60
+ @disposed
61
+ end
62
+
63
+ # Begins flashing the viewport. duration specifies the number of frames the flash will last.
64
+ #
65
+ # If color is set to nil, the viewport will disappear while flashing.
66
+
67
+ def flash(color, duration)
68
+
69
+ end
70
+ # Refreshes the viewport flash. As a rule, this method is called once per frame.
71
+ #
72
+ # It is not necessary to call this method if no flash effect is needed.
73
+
74
+ def update
75
+
76
+ end
77
+
78
+ def z=(z)
79
+ @z = z
80
+ RGSS.resources.select { |resource| resource.viewport == self }.each { |resource| resource.visible = resource.visible }
81
+ end
82
82
  end
@@ -1,303 +1,303 @@
1
- class Window
2
- include RGSS::Drawable
3
-
4
- # Refers to the bitmap (Bitmap) used as a window skin.
5
- #
6
- # Skin specifications are nearly identical to those in the previous version (VX). Resource standards: See the detailed information on window skins.
7
- attr_accessor :windowskin
8
-
9
- # Refers to the bitmap (Bitmap) used for the window's contents.
10
- attr_accessor :contents
11
-
12
- # The cursor box (Rect).
13
- #
14
- # Specifies a rectangle with coordinates based on the window's contents.
15
- attr_accessor :cursor_rect
16
-
17
- # Refers to the viewport (Viewport) associated with the window.
18
- attr_accessor :viewport
19
-
20
- # The cursor's blink status. If TRUE, the cursor is blinking. The default is TRUE.
21
- attr_accessor :active
22
-
23
- # The visibility of scrolling arrows. If TRUE, the arrows are visible. The default is TRUE.
24
- attr_accessor :arrows_visible
25
-
26
- # The pause graphic's visibility. This is a symbol that appears in the message window when waiting for the player to press a button. If TRUE, the graphic is visible. The default is FALSE.
27
- attr_accessor :pause
28
-
29
- # The window's x-coordinate.
30
- attr_accessor :x
31
-
32
- # The window's y-coordinate.
33
- attr_accessor :y
34
-
35
- # The window's width.
36
- attr_accessor :width
37
-
38
- # The window's height.
39
- attr_accessor :height
40
-
41
- # The window's z-coordinate. The larger the value, the closer to the player the window will be displayed.
42
- #
43
- # If multiple objects share the same z-coordinate, the more recently created object will be displayed closest to the player.
44
- #
45
- # The default is 100 (RGSS3).
46
- attr_accessor :z
47
-
48
- # The x-coordinate of the starting point of the window's contents. Change this value to scroll the window's contents.
49
- #
50
- # Also affects the cursor. (RGSS3)
51
- attr_accessor :ox
52
-
53
- # The y-coordinate of the starting point of the window's contents. Change this value to scroll the window's contents.
54
- #
55
- # Also affects the cursor. (RGSS3)
56
- attr_accessor :oy
57
-
58
- # The size of the padding between the window's frame and contents. The default value is 12. (RGSS3)
59
- attr_accessor :padding
60
-
61
- # The padding for the bottom. Must be set after padding because it is changed along with it.
62
- attr_accessor :padding_bottom
63
-
64
- # The window's opacity (0-255). Out-of-range values are automatically corrected. The default value is 255.
65
- attr_accessor :opacity
66
-
67
- # The window background's opacity (0-255). Out-of-range values are automatically corrected. The default value is 192 (RGSS3).
68
- attr_accessor :back_opacity
69
-
70
- # The opacity of the window's contents (0-255). Out-of-range values are automatically corrected. The default value is 255.
71
- attr_accessor :contents_opacity
72
-
73
- # The openness of the window (from 0 to 255). Out-of-range values are automatically corrected.
74
- #
75
- # By changing this value in stages from 0 (completely closed) to 255 (completely open), it is possible to create an animation of the window opening and closing. If the openness is less than 255, the contents of the window will not be displayed. The default value is 255.
76
- attr_accessor :openness
77
-
78
- # The color (Tone) of the window's background.
79
- attr_accessor :tone
80
-
81
- @@background = {}
82
- @@border = {}
83
- @@tone = {}
84
-
85
- def initialize(x=0, y=0, width=0, height=0)
86
- @x = x
87
- @y = y
88
- @z = 100
89
- @ox = 0
90
- @oy = 0
91
- @width = width
92
- @height = height
93
- @tone = Tone.new
94
- @contents = Bitmap.new(32, 32)
95
- @cursor_rect = Rect.new
96
- @back_opacity = 200
97
- @opacity = 255
98
- @contents_opacity = 255
99
- @active = true
100
- @openness = 255
101
- @padding = 12
102
- @padding_bottom = 12
103
- @cursor_status = 0
104
- @visible = true
105
- @curcos_flash = 0
106
- super()
107
- end
108
-
109
-
110
- def update
111
- if active
112
- @cursor_status = (@cursor_status + 4) % 511
113
- else
114
- @cursor_status = 0
115
- end
116
- end
117
-
118
- def move(x, y, width, height)
119
- @x = x
120
- @y = y
121
- @width = width
122
- @height = height
123
- end
124
-
125
- def open?
126
- openness == 255
127
- end
128
-
129
-
130
- def close?
131
- openness == 0
132
- end
133
-
134
- def openness=(openness)
135
- @openness = openness < 0 ? 0 : openness > 255 ? 255 : openness
136
- end
137
-
138
-
139
- def draw(destination=Graphics)
140
- return if close?
141
- base_x = @x-@ox
142
- base_y = @y-@oy
143
- if viewport
144
- destination.entity.set_clip_rect(viewport.rect.x, viewport.rect.y, viewport.rect.width, viewport.rect.height)
145
- base_x += viewport.rect.x - viewport.ox
146
- base_y += viewport.rect.y - viewport.oy
147
- end
148
- if @openness < 255
149
- base_y += @height*(255-@openness)/255 / 2
150
- end
151
- destination.entity.put(background(destination), base_x+4, base_y+4) if opacity > 0 and back_opacity > 0 and @height * @openness / 255 - 8 > 0
152
- destination.entity.put(border(destination), base_x, base_y) if opacity > 0
153
-
154
- if open?
155
- if contents_opacity > 0
156
- SDL::Surface.blit(@contents.entity, 0, 0, @width-padding*2, @height-padding-padding_bottom, destination.entity, base_x+padding, base_y+padding)
157
- end
158
-
159
-
160
- #cursor
161
- if cursor_rect.width > 0 and cursor_rect.height > 0
162
- destination.entity.put cursor(destination), base_x + cursor_rect.x + padding, base_y + cursor_rect.y + padding
163
- #cursor_color = (255 - @cursor_status).abs
164
- #destination.entity.draw_rect(base_x+padding+cursor_rect.x, base_y+padding+cursor_rect.y, cursor_rect.width, cursor_rect.height, destination.entity.map_rgba(cursor_color, cursor_color, 255, 255))
165
- end
166
- end
167
-
168
-
169
- destination.entity.set_clip_rect(0, 0, destination.width, destination.height) if viewport
170
- end
171
-
172
-
173
- def applyTone
174
- tone = @tone
175
- rst = @@tone[[@windowskin.entity, tone.red, tone.green, tone.blue, tone.gray]]
176
- return rst if rst
177
- rst = @windowskin.entity.copyRect(0, 0, 64, 64)
178
- pf =rst.format
179
- gg =tone.gray/256
180
- rst.lock
181
- for x in 0...64
182
- for y in 0...64
183
- c =pf.getRGB(rst.getPixel(x, y))
184
- g =((c[0]*38+c[1]*75+c[2]*15)/128)%256
185
- c[0]=[[tone.red+c[0]+(g-c[0])*gg, 0].max, 255].min
186
- c[1]=[[tone.green+c[1]+(g-c[1])*gg, 0].max, 255].min
187
- c[2]=[[tone.blue+c[2]+(g-c[2])*gg, 0].max, 255].min
188
- rst.putPixel(x, y, pf.map_rgb(c[0], c[1], c[2]))
189
- end
190
- end
191
- rst.unlock
192
- @@tone[[@windowskin.entity, tone.red, tone.green, tone.blue, tone.gray]]=rst
193
- return rst
194
- end
195
-
196
-
197
- def background(g)
198
- width = @width - 8
199
- height = @height*@openness/255-8
200
- result = @@background[[@windowskin.entity, width, height, @tone]]
201
- if result.nil?
202
- tonedbg = applyTone
203
- result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, Graphics.entity)
204
-
205
- @windowskin.entity.set_clip_rect(0, 0, 64, 64)
206
- SDL::Surface.transform_draw(tonedbg, result, 0, (width).to_f/64 * 1.2, height.to_f/64*1.2, 0, 0, 0, 0, 0) #*1.2 to fix SDL bu
207
-
208
- @windowskin.entity.set_alpha(SDL::SRCALPHA, 255)
209
- tiled(result, 0, 0, result.w, result.h, @windowskin.entity, 0, 64, 64, 64)
210
- result.set_alpha(SDL::SRCALPHA|SDL::RLEACCEL, opacity * back_opacity / 255)
211
- @@background[[@windowskin.entity, width, height, @tone]] = result
212
- end
213
- result.set_alpha(SDL::SRCALPHA|SDL::RLEACCEL, opacity * back_opacity / 255)
214
- result
215
- end
216
-
217
-
218
- def border(g)
219
- width = @width
220
- height = @height*@openness/255
221
- result = @@border[[@windowskin.entity, width, height]]
222
- return result if result
223
- puts 'drawing a window border'
224
-
225
-
226
- big_endian = ([1].pack("N") == [1].pack("L"))
227
- if big_endian
228
- rmask = 0xff000000
229
- gmask = 0x00ff0000
230
- bmask = 0x0000ff00
231
- amask = 0x000000ff
232
- else
233
- rmask = 0x000000ff
234
- gmask = 0x0000ff00
235
- bmask = 0x00ff0000
236
- amask = 0xff000000
237
- end
238
-
239
-
240
- result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, 32, rmask, gmask, bmask, amask)
241
- @windowskin.entity.set_alpha(0, 255)
242
- SDL::Surface.blit(@windowskin.entity, 64, 0, 16, 16, result, 0, 0)
243
- SDL::Surface.blit(@windowskin.entity, 128-16, 0, 16, 16, result, result.w-16, 0)
244
- SDL::Surface.blit(@windowskin.entity, 64, 64-16, 16, 16, result, 0, result.h-16)
245
- SDL::Surface.blit(@windowskin.entity, 128-16, 64-16, 16, 16, result, result.w-16, result.h-16)
246
- tiled(result, 0, 16, 16, result.h-32, @windowskin.entity, 64, 16, 32, 32)
247
- tiled(result, result.w-16, 16, 16, result.h-32, @windowskin.entity, 128-16, 16, 32, 32)
248
- tiled(result, 16, 0, result.w-32, 16, @windowskin.entity, 64+16, 0, 32, 32)
249
- tiled(result, 16, result.h-16, result.w-32, 16, @windowskin.entity, 64+16, 64-16, 32, 32)
250
- @@border[[@windowskin.entity, width, height]] = result
251
- end
252
-
253
-
254
- def cursor(g)
255
- width = cursor_rect.width
256
- height = cursor_rect.height
257
- result = @@background[[@windowskin.entity, width, height]]
258
-
259
- return result if result
260
- puts "drawing a new cursor"
261
- big_endian = ([1].pack("N") == [1].pack("L"))
262
- if big_endian
263
- rmask = 0xff000000
264
- gmask = 0x00ff0000
265
- bmask = 0x0000ff00
266
- amask = 0x000000ff
267
- else
268
- rmask = 0x000000ff
269
- gmask = 0x0000ff00
270
- bmask = 0x00ff0000
271
- amask = 0xff000000
272
- end
273
- result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, 32, rmask, gmask, bmask, amask)
274
-
275
-
276
- @windowskin.entity.set_alpha(0, 255)
277
- SDL::Surface.blit(@windowskin.entity, 64, 64, 8, 8, result, 0, 0)
278
- SDL::Surface.blit(@windowskin.entity, 96-8, 64, 8, 8, result, width-8, 0)
279
- SDL::Surface.blit(@windowskin.entity, 64, 96-8, 8, 8, result, 0, height-8)
280
- SDL::Surface.blit(@windowskin.entity, 96-8, 96-8, 8, 8, result, width-8, height-8)
281
- tiled(result, 0, 8, 8, height-16, @windowskin.entity, 64, 64+8, 8, 8)
282
- tiled(result, width-8, 8, 8, height-16, @windowskin.entity, 96-8, 64+8, 8, 8)
283
- tiled(result, 8, 0, width-16, 8, @windowskin.entity, 64+8, 64, 8, 8)
284
- tiled(result, 8, height-8, width-16, 8, @windowskin.entity, 64+8, 96-8, 8, 8)
285
- tiled(result, 8, 8, width-16, height-16, @windowskin.entity, 64+8, 64+8, 16, 16)
286
- @@background[[@windowskin.entity, width, height]] = result
287
- end
288
-
289
-
290
- def tiled(g, x, y, w, h, skin, x1, y1, w1, h1)
291
- g.set_clip_rect(x, y, w, h)
292
- xnow=x
293
- while (xnow<=x+w)
294
- ynow=y
295
- while (ynow<=y+h)
296
- SDL::Surface.blit(skin, x1, y1, w1, h1, g, xnow, ynow)
297
- ynow+=h1
298
- end
299
- xnow+=w1
300
- end
301
- end
302
- #SDL::Surface.blit(cache([skin, :bg, w, h]), 0, 0, w, h, g, x, y)
1
+ class Window
2
+ include RGSS::Drawable
3
+
4
+ # Refers to the bitmap (Bitmap) used as a window skin.
5
+ #
6
+ # Skin specifications are nearly identical to those in the previous version (VX). Resource standards: See the detailed information on window skins.
7
+ attr_accessor :windowskin
8
+
9
+ # Refers to the bitmap (Bitmap) used for the window's contents.
10
+ attr_accessor :contents
11
+
12
+ # The cursor box (Rect).
13
+ #
14
+ # Specifies a rectangle with coordinates based on the window's contents.
15
+ attr_accessor :cursor_rect
16
+
17
+ # Refers to the viewport (Viewport) associated with the window.
18
+ attr_accessor :viewport
19
+
20
+ # The cursor's blink status. If TRUE, the cursor is blinking. The default is TRUE.
21
+ attr_accessor :active
22
+
23
+ # The visibility of scrolling arrows. If TRUE, the arrows are visible. The default is TRUE.
24
+ attr_accessor :arrows_visible
25
+
26
+ # The pause graphic's visibility. This is a symbol that appears in the message window when waiting for the player to press a button. If TRUE, the graphic is visible. The default is FALSE.
27
+ attr_accessor :pause
28
+
29
+ # The window's x-coordinate.
30
+ attr_accessor :x
31
+
32
+ # The window's y-coordinate.
33
+ attr_accessor :y
34
+
35
+ # The window's width.
36
+ attr_accessor :width
37
+
38
+ # The window's height.
39
+ attr_accessor :height
40
+
41
+ # The window's z-coordinate. The larger the value, the closer to the player the window will be displayed.
42
+ #
43
+ # If multiple objects share the same z-coordinate, the more recently created object will be displayed closest to the player.
44
+ #
45
+ # The default is 100 (RGSS3).
46
+ attr_accessor :z
47
+
48
+ # The x-coordinate of the starting point of the window's contents. Change this value to scroll the window's contents.
49
+ #
50
+ # Also affects the cursor. (RGSS3)
51
+ attr_accessor :ox
52
+
53
+ # The y-coordinate of the starting point of the window's contents. Change this value to scroll the window's contents.
54
+ #
55
+ # Also affects the cursor. (RGSS3)
56
+ attr_accessor :oy
57
+
58
+ # The size of the padding between the window's frame and contents. The default value is 12. (RGSS3)
59
+ attr_accessor :padding
60
+
61
+ # The padding for the bottom. Must be set after padding because it is changed along with it.
62
+ attr_accessor :padding_bottom
63
+
64
+ # The window's opacity (0-255). Out-of-range values are automatically corrected. The default value is 255.
65
+ attr_accessor :opacity
66
+
67
+ # The window background's opacity (0-255). Out-of-range values are automatically corrected. The default value is 192 (RGSS3).
68
+ attr_accessor :back_opacity
69
+
70
+ # The opacity of the window's contents (0-255). Out-of-range values are automatically corrected. The default value is 255.
71
+ attr_accessor :contents_opacity
72
+
73
+ # The openness of the window (from 0 to 255). Out-of-range values are automatically corrected.
74
+ #
75
+ # By changing this value in stages from 0 (completely closed) to 255 (completely open), it is possible to create an animation of the window opening and closing. If the openness is less than 255, the contents of the window will not be displayed. The default value is 255.
76
+ attr_accessor :openness
77
+
78
+ # The color (Tone) of the window's background.
79
+ attr_accessor :tone
80
+
81
+ @@background = {}
82
+ @@border = {}
83
+ @@tone = {}
84
+
85
+ def initialize(x=0, y=0, width=0, height=0)
86
+ @x = x
87
+ @y = y
88
+ @z = 100
89
+ @ox = 0
90
+ @oy = 0
91
+ @width = width
92
+ @height = height
93
+ @tone = Tone.new
94
+ @contents = Bitmap.new(32, 32)
95
+ @cursor_rect = Rect.new
96
+ @back_opacity = 200
97
+ @opacity = 255
98
+ @contents_opacity = 255
99
+ @active = true
100
+ @openness = 255
101
+ @padding = 12
102
+ @padding_bottom = 12
103
+ @cursor_status = 0
104
+ @visible = true
105
+ @curcos_flash = 0
106
+ super()
107
+ end
108
+
109
+
110
+ def update
111
+ if active
112
+ @cursor_status = (@cursor_status + 4) % 511
113
+ else
114
+ @cursor_status = 0
115
+ end
116
+ end
117
+
118
+ def move(x, y, width, height)
119
+ @x = x
120
+ @y = y
121
+ @width = width
122
+ @height = height
123
+ end
124
+
125
+ def open?
126
+ openness == 255
127
+ end
128
+
129
+
130
+ def close?
131
+ openness == 0
132
+ end
133
+
134
+ def openness=(openness)
135
+ @openness = openness < 0 ? 0 : openness > 255 ? 255 : openness
136
+ end
137
+
138
+
139
+ def draw(destination=Graphics)
140
+ return if close?
141
+ base_x = @x-@ox
142
+ base_y = @y-@oy
143
+ if viewport
144
+ destination.entity.set_clip_rect(viewport.rect.x, viewport.rect.y, viewport.rect.width, viewport.rect.height)
145
+ base_x += viewport.rect.x - viewport.ox
146
+ base_y += viewport.rect.y - viewport.oy
147
+ end
148
+ if @openness < 255
149
+ base_y += @height*(255-@openness)/255 / 2
150
+ end
151
+ destination.entity.put(background(destination), base_x+4, base_y+4) if opacity > 0 and back_opacity > 0 and @height * @openness / 255 - 8 > 0
152
+ destination.entity.put(border(destination), base_x, base_y) if opacity > 0
153
+
154
+ if open?
155
+ if contents_opacity > 0
156
+ SDL::Surface.blit(@contents.entity, 0, 0, @width-padding*2, @height-padding-padding_bottom, destination.entity, base_x+padding, base_y+padding)
157
+ end
158
+
159
+
160
+ #cursor
161
+ if cursor_rect.width > 0 and cursor_rect.height > 0
162
+ destination.entity.put cursor(destination), base_x + cursor_rect.x + padding, base_y + cursor_rect.y + padding
163
+ #cursor_color = (255 - @cursor_status).abs
164
+ #destination.entity.draw_rect(base_x+padding+cursor_rect.x, base_y+padding+cursor_rect.y, cursor_rect.width, cursor_rect.height, destination.entity.map_rgba(cursor_color, cursor_color, 255, 255))
165
+ end
166
+ end
167
+
168
+
169
+ destination.entity.set_clip_rect(0, 0, destination.width, destination.height) if viewport
170
+ end
171
+
172
+
173
+ def applyTone
174
+ tone = @tone
175
+ rst = @@tone[[@windowskin.entity, tone.red, tone.green, tone.blue, tone.gray]]
176
+ return rst if rst
177
+ rst = @windowskin.entity.copyRect(0, 0, 64, 64)
178
+ pf =rst.format
179
+ gg =tone.gray/256
180
+ rst.lock
181
+ for x in 0...64
182
+ for y in 0...64
183
+ c =pf.getRGB(rst.getPixel(x, y))
184
+ g =((c[0]*38+c[1]*75+c[2]*15)/128)%256
185
+ c[0]=[[tone.red+c[0]+(g-c[0])*gg, 0].max, 255].min
186
+ c[1]=[[tone.green+c[1]+(g-c[1])*gg, 0].max, 255].min
187
+ c[2]=[[tone.blue+c[2]+(g-c[2])*gg, 0].max, 255].min
188
+ rst.putPixel(x, y, pf.map_rgb(c[0], c[1], c[2]))
189
+ end
190
+ end
191
+ rst.unlock
192
+ @@tone[[@windowskin.entity, tone.red, tone.green, tone.blue, tone.gray]]=rst
193
+ return rst
194
+ end
195
+
196
+
197
+ def background(g)
198
+ width = @width - 8
199
+ height = @height*@openness/255-8
200
+ result = @@background[[@windowskin.entity, width, height, @tone]]
201
+ if result.nil?
202
+ tonedbg = applyTone
203
+ result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, Graphics.entity)
204
+
205
+ @windowskin.entity.set_clip_rect(0, 0, 64, 64)
206
+ SDL::Surface.transform_draw(tonedbg, result, 0, (width).to_f/64 * 1.2, height.to_f/64*1.2, 0, 0, 0, 0, 0) #*1.2 to fix SDL bu
207
+
208
+ @windowskin.entity.set_alpha(SDL::SRCALPHA, 255)
209
+ tiled(result, 0, 0, result.w, result.h, @windowskin.entity, 0, 64, 64, 64)
210
+ result.set_alpha(SDL::SRCALPHA|SDL::RLEACCEL, opacity * back_opacity / 255)
211
+ @@background[[@windowskin.entity, width, height, @tone]] = result
212
+ end
213
+ result.set_alpha(SDL::SRCALPHA|SDL::RLEACCEL, opacity * back_opacity / 255)
214
+ result
215
+ end
216
+
217
+
218
+ def border(g)
219
+ width = @width
220
+ height = @height*@openness/255
221
+ result = @@border[[@windowskin.entity, width, height]]
222
+ return result if result
223
+ puts 'drawing a window border'
224
+
225
+
226
+ big_endian = ([1].pack("N") == [1].pack("L"))
227
+ if big_endian
228
+ rmask = 0xff000000
229
+ gmask = 0x00ff0000
230
+ bmask = 0x0000ff00
231
+ amask = 0x000000ff
232
+ else
233
+ rmask = 0x000000ff
234
+ gmask = 0x0000ff00
235
+ bmask = 0x00ff0000
236
+ amask = 0xff000000
237
+ end
238
+
239
+
240
+ result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, 32, rmask, gmask, bmask, amask)
241
+ @windowskin.entity.set_alpha(0, 255)
242
+ SDL::Surface.blit(@windowskin.entity, 64, 0, 16, 16, result, 0, 0)
243
+ SDL::Surface.blit(@windowskin.entity, 128-16, 0, 16, 16, result, result.w-16, 0)
244
+ SDL::Surface.blit(@windowskin.entity, 64, 64-16, 16, 16, result, 0, result.h-16)
245
+ SDL::Surface.blit(@windowskin.entity, 128-16, 64-16, 16, 16, result, result.w-16, result.h-16)
246
+ tiled(result, 0, 16, 16, result.h-32, @windowskin.entity, 64, 16, 32, 32)
247
+ tiled(result, result.w-16, 16, 16, result.h-32, @windowskin.entity, 128-16, 16, 32, 32)
248
+ tiled(result, 16, 0, result.w-32, 16, @windowskin.entity, 64+16, 0, 32, 32)
249
+ tiled(result, 16, result.h-16, result.w-32, 16, @windowskin.entity, 64+16, 64-16, 32, 32)
250
+ @@border[[@windowskin.entity, width, height]] = result
251
+ end
252
+
253
+
254
+ def cursor(g)
255
+ width = cursor_rect.width
256
+ height = cursor_rect.height
257
+ result = @@background[[@windowskin.entity, width, height]]
258
+
259
+ return result if result
260
+ puts "drawing a new cursor"
261
+ big_endian = ([1].pack("N") == [1].pack("L"))
262
+ if big_endian
263
+ rmask = 0xff000000
264
+ gmask = 0x00ff0000
265
+ bmask = 0x0000ff00
266
+ amask = 0x000000ff
267
+ else
268
+ rmask = 0x000000ff
269
+ gmask = 0x0000ff00
270
+ bmask = 0x00ff0000
271
+ amask = 0xff000000
272
+ end
273
+ result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, 32, rmask, gmask, bmask, amask)
274
+
275
+
276
+ @windowskin.entity.set_alpha(0, 255)
277
+ SDL::Surface.blit(@windowskin.entity, 64, 64, 8, 8, result, 0, 0)
278
+ SDL::Surface.blit(@windowskin.entity, 96-8, 64, 8, 8, result, width-8, 0)
279
+ SDL::Surface.blit(@windowskin.entity, 64, 96-8, 8, 8, result, 0, height-8)
280
+ SDL::Surface.blit(@windowskin.entity, 96-8, 96-8, 8, 8, result, width-8, height-8)
281
+ tiled(result, 0, 8, 8, height-16, @windowskin.entity, 64, 64+8, 8, 8)
282
+ tiled(result, width-8, 8, 8, height-16, @windowskin.entity, 96-8, 64+8, 8, 8)
283
+ tiled(result, 8, 0, width-16, 8, @windowskin.entity, 64+8, 64, 8, 8)
284
+ tiled(result, 8, height-8, width-16, 8, @windowskin.entity, 64+8, 96-8, 8, 8)
285
+ tiled(result, 8, 8, width-16, height-16, @windowskin.entity, 64+8, 64+8, 16, 16)
286
+ @@background[[@windowskin.entity, width, height]] = result
287
+ end
288
+
289
+
290
+ def tiled(g, x, y, w, h, skin, x1, y1, w1, h1)
291
+ g.set_clip_rect(x, y, w, h)
292
+ xnow=x
293
+ while (xnow<=x+w)
294
+ ynow=y
295
+ while (ynow<=y+h)
296
+ SDL::Surface.blit(skin, x1, y1, w1, h1, g, xnow, ynow)
297
+ ynow+=h1
298
+ end
299
+ xnow+=w1
300
+ end
301
+ end
302
+ #SDL::Surface.blit(cache([skin, :bg, w, h]), 0, 0, w, h, g, x, y)
303
303
  end