glfw 1.0.3 → 3.3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +161 -0
- data/.yardopts +6 -0
- data/Gemfile +2 -4
- data/README.md +29 -33
- data/Rakefile +6 -4
- data/ext/glfw/common.c +159 -0
- data/ext/glfw/cursor.c +34 -30
- data/ext/glfw/extconf.rb +7 -17
- data/ext/glfw/glfw.c +122 -377
- data/ext/glfw/glfw.h +46 -41
- data/ext/glfw/image.c +96 -64
- data/ext/glfw/joystick.c +169 -0
- data/ext/glfw/monitor.c +231 -155
- data/ext/glfw/stb_image.h +7656 -0
- data/ext/glfw/window.c +708 -576
- data/glfw.gemspec +10 -9
- data/lib/glfw.rb +4 -14
- data/lib/glfw/constants.rb +365 -0
- data/lib/glfw/stubs.rb +234 -0
- data/lib/glfw/stubs/cursor.rb +21 -0
- data/lib/glfw/stubs/gamepad_state.rb +30 -0
- data/lib/glfw/stubs/image.rb +39 -0
- data/lib/glfw/stubs/joystick.rb +125 -0
- data/lib/glfw/stubs/monitor.rb +115 -0
- data/lib/glfw/stubs/video_mode.rb +32 -0
- data/lib/glfw/stubs/window.rb +626 -0
- data/lib/glfw/version.rb +8 -1
- metadata +31 -35
- data/.travis.yml +0 -5
- data/Makefile +0 -267
- data/ext/glfw/common.h +0 -46
- data/ext/glfw/cursor.h +0 -14
- data/ext/glfw/glfw3.h +0 -4248
- data/ext/glfw/glfw3native.h +0 -456
- data/ext/glfw/image.h +0 -14
- 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
- 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
- data/ext/glfw/monitor.h +0 -29
- data/ext/glfw/video_mode.c +0 -60
- data/ext/glfw/video_mode.h +0 -21
- data/ext/glfw/vulkan.c +0 -48
- data/ext/glfw/vulkan.h +0 -16
- data/ext/glfw/window.h +0 -87
data/ext/glfw/glfw.h
CHANGED
@@ -1,41 +1,46 @@
|
|
1
|
-
#ifndef
|
2
|
-
#define
|
3
|
-
|
4
|
-
#include "
|
5
|
-
#include "
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
1
|
+
#ifndef RB_GLFW_H
|
2
|
+
#define RB_GLFW_H 1
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
#include "GLFW/glfw3.h"
|
6
|
+
|
7
|
+
#define GLFW_IMAGE_LOADER 1
|
8
|
+
|
9
|
+
extern VALUE mGLFW;
|
10
|
+
extern VALUE eGLFWError;
|
11
|
+
extern VALUE cWindow;
|
12
|
+
extern VALUE cMonitor;
|
13
|
+
extern VALUE cImage;
|
14
|
+
extern VALUE cCursor;
|
15
|
+
extern VALUE cVideoMode;
|
16
|
+
extern VALUE mJoystick;
|
17
|
+
extern VALUE cGamepadState;
|
18
|
+
extern VALUE cPoint;
|
19
|
+
extern VALUE cSize;
|
20
|
+
extern VALUE cVec2;
|
21
|
+
|
22
|
+
#define RB_BOOL(exp) ((exp) ? Qtrue : Qfalse)
|
23
|
+
#define NUM2FLT(v) ((float) NUM2DBL(v))
|
24
|
+
#define STR2SYM(str) (ID2SYM(rb_intern(str)))
|
25
|
+
|
26
|
+
void rb_glfw_window_init(void);
|
27
|
+
void rb_glfw_monitor_init(void);
|
28
|
+
void rb_glfw_image_init(void);
|
29
|
+
void rb_glfw_cursor_init(void);
|
30
|
+
void rb_glfw_common_init(void);
|
31
|
+
void rb_glfw_joystick_init(void);
|
32
|
+
|
33
|
+
typedef struct {
|
34
|
+
int x;
|
35
|
+
int y;
|
36
|
+
} RBivec2;
|
37
|
+
|
38
|
+
typedef struct {
|
39
|
+
double x;
|
40
|
+
double y;
|
41
|
+
} RBvec2;
|
42
|
+
|
43
|
+
VALUE rb_glfw_ivec2_create(VALUE klass, int x, int y);
|
44
|
+
VALUE rb_glfw_vec2_create(VALUE klass, double x, double y);
|
45
|
+
|
46
|
+
#endif /* RB_GLFW_H */
|
data/ext/glfw/image.c
CHANGED
@@ -1,77 +1,109 @@
|
|
1
1
|
|
2
|
-
#include "
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
2
|
+
#include "glfw.h"
|
3
|
+
|
4
|
+
#ifdef GLFW_IMAGE_LOADER
|
5
|
+
#define STBI_MALLOC xmalloc
|
6
|
+
#define STBI_REALLOC xrealloc
|
7
|
+
#define STBI_FREE xfree
|
8
|
+
#define STB_IMAGE_IMPLEMENTATION 1
|
9
|
+
#include "stb_image.h"
|
10
|
+
#define ARG_PATTERN "12"
|
11
|
+
#else
|
12
|
+
#define ARG_PATTERN "21"
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#define BYTES_PER_PIXEL (4)
|
16
|
+
|
17
|
+
VALUE cImage;
|
18
|
+
|
19
|
+
static void rb_glfw_image_free(void *image)
|
20
|
+
{
|
21
|
+
GLFWimage *img = image;
|
22
|
+
if (img->pixels)
|
23
|
+
xfree(img->pixels);
|
24
|
+
xfree(img);
|
18
25
|
}
|
19
26
|
|
20
|
-
static VALUE rb_glfw_image_alloc(VALUE klass)
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
static VALUE rb_glfw_image_alloc(VALUE klass)
|
28
|
+
{
|
29
|
+
GLFWimage *img = ALLOC(GLFWimage);
|
30
|
+
memset(img, 0, sizeof(GLFWimage));
|
31
|
+
return Data_Wrap_Struct(klass, NULL, rb_glfw_image_free, img);
|
24
32
|
}
|
25
33
|
|
26
|
-
VALUE
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
image->width = NUM2INT(argv[0]);
|
31
|
-
image->height = NUM2INT(argv[1]);
|
32
|
-
|
33
|
-
if (argc == 3)
|
34
|
-
{
|
35
|
-
if (RB_TYPE_P(argv[2], T_STRING))
|
36
|
-
{
|
37
|
-
image->pixels = StringValuePtr(argv[2]);
|
38
|
-
}
|
39
|
-
else
|
40
|
-
{
|
41
|
-
uint32_t packed = NUM2UINT(argv[2]);
|
42
|
-
int size = sizeof(uint32_t) * image->width * image->height;
|
43
|
-
image->pixels = malloc(size);
|
44
|
-
memset(image->pixels, packed, size);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
else
|
48
|
-
{
|
49
|
-
int size = 4 * image->width * image->height;
|
50
|
-
image->pixels = malloc(size);
|
51
|
-
memset(image->pixels, 0, size);
|
52
|
-
}
|
53
|
-
RDATA(self)->data = image;
|
54
|
-
return Qnil;
|
55
|
-
}
|
34
|
+
static VALUE rb_glfw_image_width(VALUE self)
|
35
|
+
{
|
36
|
+
return INT2NUM(((GLFWimage *)DATA_PTR(self))->width);
|
37
|
+
}
|
56
38
|
|
57
|
-
|
39
|
+
static VALUE rb_glfw_image_height(VALUE self)
|
40
|
+
{
|
41
|
+
return INT2NUM(((GLFWimage *)DATA_PTR(self))->height);
|
58
42
|
}
|
59
43
|
|
60
|
-
VALUE
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
static VALUE rb_glfw_image_pixels(VALUE self)
|
45
|
+
{
|
46
|
+
GLFWimage *img = DATA_PTR(self);
|
47
|
+
long len = img->width * img->height * BYTES_PER_PIXEL;
|
48
|
+
return rb_str_new(img->pixels, len);
|
64
49
|
}
|
65
50
|
|
66
|
-
VALUE
|
67
|
-
|
68
|
-
|
69
|
-
|
51
|
+
static VALUE rb_glfw_image_initialize(int argc, VALUE *argv, VALUE self)
|
52
|
+
{
|
53
|
+
VALUE w, h, blob;
|
54
|
+
rb_scan_args(argc, argv, ARG_PATTERN, &w, &h, &blob);
|
55
|
+
GLFWimage *image = DATA_PTR(self);
|
56
|
+
|
57
|
+
switch (argc)
|
58
|
+
{
|
59
|
+
#ifdef GLFW_IMAGE_LOADER
|
60
|
+
case 1:
|
61
|
+
{
|
62
|
+
const char *filename = StringValueCStr(w);
|
63
|
+
image->pixels = stbi_load(filename, &image->width, &image->height, NULL, 4);
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
#endif
|
67
|
+
case 2:
|
68
|
+
{
|
69
|
+
image->width = NUM2INT(w);
|
70
|
+
image->height = NUM2INT(h);
|
71
|
+
size_t size = image->width * image->height * BYTES_PER_PIXEL;
|
72
|
+
if (size <= 0)
|
73
|
+
rb_raise(rb_eArgError, "invalid image size specified");
|
74
|
+
|
75
|
+
image->pixels = xcalloc(size, 1);
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
case 3:
|
79
|
+
{
|
80
|
+
image->width = NUM2INT(w);
|
81
|
+
image->height = NUM2INT(h);
|
82
|
+
size_t size = image->width * image->height * BYTES_PER_PIXEL;
|
83
|
+
|
84
|
+
if (size <= 0)
|
85
|
+
rb_raise(rb_eArgError, "invalid image size specified");
|
86
|
+
|
87
|
+
image->pixels = xmalloc(size);
|
88
|
+
memcpy(image->pixels, StringValuePtr(blob), size);
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
return Qnil;
|
70
94
|
}
|
71
95
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
96
|
+
void rb_glfw_image_init(void)
|
97
|
+
{
|
98
|
+
cImage = rb_define_class_under(mGLFW, "Image", rb_cObject);
|
99
|
+
rb_define_alloc_func(cImage, rb_glfw_image_alloc);
|
100
|
+
rb_define_method(cImage, "initialize", rb_glfw_image_initialize, -1);
|
101
|
+
|
102
|
+
rb_define_method(cImage, "width", rb_glfw_image_width, 0);
|
103
|
+
rb_define_method(cImage, "height", rb_glfw_image_height, 0);
|
104
|
+
rb_define_method(cImage, "pixels", rb_glfw_image_pixels, 0);
|
105
|
+
|
106
|
+
rb_define_alias(cImage, "columns", "width");
|
107
|
+
rb_define_alias(cImage, "rows", "height");
|
108
|
+
rb_define_alias(cImage, "to_blob", "pixels");
|
77
109
|
}
|
data/ext/glfw/joystick.c
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
|
2
|
+
#include "glfw.h"
|
3
|
+
|
4
|
+
VALUE mJoystick;
|
5
|
+
VALUE cGamepadState;
|
6
|
+
VALUE cb_joystick;
|
7
|
+
|
8
|
+
static VALUE rb_glfw_gamepad_state_alloc(VALUE klass)
|
9
|
+
{
|
10
|
+
GLFWgamepadstate *state = ALLOC(GLFWgamepadstate);
|
11
|
+
memset(state, 0, sizeof(GLFWgamepadstate));
|
12
|
+
return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, state);
|
13
|
+
}
|
14
|
+
|
15
|
+
static VALUE rb_glfw_gamepad_axis(VALUE self, VALUE axis)
|
16
|
+
{
|
17
|
+
int index = NUM2INT(axis);
|
18
|
+
if (index >= 0 && index <= GLFW_GAMEPAD_AXIS_LAST)
|
19
|
+
return DBL2NUM(((GLFWgamepadstate*) DATA_PTR(self))->axes[index]);
|
20
|
+
return DBL2NUM(0.0);
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE rb_glfw_gamepad_button(VALUE self, VALUE button)
|
24
|
+
{
|
25
|
+
int index = NUM2INT(button);
|
26
|
+
if (index >= 0 && index <= GLFW_GAMEPAD_BUTTON_LAST)
|
27
|
+
return RB_BOOL(((GLFWgamepadstate*) DATA_PTR(self))->buttons[index]);
|
28
|
+
return Qfalse;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rb_glfw_joystick_is_present(VALUE module, VALUE jid)
|
32
|
+
{
|
33
|
+
return RB_BOOL(glfwJoystickPresent(NUM2INT(jid)));
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE rb_glfw_joystick_is_gamepad(VALUE module, VALUE jid)
|
37
|
+
{
|
38
|
+
return RB_BOOL(glfwJoystickIsGamepad(NUM2INT(jid)));
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE rb_glfw_joystick_name(VALUE module, VALUE jid)
|
42
|
+
{
|
43
|
+
const char *name = glfwGetJoystickName(NUM2INT(jid));
|
44
|
+
return name ? rb_str_new_cstr(name) : Qnil;
|
45
|
+
}
|
46
|
+
|
47
|
+
static VALUE rb_glfw_joystick_gamepad_name(VALUE module, VALUE jid)
|
48
|
+
{
|
49
|
+
const char *name = glfwGetGamepadName(NUM2INT(jid));
|
50
|
+
return name ? rb_str_new_cstr(name) : Qnil;
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE rb_glfw_joystick_guid(VALUE module, VALUE jid)
|
54
|
+
{
|
55
|
+
const char *guid = glfwGetJoystickGUID(NUM2INT(jid));
|
56
|
+
return guid ? rb_str_new_cstr(guid) : Qnil;
|
57
|
+
}
|
58
|
+
|
59
|
+
static void rb_glfw_joystick_cb_connection(int jid, int event)
|
60
|
+
{
|
61
|
+
if (RTEST(cb_joystick))
|
62
|
+
{
|
63
|
+
VALUE args = rb_ary_new_from_args(2, INT2NUM(jid), RB_BOOL(event == GLFW_CONNECTED));
|
64
|
+
rb_proc_call(cb_joystick, args);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE rb_glfw_joystick_on_connection(VALUE module)
|
69
|
+
{
|
70
|
+
VALUE current = cb_joystick;
|
71
|
+
if (rb_block_given_p())
|
72
|
+
{
|
73
|
+
cb_joystick = rb_block_proc();
|
74
|
+
rb_iv_set(mJoystick, "@connection_proc", cb_joystick);
|
75
|
+
glfwSetJoystickCallback(rb_glfw_joystick_cb_connection);
|
76
|
+
}
|
77
|
+
else
|
78
|
+
{
|
79
|
+
cb_joystick = Qnil;
|
80
|
+
rb_iv_set(mJoystick, "@connection_proc", Qnil);
|
81
|
+
glfwSetJoystickCallback(NULL);
|
82
|
+
}
|
83
|
+
return current;
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE rb_glfw_joystick_update_mappings(int argc, VALUE *argv, VALUE module)
|
87
|
+
{
|
88
|
+
int count = 0;
|
89
|
+
for (int i = 0; i < argc; i++)
|
90
|
+
{
|
91
|
+
const char *str = StringValueCStr(argv[i]);
|
92
|
+
count += glfwUpdateGamepadMappings(str);
|
93
|
+
}
|
94
|
+
return INT2NUM(count);
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE rb_glfw_joystick_gamepad_state(VALUE module, VALUE jid)
|
98
|
+
{
|
99
|
+
GLFWgamepadstate *state = ALLOC(GLFWgamepadstate);
|
100
|
+
if (glfwGetGamepadState(NUM2INT(jid), state))
|
101
|
+
return Data_Wrap_Struct(cGamepadState, NULL, RUBY_DEFAULT_FREE, state);
|
102
|
+
xfree(state);
|
103
|
+
return Qnil;
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE rb_glfw_joystick_buttons(VALUE module, VALUE jid)
|
107
|
+
{
|
108
|
+
int count;
|
109
|
+
const unsigned char* buttons = glfwGetJoystickButtons(NUM2INT(jid), &count);
|
110
|
+
if (count > 0)
|
111
|
+
{
|
112
|
+
VALUE ary = rb_ary_new_capa(count);
|
113
|
+
for (int i = 0; i < count; i++)
|
114
|
+
rb_ary_store(ary, i, RB_BOOL(buttons[i]));
|
115
|
+
return ary;
|
116
|
+
}
|
117
|
+
return Qnil;
|
118
|
+
}
|
119
|
+
|
120
|
+
static VALUE rb_glfw_joystick_axes(VALUE module, VALUE jid)
|
121
|
+
{
|
122
|
+
int count;
|
123
|
+
const float* axes = glfwGetJoystickAxes(NUM2INT(jid), &count);
|
124
|
+
if (count > 0)
|
125
|
+
{
|
126
|
+
VALUE ary = rb_ary_new_capa(count);
|
127
|
+
for (int i = 0; i < count; i++)
|
128
|
+
rb_ary_store(ary, i, DBL2NUM(axes[i]));
|
129
|
+
return ary;
|
130
|
+
}
|
131
|
+
return Qnil;
|
132
|
+
}
|
133
|
+
|
134
|
+
static VALUE rb_glfw_joystick_hats(VALUE module, VALUE jid)
|
135
|
+
{
|
136
|
+
int count;
|
137
|
+
const unsigned char* hats = glfwGetJoystickHats(NUM2INT(jid), &count);
|
138
|
+
if (count > 0)
|
139
|
+
{
|
140
|
+
VALUE ary = rb_ary_new_capa(count);
|
141
|
+
for (int i = 0; i < count; i++)
|
142
|
+
rb_ary_store(ary, i, RB_BOOL(hats[i]));
|
143
|
+
return ary;
|
144
|
+
}
|
145
|
+
return Qnil;
|
146
|
+
}
|
147
|
+
|
148
|
+
void rb_glfw_joystick_init(void)
|
149
|
+
{
|
150
|
+
cGamepadState = rb_define_class_under(mGLFW, "GamepadState", rb_cObject);
|
151
|
+
rb_define_alloc_func(cGamepadState, rb_glfw_gamepad_state_alloc);
|
152
|
+
rb_define_method(cGamepadState, "axis", rb_glfw_gamepad_axis, 1);
|
153
|
+
rb_define_method(cGamepadState, "button", rb_glfw_gamepad_button, 1);
|
154
|
+
|
155
|
+
mJoystick = rb_define_module_under(mGLFW, "Joystick");
|
156
|
+
rb_define_singleton_method(mJoystick, "gamepad_state", rb_glfw_joystick_gamepad_state, 1);
|
157
|
+
rb_define_singleton_method(mJoystick, "name", rb_glfw_joystick_name, 1);
|
158
|
+
rb_define_singleton_method(mJoystick, "gamepad_name", rb_glfw_joystick_gamepad_name, 1);
|
159
|
+
rb_define_singleton_method(mJoystick, "present?", rb_glfw_joystick_is_present, 1);
|
160
|
+
rb_define_singleton_method(mJoystick, "gamepad?", rb_glfw_joystick_is_gamepad, 1);
|
161
|
+
rb_define_singleton_method(mJoystick, "guid", rb_glfw_joystick_guid, 1);
|
162
|
+
rb_define_singleton_method(mJoystick, "buttons", rb_glfw_joystick_buttons, 1);
|
163
|
+
rb_define_singleton_method(mJoystick, "axes", rb_glfw_joystick_axes, 1);
|
164
|
+
rb_define_singleton_method(mJoystick, "hats", rb_glfw_joystick_hats, 1);
|
165
|
+
rb_define_singleton_method(mJoystick, "update_mappings", rb_glfw_joystick_update_mappings, -1);
|
166
|
+
rb_define_singleton_method(mJoystick, "on_connection", rb_glfw_joystick_on_connection, 0);
|
167
|
+
|
168
|
+
cb_joystick = Qnil;
|
169
|
+
}
|
data/ext/glfw/monitor.c
CHANGED
@@ -1,209 +1,285 @@
|
|
1
|
+
#include "glfw.h"
|
1
2
|
|
2
|
-
|
3
|
+
VALUE cb_monitor;
|
4
|
+
VALUE cMonitor;
|
5
|
+
VALUE cVideoMode;
|
3
6
|
|
4
|
-
VALUE
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
rb_define_method(rb_cGLFWmonitor, "x", rb_glfw_monitor_x, 0);
|
13
|
-
rb_define_method(rb_cGLFWmonitor, "y", rb_glfw_monitor_y, 0);
|
14
|
-
rb_define_method(rb_cGLFWmonitor, "width", rb_glfw_monitor_width, 0);
|
15
|
-
rb_define_method(rb_cGLFWmonitor, "height", rb_glfw_monitor_height, 0);
|
16
|
-
rb_define_method(rb_cGLFWmonitor, "dimensions", rb_glfw_monitor_dimensions, 0);
|
17
|
-
|
18
|
-
rb_define_method(rb_cGLFWmonitor, "gamma", rb_glfw_monitor_gamma, 1);
|
19
|
-
rb_define_method(rb_cGLFWmonitor, "gamma_ramp", rb_glfw_monitor_get_gamma_ramp, 0);
|
20
|
-
rb_define_method(rb_cGLFWmonitor, "set_gamma_ramp", rb_glfw_monitor_set_gamma_ramp, -1);
|
21
|
-
rb_define_method(rb_cGLFWmonitor, "video_mode", rb_glfw_monitor_video_mode, 0);
|
22
|
-
rb_define_method(rb_cGLFWmonitor, "video_modes", rb_glfw_monitor_video_modes, 0);
|
23
|
-
|
24
|
-
rb_define_singleton_method(rb_cGLFWmonitor, "primary", rb_glfw_monitor_primary, 0);
|
25
|
-
rb_define_const(rb_cGLFWmonitor, "NONE", rb_glfw_monitor_alloc(rb_cGLFWmonitor));
|
26
|
-
|
27
|
-
rb_funcall(rb_cGLFWmonitor, rb_intern("private_class_method"), 1, STR2SYM("new"));
|
7
|
+
static inline VALUE rb_glfw_video_create(const GLFWvidmode *value)
|
8
|
+
{
|
9
|
+
GLFWvidmode *video = ALLOC(GLFWvidmode);
|
10
|
+
if (value)
|
11
|
+
memcpy(video, value, sizeof(GLFWvidmode));
|
12
|
+
else
|
13
|
+
memset(video, 0, sizeof(GLFWvidmode));
|
14
|
+
return Data_Wrap_Struct(cVideoMode, NULL, RUBY_DEFAULT_FREE, video);
|
28
15
|
}
|
29
16
|
|
30
|
-
static VALUE
|
31
|
-
|
32
|
-
|
33
|
-
|
17
|
+
static VALUE rb_glfw_video_alloc(VALUE klass)
|
18
|
+
{
|
19
|
+
GLFWvidmode *video = ALLOC(GLFWvidmode);
|
20
|
+
memset(video, 0, sizeof(GLFWvidmode));
|
21
|
+
return Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, video);
|
34
22
|
}
|
35
23
|
|
36
|
-
VALUE
|
37
|
-
|
38
|
-
|
39
|
-
return rb_str_new_cstr(name);
|
24
|
+
static VALUE rb_glfw_video_width(VALUE self)
|
25
|
+
{
|
26
|
+
return INT2NUM(((GLFWvidmode*) DATA_PTR(self))->width);
|
40
27
|
}
|
41
28
|
|
42
|
-
VALUE
|
43
|
-
|
44
|
-
|
45
|
-
glfwGetMonitorPos(m, &x, &y);
|
46
|
-
VALUE ary = rb_ary_new_capa(2);
|
47
|
-
rb_ary_store(ary, 0, INT2NUM(x));
|
48
|
-
rb_ary_store(ary, 1, INT2NUM(y));
|
49
|
-
return ary;
|
29
|
+
static VALUE rb_glfw_video_height(VALUE self)
|
30
|
+
{
|
31
|
+
return INT2NUM(((GLFWvidmode*) DATA_PTR(self))->height);
|
50
32
|
}
|
51
33
|
|
52
|
-
VALUE
|
53
|
-
|
54
|
-
|
55
|
-
glfwGetMonitorPhysicalSize(m, &width, &height);
|
56
|
-
VALUE ary = rb_ary_new_capa(2);
|
57
|
-
rb_ary_store(ary, 0, INT2NUM(width));
|
58
|
-
rb_ary_store(ary, 1, INT2NUM(height));
|
59
|
-
return ary;
|
34
|
+
static VALUE rb_glfw_video_r_bits(VALUE self)
|
35
|
+
{
|
36
|
+
return INT2NUM(((GLFWvidmode*) DATA_PTR(self))->redBits);
|
60
37
|
}
|
61
38
|
|
62
|
-
VALUE
|
63
|
-
|
64
|
-
|
65
|
-
glfwGetMonitorPos(m, &x, NULL);
|
66
|
-
return INT2NUM(x);
|
39
|
+
static VALUE rb_glfw_video_g_bits(VALUE self)
|
40
|
+
{
|
41
|
+
return INT2NUM(((GLFWvidmode*) DATA_PTR(self))->greenBits);
|
67
42
|
}
|
68
43
|
|
69
|
-
VALUE
|
70
|
-
|
71
|
-
|
72
|
-
glfwGetMonitorPos(m, NULL, &y);
|
73
|
-
return INT2NUM(y);
|
44
|
+
static VALUE rb_glfw_video_b_bits(VALUE self)
|
45
|
+
{
|
46
|
+
return INT2NUM(((GLFWvidmode*) DATA_PTR(self))->blueBits);
|
74
47
|
}
|
75
48
|
|
76
|
-
VALUE
|
77
|
-
|
78
|
-
|
79
|
-
glfwGetMonitorPhysicalSize(m, &width, NULL);
|
80
|
-
return INT2NUM(width);
|
49
|
+
static VALUE rb_glfw_video_refresh_rate(VALUE self)
|
50
|
+
{
|
51
|
+
return INT2NUM(((GLFWvidmode*) DATA_PTR(self))->refreshRate);
|
81
52
|
}
|
82
53
|
|
83
|
-
VALUE
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return INT2NUM(height);
|
54
|
+
static VALUE rb_glfw_video_to_s(VALUE self)
|
55
|
+
{
|
56
|
+
GLFWvidmode *v = DATA_PTR(self);
|
57
|
+
return rb_sprintf("<%s: width:%d, height:%d, r:%d, g:%d, b:%d, rate:%dhz>", rb_class2name(CLASS_OF(self)), v->width, v->height, v->redBits, v->greenBits, v->blueBits, v->refreshRate);
|
88
58
|
}
|
89
59
|
|
90
|
-
VALUE
|
91
|
-
|
92
|
-
|
93
|
-
glfwGetMonitorPos(m, &x, &y);
|
94
|
-
glfwGetMonitorPhysicalSize(m, &width, &height);
|
95
|
-
VALUE ary = rb_ary_new_capa(4);
|
96
|
-
rb_ary_store(ary, 0, INT2NUM(x));
|
97
|
-
rb_ary_store(ary, 1, INT2NUM(y));
|
98
|
-
rb_ary_store(ary, 2, INT2NUM(width));
|
99
|
-
rb_ary_store(ary, 3, INT2NUM(height));
|
100
|
-
return ary;
|
101
|
-
}
|
60
|
+
static VALUE rb_glfw_monitor_get_gamma_ramp(VALUE self)
|
61
|
+
{
|
62
|
+
const GLFWgammaramp *ramp = glfwGetGammaRamp(DATA_PTR(self));
|
102
63
|
|
103
|
-
|
104
|
-
|
105
|
-
|
64
|
+
long capa = (long) ramp->size;
|
65
|
+
VALUE r = rb_ary_new_capa(capa);
|
66
|
+
VALUE g = rb_ary_new_capa(capa);
|
67
|
+
VALUE b = rb_ary_new_capa(capa);
|
106
68
|
|
107
|
-
|
108
|
-
|
69
|
+
for (long i = 0; i < capa; i++)
|
70
|
+
{
|
71
|
+
rb_ary_store(r, i, USHORT2NUM(ramp->red[i]));
|
72
|
+
rb_ary_store(g, i, USHORT2NUM(ramp->green[i]));
|
73
|
+
rb_ary_store(b, i, USHORT2NUM(ramp->blue[i]));
|
74
|
+
}
|
75
|
+
return rb_ary_new_from_args(3, r, g, b);
|
76
|
+
}
|
109
77
|
|
110
|
-
|
111
|
-
|
112
|
-
|
78
|
+
static VALUE rb_glfw_monitor_set_gamma_ramp(VALUE self, VALUE gamma)
|
79
|
+
{
|
80
|
+
if (!RB_TYPE_P(gamma, T_ARRAY))
|
81
|
+
rb_raise(rb_eTypeError, "%s us not an Array", rb_obj_classname(CLASS_OF(gamma)));
|
82
|
+
if (rb_array_len(gamma) != 3)
|
83
|
+
rb_raise(rb_eArgError, "gamma array must have a length of 3");
|
113
84
|
|
114
|
-
for (int i = 0; i < count; i++) {
|
115
|
-
rb_ary_store(red, i, INT2NUM(ramp->red[i]));
|
116
|
-
rb_ary_store(green, i, INT2NUM(ramp->green[i]));
|
117
|
-
rb_ary_store(blue, i, INT2NUM(ramp->blue[i]));
|
118
|
-
}
|
119
85
|
|
120
|
-
|
121
|
-
|
122
|
-
|
86
|
+
VALUE r = rb_ary_entry(gamma, 0);
|
87
|
+
VALUE g = rb_ary_entry(gamma, 1);
|
88
|
+
VALUE b = rb_ary_entry(gamma, 2);
|
123
89
|
|
124
|
-
|
125
|
-
|
90
|
+
long capa = rb_array_len(g);
|
91
|
+
if (rb_array_len(r) != capa || rb_array_len(b) != capa)
|
92
|
+
rb_raise(rb_eArgError, "all arrays must be the same length");
|
126
93
|
|
127
|
-
|
128
|
-
|
94
|
+
GLFWgammaramp ramp = {0};
|
95
|
+
ramp.size = (unsigned int) capa;
|
96
|
+
ramp.red = xmalloc(sizeof(short) * capa);
|
97
|
+
ramp.green = xmalloc(sizeof(short) * capa);
|
98
|
+
ramp.blue = xmalloc(sizeof(short) * capa);
|
99
|
+
|
100
|
+
for (long i = 0; i < capa; i++)
|
129
101
|
{
|
130
|
-
|
131
|
-
|
102
|
+
ramp.red[i] = NUM2USHORT(rb_ary_entry(r, i));
|
103
|
+
ramp.green[i] = NUM2USHORT(rb_ary_entry(g, i));
|
104
|
+
ramp.blue[i] = NUM2USHORT(rb_ary_entry(b, i));
|
132
105
|
}
|
133
106
|
|
134
|
-
|
135
|
-
VALUE red, green, blue;
|
107
|
+
glfwSetGammaRamp(DATA_PTR(self), &ramp);
|
136
108
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
red = rb_hash_aref(argv[0], ID2SYM(rb_intern("red")));
|
141
|
-
green = rb_hash_aref(argv[0], ID2SYM(rb_intern("green")));
|
142
|
-
blue = rb_hash_aref(argv[0], ID2SYM(rb_intern("blue")));
|
143
|
-
}
|
144
|
-
else
|
145
|
-
{
|
146
|
-
red = argv[0];
|
147
|
-
green = argv[1];
|
148
|
-
blue = argv[2];
|
149
|
-
}
|
109
|
+
xfree(ramp.red);
|
110
|
+
xfree(ramp.green);
|
111
|
+
xfree(ramp.blue);
|
150
112
|
|
151
|
-
|
152
|
-
|
153
|
-
Check_Type(blue, T_ARRAY);
|
113
|
+
return gamma;
|
114
|
+
}
|
154
115
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
116
|
+
static VALUE rb_glfw_monitor_gamma(VALUE self, VALUE gamma)
|
117
|
+
{
|
118
|
+
glfwSetGamma(DATA_PTR(self), NUM2FLT(gamma));
|
119
|
+
return Qnil;
|
120
|
+
}
|
121
|
+
|
122
|
+
static VALUE rb_glfw_monitor_content_scale(VALUE self)
|
123
|
+
{
|
124
|
+
float x, y;
|
125
|
+
glfwGetMonitorContentScale(DATA_PTR(self), &x, &y);
|
126
|
+
return rb_glfw_vec2_create(cVec2, x, y);
|
127
|
+
}
|
161
128
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
129
|
+
static VALUE rb_glfw_monitor_video_mode(VALUE self)
|
130
|
+
{
|
131
|
+
const GLFWvidmode *mode = glfwGetVideoMode(DATA_PTR(self));
|
132
|
+
return rb_glfw_video_create(mode);
|
133
|
+
}
|
134
|
+
|
135
|
+
static VALUE rb_glfw_monitor_video_modes(VALUE self)
|
136
|
+
{
|
137
|
+
int count;
|
138
|
+
const GLFWvidmode *modes = glfwGetVideoModes(DATA_PTR(self), &count);
|
167
139
|
|
168
|
-
|
140
|
+
VALUE ary = rb_ary_new_capa(count);
|
141
|
+
for (int i = 0; i < count; i++)
|
169
142
|
{
|
170
|
-
|
171
|
-
|
172
|
-
ramp->blue[i] = NUM2USHORT(rb_ary_entry(blue, i));
|
143
|
+
VALUE video = rb_glfw_video_create(&modes[i]);
|
144
|
+
rb_ary_store(ary, i, video);
|
173
145
|
}
|
146
|
+
return ary;
|
147
|
+
}
|
174
148
|
|
175
|
-
|
149
|
+
static VALUE rb_glfw_monitor_work_area_location(VALUE self)
|
150
|
+
{
|
151
|
+
int x, y;
|
152
|
+
glfwGetMonitorWorkarea(DATA_PTR(self), &x, &y, NULL, NULL);
|
153
|
+
return rb_glfw_ivec2_create(cPoint, x, y);
|
154
|
+
}
|
176
155
|
|
177
|
-
|
178
|
-
|
156
|
+
static VALUE rb_glfw_monitor_work_area_size(VALUE self)
|
157
|
+
{
|
158
|
+
int w, h;
|
159
|
+
glfwGetMonitorWorkarea(DATA_PTR(self), NULL, NULL, &w, &h);
|
160
|
+
return rb_glfw_ivec2_create(cSize, w, h);
|
179
161
|
}
|
180
162
|
|
181
|
-
VALUE
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
return exponent;
|
163
|
+
static VALUE rb_glfw_monitor_size(VALUE self)
|
164
|
+
{
|
165
|
+
const GLFWvidmode *vid = glfwGetVideoMode(DATA_PTR(self));
|
166
|
+
return rb_glfw_ivec2_create(cSize, vid->width, vid->height);
|
186
167
|
}
|
187
168
|
|
188
|
-
VALUE
|
189
|
-
|
190
|
-
|
169
|
+
static VALUE rb_glfw_monitor_physical_size(VALUE self)
|
170
|
+
{
|
171
|
+
int w, h;
|
172
|
+
glfwGetMonitorPhysicalSize(DATA_PTR(self), &w, &h);
|
173
|
+
return rb_glfw_ivec2_create(cSize, w, h);
|
191
174
|
}
|
192
175
|
|
193
|
-
VALUE
|
194
|
-
|
195
|
-
|
196
|
-
|
176
|
+
static VALUE rb_glfw_monitor_position(VALUE self)
|
177
|
+
{
|
178
|
+
int x, y;
|
179
|
+
glfwGetMonitorPos(DATA_PTR(self), &x, &y);
|
180
|
+
return rb_glfw_ivec2_create(cPoint, x, y);
|
197
181
|
}
|
198
182
|
|
199
|
-
VALUE
|
200
|
-
|
183
|
+
static VALUE rb_glfw_monitor_available(VALUE klass)
|
184
|
+
{
|
201
185
|
int count;
|
202
|
-
|
186
|
+
GLFWmonitor **monitors = glfwGetMonitors(&count);
|
203
187
|
VALUE ary = rb_ary_new_capa(count);
|
188
|
+
|
204
189
|
for (int i = 0; i < count; i++)
|
205
190
|
{
|
206
|
-
|
191
|
+
VALUE monitor = Data_Wrap_Struct(klass, NULL, NULL, monitors[i]);
|
192
|
+
rb_ary_store(ary, i, monitor);
|
207
193
|
}
|
194
|
+
|
208
195
|
return ary;
|
209
196
|
}
|
197
|
+
|
198
|
+
static VALUE rb_glfw_monitor_name(VALUE self)
|
199
|
+
{
|
200
|
+
return rb_str_new_cstr(glfwGetMonitorName(DATA_PTR(self)));
|
201
|
+
}
|
202
|
+
|
203
|
+
static VALUE rb_glfw_monitor_eql(VALUE self, VALUE other)
|
204
|
+
{
|
205
|
+
|
206
|
+
if (CLASS_OF(self) != CLASS_OF(other))
|
207
|
+
return Qfalse;
|
208
|
+
|
209
|
+
return RB_BOOL(DATA_PTR(self) == DATA_PTR(other));
|
210
|
+
}
|
211
|
+
|
212
|
+
static VALUE rb_glfw_monitor_primary(VALUE klass)
|
213
|
+
{
|
214
|
+
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
215
|
+
return monitor ? Data_Wrap_Struct(klass, NULL, NULL, monitor) : Qnil;
|
216
|
+
}
|
217
|
+
|
218
|
+
static void rb_glfw_monitor_cb_connected(GLFWmonitor *monitor, int connected)
|
219
|
+
{
|
220
|
+
if (RTEST(cb_monitor))
|
221
|
+
{
|
222
|
+
VALUE mon = Data_Wrap_Struct(cMonitor, NULL, NULL, monitor);
|
223
|
+
VALUE state = RB_BOOL(connected == GLFW_CONNECTED);
|
224
|
+
rb_proc_call(cb_monitor, rb_ary_new_from_args(2, mon, state));
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
static VALUE rb_glfw_monitor_on_connection(VALUE klass)
|
229
|
+
{
|
230
|
+
VALUE current = cb_monitor;
|
231
|
+
if (rb_block_given_p())
|
232
|
+
{
|
233
|
+
cb_monitor = rb_block_proc();
|
234
|
+
glfwSetMonitorCallback(rb_glfw_monitor_cb_connected);
|
235
|
+
rb_iv_set(cMonitor, "@connection_proc", cb_monitor);
|
236
|
+
}
|
237
|
+
else
|
238
|
+
{
|
239
|
+
cb_monitor = Qnil;
|
240
|
+
glfwSetMonitorCallback(NULL);
|
241
|
+
rb_iv_set(cMonitor, "@connection_proc", Qnil);
|
242
|
+
}
|
243
|
+
return current;
|
244
|
+
}
|
245
|
+
|
246
|
+
static VALUE rb_glfw_monitor_to_s(VALUE self) {
|
247
|
+
return rb_str_new_cstr(glfwGetMonitorName(DATA_PTR(self)));
|
248
|
+
}
|
249
|
+
|
250
|
+
void rb_glfw_monitor_init(void)
|
251
|
+
{
|
252
|
+
|
253
|
+
cVideoMode = rb_define_class_under(mGLFW, "VideoMode", rb_cObject);
|
254
|
+
rb_define_alloc_func(cVideoMode, rb_glfw_video_alloc);
|
255
|
+
rb_define_method(cVideoMode, "width", rb_glfw_video_width, 0);
|
256
|
+
rb_define_method(cVideoMode, "height", rb_glfw_video_height, 0);
|
257
|
+
rb_define_method(cVideoMode, "red_bits", rb_glfw_video_r_bits, 0);
|
258
|
+
rb_define_method(cVideoMode, "green_bits", rb_glfw_video_g_bits, 0);
|
259
|
+
rb_define_method(cVideoMode, "blue_bits", rb_glfw_video_b_bits, 0);
|
260
|
+
rb_define_method(cVideoMode, "refresh_rate", rb_glfw_video_refresh_rate, 0);
|
261
|
+
rb_define_method(cVideoMode, "to_s", rb_glfw_video_to_s, 0);
|
262
|
+
|
263
|
+
cMonitor = rb_define_class_under(mGLFW, "Monitor", rb_cObject);
|
264
|
+
rb_define_singleton_method(cMonitor, "available", rb_glfw_monitor_available, 0);
|
265
|
+
rb_define_singleton_method(cMonitor, "primary", rb_glfw_monitor_primary, 0);
|
266
|
+
rb_define_singleton_method(cMonitor, "on_connection", rb_glfw_monitor_on_connection, 0);
|
267
|
+
|
268
|
+
rb_define_method(cMonitor, "name", rb_glfw_monitor_name, 0);
|
269
|
+
rb_define_method(cMonitor, "position", rb_glfw_monitor_position, 0);
|
270
|
+
rb_define_method(cMonitor, "physical_size", rb_glfw_monitor_physical_size, 0);
|
271
|
+
rb_define_method(cMonitor, "size", rb_glfw_monitor_size, 0);
|
272
|
+
rb_define_method(cMonitor, "client_position", rb_glfw_monitor_work_area_location, 0);
|
273
|
+
rb_define_method(cMonitor, "client_size", rb_glfw_monitor_work_area_size, 0);
|
274
|
+
rb_define_method(cMonitor, "video_mode", rb_glfw_monitor_video_mode, 0);
|
275
|
+
rb_define_method(cMonitor, "video_modes", rb_glfw_monitor_video_modes, 0);
|
276
|
+
rb_define_method(cMonitor, "content_scale", rb_glfw_monitor_content_scale, 0);
|
277
|
+
rb_define_method(cMonitor, "gamma", rb_glfw_monitor_gamma, 1);
|
278
|
+
rb_define_method(cMonitor, "gamma_ramp", rb_glfw_monitor_get_gamma_ramp, 0);
|
279
|
+
rb_define_method(cMonitor, "gamma_ramp=", rb_glfw_monitor_set_gamma_ramp, 1);
|
280
|
+
rb_define_method(cMonitor, "==", rb_glfw_monitor_eql, 1);
|
281
|
+
rb_define_method(cMonitor, "eql?", rb_glfw_monitor_eql, 1);
|
282
|
+
rb_define_method(cMonitor, "to_s", rb_glfw_monitor_to_s, 0);
|
283
|
+
|
284
|
+
cb_monitor = Qnil;
|
285
|
+
}
|