glfw 0.9.8 → 1.0.1
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.
- checksums.yaml +5 -5
- data/Makefile +3 -3
- data/README.md +5 -2
- data/Rakefile +0 -9
- data/ext/glfw/common.h +45 -45
- data/ext/glfw/cursor.c +42 -42
- data/ext/glfw/cursor.h +13 -13
- data/ext/glfw/extconf.rb +13 -16
- data/ext/glfw/glfw.c +2 -2
- data/ext/glfw/image.c +76 -76
- data/ext/glfw/image.h +13 -13
- data/ext/glfw/monitor.c +209 -209
- data/ext/glfw/monitor.h +28 -28
- data/ext/glfw/video_mode.c +60 -60
- data/ext/glfw/video_mode.h +20 -20
- data/ext/glfw/vulkan.c +48 -48
- data/ext/glfw/vulkan.h +15 -15
- data/ext/glfw/window.c +708 -708
- data/ext/glfw/window.h +86 -86
- data/lib/glfw.rb +8 -26
- data/lib/glfw/version.rb +1 -1
- metadata +3 -4
- data/ext/glfw/lib/libglfw3.a +0 -0
data/ext/glfw/video_mode.c
CHANGED
@@ -1,60 +1,60 @@
|
|
1
|
-
|
2
|
-
#include "video_mode.h"
|
3
|
-
|
4
|
-
VALUE rb_cGLFWvidmode;
|
5
|
-
|
6
|
-
void Init_glfw_vidmode(VALUE module) {
|
7
|
-
rb_cGLFWvidmode = rb_define_class_under(module, "VideoMode", rb_cObject);
|
8
|
-
|
9
|
-
rb_define_method(rb_cGLFWvidmode, "width", rb_glfw_vidmode_width, 0);
|
10
|
-
rb_define_method(rb_cGLFWvidmode, "height", rb_glfw_vidmode_height, 0);
|
11
|
-
rb_define_method(rb_cGLFWvidmode, "red_bits", rb_glfw_vidmode_red_bits, 0);
|
12
|
-
rb_define_method(rb_cGLFWvidmode, "green_bits", rb_glfw_vidmode_green_bits, 0);
|
13
|
-
rb_define_method(rb_cGLFWvidmode, "blue_bits", rb_glfw_vidmode_blue_bits, 0);
|
14
|
-
rb_define_method(rb_cGLFWvidmode, "refresh_rate", rb_glfw_vidmode_refresh_rate, 0);
|
15
|
-
|
16
|
-
rb_define_method(rb_cGLFWvidmode, "to_s", rb_glfw_vidmode_to_s, 0);
|
17
|
-
rb_funcall(rb_cGLFWvidmode, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
18
|
-
}
|
19
|
-
|
20
|
-
static VALUE rb_glfw_vidmode_alloc(VALUE klass) {
|
21
|
-
GLFWvidmode *v = ALLOC(GLFWvidmode);
|
22
|
-
memset(v, 0, sizeof(GLFWvidmode));
|
23
|
-
return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, v);
|
24
|
-
}
|
25
|
-
|
26
|
-
VALUE rb_glfw_vidmode_width(VALUE self) {
|
27
|
-
VIDMODE();
|
28
|
-
return INT2NUM(v->width);
|
29
|
-
}
|
30
|
-
|
31
|
-
VALUE rb_glfw_vidmode_height(VALUE self) {
|
32
|
-
VIDMODE();
|
33
|
-
return INT2NUM(v->height);
|
34
|
-
}
|
35
|
-
|
36
|
-
VALUE rb_glfw_vidmode_red_bits(VALUE self) {
|
37
|
-
VIDMODE();
|
38
|
-
return INT2NUM(v->redBits);
|
39
|
-
}
|
40
|
-
|
41
|
-
VALUE rb_glfw_vidmode_green_bits(VALUE self) {
|
42
|
-
VIDMODE();
|
43
|
-
return INT2NUM(v->greenBits);
|
44
|
-
}
|
45
|
-
|
46
|
-
VALUE rb_glfw_vidmode_blue_bits(VALUE self) {
|
47
|
-
VIDMODE();
|
48
|
-
return INT2NUM(v->blueBits);
|
49
|
-
}
|
50
|
-
|
51
|
-
VALUE rb_glfw_vidmode_refresh_rate(VALUE self) {
|
52
|
-
VIDMODE();
|
53
|
-
return INT2NUM(v->refreshRate);
|
54
|
-
}
|
55
|
-
|
56
|
-
VALUE rb_glfw_vidmode_to_s(VALUE self) {
|
57
|
-
VIDMODE();
|
58
|
-
return rb_sprintf("<%s: width:%d, height:%d, r:%d, g:%d, b:%d, rate:%dhz",
|
59
|
-
rb_class2name(CLASS_OF(self)), v->width, v->height, v->redBits, v->greenBits, v->blueBits, v->refreshRate);
|
60
|
-
}
|
1
|
+
|
2
|
+
#include "video_mode.h"
|
3
|
+
|
4
|
+
VALUE rb_cGLFWvidmode;
|
5
|
+
|
6
|
+
void Init_glfw_vidmode(VALUE module) {
|
7
|
+
rb_cGLFWvidmode = rb_define_class_under(module, "VideoMode", rb_cObject);
|
8
|
+
|
9
|
+
rb_define_method(rb_cGLFWvidmode, "width", rb_glfw_vidmode_width, 0);
|
10
|
+
rb_define_method(rb_cGLFWvidmode, "height", rb_glfw_vidmode_height, 0);
|
11
|
+
rb_define_method(rb_cGLFWvidmode, "red_bits", rb_glfw_vidmode_red_bits, 0);
|
12
|
+
rb_define_method(rb_cGLFWvidmode, "green_bits", rb_glfw_vidmode_green_bits, 0);
|
13
|
+
rb_define_method(rb_cGLFWvidmode, "blue_bits", rb_glfw_vidmode_blue_bits, 0);
|
14
|
+
rb_define_method(rb_cGLFWvidmode, "refresh_rate", rb_glfw_vidmode_refresh_rate, 0);
|
15
|
+
|
16
|
+
rb_define_method(rb_cGLFWvidmode, "to_s", rb_glfw_vidmode_to_s, 0);
|
17
|
+
rb_funcall(rb_cGLFWvidmode, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
18
|
+
}
|
19
|
+
|
20
|
+
static VALUE rb_glfw_vidmode_alloc(VALUE klass) {
|
21
|
+
GLFWvidmode *v = ALLOC(GLFWvidmode);
|
22
|
+
memset(v, 0, sizeof(GLFWvidmode));
|
23
|
+
return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, v);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE rb_glfw_vidmode_width(VALUE self) {
|
27
|
+
VIDMODE();
|
28
|
+
return INT2NUM(v->width);
|
29
|
+
}
|
30
|
+
|
31
|
+
VALUE rb_glfw_vidmode_height(VALUE self) {
|
32
|
+
VIDMODE();
|
33
|
+
return INT2NUM(v->height);
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE rb_glfw_vidmode_red_bits(VALUE self) {
|
37
|
+
VIDMODE();
|
38
|
+
return INT2NUM(v->redBits);
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE rb_glfw_vidmode_green_bits(VALUE self) {
|
42
|
+
VIDMODE();
|
43
|
+
return INT2NUM(v->greenBits);
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE rb_glfw_vidmode_blue_bits(VALUE self) {
|
47
|
+
VIDMODE();
|
48
|
+
return INT2NUM(v->blueBits);
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE rb_glfw_vidmode_refresh_rate(VALUE self) {
|
52
|
+
VIDMODE();
|
53
|
+
return INT2NUM(v->refreshRate);
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE rb_glfw_vidmode_to_s(VALUE self) {
|
57
|
+
VIDMODE();
|
58
|
+
return rb_sprintf("<%s: width:%d, height:%d, r:%d, g:%d, b:%d, rate:%dhz",
|
59
|
+
rb_class2name(CLASS_OF(self)), v->width, v->height, v->redBits, v->greenBits, v->blueBits, v->refreshRate);
|
60
|
+
}
|
data/ext/glfw/video_mode.h
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
#ifndef GLFW_RB_VIDEOMODE_H
|
2
|
-
#define GLFW_RB_VIDEOMODE_H 1
|
3
|
-
|
4
|
-
#include "common.h"
|
5
|
-
|
6
|
-
#define VIDMODE() \
|
7
|
-
GLFWvidmode *v; \
|
8
|
-
Data_Get_Struct(self, GLFWvidmode, v)
|
9
|
-
|
10
|
-
void Init_glfw_vidmode(VALUE module);
|
11
|
-
static VALUE rb_glfw_vidmode_alloc(VALUE klass);
|
12
|
-
|
13
|
-
VALUE rb_glfw_vidmode_width(VALUE self);
|
14
|
-
VALUE rb_glfw_vidmode_height(VALUE self);
|
15
|
-
VALUE rb_glfw_vidmode_red_bits(VALUE self);
|
16
|
-
VALUE rb_glfw_vidmode_green_bits(VALUE self);
|
17
|
-
VALUE rb_glfw_vidmode_blue_bits(VALUE self);
|
18
|
-
VALUE rb_glfw_vidmode_refresh_rate(VALUE self);
|
19
|
-
VALUE rb_glfw_vidmode_to_s(VALUE self);
|
20
|
-
|
1
|
+
#ifndef GLFW_RB_VIDEOMODE_H
|
2
|
+
#define GLFW_RB_VIDEOMODE_H 1
|
3
|
+
|
4
|
+
#include "common.h"
|
5
|
+
|
6
|
+
#define VIDMODE() \
|
7
|
+
GLFWvidmode *v; \
|
8
|
+
Data_Get_Struct(self, GLFWvidmode, v)
|
9
|
+
|
10
|
+
void Init_glfw_vidmode(VALUE module);
|
11
|
+
static VALUE rb_glfw_vidmode_alloc(VALUE klass);
|
12
|
+
|
13
|
+
VALUE rb_glfw_vidmode_width(VALUE self);
|
14
|
+
VALUE rb_glfw_vidmode_height(VALUE self);
|
15
|
+
VALUE rb_glfw_vidmode_red_bits(VALUE self);
|
16
|
+
VALUE rb_glfw_vidmode_green_bits(VALUE self);
|
17
|
+
VALUE rb_glfw_vidmode_blue_bits(VALUE self);
|
18
|
+
VALUE rb_glfw_vidmode_refresh_rate(VALUE self);
|
19
|
+
VALUE rb_glfw_vidmode_to_s(VALUE self);
|
20
|
+
|
21
21
|
#endif /* GLFW_RB_VIDEOMODE_H */
|
data/ext/glfw/vulkan.c
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
|
2
|
-
#include "vulkan.h"
|
3
|
-
|
4
|
-
VALUE rb_cGLFWvulkan;
|
5
|
-
|
6
|
-
void Init_glfw_vulkan(VALUE module) {
|
7
|
-
rb_cGLFWvulkan = rb_define_class_under(module, "Vulkan", rb_cObject);
|
8
|
-
|
9
|
-
rb_define_method(rb_cGLFWvulkan, "create_surface", rb_glfw_vulkan_create_surface, 2);
|
10
|
-
rb_define_method(rb_cGLFWvulkan, "proc_address", rb_glfw_vulkan_proc_address, 1);
|
11
|
-
rb_define_method(rb_cGLFWvulkan, "device_support", rb_glfw_vulkan_device_support, 2);
|
12
|
-
|
13
|
-
rb_define_singleton_method(rb_cGLFWvulkan, "supported?", rb_glfw_vulkan_supported, 0);
|
14
|
-
rb_define_singleton_method(rb_cGLFWvulkan, "required_extensions", rb_glfw_vulkan_required_ext, 0);
|
15
|
-
|
16
|
-
// TODO: Implement once Vulkan support is better in GLFW
|
17
|
-
rb_funcall(rb_cGLFWvulkan, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
18
|
-
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
VALUE rb_glfw_vulkan_supported(VALUE klass) {
|
23
|
-
return glfwVulkanSupported() ? Qtrue : Qfalse;
|
24
|
-
}
|
25
|
-
|
26
|
-
VALUE rb_glfw_vulkan_required_ext(VALUE klass) {
|
27
|
-
uint32_t count;
|
28
|
-
const char **exts = glfwGetRequiredInstanceExtensions(&count);
|
29
|
-
VALUE ary = rb_ary_new_capa(count);
|
30
|
-
for (int i = 0; i < count; i++)
|
31
|
-
rb_ary_store(ary, i, rb_str_new_cstr(exts[i]));
|
32
|
-
return ary;
|
33
|
-
}
|
34
|
-
|
35
|
-
VALUE rb_glfw_vulkan_create_surface(VALUE self, VALUE window, VALUE allocator) {
|
36
|
-
// TODO: glfwCreateWindowSurface
|
37
|
-
return Qnil;
|
38
|
-
}
|
39
|
-
|
40
|
-
VALUE rb_glfw_vulkan_proc_address(VALUE self, VALUE name) {
|
41
|
-
// TODO: glfwGetInstanceProcAddress
|
42
|
-
return Qnil;
|
43
|
-
}
|
44
|
-
|
45
|
-
VALUE rb_glfw_vulkan_device_support(VALUE self, VALUE device, VALUE family) {
|
46
|
-
// TODO: glfwGetPhysicalDevicePresentationSupport
|
47
|
-
return Qnil;
|
48
|
-
}
|
1
|
+
|
2
|
+
#include "vulkan.h"
|
3
|
+
|
4
|
+
VALUE rb_cGLFWvulkan;
|
5
|
+
|
6
|
+
void Init_glfw_vulkan(VALUE module) {
|
7
|
+
rb_cGLFWvulkan = rb_define_class_under(module, "Vulkan", rb_cObject);
|
8
|
+
|
9
|
+
rb_define_method(rb_cGLFWvulkan, "create_surface", rb_glfw_vulkan_create_surface, 2);
|
10
|
+
rb_define_method(rb_cGLFWvulkan, "proc_address", rb_glfw_vulkan_proc_address, 1);
|
11
|
+
rb_define_method(rb_cGLFWvulkan, "device_support", rb_glfw_vulkan_device_support, 2);
|
12
|
+
|
13
|
+
rb_define_singleton_method(rb_cGLFWvulkan, "supported?", rb_glfw_vulkan_supported, 0);
|
14
|
+
rb_define_singleton_method(rb_cGLFWvulkan, "required_extensions", rb_glfw_vulkan_required_ext, 0);
|
15
|
+
|
16
|
+
// TODO: Implement once Vulkan support is better in GLFW
|
17
|
+
rb_funcall(rb_cGLFWvulkan, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
VALUE rb_glfw_vulkan_supported(VALUE klass) {
|
23
|
+
return glfwVulkanSupported() ? Qtrue : Qfalse;
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE rb_glfw_vulkan_required_ext(VALUE klass) {
|
27
|
+
uint32_t count;
|
28
|
+
const char **exts = glfwGetRequiredInstanceExtensions(&count);
|
29
|
+
VALUE ary = rb_ary_new_capa(count);
|
30
|
+
for (int i = 0; i < count; i++)
|
31
|
+
rb_ary_store(ary, i, rb_str_new_cstr(exts[i]));
|
32
|
+
return ary;
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE rb_glfw_vulkan_create_surface(VALUE self, VALUE window, VALUE allocator) {
|
36
|
+
// TODO: glfwCreateWindowSurface
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE rb_glfw_vulkan_proc_address(VALUE self, VALUE name) {
|
41
|
+
// TODO: glfwGetInstanceProcAddress
|
42
|
+
return Qnil;
|
43
|
+
}
|
44
|
+
|
45
|
+
VALUE rb_glfw_vulkan_device_support(VALUE self, VALUE device, VALUE family) {
|
46
|
+
// TODO: glfwGetPhysicalDevicePresentationSupport
|
47
|
+
return Qnil;
|
48
|
+
}
|
data/ext/glfw/vulkan.h
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
#ifndef GLFW_RB_VULKAN_H
|
3
|
-
#define GLFW_RB_VULKAN_H 1
|
4
|
-
|
5
|
-
#include "common.h"
|
6
|
-
|
7
|
-
void Init_glfw_vulkan(VALUE module);
|
8
|
-
|
9
|
-
VALUE rb_glfw_vulkan_supported(VALUE klass);
|
10
|
-
VALUE rb_glfw_vulkan_required_ext(VALUE klass);
|
11
|
-
|
12
|
-
VALUE rb_glfw_vulkan_create_surface(VALUE self, VALUE window, VALUE allocator);
|
13
|
-
VALUE rb_glfw_vulkan_proc_address(VALUE self, VALUE name);
|
14
|
-
VALUE rb_glfw_vulkan_device_support(VALUE self, VALUE device, VALUE family);
|
15
|
-
|
1
|
+
|
2
|
+
#ifndef GLFW_RB_VULKAN_H
|
3
|
+
#define GLFW_RB_VULKAN_H 1
|
4
|
+
|
5
|
+
#include "common.h"
|
6
|
+
|
7
|
+
void Init_glfw_vulkan(VALUE module);
|
8
|
+
|
9
|
+
VALUE rb_glfw_vulkan_supported(VALUE klass);
|
10
|
+
VALUE rb_glfw_vulkan_required_ext(VALUE klass);
|
11
|
+
|
12
|
+
VALUE rb_glfw_vulkan_create_surface(VALUE self, VALUE window, VALUE allocator);
|
13
|
+
VALUE rb_glfw_vulkan_proc_address(VALUE self, VALUE name);
|
14
|
+
VALUE rb_glfw_vulkan_device_support(VALUE self, VALUE device, VALUE family);
|
15
|
+
|
16
16
|
#endif /* GLFW_RB_VULKAN_H */
|
data/ext/glfw/window.c
CHANGED
@@ -1,708 +1,708 @@
|
|
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
|
-
}
|
141
|
-
|
142
|
-
// Share
|
143
|
-
share = rb_hash_aref(options, STR2SYM("share"));
|
144
|
-
if (!NIL_P(share))
|
145
|
-
Data_Get_Struct(share, GLFWwindow, other);
|
146
|
-
}
|
147
|
-
|
148
|
-
window = glfwCreateWindow(NUM2INT(width), NUM2INT(height), str, mon, other);
|
149
|
-
RDATA(self)->data = window;
|
150
|
-
|
151
|
-
// Store the Ruby VALUE as a "user pointer" to get the Ruby instance from the C struct
|
152
|
-
glfwSetWindowUserPointer(window, (void *)self);
|
153
|
-
|
154
|
-
if (rb_block_given_p()) {
|
155
|
-
rb_yield(self);
|
156
|
-
glfwDestroyWindow(window);
|
157
|
-
}
|
158
|
-
|
159
|
-
return Qnil;
|
160
|
-
}
|
161
|
-
|
162
|
-
VALUE rb_glfw_window_destroy(VALUE self) {
|
163
|
-
WINDOW();
|
164
|
-
glfwDestroyWindow(w);
|
165
|
-
return self;
|
166
|
-
}
|
167
|
-
|
168
|
-
VALUE rb_glfw_window_show(VALUE self) {
|
169
|
-
WINDOW();
|
170
|
-
glfwShowWindow(w);
|
171
|
-
return self;
|
172
|
-
}
|
173
|
-
|
174
|
-
VALUE rb_glfw_window_hide(VALUE self) {
|
175
|
-
WINDOW();
|
176
|
-
glfwHideWindow(w);
|
177
|
-
return self;
|
178
|
-
}
|
179
|
-
|
180
|
-
VALUE rb_glfw_window_minimize(VALUE self) {
|
181
|
-
WINDOW();
|
182
|
-
glfwIconifyWindow(w);
|
183
|
-
return self;
|
184
|
-
}
|
185
|
-
|
186
|
-
VALUE rb_glfw_window_maximize(VALUE self) {
|
187
|
-
WINDOW();
|
188
|
-
glfwMaximizeWindow(w);
|
189
|
-
return self;
|
190
|
-
}
|
191
|
-
|
192
|
-
VALUE rb_glfw_window_restore(VALUE self) {
|
193
|
-
WINDOW();
|
194
|
-
glfwRestoreWindow(w);
|
195
|
-
return self;
|
196
|
-
}
|
197
|
-
|
198
|
-
VALUE rb_glfw_window_focus(VALUE self) {
|
199
|
-
WINDOW();
|
200
|
-
glfwFocusWindow(w);
|
201
|
-
return self;
|
202
|
-
}
|
203
|
-
|
204
|
-
VALUE rb_glfw_window_swap_buffers(VALUE self) {
|
205
|
-
WINDOW();
|
206
|
-
glfwSwapBuffers(w);
|
207
|
-
return Qnil;
|
208
|
-
}
|
209
|
-
|
210
|
-
VALUE rb_glfw_window_make_current(VALUE self) {
|
211
|
-
WINDOW();
|
212
|
-
glfwMakeContextCurrent(w);
|
213
|
-
return Qnil;
|
214
|
-
}
|
215
|
-
|
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;
|
227
|
-
}
|
228
|
-
|
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;
|
237
|
-
}
|
238
|
-
|
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;
|
243
|
-
}
|
244
|
-
|
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;
|
253
|
-
}
|
254
|
-
|
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;
|
259
|
-
}
|
260
|
-
|
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;
|
348
|
-
}
|
349
|
-
return self;
|
350
|
-
}
|
351
|
-
|
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);
|
356
|
-
}
|
357
|
-
|
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;
|
377
|
-
}
|
378
|
-
return self;
|
379
|
-
}
|
380
|
-
|
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;
|
386
|
-
}
|
387
|
-
|
388
|
-
VALUE rb_glfw_window_focused_p(VALUE self) {
|
389
|
-
WINDOW();
|
390
|
-
return glfwGetWindowAttrib(w, GLFW_FOCUSED) ? Qtrue : Qfalse;
|
391
|
-
}
|
392
|
-
|
393
|
-
VALUE rb_glfw_window_minimized_p(VALUE self) {
|
394
|
-
WINDOW();
|
395
|
-
return glfwGetWindowAttrib(w, GLFW_ICONIFIED) ? Qtrue : Qfalse;
|
396
|
-
}
|
397
|
-
|
398
|
-
VALUE rb_glfw_window_maximized_p(VALUE self) {
|
399
|
-
WINDOW();
|
400
|
-
return glfwGetWindowAttrib(w, GLFW_MAXIMIZED) ? Qtrue : Qfalse;
|
401
|
-
}
|
402
|
-
|
403
|
-
VALUE rb_glfw_window_visible_p(VALUE self) {
|
404
|
-
WINDOW();
|
405
|
-
return glfwGetWindowAttrib(w, GLFW_VISIBLE) ? Qtrue : Qfalse;
|
406
|
-
}
|
407
|
-
|
408
|
-
VALUE rb_glfw_window_resizable_p(VALUE self) {
|
409
|
-
WINDOW();
|
410
|
-
return glfwGetWindowAttrib(w, GLFW_RESIZABLE) ? Qtrue : Qfalse;
|
411
|
-
}
|
412
|
-
|
413
|
-
VALUE rb_glfw_window_decorated_p(VALUE self) {
|
414
|
-
WINDOW();
|
415
|
-
return glfwGetWindowAttrib(w, GLFW_DECORATED) ? Qtrue : Qfalse;
|
416
|
-
}
|
417
|
-
|
418
|
-
VALUE rb_glfw_window_floating_p(VALUE self) {
|
419
|
-
WINDOW();
|
420
|
-
return glfwGetWindowAttrib(w, GLFW_FLOATING) ? Qtrue : Qfalse;
|
421
|
-
}
|
422
|
-
|
423
|
-
VALUE rb_glfw_window_aspect_ratio(VALUE self, VALUE numerator, VALUE denominator) {
|
424
|
-
WINDOW();
|
425
|
-
glfwSetWindowAspectRatio(w, NUM2INT(numerator), NUM2INT(denominator));
|
426
|
-
return Qnil;
|
427
|
-
}
|
428
|
-
|
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;
|
433
|
-
}
|
434
|
-
|
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;
|
445
|
-
}
|
446
|
-
|
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);
|
451
|
-
}
|
452
|
-
|
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;
|
458
|
-
}
|
459
|
-
|
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);
|
464
|
-
|
465
|
-
for (int i = 0; i < argc; i++) {
|
466
|
-
VALUE img = rb_ary_entry(args, i);
|
467
|
-
images[i] = *(GLFWimage *)RDATA(img)->data;
|
468
|
-
}
|
469
|
-
|
470
|
-
glfwSetWindowIcon(w, argc, images);
|
471
|
-
|
472
|
-
free(images);
|
473
|
-
return self;
|
474
|
-
}
|
475
|
-
|
476
|
-
VALUE rb_glfw_window_get_input_cursor(VALUE self) {
|
477
|
-
WINDOW();
|
478
|
-
return INT2BOOL(glfwGetInputMode(w, GLFW_CURSOR));
|
479
|
-
}
|
480
|
-
|
481
|
-
VALUE rb_glfw_window_set_input_cursor(VALUE self, VALUE value) {
|
482
|
-
WINDOW();
|
483
|
-
glfwSetInputMode(w, GLFW_CURSOR, RTEST(value));
|
484
|
-
return value;
|
485
|
-
}
|
486
|
-
|
487
|
-
VALUE rb_glfw_window_get_input_sticky_keys(VALUE self) {
|
488
|
-
WINDOW();
|
489
|
-
return INT2BOOL(glfwGetInputMode(w, GLFW_STICKY_KEYS));
|
490
|
-
}
|
491
|
-
|
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;
|
496
|
-
}
|
497
|
-
|
498
|
-
VALUE rb_glfw_window_get_input_sticky_mouse(VALUE self) {
|
499
|
-
WINDOW();
|
500
|
-
return INT2BOOL(glfwGetInputMode(w, GLFW_STICKY_MOUSE_BUTTONS));
|
501
|
-
}
|
502
|
-
|
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;
|
507
|
-
}
|
508
|
-
|
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;
|
517
|
-
}
|
518
|
-
|
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;
|
523
|
-
}
|
524
|
-
|
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;
|
531
|
-
}
|
532
|
-
|
533
|
-
VALUE rb_glfw_window_get_key(VALUE self, VALUE key) {
|
534
|
-
WINDOW();
|
535
|
-
return RTEST(glfwGetKey(w, NUM2INT(key)));
|
536
|
-
}
|
537
|
-
|
538
|
-
VALUE rb_glfw_window_get_mouse_button(VALUE self, VALUE mbtn) {
|
539
|
-
WINDOW();
|
540
|
-
return RTEST(glfwGetMouseButton(w, NUM2INT(mbtn)));
|
541
|
-
}
|
542
|
-
|
543
|
-
/////////////////////////////////////////////////////////////////////////////
|
544
|
-
// Callbacks
|
545
|
-
/////////////////////////////////////////////////////////////////////////////
|
546
|
-
|
547
|
-
VALUE rb_glfw_window_empty_method(int argc, VALUE *argv, VALUE self) {
|
548
|
-
// Empty method stub, as NULL causes segfaults
|
549
|
-
return Qnil;
|
550
|
-
}
|
551
|
-
|
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
|
-
|
607
|
-
return Qnil;
|
608
|
-
}
|
609
|
-
|
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);
|
614
|
-
}
|
615
|
-
|
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));
|
620
|
-
}
|
621
|
-
|
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
|
-
}
|
627
|
-
|
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);
|
632
|
-
}
|
633
|
-
|
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));
|
638
|
-
}
|
639
|
-
|
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
|
-
}
|
645
|
-
|
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
|
-
}
|
651
|
-
|
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));
|
656
|
-
}
|
657
|
-
|
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));
|
662
|
-
}
|
663
|
-
|
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));
|
668
|
-
}
|
669
|
-
|
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));
|
674
|
-
}
|
675
|
-
|
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));
|
680
|
-
}
|
681
|
-
|
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));
|
686
|
-
}
|
687
|
-
|
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));
|
692
|
-
}
|
693
|
-
|
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
|
-
}
|
708
|
-
}
|
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
|
+
}
|
141
|
+
|
142
|
+
// Share
|
143
|
+
share = rb_hash_aref(options, STR2SYM("share"));
|
144
|
+
if (!NIL_P(share))
|
145
|
+
Data_Get_Struct(share, GLFWwindow, other);
|
146
|
+
}
|
147
|
+
|
148
|
+
window = glfwCreateWindow(NUM2INT(width), NUM2INT(height), str, mon, other);
|
149
|
+
RDATA(self)->data = window;
|
150
|
+
|
151
|
+
// Store the Ruby VALUE as a "user pointer" to get the Ruby instance from the C struct
|
152
|
+
glfwSetWindowUserPointer(window, (void *)self);
|
153
|
+
|
154
|
+
if (rb_block_given_p()) {
|
155
|
+
rb_yield(self);
|
156
|
+
glfwDestroyWindow(window);
|
157
|
+
}
|
158
|
+
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
|
162
|
+
VALUE rb_glfw_window_destroy(VALUE self) {
|
163
|
+
WINDOW();
|
164
|
+
glfwDestroyWindow(w);
|
165
|
+
return self;
|
166
|
+
}
|
167
|
+
|
168
|
+
VALUE rb_glfw_window_show(VALUE self) {
|
169
|
+
WINDOW();
|
170
|
+
glfwShowWindow(w);
|
171
|
+
return self;
|
172
|
+
}
|
173
|
+
|
174
|
+
VALUE rb_glfw_window_hide(VALUE self) {
|
175
|
+
WINDOW();
|
176
|
+
glfwHideWindow(w);
|
177
|
+
return self;
|
178
|
+
}
|
179
|
+
|
180
|
+
VALUE rb_glfw_window_minimize(VALUE self) {
|
181
|
+
WINDOW();
|
182
|
+
glfwIconifyWindow(w);
|
183
|
+
return self;
|
184
|
+
}
|
185
|
+
|
186
|
+
VALUE rb_glfw_window_maximize(VALUE self) {
|
187
|
+
WINDOW();
|
188
|
+
glfwMaximizeWindow(w);
|
189
|
+
return self;
|
190
|
+
}
|
191
|
+
|
192
|
+
VALUE rb_glfw_window_restore(VALUE self) {
|
193
|
+
WINDOW();
|
194
|
+
glfwRestoreWindow(w);
|
195
|
+
return self;
|
196
|
+
}
|
197
|
+
|
198
|
+
VALUE rb_glfw_window_focus(VALUE self) {
|
199
|
+
WINDOW();
|
200
|
+
glfwFocusWindow(w);
|
201
|
+
return self;
|
202
|
+
}
|
203
|
+
|
204
|
+
VALUE rb_glfw_window_swap_buffers(VALUE self) {
|
205
|
+
WINDOW();
|
206
|
+
glfwSwapBuffers(w);
|
207
|
+
return Qnil;
|
208
|
+
}
|
209
|
+
|
210
|
+
VALUE rb_glfw_window_make_current(VALUE self) {
|
211
|
+
WINDOW();
|
212
|
+
glfwMakeContextCurrent(w);
|
213
|
+
return Qnil;
|
214
|
+
}
|
215
|
+
|
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;
|
227
|
+
}
|
228
|
+
|
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;
|
237
|
+
}
|
238
|
+
|
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;
|
243
|
+
}
|
244
|
+
|
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;
|
253
|
+
}
|
254
|
+
|
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;
|
259
|
+
}
|
260
|
+
|
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;
|
348
|
+
}
|
349
|
+
return self;
|
350
|
+
}
|
351
|
+
|
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);
|
356
|
+
}
|
357
|
+
|
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;
|
377
|
+
}
|
378
|
+
return self;
|
379
|
+
}
|
380
|
+
|
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;
|
386
|
+
}
|
387
|
+
|
388
|
+
VALUE rb_glfw_window_focused_p(VALUE self) {
|
389
|
+
WINDOW();
|
390
|
+
return glfwGetWindowAttrib(w, GLFW_FOCUSED) ? Qtrue : Qfalse;
|
391
|
+
}
|
392
|
+
|
393
|
+
VALUE rb_glfw_window_minimized_p(VALUE self) {
|
394
|
+
WINDOW();
|
395
|
+
return glfwGetWindowAttrib(w, GLFW_ICONIFIED) ? Qtrue : Qfalse;
|
396
|
+
}
|
397
|
+
|
398
|
+
VALUE rb_glfw_window_maximized_p(VALUE self) {
|
399
|
+
WINDOW();
|
400
|
+
return glfwGetWindowAttrib(w, GLFW_MAXIMIZED) ? Qtrue : Qfalse;
|
401
|
+
}
|
402
|
+
|
403
|
+
VALUE rb_glfw_window_visible_p(VALUE self) {
|
404
|
+
WINDOW();
|
405
|
+
return glfwGetWindowAttrib(w, GLFW_VISIBLE) ? Qtrue : Qfalse;
|
406
|
+
}
|
407
|
+
|
408
|
+
VALUE rb_glfw_window_resizable_p(VALUE self) {
|
409
|
+
WINDOW();
|
410
|
+
return glfwGetWindowAttrib(w, GLFW_RESIZABLE) ? Qtrue : Qfalse;
|
411
|
+
}
|
412
|
+
|
413
|
+
VALUE rb_glfw_window_decorated_p(VALUE self) {
|
414
|
+
WINDOW();
|
415
|
+
return glfwGetWindowAttrib(w, GLFW_DECORATED) ? Qtrue : Qfalse;
|
416
|
+
}
|
417
|
+
|
418
|
+
VALUE rb_glfw_window_floating_p(VALUE self) {
|
419
|
+
WINDOW();
|
420
|
+
return glfwGetWindowAttrib(w, GLFW_FLOATING) ? Qtrue : Qfalse;
|
421
|
+
}
|
422
|
+
|
423
|
+
VALUE rb_glfw_window_aspect_ratio(VALUE self, VALUE numerator, VALUE denominator) {
|
424
|
+
WINDOW();
|
425
|
+
glfwSetWindowAspectRatio(w, NUM2INT(numerator), NUM2INT(denominator));
|
426
|
+
return Qnil;
|
427
|
+
}
|
428
|
+
|
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;
|
433
|
+
}
|
434
|
+
|
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;
|
445
|
+
}
|
446
|
+
|
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);
|
451
|
+
}
|
452
|
+
|
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;
|
458
|
+
}
|
459
|
+
|
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);
|
464
|
+
|
465
|
+
for (int i = 0; i < argc; i++) {
|
466
|
+
VALUE img = rb_ary_entry(args, i);
|
467
|
+
images[i] = *(GLFWimage *)RDATA(img)->data;
|
468
|
+
}
|
469
|
+
|
470
|
+
glfwSetWindowIcon(w, argc, images);
|
471
|
+
|
472
|
+
free(images);
|
473
|
+
return self;
|
474
|
+
}
|
475
|
+
|
476
|
+
VALUE rb_glfw_window_get_input_cursor(VALUE self) {
|
477
|
+
WINDOW();
|
478
|
+
return INT2BOOL(glfwGetInputMode(w, GLFW_CURSOR));
|
479
|
+
}
|
480
|
+
|
481
|
+
VALUE rb_glfw_window_set_input_cursor(VALUE self, VALUE value) {
|
482
|
+
WINDOW();
|
483
|
+
glfwSetInputMode(w, GLFW_CURSOR, RTEST(value));
|
484
|
+
return value;
|
485
|
+
}
|
486
|
+
|
487
|
+
VALUE rb_glfw_window_get_input_sticky_keys(VALUE self) {
|
488
|
+
WINDOW();
|
489
|
+
return INT2BOOL(glfwGetInputMode(w, GLFW_STICKY_KEYS));
|
490
|
+
}
|
491
|
+
|
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;
|
496
|
+
}
|
497
|
+
|
498
|
+
VALUE rb_glfw_window_get_input_sticky_mouse(VALUE self) {
|
499
|
+
WINDOW();
|
500
|
+
return INT2BOOL(glfwGetInputMode(w, GLFW_STICKY_MOUSE_BUTTONS));
|
501
|
+
}
|
502
|
+
|
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;
|
507
|
+
}
|
508
|
+
|
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;
|
517
|
+
}
|
518
|
+
|
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;
|
523
|
+
}
|
524
|
+
|
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;
|
531
|
+
}
|
532
|
+
|
533
|
+
VALUE rb_glfw_window_get_key(VALUE self, VALUE key) {
|
534
|
+
WINDOW();
|
535
|
+
return RTEST(glfwGetKey(w, NUM2INT(key)));
|
536
|
+
}
|
537
|
+
|
538
|
+
VALUE rb_glfw_window_get_mouse_button(VALUE self, VALUE mbtn) {
|
539
|
+
WINDOW();
|
540
|
+
return RTEST(glfwGetMouseButton(w, NUM2INT(mbtn)));
|
541
|
+
}
|
542
|
+
|
543
|
+
/////////////////////////////////////////////////////////////////////////////
|
544
|
+
// Callbacks
|
545
|
+
/////////////////////////////////////////////////////////////////////////////
|
546
|
+
|
547
|
+
VALUE rb_glfw_window_empty_method(int argc, VALUE *argv, VALUE self) {
|
548
|
+
// Empty method stub, as NULL causes segfaults
|
549
|
+
return Qnil;
|
550
|
+
}
|
551
|
+
|
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
|
+
|
607
|
+
return Qnil;
|
608
|
+
}
|
609
|
+
|
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);
|
614
|
+
}
|
615
|
+
|
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));
|
620
|
+
}
|
621
|
+
|
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
|
+
}
|
627
|
+
|
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);
|
632
|
+
}
|
633
|
+
|
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));
|
638
|
+
}
|
639
|
+
|
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
|
+
}
|
645
|
+
|
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
|
+
}
|
651
|
+
|
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));
|
656
|
+
}
|
657
|
+
|
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));
|
662
|
+
}
|
663
|
+
|
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));
|
668
|
+
}
|
669
|
+
|
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));
|
674
|
+
}
|
675
|
+
|
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));
|
680
|
+
}
|
681
|
+
|
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));
|
686
|
+
}
|
687
|
+
|
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));
|
692
|
+
}
|
693
|
+
|
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
|
+
}
|
708
|
+
}
|