LiteRGSS 0.1.3
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 +7 -0
- data/ext/LiteRGSS/Bitmap.cpp +316 -0
- data/ext/LiteRGSS/Bitmap.h +24 -0
- data/ext/LiteRGSS/BlendMode.cpp +202 -0
- data/ext/LiteRGSS/BlendMode.h +20 -0
- data/ext/LiteRGSS/CBitmap_Element.cpp +50 -0
- data/ext/LiteRGSS/CBitmap_Element.h +17 -0
- data/ext/LiteRGSS/CDrawable_Element.cpp +38 -0
- data/ext/LiteRGSS/CDrawable_Element.h +30 -0
- data/ext/LiteRGSS/CRect_Element.h +15 -0
- data/ext/LiteRGSS/CShaderSprite_Element.cpp +17 -0
- data/ext/LiteRGSS/CShaderSprite_Element.h +17 -0
- data/ext/LiteRGSS/CSprite_Element.cpp +15 -0
- data/ext/LiteRGSS/CSprite_Element.h +36 -0
- data/ext/LiteRGSS/CText_Element.cpp +12 -0
- data/ext/LiteRGSS/CText_Element.h +29 -0
- data/ext/LiteRGSS/CTone_Element.h +17 -0
- data/ext/LiteRGSS/CViewport_Element.cpp +224 -0
- data/ext/LiteRGSS/CViewport_Element.h +57 -0
- data/ext/LiteRGSS/Color.cpp +200 -0
- data/ext/LiteRGSS/Color.h +22 -0
- data/ext/LiteRGSS/Fonts.cpp +126 -0
- data/ext/LiteRGSS/Fonts.h +20 -0
- data/ext/LiteRGSS/Graphics.cpp +314 -0
- data/ext/LiteRGSS/Graphics.h +31 -0
- data/ext/LiteRGSS/Graphics.local.cpp +365 -0
- data/ext/LiteRGSS/Graphics.local.h +37 -0
- data/ext/LiteRGSS/Image.cpp +460 -0
- data/ext/LiteRGSS/Image.h +32 -0
- data/ext/LiteRGSS/Input.cpp +664 -0
- data/ext/LiteRGSS/Input.h +38 -0
- data/ext/LiteRGSS/LiteRGSS.cpp +34 -0
- data/ext/LiteRGSS/LiteRGSS.h +113 -0
- data/ext/LiteRGSS/Rect.cpp +324 -0
- data/ext/LiteRGSS/Rect.h +24 -0
- data/ext/LiteRGSS/Shader.cpp +279 -0
- data/ext/LiteRGSS/Shader.h +13 -0
- data/ext/LiteRGSS/ShaderSprite.cpp +78 -0
- data/ext/LiteRGSS/ShaderSprite.h +8 -0
- data/ext/LiteRGSS/Sprite.cpp +495 -0
- data/ext/LiteRGSS/Sprite.h +43 -0
- data/ext/LiteRGSS/Table.cpp +228 -0
- data/ext/LiteRGSS/Table.h +29 -0
- data/ext/LiteRGSS/Table32.cpp +228 -0
- data/ext/LiteRGSS/Table32.h +29 -0
- data/ext/LiteRGSS/Text.cpp +574 -0
- data/ext/LiteRGSS/Text.h +52 -0
- data/ext/LiteRGSS/Texture.hpp +735 -0
- data/ext/LiteRGSS/Tone.cpp +228 -0
- data/ext/LiteRGSS/Tone.h +22 -0
- data/ext/LiteRGSS/Viewport.cpp +491 -0
- data/ext/LiteRGSS/Viewport.h +33 -0
- data/ext/LiteRGSS/Yuki.cpp +29 -0
- data/ext/LiteRGSS/Yuki.h +8 -0
- data/ext/LiteRGSS/Yuki_Gif.cpp +218 -0
- data/ext/LiteRGSS/Yuki_Gif.h +25 -0
- data/ext/LiteRGSS/extconf.rb +8 -0
- data/ext/LiteRGSS/libnsgif.c +1169 -0
- data/ext/LiteRGSS/libnsgif.h +183 -0
- data/ext/LiteRGSS/libnsgif.hpp +184 -0
- data/ext/LiteRGSS/lodepng.cpp +6245 -0
- data/ext/LiteRGSS/lodepng.h +1769 -0
- data/ext/LiteRGSS/lzw.c +377 -0
- data/ext/LiteRGSS/lzw.h +105 -0
- data/ext/LiteRGSS/sf_Text2.cpp +690 -0
- data/ext/LiteRGSS/sf_Text2.hpp +549 -0
- data/ext/LiteRGSS/utils/log.h +21 -0
- metadata +112 -0
@@ -0,0 +1,228 @@
|
|
1
|
+
#include "LiteRGSS.h"
|
2
|
+
#include "CTone_Element.h"
|
3
|
+
|
4
|
+
VALUE rb_cTone = Qnil;
|
5
|
+
|
6
|
+
#define TONE_PROTECT if(RDATA(self)->data == nullptr) \
|
7
|
+
{\
|
8
|
+
rb_raise(rb_eRGSSError, "Freed Tone."); \
|
9
|
+
}
|
10
|
+
|
11
|
+
#define GET_TONE CTone_Element* tone; \
|
12
|
+
Data_Get_Struct(self, CTone_Element, tone); \
|
13
|
+
TONE_PROTECT \
|
14
|
+
sf::Glsl::Vec4* tonev = tone->getTone();
|
15
|
+
|
16
|
+
void __Tone_Check_LinkedObject(CTone_Element* tone);
|
17
|
+
|
18
|
+
void rb_Tone_Free(void* data)
|
19
|
+
{
|
20
|
+
CTone_Element* tone = reinterpret_cast<CTone_Element*>(data);
|
21
|
+
if(tone)
|
22
|
+
{
|
23
|
+
CViewport_Element* viewport = tone->getElement();
|
24
|
+
if(viewport != nullptr)
|
25
|
+
{
|
26
|
+
viewport->setLinkedRect(nullptr);
|
27
|
+
}
|
28
|
+
delete tone;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE rb_Tone_Alloc(VALUE klass)
|
33
|
+
{
|
34
|
+
CTone_Element* tone = new CTone_Element();
|
35
|
+
return Data_Wrap_Struct(klass, NULL, rb_Tone_Free, tone);
|
36
|
+
}
|
37
|
+
|
38
|
+
void Init_Tone()
|
39
|
+
{
|
40
|
+
rb_cTone = rb_define_class_under(rb_mLiteRGSS, "Tone", rb_cObject);
|
41
|
+
rb_define_alloc_func(rb_cTone, rb_Tone_Alloc);
|
42
|
+
|
43
|
+
rb_define_method(rb_cTone, "initialize", _rbf rb_Tone_Initialize, -1);
|
44
|
+
rb_define_method(rb_cTone, "set", _rbf rb_Tone_Initialize, -1);
|
45
|
+
rb_define_method(rb_cTone, "initialize_copy", _rbf rb_Tone_InitializeCopy, 1);
|
46
|
+
rb_define_method(rb_cTone, "red", _rbf rb_Tone_getRed, 0);
|
47
|
+
rb_define_method(rb_cTone, "red=", _rbf rb_Tone_setRed, 1);
|
48
|
+
rb_define_method(rb_cTone, "green", _rbf rb_Tone_getGreen, 0);
|
49
|
+
rb_define_method(rb_cTone, "green=", _rbf rb_Tone_setGreen, 1);
|
50
|
+
rb_define_method(rb_cTone, "blue", _rbf rb_Tone_getBlue, 0);
|
51
|
+
rb_define_method(rb_cTone, "blue=", _rbf rb_Tone_setBlue, 1);
|
52
|
+
rb_define_method(rb_cTone, "gray", _rbf rb_Tone_getGray, 0);
|
53
|
+
rb_define_method(rb_cTone, "gray=", _rbf rb_Tone_setGray, 1);
|
54
|
+
rb_define_method(rb_cTone, "==", _rbf rb_Tone_eql, 1);
|
55
|
+
rb_define_method(rb_cTone, "===", _rbf rb_Tone_eql, 1);
|
56
|
+
rb_define_method(rb_cTone, "eql?", _rbf rb_Tone_eql, 1);
|
57
|
+
rb_define_method(rb_cTone, "to_s", _rbf rb_Tone_to_s, 0);
|
58
|
+
rb_define_method(rb_cTone, "inspect", _rbf rb_Tone_to_s, 0);
|
59
|
+
rb_define_method(rb_cTone, "_dump", _rbf rb_Tone_Save, 1);
|
60
|
+
rb_define_singleton_method(rb_cTone, "_load", _rbf rb_Tone_Load, 1);
|
61
|
+
}
|
62
|
+
|
63
|
+
VALUE rb_Tone_Initialize(int argc, VALUE* argv, VALUE self)
|
64
|
+
{
|
65
|
+
VALUE red, green, blue, alpha;
|
66
|
+
rb_scan_args(argc, argv, "13", &red, &green, &blue, &alpha);
|
67
|
+
GET_TONE
|
68
|
+
if(RTEST(red))
|
69
|
+
tonev->x = normalize_long(rb_num2long(red), -255, 255) / 255.0f;
|
70
|
+
if(RTEST(green))
|
71
|
+
tonev->y = normalize_long(rb_num2long(green), -255, 255) / 255.0f;
|
72
|
+
if(RTEST(blue))
|
73
|
+
tonev->z = normalize_long(rb_num2long(blue), -255, 255) / 255.0f;
|
74
|
+
if(RTEST(alpha))
|
75
|
+
tonev->w = normalize_long(rb_num2long(alpha), 0, 255) / 255.0f;
|
76
|
+
__Tone_Check_LinkedObject(tone);
|
77
|
+
return self;
|
78
|
+
}
|
79
|
+
|
80
|
+
VALUE rb_Tone_InitializeCopy(VALUE self, VALUE original)
|
81
|
+
{
|
82
|
+
GET_TONE
|
83
|
+
CTone_Element* toneo;
|
84
|
+
Data_Get_Struct(original, CTone_Element, toneo);
|
85
|
+
TONE_PROTECT
|
86
|
+
if(RDATA(original)->data == nullptr)
|
87
|
+
rb_raise(rb_eRGSSError, "Freed Tone.");
|
88
|
+
tone_copy(tonev, toneo->getTone());
|
89
|
+
return self;
|
90
|
+
}
|
91
|
+
|
92
|
+
VALUE rb_Tone_getRed(VALUE self)
|
93
|
+
{
|
94
|
+
GET_TONE
|
95
|
+
return rb_int2inum(static_cast<long>(tonev->x * 255.0f));
|
96
|
+
}
|
97
|
+
|
98
|
+
VALUE rb_Tone_setRed(VALUE self, VALUE val)
|
99
|
+
{
|
100
|
+
GET_TONE
|
101
|
+
tonev->x = normalize_long(rb_num2long(val), -255, 255) / 255.0f;
|
102
|
+
__Tone_Check_LinkedObject(tone);
|
103
|
+
return self;
|
104
|
+
}
|
105
|
+
|
106
|
+
VALUE rb_Tone_getGreen(VALUE self)
|
107
|
+
{
|
108
|
+
GET_TONE
|
109
|
+
return rb_int2inum(static_cast<long>(tonev->y * 255.0f));
|
110
|
+
}
|
111
|
+
|
112
|
+
VALUE rb_Tone_setGreen(VALUE self, VALUE val)
|
113
|
+
{
|
114
|
+
GET_TONE
|
115
|
+
tonev->y = normalize_long(rb_num2long(val), -255, 255) / 255.0f;
|
116
|
+
__Tone_Check_LinkedObject(tone);
|
117
|
+
return self;
|
118
|
+
}
|
119
|
+
|
120
|
+
VALUE rb_Tone_getBlue(VALUE self)
|
121
|
+
{
|
122
|
+
GET_TONE
|
123
|
+
return rb_int2inum(static_cast<long>(tonev->z * 255.0f));
|
124
|
+
}
|
125
|
+
|
126
|
+
VALUE rb_Tone_setBlue(VALUE self, VALUE val)
|
127
|
+
{
|
128
|
+
GET_TONE
|
129
|
+
tonev->z = normalize_long(rb_num2long(val), -255, 255) / 255.0f;
|
130
|
+
__Tone_Check_LinkedObject(tone);
|
131
|
+
return self;
|
132
|
+
}
|
133
|
+
|
134
|
+
VALUE rb_Tone_getGray(VALUE self)
|
135
|
+
{
|
136
|
+
GET_TONE
|
137
|
+
return rb_int2inum(static_cast<long>(tonev->w * 255.0f));
|
138
|
+
}
|
139
|
+
|
140
|
+
VALUE rb_Tone_setGray(VALUE self, VALUE val)
|
141
|
+
{
|
142
|
+
GET_TONE
|
143
|
+
tonev->w = normalize_long(rb_num2long(val), 0, 255) / 255.0f;
|
144
|
+
__Tone_Check_LinkedObject(tone);
|
145
|
+
return self;
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE rb_Tone_eql(VALUE self, VALUE other)
|
149
|
+
{
|
150
|
+
if(rb_obj_is_kind_of(other, rb_cTone) != Qtrue)
|
151
|
+
return Qfalse;
|
152
|
+
GET_TONE
|
153
|
+
CTone_Element* otone;
|
154
|
+
Data_Get_Struct(other, CTone_Element, otone);
|
155
|
+
if(otone == nullptr)
|
156
|
+
return Qfalse;
|
157
|
+
sf::Glsl::Vec4* otonev = otone->getTone();
|
158
|
+
if(tonev->x != otonev->x)
|
159
|
+
return Qfalse;
|
160
|
+
if(tonev->y != otonev->y)
|
161
|
+
return Qfalse;
|
162
|
+
if(tonev->z != otonev->z)
|
163
|
+
return Qfalse;
|
164
|
+
if(tonev->w != otonev->w)
|
165
|
+
return Qfalse;
|
166
|
+
return Qtrue;
|
167
|
+
}
|
168
|
+
|
169
|
+
VALUE rb_Tone_to_s(VALUE self)
|
170
|
+
{
|
171
|
+
GET_TONE
|
172
|
+
return rb_sprintf("(%d, %d, %d, %d)", static_cast<int>(tonev->x * 255),
|
173
|
+
static_cast<int>(tonev->y * 255),
|
174
|
+
static_cast<int>(tonev->z * 255),
|
175
|
+
static_cast<int>(tonev->w * 255));
|
176
|
+
}
|
177
|
+
|
178
|
+
CTone_Element* rb_Tone_get_tone(VALUE self)
|
179
|
+
{
|
180
|
+
rb_Tone_test_tone(self);
|
181
|
+
GET_TONE;
|
182
|
+
return tone;
|
183
|
+
}
|
184
|
+
|
185
|
+
void rb_Tone_test_tone(VALUE self)
|
186
|
+
{
|
187
|
+
if (rb_obj_is_kind_of(self, rb_cTone) != Qtrue)
|
188
|
+
{
|
189
|
+
rb_raise(rb_eTypeError, "Expected Tone got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(self))));
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
VALUE rb_Tone_Load(VALUE self, VALUE str)
|
194
|
+
{
|
195
|
+
rb_check_type(str, T_STRING);
|
196
|
+
VALUE arr[4];
|
197
|
+
if(RSTRING_LEN(str) < (sizeof(double) * 4))
|
198
|
+
{
|
199
|
+
arr[3] = arr[2] = arr[1] = arr[0] = LONG2FIX(0);
|
200
|
+
return rb_class_new_instance(4, arr, self);
|
201
|
+
}
|
202
|
+
double* tone_data = reinterpret_cast<double*>(RSTRING_PTR(str));
|
203
|
+
arr[0] = rb_int2inum(static_cast<long>(tone_data[0]));
|
204
|
+
arr[1] = rb_int2inum(static_cast<long>(tone_data[1]));
|
205
|
+
arr[2] = rb_int2inum(static_cast<long>(tone_data[2]));
|
206
|
+
arr[3] = rb_int2inum(static_cast<long>(tone_data[3]));
|
207
|
+
return rb_class_new_instance(4, arr, self);
|
208
|
+
}
|
209
|
+
|
210
|
+
VALUE rb_Tone_Save(VALUE self, VALUE limit)
|
211
|
+
{
|
212
|
+
GET_TONE
|
213
|
+
double tone_data[4];
|
214
|
+
tone_data[0] = static_cast<double>(tonev->x * 255);
|
215
|
+
tone_data[1] = static_cast<double>(tonev->y * 255);
|
216
|
+
tone_data[2] = static_cast<double>(tonev->z * 255);
|
217
|
+
tone_data[3] = static_cast<double>(tonev->w * 255);
|
218
|
+
return rb_str_new(reinterpret_cast<const char*>(tone_data), sizeof(double) * 4);
|
219
|
+
}
|
220
|
+
|
221
|
+
void __Tone_Check_LinkedObject(CTone_Element* tone)
|
222
|
+
{
|
223
|
+
CViewport_Element* view = tone->getElement();
|
224
|
+
if(view == nullptr)
|
225
|
+
return;
|
226
|
+
tone_copy(view->getTone(), tone->getTone());
|
227
|
+
view->updatetone();
|
228
|
+
}
|
data/ext/LiteRGSS/Tone.h
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef L_TONE_H
|
2
|
+
#define L_TONE_H
|
3
|
+
|
4
|
+
VALUE rb_Tone_Initialize(int argc, VALUE* argv, VALUE self); // Also .set
|
5
|
+
VALUE rb_Tone_InitializeCopy(VALUE self, VALUE original);
|
6
|
+
VALUE rb_Tone_getRed(VALUE self);
|
7
|
+
VALUE rb_Tone_setRed(VALUE self, VALUE val);
|
8
|
+
VALUE rb_Tone_getGreen(VALUE self);
|
9
|
+
VALUE rb_Tone_setGreen(VALUE self, VALUE val);
|
10
|
+
VALUE rb_Tone_getBlue(VALUE self);
|
11
|
+
VALUE rb_Tone_setBlue(VALUE self, VALUE val);
|
12
|
+
VALUE rb_Tone_getGray(VALUE self);
|
13
|
+
VALUE rb_Tone_setGray(VALUE self, VALUE val);
|
14
|
+
VALUE rb_Tone_eql(VALUE self, VALUE other);
|
15
|
+
VALUE rb_Tone_to_s(VALUE self);
|
16
|
+
VALUE rb_Tone_Load(VALUE self, VALUE str);
|
17
|
+
VALUE rb_Tone_Save(VALUE self, VALUE limit);
|
18
|
+
|
19
|
+
CTone_Element* rb_Tone_get_tone(VALUE self);
|
20
|
+
void rb_Tone_test_tone(VALUE self);
|
21
|
+
|
22
|
+
#endif
|
@@ -0,0 +1,491 @@
|
|
1
|
+
#include "LiteRGSS.h"
|
2
|
+
#include "CViewport_Element.h"
|
3
|
+
#include "CRect_Element.h"
|
4
|
+
#include "CTone_Element.h"
|
5
|
+
|
6
|
+
VALUE rb_cViewport = Qnil;
|
7
|
+
|
8
|
+
#define VIEWPORT_PROTECT if(RDATA(self)->data == nullptr) \
|
9
|
+
{\
|
10
|
+
rb_raise(rb_eRGSSError, "Disposed Viewport."); \
|
11
|
+
return self; \
|
12
|
+
}
|
13
|
+
|
14
|
+
#define GET_VIEWPORT CViewport_Element* viewport; \
|
15
|
+
Data_Get_Struct(self, CViewport_Element, viewport); \
|
16
|
+
VIEWPORT_PROTECT
|
17
|
+
|
18
|
+
void rb_Viewport_Free(void* data)
|
19
|
+
{
|
20
|
+
CViewport_Element* viewport = reinterpret_cast<CViewport_Element*>(data);
|
21
|
+
if(viewport != nullptr)
|
22
|
+
{
|
23
|
+
viewport->setOriginStack(nullptr);
|
24
|
+
CRect_Element* rect = viewport->getLinkedRect();
|
25
|
+
if(rect != nullptr)
|
26
|
+
rect->setElement(nullptr);
|
27
|
+
CTone_Element* tone = viewport->getLinkedTone();
|
28
|
+
if(tone != nullptr)
|
29
|
+
tone->setElement(nullptr);
|
30
|
+
delete viewport;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
void rb_Viewport_Mark(CViewport_Element* viewport)
|
35
|
+
{
|
36
|
+
if(viewport == nullptr)
|
37
|
+
return;
|
38
|
+
rb_gc_mark(viewport->rRect);
|
39
|
+
rb_gc_mark(viewport->rTone);
|
40
|
+
rb_gc_mark(viewport->rColor);
|
41
|
+
rb_gc_mark(viewport->rZ);
|
42
|
+
rb_gc_mark(viewport->rAngle);
|
43
|
+
rb_gc_mark(viewport->rZoom);
|
44
|
+
rb_gc_mark(viewport->rRenderState);
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE rb_Viewport_Alloc(VALUE klass)
|
48
|
+
{
|
49
|
+
CViewport_Element* viewport = new CViewport_Element();
|
50
|
+
viewport->setLinkedRect(nullptr);
|
51
|
+
viewport->setLinkedTone(nullptr);
|
52
|
+
viewport->setVisible(true);
|
53
|
+
viewport->rZ = LONG2FIX(0);
|
54
|
+
return Data_Wrap_Struct(klass, rb_Viewport_Mark, rb_Viewport_Free, viewport);
|
55
|
+
}
|
56
|
+
|
57
|
+
void Init_Viewport()
|
58
|
+
{
|
59
|
+
rb_cViewport = rb_define_class_under(rb_mLiteRGSS, "Viewport", rb_cObject);
|
60
|
+
|
61
|
+
rb_define_alloc_func(rb_cViewport, rb_Viewport_Alloc);
|
62
|
+
|
63
|
+
rb_define_method(rb_cViewport, "initialize", _rbf rb_Viewport_Initialize, -1);
|
64
|
+
rb_define_method(rb_cViewport, "ox", _rbf rb_Viewport_getOX, 0);
|
65
|
+
rb_define_method(rb_cViewport, "ox=", _rbf rb_Viewport_setOX, 1);
|
66
|
+
rb_define_method(rb_cViewport, "oy", _rbf rb_Viewport_getOY, 0);
|
67
|
+
rb_define_method(rb_cViewport, "oy=", _rbf rb_Viewport_setOY, 1);
|
68
|
+
rb_define_method(rb_cViewport, "rect", _rbf rb_Viewport_getRect, 0);
|
69
|
+
rb_define_method(rb_cViewport, "rect=", _rbf rb_Viewport_setRect, 1);
|
70
|
+
rb_define_method(rb_cViewport, "dispose", _rbf rb_Viewport_Dispose, 0);
|
71
|
+
rb_define_method(rb_cViewport, "disposed?", _rbf rb_Viewport_Disposed, 0);
|
72
|
+
rb_define_method(rb_cViewport, "tone", _rbf rb_Viewport_getTone, 0);
|
73
|
+
rb_define_method(rb_cViewport, "tone=", _rbf rb_Viewport_setTone, 1);
|
74
|
+
rb_define_method(rb_cViewport, "color", _rbf rb_Viewport_getColor, 0);
|
75
|
+
rb_define_method(rb_cViewport, "color=", _rbf rb_Viewport_setColor, 1);
|
76
|
+
rb_define_method(rb_cViewport, "update", _rbf rb_Viewport_Update, 0);
|
77
|
+
rb_define_method(rb_cViewport, "visible", _rbf rb_Viewport_getVisible, 0);
|
78
|
+
rb_define_method(rb_cViewport, "visible=", _rbf rb_Viewport_setVisible, 1);
|
79
|
+
rb_define_method(rb_cViewport, "z", _rbf rb_Viewport_getZ, 0);
|
80
|
+
rb_define_method(rb_cViewport, "z=", _rbf rb_Viewport_setZ, 1);
|
81
|
+
rb_define_method(rb_cViewport, "zoom", _rbf rb_Viewport_getZoom, 0);
|
82
|
+
rb_define_method(rb_cViewport, "zoom=", _rbf rb_Viewport_setZoom, 1);
|
83
|
+
rb_define_method(rb_cViewport, "angle", _rbf rb_Viewport_getAngle, 0);
|
84
|
+
rb_define_method(rb_cViewport, "angle=", _rbf rb_Viewport_setAngle, 1);
|
85
|
+
rb_define_method(rb_cViewport, "shader", _rbf rb_Viewport_getRenderState, 0);
|
86
|
+
rb_define_method(rb_cViewport, "shader=", _rbf rb_Viewport_setRenderState, 1);
|
87
|
+
rb_define_method(rb_cViewport, "blendmode", _rbf rb_Viewport_getRenderState, 0);
|
88
|
+
rb_define_method(rb_cViewport, "blendmode=", _rbf rb_Viewport_setRenderState, 1);
|
89
|
+
rb_define_method(rb_cViewport, "reload_stack", _rbf rb_Viewport_ReloadStack, 0);
|
90
|
+
rb_define_method(rb_cViewport, "__index__", _rbf rb_Viewport_Index, 0);
|
91
|
+
|
92
|
+
rb_define_method(rb_cViewport, "clone", _rbf rb_Viewport_Copy, 0);
|
93
|
+
rb_define_method(rb_cViewport, "dup", _rbf rb_Viewport_Copy, 0);
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE rb_Viewport_Copy(VALUE self)
|
97
|
+
{
|
98
|
+
rb_raise(rb_eRGSSError, "Viewports can not be cloned or duplicated.");
|
99
|
+
return self;
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE rb_Viewport_Initialize(int argc, VALUE* argv, VALUE self)
|
103
|
+
{
|
104
|
+
VALUE x, y, width, height;
|
105
|
+
rb_scan_args(argc, argv, "22", &x, &y, &width, &height);
|
106
|
+
/* Parameter normalization */
|
107
|
+
if(NIL_P(width))
|
108
|
+
{
|
109
|
+
width = x;
|
110
|
+
height = y;
|
111
|
+
x = LONG2FIX(0);
|
112
|
+
y = LONG2FIX(0);
|
113
|
+
}
|
114
|
+
else if(NIL_P(height))
|
115
|
+
{
|
116
|
+
height = width;
|
117
|
+
width = y;
|
118
|
+
y = LONG2FIX(0);
|
119
|
+
}
|
120
|
+
/* Sprite table creation */
|
121
|
+
rb_ivar_set(self, rb_iElementTable, rb_ary_new());
|
122
|
+
/* Viewport setting */
|
123
|
+
GET_VIEWPORT
|
124
|
+
VALUE table;
|
125
|
+
global_Graphics_Bind(viewport);
|
126
|
+
table = rb_ivar_get(rb_mGraphics, rb_iElementTable);
|
127
|
+
rb_ary_push(table, self);
|
128
|
+
viewport->setOx(0);
|
129
|
+
viewport->setOy(0);
|
130
|
+
viewport->rAngle = LONG2FIX(0);
|
131
|
+
viewport->rZoom = LONG2FIX(1);
|
132
|
+
Viewport_SetView(viewport, rb_num2long(x), rb_num2long(y), rb_num2long(width), rb_num2long(height));
|
133
|
+
/* Creating rect */
|
134
|
+
VALUE rc = rb_class_new_instance(argc, argv, rb_cRect);
|
135
|
+
/* Fetching data */
|
136
|
+
CRect_Element* rect;
|
137
|
+
Data_Get_Struct(rc, CRect_Element, rect);
|
138
|
+
rect->setElement(viewport);
|
139
|
+
viewport->setLinkedRect(rect);
|
140
|
+
viewport->rRect = rc;
|
141
|
+
viewport->rTone = Qnil;
|
142
|
+
viewport->rColor = Qnil;
|
143
|
+
viewport->clearStack();
|
144
|
+
return self;
|
145
|
+
}
|
146
|
+
|
147
|
+
void __Viewport_Dispose_AllSprite(VALUE table)
|
148
|
+
{
|
149
|
+
rb_check_type(table, T_ARRAY);
|
150
|
+
long sz = RARRAY_LEN(table);
|
151
|
+
VALUE* ori = RARRAY_PTR(table);
|
152
|
+
for(long i = 0; i < sz; i++)
|
153
|
+
{
|
154
|
+
if(rb_obj_is_kind_of(ori[i], rb_cSprite) == Qtrue)
|
155
|
+
rb_Sprite_DisposeFromViewport(ori[i]);
|
156
|
+
else
|
157
|
+
rb_Text_DisposeFromViewport(ori[i]);
|
158
|
+
}
|
159
|
+
rb_ary_clear(table);
|
160
|
+
}
|
161
|
+
|
162
|
+
VALUE rb_Viewport_Dispose(VALUE self)
|
163
|
+
{
|
164
|
+
GET_VIEWPORT
|
165
|
+
RDATA(self)->data = nullptr;
|
166
|
+
VALUE table = rb_ivar_get(rb_mGraphics, rb_iElementTable);
|
167
|
+
rb_ary_delete(table, self);
|
168
|
+
viewport->clearStack();
|
169
|
+
__Viewport_Dispose_AllSprite(rb_ivar_get(self, rb_iElementTable));
|
170
|
+
rb_Viewport_Free(reinterpret_cast<void*>(viewport));
|
171
|
+
return self;
|
172
|
+
}
|
173
|
+
|
174
|
+
VALUE rb_Viewport_Disposed(VALUE self)
|
175
|
+
{
|
176
|
+
rb_check_type(self, T_DATA);
|
177
|
+
return (RDATA(self)->data == nullptr ? Qtrue : Qfalse);
|
178
|
+
}
|
179
|
+
|
180
|
+
void Viewport_AdjustOXY(CViewport_Element* viewport, VALUE rect)
|
181
|
+
{
|
182
|
+
if(RDATA(rect)->data == nullptr)
|
183
|
+
return;
|
184
|
+
CRect_Element* srect;
|
185
|
+
Data_Get_Struct(rect, CRect_Element, srect);
|
186
|
+
sf::IntRect* rc = srect->getRect();
|
187
|
+
sf::View* view = viewport->getView();
|
188
|
+
view->setCenter(std::roundf(static_cast<float>(viewport->getOx()) + static_cast<float>(rc->width) / 2.0f),
|
189
|
+
std::roundf(static_cast<float>(viewport->getOy()) + static_cast<float>(rc->height) / 2.0f));
|
190
|
+
}
|
191
|
+
|
192
|
+
VALUE rb_Viewport_getOX(VALUE self)
|
193
|
+
{
|
194
|
+
GET_VIEWPORT
|
195
|
+
return rb_int2inum(viewport->getOx());
|
196
|
+
}
|
197
|
+
|
198
|
+
VALUE rb_Viewport_setOX(VALUE self, VALUE val)
|
199
|
+
{
|
200
|
+
GET_VIEWPORT
|
201
|
+
viewport->setOx(rb_num2long(val));
|
202
|
+
Viewport_AdjustOXY(viewport, viewport->rRect);
|
203
|
+
return val;
|
204
|
+
}
|
205
|
+
|
206
|
+
VALUE rb_Viewport_getOY(VALUE self)
|
207
|
+
{
|
208
|
+
GET_VIEWPORT
|
209
|
+
return rb_int2inum(viewport->getOy());
|
210
|
+
}
|
211
|
+
|
212
|
+
VALUE rb_Viewport_setOY(VALUE self, VALUE val)
|
213
|
+
{
|
214
|
+
GET_VIEWPORT
|
215
|
+
viewport->setOy(rb_num2long(val));
|
216
|
+
Viewport_AdjustOXY(viewport, viewport->rRect);
|
217
|
+
return val;
|
218
|
+
}
|
219
|
+
|
220
|
+
VALUE rb_Viewport_getRect(VALUE self)
|
221
|
+
{
|
222
|
+
GET_VIEWPORT
|
223
|
+
return viewport->rRect;
|
224
|
+
}
|
225
|
+
|
226
|
+
VALUE rb_Viewport_setRect(VALUE self, VALUE val)
|
227
|
+
{
|
228
|
+
VALUE rc = rb_Viewport_getRect(self);
|
229
|
+
if(RDATA(rc)->data == nullptr) { return Qnil; }
|
230
|
+
if(rb_obj_is_kind_of(val, rb_cRect) != Qtrue)
|
231
|
+
{
|
232
|
+
rb_raise(rb_eTypeError, "Expected Rect got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(val))));
|
233
|
+
return Qnil;
|
234
|
+
}
|
235
|
+
if(RDATA(val)->data == nullptr) { return Qnil; }
|
236
|
+
CViewport_Element* viewport;
|
237
|
+
Data_Get_Struct(self, CViewport_Element, viewport);
|
238
|
+
/* Getting data to update the rect */
|
239
|
+
CRect_Element* rect1;
|
240
|
+
Data_Get_Struct(val, CRect_Element, rect1);
|
241
|
+
CRect_Element* rect2;
|
242
|
+
Data_Get_Struct(rc, CRect_Element, rect2);
|
243
|
+
/* Copying the rect */
|
244
|
+
sf::IntRect* rect_target = rect2->getRect();
|
245
|
+
rect_copy(rect_target, rect1->getRect());
|
246
|
+
/* Updating the viewport view */
|
247
|
+
Viewport_SetView(viewport, rect_target->left, rect_target->top, rect_target->width, rect_target->height);
|
248
|
+
return val;
|
249
|
+
|
250
|
+
}
|
251
|
+
|
252
|
+
VALUE rb_Viewport_getTone(VALUE self)
|
253
|
+
{
|
254
|
+
GET_VIEWPORT
|
255
|
+
VALUE tn = viewport->rTone;
|
256
|
+
if(!NIL_P(tn))
|
257
|
+
return tn;
|
258
|
+
/* New tone */
|
259
|
+
VALUE argv[4] = {LONG2FIX(0), LONG2FIX(0), LONG2FIX(0), LONG2FIX(0)};
|
260
|
+
viewport->rColor = rb_class_new_instance(4, argv, rb_cColor);
|
261
|
+
tn = rb_class_new_instance(4, argv, rb_cTone);
|
262
|
+
CTone_Element* tone;
|
263
|
+
Data_Get_Struct(tn, CTone_Element, tone);
|
264
|
+
tone->setElement(viewport);
|
265
|
+
viewport->setLinkedTone(tone);
|
266
|
+
viewport->rTone = tn;
|
267
|
+
viewport->create_render();
|
268
|
+
return tn;
|
269
|
+
}
|
270
|
+
|
271
|
+
VALUE rb_Viewport_setTone(VALUE self, VALUE val)
|
272
|
+
{
|
273
|
+
VALUE tn = rb_Viewport_getTone(self);
|
274
|
+
if(RDATA(tn)->data == nullptr) { return Qnil; }
|
275
|
+
if(rb_obj_is_kind_of(val, rb_cTone) != Qtrue)
|
276
|
+
{
|
277
|
+
rb_raise(rb_eTypeError, "Expected Tone, got %s", RSTRING_PTR(rb_class_name(CLASS_OF(val))));
|
278
|
+
return Qnil;
|
279
|
+
}
|
280
|
+
if(RDATA(val)->data == nullptr) { return Qnil; }
|
281
|
+
GET_VIEWPORT
|
282
|
+
CTone_Element* tonesrc;
|
283
|
+
Data_Get_Struct(val, CTone_Element, tonesrc);
|
284
|
+
CTone_Element* tonedest;
|
285
|
+
Data_Get_Struct(tn, CTone_Element, tonedest);
|
286
|
+
sf::Glsl::Vec4* stone = tonesrc->getTone();
|
287
|
+
sf::Glsl::Vec4* vtone = viewport->getTone();
|
288
|
+
if (vtone->x != stone->x || vtone->y != stone->y || vtone->z != stone->z || vtone->w != vtone->w)
|
289
|
+
{
|
290
|
+
tone_copy(tonedest->getTone(), stone);
|
291
|
+
tone_copy(vtone, stone);
|
292
|
+
viewport->updatetone();
|
293
|
+
}
|
294
|
+
return val;
|
295
|
+
}
|
296
|
+
|
297
|
+
VALUE rb_Viewport_getColor(VALUE self)
|
298
|
+
{
|
299
|
+
VALUE tn = rb_Viewport_getTone(self);
|
300
|
+
GET_VIEWPORT
|
301
|
+
return viewport->rColor;
|
302
|
+
}
|
303
|
+
|
304
|
+
VALUE rb_Viewport_setColor(VALUE self, VALUE val)
|
305
|
+
{
|
306
|
+
VALUE tn = rb_Viewport_getTone(self);
|
307
|
+
GET_VIEWPORT
|
308
|
+
if(rb_obj_is_kind_of(val, rb_cColor) != Qtrue)
|
309
|
+
{
|
310
|
+
rb_raise(rb_eTypeError, "Expected Color, got %s", RSTRING_PTR(rb_class_name(CLASS_OF(val))));
|
311
|
+
return Qnil;
|
312
|
+
}
|
313
|
+
viewport->rColor = val;
|
314
|
+
return self;
|
315
|
+
}
|
316
|
+
|
317
|
+
VALUE rb_Viewport_getVisible(VALUE self)
|
318
|
+
{
|
319
|
+
GET_VIEWPORT
|
320
|
+
return (viewport->getVisible() ? Qtrue : Qfalse);
|
321
|
+
}
|
322
|
+
|
323
|
+
VALUE rb_Viewport_setVisible(VALUE self, VALUE val)
|
324
|
+
{
|
325
|
+
GET_VIEWPORT
|
326
|
+
viewport->setVisible(RTEST(val));
|
327
|
+
return self;
|
328
|
+
}
|
329
|
+
|
330
|
+
VALUE rb_Viewport_Update(VALUE self)
|
331
|
+
{
|
332
|
+
GET_VIEWPORT
|
333
|
+
return self;
|
334
|
+
}
|
335
|
+
|
336
|
+
VALUE rb_Viewport_getZ(VALUE self)
|
337
|
+
{
|
338
|
+
GET_VIEWPORT
|
339
|
+
return viewport->rZ;
|
340
|
+
}
|
341
|
+
|
342
|
+
VALUE rb_Viewport_setZ(VALUE self, VALUE val)
|
343
|
+
{
|
344
|
+
GET_VIEWPORT
|
345
|
+
rb_num2long(val);
|
346
|
+
viewport->rZ = val;
|
347
|
+
return self;
|
348
|
+
}
|
349
|
+
|
350
|
+
void Viewport_AdjustZoomAngle(CViewport_Element* viewport, VALUE rect)
|
351
|
+
{
|
352
|
+
if (RDATA(rect)->data == nullptr)
|
353
|
+
return;
|
354
|
+
long x, y, width, height;
|
355
|
+
CRect_Element* srect;
|
356
|
+
Data_Get_Struct(rect, CRect_Element, srect);
|
357
|
+
sf::IntRect* rc = srect->getRect();
|
358
|
+
sf::View* view = viewport->getView();
|
359
|
+
x = rc->left;
|
360
|
+
y = rc->top;
|
361
|
+
width = rc->width;
|
362
|
+
height = rc->height;
|
363
|
+
if (width & 1)
|
364
|
+
width++;
|
365
|
+
if (height & 1)
|
366
|
+
height++;
|
367
|
+
view->setCenter(static_cast<float>(viewport->getOx() + width / 2),
|
368
|
+
static_cast<float>(viewport->getOy() + height / 2));
|
369
|
+
view->setSize(static_cast<float>(width), static_cast<float>(height));
|
370
|
+
view->setRotation(-NUM2DBL(viewport->rAngle));
|
371
|
+
view->zoom(NUM2DBL(viewport->rZoom));
|
372
|
+
float sw = static_cast<float>(ScreenWidth);
|
373
|
+
float sh = static_cast<float>(ScreenHeight);
|
374
|
+
sf::FloatRect frect(x / sw, y / sh, width / sw, height / sh);
|
375
|
+
view->setViewport(frect);
|
376
|
+
}
|
377
|
+
|
378
|
+
VALUE rb_Viewport_getAngle(VALUE self)
|
379
|
+
{
|
380
|
+
GET_VIEWPORT;
|
381
|
+
return viewport->rAngle;
|
382
|
+
}
|
383
|
+
|
384
|
+
VALUE rb_Viewport_setAngle(VALUE self, VALUE val)
|
385
|
+
{
|
386
|
+
GET_VIEWPORT;
|
387
|
+
viewport->rAngle = LONG2NUM(NUM2LONG(val) % 360);
|
388
|
+
Viewport_AdjustZoomAngle(viewport, viewport->rRect);
|
389
|
+
return self;
|
390
|
+
}
|
391
|
+
|
392
|
+
VALUE rb_Viewport_getZoom(VALUE self)
|
393
|
+
{
|
394
|
+
GET_VIEWPORT;
|
395
|
+
return viewport->rZoom;
|
396
|
+
}
|
397
|
+
|
398
|
+
VALUE rb_Viewport_setZoom(VALUE self, VALUE val)
|
399
|
+
{
|
400
|
+
GET_VIEWPORT;
|
401
|
+
viewport->rZoom = DBL2NUM(1.0 / normalize_double(NUM2DBL(val), 0.001, 1000.0));
|
402
|
+
Viewport_AdjustZoomAngle(viewport, viewport->rRect);
|
403
|
+
return self;
|
404
|
+
}
|
405
|
+
|
406
|
+
VALUE rb_Viewport_getRenderState(VALUE self)
|
407
|
+
{
|
408
|
+
GET_VIEWPORT;
|
409
|
+
return viewport->rRenderState;
|
410
|
+
}
|
411
|
+
|
412
|
+
VALUE rb_Viewport_setRenderState(VALUE self, VALUE val)
|
413
|
+
{
|
414
|
+
sf::RenderStates* render_state;
|
415
|
+
GET_VIEWPORT;
|
416
|
+
if (rb_obj_is_kind_of(val, rb_cBlendMode) == Qtrue)
|
417
|
+
{
|
418
|
+
Data_Get_Struct(val, sf::RenderStates, render_state);
|
419
|
+
if (render_state)
|
420
|
+
{
|
421
|
+
viewport->setRenderStates(render_state);
|
422
|
+
viewport->rRenderState = val;
|
423
|
+
viewport->create_render(); // Make sure the global render is initialized
|
424
|
+
viewport->updatetone();
|
425
|
+
return self;
|
426
|
+
}
|
427
|
+
}
|
428
|
+
viewport->setRenderStates(nullptr);
|
429
|
+
if (viewport->rColor != Qnil && viewport->rTone != Qnil)
|
430
|
+
{
|
431
|
+
viewport->rRenderState = Qnil;
|
432
|
+
viewport->create_render(); // Restore the old render
|
433
|
+
viewport->updatetone();
|
434
|
+
}
|
435
|
+
else
|
436
|
+
viewport->rRenderState = Qfalse; // False to prevent intempestive delete
|
437
|
+
return self;
|
438
|
+
}
|
439
|
+
|
440
|
+
VALUE rb_Viewport_ReloadStack(VALUE self)
|
441
|
+
{
|
442
|
+
GET_VIEWPORT
|
443
|
+
VALUE table = rb_ivar_get(self, rb_iElementTable);
|
444
|
+
rb_check_type(table, T_ARRAY);
|
445
|
+
for(auto it = viewport->getStack()->begin(); it != viewport->getStack()->end(); it++)
|
446
|
+
{
|
447
|
+
(*it)->overrideOrigineStack(nullptr);
|
448
|
+
}
|
449
|
+
viewport->clearStack();
|
450
|
+
long sz = RARRAY_LEN(table);
|
451
|
+
VALUE* ori = RARRAY_PTR(table);
|
452
|
+
for(long i = 0; i < sz; i++)
|
453
|
+
{
|
454
|
+
if(rb_obj_is_kind_of(ori[i], rb_cViewport) == Qtrue ||
|
455
|
+
rb_obj_is_kind_of(ori[i], rb_cSprite) == Qtrue ||
|
456
|
+
rb_obj_is_kind_of(ori[i], rb_cText) == Qtrue)
|
457
|
+
{
|
458
|
+
if(RDATA(ori[i])->data != nullptr)
|
459
|
+
{
|
460
|
+
viewport->bind(reinterpret_cast<CDrawable_Element*>(RDATA(ori[i])->data));
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}
|
464
|
+
return self;
|
465
|
+
}
|
466
|
+
|
467
|
+
VALUE rb_Viewport_Index(VALUE self)
|
468
|
+
{
|
469
|
+
GET_VIEWPORT
|
470
|
+
return rb_uint2inum(viewport->getIndex());
|
471
|
+
}
|
472
|
+
|
473
|
+
void Viewport_SetView(CViewport_Element* viewport, long x, long y, long width, long height)
|
474
|
+
{
|
475
|
+
sf::View* view = viewport->getView();
|
476
|
+
/* Adjustment for text */
|
477
|
+
if(width & 1)
|
478
|
+
width++;
|
479
|
+
if(height & 1)
|
480
|
+
height++;
|
481
|
+
view->setCenter(static_cast<float>(viewport->getOx() + width / 2),
|
482
|
+
static_cast<float>(viewport->getOy() + height / 2));
|
483
|
+
view->setSize(static_cast<float>(width), static_cast<float>(height));
|
484
|
+
view->setRotation(-NUM2DBL(viewport->rAngle));
|
485
|
+
view->zoom(NUM2DBL(viewport->rZoom));
|
486
|
+
float sw = static_cast<float>(ScreenWidth);
|
487
|
+
float sh = static_cast<float>(ScreenHeight);
|
488
|
+
sf::FloatRect frect(x / sw, y / sh, width / sw, height / sh);
|
489
|
+
view->setViewport(frect);
|
490
|
+
// viewport->reset_render();
|
491
|
+
}
|