module DXRubySDL::Window
Constants
- DEFAULTS
Attributes
height[W]
scale[W]
width[W]
Private Class Methods
screen()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 177 def screen return SDL::Screen.get rescue SDL::Error flags = SDL::HWSURFACE | SDL::ASYNCBLIT | SDL::HWPALETTE | SDL::DOUBLEBUF flags |= SDL::FULLSCREEN unless windowed? return SDL::Screen.open(width, height, 0, flags) end
Public Instance Methods
bgcolor()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 35 def bgcolor @bgcolor ||= DEFAULTS[:background_color] end
bgcolor=(val)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 39 def bgcolor=(val) @bgcolor = val end
caption()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 23 def caption return SDL::WM.caption[0] end
caption=(val)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 27 def caption=(val) SDL::WM.set_caption(val, '') end
draw(x, y, image, z = 0)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 69 def draw(x, y, image, z = 0) if z != 0 raise NotImplementedError, 'Window.draw(x, y, image, z != 0)' end screen.put(image._surface, x, y) end
draw_ex(x, y, image, hash = {})
click to toggle source
# File lib/dxruby_sdl/window.rb, line 86 def draw_ex(x, y, image, hash = {}) if hash[:z] && hash[:z] != 0 raise NotImplementedError, 'Window.draw_ex(x, y, image, z: != 0)' end option = { angle: 0, scale_x: 1, scale_y: 1, center_x: 0, center_y: 0, }.merge(hash) SDL::Surface.transform_blit(image._surface, screen, option[:angle], option[:scale_x], option[:scale_y], option[:center_x], option[:center_y], x + option[:center_x], y + option[:center_y], 0) end
draw_font(x, y, string, font, hash = {})
click to toggle source
# File lib/dxruby_sdl/window.rb, line 105 def draw_font(x, y, string, font, hash = {}) if string.empty? return end if hash[:color] r, g, b = *hash[:color] else r, g, b = 255, 255, 255 end h = font._ttf.height + 1 string.lines.each.with_index do |line, i| line.chomp! if line.empty? next end font._ttf.draw_blended_utf8(screen, line, x, y + i * h, r, g, b) end end
draw_scale(x, y, image, scalex, scaley, centerx = nil, centery = nil, z = 0)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 76 def draw_scale(x, y, image, scalex, scaley, centerx = nil, centery = nil, z = 0) opt = { scale_x: scalex, scale_y: scaley, center_x: centerx, center_y: centery, } draw_ex(x, y, image, opt) end
fps=(val)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 31 def fps=(val) FPSTimer.instance.fps = val end
height()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 13 def height @height ||= DEFAULTS[:height] return @height end
loop() { || ... }
click to toggle source
# File lib/dxruby_sdl/window.rb, line 43 def loop(&block) timer = FPSTimer.instance timer.reset Kernel.loop do timer.wait_frame do while (event = SDL::Event.poll) case event when SDL::Event::Quit exit when SDL::Event::KeyDown, SDL::Event::KeyUp Input.send(:handle_key_event, event) end end screen.fill_rect(0, 0, width, height, bgcolor) yield screen.flip Input.send(:store_last_state) end end end
open_filename(filter, title)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 124 def open_filename(filter, title) # :nocov: if /darwin/ =~ RUBY_PLATFORM apple_script = <<-EOS on run tell application "Finder" activate set theImage to choose file return theImage as Unicode text end tell end run EOS s = `osascript -e '#{apple_script}'` return s.chomp.sub(/^ "/, '').gsub(/:/, '/') else raise NotImplementedError, 'Window.open_filename' end # :nocov: end
scale()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 18 def scale @scale ||= DEFAULTS[:scale] return @scale end
width()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 8 def width @width ||= DEFAULTS[:width] return @width end
windowed=(val)
click to toggle source
# File lib/dxruby_sdl/window.rb, line 148 def windowed=(val) @_fullscreen = !val end
windowed?()
click to toggle source
# File lib/dxruby_sdl/window.rb, line 144 def windowed? !@_fullscreen end