sfml3.rb

Class: SFML::WindowBase

Inherits:
Object
  • Object
show all
Defined in:
ext/window/window_base.c,
ext/window/window_base.c

Overview

An OS window and its event queue, without an OpenGL context. It is the base of SFML::Window and SFML::RenderWindow, and every method below is also available -- backed by the matching sfRenderWindow entry point -- on both.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#new(video_mode, title, style = :default, state = :windowed) ⇒ WindowBase

Creates an OS window with no OpenGL context of its own.

Raises:

  • (RuntimeError) —

    if window creation fails



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'ext/window/window_base.c', line 79

static VALUE WindowBase_initialize(int argc, VALUE* argv, VALUE self) {
    VALUE rb_video_mode, rb_title, rb_style, rb_state, title_buffer;
    sfWindowState state = sfWindowed;
    uint32_t style = sfDefaultStyle;
    sfWindowBase* window;

    rb_scan_args(argc, argv, "22", &rb_video_mode, &rb_title, &rb_style, &rb_state);

    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);
    }

    title_buffer = utf32_from_rb(rb_title);
    window = sfWindowBase_createUnicode(*Get_Mode_Struct(rb_video_mode), UTF32_PTR(title_buffer),
                                        style, state);
    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_BASE;

    return self;
}

Class Method Details

.from_handle(handle) ⇒ WindowBase

Returns:

Returns:

Raises:

  • (RuntimeError) —

    if window creation fails



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'ext/window/window_base.c', line 124

static VALUE WindowBase_s_from_handle(int argc, VALUE* argv, VALUE klass) {
    VALUE rb_handle;
    sfWindowBase* window;

    rb_scan_args(argc, argv, "1", &rb_handle);

    window = sfWindowBase_createFromHandle((sfWindowHandle)(uintptr_t)NUM2ULL(rb_handle));

    if (window == NULL) {
        rb_raise(rb_eRuntimeError, "failed to create window from handle");
    }

    return Window_wrap_handle(klass, window, SFML_WINDOW_KIND_BASE);
}

Instance Method Details

#close! ⇒ self

Closes the window.

Returns:

  • (self)

#create_vulkan_surface(instance, allocator = nil) ⇒ Integer?

Creates a Vulkan surface for this window.

Returns:

  • (Integer, nil) —

    the new VkSurfaceKHR, or nil if creation failed

#cursor=(value) ⇒ Cursor

Sets the window's mouse cursor.

Returns:

#cursor_grabbed=(value) ⇒ self

Confines or releases the mouse cursor to the window's client area.

Returns:

  • (self)

#cursor_visible=(value) ⇒ self

Shows or hides the mouse cursor over the window.

Returns:

  • (self)

#focus? ⇒ Boolean

Returns true if the window currently has focus.

Returns:

  • (Boolean)

#is_open? ⇒ Boolean

Returns true while the window is open.

Returns:

  • (Boolean)

#joystick_threshold=(value) ⇒ Float

Sets the minimum joystick axis change that generates a move event.

Returns:

  • (Float) —

    value

#key_repeat_enabled=(value) ⇒ self

Enables or disables key-repeat events.

Returns:

  • (self)

#maximum_size=(value) ⇒ Vector2

Sets the window's maximum allowed client size.

Returns:

#minimum_size=(value) ⇒ Vector2

Sets the window's minimum allowed client size.

Returns:

#mouse_cursor=(value) ⇒ Cursor

Sets the window's mouse cursor.

Returns:

#native_handle ⇒ Integer

Returns the OS-specific window handle.

Returns:

  • (Integer)

#poll_event!(event) ⇒ Boolean

Pops the next pending event into event, if any, without blocking.

Returns:

  • (Boolean) —

    whether an event was popped

#position ⇒ Vector2

Returns the window's position in desktop coordinates.

Returns:

#position=(value) ⇒ Vector2

Moves the window to value.

Returns:

#request_focus ⇒ self

Requests focus for this window.

Returns:

  • (self)

#set_icon(size, pixels) ⇒ String

Sets the window's icon from RGBA32 pixel data.

Returns:

  • (String) —

    pixels

#size ⇒ Vector2

Returns the client area size in pixels.

Returns:

#size=(value) ⇒ self

Resizes the window's client area.

Returns:

  • (self)

#title=(value) ⇒ self

Sets the window title.

Returns:

  • (self)

#visible=(value) ⇒ self

Shows or hides the window.

Returns:

  • (self)

#wait_event!(event) ⇒ Boolean

Blocks until an event is available and pops it into event.

Returns:

  • (Boolean) —

    whether an event was popped