Class: SFML::Window
- Inherits:
-
Get_Klass_WindowBase()
- Object
- Get_Klass_WindowBase()
- SFML::Window
- Defined in:
- ext/window/window.c,
ext/window/window.c
Overview
A renderable OS window with an OpenGL context attached. It derives from SFML::WindowBase; SFML::RenderWindow is the same object under the name that includes SFML::RenderTarget.
view
Class Method Summary collapse
Instance Method Summary collapse
-
#active=(value) ⇒ Boolean
Activates or deactivates this window's OpenGL context as the current one on the calling thread.
-
#clear(color = Color::BLACK) ⇒ self
Clears the window to
color(black by default). -
#clear_color_and_stencil(color, stencil) ⇒ self
Clears the color buffer to
colorand the stencil buffer tostencil. -
#clear_stencil(value) ⇒ self
Clears the stencil buffer to
value. -
#close! ⇒ self
Closes the window.
-
#create_vulkan_surface(instance, allocator = nil) ⇒ Integer?
Creates a Vulkan surface for this window.
-
#cursor=(value) ⇒ Cursor
Sets the window's mouse cursor.
-
#cursor_grabbed=(value) ⇒ self
Confines or releases the mouse cursor to the window's client area.
-
#cursor_visible=(value) ⇒ self
Shows or hides the mouse cursor over the window.
-
#default_view ⇒ View
Returns a copy of the window's default view.
-
#display ⇒ self
Presents everything drawn since the last call to the screen.
-
#draw(drawable, state = nil) ⇒ self
Draws
drawableinto the window. -
#draw_primitives(vertices, primitive, state = nil) ⇒ self
Draws raw vertex data as the given primitive type.
-
#draw_vertex_buffer_range(buffer, first, count, state = nil) ⇒ self
Draws a range of vertices from a vertex buffer.
-
#focus? ⇒ Boolean
Returns
trueif the window currently has focus. -
#frame_rate=(value) ⇒ self
Limits the framerate to
valueframes per second; 0 disables the limit. -
#frame_rate=(value) ⇒ self
Limits the framerate to
valueframes per second; 0 disables the limit. -
#new(video_mode, title, style = :default, state = :windowed, settings = nil) ⇒ Window
constructor
Creates a window with an OpenGL context from
video_modeandtitle. -
#is_open? ⇒ Boolean
Returns
truewhile the window is open. -
#joystick_threshold=(value) ⇒ Float
Sets the minimum joystick axis change that generates a move event.
-
#key_repeat_enabled=(value) ⇒ self
Enables or disables key-repeat events.
-
#map_coords_to_pixel(point, view = nil) ⇒ Vector2
Converts a world position to pixel coordinates.
-
#map_pixel_to_coords(point, view = nil) ⇒ Vector2
Converts a pixel position to world coordinates, using the inverse of the view transform.
-
#maximum_size=(value) ⇒ Vector2
Sets the window's maximum allowed client size.
-
#minimum_size=(value) ⇒ Vector2
Sets the window's minimum allowed client size.
-
#mouse_cursor=(value) ⇒ Cursor
Sets the window's mouse cursor.
-
#native_handle ⇒ Integer
Returns the OS-specific window handle.
-
#poll_event!(event) ⇒ Boolean
Pops the next pending event into
event, if any, without blocking. -
#pop_gl_states ⇒ self
Restores the OpenGL state saved by #push_gl_states.
-
#position ⇒ Vector2
Returns the window's position in desktop coordinates.
-
#position=(value) ⇒ Vector2
Moves the window to
value. -
#push_gl_states ⇒ self
Saves the current OpenGL state.
-
#request_focus ⇒ self
Requests focus for this window.
-
#reset_gl_states ⇒ self
Resets the OpenGL state to SFML's defaults.
-
#scissor(view = nil) ⇒ Rect
Returns the current scissor rectangle in pixels.
-
#set_icon(size, pixels) ⇒ String
Sets the window's icon from RGBA32 pixel data.
-
#settings ⇒ ContextSettings
Returns the context settings this window was created with.
-
#size ⇒ Vector2
Returns the client area size in pixels.
-
#size=(value) ⇒ self
Resizes the window's client area.
-
#srgb? ⇒ Boolean
Returns
trueif the target's framebuffer is sRGB-capable. -
#title=(value) ⇒ self
Sets the window title.
-
#vertical_sync_enabled=(value) ⇒ self
Enables or disables vertical synchronization.
-
#view ⇒ View
Returns a copy of the window's currently active view.
-
#view=(value) ⇒ self
Sets the window's active view to
value. -
#viewport(view = nil) ⇒ Rect
Returns the current viewport rectangle in pixels.
-
#visible=(value) ⇒ self
Shows or hides the window.
-
#wait_event!(event) ⇒ Boolean
Blocks until an event is available and pops it into
event.
Constructor Details
#new(video_mode, title, style = :default, state = :windowed, settings = nil) ⇒ Window
Creates a window with an OpenGL context from video_mode and title.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'ext/window/window.c', line 43
static VALUE Window_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_video_mode, rb_title, rb_style, rb_state, rb_settings, title_buffer;
sfWindowState state = sfWindowed;
sfContextSettings settings;
const sfContextSettings* settings_ptr = NULL;
uint32_t style = sfDefaultStyle;
sfRenderWindow* window;
rb_scan_args(argc, argv, "23", &rb_video_mode, &rb_title, &rb_style, &rb_state, &rb_settings);
if (!rb_obj_is_kind_of(rb_video_mode, Get_Klass_Mode())) {
raise_invalid_argument_class(Get_Klass_Mode());
}
if (!NIL_P(rb_style)) {
style = window_style_from_rb(rb_style);
}
if (!NIL_P(rb_state)) {
state = window_state_from_rb(rb_state);
}
if (!NIL_P(rb_settings)) {
settings = context_settings_from_rb(rb_settings);
settings_ptr = &settings;
}
title_buffer = utf32_from_rb(rb_title);
window = sfRenderWindow_createUnicode(*Get_Mode_Struct(rb_video_mode), UTF32_PTR(title_buffer),
style, state, settings_ptr);
RB_GC_GUARD(title_buffer);
if (window == NULL) {
rb_raise(rb_eRuntimeError, "failed to create window");
}
Get_Window_Data(self)->handle = window;
Get_Window_Data(self)->kind = SFML_WINDOW_KIND_WINDOW;
return self;
}
|
Class Method Details
.from_handle(handle, settings = nil) ⇒ Window
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/window/window.c', line 95
static VALUE Window_s_from_handle(int argc, VALUE* argv, VALUE klass) {
VALUE rb_handle, rb_settings;
sfContextSettings settings;
const sfContextSettings* settings_ptr = NULL;
sfRenderWindow* window;
rb_scan_args(argc, argv, "11", &rb_handle, &rb_settings);
if (!NIL_P(rb_settings)) {
settings = context_settings_from_rb(rb_settings);
settings_ptr = &settings;
}
window = sfRenderWindow_createFromHandle((sfWindowHandle)(uintptr_t)NUM2ULL(rb_handle),
settings_ptr);
if (window == NULL) {
rb_raise(rb_eRuntimeError, "failed to create window from handle");
}
return Window_wrap_handle(klass, window, SFML_WINDOW_KIND_WINDOW);
}
|
Instance Method Details
#active=(value) ⇒ Boolean
Activates or deactivates this window's OpenGL context as the current one on the calling thread.
174 175 176 |
# File 'ext/window/window.c', line 174
static VALUE Window_set_active(VALUE self, VALUE rb_active) {
return BOOL2RB(sfRenderWindow_setActive(Get_Window_Struct(self), RTEST(rb_active)));
}
|
#clear(color = Color::BLACK) ⇒ self
Clears the window to color (black by default).
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/window/window.c', line 126
static VALUE Window_clear(int argc, VALUE* argv, VALUE self) {
sfColor color = sfBlack;
if (argc > 1) {
raise_invalid_arguments_excepted(1, argc);
}
if (argc == 1) {
color_check(argv[0]);
color = color_new_from_rb(argv[0]);
}
sfRenderWindow_clear(Get_Window_Struct(self), color);
return self;
}
|
#clear_color_and_stencil(color, stencil) ⇒ self
Clears the color buffer to color and the stencil buffer to stencil.
#clear_stencil(value) ⇒ self
Clears the stencil buffer to value.
#close! ⇒ self
Closes the window.
#create_vulkan_surface(instance, allocator = nil) ⇒ Integer?
Creates a Vulkan surface for this window.
#cursor=(value) ⇒ Cursor
Sets the window's mouse cursor.
#cursor_grabbed=(value) ⇒ self
Confines or releases the mouse cursor to the window's client area.
#cursor_visible=(value) ⇒ self
Shows or hides the mouse cursor over the window.
#default_view ⇒ View
Returns a copy of the window's default view.
256 257 258 |
# File 'ext/window/window.c', line 256 static VALUE Window_get_default_view(VALUE self) { return Get_Casting_View(sfView_copy((sfRenderWindow_getDefaultView(Get_Window_Struct(self))))); } |
#display ⇒ self
Presents everything drawn since the last call to the screen.
149 150 151 152 |
# File 'ext/window/window.c', line 149 static VALUE Window_display(VALUE self) { sfRenderWindow_display(Get_Window_Struct(self)); return self; } |
#draw(drawable, state = nil) ⇒ self
Draws drawable into the window.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'ext/window/window.c', line 208
static VALUE Window_draw(int argc, VALUE* argv, VALUE self) {
VALUE rb_drawable, rb_state;
if (argc == 0 || argc > 2) {
raise_invalid_arguments_excepted(-1, argc);
}
rb_drawable = argv[0];
rb_state = (argc == 2) ? argv[1] : Get_New_RenderState();
rb_funcall(Get_New_Target(self), rb_intern("draw"), 2, rb_drawable, rb_state);
return self;
}
|
#draw_primitives(vertices, primitive, state = nil) ⇒ self
Draws raw vertex data as the given primitive type.
#draw_vertex_buffer_range(buffer, first, count, state = nil) ⇒ self
Draws a range of vertices from a vertex buffer.
#focus? ⇒ Boolean
Returns true if the window currently has focus.
#frame_rate=(value) ⇒ self
Limits the framerate to value frames per second; 0 disables the limit.
161 162 163 164 |
# File 'ext/window/window.c', line 161
static VALUE Window_set_frame_rate(VALUE self, VALUE rb_limit) {
sfRenderWindow_setFramerateLimit(Get_Window_Struct(self), NUM2INT(rb_limit));
return self;
}
|
#frame_rate=(value) ⇒ self
Limits the framerate to value frames per second; 0 disables the limit.
161 162 163 164 |
# File 'ext/window/window.c', line 161
static VALUE Window_set_frame_rate(VALUE self, VALUE rb_limit) {
sfRenderWindow_setFramerateLimit(Get_Window_Struct(self), NUM2INT(rb_limit));
return self;
}
|
#is_open? ⇒ Boolean
Returns true while the window is open.
#joystick_threshold=(value) ⇒ Float
Sets the minimum joystick axis change that generates a move event.
#key_repeat_enabled=(value) ⇒ self
Enables or disables key-repeat events.
#map_coords_to_pixel(point, view = nil) ⇒ Vector2
Converts a world position to pixel coordinates.
#map_pixel_to_coords(point, view = nil) ⇒ Vector2
Converts a pixel position to world coordinates, using the inverse of the view transform.
#maximum_size=(value) ⇒ Vector2
Sets the window's maximum allowed client size.
#minimum_size=(value) ⇒ Vector2
Sets the window's minimum allowed client size.
#mouse_cursor=(value) ⇒ Cursor
Sets the window's mouse cursor.
#native_handle ⇒ Integer
Returns the OS-specific window handle.
#poll_event!(event) ⇒ Boolean
Pops the next pending event into event, if any, without blocking.
#pop_gl_states ⇒ self
Restores the OpenGL state saved by #push_gl_states.
#position ⇒ Vector2
Returns the window's position in desktop coordinates.
#position=(value) ⇒ Vector2
Moves the window to value.
#push_gl_states ⇒ self
Saves the current OpenGL state.
#request_focus ⇒ self
Requests focus for this window.
#reset_gl_states ⇒ self
Resets the OpenGL state to SFML's defaults.
#scissor(view = nil) ⇒ Rect
Returns the current scissor rectangle in pixels.
#set_icon(size, pixels) ⇒ String
Sets the window's icon from RGBA32 pixel data.
#settings ⇒ ContextSettings
Returns the context settings this window was created with.
196 197 198 |
# File 'ext/window/window.c', line 196 static VALUE Window_get_settings(VALUE self) { return context_settings_to_rb(sfRenderWindow_getSettings(Get_Window_Struct(self))); } |
#size ⇒ Vector2
Returns the client area size in pixels.
#size=(value) ⇒ self
Resizes the window's client area.
#srgb? ⇒ Boolean
Returns true if the target's framebuffer is sRGB-capable.
#title=(value) ⇒ self
Sets the window title.
#vertical_sync_enabled=(value) ⇒ self
Enables or disables vertical synchronization.
185 186 187 188 |
# File 'ext/window/window.c', line 185
static VALUE Window_set_vertical_sync_enabled(VALUE self, VALUE rb_enable) {
sfRenderWindow_setVerticalSyncEnabled(Get_Window_Struct(self), RTEST(rb_enable));
return self;
}
|
#view ⇒ View
Returns a copy of the window's currently active view.
246 247 248 |
# File 'ext/window/window.c', line 246 static VALUE Window_get_view(VALUE self) { return Get_Casting_View(sfView_copy(sfRenderWindow_getView(Get_Window_Struct(self)))); } |
#view=(value) ⇒ self
Sets the window's active view to value.
230 231 232 233 234 235 236 237 238 |
# File 'ext/window/window.c', line 230
static VALUE Window_set_view(VALUE self, VALUE rb_view) {
if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
rb_raise(rb_eArgError, "invalid object, expected a View object");
}
sfRenderWindow_setView(Get_Window_Struct(self), Get_View_Struct(rb_view));
return self;
}
|
#viewport(view = nil) ⇒ Rect
Returns the current viewport rectangle in pixels.
#visible=(value) ⇒ self
Shows or hides the window.
#wait_event!(event) ⇒ Boolean
Blocks until an event is available and pops it into event.