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,57 @@
|
|
1
|
+
#ifndef CViewport_Element_H
|
2
|
+
#define CViewport_Element_H
|
3
|
+
#include "CDrawable_Element.h"
|
4
|
+
#include "CSprite_Element.h"
|
5
|
+
|
6
|
+
class CViewport_Element : public CDrawable_Element {
|
7
|
+
protected:
|
8
|
+
long ox, oy;
|
9
|
+
sf::View view;
|
10
|
+
std::vector<CDrawable_Element*> stack;
|
11
|
+
sf::Glsl::Vec4 tone;
|
12
|
+
CTone_Element* linkedTone;
|
13
|
+
/*sf::RenderTexture* render;
|
14
|
+
sf::Shader* shader;*/
|
15
|
+
sf::Color* color_copy;
|
16
|
+
bool visible;
|
17
|
+
sf::RenderStates* render_states;
|
18
|
+
public:
|
19
|
+
CViewport_Element();
|
20
|
+
~CViewport_Element();
|
21
|
+
void draw(sf::RenderTarget& target) const override;
|
22
|
+
void drawFast(sf::RenderTarget& target) const override;
|
23
|
+
bool isViewport() const override;
|
24
|
+
bool isPureSprite() const override;
|
25
|
+
sf::View* getView() {return &view;};
|
26
|
+
sf::RenderStates* getRenderStates();
|
27
|
+
void setRenderStates(sf::RenderStates* states);
|
28
|
+
long getOx() {return ox;};
|
29
|
+
long getOy() {return oy;};
|
30
|
+
void setOx(long nox) {ox = nox;};
|
31
|
+
void setOy(long noy) {oy = noy;};
|
32
|
+
void bind(CDrawable_Element* sprite);
|
33
|
+
void clearStack();
|
34
|
+
sf::Glsl::Vec4* getTone();
|
35
|
+
void updatetone();
|
36
|
+
void setLinkedTone(CTone_Element* _tone);
|
37
|
+
CTone_Element* getLinkedTone();
|
38
|
+
// void reset_render();
|
39
|
+
void create_render();
|
40
|
+
void setVisible(bool value);
|
41
|
+
bool getVisible() { return visible; };
|
42
|
+
const std::vector<CDrawable_Element*>* getStack();
|
43
|
+
/* Ruby Ivar */
|
44
|
+
VALUE rRect;
|
45
|
+
VALUE rTone;
|
46
|
+
VALUE rColor;
|
47
|
+
VALUE rZ;
|
48
|
+
VALUE rAngle;
|
49
|
+
VALUE rZoom;
|
50
|
+
VALUE rRenderState;
|
51
|
+
/* Shader related stuff */
|
52
|
+
static sf::RenderTexture* render;
|
53
|
+
static sf::Sprite* render_sprite;
|
54
|
+
private:
|
55
|
+
sf::Color* check_up_color() const;
|
56
|
+
};
|
57
|
+
#endif
|
@@ -0,0 +1,200 @@
|
|
1
|
+
#include "LiteRGSS.h"
|
2
|
+
|
3
|
+
VALUE rb_cColor = Qnil;
|
4
|
+
|
5
|
+
#define COLOR_PROTECT if(RDATA(self)->data == nullptr) \
|
6
|
+
{\
|
7
|
+
rb_raise(rb_eRGSSError, "Freed Color."); \
|
8
|
+
}
|
9
|
+
|
10
|
+
#define GET_COLOR sf::Color* color; \
|
11
|
+
Data_Get_Struct(self, sf::Color, color); \
|
12
|
+
COLOR_PROTECT
|
13
|
+
|
14
|
+
void rb_Color_Free(void* data)
|
15
|
+
{
|
16
|
+
sf::Color* color = reinterpret_cast<sf::Color*>(data);
|
17
|
+
if(color)
|
18
|
+
{
|
19
|
+
delete color;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
VALUE rb_Color_Alloc(VALUE klass)
|
24
|
+
{
|
25
|
+
sf::Color* color = new sf::Color();
|
26
|
+
color->a = 255;
|
27
|
+
return Data_Wrap_Struct(klass, NULL, rb_Color_Free, color);
|
28
|
+
}
|
29
|
+
|
30
|
+
void Init_Color()
|
31
|
+
{
|
32
|
+
rb_cColor = rb_define_class_under(rb_mLiteRGSS, "Color", rb_cObject);
|
33
|
+
rb_define_alloc_func(rb_cColor, rb_Color_Alloc);
|
34
|
+
|
35
|
+
rb_define_method(rb_cColor, "initialize", _rbf rb_Color_Initialize, -1);
|
36
|
+
rb_define_method(rb_cColor, "set", _rbf rb_Color_Initialize, -1);
|
37
|
+
rb_define_method(rb_cColor, "initialize_copy", _rbf rb_Color_InitializeCopy, 1);
|
38
|
+
rb_define_method(rb_cColor, "red", _rbf rb_Color_getRed, 0);
|
39
|
+
rb_define_method(rb_cColor, "red=", _rbf rb_Color_setRed, 1);
|
40
|
+
rb_define_method(rb_cColor, "green", _rbf rb_Color_getGreen, 0);
|
41
|
+
rb_define_method(rb_cColor, "green=", _rbf rb_Color_setGreen, 1);
|
42
|
+
rb_define_method(rb_cColor, "blue", _rbf rb_Color_getBlue, 0);
|
43
|
+
rb_define_method(rb_cColor, "blue=", _rbf rb_Color_setBlue, 1);
|
44
|
+
rb_define_method(rb_cColor, "alpha", _rbf rb_Color_getAlpha, 0);
|
45
|
+
rb_define_method(rb_cColor, "alpha=", _rbf rb_Color_setAlpha, 1);
|
46
|
+
rb_define_method(rb_cColor, "==", _rbf rb_Color_eql, 1);
|
47
|
+
rb_define_method(rb_cColor, "===", _rbf rb_Color_eql, 1);
|
48
|
+
rb_define_method(rb_cColor, "eql?", _rbf rb_Color_eql, 1);
|
49
|
+
rb_define_method(rb_cColor, "to_s", _rbf rb_Color_to_s, 0);
|
50
|
+
rb_define_method(rb_cColor, "inspect", _rbf rb_Color_to_s, 0);
|
51
|
+
rb_define_method(rb_cColor, "_dump", _rbf rb_Color_Save, 1);
|
52
|
+
rb_define_singleton_method(rb_cColor, "_load", _rbf rb_Color_Load, 1);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE rb_Color_Initialize(int argc, VALUE* argv, VALUE self)
|
56
|
+
{
|
57
|
+
VALUE red, green, blue, alpha;
|
58
|
+
rb_scan_args(argc, argv, "13", &red, &green, &blue, &alpha);
|
59
|
+
GET_COLOR
|
60
|
+
if(RTEST(red))
|
61
|
+
color->r = normalize_long(rb_num2long(red), 0, 255);
|
62
|
+
if(RTEST(green))
|
63
|
+
color->g = normalize_long(rb_num2long(green), 0, 255);
|
64
|
+
if(RTEST(blue))
|
65
|
+
color->b = normalize_long(rb_num2long(blue), 0, 255);
|
66
|
+
if(RTEST(alpha))
|
67
|
+
color->a = normalize_long(rb_num2long(alpha), 0, 255);
|
68
|
+
return self;
|
69
|
+
}
|
70
|
+
|
71
|
+
VALUE rb_Color_InitializeCopy(VALUE self, VALUE original)
|
72
|
+
{
|
73
|
+
GET_COLOR
|
74
|
+
sf::Color* coloro;
|
75
|
+
Data_Get_Struct(original, sf::Color, coloro);
|
76
|
+
if(RDATA(original)->data == nullptr)
|
77
|
+
rb_raise(rb_eRGSSError, "Freed Color.");
|
78
|
+
color->r = coloro->r;
|
79
|
+
color->g = coloro->g;
|
80
|
+
color->b = coloro->b;
|
81
|
+
color->a = coloro->a;
|
82
|
+
return self;
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE rb_Color_getRed(VALUE self)
|
86
|
+
{
|
87
|
+
GET_COLOR
|
88
|
+
return rb_int2inum(color->r);
|
89
|
+
}
|
90
|
+
|
91
|
+
VALUE rb_Color_setRed(VALUE self, VALUE red)
|
92
|
+
{
|
93
|
+
GET_COLOR
|
94
|
+
color->r = normalize_long(rb_num2long(red), 0, 255);
|
95
|
+
return self;
|
96
|
+
}
|
97
|
+
|
98
|
+
VALUE rb_Color_getGreen(VALUE self)
|
99
|
+
{
|
100
|
+
GET_COLOR
|
101
|
+
return rb_int2inum(color->g);
|
102
|
+
}
|
103
|
+
|
104
|
+
VALUE rb_Color_setGreen(VALUE self, VALUE red)
|
105
|
+
{
|
106
|
+
GET_COLOR
|
107
|
+
color->g = normalize_long(rb_num2long(red), 0, 255);
|
108
|
+
return self;
|
109
|
+
}
|
110
|
+
|
111
|
+
VALUE rb_Color_getBlue(VALUE self)
|
112
|
+
{
|
113
|
+
GET_COLOR
|
114
|
+
return rb_int2inum(color->b);
|
115
|
+
}
|
116
|
+
|
117
|
+
VALUE rb_Color_setBlue(VALUE self, VALUE red)
|
118
|
+
{
|
119
|
+
GET_COLOR
|
120
|
+
color->b = normalize_long(rb_num2long(red), 0, 255);
|
121
|
+
return self;
|
122
|
+
}
|
123
|
+
|
124
|
+
VALUE rb_Color_getAlpha(VALUE self)
|
125
|
+
{
|
126
|
+
GET_COLOR
|
127
|
+
return rb_int2inum(color->a);
|
128
|
+
}
|
129
|
+
|
130
|
+
VALUE rb_Color_setAlpha(VALUE self, VALUE red)
|
131
|
+
{
|
132
|
+
GET_COLOR
|
133
|
+
color->a = normalize_long(rb_num2long(red), 0, 255);
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
VALUE rb_Color_eql(VALUE self, VALUE other)
|
139
|
+
{
|
140
|
+
if(rb_obj_is_kind_of(other, rb_cColor) != Qtrue)
|
141
|
+
return Qfalse;
|
142
|
+
GET_COLOR
|
143
|
+
sf::Color* color2;
|
144
|
+
Data_Get_Struct(other, sf::Color, color2);
|
145
|
+
if(color2 == nullptr)
|
146
|
+
return Qfalse;
|
147
|
+
if(*color != *color2)
|
148
|
+
return Qfalse;
|
149
|
+
return Qtrue;
|
150
|
+
}
|
151
|
+
|
152
|
+
VALUE rb_Color_Load(VALUE self, VALUE str)
|
153
|
+
{
|
154
|
+
rb_check_type(str, T_STRING);
|
155
|
+
VALUE arr[4];
|
156
|
+
if(RSTRING_LEN(str) < (sizeof(double) * 4))
|
157
|
+
{
|
158
|
+
arr[2] = arr[1] = arr[0] = LONG2FIX(1);
|
159
|
+
return rb_class_new_instance(3, arr, self);
|
160
|
+
}
|
161
|
+
double* color_data = reinterpret_cast<double*>(RSTRING_PTR(str));
|
162
|
+
arr[0] = rb_int2inum(static_cast<long>(color_data[0]));
|
163
|
+
arr[1] = rb_int2inum(static_cast<long>(color_data[1]));
|
164
|
+
arr[2] = rb_int2inum(static_cast<long>(color_data[2]));
|
165
|
+
arr[3] = rb_int2inum(static_cast<long>(color_data[3]));
|
166
|
+
return rb_class_new_instance(4, arr, self);
|
167
|
+
}
|
168
|
+
|
169
|
+
VALUE rb_Color_Save(VALUE self, VALUE limit)
|
170
|
+
{
|
171
|
+
GET_COLOR
|
172
|
+
double color_data[4];
|
173
|
+
color_data[0] = static_cast<double>(color->r);
|
174
|
+
color_data[1] = static_cast<double>(color->g);
|
175
|
+
color_data[2] = static_cast<double>(color->b);
|
176
|
+
color_data[3] = static_cast<double>(color->a);
|
177
|
+
return rb_str_new(reinterpret_cast<const char*>(color_data), sizeof(double) * 4);
|
178
|
+
}
|
179
|
+
|
180
|
+
VALUE rb_Color_to_s(VALUE self)
|
181
|
+
{
|
182
|
+
GET_COLOR
|
183
|
+
return rb_sprintf("(%d, %d, %d, %d)", color->r, color->g, color->b, color->a);
|
184
|
+
}
|
185
|
+
|
186
|
+
sf::Color* rb_Color_get_color(VALUE self)
|
187
|
+
{
|
188
|
+
rb_Color_test_color(self);
|
189
|
+
GET_COLOR;
|
190
|
+
return color;
|
191
|
+
}
|
192
|
+
|
193
|
+
void rb_Color_test_color(VALUE self)
|
194
|
+
{
|
195
|
+
|
196
|
+
if (rb_obj_is_kind_of(self, rb_cColor) != Qtrue)
|
197
|
+
{
|
198
|
+
rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(self))));
|
199
|
+
}
|
200
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef L_COLOR_H
|
2
|
+
#define L_COLOR_H
|
3
|
+
|
4
|
+
VALUE rb_Color_Initialize(int argc, VALUE* argv, VALUE self); // Also .set
|
5
|
+
VALUE rb_Color_InitializeCopy(VALUE self, VALUE original);
|
6
|
+
VALUE rb_Color_getRed(VALUE self);
|
7
|
+
VALUE rb_Color_setRed(VALUE self, VALUE red);
|
8
|
+
VALUE rb_Color_getGreen(VALUE self);
|
9
|
+
VALUE rb_Color_setGreen(VALUE self, VALUE red);
|
10
|
+
VALUE rb_Color_getBlue(VALUE self);
|
11
|
+
VALUE rb_Color_setBlue(VALUE self, VALUE red);
|
12
|
+
VALUE rb_Color_getAlpha(VALUE self);
|
13
|
+
VALUE rb_Color_setAlpha(VALUE self, VALUE red);
|
14
|
+
VALUE rb_Color_eql(VALUE self, VALUE other);
|
15
|
+
VALUE rb_Color_Load(VALUE self, VALUE str);
|
16
|
+
VALUE rb_Color_Save(VALUE self, VALUE limit);
|
17
|
+
VALUE rb_Color_to_s(VALUE self);
|
18
|
+
|
19
|
+
sf::Color* rb_Color_get_color(VALUE self);
|
20
|
+
void rb_Color_test_color(VALUE self);
|
21
|
+
|
22
|
+
#endif
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#include "LiteRGSS.h"
|
2
|
+
|
3
|
+
VALUE rb_mFonts = Qnil;
|
4
|
+
|
5
|
+
ID rb_Fonts_ivSize = Qnil;
|
6
|
+
ID rb_Fonts_ivFColor = Qnil;
|
7
|
+
ID rb_Fonts_ivOColor = Qnil;
|
8
|
+
ID rb_Fonts_ivSColor = Qnil;
|
9
|
+
|
10
|
+
std::vector<unsigned int> rb_Fonts_Size_Tbl;
|
11
|
+
std::vector<sf::Font> rb_Fonts_font_tbl;
|
12
|
+
|
13
|
+
void Init_Fonts()
|
14
|
+
{
|
15
|
+
rb_mFonts = rb_define_module_under(rb_mLiteRGSS, "Fonts");
|
16
|
+
|
17
|
+
rb_define_module_function(rb_mFonts, "load_font", _rbf rb_Fonts_load_font, 2);
|
18
|
+
rb_define_module_function(rb_mFonts, "set_default_size", _rbf rb_Fonts_set_default_size, 2);
|
19
|
+
rb_define_module_function(rb_mFonts, "define_fill_color", _rbf rb_Fonts_define_fill_color, 2);
|
20
|
+
rb_define_module_function(rb_mFonts, "define_outline_color", _rbf rb_Fonts_define_outline_color, 2);
|
21
|
+
rb_define_module_function(rb_mFonts, "define_shadow_color", _rbf rb_Fonts_define_shadow_color, 2);
|
22
|
+
rb_define_module_function(rb_mFonts, "get_default_size", _rbf rb_Fonts_get_default_size, 1);
|
23
|
+
rb_define_module_function(rb_mFonts, "get_fill_color", _rbf rb_Fonts_get_fill_color, 1);
|
24
|
+
rb_define_module_function(rb_mFonts, "get_outline_color", _rbf rb_Fonts_get_outline_color, 1);
|
25
|
+
rb_define_module_function(rb_mFonts, "get_shadow_color", _rbf rb_Fonts_get_shadow_color, 1);
|
26
|
+
|
27
|
+
rb_Fonts_ivSize = rb_intern("@default_size");
|
28
|
+
rb_Fonts_ivFColor = rb_intern("@fill_color");
|
29
|
+
rb_Fonts_ivOColor = rb_intern("@outline_color");
|
30
|
+
rb_Fonts_ivSColor = rb_intern("@shadow_color");
|
31
|
+
|
32
|
+
rb_ivar_set(rb_mFonts, rb_Fonts_ivSize, rb_ary_new());
|
33
|
+
rb_ivar_set(rb_mFonts, rb_Fonts_ivFColor, rb_ary_new());
|
34
|
+
rb_ivar_set(rb_mFonts, rb_Fonts_ivOColor, rb_ary_new());
|
35
|
+
rb_ivar_set(rb_mFonts, rb_Fonts_ivSColor, rb_ary_new());
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
VALUE rb_Fonts_load_font(VALUE self, VALUE id, VALUE str)
|
40
|
+
{
|
41
|
+
unsigned long position = normalize_long(rb_num2long(id), 0, 255);
|
42
|
+
rb_check_type(str, T_STRING);
|
43
|
+
while(rb_Fonts_font_tbl.size() <= position)
|
44
|
+
{
|
45
|
+
rb_Fonts_font_tbl.push_back(sf::Font());
|
46
|
+
}
|
47
|
+
rb_Fonts_font_tbl[position].loadFromFile(RSTRING_PTR(str));
|
48
|
+
return self;
|
49
|
+
}
|
50
|
+
|
51
|
+
sf::Font& rb_Fonts_get_font(unsigned long id)
|
52
|
+
{
|
53
|
+
if(rb_Fonts_font_tbl.size() <= id)
|
54
|
+
{
|
55
|
+
rb_raise(rb_eRGSSError, "Unable to fetch font n°%d.", static_cast<int>(id));
|
56
|
+
}
|
57
|
+
return rb_Fonts_font_tbl[id];
|
58
|
+
}
|
59
|
+
|
60
|
+
VALUE rb_Fonts_set_default_size(VALUE self, VALUE id, VALUE size)
|
61
|
+
{
|
62
|
+
unsigned long position = rb_num2long(id);
|
63
|
+
while(rb_Fonts_Size_Tbl.size() <= position)
|
64
|
+
rb_Fonts_Size_Tbl.push_back(16);
|
65
|
+
rb_Fonts_Size_Tbl[position] = static_cast<unsigned int>(rb_num2long(size));
|
66
|
+
return self;
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE rb_Fonts_define_fill_color(VALUE self, VALUE id, VALUE color)
|
70
|
+
{
|
71
|
+
if(rb_obj_is_kind_of(color, rb_cColor) != Qtrue)
|
72
|
+
{
|
73
|
+
rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(color))));
|
74
|
+
return self;
|
75
|
+
}
|
76
|
+
rb_ary_store(rb_ivar_get(rb_mFonts, rb_Fonts_ivFColor), rb_num2long(id), color);
|
77
|
+
return self;
|
78
|
+
}
|
79
|
+
|
80
|
+
VALUE rb_Fonts_define_outline_color(VALUE self, VALUE id, VALUE color)
|
81
|
+
{
|
82
|
+
if(rb_obj_is_kind_of(color, rb_cColor) != Qtrue)
|
83
|
+
{
|
84
|
+
rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(color))));
|
85
|
+
return self;
|
86
|
+
}
|
87
|
+
rb_ary_store(rb_ivar_get(rb_mFonts, rb_Fonts_ivOColor), rb_num2long(id), color);
|
88
|
+
return self;
|
89
|
+
}
|
90
|
+
|
91
|
+
VALUE rb_Fonts_define_shadow_color(VALUE self, VALUE id, VALUE color)
|
92
|
+
{
|
93
|
+
if(rb_obj_is_kind_of(color, rb_cColor) != Qtrue)
|
94
|
+
{
|
95
|
+
rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(color))));
|
96
|
+
return self;
|
97
|
+
}
|
98
|
+
rb_ary_store(rb_ivar_get(rb_mFonts, rb_Fonts_ivSColor), rb_num2long(id), color);
|
99
|
+
return self;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
VALUE rb_Fonts_get_default_size(VALUE self, VALUE id)
|
104
|
+
{
|
105
|
+
long lid = rb_num2long(id);
|
106
|
+
if(lid >= rb_Fonts_Size_Tbl.size())
|
107
|
+
{
|
108
|
+
return LONG2FIX(16);
|
109
|
+
}
|
110
|
+
return rb_int2inum(static_cast<long>(rb_Fonts_Size_Tbl[lid]));
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE rb_Fonts_get_fill_color(VALUE self, VALUE id)
|
114
|
+
{
|
115
|
+
return rb_ary_aref(1, &id, rb_ivar_get(rb_mFonts, rb_Fonts_ivFColor));
|
116
|
+
}
|
117
|
+
|
118
|
+
VALUE rb_Fonts_get_outline_color(VALUE self, VALUE id)
|
119
|
+
{
|
120
|
+
return rb_ary_aref(1, &id, rb_ivar_get(rb_mFonts, rb_Fonts_ivOColor));
|
121
|
+
}
|
122
|
+
|
123
|
+
VALUE rb_Fonts_get_shadow_color(VALUE self, VALUE id)
|
124
|
+
{
|
125
|
+
return rb_ary_aref(1, &id, rb_ivar_get(rb_mFonts, rb_Fonts_ivSColor));
|
126
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef L_FONTS_HEADER
|
2
|
+
#define L_FONTS_HEADER
|
3
|
+
|
4
|
+
extern ID rb_Fonts_ivSize;
|
5
|
+
extern ID rb_Fonts_ivFColor;
|
6
|
+
extern ID rb_Fonts_ivOColor;
|
7
|
+
extern ID rb_Fonts_ivSColor;
|
8
|
+
|
9
|
+
VALUE rb_Fonts_load_font(VALUE self, VALUE id, VALUE str);
|
10
|
+
sf::Font& rb_Fonts_get_font(unsigned long id);
|
11
|
+
VALUE rb_Fonts_set_default_size(VALUE self, VALUE id, VALUE size);
|
12
|
+
VALUE rb_Fonts_define_fill_color(VALUE self, VALUE id, VALUE color);
|
13
|
+
VALUE rb_Fonts_define_outline_color(VALUE self, VALUE id, VALUE color);
|
14
|
+
VALUE rb_Fonts_define_shadow_color(VALUE self, VALUE id, VALUE color);
|
15
|
+
VALUE rb_Fonts_get_default_size(VALUE self, VALUE id);
|
16
|
+
VALUE rb_Fonts_get_fill_color(VALUE self, VALUE id);
|
17
|
+
VALUE rb_Fonts_get_outline_color(VALUE self, VALUE id);
|
18
|
+
VALUE rb_Fonts_get_shadow_color(VALUE self, VALUE id);
|
19
|
+
|
20
|
+
#endif
|
@@ -0,0 +1,314 @@
|
|
1
|
+
#include "LiteRGSS.h"
|
2
|
+
#include "ruby/thread.h"
|
3
|
+
#include "Graphics.local.h"
|
4
|
+
#include "CBitmap_Element.h"
|
5
|
+
#include "CViewport_Element.h"
|
6
|
+
|
7
|
+
/* Variables definition */
|
8
|
+
VALUE rb_mGraphics = Qnil;
|
9
|
+
VALUE rb_eStoppedGraphics = Qnil;
|
10
|
+
VALUE rb_eClosedWindow = Qnil;
|
11
|
+
ID rb_iGraphicsShader = Qnil;
|
12
|
+
|
13
|
+
long ScreenWidth = 640;
|
14
|
+
long ScreenHeight = 480;
|
15
|
+
unsigned long frame_count = 0;
|
16
|
+
unsigned long frame_rate = 60;
|
17
|
+
|
18
|
+
sf::RenderWindow* game_window = nullptr;
|
19
|
+
bool InsideGraphicsUpdate = false;
|
20
|
+
std::vector<CDrawable_Element*> Graphics_stack;
|
21
|
+
|
22
|
+
sf::Texture* Graphics_freeze_texture = nullptr;
|
23
|
+
sf::Sprite* Graphics_freeze_sprite = nullptr;
|
24
|
+
sf::Shader* Graphics_freeze_shader = nullptr;
|
25
|
+
|
26
|
+
/* Macro Definition */
|
27
|
+
#define GRAPHICS_PROTECT if(game_window == nullptr) { \
|
28
|
+
rb_raise(rb_eStoppedGraphics, "Graphics is not started, window closed thus no Graphics operation allowed. Please call Graphics.start before using other Graphics functions."); \
|
29
|
+
return self; \
|
30
|
+
}
|
31
|
+
|
32
|
+
void Init_Graphics()
|
33
|
+
{
|
34
|
+
rb_mGraphics = rb_define_module_under(rb_mLiteRGSS, "Graphics");
|
35
|
+
/* Defining the Stopped Graphics Error */
|
36
|
+
rb_eStoppedGraphics = rb_define_class_under(rb_mGraphics, "StoppedError", rb_eStandardError);
|
37
|
+
rb_eClosedWindow = rb_define_class_under(rb_mGraphics, "ClosedWindowError", rb_eStandardError);
|
38
|
+
/* Defining the Graphics functions */
|
39
|
+
rb_define_module_function(rb_mGraphics, "start", _rbf rb_Graphics_start, 0);
|
40
|
+
rb_define_module_function(rb_mGraphics, "stop", _rbf rb_Graphics_stop, 0);
|
41
|
+
rb_define_module_function(rb_mGraphics, "update", _rbf rb_Graphics_update, 0);
|
42
|
+
rb_define_module_function(rb_mGraphics, "snap_to_bitmap", _rbf rb_Graphics_snap_to_bitmap, 0);
|
43
|
+
rb_define_module_function(rb_mGraphics, "freeze", _rbf rb_Graphics_freeze, 0);
|
44
|
+
rb_define_module_function(rb_mGraphics, "transition", _rbf rb_Graphics_transition, -1);
|
45
|
+
rb_define_module_function(rb_mGraphics, "list_resolutions", _rbf rb_Graphics_list_res, 0);
|
46
|
+
rb_define_module_function(rb_mGraphics, "frame_count", _rbf rb_Graphics_get_frame_count, 0);
|
47
|
+
rb_define_module_function(rb_mGraphics, "frame_count=", _rbf rb_Graphics_set_frame_count, 1);
|
48
|
+
rb_define_module_function(rb_mGraphics, "width", _rbf rb_Graphics_width, 0);
|
49
|
+
rb_define_module_function(rb_mGraphics, "height", _rbf rb_Graphics_height, 0);
|
50
|
+
rb_define_module_function(rb_mGraphics, "reload_stack", _rbf rb_Graphics_ReloadStack, 0);
|
51
|
+
rb_define_module_function(rb_mGraphics, "update_no_input", _rbf rb_Graphics_update_no_input_count, 0);
|
52
|
+
rb_define_module_function(rb_mGraphics, "update_only_input", _rbf rb_Graphics_update_only_input, 0);
|
53
|
+
rb_define_module_function(rb_mGraphics, "brightness", _rbf rb_Graphics_getBrightness, 0);
|
54
|
+
rb_define_module_function(rb_mGraphics, "brightness=", _rbf rb_Graphics_setBrightness, 1);
|
55
|
+
rb_define_module_function(rb_mGraphics, "shader", _rbf rb_Graphics_getShader, 0);
|
56
|
+
rb_define_module_function(rb_mGraphics, "shader=", _rbf rb_Graphics_setShader, 1);
|
57
|
+
/* creating the element table */
|
58
|
+
rb_ivar_set(rb_mGraphics, rb_iElementTable, rb_ary_new());
|
59
|
+
rb_iGraphicsShader = rb_intern("@__GraphicsShader");
|
60
|
+
/* Store the max texture size */
|
61
|
+
rb_define_const(rb_mGraphics, "MAX_TEXTURE_SIZE", LONG2FIX(sf::Texture::getMaximumSize()));
|
62
|
+
}
|
63
|
+
|
64
|
+
VALUE rb_Graphics_start(VALUE self)
|
65
|
+
{
|
66
|
+
unsigned int framerate;
|
67
|
+
if(game_window != nullptr)
|
68
|
+
return Qnil;
|
69
|
+
/* Shader Testing */
|
70
|
+
if (!sf::Shader::isAvailable())
|
71
|
+
rb_raise(rb_eRGSSError, "Shaders are not available :(");
|
72
|
+
/* Window Loading */
|
73
|
+
sf::VideoMode vmode(640, 480, 32);
|
74
|
+
local_LoadVideoModeFromConfigs(vmode);
|
75
|
+
local_LoadSmoothScreenFromConfigs();
|
76
|
+
sf::Uint32 style = sf::Style::Close | sf::Style::Titlebar; // sf::Style::Resize = text issues !
|
77
|
+
if(local_LoadFullScreenFromConfigs())
|
78
|
+
style = sf::Style::Fullscreen;
|
79
|
+
game_window = new sf::RenderWindow(vmode, local_LoadTitleFromConfigs(), style);
|
80
|
+
game_window->setMouseCursorVisible(false);
|
81
|
+
framerate = local_LoadFrameRateFromConfigs();
|
82
|
+
/* VSYNC choice */
|
83
|
+
if(local_LoadVSYNCFromConfigs())
|
84
|
+
game_window->setVerticalSyncEnabled(true);
|
85
|
+
else
|
86
|
+
{
|
87
|
+
game_window->setVerticalSyncEnabled(false);
|
88
|
+
game_window->setFramerateLimit(framerate);
|
89
|
+
}
|
90
|
+
/* Input adjustement */
|
91
|
+
L_Input_Reset_Clocks();
|
92
|
+
L_Input_Setusec_threshold(1000000 / framerate);
|
93
|
+
frame_count = 0;
|
94
|
+
frame_rate = framerate;
|
95
|
+
/* Shader loading */
|
96
|
+
local_Graphics_LoadShader();
|
97
|
+
return self;
|
98
|
+
}
|
99
|
+
|
100
|
+
VALUE rb_Graphics_stop(VALUE self)
|
101
|
+
{
|
102
|
+
GRAPHICS_PROTECT
|
103
|
+
if(InsideGraphicsUpdate) // Prevent a Thread from calling stop during the Graphics.update process
|
104
|
+
return self;
|
105
|
+
/* Clear the stack */
|
106
|
+
local_Graphics_Clear_Stack();
|
107
|
+
/* Close the window */
|
108
|
+
game_window->close();
|
109
|
+
delete game_window;
|
110
|
+
game_window = nullptr;
|
111
|
+
/* Unfreezing Graphics */
|
112
|
+
if(Graphics_freeze_texture != nullptr)
|
113
|
+
{
|
114
|
+
delete Graphics_freeze_sprite;
|
115
|
+
Graphics_freeze_sprite = nullptr;
|
116
|
+
delete Graphics_freeze_texture;
|
117
|
+
Graphics_freeze_texture = nullptr;
|
118
|
+
}
|
119
|
+
if (Graphics_freeze_shader != nullptr)
|
120
|
+
{
|
121
|
+
delete Graphics_freeze_shader;
|
122
|
+
Graphics_freeze_shader = nullptr;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
VALUE rb_Graphics_snap_to_bitmap(VALUE self)
|
127
|
+
{
|
128
|
+
GRAPHICS_PROTECT
|
129
|
+
if(InsideGraphicsUpdate)
|
130
|
+
return Qnil;
|
131
|
+
VALUE bmp = rb_obj_alloc(rb_cBitmap);
|
132
|
+
CBitmap_Element* bitmap;
|
133
|
+
Data_Get_Struct(bmp, CBitmap_Element, bitmap);
|
134
|
+
if(bitmap == nullptr)
|
135
|
+
return Qnil;
|
136
|
+
sf::Texture* text = bitmap->getTexture();
|
137
|
+
local_Graphics_Take_Snapshot(text);
|
138
|
+
return bmp;
|
139
|
+
}
|
140
|
+
|
141
|
+
VALUE rb_Graphics_freeze(VALUE self)
|
142
|
+
{
|
143
|
+
GRAPHICS_PROTECT
|
144
|
+
if(Graphics_freeze_texture != nullptr)
|
145
|
+
return self;
|
146
|
+
rb_Graphics_update(self);
|
147
|
+
Graphics_freeze_texture = new sf::Texture();
|
148
|
+
local_Graphics_Take_Snapshot(Graphics_freeze_texture);
|
149
|
+
Graphics_freeze_sprite = new sf::Sprite(*Graphics_freeze_texture);
|
150
|
+
Graphics_freeze_sprite->setScale(1.0f / Graphics_Scale, 1.0f / Graphics_Scale);
|
151
|
+
return self;
|
152
|
+
}
|
153
|
+
|
154
|
+
VALUE rb_Graphics_transition(int argc, VALUE* argv, VALUE self)
|
155
|
+
{
|
156
|
+
GRAPHICS_PROTECT
|
157
|
+
if(Graphics_freeze_sprite == nullptr)
|
158
|
+
return self;
|
159
|
+
long time = 8; //< RGSS doc
|
160
|
+
if(argc >= 1)
|
161
|
+
time = rb_num2long(argv[0]);
|
162
|
+
time = normalize_long(time, 1, 0xFFFF);
|
163
|
+
if (argc < 2 || rb_obj_is_kind_of(argv[1], rb_cBitmap) != Qtrue)
|
164
|
+
local_Graphics_TransitionBasic(self, time);
|
165
|
+
else
|
166
|
+
local_Graphics_TransitionRGSS(self, time, argv[1]);
|
167
|
+
delete Graphics_freeze_sprite;
|
168
|
+
Graphics_freeze_sprite = nullptr;
|
169
|
+
delete Graphics_freeze_texture;
|
170
|
+
Graphics_freeze_texture = nullptr;
|
171
|
+
return self;
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
VALUE rb_Graphics_list_res(VALUE self)
|
176
|
+
{
|
177
|
+
VALUE array = rb_ary_new();
|
178
|
+
auto modes = sf::VideoMode::getFullscreenModes();
|
179
|
+
for(int i = 0; i < modes.size(); i++)
|
180
|
+
{
|
181
|
+
if(modes[i].bitsPerPixel == 32)
|
182
|
+
rb_ary_push(array, rb_ary_new3(2, rb_int2inum(modes[i].width), rb_int2inum(modes[i].height)));
|
183
|
+
}
|
184
|
+
return array;
|
185
|
+
}
|
186
|
+
|
187
|
+
VALUE rb_Graphics_update(VALUE self)
|
188
|
+
{
|
189
|
+
GRAPHICS_PROTECT
|
190
|
+
if(InsideGraphicsUpdate) // Prevent a Thread from calling Graphics.update during Graphics.update process
|
191
|
+
return self;
|
192
|
+
InsideGraphicsUpdate = true;
|
193
|
+
/* Graphics.update real process */
|
194
|
+
GraphicUpdateMessage* message =
|
195
|
+
reinterpret_cast<GraphicUpdateMessage*>(rb_thread_call_without_gvl(local_Graphics_Update_Internal, (void*)&Graphics_stack, NULL, NULL));
|
196
|
+
/* Message Processing */
|
197
|
+
local_Graphics_Update_Process_Event(message);
|
198
|
+
if(message != nullptr)
|
199
|
+
return local_Graphics_Update_RaiseError(self, message);
|
200
|
+
/* End of Graphics.update process */
|
201
|
+
InsideGraphicsUpdate = false;
|
202
|
+
/* Update the frame count */
|
203
|
+
frame_count++;
|
204
|
+
return self;
|
205
|
+
}
|
206
|
+
|
207
|
+
VALUE rb_Graphics_update_no_input_count(VALUE self)
|
208
|
+
{
|
209
|
+
GRAPHICS_PROTECT
|
210
|
+
if (InsideGraphicsUpdate) // Prevent a Thread from calling Graphics.update during Graphics.update process
|
211
|
+
return self;
|
212
|
+
InsideGraphicsUpdate = true;
|
213
|
+
/* Graphics.update real process */
|
214
|
+
GraphicUpdateMessage* message =
|
215
|
+
reinterpret_cast<GraphicUpdateMessage*>(rb_thread_call_without_gvl(local_Graphics_Update_Internal, (void*)&Graphics_stack, NULL, NULL));
|
216
|
+
if (message != nullptr)
|
217
|
+
return local_Graphics_Update_RaiseError(self, message);
|
218
|
+
/* End of Graphics.update process */
|
219
|
+
InsideGraphicsUpdate = false;
|
220
|
+
return self;
|
221
|
+
}
|
222
|
+
|
223
|
+
VALUE rb_Graphics_update_only_input(VALUE self)
|
224
|
+
{
|
225
|
+
GRAPHICS_PROTECT
|
226
|
+
InsideGraphicsUpdate = true;
|
227
|
+
GraphicUpdateMessage* message = nullptr;
|
228
|
+
local_Graphics_Update_Process_Event(message);
|
229
|
+
if (message != nullptr)
|
230
|
+
return local_Graphics_Update_RaiseError(self, message);
|
231
|
+
InsideGraphicsUpdate = false;
|
232
|
+
return self;
|
233
|
+
}
|
234
|
+
|
235
|
+
VALUE rb_Graphics_get_frame_count(VALUE self)
|
236
|
+
{
|
237
|
+
return RB_UINT2NUM(frame_count);
|
238
|
+
}
|
239
|
+
|
240
|
+
VALUE rb_Graphics_set_frame_count(VALUE self, VALUE val)
|
241
|
+
{
|
242
|
+
frame_count = rb_num2ulong(val);
|
243
|
+
return val;
|
244
|
+
}
|
245
|
+
|
246
|
+
VALUE rb_Graphics_width(VALUE self)
|
247
|
+
{
|
248
|
+
return rb_int2inum(ScreenWidth);
|
249
|
+
}
|
250
|
+
|
251
|
+
VALUE rb_Graphics_height(VALUE self)
|
252
|
+
{
|
253
|
+
return rb_int2inum(ScreenHeight);
|
254
|
+
}
|
255
|
+
|
256
|
+
VALUE rb_Graphics_ReloadStack(VALUE self)
|
257
|
+
{
|
258
|
+
VALUE table = rb_ivar_get(rb_mGraphics, rb_iElementTable);
|
259
|
+
rb_check_type(table, T_ARRAY);
|
260
|
+
for(auto it = Graphics_stack.begin(); it != Graphics_stack.end(); it++)
|
261
|
+
{
|
262
|
+
(*it)->overrideOrigineStack(nullptr);
|
263
|
+
}
|
264
|
+
Graphics_stack.clear();
|
265
|
+
long sz = RARRAY_LEN(table);
|
266
|
+
VALUE* ori = RARRAY_PTR(table);
|
267
|
+
for(long i = 0; i < sz; i++)
|
268
|
+
{
|
269
|
+
if(rb_obj_is_kind_of(ori[i], rb_cViewport) == Qtrue ||
|
270
|
+
rb_obj_is_kind_of(ori[i], rb_cSprite) == Qtrue ||
|
271
|
+
rb_obj_is_kind_of(ori[i], rb_cText) == Qtrue)
|
272
|
+
{
|
273
|
+
if(RDATA(ori[i])->data != nullptr)
|
274
|
+
{
|
275
|
+
global_Graphics_Bind(reinterpret_cast<CDrawable_Element*>(RDATA(ori[i])->data));
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}
|
279
|
+
return self;
|
280
|
+
}
|
281
|
+
|
282
|
+
VALUE rb_Graphics_getBrightness(VALUE self)
|
283
|
+
{
|
284
|
+
return LONG2FIX(Graphics_Brightness);
|
285
|
+
}
|
286
|
+
|
287
|
+
VALUE rb_Graphics_setBrightness(VALUE self, VALUE brightness)
|
288
|
+
{
|
289
|
+
Graphics_Brightness = normalize_long(rb_num2long(brightness), 0, 255);
|
290
|
+
return self;
|
291
|
+
}
|
292
|
+
|
293
|
+
VALUE rb_Graphics_getShader(VALUE self)
|
294
|
+
{
|
295
|
+
return rb_ivar_get(self, rb_iGraphicsShader);
|
296
|
+
}
|
297
|
+
|
298
|
+
VALUE rb_Graphics_setShader(VALUE self, VALUE shader)
|
299
|
+
{
|
300
|
+
GRAPHICS_PROTECT;
|
301
|
+
sf::RenderStates* render_state;
|
302
|
+
if (rb_obj_is_kind_of(shader, rb_cBlendMode) == Qtrue)
|
303
|
+
{
|
304
|
+
rb_ivar_set(self, rb_iGraphicsShader, shader);
|
305
|
+
Data_Get_Struct(shader, sf::RenderStates, render_state);
|
306
|
+
Graphics_States = render_state;
|
307
|
+
local_Graphics_initRender();
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
void global_Graphics_Bind(CDrawable_Element* element)
|
312
|
+
{
|
313
|
+
element->setOriginStack(&Graphics_stack);
|
314
|
+
}
|