Module: Graphics
- Defined in:
- lib/openrgss/graphics.rb
Constant Summary collapse
- FPS_COUNT =
30
Class Attribute Summary collapse
-
.brightness ⇒ Object
Returns the value of attribute brightness.
-
.entity ⇒ Object
Returns the value of attribute entity.
-
.frame_count ⇒ Object
Returns the value of attribute frame_count.
-
.frame_rate ⇒ Object
Returns the value of attribute frame_rate.
-
.height ⇒ Object
readonly
Returns the value of attribute height.
-
.real_fps ⇒ Object
readonly
Returns the value of attribute real_fps.
-
.width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
- .fadein(duration) ⇒ Object
- .fadeout(duration) ⇒ Object
- .frame_reset ⇒ Object
- .freeze ⇒ Object
- .play_movie(filename) ⇒ Object
- .resize_screen(width, height) ⇒ Object
- .snap_to_bitmap ⇒ Object
- .transition(duration = 10, filename = nil, vague = 40) ⇒ Object
- .update ⇒ Object
- .wait(duration) ⇒ Object
Class Attribute Details
.brightness ⇒ Object
Returns the value of attribute brightness.
17 18 19 |
# File 'lib/openrgss/graphics.rb', line 17 def brightness @brightness end |
.entity ⇒ Object
Returns the value of attribute entity.
16 17 18 |
# File 'lib/openrgss/graphics.rb', line 16 def entity @entity end |
.frame_count ⇒ Object
Returns the value of attribute frame_count.
17 18 19 |
# File 'lib/openrgss/graphics.rb', line 17 def frame_count @frame_count end |
.frame_rate ⇒ Object
Returns the value of attribute frame_rate.
17 18 19 |
# File 'lib/openrgss/graphics.rb', line 17 def frame_rate @frame_rate end |
.height ⇒ Object (readonly)
Returns the value of attribute height.
15 16 17 |
# File 'lib/openrgss/graphics.rb', line 15 def height @height end |
.real_fps ⇒ Object (readonly)
Returns the value of attribute real_fps.
19 20 21 |
# File 'lib/openrgss/graphics.rb', line 19 def real_fps @real_fps end |
.width ⇒ Object (readonly)
Returns the value of attribute width.
15 16 17 |
# File 'lib/openrgss/graphics.rb', line 15 def width @width end |
Class Method Details
.fadein(duration) ⇒ Object
72 73 74 75 76 |
# File 'lib/openrgss/graphics.rb', line 72 def fadein(duration) step=255/duration duration.times { |i| @brightness=i*step; update } @brightness=255 end |
.fadeout(duration) ⇒ Object
66 67 68 69 70 |
# File 'lib/openrgss/graphics.rb', line 66 def fadeout(duration) step=255/duration duration.times { |i| @brightness=255-i*step; update } @brightness=0 end |
.frame_reset ⇒ Object
135 136 137 |
# File 'lib/openrgss/graphics.rb', line 135 def frame_reset end |
.freeze ⇒ Object
78 79 80 |
# File 'lib/openrgss/graphics.rb', line 78 def freeze @freezed=true end |
.play_movie(filename) ⇒ Object
139 140 141 |
# File 'lib/openrgss/graphics.rb', line 139 def play_movie(filename) end |
.resize_screen(width, height) ⇒ Object
21 22 23 24 |
# File 'lib/openrgss/graphics.rb', line 21 def resize_screen(width, height) @width = width @height = height end |
.snap_to_bitmap ⇒ Object
131 132 133 |
# File 'lib/openrgss/graphics.rb', line 131 def snap_to_bitmap return @graphics_render_target.clone # free end |
.transition(duration = 10, filename = nil, vague = 40) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/openrgss/graphics.rb', line 82 def transition(duration=10, filename=nil, vague=40) if (duration==0) @freezed=false; return; end if (filename.nil?) # imgmap=Array.new(@width) { Array.new(@height) { 255 } } else # b =Bitmap.new(filename); pfb = b.entity.format imgmap=Array.new(@width) { |x| Array.new(@height) { |y| [pfb.get_rgb(b.entity[x, y])[0], 1].max } } #TODO : free end step =255/duration new_frame = Bitmap.new(@width, @height) RGSS.resources.sort! @old_resources=RGSS.resources.clone new_frame.entity.fill_rect(0, 0, @width, @height, new_frame.entity.map_rgba(0, 0, 0, 255)) new_frame.entity.set_alpha(SDL::SRCALPHA, 255) RGSS.resources.each { |resource| resource.draw(new_frame) } # draw frame to bitmap pf = new_frame.entity.format new_frame.entity.lock picmap=Array.new(@width) { |x| Array.new(@height) { |y| pf.getRGBA(new_frame.entity[x, y]) } } # better to use bit calculate new_frame.entity.unlock maker = Bitmap.new(@width, @height) # create pre-render layoyt maker.entity.fill_rect(0, 0, @width, @height, new_frame.entity.map_rgba(0, 0, 0, 255)) maker.entity.put @graphics_render_target.entity, 0, 0 # transition layout new_frame.entity.lock @width.times { |x| @height.times { |y| if (imgmap[x][y]!=0) new_frame.entity[x, y]=pf.map_rgba(picmap[x][y][0], picmap[x][y][1], picmap[x][y][2], [255/(duration/(255.0/imgmap[x][y])), 255].min) #TODO : alpha will be 255 after many render.it's different fron RPG Maker else new_frame.entity[x, y]=pf.map_rgba(picmap[x][y][0], picmap[x][y][1], picmap[x][y][2], 255) end } } new_frame.entity.unlock duration.times { |i| @entity.fill_rect(0, 0, @width, @height, 0x000000) maker.entity.put new_frame.entity, 0, 0 # alpha @entity.put maker.entity, 0, 0 @entity.update_rect(0, 0, 0, 0) } # TODO: free @graphics_render_target.entity.set_alpha(0, 255); @freezed=false; @brightness=255; update end |
.update ⇒ Object
26 27 28 29 30 31 32 33 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 |
# File 'lib/openrgss/graphics.rb', line 26 def update RGSS.update @frame_count += 1 if @skip >= 10 or SDL.get_ticks < @ticks + 1000 / frame_rate @entity.fill_rect(0, 0, @width, @height, 0x000000) if (@old_resources!=RGSS.resources) # Maybe here can make a dirty mark RGSS.resources.sort! @old_resources=RGSS.resources.clone end unless @freezed # redraw only when !freezed @graphics_render_target.entity.fill_rect(0, 0, @width, @height, @graphics_render_target.entity.map_rgba(0, 0, 0, 255)) @graphics_render_target.entity.set_alpha(SDL::RLEACCEL, 0) RGSS.resources.each { |resource| resource.draw(@graphics_render_target) } end @entity.put @graphics_render_target.entity, 0, 0 @entity.drawRect(0, 0, @width, @height, @entity.map_rgb(0, 0, 0), true, 255-@brightness) # draw gray layout @entity.update_rect(0, 0, 0, 0) sleeptime = @ticks + 1000.0 / frame_rate - SDL.get_ticks sleep sleeptime.to_f / 1000 if sleeptime > 0 @skip = 0 @ticks = SDL.get_ticks else @skip += 1 end @frame_count_recent += 1 if @frame_count_recent >= FPS_COUNT @frame_count_recent = 0 now = SDL.get_ticks @real_fps = FPS_COUNT * 1000 / (now - @fps_ticks) @fps_ticks = now end end |
.wait(duration) ⇒ Object
62 63 64 |
# File 'lib/openrgss/graphics.rb', line 62 def wait(duration) duration.times { update } end |