glfw 1.0.3 → 3.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +161 -0
  3. data/.yardopts +6 -0
  4. data/Gemfile +2 -4
  5. data/README.md +29 -33
  6. data/Rakefile +6 -4
  7. data/ext/glfw/common.c +159 -0
  8. data/ext/glfw/cursor.c +34 -30
  9. data/ext/glfw/extconf.rb +7 -17
  10. data/ext/glfw/glfw.c +122 -377
  11. data/ext/glfw/glfw.h +46 -41
  12. data/ext/glfw/image.c +96 -64
  13. data/ext/glfw/joystick.c +169 -0
  14. data/ext/glfw/monitor.c +231 -155
  15. data/ext/glfw/stb_image.h +7656 -0
  16. data/ext/glfw/window.c +708 -576
  17. data/glfw.gemspec +10 -9
  18. data/lib/glfw.rb +4 -14
  19. data/lib/glfw/constants.rb +365 -0
  20. data/lib/glfw/stubs.rb +234 -0
  21. data/lib/glfw/stubs/cursor.rb +21 -0
  22. data/lib/glfw/stubs/gamepad_state.rb +30 -0
  23. data/lib/glfw/stubs/image.rb +39 -0
  24. data/lib/glfw/stubs/joystick.rb +125 -0
  25. data/lib/glfw/stubs/monitor.rb +115 -0
  26. data/lib/glfw/stubs/video_mode.rb +32 -0
  27. data/lib/glfw/stubs/window.rb +626 -0
  28. data/lib/glfw/version.rb +8 -1
  29. metadata +31 -35
  30. data/.travis.yml +0 -5
  31. data/Makefile +0 -267
  32. data/ext/glfw/common.h +0 -46
  33. data/ext/glfw/cursor.h +0 -14
  34. data/ext/glfw/glfw3.h +0 -4248
  35. data/ext/glfw/glfw3native.h +0 -456
  36. data/ext/glfw/image.h +0 -14
  37. data/ext/glfw/ming32/WINDOWS USERS PLACE libglf3.a HERE.txt b/data/ext/glfw/ming32/WINDOWS USERS PLACE libglf3.a → HERE.txt +0 -0
  38. data/ext/glfw/ming64/WINDOWS USERS PLACE libglf3.a HERE.txt b/data/ext/glfw/ming64/WINDOWS USERS PLACE libglf3.a → HERE.txt +0 -0
  39. data/ext/glfw/monitor.h +0 -29
  40. data/ext/glfw/video_mode.c +0 -60
  41. data/ext/glfw/video_mode.h +0 -21
  42. data/ext/glfw/vulkan.c +0 -48
  43. data/ext/glfw/vulkan.h +0 -16
  44. data/ext/glfw/window.h +0 -87
@@ -1,708 +1,840 @@
1
1
 
2
- #include "window.h"
3
-
4
- VALUE rb_cGLFWwindow;
5
-
6
- ID id_moved;
7
- ID id_resized;
8
- ID id_framebuffer_resized;
9
- ID id_closing;
10
- ID id_refreshed;
11
- ID id_focus_changed;
12
- ID id_minimize_changed;
13
- ID id_mouse_move;
14
- ID id_mouse_scroll;
15
- ID id_mouse_button;
16
- ID id_mouse_enter;
17
- ID id_key;
18
- ID id_char;
19
- ID id_char_mods;
20
- ID id_file_drop;
21
-
22
- #define RB_CALLBACK(id, name) \
23
- id = rb_intern(name); \
24
- rb_define_method_id(rb_cGLFWwindow, id, rb_glfw_window_empty_method, -1)
25
-
26
- void Init_glfw_window(VALUE mmodule) {
27
- rb_cGLFWwindow = rb_define_class_under(rb_mGLFW, "Window", rb_cObject);
28
-
29
- rb_define_alloc_func(rb_cGLFWwindow, rb_glfw_window_alloc);
30
- rb_define_method(rb_cGLFWwindow, "initialize", rb_glfw_window_initialize, -1);
31
- rb_define_method(rb_cGLFWwindow, "destroy", rb_glfw_window_destroy, 0);
32
- rb_define_method(rb_cGLFWwindow, "show", rb_glfw_window_show, 0);
33
- rb_define_method(rb_cGLFWwindow, "hide", rb_glfw_window_hide, 0);
34
- rb_define_method(rb_cGLFWwindow, "minimize", rb_glfw_window_minimize, 0);
35
- rb_define_method(rb_cGLFWwindow, "maximize", rb_glfw_window_maximize, 0);
36
- rb_define_method(rb_cGLFWwindow, "restore", rb_glfw_window_restore, 0);
37
- rb_define_method(rb_cGLFWwindow, "focus", rb_glfw_window_focus, 0);
38
- rb_define_method(rb_cGLFWwindow, "closing?", rb_glfw_window_closing_p, 0);
39
- rb_define_method(rb_cGLFWwindow, "close", rb_glfw_window_close, -1);
40
-
41
- rb_define_method(rb_cGLFWwindow, "swap_buffers", rb_glfw_window_swap_buffers, 0);
42
- rb_define_method(rb_cGLFWwindow, "make_current", rb_glfw_window_make_current, 0);
43
- rb_define_method(rb_cGLFWwindow, "monitor", rb_glfw_window_get_monitor, 0);
44
- rb_define_method(rb_cGLFWwindow, "set_monitor", rb_glfw_window_set_monitor, -1);
45
-
46
- rb_define_method(rb_cGLFWwindow, "dimensions", rb_glfw_window_dimensions, 0);
47
- rb_define_method(rb_cGLFWwindow, "position", rb_glfw_window_get_pos, 0);
48
- rb_define_method(rb_cGLFWwindow, "move", rb_glfw_window_set_pos, 2);
49
- rb_define_method(rb_cGLFWwindow, "size", rb_glfw_window_get_size, 0);
50
- rb_define_method(rb_cGLFWwindow, "resize", rb_glfw_window_set_size, 2);
51
- rb_define_method(rb_cGLFWwindow, "framebuffer_size", rb_glfw_window_get_framebuffer_size, 0);
52
- rb_define_method(rb_cGLFWwindow, "x", rb_glfw_window_get_x, 0);
53
- rb_define_method(rb_cGLFWwindow, "y", rb_glfw_window_get_y, 0);
54
- rb_define_method(rb_cGLFWwindow, "width", rb_glfw_window_get_width, 0);
55
- rb_define_method(rb_cGLFWwindow, "height", rb_glfw_window_get_height, 0);
56
- rb_define_method(rb_cGLFWwindow, "x=", rb_glfw_window_set_x, 1);
57
- rb_define_method(rb_cGLFWwindow, "y=", rb_glfw_window_set_y, 1);
58
- rb_define_method(rb_cGLFWwindow, "width=", rb_glfw_window_set_width, 1);
59
- rb_define_method(rb_cGLFWwindow, "height=", rb_glfw_window_set_height, 1);
60
-
61
- rb_define_method(rb_cGLFWwindow, "focused?", rb_glfw_window_focused_p, 0);
62
- rb_define_method(rb_cGLFWwindow, "minimized?", rb_glfw_window_minimized_p, 0);
63
- rb_define_method(rb_cGLFWwindow, "maximized?", rb_glfw_window_maximized_p, 0);
64
- rb_define_method(rb_cGLFWwindow, "visible?", rb_glfw_window_visible_p, 0);
65
- rb_define_method(rb_cGLFWwindow, "resizable?", rb_glfw_window_resizable_p, 0);
66
- rb_define_method(rb_cGLFWwindow, "decorated?", rb_glfw_window_decorated_p, 0);
67
- rb_define_method(rb_cGLFWwindow, "topmost?", rb_glfw_window_floating_p, 0);
68
- rb_define_method(rb_cGLFWwindow, "set_icon", rb_glfw_window_set_icon, -2);
69
- rb_define_method(rb_cGLFWwindow, "enable_callback", rb_glfw_window_enable_callback, 2);
70
-
71
- rb_define_method(rb_cGLFWwindow, "aspect_ratio", rb_glfw_window_aspect_ratio, 2);
72
- rb_define_method(rb_cGLFWwindow, "size_limits", rb_glfw_window_limits, 4);
73
- rb_define_method(rb_cGLFWwindow, "frame_size", rb_glfw_window_frame_size, 0);
74
-
75
- rb_define_method(rb_cGLFWwindow, "set_cursor", rb_glfw_window_set_cursor, 1);
76
- rb_define_method(rb_cGLFWwindow, "cursor_pos", rb_glfw_window_cursor_pos, 0);
77
- rb_define_method(rb_cGLFWwindow, "set_cursor_pos", rb_glfw_window_set_cursor_pos, 2);
78
- rb_define_method(rb_cGLFWwindow, "cursor", rb_glfw_window_get_input_cursor, 0);
79
- rb_define_method(rb_cGLFWwindow, "cursor=", rb_glfw_window_set_input_cursor, 1);
80
- rb_define_method(rb_cGLFWwindow, "sticky_keys", rb_glfw_window_get_input_sticky_keys, 0);
81
- rb_define_method(rb_cGLFWwindow, "sticky_keys=", rb_glfw_window_set_input_sticky_keys, 1);
82
- rb_define_method(rb_cGLFWwindow, "sticky_mouse", rb_glfw_window_get_input_sticky_mouse, 0);
83
- rb_define_method(rb_cGLFWwindow, "sticky_mouse=", rb_glfw_window_set_input_sticky_mouse, 1);
84
-
85
- rb_define_method(rb_cGLFWwindow, "key_down?", rb_glfw_window_get_key, 1);
86
- rb_define_method(rb_cGLFWwindow, "mouse_down?", rb_glfw_window_get_mouse_button, 1);
87
-
88
- // Callbacks
89
- RB_CALLBACK(id_moved, "moved");
90
- RB_CALLBACK(id_refreshed, "resized");
91
- RB_CALLBACK(id_framebuffer_resized, "framebuffer_resized");
92
- RB_CALLBACK(id_closing, "closing");
93
- RB_CALLBACK(id_refreshed, "refreshed");
94
- RB_CALLBACK(id_focus_changed, "focus_changed");
95
- RB_CALLBACK(id_minimize_changed, "minimize_changed");
96
- RB_CALLBACK(id_mouse_move, "mouse_move");
97
- RB_CALLBACK(id_mouse_scroll, "mouse_scroll");
98
- RB_CALLBACK(id_mouse_button, "mouse_button");
99
- RB_CALLBACK(id_mouse_enter, "mouse_enter");
100
- RB_CALLBACK(id_key, "key");
101
- RB_CALLBACK(id_char, "char");
102
- RB_CALLBACK(id_char_mods, "char_mods");
103
- RB_CALLBACK(id_file_drop, "file_drop");
104
-
105
- // Alias
106
- rb_define_alias(rb_cGLFWwindow, "dispose", "destroy");
107
- rb_define_alias(rb_cGLFWwindow, "iconify", "minimize");
108
- rb_define_alias(rb_cGLFWwindow, "floating?", "topmost?");
109
- rb_define_alias(rb_cGLFWwindow, "iconified?", "minimized?");
110
- rb_define_alias(rb_cGLFWwindow, "iconify_changed", "minimize_changed");
111
- }
112
-
113
- static VALUE rb_glfw_window_alloc(VALUE klass) {
114
- GLFWwindow *w = ruby_xmalloc(SIZEOF_INTPTR_T);
115
- memset(w, 0, SIZEOF_INTPTR_T);
116
- return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, w);
117
- }
118
-
119
- // initialize(width, height, title = '', **options)
120
- VALUE rb_glfw_window_initialize(int argc, VALUE *argv, VALUE self) {
121
- // Initialize GLFW (does nothing and returns immediately if already called)
122
- glfwInit();
123
-
124
- GLFWmonitor *mon = NULL;
125
- GLFWwindow *window, *other = NULL;
126
-
127
- VALUE width, height, title, options, monitor, share;
128
-
129
- rb_scan_args(argc, argv, "21:", &width, &height, &title, &options);
130
- const char *str = NIL_P(title) ? "" : StringValueCStr(title);
131
-
132
- if (!NIL_P(options)) {
133
- // Monitor
134
- if (RTEST(rb_hash_aref(options, STR2SYM("fullscreen")))) {
135
- mon = glfwGetPrimaryMonitor();
136
- } else {
137
- monitor = rb_hash_aref(options, STR2SYM("monitor"));
138
- if (!NIL_P(monitor))
139
- Data_Get_Struct(monitor, GLFWmonitor, mon);
140
- }
2
+ #include "glfw.h"
3
+
4
+ #define CB_WINDOW_RESIZE (0)
5
+ #define CB_FRAMEBUFFER_RESIZE (1)
6
+ #define CB_WINDOW_MOVE (2)
7
+ #define CB_WINDOW_CLOSE (3)
8
+ #define CB_WINDOW_REFRESH (4)
9
+ #define CB_WINDOW_FOCUS (5)
10
+ #define CB_WINDOW_MINIMIZE (6)
11
+ #define CB_WINDOW_MAXIMIZE (7)
12
+ #define CB_WINDOW_FILE_DROP (8)
13
+ #define CB_CURSOR_MOVE (9)
14
+ #define CB_SCROLL (10)
15
+ #define CB_KEY (11)
16
+ #define CB_BUTTON (12)
17
+ #define CB_CURSOR_ENTER (13)
18
+ #define CB_CHAR (14)
19
+ #define CB_WINDOW_SCALE (15)
20
+
21
+ #define CB_COUNT (16)
22
+
23
+ #define GET_WINDOW_ATTRIB(name, constant, to_ruby) \
24
+ static VALUE name(VALUE self) \
25
+ { \
26
+ return to_ruby(glfwGetWindowAttrib(DATA_PTR(self), constant)); \
27
+ }
141
28
 
142
- // Share
143
- share = rb_hash_aref(options, STR2SYM("share"));
144
- if (!NIL_P(share))
145
- Data_Get_Struct(share, GLFWwindow, other);
29
+ #define SET_WINDOW_ATTRIB(name, constant, to_c) \
30
+ static VALUE name(VALUE self, VALUE value) \
31
+ { \
32
+ glfwSetWindowAttrib(DATA_PTR(self), constant, to_c(value)); \
33
+ return value; \
146
34
  }
147
35
 
148
- window = glfwCreateWindow(NUM2INT(width), NUM2INT(height), str, mon, other);
149
- RDATA(self)->data = window;
36
+ #define WINDOW_ATTRIBUTE(name, constant, to_ruby, to_c) \
37
+ GET_WINDOW_ATTRIB(rb_glfw_window_get_##name, constant, to_ruby) \
38
+ SET_WINDOW_ATTRIB(rb_glfw_window_set_##name, constant, to_c)
39
+
40
+ #define CALLBACK_PROC(name, glfw_callback, index) \
41
+ static VALUE rb_glfw_window_on_##name(VALUE self) \
42
+ { \
43
+ GLFWwindow *window = DATA_PTR(self); \
44
+ GLFWruby *data = glfwGetWindowUserPointer(window); \
45
+ VALUE current = data->procs[index]; \
46
+ if (rb_block_given_p()) \
47
+ { \
48
+ data->procs[index] = rb_block_proc(); \
49
+ glfw_callback(window, rb_glfw_window_cb_##name); \
50
+ } \
51
+ else \
52
+ { \
53
+ data->procs[index] = Qnil; \
54
+ glfw_callback(window, NULL); \
55
+ } \
56
+ return RTEST(current) ? current : Qnil; \
57
+ }
150
58
 
151
- // Store the Ruby VALUE as a "user pointer" to get the Ruby instance from the C struct
152
- glfwSetWindowUserPointer(window, (void *)self);
59
+ #define WINDOW_INPUT_ATTR(name, constant) \
60
+ static VALUE rb_glfw_window_get_##name(VALUE self) \
61
+ { \
62
+ return RB_BOOL(glfwGetInputMode(DATA_PTR(self), constant)); \
63
+ } \
64
+ static VALUE rb_glfw_window_set_##name(VALUE self, VALUE value) \
65
+ { \
66
+ glfwSetInputMode(DATA_PTR(self), constant, RTEST(value)); \
67
+ return value; \
68
+ }
153
69
 
154
- if (rb_block_given_p()) {
155
- rb_yield(self);
156
- glfwDestroyWindow(window);
70
+ WINDOW_INPUT_ATTR(sticky_keys, GLFW_STICKY_KEYS)
71
+ WINDOW_INPUT_ATTR(sticky_buttons, GLFW_STICKY_MOUSE_BUTTONS)
72
+ WINDOW_INPUT_ATTR(lock_modifiers, GLFW_LOCK_KEY_MODS)
73
+ WINDOW_INPUT_ATTR(raw_mouse_motion, GLFW_RAW_MOUSE_MOTION)
74
+
75
+ typedef struct
76
+ {
77
+ VALUE window;
78
+ VALUE title;
79
+ VALUE icon;
80
+ VALUE cursor;
81
+ VALUE procs[CB_COUNT];
82
+ } GLFWruby;
83
+
84
+ VALUE cWindow;
85
+
86
+ static void rb_glfw_window_mark(void *window)
87
+ {
88
+ if (window)
89
+ {
90
+ GLFWruby *data = glfwGetWindowUserPointer(window);
91
+ if (data)
92
+ {
93
+ rb_gc_mark(data->window);
94
+ if (RTEST(data->title))
95
+ rb_gc_mark(data->title);
96
+ if (RTEST(data->icon))
97
+ rb_gc_mark(data->icon);
98
+ if (RTEST(data->cursor))
99
+ rb_gc_mark(data->cursor);
100
+ for (int i = 0; i < CB_COUNT; i++)
101
+ {
102
+ if (RTEST(data->procs[i]))
103
+ rb_gc_mark(data->procs[i]);
104
+ }
105
+ }
157
106
  }
107
+ }
158
108
 
159
- return Qnil;
109
+ static void rb_glfw_window_cb_framebuffer_resize(GLFWwindow *window, int width, int height)
110
+ {
111
+ GLFWruby *data = glfwGetWindowUserPointer(window);
112
+ if (RTEST(data->procs[CB_FRAMEBUFFER_RESIZE]))
113
+ {
114
+ rb_proc_call(data->procs[CB_FRAMEBUFFER_RESIZE], rb_ary_new_from_args(2, INT2NUM(width), INT2NUM(height)));
115
+ }
160
116
  }
161
117
 
162
- VALUE rb_glfw_window_destroy(VALUE self) {
163
- WINDOW();
164
- glfwDestroyWindow(w);
165
- return self;
118
+ static void rb_glfw_window_cb_resize(GLFWwindow *window, int width, int height)
119
+ {
120
+ GLFWruby *data = glfwGetWindowUserPointer(window);
121
+ if (RTEST(data->procs[CB_WINDOW_RESIZE]))
122
+ {
123
+ rb_proc_call(data->procs[CB_WINDOW_RESIZE], rb_ary_new_from_args(2, INT2NUM(width), INT2NUM(height)));
124
+ }
166
125
  }
167
126
 
168
- VALUE rb_glfw_window_show(VALUE self) {
169
- WINDOW();
170
- glfwShowWindow(w);
171
- return self;
127
+ static void rb_glfw_window_cb_move(GLFWwindow *window, int x, int y)
128
+ {
129
+ GLFWruby *data = glfwGetWindowUserPointer(window);
130
+ if (RTEST(data->procs[CB_WINDOW_MOVE]))
131
+ {
132
+ rb_proc_call(data->procs[CB_WINDOW_MOVE], rb_ary_new_from_args(2, INT2NUM(x), INT2NUM(y)));
133
+ }
172
134
  }
173
135
 
174
- VALUE rb_glfw_window_hide(VALUE self) {
175
- WINDOW();
176
- glfwHideWindow(w);
177
- return self;
136
+ static void rb_glfw_window_cb_focus(GLFWwindow *window, int focused)
137
+ {
138
+ GLFWruby *data = glfwGetWindowUserPointer(window);
139
+ if (RTEST(data->procs[CB_WINDOW_FOCUS]))
140
+ {
141
+ rb_proc_call(data->procs[CB_WINDOW_FOCUS], rb_ary_new_from_args(1, RB_BOOL(focused)));
142
+ }
178
143
  }
179
144
 
180
- VALUE rb_glfw_window_minimize(VALUE self) {
181
- WINDOW();
182
- glfwIconifyWindow(w);
183
- return self;
145
+ static void rb_glfw_window_cb_close(GLFWwindow *window)
146
+ {
147
+ GLFWruby *data = glfwGetWindowUserPointer(window);
148
+ if (RTEST(data->procs[CB_WINDOW_CLOSE]))
149
+ {
150
+ rb_proc_call(data->procs[CB_WINDOW_CLOSE], rb_ary_new());
151
+ }
184
152
  }
185
153
 
186
- VALUE rb_glfw_window_maximize(VALUE self) {
187
- WINDOW();
188
- glfwMaximizeWindow(w);
189
- return self;
154
+ static void rb_glfw_window_cb_refresh(GLFWwindow *window)
155
+ {
156
+ GLFWruby *data = glfwGetWindowUserPointer(window);
157
+ if (RTEST(data->procs[CB_WINDOW_REFRESH]))
158
+ {
159
+ rb_proc_call(data->procs[CB_WINDOW_REFRESH], rb_ary_new());
160
+ }
190
161
  }
191
162
 
192
- VALUE rb_glfw_window_restore(VALUE self) {
193
- WINDOW();
194
- glfwRestoreWindow(w);
195
- return self;
163
+ static void rb_glfw_window_cb_minimize(GLFWwindow *window, int minimized)
164
+ {
165
+ GLFWruby *data = glfwGetWindowUserPointer(window);
166
+ if (RTEST(data->procs[CB_WINDOW_MINIMIZE]))
167
+ {
168
+ rb_proc_call(data->procs[CB_WINDOW_MINIMIZE], rb_ary_new_from_args(1, RB_BOOL(minimized)));
169
+ }
196
170
  }
197
171
 
198
- VALUE rb_glfw_window_focus(VALUE self) {
199
- WINDOW();
200
- glfwFocusWindow(w);
201
- return self;
172
+ static void rb_glfw_window_cb_maximize(GLFWwindow *window, int maximized)
173
+ {
174
+ GLFWruby *data = glfwGetWindowUserPointer(window);
175
+ if (RTEST(data->procs[CB_WINDOW_MAXIMIZE]))
176
+ {
177
+ rb_proc_call(data->procs[CB_WINDOW_MAXIMIZE], rb_ary_new_from_args(1, RB_BOOL(maximized)));
178
+ }
202
179
  }
203
180
 
204
- VALUE rb_glfw_window_swap_buffers(VALUE self) {
205
- WINDOW();
206
- glfwSwapBuffers(w);
207
- return Qnil;
181
+ static void rb_glfw_window_cb_file_drop(GLFWwindow *window, int count, const char **paths)
182
+ {
183
+ GLFWruby *data = glfwGetWindowUserPointer(window);
184
+ if (RTEST(data->procs[CB_WINDOW_FILE_DROP]))
185
+ {
186
+ VALUE ary = rb_ary_new_capa(count);
187
+ for (int i = 0; i < count; i++)
188
+ {
189
+ rb_ary_store(ary, i, rb_str_new_cstr(paths[i]));
190
+ }
191
+ rb_proc_call(data->procs[CB_WINDOW_FILE_DROP], rb_ary_new_from_args(1, ary));
192
+ }
208
193
  }
209
194
 
210
- VALUE rb_glfw_window_make_current(VALUE self) {
211
- WINDOW();
212
- glfwMakeContextCurrent(w);
213
- return Qnil;
195
+ static void rb_glfw_window_cb_cursor_move(GLFWwindow *window, double x, double y)
196
+ {
197
+ GLFWruby *data = glfwGetWindowUserPointer(window);
198
+ if (RTEST(data->procs[CB_CURSOR_MOVE]))
199
+ {
200
+ rb_proc_call(data->procs[CB_CURSOR_MOVE], rb_ary_new_from_args(2, DBL2NUM(x), DBL2NUM(y)));
201
+ }
214
202
  }
215
203
 
216
- VALUE rb_glfw_window_dimensions(VALUE self) {
217
- WINDOW();
218
- int x, y, width, height;
219
- glfwGetWindowPos(w, &x, &y);
220
- glfwGetWindowSize(w, &width, &height);
221
- VALUE ary = rb_ary_new_capa(4);
222
- rb_ary_store(ary, 0, INT2NUM(x));
223
- rb_ary_store(ary, 1, INT2NUM(y));
224
- rb_ary_store(ary, 2, INT2NUM(width));
225
- rb_ary_store(ary, 3, INT2NUM(height));
226
- return ary;
204
+ static void rb_glfw_window_cb_scroll(GLFWwindow *window, double x, double y)
205
+ {
206
+ GLFWruby *data = glfwGetWindowUserPointer(window);
207
+ if (RTEST(data->procs[CB_SCROLL]))
208
+ {
209
+ rb_proc_call(data->procs[CB_SCROLL], rb_ary_new_from_args(2, DBL2NUM(x), DBL2NUM(y)));
210
+ }
227
211
  }
228
212
 
229
- VALUE rb_glfw_window_get_pos(VALUE self) {
230
- WINDOW();
231
- int x, y;
232
- glfwGetWindowPos(*&w, &x, &y);
233
- VALUE ary = rb_ary_new_capa(2);
234
- rb_ary_store(ary, 0, INT2NUM(x));
235
- rb_ary_store(ary, 1, INT2NUM(y));
236
- return ary;
213
+ static void rb_glfw_window_cb_key(GLFWwindow *window, int key, int scancode, int action, int mods)
214
+ {
215
+ GLFWruby *data = glfwGetWindowUserPointer(window);
216
+ if (RTEST(data->procs[CB_KEY]))
217
+ {
218
+ VALUE args = rb_ary_new_from_args(4, INT2NUM(key), INT2NUM(scancode), INT2NUM(action), INT2NUM(mods));
219
+ rb_proc_call(data->procs[CB_KEY], args);
220
+ }
237
221
  }
238
222
 
239
- VALUE rb_glfw_window_set_pos(VALUE self, VALUE x, VALUE y) {
240
- WINDOW();
241
- glfwSetWindowPos(w, NUM2INT(x), NUM2INT(y));
242
- return self;
223
+ static void rb_glfw_window_cb_mouse_button(GLFWwindow *window, int key, int action, int mods)
224
+ {
225
+ GLFWruby *data = glfwGetWindowUserPointer(window);
226
+ if (RTEST(data->procs[CB_BUTTON]))
227
+ {
228
+ VALUE args = rb_ary_new_from_args(3, INT2NUM(key), INT2NUM(action), INT2NUM(mods));
229
+ rb_proc_call(data->procs[CB_BUTTON], args);
230
+ }
243
231
  }
244
232
 
245
- VALUE rb_glfw_window_get_size(VALUE self) {
246
- WINDOW();
247
- int width, height;
248
- glfwGetWindowSize(w, &width, &height);
249
- VALUE ary = rb_ary_new_capa(2);
250
- rb_ary_store(ary, 0, INT2NUM(width));
251
- rb_ary_store(ary, 1, INT2NUM(height));
252
- return ary;
233
+ static void rb_glfw_window_cb_cursor_enter(GLFWwindow *window, int entered)
234
+ {
235
+ GLFWruby *data = glfwGetWindowUserPointer(window);
236
+ if (RTEST(data->procs[CB_CURSOR_ENTER]))
237
+ {
238
+ rb_proc_call(data->procs[CB_CURSOR_ENTER], rb_ary_new_from_args(1, RB_BOOL(entered)));
239
+ }
253
240
  }
254
241
 
255
- VALUE rb_glfw_window_set_size(VALUE self, VALUE width, VALUE height) {
256
- WINDOW();
257
- glfwSetWindowSize(w, NUM2INT(width), NUM2INT(height));
258
- return self;
242
+ static void rb_glfw_window_cb_char(GLFWwindow *window, unsigned int codepoint)
243
+ {
244
+ GLFWruby *data = glfwGetWindowUserPointer(window);
245
+ if (RTEST(data->procs[CB_CHAR]))
246
+ {
247
+ rb_proc_call(data->procs[CB_CHAR], rb_ary_new_from_args(1, UINT2NUM(codepoint)));
248
+ }
259
249
  }
260
250
 
261
- VALUE rb_glfw_window_get_framebuffer_size(VALUE self) {
262
- WINDOW();
263
- int width, height;
264
- glfwGetFramebufferSize(w, &width, &height);
265
- VALUE ary = rb_ary_new_capa(2);
266
- rb_ary_store(ary, 0, INT2NUM(width));
267
- rb_ary_store(ary, 1, INT2NUM(height));
268
- return ary;
269
- }
270
-
271
- VALUE rb_glfw_window_get_x(VALUE self) {
272
- WINDOW();
273
- int x;
274
- glfwGetWindowPos(w, &x, NULL);
275
- return INT2NUM(x);
276
- }
277
-
278
- VALUE rb_glfw_window_get_y(VALUE self) {
279
- WINDOW();
280
- int y;
281
- glfwGetWindowPos(w, NULL, &y);
282
- return INT2NUM(y);
283
- }
284
-
285
- VALUE rb_glfw_window_set_x(VALUE self, VALUE x) {
286
- WINDOW();
287
- int y;
288
- glfwGetWindowSize(w, NULL, &y);
289
- glfwSetWindowSize(w, NUM2INT(x), y);
290
- return x;
291
- }
292
-
293
- VALUE rb_glfw_window_set_y(VALUE self, VALUE y) {
294
- WINDOW();
295
- int x;
296
- glfwGetWindowSize(w, &x, NULL);
297
- glfwSetWindowSize(w, x, NUM2INT(y));
298
- return y;
299
- }
300
-
301
- VALUE rb_glfw_window_get_width(VALUE self) {
302
- WINDOW();
303
- int width;
304
- glfwGetWindowSize(w, &width, NULL);
305
- return INT2NUM(width);
306
- }
307
-
308
- VALUE rb_glfw_window_get_height(VALUE self) {
309
- WINDOW();
310
- int height;
311
- glfwGetWindowSize(w, NULL, &height);
312
- return INT2NUM(height);
313
- }
314
-
315
- VALUE rb_glfw_window_set_width(VALUE self, VALUE width) {
316
- WINDOW();
317
- int height;
318
- glfwGetWindowSize(w, NULL, &height);
319
- glfwSetWindowSize(w, NUM2INT(width), height);
320
- return width;
321
- }
322
-
323
- VALUE rb_glfw_window_set_height(VALUE self, VALUE height) {
324
- WINDOW();
325
- int width;
326
- glfwGetWindowSize(w, &width, NULL);
327
- glfwSetWindowSize(w, width, NUM2INT(height));
328
- return height;
329
- }
330
-
331
- VALUE rb_glfw_window_closing_p(VALUE self) {
332
- WINDOW();
333
- return glfwWindowShouldClose(w) ? Qtrue : Qfalse;
334
- }
335
-
336
- VALUE rb_glfw_window_close(int argc, VALUE *argv, VALUE self) {
337
- WINDOW();
338
- switch (argc) {
339
- case 0:
340
- glfwSetWindowShouldClose(w, 1);
341
- break;
342
- case 1:
343
- glfwSetWindowShouldClose(w, RTEST(argv[0]));
344
- break;
345
- default:
346
- rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0, 1)", argc);
347
- break;
251
+ static void rb_glfw_window_cb_scale(GLFWwindow *window, float x, float y)
252
+ {
253
+ GLFWruby *data = glfwGetWindowUserPointer(window);
254
+ if (RTEST(data->procs[CB_WINDOW_SCALE]))
255
+ {
256
+ rb_proc_call(data->procs[CB_WINDOW_SCALE], rb_ary_new_from_args(2, DBL2NUM(x), DBL2NUM(y)));
348
257
  }
349
- return self;
350
258
  }
351
259
 
352
- VALUE rb_glfw_window_get_monitor(VALUE self) {
353
- WINDOW();
354
- GLFWmonitor *monitor = glfwGetWindowMonitor(w);
355
- return Data_Wrap_Struct(rb_cGLFWmonitor, NULL, RUBY_DEFAULT_FREE, monitor);
260
+ CALLBACK_PROC(resize, glfwSetWindowSizeCallback, CB_WINDOW_RESIZE)
261
+ CALLBACK_PROC(framebuffer_resize, glfwSetFramebufferSizeCallback, CB_FRAMEBUFFER_RESIZE)
262
+ CALLBACK_PROC(move, glfwSetWindowPosCallback, CB_WINDOW_MOVE)
263
+ CALLBACK_PROC(focus, glfwSetWindowFocusCallback, CB_WINDOW_FOCUS)
264
+ CALLBACK_PROC(close, glfwSetWindowCloseCallback, CB_WINDOW_CLOSE)
265
+ CALLBACK_PROC(refresh, glfwSetWindowRefreshCallback, CB_WINDOW_REFRESH)
266
+ CALLBACK_PROC(minimize, glfwSetWindowIconifyCallback, CB_WINDOW_MINIMIZE)
267
+ CALLBACK_PROC(maximize, glfwSetWindowMaximizeCallback, CB_WINDOW_MAXIMIZE)
268
+ CALLBACK_PROC(file_drop, glfwSetDropCallback, CB_WINDOW_FILE_DROP)
269
+ CALLBACK_PROC(cursor_move, glfwSetCursorPosCallback, CB_CURSOR_MOVE)
270
+ CALLBACK_PROC(scroll, glfwSetScrollCallback, CB_SCROLL)
271
+ CALLBACK_PROC(key, glfwSetKeyCallback, CB_KEY)
272
+ CALLBACK_PROC(mouse_button, glfwSetMouseButtonCallback, CB_BUTTON)
273
+ CALLBACK_PROC(cursor_enter, glfwSetCursorEnterCallback, CB_CURSOR_ENTER)
274
+ CALLBACK_PROC(char, glfwSetCharCallback, CB_CHAR)
275
+ CALLBACK_PROC(scale, glfwSetWindowContentScaleCallback, CB_WINDOW_SCALE)
276
+
277
+ static VALUE rb_glfw_window_alloc(VALUE klass)
278
+ {
279
+ // GLFW handles allocating/freeing window pointers
280
+ return Data_Wrap_Struct(klass, rb_glfw_window_mark, NULL, NULL);
281
+ }
282
+
283
+ static VALUE rb_glfw_window_default_hints(VALUE glfw)
284
+ {
285
+ glfwDefaultWindowHints();
286
+ return Qnil;
356
287
  }
357
288
 
358
- VALUE rb_glfw_window_set_monitor(int argc, VALUE *argv, VALUE self) {
359
- WINDOW();
360
- switch (argc) {
361
- case 2: // monitor, refresh_rate (fullscreen)
362
- {
363
- GLFWmonitor *m = NULL;
364
- Data_Get_Struct(argv[0], GLFWmonitor, m);
365
- glfwSetWindowMonitor(w, m, 0, 0, 0, 0, NUM2INT(argv[1]));
366
- break;
367
- }
368
- case 4: // x, y, width, height (windowed)
369
- {
370
- int mx = NUM2INT(argv[0]), my = NUM2INT(argv[1]), mw = NUM2INT(argv[2]), mh = NUM2INT(argv[3]);
371
- glfwSetWindowMonitor(w, NULL, mx, my, mw, mh, 0);
372
- break;
373
- }
374
- default:
375
- rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 2, 4)", argc);
376
- break;
289
+ static VALUE rb_glfw_window_hint(VALUE glfw, VALUE hint, VALUE value)
290
+ {
291
+ int h = NUM2INT(hint);
292
+
293
+ if (FIXNUM_P(value))
294
+ {
295
+ glfwWindowHint(h, NUM2INT(value));
296
+ }
297
+ else if (RB_TYPE_P(value, T_STRING))
298
+ {
299
+ glfwWindowHintString(h, StringValueCStr(value));
300
+ }
301
+ else
302
+ {
303
+ glfwWindowHint(h, RTEST(value));
377
304
  }
378
- return self;
379
- }
380
305
 
381
- VALUE rb_glfw_window_set_title(VALUE self, volatile VALUE title) {
382
- WINDOW();
383
- const char *str = rb_string_value_cstr(&title);
384
- glfwSetWindowTitle(w, str);
385
- return title;
306
+ return Qnil;
386
307
  }
387
308
 
388
- VALUE rb_glfw_window_focused_p(VALUE self) {
389
- WINDOW();
390
- return glfwGetWindowAttrib(w, GLFW_FOCUSED) ? Qtrue : Qfalse;
391
- }
309
+ static VALUE rb_glfw_window_eql(VALUE self, VALUE other)
310
+ {
311
+ if (CLASS_OF(self) != CLASS_OF(other))
312
+ return Qfalse;
392
313
 
393
- VALUE rb_glfw_window_minimized_p(VALUE self) {
394
- WINDOW();
395
- return glfwGetWindowAttrib(w, GLFW_ICONIFIED) ? Qtrue : Qfalse;
314
+ return RB_BOOL(DATA_PTR(self) == DATA_PTR(other));
396
315
  }
397
316
 
398
- VALUE rb_glfw_window_maximized_p(VALUE self) {
399
- WINDOW();
400
- return glfwGetWindowAttrib(w, GLFW_MAXIMIZED) ? Qtrue : Qfalse;
317
+ static VALUE rb_glfw_window_current(VALUE klass)
318
+ {
319
+ GLFWwindow *window = glfwGetCurrentContext();
320
+ return window ? Data_Wrap_Struct(klass, NULL, NULL, window) : Qnil;
401
321
  }
402
322
 
403
- VALUE rb_glfw_window_visible_p(VALUE self) {
404
- WINDOW();
405
- return glfwGetWindowAttrib(w, GLFW_VISIBLE) ? Qtrue : Qfalse;
323
+ static VALUE rb_glfw_window_make_current(VALUE self)
324
+ {
325
+ glfwMakeContextCurrent(DATA_PTR(self));
326
+ return self;
406
327
  }
407
328
 
408
- VALUE rb_glfw_window_resizable_p(VALUE self) {
409
- WINDOW();
410
- return glfwGetWindowAttrib(w, GLFW_RESIZABLE) ? Qtrue : Qfalse;
329
+ static VALUE rb_glfw_window_center(VALUE self)
330
+ {
331
+ GLFWwindow *window = DATA_PTR(self);
332
+ GLFWmonitor *monitor = glfwGetWindowMonitor(window);
333
+
334
+ // If monitor is not NULL, then window is fullscreen, do nothing.
335
+ if (!monitor)
336
+ {
337
+ monitor = glfwGetPrimaryMonitor();
338
+
339
+ int x, y, w, h, width, height;
340
+ glfwGetMonitorWorkarea(monitor, &x, &y, &w, &h);
341
+ glfwGetWindowSize(window, &width, &height);
342
+
343
+ x += ((w - width) / 2);
344
+ y += ((h - height) / 2);
345
+ glfwSetWindowPos(window, x, y);
346
+ }
347
+ return self;
411
348
  }
412
349
 
413
- VALUE rb_glfw_window_decorated_p(VALUE self) {
414
- WINDOW();
415
- return glfwGetWindowAttrib(w, GLFW_DECORATED) ? Qtrue : Qfalse;
350
+ static VALUE rb_glfw_window_get_opacity(VALUE self)
351
+ {
352
+ return DBL2NUM(glfwGetWindowOpacity(DATA_PTR(self)));
416
353
  }
417
354
 
418
- VALUE rb_glfw_window_floating_p(VALUE self) {
419
- WINDOW();
420
- return glfwGetWindowAttrib(w, GLFW_FLOATING) ? Qtrue : Qfalse;
355
+ static VALUE rb_glfw_window_set_opacity(VALUE self, VALUE value)
356
+ {
357
+ glfwSetWindowOpacity(DATA_PTR(self), NUM2FLT(value));
358
+ return value;
421
359
  }
422
360
 
423
- VALUE rb_glfw_window_aspect_ratio(VALUE self, VALUE numerator, VALUE denominator) {
424
- WINDOW();
425
- glfwSetWindowAspectRatio(w, NUM2INT(numerator), NUM2INT(denominator));
361
+ static VALUE rb_glfw_window_initialize(int argc, VALUE *argv, VALUE self)
362
+ {
363
+ if (!glfwInit())
364
+ rb_raise(eGLFWError, "failed to initialize GLFW");
365
+
366
+ VALUE w, h, title, opts;
367
+ rb_scan_args(argc, argv, "21:", &w, &h, &title, &opts);
368
+
369
+ // Validate width/height
370
+ int width, height;
371
+ width = NUM2INT(w);
372
+ height = NUM2INT(h);
373
+ if (width < 1)
374
+ rb_raise(rb_eArgError, "width must be greater than 0");
375
+ if (height < 1)
376
+ rb_raise(rb_eArgError, "height must be greater than 0");
377
+
378
+ GLFWwindow *window = NULL;
379
+ GLFWmonitor *monitor = NULL;
380
+ GLFWwindow *shared = NULL;
381
+
382
+ int center = GLFW_TRUE;
383
+ int vsync = GLFW_TRUE;
384
+
385
+ if (RTEST(opts))
386
+ {
387
+ VALUE opt = rb_hash_aref(opts, STR2SYM("center"));
388
+ if (opt != Qnil)
389
+ center = opt != Qfalse;
390
+
391
+ opt = rb_hash_aref(opts, STR2SYM("vsync"));
392
+ if (opt != Qnil)
393
+ vsync = opt != Qfalse;
394
+
395
+ opt = rb_hash_aref(opts, STR2SYM("monitor"));
396
+ if (RTEST(opt))
397
+ monitor = DATA_PTR(opt);
398
+
399
+ opt = rb_hash_aref(opts, STR2SYM("shared"));
400
+ if (RTEST(shared))
401
+ shared = DATA_PTR(opt);
402
+
403
+ if (RTEST(rb_hash_aref(opts, STR2SYM("full_window"))))
404
+ {
405
+ if (!monitor)
406
+ monitor = glfwGetPrimaryMonitor();
407
+ const GLFWvidmode *mode = glfwGetVideoMode(monitor);
408
+
409
+ glfwWindowHint(GLFW_RED_BITS, mode->redBits);
410
+ glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
411
+ glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
412
+ glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
413
+ width = mode->width;
414
+ height = mode->height;
415
+ }
416
+ else if (RTEST(rb_hash_aref(opts, STR2SYM("fullscreen"))) && !monitor)
417
+ {
418
+ monitor = glfwGetPrimaryMonitor();
419
+ }
420
+ }
421
+
422
+ const char *caption = RTEST(title) ? StringValueCStr(title) : "";
423
+ window = glfwCreateWindow(width, height, caption, monitor, shared);
424
+ if (!window)
425
+ rb_raise(eGLFWError, "failed to create OpenGL context");
426
+
427
+ GLFWruby *data = ALLOC(GLFWruby);
428
+ memset(data, 0, sizeof(GLFWruby));
429
+ data->window = self;
430
+ data->title = title;
431
+ glfwSetWindowUserPointer(window, data);
432
+
433
+ RDATA(self)->data = window;
434
+ glfwMakeContextCurrent(window);
435
+
436
+ if (vsync)
437
+ glfwSwapInterval(1);
438
+ if (center)
439
+ rb_glfw_window_center(self);
440
+
441
+ if (rb_block_given_p())
442
+ {
443
+ rb_yield(self);
444
+ glfwDestroyWindow(window);
445
+ }
446
+
426
447
  return Qnil;
427
448
  }
428
449
 
429
- VALUE rb_glfw_window_limits(VALUE self, VALUE minWidth, VALUE minHeight, VALUE maxWidth, VALUE maxHeight) {
430
- WINDOW();
431
- glfwSetWindowSizeLimits(w, NUM2INT(minWidth), NUM2INT(minHeight), NUM2INT(maxWidth), NUM2INT(maxHeight));
432
- return Qnil;
450
+ static VALUE rb_glfw_window_close(int argc, VALUE *argv, VALUE self)
451
+ {
452
+ int close = argc > 0 ? RTEST(argv[0]) : GLFW_TRUE;
453
+ glfwSetWindowShouldClose(DATA_PTR(self), close);
454
+ return self;
433
455
  }
434
456
 
435
- VALUE rb_glfw_window_frame_size(VALUE self) {
436
- WINDOW();
437
- int left, top, right, bottom;
438
- glfwGetWindowFrameSize(w, &left, &top, &right, &bottom);
439
- VALUE ary = rb_ary_new_capa(4);
440
- rb_ary_store(ary, 0, INT2NUM(left));
441
- rb_ary_store(ary, 1, INT2NUM(top));
442
- rb_ary_store(ary, 2, INT2NUM(right));
443
- rb_ary_store(ary, 3, INT2NUM(bottom));
444
- return ary;
457
+ static VALUE rb_glfw_window_closing(VALUE self)
458
+ {
459
+ return RB_BOOL(glfwWindowShouldClose(DATA_PTR(self)));
445
460
  }
446
461
 
447
- VALUE rb_glfw_window_get_clipboard(VALUE self) {
448
- WINDOW();
449
- const char *str = glfwGetClipboardString(w);
450
- return rb_utf8_str_new_cstr(str);
462
+ static VALUE rb_glfw_window_swap_buffers(VALUE self)
463
+ {
464
+ glfwSwapBuffers(DATA_PTR(self));
465
+ return Qnil;
451
466
  }
452
467
 
453
- VALUE rb_glfw_window_set_clipboard(VALUE self, VALUE str) {
454
- WINDOW();
455
- volatile VALUE utf8 = rb_funcall(str, rb_intern("encode"), 1, rb_str_new_cstr("utf-8"));
456
- glfwSetClipboardString(w, StringValueCStr(utf8));
457
- return str;
468
+ static VALUE rb_glfw_window_is_current(VALUE self)
469
+ {
470
+ return RB_BOOL(glfwGetCurrentContext() == DATA_PTR(self));
458
471
  }
459
472
 
460
- VALUE rb_glfw_window_set_icon(VALUE self, VALUE args) {
461
- WINDOW();
462
- int argc = rb_array_len(args);
463
- GLFWimage *images = malloc(sizeof(GLFWimage) * argc);
473
+ static VALUE rb_glfw_window_show(VALUE self)
474
+ {
475
+ glfwShowWindow(DATA_PTR(self));
476
+ return self;
477
+ }
464
478
 
465
- for (int i = 0; i < argc; i++) {
466
- VALUE img = rb_ary_entry(args, i);
467
- images[i] = *(GLFWimage *)RDATA(img)->data;
468
- }
479
+ static VALUE rb_glfw_window_hide(VALUE self)
480
+ {
481
+ glfwHideWindow(DATA_PTR(self));
482
+ return self;
483
+ }
469
484
 
470
- glfwSetWindowIcon(w, argc, images);
485
+ static VALUE rb_glfw_window_focus(VALUE self)
486
+ {
487
+ glfwFocusWindow(DATA_PTR(self));
488
+ return self;
489
+ }
471
490
 
472
- free(images);
491
+ static VALUE rb_glfw_window_minimize(VALUE self)
492
+ {
493
+ glfwIconifyWindow(DATA_PTR(self));
473
494
  return self;
474
495
  }
475
496
 
476
- VALUE rb_glfw_window_get_input_cursor(VALUE self) {
477
- WINDOW();
478
- return INT2BOOL(glfwGetInputMode(w, GLFW_CURSOR));
497
+ static VALUE rb_glfw_window_maximize(VALUE self)
498
+ {
499
+ glfwMaximizeWindow(DATA_PTR(self));
500
+ return self;
479
501
  }
480
502
 
481
- VALUE rb_glfw_window_set_input_cursor(VALUE self, VALUE value) {
482
- WINDOW();
483
- glfwSetInputMode(w, GLFW_CURSOR, RTEST(value));
484
- return value;
503
+ static VALUE rb_glfw_window_restore(VALUE self)
504
+ {
505
+ glfwRestoreWindow(DATA_PTR(self));
506
+ return self;
485
507
  }
486
508
 
487
- VALUE rb_glfw_window_get_input_sticky_keys(VALUE self) {
488
- WINDOW();
489
- return INT2BOOL(glfwGetInputMode(w, GLFW_STICKY_KEYS));
509
+ static VALUE rb_glfw_window_destroy(VALUE self)
510
+ {
511
+ glfwDestroyWindow(DATA_PTR(self));
512
+ return Qnil;
490
513
  }
491
514
 
492
- VALUE rb_glfw_window_set_input_sticky_keys(VALUE self, VALUE value) {
493
- WINDOW();
494
- glfwSetInputMode(w, GLFW_STICKY_KEYS, RTEST(value));
495
- return value;
515
+ static VALUE rb_glfw_window_request_attention(VALUE self)
516
+ {
517
+ glfwRequestWindowAttention(DATA_PTR(self));
518
+ return self;
496
519
  }
497
520
 
498
- VALUE rb_glfw_window_get_input_sticky_mouse(VALUE self) {
499
- WINDOW();
500
- return INT2BOOL(glfwGetInputMode(w, GLFW_STICKY_MOUSE_BUTTONS));
521
+ static VALUE rb_glfw_window_monitor(VALUE self)
522
+ {
523
+ GLFWmonitor *monitor = glfwGetWindowMonitor(DATA_PTR(self));
524
+ return monitor ? Data_Wrap_Struct(cMonitor, NULL, NULL, monitor) : Qnil;
501
525
  }
502
526
 
503
- VALUE rb_glfw_window_set_input_sticky_mouse(VALUE self, VALUE value) {
504
- WINDOW();
505
- glfwSetInputMode(w, GLFW_STICKY_MOUSE_BUTTONS, RTEST(value));
506
- return value;
527
+ static VALUE rb_glfw_window_get_title(VALUE self)
528
+ {
529
+ GLFWruby *data = glfwGetWindowUserPointer(DATA_PTR(self));
530
+ return data ? data->title : Qnil;
507
531
  }
508
532
 
509
- VALUE rb_glfw_window_cursor_pos(VALUE self) {
510
- WINDOW();
511
- double x, y;
512
- glfwGetCursorPos(w, &x, &y);
513
- VALUE ary = rb_ary_new_capa(2);
514
- rb_ary_store(ary, 0, DBL2NUM(x));
515
- rb_ary_store(ary, 1, DBL2NUM(y));
516
- return ary;
533
+ static VALUE rb_glfw_window_set_title(VALUE self, VALUE title)
534
+ {
535
+ GLFWwindow *window = DATA_PTR(self);
536
+ GLFWruby *data = glfwGetWindowUserPointer(window);
537
+ data->title = title;
538
+ glfwSetWindowTitle(window, RTEST(title) ? StringValueCStr(title) : "");
539
+ return title;
517
540
  }
518
541
 
519
- VALUE rb_glfw_window_set_cursor_pos(VALUE self, VALUE x, VALUE y) {
520
- WINDOW();
521
- glfwSetCursorPos(w, NUM2DBL(x), NUM2DBL(y));
522
- return self;
542
+ static VALUE rb_glfw_window_framebuffer_size(VALUE self)
543
+ {
544
+ int w, h;
545
+ glfwGetFramebufferSize(DATA_PTR(self), &w, &h);
546
+ return rb_glfw_ivec2_create(cSize, w, h);
523
547
  }
524
548
 
525
- VALUE rb_glfw_window_set_cursor(VALUE self, VALUE cursor) {
526
- WINDOW();
527
- GLFWcursor *c;
528
- Data_Get_Struct(cursor, GLFWcursor, c);
529
- glfwSetCursor(w, c);
530
- return self;
549
+ static VALUE rb_glfw_window_get_size(VALUE self)
550
+ {
551
+ int w, h;
552
+ glfwGetWindowSize(DATA_PTR(self), &w, &h);
553
+ return rb_glfw_ivec2_create(cSize, w, h);
531
554
  }
532
555
 
533
- VALUE rb_glfw_window_get_key(VALUE self, VALUE key) {
534
- WINDOW();
535
- return RTEST(glfwGetKey(w, NUM2INT(key)));
556
+ static VALUE rb_glfw_window_set_size(VALUE self, VALUE size)
557
+ {
558
+ RBivec2 *v = DATA_PTR(size);
559
+ glfwSetWindowSize(DATA_PTR(self), v->x, v->y);
560
+ return size;
536
561
  }
537
562
 
538
- VALUE rb_glfw_window_get_mouse_button(VALUE self, VALUE mbtn) {
539
- WINDOW();
540
- return RTEST(glfwGetMouseButton(w, NUM2INT(mbtn)));
563
+ static VALUE rb_glfw_window_get_position(VALUE self)
564
+ {
565
+ int x, y;
566
+ glfwGetWindowPos(DATA_PTR(self), &x, &y);
567
+ return rb_glfw_ivec2_create(cSize, x, y);
541
568
  }
542
569
 
543
- /////////////////////////////////////////////////////////////////////////////
544
- // Callbacks
545
- /////////////////////////////////////////////////////////////////////////////
570
+ static VALUE rb_glfw_window_set_position(VALUE self, VALUE size)
571
+ {
572
+ RBivec2 *v = DATA_PTR(size);
573
+ glfwSetWindowPos(DATA_PTR(self), v->x, v->y);
574
+ return size;
575
+ }
546
576
 
547
- VALUE rb_glfw_window_empty_method(int argc, VALUE *argv, VALUE self) {
548
- // Empty method stub, as NULL causes segfaults
577
+ static VALUE rb_glfw_window_aspect_ratio(VALUE self, VALUE numerator, VALUE denominator)
578
+ {
579
+ glfwSetWindowAspectRatio(DATA_PTR(self), NUM2INT(numerator), NUM2INT(denominator));
549
580
  return Qnil;
550
581
  }
551
582
 
552
- VALUE rb_glfw_window_enable_callback(VALUE self, VALUE cbtype, VALUE enable) {
553
- WINDOW();
554
- enum GLFW_RB_CALLBACK_TYPE type = NUM2INT(cbtype);
555
- int state = RTEST(enable);
556
- switch (type) {
557
- case GLFW_RB_MOVED:
558
- glfwSetWindowPosCallback(w, state ? rb_glfw_window_moved : NULL);
559
- break;
560
- case GLFW_RB_RESIZED:
561
- glfwSetWindowSizeCallback(w, state ? rb_glfw_window_resized : NULL);
562
- break;
563
- case GLFW_RB_FRAMEBUFFER_RESIZED:
564
- glfwSetFramebufferSizeCallback(w, state ? rb_glfw_window_frame_buffer_resized : NULL);
565
- break;
566
- case GLFW_RB_CLOSING:
567
- glfwSetWindowCloseCallback(w, state ? rb_glfw_window_closing : NULL);
568
- break;
569
- case GLFW_RB_REFRESHED:
570
- glfwSetWindowRefreshCallback(w, state ? rb_glfw_window_refreshed : NULL);
571
- break;
572
- case GLFW_RB_FOCUS_CHANGED:
573
- glfwSetWindowFocusCallback(w, state ? rb_glfw_window_focus_changed : NULL);
574
- break;
575
- case GLFW_RB_MINIMIZE_CHANGED:
576
- glfwSetWindowIconifyCallback(w, state ? rb_glfw_window_minimize_changed : NULL);
577
- break;
578
- case GLFW_RB_MOUSE_MOVE:
579
- glfwSetCursorPosCallback(w, state ? rb_glfw_window_cursor_mouse_move : NULL);
580
- break;
581
- case GLFW_RB_MOUSE_SCROLL:
582
- glfwSetScrollCallback(w, state ? rb_glfw_window_cursor_mouse_scroll : NULL);
583
- break;
584
- case GLFW_RB_MOUSE_BUTTON:
585
- glfwSetMouseButtonCallback(w, state ? rb_glfw_window_cursor_mouse_button : NULL);
586
- break;
587
- case GLFW_RB_MOUSE_ENTER:
588
- glfwSetCursorEnterCallback(w, state ? rb_glfw_window_mouse_enter : NULL);
589
- break;
590
- case GLFW_RB_KEY:
591
- glfwSetKeyCallback(w, state ? rb_glfw_window_key : NULL);
592
- break;
593
- case GLFW_RB_CHAR:
594
- glfwSetCharCallback(w, state ? rb_glfw_window_char : NULL);
595
- break;
596
- case GLFW_RB_CHAR_MODS:
597
- glfwSetCharModsCallback(w, state ? rb_glfw_window_char_mods : NULL);
598
- break;
599
- case GLFW_RB_FILE_DROP:
600
- glfwSetDropCallback(w, state ? rb_glfw_window_file_drop : NULL);
601
- break;
602
- default:
603
- rb_raise(rb_eArgError, "invalid callback identifier - %d", type);
604
- break;
605
- }
606
-
583
+ static VALUE rb_glfw_window_size_limits(VALUE self, VALUE minimum, VALUE maximum)
584
+ {
585
+ RBivec2 *min = DATA_PTR(minimum), *max = DATA_PTR(maximum);
586
+ glfwSetWindowSizeLimits(DATA_PTR(self), min->x, min->y, max->x, max->y);
607
587
  return Qnil;
608
588
  }
609
589
 
610
- static void rb_glfw_window_closing(GLFWwindow *window) {
611
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
612
- if (RTEST(w))
613
- rb_funcall(w, id_closing, 0);
590
+ static VALUE rb_glfw_window_frame_size(VALUE self)
591
+ {
592
+ int left, top, right, bottom;
593
+ glfwGetWindowFrameSize(DATA_PTR(self), &left, &top, &right, &bottom);
594
+ return rb_ary_new_from_args(4, INT2NUM(left), INT2NUM(top), INT2NUM(right), INT2NUM(bottom));
614
595
  }
615
596
 
616
- static void rb_glfw_window_moved(GLFWwindow *window, int x, int y) {
617
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
618
- if (RTEST(w))
619
- rb_funcall(w, id_moved, 2, INT2NUM(x), INT2NUM(y));
597
+ static VALUE rb_glfw_window_get_icon(VALUE self)
598
+ {
599
+ GLFWruby *data = glfwGetWindowUserPointer(DATA_PTR(self));
600
+ return RTEST(data->icon) ? data->icon : Qnil;
620
601
  }
621
602
 
622
- static void rb_glfw_window_resized(GLFWwindow *window, int width, int height) {
623
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
624
- if (RTEST(w))
625
- rb_funcall(w, id_resized, 2, INT2NUM(width), INT2NUM(height));
626
- }
603
+ static VALUE rb_glfw_window_set_icon(VALUE self, VALUE icon)
604
+ {
605
+ GLFWwindow *window = DATA_PTR(self);
606
+ if (!RTEST(icon))
607
+ {
608
+ glfwSetWindowIcon(window, 0, NULL);
609
+ }
610
+ else if (RB_TYPE_P(icon, T_DATA))
611
+ {
612
+ GLFWimage *image = DATA_PTR(icon);
613
+ glfwSetWindowIcon(window, 1, image);
614
+ }
615
+ else // Array
616
+ {
617
+ long len = rb_array_len(icon);
618
+ GLFWimage images[len];
619
+ for (long i = 0; i < len; i++)
620
+ {
621
+ VALUE img = rb_ary_entry(icon, i);
622
+ images[i] = *(GLFWimage *)(DATA_PTR(img));
623
+ }
624
+ glfwSetWindowIcon(window, (int)len, images);
625
+ }
627
626
 
628
- static void rb_glfw_window_refreshed(GLFWwindow *window) {
629
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
630
- if (RTEST(w))
631
- rb_funcall(w, id_refreshed, 0);
627
+ GLFWruby *data = glfwGetWindowUserPointer(window);
628
+ data->icon = icon;
629
+ return icon;
632
630
  }
633
631
 
634
- static void rb_glfw_window_focus_changed(GLFWwindow *window, int focused) {
635
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
636
- if (RTEST(w))
637
- rb_funcall(w, id_focus_changed, 1, INT2BOOL(focused));
632
+ static VALUE rb_glfw_window_get_cursor(VALUE self)
633
+ {
634
+ GLFWruby *data = glfwGetWindowUserPointer(DATA_PTR(self));
635
+ return RTEST(data->cursor) ? data->cursor : Qnil;
638
636
  }
639
637
 
640
- static void rb_glfw_window_minimize_changed(GLFWwindow *window, int minimized) {
641
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
642
- if (RTEST(w))
643
- rb_funcall(w, id_minimize_changed, 1, INT2BOOL(minimized));
644
- }
638
+ static VALUE rb_glfw_window_set_cursor(VALUE self, VALUE cursor)
639
+ {
640
+ GLFWwindow *window = DATA_PTR(self);
641
+ GLFWruby *data = glfwGetWindowUserPointer(window);
645
642
 
646
- static void rb_glfw_window_frame_buffer_resized(GLFWwindow *window, int width, int height) {
647
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
648
- if (RTEST(w))
649
- rb_funcall(w, id_framebuffer_resized, 2, INT2NUM(width), INT2NUM(height));
650
- }
643
+ glfwSetCursor(window, DATA_PTR(cursor));
644
+ data->cursor = cursor;
651
645
 
652
- static void rb_glfw_window_cursor_mouse_move(GLFWwindow *window, double x, double y) {
653
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
654
- if (RTEST(w))
655
- rb_funcall(w, id_mouse_move, 2, DBL2NUM(x), DBL2NUM(y));
646
+ return cursor;
656
647
  }
657
648
 
658
- static void rb_glfw_window_cursor_mouse_button(GLFWwindow *window, int button, int action, int mods) {
659
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
660
- if (RTEST(w))
661
- rb_funcall(w, id_mouse_button, 3, INT2NUM(button), INT2NUM(action), INT2NUM(mods));
649
+ static VALUE rb_glfw_window_content_scale(VALUE self)
650
+ {
651
+ float x, y;
652
+ glfwGetWindowContentScale(DATA_PTR(self), &x, &y);
653
+ return rb_glfw_vec2_create(cVec2, x, y);
662
654
  }
663
655
 
664
- static void rb_glfw_window_cursor_mouse_scroll(GLFWwindow *window, double xoffset, double yoffset) {
665
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
666
- if (RTEST(w))
667
- rb_funcall(w, id_mouse_scroll, 2, DBL2NUM(xoffset), DBL2NUM(yoffset));
656
+ static VALUE rb_glfw_window_get_cursor_pos(VALUE self)
657
+ {
658
+ double x, y;
659
+ glfwGetCursorPos(DATA_PTR(self), &x, &y);
660
+ return rb_glfw_vec2_create(cVec2, x, y);
668
661
  }
669
662
 
670
- static void rb_glfw_window_mouse_enter(GLFWwindow *window, int entered) {
671
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
672
- if (RTEST(w))
673
- rb_funcall(w, id_mouse_enter, 1, INT2BOOL(entered));
663
+ static VALUE rb_glfw_window_set_cursor_pos(VALUE self, VALUE position)
664
+ {
665
+ RBvec2 *vec = DATA_PTR(position);
666
+ glfwSetCursorPos(DATA_PTR(self), vec->x, vec->y);
667
+ return position;
674
668
  }
675
669
 
676
- static void rb_glfw_window_key(GLFWwindow *window, int key, int scancode, int action, int mods) {
677
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
678
- if (RTEST(w))
679
- rb_funcall(w, id_key, 4, INT2NUM(key), INT2NUM(scancode), INT2NUM(action), INT2NUM(mods));
670
+ static VALUE rb_glfw_window_cursor_move(VALUE self, VALUE x, VALUE y)
671
+ {
672
+ glfwSetCursorPos(DATA_PTR(self), NUM2DBL(x), NUM2DBL(y));
673
+ return Qnil;
680
674
  }
681
675
 
682
- static void rb_glfw_window_char(GLFWwindow *window, unsigned int codepoint) {
683
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
684
- if (RTEST(w))
685
- rb_funcall(w, id_char, 1, UINT2NUM(codepoint));
676
+ static VALUE rb_glfw_window_get_clipboard(VALUE self)
677
+ {
678
+ const char *str = glfwGetClipboardString(DATA_PTR(self));
679
+ return str ? rb_str_new_cstr(str) : Qnil;
686
680
  }
687
681
 
688
- static void rb_glfw_window_char_mods(GLFWwindow *window, unsigned int codepoint, int mods) {
689
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
690
- if (RTEST(w))
691
- rb_funcall(w, id_char_mods, 2, UINT2NUM(codepoint), INT2NUM(mods));
682
+ static VALUE rb_glfw_window_set_clipboard(VALUE self, VALUE str)
683
+ {
684
+ const char *s = RTEST(str) ? StringValueCStr(str) : "";
685
+ glfwSetClipboardString(DATA_PTR(self), s);
686
+ return str;
692
687
  }
693
688
 
694
- static void rb_glfw_window_file_drop(GLFWwindow *window, int count, const char **files) {
695
- VALUE w = (VALUE)glfwGetWindowUserPointer(window);
696
- if (RTEST(w)) {
697
- VALUE ary = rb_ary_new_capa(count);
698
- for (int i = 0; i < count; i++) {
699
- char *pos = strchr(files[i], '\\');
700
- while (pos) {
701
- *pos = '/';
702
- pos = strchr(pos, '\\');
703
- }
704
- rb_ary_store(ary, i, rb_utf8_str_new_cstr(files[i]));
705
- }
706
- rb_funcall(w, id_file_drop, 1, ary);
707
- }
689
+ static VALUE rb_glfw_window_change_monitor(VALUE self, VALUE monitor, VALUE position, VALUE size, VALUE hz)
690
+ {
691
+ GLFWmonitor *m = RTEST(monitor) ? DATA_PTR(monitor) : NULL;
692
+ RBivec2 *pos = DATA_PTR(position);
693
+ RBivec2 *sz = DATA_PTR(size);
694
+
695
+ glfwSetWindowMonitor(DATA_PTR(self), m, pos->x, pos->y, sz->x, sz->y, NUM2INT(hz));
696
+ return Qnil;
708
697
  }
698
+
699
+ static VALUE rb_glfw_window_is_key(VALUE self, VALUE key)
700
+ {
701
+ return RB_BOOL(glfwGetKey(DATA_PTR(self), NUM2INT(key)));
702
+ }
703
+
704
+ static VALUE rb_glfw_window_is_button(VALUE self, VALUE button)
705
+ {
706
+ return RB_BOOL(glfwGetMouseButton(DATA_PTR(self), NUM2INT(button)));
707
+ }
708
+
709
+ static VALUE rb_glfw_window_get_cursor_mode(VALUE self)
710
+ {
711
+ return INT2NUM(glfwGetInputMode(DATA_PTR(self), GLFW_CURSOR));
712
+ }
713
+
714
+ static VALUE rb_glfw_window_set_cursor_mode(VALUE self, VALUE mode)
715
+ {
716
+ glfwSetInputMode(DATA_PTR(self), GLFW_CURSOR, NUM2INT(mode));
717
+ return mode;
718
+ }
719
+
720
+ static VALUE rb_glfw_window_is_fullscreen(VALUE self)
721
+ {
722
+ GLFWmonitor *monitor = glfwGetWindowMonitor(DATA_PTR(self));
723
+ return RB_BOOL(monitor != NULL);
724
+ }
725
+
726
+ WINDOW_ATTRIBUTE(topmost, GLFW_FLOATING, RB_BOOL, RTEST)
727
+ WINDOW_ATTRIBUTE(decorated, GLFW_DECORATED, RB_BOOL, RTEST)
728
+ WINDOW_ATTRIBUTE(resizable, GLFW_RESIZABLE, RB_BOOL, RTEST)
729
+ WINDOW_ATTRIBUTE(auto_focus, GLFW_FOCUS_ON_SHOW, RB_BOOL, RTEST)
730
+ WINDOW_ATTRIBUTE(visible, GLFW_VISIBLE, RB_BOOL, RTEST)
731
+
732
+ GET_WINDOW_ATTRIB(rb_glfw_window_is_focused, GLFW_FOCUSED, RB_BOOL)
733
+ GET_WINDOW_ATTRIB(rb_glfw_window_is_minimized, GLFW_ICONIFIED, RB_BOOL)
734
+ GET_WINDOW_ATTRIB(rb_glfw_window_is_maximized, GLFW_MAXIMIZED, RB_BOOL)
735
+ GET_WINDOW_ATTRIB(rb_glfw_window_is_hovered, GLFW_HOVERED, RB_BOOL)
736
+
737
+ void rb_glfw_window_init(void)
738
+ {
739
+
740
+ cWindow = rb_define_class_under(mGLFW, "Window", rb_cObject);
741
+ rb_define_alloc_func(cWindow, rb_glfw_window_alloc);
742
+
743
+ rb_define_singleton_method(cWindow, "hint", rb_glfw_window_hint, 2);
744
+ rb_define_singleton_method(cWindow, "default_hints", rb_glfw_window_default_hints, 0);
745
+ rb_define_singleton_method(cWindow, "current", rb_glfw_window_current, 0);
746
+
747
+ rb_define_method(cWindow, "initialize", rb_glfw_window_initialize, -1);
748
+ rb_define_method(cWindow, "destroy", rb_glfw_window_destroy, 0);
749
+ rb_define_method(cWindow, "make_current", rb_glfw_window_make_current, 0);
750
+ rb_define_method(cWindow, "current?", rb_glfw_window_is_current, 0);
751
+ rb_define_method(cWindow, "monitor", rb_glfw_window_monitor, 0);
752
+ rb_define_method(cWindow, "content_scale", rb_glfw_window_content_scale, 0);
753
+
754
+ rb_define_method(cWindow, "title", rb_glfw_window_get_title, 0);
755
+ rb_define_method(cWindow, "title=", rb_glfw_window_set_title, 1);
756
+ rb_define_method(cWindow, "icon", rb_glfw_window_get_icon, 0);
757
+ rb_define_method(cWindow, "icon=", rb_glfw_window_set_icon, 1);
758
+ rb_define_method(cWindow, "size", rb_glfw_window_get_size, 0);
759
+ rb_define_method(cWindow, "size=", rb_glfw_window_set_size, 1);
760
+ rb_define_method(cWindow, "position", rb_glfw_window_get_position, 0);
761
+ rb_define_method(cWindow, "position=", rb_glfw_window_set_position, 1);
762
+ rb_define_method(cWindow, "cursor", rb_glfw_window_get_cursor, 0);
763
+ rb_define_method(cWindow, "cursor=", rb_glfw_window_set_cursor, 1);
764
+ rb_define_method(cWindow, "cursor_pos", rb_glfw_window_get_cursor_pos, 0);
765
+ rb_define_method(cWindow, "cursor_pos=", rb_glfw_window_set_cursor_pos, 1);
766
+ rb_define_method(cWindow, "opacity", rb_glfw_window_get_opacity, 0);
767
+ rb_define_method(cWindow, "opacity=", rb_glfw_window_set_opacity, 1);
768
+ rb_define_method(cWindow, "topmost", rb_glfw_window_get_topmost, 0);
769
+ rb_define_method(cWindow, "topmost=", rb_glfw_window_set_topmost, 1);
770
+ rb_define_method(cWindow, "decorated", rb_glfw_window_get_decorated, 0);
771
+ rb_define_method(cWindow, "decorated=", rb_glfw_window_set_decorated, 1);
772
+ rb_define_method(cWindow, "resizable", rb_glfw_window_get_resizable, 0);
773
+ rb_define_method(cWindow, "resizable=", rb_glfw_window_set_resizable, 1);
774
+ rb_define_method(cWindow, "auto_focus", rb_glfw_window_get_auto_focus, 0);
775
+ rb_define_method(cWindow, "auto_focus=", rb_glfw_window_set_auto_focus, 1);
776
+ rb_define_method(cWindow, "visible", rb_glfw_window_get_visible, 0);
777
+ rb_define_method(cWindow, "visible=", rb_glfw_window_set_visible, 1);
778
+ rb_define_method(cWindow, "clipboard", rb_glfw_window_get_clipboard, 0);
779
+ rb_define_method(cWindow, "clipboard=", rb_glfw_window_set_clipboard, 1);
780
+ rb_define_method(cWindow, "cursor_mode", rb_glfw_window_get_cursor_mode, 0);
781
+ rb_define_method(cWindow, "cursor_mode=", rb_glfw_window_set_cursor_mode, 1);
782
+
783
+ rb_define_method(cWindow, "focused?", rb_glfw_window_is_focused, 0);
784
+ rb_define_method(cWindow, "minimized?", rb_glfw_window_is_minimized, 0);
785
+ rb_define_method(cWindow, "maximized?", rb_glfw_window_is_maximized, 0);
786
+ rb_define_method(cWindow, "hovered?", rb_glfw_window_is_hovered, 0);
787
+ rb_define_method(cWindow, "fullscreen?", rb_glfw_window_is_fullscreen, 0);
788
+
789
+ rb_define_method(cWindow, "aspect_ratio", rb_glfw_window_aspect_ratio, 2);
790
+ rb_define_method(cWindow, "size_limits", rb_glfw_window_size_limits, 2);
791
+ rb_define_method(cWindow, "frame_size", rb_glfw_window_frame_size, 0);
792
+
793
+ rb_define_method(cWindow, "move_cursor", rb_glfw_window_cursor_move, 2);
794
+ rb_define_method(cWindow, "framebuffer_size", rb_glfw_window_framebuffer_size, 0);
795
+ rb_define_method(cWindow, "center", rb_glfw_window_center, 0);
796
+ rb_define_method(cWindow, "close", rb_glfw_window_close, -1);
797
+ rb_define_method(cWindow, "closing?", rb_glfw_window_closing, 0);
798
+ rb_define_method(cWindow, "swap_buffers", rb_glfw_window_swap_buffers, 0);
799
+ rb_define_method(cWindow, "show", rb_glfw_window_show, 0);
800
+ rb_define_method(cWindow, "hide", rb_glfw_window_hide, 0);
801
+ rb_define_method(cWindow, "focus", rb_glfw_window_focus, 0);
802
+ rb_define_method(cWindow, "minimize", rb_glfw_window_minimize, 0);
803
+ rb_define_method(cWindow, "maximize", rb_glfw_window_maximize, 0);
804
+ rb_define_method(cWindow, "restore", rb_glfw_window_restore, 0);
805
+ rb_define_method(cWindow, "request_attention", rb_glfw_window_request_attention, 0);
806
+ rb_define_method(cWindow, "change_monitor", rb_glfw_window_change_monitor, 4);
807
+
808
+ rb_define_method(cWindow, "key?", rb_glfw_window_is_key, 1);
809
+ rb_define_method(cWindow, "mouse_button?", rb_glfw_window_is_button, 1);
810
+ rb_define_method(cWindow, "sticky_keys", rb_glfw_window_get_sticky_keys, 0);
811
+ rb_define_method(cWindow, "sticky_keys=", rb_glfw_window_set_sticky_keys, 1);
812
+ rb_define_method(cWindow, "sticky_buttons", rb_glfw_window_get_sticky_buttons, 0);
813
+ rb_define_method(cWindow, "sticky_buttons=", rb_glfw_window_set_sticky_buttons, 1);
814
+ rb_define_method(cWindow, "lock_modifiers", rb_glfw_window_get_lock_modifiers, 0);
815
+ rb_define_method(cWindow, "lock_modifiers=", rb_glfw_window_set_lock_modifiers, 1);
816
+ rb_define_method(cWindow, "raw_mouse_motion", rb_glfw_window_get_raw_mouse_motion, 0);
817
+ rb_define_method(cWindow, "raw_mouse_motion=", rb_glfw_window_set_raw_mouse_motion, 1);
818
+
819
+ rb_define_method(cWindow, "on_framebuffer_resize", rb_glfw_window_on_framebuffer_resize, 0);
820
+ rb_define_method(cWindow, "on_resize", rb_glfw_window_on_resize, 0);
821
+ rb_define_method(cWindow, "on_move", rb_glfw_window_on_move, 0);
822
+ rb_define_method(cWindow, "on_focus", rb_glfw_window_on_focus, 0);
823
+ rb_define_method(cWindow, "on_refresh", rb_glfw_window_on_refresh, 0);
824
+ rb_define_method(cWindow, "on_close", rb_glfw_window_on_close, 0);
825
+ rb_define_method(cWindow, "on_minimize", rb_glfw_window_on_minimize, 0);
826
+ rb_define_method(cWindow, "on_maximize", rb_glfw_window_on_maximize, 0);
827
+ rb_define_method(cWindow, "on_file_drop", rb_glfw_window_on_file_drop, 0);
828
+ rb_define_method(cWindow, "on_cursor_move", rb_glfw_window_on_cursor_move, 0);
829
+ rb_define_method(cWindow, "on_scroll", rb_glfw_window_on_scroll, 0);
830
+ rb_define_method(cWindow, "on_key", rb_glfw_window_on_key, 0);
831
+ rb_define_method(cWindow, "on_mouse_button", rb_glfw_window_on_mouse_button, 0);
832
+ rb_define_method(cWindow, "on_cursor_enter", rb_glfw_window_on_cursor_enter, 0);
833
+ rb_define_method(cWindow, "on_char", rb_glfw_window_on_char, 0);
834
+ rb_define_method(cWindow, "on_scale", rb_glfw_window_on_scale, 0);
835
+
836
+ rb_define_method(cWindow, "==", rb_glfw_window_eql, 1);
837
+ rb_define_method(cWindow, "eql?", rb_glfw_window_eql, 1);
838
+
839
+ rb_define_alias(cWindow, "dispose", "destroy");
840
+ }