Class: Engine::Window
- Inherits:
-
Object
- Object
- Engine::Window
- Defined in:
- lib/engine/window.rb
Constant Summary collapse
- DEFAULT_TITLE =
File.basename($PROGRAM_NAME).gsub(/\.rb$/,'')
Class Attribute Summary collapse
-
.framebuffer_height ⇒ Object
readonly
Returns the value of attribute framebuffer_height.
-
.framebuffer_width ⇒ Object
readonly
Returns the value of attribute framebuffer_width.
-
.full_screen ⇒ Object
(also: full_screen?)
Returns the value of attribute full_screen.
- .opengl_version ⇒ Object
-
.window ⇒ Object
Returns the value of attribute window.
-
.window_title ⇒ Object
Returns the value of attribute window_title.
Class Method Summary collapse
- .auto_iconify(state) ⇒ Object
- .create_window ⇒ Object
- .decorations(state) ⇒ Object
- .focus_window ⇒ Object
- .get_framebuffer_size ⇒ Object
- .height ⇒ Object
- .monitor ⇒ Object
- .primary_monitor ⇒ Object
- .refresh_rate ⇒ Object
- .set_opengl_version ⇒ Object
- .set_title(title) ⇒ Object
- .set_to_full_screen ⇒ Object
- .set_to_windowed ⇒ Object
- .toggle_full_screen ⇒ Object
- .translate_state ⇒ Object
- .width ⇒ Object
Class Attribute Details
.framebuffer_height ⇒ Object (readonly)
Returns the value of attribute framebuffer_height.
10 11 12 |
# File 'lib/engine/window.rb', line 10 def framebuffer_height @framebuffer_height end |
.framebuffer_width ⇒ Object (readonly)
Returns the value of attribute framebuffer_width.
10 11 12 |
# File 'lib/engine/window.rb', line 10 def framebuffer_width @framebuffer_width end |
.full_screen ⇒ Object Also known as: full_screen?
Returns the value of attribute full_screen.
9 10 11 |
# File 'lib/engine/window.rb', line 9 def full_screen @full_screen end |
.opengl_version ⇒ Object
122 123 124 |
# File 'lib/engine/window.rb', line 122 def opengl_version @opengl_version || (OS.mac? ? "4.1" : "4.3") end |
.window ⇒ Object
Returns the value of attribute window.
9 10 11 |
# File 'lib/engine/window.rb', line 9 def window @window end |
.window_title ⇒ Object
Returns the value of attribute window_title.
9 10 11 |
# File 'lib/engine/window.rb', line 9 def window_title @window_title end |
Class Method Details
.auto_iconify(state) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/engine/window.rb', line 82 def auto_iconify(state) # GLFW_AUTO_ICONIFY specifies whether the full screen window will automatically iconify and restore the previous # video mode on input focus loss. # Possible values are GLFW_TRUE and GLFW_FALSE. # This hint is ignored for windowed mode windows. # https://www.glfw.org/docs/latest/window_guide.html#GLFW_AUTO_ICONIFY_hint glfw_setting = translate_state[state] GLFW.WindowHint(GLFW::AUTO_ICONIFY, glfw_setting) GLFW.SetWindowAttrib(window, GLFW::AUTO_ICONIFY, glfw_setting) if window end |
.create_window ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/engine/window.rb', line 13 def create_window set_opengl_version decorations :disable auto_iconify :disable @full_screen = true initial_video_mode = VideoMode.current_video_mode @window = GLFW.CreateWindow( initial_video_mode.width, initial_video_mode.height, DEFAULT_TITLE, nil, nil ) if @window.nil? code, description = GLFW.GetError raise "Failed to create GLFW window (error #{code}: #{description})" end GLFW.SetWindowMonitor( @window, nil, 0, 0, initial_video_mode.width, initial_video_mode.height, GLFW::DONT_CARE ) end |
.decorations(state) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/engine/window.rb', line 68 def decorations(state) # GLFW_DECORATED specifies whether the windowed mode window will have window decorations such as a border, # a close widget, etc. # An undecorated window will not be resizable by the user but will still allow the user to generate close events # on some platforms. # Possible values are GLFW_TRUE and GLFW_FALSE. # This hint is ignored for full screen windows. # https://www.glfw.org/docs/latest/window_guide.html#GLFW_DECORATED_attrib glfw_setting = translate_state[state] GLFW.WindowHint(GLFW::DECORATED, glfw_setting) GLFW.SetWindowAttrib(window, GLFW::DECORATED, glfw_setting) if window end |
.focus_window ⇒ Object
109 110 111 |
# File 'lib/engine/window.rb', line 109 def focus_window GLFW.FocusWindow(window) end |
.get_framebuffer_size ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/engine/window.rb', line 113 def get_framebuffer_size width_buf = ' ' * 8 height_buf = ' ' * 8 GLFW.GetFramebufferSize(window, width_buf, height_buf) @framebuffer_width = width_buf.unpack1('L') @framebuffer_height = height_buf.unpack1('L') end |
.height ⇒ Object
40 41 42 43 |
# File 'lib/engine/window.rb', line 40 def height max_height = VideoMode.current_video_mode.height @height = full_screen? ? max_height : max_height * 0.8 end |
.monitor ⇒ Object
45 46 47 |
# File 'lib/engine/window.rb', line 45 def monitor full_screen? ? primary_monitor : nil end |
.primary_monitor ⇒ Object
53 54 55 56 57 58 |
# File 'lib/engine/window.rb', line 53 def primary_monitor # The primary monitor is returned by glfwGetPrimaryMonitor. # It is the user's preferred monitor and is usually the one with global UI elements like task bar or menu bar. # https://www.glfw.org/docs/latest/monitor_guide.html#monitor_monitors GLFW.GetPrimaryMonitor end |
.refresh_rate ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/engine/window.rb', line 60 def refresh_rate # GLFW_REFRESH_RATE specifies the desired refresh rate for full screen windows. # A value of GLFW_DONT_CARE means the highest available refresh rate will be used. # This hint is ignored for windowed mode windows. # https://www.glfw.org/docs/latest/window_guide.html#GLFW_REFRESH_RATE GLFW::DONT_CARE end |
.set_opengl_version ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/engine/window.rb', line 126 def set_opengl_version major, minor = opengl_version.split(".").map { |part| Integer(part) } GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, major) GLFW.WindowHint(GLFW::CONTEXT_VERSION_MINOR, minor) GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE) GLFW.WindowHint(GLFW::OPENGL_FORWARD_COMPAT, GLFW::TRUE) end |
.set_title(title) ⇒ Object
49 50 51 |
# File 'lib/engine/window.rb', line 49 def set_title(title) GLFW::SetWindowTitle(window, title) end |
.set_to_full_screen ⇒ Object
99 100 101 102 103 |
# File 'lib/engine/window.rb', line 99 def set_to_full_screen @full_screen = true vid = VideoMode.current_video_mode GLFW.SetWindowMonitor(window, nil, 0, 0, vid.width, vid.height, GLFW::DONT_CARE) end |
.set_to_windowed ⇒ Object
94 95 96 97 |
# File 'lib/engine/window.rb', line 94 def set_to_windowed @full_screen = false GLFW.SetWindowMonitor(window, nil, 0, 0, width, height, refresh_rate) end |
.toggle_full_screen ⇒ Object
105 106 107 |
# File 'lib/engine/window.rb', line 105 def toggle_full_screen full_screen? ? set_to_windowed : set_to_full_screen end |
.translate_state ⇒ Object
134 135 136 137 138 139 |
# File 'lib/engine/window.rb', line 134 def translate_state { :enable => GLFW::TRUE, :disable => GLFW::FALSE } end |
.width ⇒ Object
35 36 37 38 |
# File 'lib/engine/window.rb', line 35 def width max_width = VideoMode.current_video_mode.width @width = full_screen? ? max_width : max_width * 0.8 end |