Class: Ray::Window

Inherits:
Target show all
Defined in:
lib/ray/window.rb,
ext/window.c

Instance Method Summary collapse

Methods inherited from Target

#[], #clear, #clip, #default_view, #draw, #make_current, #rect, #shader, #size, #to_image, #turtle, #view, #view=, #viewport_for, #with_view

Constructor Details

#initialize(title = nil, size = [640, 480], opts = {}) ⇒ Window

Returns a new instance of Window.



6
7
8
# File 'lib/ray/window.rb', line 6

def initialize(title = nil, size = [640, 480], opts = {})
  open(title, size, opts) if title
end

Instance Method Details

#closeObject

Closes the window



64
65
66
67
68
# File 'ext/window.c', line 64

static
VALUE ray_window_close(VALUE self) {
  say_window_close(ray_rb2window(self));
  return self;
}

#each_event {|event| ... } ⇒ Object

Yield Parameters:

  • event (Ray::Event)

    Each event to be processed



13
14
15
16
17
18
19
20
21
# File 'lib/ray/window.rb', line 13

def each_event
  return Enumerator.new(self, :each_event) unless block_given?

  ev = Ray::Event.new

  until poll_event(ev).type == Ray::Event::TypeNone
    yield ev
  end
end

#hide_cursorObject

Hides the window cursor



127
128
129
130
131
# File 'ext/window.c', line 127

static
VALUE ray_window_hide_cursor(VALUE self) {
  say_window_hide_cursor(ray_rb2window(self));
  return self;
}

#icon=(icon) ⇒ Object

Sets the icon used by the window

Parameters:



75
76
77
78
79
80
81
82
# File 'ext/window.c', line 75

static
VALUE ray_window_set_icon(VALUE self, VALUE icon) {
  if (!say_window_set_icon(ray_rb2window(self), ray_rb2image(icon))) {
    rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
  }

  return icon;
}

#inputRay::Input

Returns The input used by this object.

Returns:



158
159
160
161
# File 'ext/window.c', line 158

static
VALUE ray_window_input(VALUE self) {
  return ray_input2rb(say_window_get_input(ray_rb2window(self)), self);
}

#open(size, opts = {}) ⇒ Object

Parameters:

Options Hash (opts):

  • :resizable (true, false) — default: false

    whether the window can be resized.

  • :no_frame (true, false) — default: false

    whether the window should be decorated.

  • :fullscreen (true, false) — default: false

    whether the window should be fullscreen.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/window.c', line 34

static
VALUE ray_window_open(int argc, VALUE *argv, VALUE self) {
  VALUE title = Qnil, size = Qnil, opts = Qnil;
  rb_scan_args(argc, argv, "21", &title, &size, &opts);

  say_window *window = ray_rb2window(self);

  uint8_t flags = 0;
  if (!NIL_P(opts)) {
    if (RTEST(rb_hash_aref(opts, RAY_SYM("resizable"))))
      flags |= SAY_WINDOW_RESIZABLE;

    if (RTEST(rb_hash_aref(opts, RAY_SYM("no_frame"))))
      flags |= SAY_WINDOW_NO_FRAME;

    if (RTEST(rb_hash_aref(opts, RAY_SYM("fullscreen"))))
      flags |= SAY_WINDOW_FULLSCREEN;
  }

  say_vector2 c_size = ray_convert_to_vector2(size);

  if (!say_window_open(window, c_size.x, c_size.y,
                       StringValuePtr(title), flags)) {
    rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
  }

  return self;
}

#poll_event(ev) ⇒ Object

Gets the next event from the event queue. If there’s none, return directly.

Parameters:

  • ev (Ray::Event)

    Event object to store the result into.



138
139
140
141
142
# File 'ext/window.c', line 138

static
VALUE ray_window_poll_event(VALUE self, VALUE ev) {
  say_window_poll_event(ray_rb2window(self), ray_rb2event(ev));
  return ev;
}

#resize(size) ⇒ Object Also known as: size=

Resizes the window

Parameters:



100
101
102
103
104
105
106
107
108
# File 'ext/window.c', line 100

static
VALUE ray_window_resize(VALUE self, VALUE size) {
  say_vector2 c_size = ray_convert_to_vector2(size);
  if (!say_window_resize(ray_rb2window(self), c_size.x, c_size.y)) {
    rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
  }

  return size;
}

#show_cursorObject

Shows the window cursor



120
121
122
123
124
# File 'ext/window.c', line 120

static
VALUE ray_window_show_cursor(VALUE self) {
  say_window_show_cursor(ray_rb2window(self));
  return self;
}

#title=(title) ⇒ Object

Sets the title of the window

Parameters:

  • title (String)


89
90
91
92
93
# File 'ext/window.c', line 89

static
VALUE ray_window_set_title(VALUE self, VALUE title) {
  say_window_set_title(ray_rb2window(self), StringValuePtr(title));
  return title;
}

#updateObject

Updates the content of the window. Must be updated at the end of each frame.



113
114
115
116
117
# File 'ext/window.c', line 113

static
VALUE ray_window_update(VALUE self) {
  say_window_update(ray_rb2window(self));
  return self;
}

#wait_event(ev) ⇒ Object

Gets the next event from the event queue. If there’s none, waits until there’s one. Returns directly if the window is closed.

Parameters:

  • ev (Ray::Event)

    Event object to store the result into.



151
152
153
154
155
# File 'ext/window.c', line 151

static
VALUE ray_window_wait_event(VALUE self, VALUE ev) {
  say_window_wait_event(ray_rb2window(self), ray_rb2event(ev));
  return ev;
}