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.
-
.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 |
.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
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/engine/window.rb', line 72 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
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/engine/window.rb', line 12 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, primary_monitor, nil ) end |
.decorations(state) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/engine/window.rb', line 58 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
98 99 100 |
# File 'lib/engine/window.rb', line 98 def focus_window GLFW.FocusWindow(window) end |
.get_framebuffer_size ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/engine/window.rb', line 102 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
30 31 32 33 |
# File 'lib/engine/window.rb', line 30 def height max_height = VideoMode.current_video_mode.height @height = full_screen? ? max_height : max_height * 0.8 end |
.monitor ⇒ Object
35 36 37 |
# File 'lib/engine/window.rb', line 35 def monitor full_screen? ? primary_monitor : nil end |
.primary_monitor ⇒ Object
43 44 45 46 47 48 |
# File 'lib/engine/window.rb', line 43 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
50 51 52 53 54 55 56 |
# File 'lib/engine/window.rb', line 50 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
111 112 113 114 115 116 |
# File 'lib/engine/window.rb', line 111 def set_opengl_version GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, 3) GLFW.WindowHint(GLFW::CONTEXT_VERSION_MINOR, 3) GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE) GLFW.WindowHint(GLFW::OPENGL_FORWARD_COMPAT, GLFW::TRUE) end |
.set_title(title) ⇒ Object
39 40 41 |
# File 'lib/engine/window.rb', line 39 def set_title(title) GLFW::SetWindowTitle(window, title) end |
.set_to_full_screen ⇒ Object
89 90 91 92 |
# File 'lib/engine/window.rb', line 89 def set_to_full_screen @full_screen = true GLFW.SetWindowMonitor(window, primary_monitor, 0, 0, width, height, refresh_rate) end |
.set_to_windowed ⇒ Object
84 85 86 87 |
# File 'lib/engine/window.rb', line 84 def set_to_windowed @full_screen = false GLFW.SetWindowMonitor(window, nil, 0, 0, width, height, refresh_rate) end |
.toggle_full_screen ⇒ Object
94 95 96 |
# File 'lib/engine/window.rb', line 94 def toggle_full_screen full_screen? ? set_to_windowed : set_to_full_screen end |
.translate_state ⇒ Object
118 119 120 121 122 123 |
# File 'lib/engine/window.rb', line 118 def translate_state { :enable => GLFW::TRUE, :disable => GLFW::FALSE } end |
.width ⇒ Object
25 26 27 28 |
# File 'lib/engine/window.rb', line 25 def width max_width = VideoMode.current_video_mode.width @width = full_screen? ? max_width : max_width * 0.8 end |