-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.c
276 lines (224 loc) · 7.84 KB
/
window.c
1
2
3
4
5
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#include "ext_rgss.h"
#include "graphics.h"
#include "window.h"
#include "rect.h"
#include "bitmap.h"
static void Window__mark(void *ptr) {
}
static void Window__free(void *ptr) {
if(ptr) free(ptr);
}
static size_t Window__memsize(const void *ptr) {
return ptr ? sizeof(Window) : 0;
}
const rb_data_type_t Window_data_type = {
"window", {Window__mark, Window__free, Window__memsize,},
};
static VALUE Window_s_alloc(VALUE klass) {
VALUE obj;
Window *window;
obj = TypedData_Make_Struct(klass, Window, &Window_data_type, window);
return obj;
}
static void Window__update_vertex(Window *window) {
VALUE contents = window->contents;
RgssBitmapData *bmpdata = RGSS_BITMAPDATA(contents);
BitmapExtData *extdata = BITMAP_EXTDATA(bmpdata);
VERTEX *v = window->vertex_data;
v[0].z = v[1].z = v[2].z = v[3].z = 0;
v[0].x = v[2].x = window->x - 0.5;
v[0].y = v[1].y = window->y - 0.5;
v[1].x = v[3].x = window->x + window->width - 0.5;
v[2].y = v[3].y = window->y + window->height - 0.5;
v[0].u = v[2].u = -window->width;
v[0].v = v[1].v = -window->height;
v[1].u = v[3].u = window->width;
v[2].v = v[3].v = window->height;
v[0].w = v[1].w = v[2].w = v[3].w = extdata->texw;
v[0].h = v[1].h = v[2].h = v[3].h = extdata->texh;
v[0].b1 = v[1].b1 = v[2].b1 = v[3].b1 = window->openness;
v[0].b2 = v[1].b2 = v[2].b2 = v[3].b2 = window->opacity;
v[0].b3 = v[1].b3 = v[2].b3 = v[3].b3 = window->contents_opacity;
}
static VALUE Window_initialize(int argc, VALUE *argv, VALUE self) {
VALUE windows = rb_ivar_get(mGraphics, rb_intern("@windows"));
VALUE bmp_argv[2] = {INT2FIX(1), INT2FIX(1)};
VALUE contents = rb_class_new_instance(2, bmp_argv, cBitmap);
VALUE cursor_rect = rb_class_new_instance(0, NULL, cRect);
Window *window = EXT_WINDOW(self);
rb_ary_push(windows, self);
contents = old_call(self, rb_intern("contents"), 0, NULL); /* TODO */
rb_ivar_set(self, rb_intern("@contents"), contents);
window->contents = contents;
Bitmap__init_extdata(contents);
cursor_rect = old_call(self, rb_intern("cursor_rect"), 0, NULL); /* TODO */
rb_ivar_set(self, rb_intern("@cursor_rect"), cursor_rect);
Rect__add_ref(cursor_rect, self);
window->cursor_rect = cursor_rect;
switch(argc) {
case 0:
window->x = window->y = window->width = window->height = 0;
break;
case 4:
window->x = FIX2INT(argv[0]);
window->y = FIX2INT(argv[1]);
window->width = FIX2INT(argv[2]);
window->height = FIX2INT(argv[3]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0, 4)", argc);
}
window->ox = window->oy = 0;
window->disposed = 0;
window->visible = 1;
window->openness = 255;
window->opacity = window->contents_opacity = 255;
Window__update_vertex(window);
return self;
}
static VALUE Window_dispose(VALUE self) {
Window *window = EXT_WINDOW(self);
if(!window->disposed) {
VALUE windows = rb_ivar_get(mGraphics, rb_intern("@windows"));
rb_ary_delete(windows, self);
Rect__remove_ref(window->cursor_rect, self);
old_call(self, rb_intern("dispose"), 0, NULL);
window->disposed = 1;
}
return self;
}
static VALUE Window_x_set(VALUE self, VALUE x) {
Window *window = EXT_WINDOW(self);
window->x = NUM2LONG(x);
Window__update_vertex(window);
old_call(self, rb_intern("x="), 1, &x);
return x;
}
static VALUE Window_x(VALUE self) {
Window *window = EXT_WINDOW(self);
return INT2FIX(window->x);
}
static VALUE Window_y_set(VALUE self, VALUE y) {
Window *window = EXT_WINDOW(self);
window->y = NUM2LONG(y);
Window__update_vertex(window);
old_call(self, rb_intern("y="), 1, &y);
return y;
}
static VALUE Window_y(VALUE self) {
Window *window = EXT_WINDOW(self);
return INT2FIX(window->y);
}
static VALUE Window_openness_set(VALUE self, VALUE openness) {
Window *window = EXT_WINDOW(self);
int o;
o = NUM2LONG(openness);
if(o < 0) {
o = 0;
} else if(o > 255) {
o = 255;
}
window->openness = o;
openness = INT2FIX(o);
Window__update_vertex(window);
old_call(self, rb_intern("openness="), 1, &openness);
return openness;
}
static VALUE Window_openness(VALUE self) {
Window *window = EXT_WINDOW(self);
return INT2FIX(window->openness);
}
static VALUE Window_opacity_set(VALUE self, VALUE opacity) {
Window *window = EXT_WINDOW(self);
int o;
o = NUM2LONG(opacity);
if(o < 0) {
o = 0;
} else if(o > 255) {
o = 255;
}
window->opacity = o;
opacity = INT2FIX(o);
Window__update_vertex(window);
old_call(self, rb_intern("opacity="), 1, &opacity);
return opacity;
}
static VALUE Window_opacity(VALUE self) {
Window *window = EXT_WINDOW(self);
return INT2FIX(window->opacity);
}
static VALUE Window_contents_opacity_set(VALUE self, VALUE contents_opacity) {
Window *window = EXT_WINDOW(self);
int o;
o = NUM2LONG(contents_opacity);
if(o < 0) {
o = 0;
} else if(o > 255) {
o = 255;
}
window->contents_opacity = o;
contents_opacity = INT2FIX(o);
Window__update_vertex(window);
old_call(self, rb_intern("contents_opacity="), 1, &contents_opacity);
return contents_opacity;
}
static VALUE Window_contents_opacity(VALUE self) {
Window *window = EXT_WINDOW(self);
return INT2FIX(window->contents_opacity);
}
static VALUE Window_contents_set(VALUE self, VALUE contents) {
Window *window = EXT_WINDOW(self);
window->contents = contents;
old_call(self, rb_intern("contents="), 1, &contents);
Window__update_vertex(window);
return contents;
}
static VALUE Window_contents(VALUE self) {
Window *window = EXT_WINDOW(self);
return window->contents;
}
static VALUE Window_windowskin_set(VALUE self, VALUE skin) {
Window *window = EXT_WINDOW(self);
window->skin = skin;
old_call(self, rb_intern("windowskin="), 1, &skin);
return skin;
}
static VALUE Window_windowskin(VALUE self) {
Window *window = EXT_WINDOW(self);
return window->skin;
}
static VALUE Window_visible_set(VALUE self, VALUE visible) {
Window *window = EXT_WINDOW(self);
window->visible = !!RTEST(visible);
old_call(self, rb_intern("visible="), 1, &visible);
return visible;
}
static VALUE Window_visible(VALUE self) {
Window *window = EXT_WINDOW(self);
return window->visible ? Qtrue : Qfalse;
}
void Init_ExtWindow() {
VALUE cOldWindow = rb_const_get(rb_cObject, rb_intern("Window"));
VALUE cWindow = rb_define_class_under(mExtRgss, "Window", rb_cObject);
rb_const_set(rb_cObject, rb_intern("OldWindow"), cOldWindow);
rb_const_set(rb_cObject, rb_intern("Window"), cWindow);
rb_define_alloc_func(cWindow, Window_s_alloc);
rb_define_method(cWindow, "initialize", Window_initialize, -1);
rb_define_method(cWindow, "dispose", Window_dispose, 0);
rb_define_method(cWindow, "x=", Window_x_set, 1);
rb_define_method(cWindow, "x", Window_x, 0);
rb_define_method(cWindow, "y=", Window_y_set, 1);
rb_define_method(cWindow, "y", Window_y, 0);
rb_define_method(cWindow, "openness=", Window_openness_set, 1);
rb_define_method(cWindow, "openness", Window_openness, 0);
rb_define_method(cWindow, "opacity=", Window_opacity_set, 1);
rb_define_method(cWindow, "opacity", Window_opacity, 0);
rb_define_method(cWindow, "contents_opacity=", Window_contents_opacity_set, 1);
rb_define_method(cWindow, "contents_opacity", Window_contents_opacity, 0);
rb_define_method(cWindow, "contents=", Window_contents_set, 1);
rb_define_method(cWindow, "contents", Window_contents, 0);
rb_define_method(cWindow, "windowskin=", Window_windowskin_set, 1);
rb_define_method(cWindow, "windowskin", Window_windowskin, 0);
rb_define_method(cWindow, "visible=", Window_visible_set, 1);
rb_define_method(cWindow, "visible", Window_visible, 0);
}