Class: Window
Constant Summary collapse
- @@background =
{}
- @@border =
{}
- @@tone =
{}
Instance Attribute Summary collapse
-
#active ⇒ Object
The cursor’s blink status.
-
#arrows_visible ⇒ Object
The visibility of scrolling arrows.
-
#back_opacity ⇒ Object
The window background’s opacity (0-255).
-
#contents ⇒ Object
Refers to the bitmap (Bitmap) used for the window’s contents.
-
#contents_opacity ⇒ Object
The opacity of the window’s contents (0-255).
-
#cursor_rect ⇒ Object
The cursor box (Rect).
-
#height ⇒ Object
The window’s height.
-
#opacity ⇒ Object
The window’s opacity (0-255).
-
#openness ⇒ Object
The openness of the window (from 0 to 255).
-
#ox ⇒ Object
The x-coordinate of the starting point of the window’s contents.
-
#oy ⇒ Object
The y-coordinate of the starting point of the window’s contents.
-
#padding ⇒ Object
The size of the padding between the window’s frame and contents.
-
#padding_bottom ⇒ Object
The padding for the bottom.
-
#pause ⇒ Object
The pause graphic’s visibility.
-
#tone ⇒ Object
The color (Tone) of the window’s background.
-
#viewport ⇒ Object
Refers to the viewport (Viewport) associated with the window.
-
#width ⇒ Object
The window’s width.
-
#windowskin ⇒ Object
Refers to the bitmap (Bitmap) used as a window skin.
-
#x ⇒ Object
The window’s x-coordinate.
-
#y ⇒ Object
The window’s y-coordinate.
-
#z ⇒ Object
The window’s z-coordinate.
Attributes included from RGSS::Drawable
Instance Method Summary collapse
- #applyTone ⇒ Object
- #background(g) ⇒ Object
- #border(g) ⇒ Object
- #close? ⇒ Boolean
- #cursor(g) ⇒ Object
- #draw(destination = Graphics) ⇒ Object
-
#initialize(x = 0, y = 0, width = 0, height = 0) ⇒ Window
constructor
A new instance of Window.
- #move(x, y, width, height) ⇒ Object
- #open? ⇒ Boolean
- #tiled(g, x, y, w, h, skin, x1, y1, w1, h1) ⇒ Object
- #update ⇒ Object
Methods included from RGSS::Drawable
#<=>, #>, #dispose, #disposed?
Constructor Details
#initialize(x = 0, y = 0, width = 0, height = 0) ⇒ Window
Returns a new instance of Window.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/openrgss/window.rb', line 85 def initialize(x=0, y=0, width=0, height=0) @x = x @y = y @z = 100 @ox = 0 @oy = 0 @width = width @height = height @tone = Tone.new @contents = Bitmap.new(32, 32) @cursor_rect = Rect.new @back_opacity = 200 @opacity = 255 @contents_opacity = 255 @active = true @openness = 255 @padding = 12 @padding_bottom = 12 @cursor_status = 0 @visible = true @curcos_flash = 0 super() end |
Instance Attribute Details
#active ⇒ Object
The cursor’s blink status. If TRUE, the cursor is blinking. The default is TRUE.
21 22 23 |
# File 'lib/openrgss/window.rb', line 21 def active @active end |
#arrows_visible ⇒ Object
The visibility of scrolling arrows. If TRUE, the arrows are visible. The default is TRUE.
24 25 26 |
# File 'lib/openrgss/window.rb', line 24 def arrows_visible @arrows_visible end |
#back_opacity ⇒ Object
The window background’s opacity (0-255). Out-of-range values are automatically corrected. The default value is 192 (RGSS3).
68 69 70 |
# File 'lib/openrgss/window.rb', line 68 def back_opacity @back_opacity end |
#contents ⇒ Object
Refers to the bitmap (Bitmap) used for the window’s contents.
10 11 12 |
# File 'lib/openrgss/window.rb', line 10 def contents @contents end |
#contents_opacity ⇒ Object
The opacity of the window’s contents (0-255). Out-of-range values are automatically corrected. The default value is 255.
71 72 73 |
# File 'lib/openrgss/window.rb', line 71 def contents_opacity @contents_opacity end |
#cursor_rect ⇒ Object
The cursor box (Rect).
Specifies a rectangle with coordinates based on the window’s contents.
15 16 17 |
# File 'lib/openrgss/window.rb', line 15 def cursor_rect @cursor_rect end |
#height ⇒ Object
The window’s height.
39 40 41 |
# File 'lib/openrgss/window.rb', line 39 def height @height end |
#opacity ⇒ Object
The window’s opacity (0-255). Out-of-range values are automatically corrected. The default value is 255.
65 66 67 |
# File 'lib/openrgss/window.rb', line 65 def opacity @opacity end |
#openness ⇒ Object
The openness of the window (from 0 to 255). Out-of-range values are automatically corrected.
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 77 78 |
# File 'lib/openrgss/window.rb', line 76 def openness @openness end |
#ox ⇒ Object
The x-coordinate of the starting point of the window’s contents. Change this value to scroll the window’s contents.
Also affects the cursor. (RGSS3)
51 52 53 |
# File 'lib/openrgss/window.rb', line 51 def ox @ox end |
#oy ⇒ Object
The y-coordinate of the starting point of the window’s contents. Change this value to scroll the window’s contents.
Also affects the cursor. (RGSS3)
56 57 58 |
# File 'lib/openrgss/window.rb', line 56 def oy @oy end |
#padding ⇒ Object
The size of the padding between the window’s frame and contents. The default value is 12. (RGSS3)
59 60 61 |
# File 'lib/openrgss/window.rb', line 59 def padding @padding end |
#padding_bottom ⇒ Object
The padding for the bottom. Must be set after padding because it is changed along with it.
62 63 64 |
# File 'lib/openrgss/window.rb', line 62 def padding_bottom @padding_bottom end |
#pause ⇒ Object
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 28 29 |
# File 'lib/openrgss/window.rb', line 27 def pause @pause end |
#tone ⇒ Object
The color (Tone) of the window’s background.
79 80 81 |
# File 'lib/openrgss/window.rb', line 79 def tone @tone end |
#viewport ⇒ Object
Refers to the viewport (Viewport) associated with the window.
18 19 20 |
# File 'lib/openrgss/window.rb', line 18 def @viewport end |
#width ⇒ Object
The window’s width.
36 37 38 |
# File 'lib/openrgss/window.rb', line 36 def width @width end |
#windowskin ⇒ Object
Refers to the bitmap (Bitmap) used as a window skin.
Skin specifications are nearly identical to those in the previous version (VX). Resource standards: See the detailed information on window skins.
7 8 9 |
# File 'lib/openrgss/window.rb', line 7 def windowskin @windowskin end |
#x ⇒ Object
The window’s x-coordinate.
30 31 32 |
# File 'lib/openrgss/window.rb', line 30 def x @x end |
#y ⇒ Object
The window’s y-coordinate.
33 34 35 |
# File 'lib/openrgss/window.rb', line 33 def y @y end |
#z ⇒ Object
The window’s z-coordinate. The larger the value, the closer to the player the window will be displayed.
If multiple objects share the same z-coordinate, the more recently created object will be displayed closest to the player.
The default is 100 (RGSS3).
46 47 48 |
# File 'lib/openrgss/window.rb', line 46 def z @z end |
Instance Method Details
#applyTone ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/openrgss/window.rb', line 173 def applyTone tone = @tone rst = @@tone[[@windowskin.entity, tone.red, tone.green, tone.blue, tone.gray]] return rst if rst rst = @windowskin.entity.copyRect(0, 0, 64, 64) pf =rst.format gg =tone.gray/256 rst.lock for x in 0...64 for y in 0...64 c =pf.getRGB(rst.getPixel(x, y)) g =((c[0]*38+c[1]*75+c[2]*15)/128)%256 c[0]=[[tone.red+c[0]+(g-c[0])*gg, 0].max, 255].min c[1]=[[tone.green+c[1]+(g-c[1])*gg, 0].max, 255].min c[2]=[[tone.blue+c[2]+(g-c[2])*gg, 0].max, 255].min rst.putPixel(x, y, pf.map_rgb(c[0], c[1], c[2])) end end rst.unlock @@tone[[@windowskin.entity, tone.red, tone.green, tone.blue, tone.gray]]=rst return rst end |
#background(g) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/openrgss/window.rb', line 197 def background(g) width = @width - 8 height = @height*@openness/255-8 result = @@background[[@windowskin.entity, width, height, @tone]] if result.nil? tonedbg = applyTone result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, Graphics.entity) @windowskin.entity.set_clip_rect(0, 0, 64, 64) 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 @windowskin.entity.set_alpha(SDL::SRCALPHA, 255) tiled(result, 0, 0, result.w, result.h, @windowskin.entity, 0, 64, 64, 64) result.set_alpha(SDL::SRCALPHA|SDL::RLEACCEL, opacity * back_opacity / 255) @@background[[@windowskin.entity, width, height, @tone]] = result end result.set_alpha(SDL::SRCALPHA|SDL::RLEACCEL, opacity * back_opacity / 255) result end |
#border(g) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/openrgss/window.rb', line 218 def border(g) width = @width height = @height*@openness/255 result = @@border[[@windowskin.entity, width, height]] return result if result puts 'drawing a window border' big_endian = ([1].pack("N") == [1].pack("L")) if big_endian rmask = 0xff000000 gmask = 0x00ff0000 bmask = 0x0000ff00 amask = 0x000000ff else rmask = 0x000000ff gmask = 0x0000ff00 bmask = 0x00ff0000 amask = 0xff000000 end result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, 32, rmask, gmask, bmask, amask) @windowskin.entity.set_alpha(0, 255) SDL::Surface.blit(@windowskin.entity, 64, 0, 16, 16, result, 0, 0) SDL::Surface.blit(@windowskin.entity, 128-16, 0, 16, 16, result, result.w-16, 0) SDL::Surface.blit(@windowskin.entity, 64, 64-16, 16, 16, result, 0, result.h-16) SDL::Surface.blit(@windowskin.entity, 128-16, 64-16, 16, 16, result, result.w-16, result.h-16) tiled(result, 0, 16, 16, result.h-32, @windowskin.entity, 64, 16, 32, 32) tiled(result, result.w-16, 16, 16, result.h-32, @windowskin.entity, 128-16, 16, 32, 32) tiled(result, 16, 0, result.w-32, 16, @windowskin.entity, 64+16, 0, 32, 32) tiled(result, 16, result.h-16, result.w-32, 16, @windowskin.entity, 64+16, 64-16, 32, 32) @@border[[@windowskin.entity, width, height]] = result end |
#close? ⇒ Boolean
130 131 132 |
# File 'lib/openrgss/window.rb', line 130 def close? openness == 0 end |
#cursor(g) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/openrgss/window.rb', line 254 def cursor(g) width = cursor_rect.width height = cursor_rect.height result = @@background[[@windowskin.entity, width, height]] return result if result puts "drawing a new cursor" big_endian = ([1].pack("N") == [1].pack("L")) if big_endian rmask = 0xff000000 gmask = 0x00ff0000 bmask = 0x0000ff00 amask = 0x000000ff else rmask = 0x000000ff gmask = 0x0000ff00 bmask = 0x00ff0000 amask = 0xff000000 end result = SDL::Surface.new(SDL::SWSURFACE|SDL::SRCALPHA, width, height, 32, rmask, gmask, bmask, amask) @windowskin.entity.set_alpha(0, 255) SDL::Surface.blit(@windowskin.entity, 64, 64, 8, 8, result, 0, 0) SDL::Surface.blit(@windowskin.entity, 96-8, 64, 8, 8, result, width-8, 0) SDL::Surface.blit(@windowskin.entity, 64, 96-8, 8, 8, result, 0, height-8) SDL::Surface.blit(@windowskin.entity, 96-8, 96-8, 8, 8, result, width-8, height-8) tiled(result, 0, 8, 8, height-16, @windowskin.entity, 64, 64+8, 8, 8) tiled(result, width-8, 8, 8, height-16, @windowskin.entity, 96-8, 64+8, 8, 8) tiled(result, 8, 0, width-16, 8, @windowskin.entity, 64+8, 64, 8, 8) tiled(result, 8, height-8, width-16, 8, @windowskin.entity, 64+8, 96-8, 8, 8) tiled(result, 8, 8, width-16, height-16, @windowskin.entity, 64+8, 64+8, 16, 16) @@background[[@windowskin.entity, width, height]] = result end |
#draw(destination = Graphics) ⇒ Object
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 |
# File 'lib/openrgss/window.rb', line 139 def draw(destination=Graphics) return if close? base_x = @x-@ox base_y = @y-@oy if destination.entity.set_clip_rect(.rect.x, .rect.y, .rect.width, .rect.height) base_x += .rect.x - .ox base_y += .rect.y - .oy end if @openness < 255 base_y += @height*(255-@openness)/255 / 2 end destination.entity.put(background(destination), base_x+4, base_y+4) if opacity > 0 and back_opacity > 0 and @height * @openness / 255 - 8 > 0 destination.entity.put(border(destination), base_x, base_y) if opacity > 0 if open? if contents_opacity > 0 SDL::Surface.blit(@contents.entity, 0, 0, @width-padding*2, @height-padding-padding_bottom, destination.entity, base_x+padding, base_y+padding) end #cursor if cursor_rect.width > 0 and cursor_rect.height > 0 destination.entity.put cursor(destination), base_x + cursor_rect.x + padding, base_y + cursor_rect.y + padding #cursor_color = (255 - @cursor_status).abs #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)) end end destination.entity.set_clip_rect(0, 0, destination.width, destination.height) if end |
#move(x, y, width, height) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/openrgss/window.rb', line 118 def move(x, y, width, height) @x = x @y = y @width = width @height = height end |
#open? ⇒ Boolean
125 126 127 |
# File 'lib/openrgss/window.rb', line 125 def open? openness == 255 end |
#tiled(g, x, y, w, h, skin, x1, y1, w1, h1) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/openrgss/window.rb', line 290 def tiled(g, x, y, w, h, skin, x1, y1, w1, h1) g.set_clip_rect(x, y, w, h) xnow=x while (xnow<=x+w) ynow=y while (ynow<=y+h) SDL::Surface.blit(skin, x1, y1, w1, h1, g, xnow, ynow) ynow+=h1 end xnow+=w1 end end |
#update ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/openrgss/window.rb', line 110 def update if active @cursor_status = (@cursor_status + 4) % 511 else @cursor_status = 0 end end |