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
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/engine/window.rb', line 77 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 22 23 24 25 26 |
# 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, nil, nil ) GLFW.SetWindowMonitor( @window, nil, 0, 0, initial_video_mode.width, initial_video_mode.height, GLFW::DONT_CARE ) end |
.decorations(state) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/engine/window.rb', line 63 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
104 105 106 |
# File 'lib/engine/window.rb', line 104 def focus_window GLFW.FocusWindow(window) end |
.get_framebuffer_size ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/engine/window.rb', line 108 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
35 36 37 38 |
# File 'lib/engine/window.rb', line 35 def height max_height = VideoMode.current_video_mode.height @height = full_screen? ? max_height : max_height * 0.8 end |
.monitor ⇒ Object
40 41 42 |
# File 'lib/engine/window.rb', line 40 def monitor full_screen? ? primary_monitor : nil end |
.primary_monitor ⇒ Object
48 49 50 51 52 53 |
# File 'lib/engine/window.rb', line 48 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
55 56 57 58 59 60 61 |
# File 'lib/engine/window.rb', line 55 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
117 118 119 120 121 122 |
# File 'lib/engine/window.rb', line 117 def set_opengl_version GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, 4) GLFW.WindowHint(GLFW::CONTEXT_VERSION_MINOR, OS.mac? ? 1 : 3) GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE) GLFW.WindowHint(GLFW::OPENGL_FORWARD_COMPAT, GLFW::TRUE) end |
.set_title(title) ⇒ Object
44 45 46 |
# File 'lib/engine/window.rb', line 44 def set_title(title) GLFW::SetWindowTitle(window, title) end |
.set_to_full_screen ⇒ Object
94 95 96 97 98 |
# File 'lib/engine/window.rb', line 94 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
89 90 91 92 |
# File 'lib/engine/window.rb', line 89 def set_to_windowed @full_screen = false GLFW.SetWindowMonitor(window, nil, 0, 0, width, height, refresh_rate) end |
.toggle_full_screen ⇒ Object
100 101 102 |
# File 'lib/engine/window.rb', line 100 def toggle_full_screen full_screen? ? set_to_windowed : set_to_full_screen end |
.translate_state ⇒ Object
124 125 126 127 128 129 |
# File 'lib/engine/window.rb', line 124 def translate_state { :enable => GLFW::TRUE, :disable => GLFW::FALSE } end |
.width ⇒ Object
30 31 32 33 |
# File 'lib/engine/window.rb', line 30 def width max_width = VideoMode.current_video_mode.width @width = full_screen? ? max_width : max_width * 0.8 end |