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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/ext/LiteRGSS/Bitmap.cpp +316 -0
  3. data/ext/LiteRGSS/Bitmap.h +24 -0
  4. data/ext/LiteRGSS/BlendMode.cpp +202 -0
  5. data/ext/LiteRGSS/BlendMode.h +20 -0
  6. data/ext/LiteRGSS/CBitmap_Element.cpp +50 -0
  7. data/ext/LiteRGSS/CBitmap_Element.h +17 -0
  8. data/ext/LiteRGSS/CDrawable_Element.cpp +38 -0
  9. data/ext/LiteRGSS/CDrawable_Element.h +30 -0
  10. data/ext/LiteRGSS/CRect_Element.h +15 -0
  11. data/ext/LiteRGSS/CShaderSprite_Element.cpp +17 -0
  12. data/ext/LiteRGSS/CShaderSprite_Element.h +17 -0
  13. data/ext/LiteRGSS/CSprite_Element.cpp +15 -0
  14. data/ext/LiteRGSS/CSprite_Element.h +36 -0
  15. data/ext/LiteRGSS/CText_Element.cpp +12 -0
  16. data/ext/LiteRGSS/CText_Element.h +29 -0
  17. data/ext/LiteRGSS/CTone_Element.h +17 -0
  18. data/ext/LiteRGSS/CViewport_Element.cpp +224 -0
  19. data/ext/LiteRGSS/CViewport_Element.h +57 -0
  20. data/ext/LiteRGSS/Color.cpp +200 -0
  21. data/ext/LiteRGSS/Color.h +22 -0
  22. data/ext/LiteRGSS/Fonts.cpp +126 -0
  23. data/ext/LiteRGSS/Fonts.h +20 -0
  24. data/ext/LiteRGSS/Graphics.cpp +314 -0
  25. data/ext/LiteRGSS/Graphics.h +31 -0
  26. data/ext/LiteRGSS/Graphics.local.cpp +365 -0
  27. data/ext/LiteRGSS/Graphics.local.h +37 -0
  28. data/ext/LiteRGSS/Image.cpp +460 -0
  29. data/ext/LiteRGSS/Image.h +32 -0
  30. data/ext/LiteRGSS/Input.cpp +664 -0
  31. data/ext/LiteRGSS/Input.h +38 -0
  32. data/ext/LiteRGSS/LiteRGSS.cpp +34 -0
  33. data/ext/LiteRGSS/LiteRGSS.h +113 -0
  34. data/ext/LiteRGSS/Rect.cpp +324 -0
  35. data/ext/LiteRGSS/Rect.h +24 -0
  36. data/ext/LiteRGSS/Shader.cpp +279 -0
  37. data/ext/LiteRGSS/Shader.h +13 -0
  38. data/ext/LiteRGSS/ShaderSprite.cpp +78 -0
  39. data/ext/LiteRGSS/ShaderSprite.h +8 -0
  40. data/ext/LiteRGSS/Sprite.cpp +495 -0
  41. data/ext/LiteRGSS/Sprite.h +43 -0
  42. data/ext/LiteRGSS/Table.cpp +228 -0
  43. data/ext/LiteRGSS/Table.h +29 -0
  44. data/ext/LiteRGSS/Table32.cpp +228 -0
  45. data/ext/LiteRGSS/Table32.h +29 -0
  46. data/ext/LiteRGSS/Text.cpp +574 -0
  47. data/ext/LiteRGSS/Text.h +52 -0
  48. data/ext/LiteRGSS/Texture.hpp +735 -0
  49. data/ext/LiteRGSS/Tone.cpp +228 -0
  50. data/ext/LiteRGSS/Tone.h +22 -0
  51. data/ext/LiteRGSS/Viewport.cpp +491 -0
  52. data/ext/LiteRGSS/Viewport.h +33 -0
  53. data/ext/LiteRGSS/Yuki.cpp +29 -0
  54. data/ext/LiteRGSS/Yuki.h +8 -0
  55. data/ext/LiteRGSS/Yuki_Gif.cpp +218 -0
  56. data/ext/LiteRGSS/Yuki_Gif.h +25 -0
  57. data/ext/LiteRGSS/extconf.rb +8 -0
  58. data/ext/LiteRGSS/libnsgif.c +1169 -0
  59. data/ext/LiteRGSS/libnsgif.h +183 -0
  60. data/ext/LiteRGSS/libnsgif.hpp +184 -0
  61. data/ext/LiteRGSS/lodepng.cpp +6245 -0
  62. data/ext/LiteRGSS/lodepng.h +1769 -0
  63. data/ext/LiteRGSS/lzw.c +377 -0
  64. data/ext/LiteRGSS/lzw.h +105 -0
  65. data/ext/LiteRGSS/sf_Text2.cpp +690 -0
  66. data/ext/LiteRGSS/sf_Text2.hpp +549 -0
  67. data/ext/LiteRGSS/utils/log.h +21 -0
  68. metadata +112 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9459f2fcb63963a8cea93d75513e7476c3b7fe82e016683ec52229aae5d45893
4
+ data.tar.gz: c059a84582c124246773f768df6f3252a6c2a87dac045c59986b1f7e060fa1cc
5
+ SHA512:
6
+ metadata.gz: af7516c88ea7398f2f7ae7b03e242ddd670ea368849c2f49d5667ed0aa3927f11a912c84f1c32c6a5d4fc4547d1a862e6995ee4b8e556cffb0ecff4e23eeab82
7
+ data.tar.gz: 92c31815d79702d4a35c7fb65d2ca83eac938bda44ba03669e1e3731bbfc11851bd37de21e16707e1b8f82dca96fd85d7a7fb57a492d1ed524c11375f39d1608
@@ -0,0 +1,316 @@
1
+ #include "LiteRGSS.h"
2
+ #include "CBitmap_Element.h"
3
+ #include "CRect_Element.h"
4
+
5
+ VALUE rb_cBitmap = Qnil;
6
+
7
+ #define BITMAP_PROTECT if(RDATA(self)->data == nullptr) \
8
+ {\
9
+ rb_raise(rb_eRGSSError, "Disposed Bitmap."); \
10
+ return self; \
11
+ }
12
+
13
+ #define GET_BITMAP CBitmap_Element* bitmap; \
14
+ Data_Get_Struct(self, CBitmap_Element, bitmap); \
15
+ BITMAP_PROTECT \
16
+
17
+ void rb_Bitmap_Free(void* data)
18
+ {
19
+ CBitmap_Element* bitmap = reinterpret_cast<CBitmap_Element*>(data);
20
+ if(bitmap != nullptr)
21
+ {
22
+ delete bitmap;
23
+ }
24
+ }
25
+
26
+ VALUE rb_Bitmap_Alloc(VALUE klass)
27
+ {
28
+ CBitmap_Element* bitmap = new CBitmap_Element();
29
+ return Data_Wrap_Struct(klass, NULL, rb_Bitmap_Free, bitmap);
30
+ }
31
+
32
+ void Init_Bitmap()
33
+ {
34
+ rb_cBitmap = rb_define_class_under(rb_mLiteRGSS, "Bitmap", rb_cObject);
35
+ rb_define_alloc_func(rb_cBitmap, rb_Bitmap_Alloc);
36
+ rb_define_method(rb_cBitmap, "initialize", _rbf rb_Bitmap_Initialize, -1);
37
+ rb_define_method(rb_cBitmap, "initialize_copy", _rbf rb_Bitmap_Initialize_Copy, 1);
38
+ rb_define_method(rb_cBitmap, "dispose", _rbf rb_Bitmap_Dispose, 0);
39
+ rb_define_method(rb_cBitmap, "disposed?", _rbf rb_Bitmap_Disposed, 0);
40
+ rb_define_method(rb_cBitmap, "width", _rbf rb_Bitmap_Width, 0);
41
+ rb_define_method(rb_cBitmap, "height", _rbf rb_Bitmap_Height, 0);
42
+ rb_define_method(rb_cBitmap, "rect", _rbf rb_Bitmap_Rect, 0);
43
+ rb_define_method(rb_cBitmap, "update", _rbf rb_Bitmap_Update, 0);
44
+ rb_define_method(rb_cBitmap, "blt", _rbf rb_Bitmap_blt, 4);
45
+ rb_define_method(rb_cBitmap, "clear_rect", _rbf rb_Bitmap_clear_rect, 4);
46
+ rb_define_method(rb_cBitmap, "fill_rect", _rbf rb_Bitmap_fill_rect, 5);
47
+ rb_define_method(rb_cBitmap, "to_png", _rbf rb_Bitmap_toPNG, 0);
48
+ rb_define_method(rb_cBitmap, "to_png_file", _rbf rb_Bitmap_toPNG_file, 1);
49
+ }
50
+
51
+ VALUE rb_Bitmap_Initialize(int argc, VALUE *argv, VALUE self)
52
+ {
53
+ VALUE string, fromMemory;
54
+ GET_BITMAP
55
+ rb_scan_args(argc, argv, "11", &string, &fromMemory);
56
+ sf::Texture* text = bitmap->getTexture();
57
+ /* Load From filename */
58
+ if(NIL_P(fromMemory))
59
+ {
60
+ rb_check_type(string, T_STRING);
61
+ if(!rb_Bitmap_LoadLodePNG(text, RSTRING_PTR(string), 0))
62
+ if(!text->loadFromFile(RSTRING_PTR(string)))
63
+ {
64
+ errno = ENOENT;
65
+ rb_sys_fail(RSTRING_PTR(string));
66
+ }
67
+ }
68
+ /* Load From Memory */
69
+ else if(fromMemory == Qtrue)
70
+ {
71
+ rb_check_type(string, T_STRING);
72
+ if(!rb_Bitmap_LoadLodePNG(text, RSTRING_PTR(string), RSTRING_LEN(string)))
73
+ if(!text->loadFromMemory(RSTRING_PTR(string), RSTRING_LEN(string)))
74
+ rb_raise(rb_eRGSSError, "Failed to load bitmap from memory.");
75
+ }
76
+ else
77
+ {
78
+ rb_check_type(string, T_FIXNUM);
79
+ rb_check_type(fromMemory, T_FIXNUM);
80
+ sf::Image* img = bitmap->getImage();
81
+ img->create(rb_num2long(string), rb_num2long(fromMemory), sf::Color(0, 0, 0, 0));
82
+ if(!text->loadFromImage(*img))
83
+ {
84
+ rb_raise(rb_eRGSSError, "Invalid texture size !");
85
+ }
86
+ //rb_raise(rb_eRGSSError, "Bitmap no longer allow drawing, thus Bitmap.new(width, height) is not allowed.");
87
+ }
88
+ text->setSmooth(SmoothScreen);
89
+ return self;
90
+ }
91
+
92
+ VALUE rb_Bitmap_Initialize_Copy(VALUE self, VALUE other)
93
+ {
94
+ //rb_notimplement();
95
+ rb_check_frozen(self);
96
+ if(rb_obj_is_kind_of(other, rb_cBitmap) != Qtrue)
97
+ {
98
+ rb_raise(rb_eTypeError, "Cannot clone %s into Bitmap.", RSTRING_PTR(rb_class_name(CLASS_OF(other))));
99
+ return self;
100
+ }
101
+ CBitmap_Element* bitmap;
102
+ CBitmap_Element* bitmapo;
103
+ Data_Get_Struct(self, CBitmap_Element, bitmap);
104
+ Data_Get_Struct(other, CBitmap_Element, bitmapo);
105
+ if(bitmapo == nullptr)
106
+ rb_raise(rb_eRGSSError, "Disposed Bitmap.");
107
+ bitmap->copy(bitmapo);
108
+ return self;
109
+ }
110
+
111
+ VALUE rb_Bitmap_Dispose(VALUE self)
112
+ {
113
+ GET_BITMAP
114
+ delete bitmap;
115
+ RDATA(self)->data = nullptr;
116
+ return self;
117
+ }
118
+
119
+ VALUE rb_Bitmap_Disposed(VALUE self)
120
+ {
121
+ rb_check_type(self, T_DATA);
122
+ return (RDATA(self)->data == nullptr ? Qtrue : Qfalse);
123
+ }
124
+
125
+ VALUE rb_Bitmap_Width(VALUE self)
126
+ {
127
+ GET_BITMAP
128
+ sf::Vector2u size = bitmap->getTexture()->getSize();
129
+ return rb_int2inum(size.x);
130
+ }
131
+
132
+ VALUE rb_Bitmap_Height(VALUE self)
133
+ {
134
+ GET_BITMAP
135
+ sf::Vector2u size = bitmap->getTexture()->getSize();
136
+ return rb_int2inum(size.y);
137
+ }
138
+
139
+ VALUE rb_Bitmap_Rect(VALUE self)
140
+ {
141
+ GET_BITMAP
142
+ sf::Vector2u size = bitmap->getTexture()->getSize();
143
+ VALUE argv[4] = {LONG2FIX(0), LONG2FIX(0), rb_int2inum(size.x), rb_int2inum(size.y)};
144
+ return rb_class_new_instance(4, argv, rb_cRect);
145
+ }
146
+
147
+ VALUE rb_Bitmap_Update(VALUE self)
148
+ {
149
+ GET_BITMAP
150
+ if(bitmap->has_image())
151
+ {
152
+ bitmap->getTexture()->update(*bitmap->getImage());
153
+ }
154
+ return self;
155
+ }
156
+
157
+ VALUE rb_Bitmap_blt(VALUE self, VALUE x, VALUE y, VALUE src_bitmap, VALUE rect)
158
+ {
159
+ GET_BITMAP
160
+ if(bitmap->has_image())
161
+ {
162
+ if(rb_obj_is_kind_of(rect, rb_cRect) != Qtrue)
163
+ {
164
+ rb_raise(rb_eTypeError, "Expected Rect got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(rect))));
165
+ return Qnil;
166
+ }
167
+ CBitmap_Element* s_bitmap;
168
+ Data_Get_Struct(src_bitmap, CBitmap_Element, s_bitmap);
169
+ CRect_Element* s_rect;
170
+ Data_Get_Struct(rect, CRect_Element, s_rect);
171
+ if(RDATA(src_bitmap)->data == nullptr)
172
+ {
173
+ rb_raise(rb_eRGSSError, "Disposed Bitmap.");
174
+ return self;
175
+ }
176
+ bitmap->getImage()->copy(
177
+ *s_bitmap->getImage(),
178
+ NUM2ULONG(x),
179
+ NUM2ULONG(y),
180
+ *s_rect->getRect()
181
+ );
182
+ }
183
+ return self;
184
+ }
185
+
186
+ VALUE rb_Bitmap_clear_rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
187
+ {
188
+ GET_BITMAP
189
+ rb_check_type(x, T_FIXNUM);
190
+ rb_check_type(y, T_FIXNUM);
191
+ rb_check_type(width, T_FIXNUM);
192
+ rb_check_type(height, T_FIXNUM);
193
+ long x1 = NUM2LONG(x);
194
+ long x2 = NUM2LONG(width) + x1;
195
+ if (x1 < 0)
196
+ x1 = 0;
197
+ long y1 = NUM2LONG(y);
198
+ long y2 = NUM2LONG(height) + y1;
199
+ if (y1 < 0)
200
+ y1 = 0;
201
+ sf::Image* img = bitmap->getImage();
202
+ sf::Color clr = sf::Color(0, 0, 0, 0);
203
+ while (y1 < y2)
204
+ {
205
+ for (long x3 = x1; x3 < x2; x3++)
206
+ img->setPixel(x3, y1, clr);
207
+ y1++;
208
+ }
209
+ return self;
210
+ }
211
+
212
+ VALUE rb_Bitmap_fill_rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, VALUE color)
213
+ {
214
+ GET_BITMAP;
215
+ if (rb_obj_is_kind_of(color, rb_cColor) != Qtrue)
216
+ return self;
217
+ sf::Color* rcolor;
218
+ Data_Get_Struct(color, sf::Color, rcolor);
219
+ rb_check_type(x, T_FIXNUM);
220
+ rb_check_type(y, T_FIXNUM);
221
+ rb_check_type(width, T_FIXNUM);
222
+ rb_check_type(height, T_FIXNUM);
223
+ long x1 = NUM2LONG(x);
224
+ long x2 = NUM2LONG(width) + x1;
225
+ if (x1 < 0)
226
+ x1 = 0;
227
+ long y1 = NUM2LONG(y);
228
+ long y2 = NUM2LONG(height) + y1;
229
+ if (y1 < 0)
230
+ y1 = 0;
231
+ sf::Image* img = bitmap->getImage();
232
+ while (y1 < y2)
233
+ {
234
+ for (long x3 = x1; x3 < x2; x3++)
235
+ img->setPixel(x3, y1, *rcolor);
236
+ y1++;
237
+ }
238
+ return self;
239
+ }
240
+
241
+ VALUE rb_Bitmap_toPNG(VALUE self)
242
+ {
243
+ GET_BITMAP;
244
+ sf::Image img = bitmap->getTexture()->copyToImage();
245
+ unsigned char* out;
246
+ size_t size;
247
+ if (lodepng_encode32(&out, &size, img.getPixelsPtr(), img.getSize().x, img.getSize().y) != 0)
248
+ {
249
+ if (out)
250
+ free(out);
251
+ return Qnil;
252
+ }
253
+ VALUE ret_val = rb_str_new(reinterpret_cast<const char*>(out), size);
254
+ free(out);
255
+ return ret_val;
256
+ }
257
+
258
+ VALUE rb_Bitmap_toPNG_file(VALUE self, VALUE filename)
259
+ {
260
+ rb_check_type(filename, T_STRING);
261
+ GET_BITMAP;
262
+ sf::Image img = bitmap->getTexture()->copyToImage();
263
+ if (lodepng_encode32_file(RSTRING_PTR(filename), img.getPixelsPtr(), img.getSize().x, img.getSize().y) != 0)
264
+ return Qfalse;
265
+ return Qtrue;
266
+ }
267
+
268
+ bool rb_Bitmap_LoadLodePNG(sf::Texture* text, char* str, long from_memory_size)
269
+ {
270
+ unsigned char* out = nullptr;
271
+ unsigned w;
272
+ unsigned h;
273
+ if (from_memory_size > 0)
274
+ {
275
+ if (lodepng_decode32(&out, &w, &h, reinterpret_cast<unsigned char*>(str), from_memory_size) != 0)
276
+ {
277
+ if (out)
278
+ free(out);
279
+ return false;
280
+ }
281
+ }
282
+ else
283
+ {
284
+ if (lodepng_decode32_file(&out, &w, &h, str) != 0)
285
+ {
286
+ if (out)
287
+ free(out);
288
+ return false;
289
+ }
290
+ }
291
+ text->create(w, h);
292
+ text->update(reinterpret_cast<sf::Uint8*>(out), w, h, 0, 0);
293
+ free(out);
294
+ return true;
295
+ }
296
+
297
+ sf::Texture* rb_Bitmap_getTexture(VALUE self)
298
+ {
299
+ CBitmap_Element* bitmap;
300
+ rb_Bitmap_test_bitmap(self);
301
+ Data_Get_Struct(self, CBitmap_Element, bitmap);
302
+ if (bitmap == nullptr)
303
+ {
304
+ rb_raise(rb_eRGSSError, "Disposed Bitmap.");
305
+ return nullptr;
306
+ }
307
+ return bitmap->getTexture();
308
+ }
309
+
310
+ void rb_Bitmap_test_bitmap(VALUE self)
311
+ {
312
+ if (rb_obj_is_kind_of(self, rb_cBitmap) != Qtrue)
313
+ {
314
+ rb_raise(rb_eTypeError, "Expected Bitmap got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(self))));
315
+ }
316
+ }
@@ -0,0 +1,24 @@
1
+ #ifndef L_BITMAP_HEADER
2
+ #define L_BITMAP_HEADER
3
+ #include "ruby.h"
4
+ #include <SFML/Graphics.hpp>
5
+ #include "lodepng.h"
6
+
7
+ VALUE rb_Bitmap_Initialize(int argc, VALUE *argv, VALUE self);
8
+ VALUE rb_Bitmap_Initialize_Copy(VALUE self, VALUE other);
9
+ VALUE rb_Bitmap_Dispose(VALUE self);
10
+ VALUE rb_Bitmap_Disposed(VALUE self);
11
+ VALUE rb_Bitmap_Width(VALUE self);
12
+ VALUE rb_Bitmap_Height(VALUE self);
13
+ VALUE rb_Bitmap_Rect(VALUE self);
14
+ VALUE rb_Bitmap_Update(VALUE self);
15
+ VALUE rb_Bitmap_blt(VALUE self, VALUE x, VALUE y, VALUE src_bitmap, VALUE rect);
16
+ VALUE rb_Bitmap_clear_rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height);
17
+ VALUE rb_Bitmap_fill_rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, VALUE color);
18
+ VALUE rb_Bitmap_toPNG(VALUE self);
19
+ VALUE rb_Bitmap_toPNG_file(VALUE self, VALUE filename);
20
+ bool rb_Bitmap_LoadLodePNG(sf::Texture* text, char* str, long from_memory_size);
21
+ sf::Texture* rb_Bitmap_getTexture(VALUE self);
22
+ void rb_Bitmap_test_bitmap(VALUE self);
23
+
24
+ #endif
@@ -0,0 +1,202 @@
1
+ #include "LiteRGSS.h"
2
+
3
+ VALUE rb_cBlendMode = Qnil;
4
+
5
+ #define BLENDMODE_PROTECT if(RDATA(self)->data == nullptr) \
6
+ {\
7
+ rb_raise(rb_eRGSSError, "Disposed BlendMode."); \
8
+ return self; \
9
+ }
10
+
11
+ #define GET_BLENDMODE sf::RenderStates* render_state; \
12
+ Data_Get_Struct(self, sf::RenderStates, render_state); \
13
+ BLENDMODE_PROTECT
14
+
15
+ void rb_BlendMode_Free(void* data)
16
+ {
17
+ sf::RenderStates* render_state = reinterpret_cast<sf::RenderStates*>(data);
18
+ if (render_state != nullptr)
19
+ {
20
+ if (render_state->shader != nullptr)
21
+ {
22
+ delete render_state->shader;
23
+ }
24
+ delete render_state;
25
+ }
26
+ }
27
+
28
+ VALUE rb_BlendMode_Alloc(VALUE klass)
29
+ {
30
+ sf::RenderStates* render_state = new sf::RenderStates();
31
+ return Data_Wrap_Struct(klass, NULL, rb_BlendMode_Free, render_state);
32
+ }
33
+
34
+ void Init_BlendMode()
35
+ {
36
+ rb_cBlendMode = rb_define_class_under(rb_mLiteRGSS, "BlendMode", rb_cObject);
37
+ rb_define_alloc_func(rb_cBlendMode, rb_BlendMode_Alloc);
38
+
39
+ rb_define_method(rb_cBlendMode, "color_src_factor", _rbf rb_BlendMode_getColorSrcFactor, 0);
40
+ rb_define_method(rb_cBlendMode, "color_src_factor=", _rbf rb_BlendMode_setColorSrcFactor, 1);
41
+ rb_define_method(rb_cBlendMode, "color_dest_factor", _rbf rb_BlendMode_getColorDestFactor, 0);
42
+ rb_define_method(rb_cBlendMode, "color_dest_factor=", _rbf rb_BlendMode_setColorDestFactor, 1);
43
+ rb_define_method(rb_cBlendMode, "alpha_src_factor", _rbf rb_BlendMode_getAlphaSrcFactor, 0);
44
+ rb_define_method(rb_cBlendMode, "alpha_src_factor=", _rbf rb_BlendMode_setAlphaSrcFactor, 1);
45
+ rb_define_method(rb_cBlendMode, "alpha_dest_factor", _rbf rb_BlendMode_getAlphaDestFactor, 0);
46
+ rb_define_method(rb_cBlendMode, "alpha_dest_factor=", _rbf rb_BlendMode_setAlphaDestFactor, 1);
47
+ rb_define_method(rb_cBlendMode, "color_equation", _rbf rb_BlendMode_getColorEquation, 0);
48
+ rb_define_method(rb_cBlendMode, "color_equation=", _rbf rb_BlendMode_setColorEquation, 1);
49
+ rb_define_method(rb_cBlendMode, "alpha_equation", _rbf rb_BlendMode_getAlphaEquation, 0);
50
+ rb_define_method(rb_cBlendMode, "alpha_equation=", _rbf rb_BlendMode_setAlphaEquation, 1);
51
+ rb_define_method(rb_cBlendMode, "blend_type", _rbf rb_BlendMode_getBlendType, 0);
52
+ rb_define_method(rb_cBlendMode, "blend_type=", _rbf rb_BlendMode_setBlendType, 1);
53
+
54
+ rb_define_method(rb_cBlendMode, "clone", _rbf rb_BlendMode_Copy, 0);
55
+ rb_define_method(rb_cBlendMode, "dup", _rbf rb_BlendMode_Copy, 0);
56
+
57
+ // Equation
58
+ rb_define_const(rb_cBlendMode, "Add", LONG2FIX(sf::BlendMode::Equation::Add));
59
+ rb_define_const(rb_cBlendMode, "Subtract", LONG2FIX(sf::BlendMode::Equation::Subtract));
60
+ rb_define_const(rb_cBlendMode, "ReverseSubtract", LONG2FIX(sf::BlendMode::Equation::ReverseSubtract));
61
+
62
+ // Factor
63
+ rb_define_const(rb_cBlendMode, "Zero", LONG2FIX(sf::BlendMode::Factor::Zero));
64
+ rb_define_const(rb_cBlendMode, "One", LONG2FIX(sf::BlendMode::Factor::One));
65
+ rb_define_const(rb_cBlendMode, "SrcColor", LONG2FIX(sf::BlendMode::Factor::SrcColor));
66
+ rb_define_const(rb_cBlendMode, "OneMinusSrcColor", LONG2FIX(sf::BlendMode::Factor::OneMinusSrcColor));
67
+ rb_define_const(rb_cBlendMode, "DstColor", LONG2FIX(sf::BlendMode::Factor::DstColor));
68
+ rb_define_const(rb_cBlendMode, "OneMinusDstColor", LONG2FIX(sf::BlendMode::Factor::OneMinusDstColor));
69
+ rb_define_const(rb_cBlendMode, "SrcAlpha", LONG2FIX(sf::BlendMode::Factor::SrcAlpha));
70
+ rb_define_const(rb_cBlendMode, "OneMinusSrcAlpha", LONG2FIX(sf::BlendMode::Factor::OneMinusSrcAlpha));
71
+ rb_define_const(rb_cBlendMode, "DstAlpha", LONG2FIX(sf::BlendMode::Factor::DstAlpha));
72
+ rb_define_const(rb_cBlendMode, "OneMinusDstAlpha", LONG2FIX(sf::BlendMode::Factor::OneMinusDstAlpha));
73
+
74
+ }
75
+
76
+ VALUE rb_BlendMode_setColorSrcFactor(VALUE self, VALUE val)
77
+ {
78
+ GET_BLENDMODE;
79
+ render_state->blendMode.colorSrcFactor = static_cast<sf::BlendMode::Factor>(NUM2LONG(val));
80
+ return self;
81
+ }
82
+
83
+ VALUE rb_BlendMode_getColorSrcFactor(VALUE self)
84
+ {
85
+ GET_BLENDMODE;
86
+ return LONG2NUM(render_state->blendMode.colorSrcFactor);
87
+ }
88
+
89
+ VALUE rb_BlendMode_setColorDestFactor(VALUE self, VALUE val)
90
+ {
91
+ GET_BLENDMODE;
92
+ render_state->blendMode.colorDstFactor = static_cast<sf::BlendMode::Factor>(NUM2LONG(val));
93
+ return self;
94
+ }
95
+
96
+ VALUE rb_BlendMode_getColorDestFactor(VALUE self)
97
+ {
98
+ GET_BLENDMODE;
99
+ return LONG2NUM(render_state->blendMode.colorDstFactor);
100
+ }
101
+
102
+ VALUE rb_BlendMode_setAlphaSrcFactor(VALUE self, VALUE val)
103
+ {
104
+ GET_BLENDMODE;
105
+ render_state->blendMode.alphaSrcFactor = static_cast<sf::BlendMode::Factor>(NUM2LONG(val));
106
+ return self;
107
+ }
108
+
109
+ VALUE rb_BlendMode_getAlphaSrcFactor(VALUE self)
110
+ {
111
+ GET_BLENDMODE;
112
+ return LONG2NUM(render_state->blendMode.alphaSrcFactor);
113
+ }
114
+
115
+ VALUE rb_BlendMode_setAlphaDestFactor(VALUE self, VALUE val)
116
+ {
117
+ GET_BLENDMODE;
118
+ render_state->blendMode.alphaDstFactor = static_cast<sf::BlendMode::Factor>(NUM2LONG(val));
119
+ return self;
120
+ }
121
+
122
+ VALUE rb_BlendMode_getAlphaDestFactor(VALUE self)
123
+ {
124
+ GET_BLENDMODE;
125
+ return LONG2NUM(render_state->blendMode.alphaDstFactor);
126
+ }
127
+
128
+ VALUE rb_BlendMode_setColorEquation(VALUE self, VALUE val)
129
+ {
130
+ GET_BLENDMODE;
131
+ render_state->blendMode.colorEquation = static_cast<sf::BlendMode::Equation>(NUM2LONG(val));
132
+ return self;
133
+ }
134
+
135
+ VALUE rb_BlendMode_getColorEquation(VALUE self)
136
+ {
137
+ GET_BLENDMODE;
138
+ return LONG2NUM(render_state->blendMode.colorEquation);
139
+ }
140
+
141
+ VALUE rb_BlendMode_setAlphaEquation(VALUE self, VALUE val)
142
+ {
143
+ GET_BLENDMODE;
144
+ render_state->blendMode.alphaEquation = static_cast<sf::BlendMode::Equation>(NUM2LONG(val));
145
+ return self;
146
+ }
147
+
148
+ VALUE rb_BlendMode_getAlphaEquation(VALUE self)
149
+ {
150
+ GET_BLENDMODE;
151
+ return LONG2NUM(render_state->blendMode.alphaEquation);
152
+ }
153
+
154
+ VALUE rb_BlendMode_setBlendType(VALUE self, VALUE val)
155
+ {
156
+ GET_BLENDMODE;
157
+ long mode = NUM2LONG(val);
158
+ switch (mode)
159
+ {
160
+ case 1: // Add
161
+ render_state->blendMode.colorEquation = sf::BlendMode::Equation::Add;
162
+ render_state->blendMode.alphaEquation = sf::BlendMode::Equation::Add;
163
+ render_state->blendMode.colorSrcFactor = sf::BlendMode::Factor::SrcAlpha;
164
+ render_state->blendMode.colorDstFactor = sf::BlendMode::Factor::One;
165
+ render_state->blendMode.alphaSrcFactor = sf::BlendMode::Factor::One;
166
+ render_state->blendMode.alphaDstFactor = sf::BlendMode::Factor::One;
167
+ break;
168
+ case 2: // Sub
169
+ render_state->blendMode.colorEquation = sf::BlendMode::Equation::ReverseSubtract;
170
+ render_state->blendMode.alphaEquation = sf::BlendMode::Equation::ReverseSubtract;
171
+ render_state->blendMode.colorSrcFactor = sf::BlendMode::Factor::SrcAlpha;
172
+ render_state->blendMode.colorDstFactor = sf::BlendMode::Factor::One;
173
+ render_state->blendMode.alphaSrcFactor = sf::BlendMode::Factor::Zero;
174
+ render_state->blendMode.alphaDstFactor = sf::BlendMode::Factor::One;
175
+ break;
176
+ default: // Normal
177
+ render_state->blendMode.colorEquation = sf::BlendMode::Equation::Add;
178
+ render_state->blendMode.alphaEquation = sf::BlendMode::Equation::Add;
179
+ render_state->blendMode.colorSrcFactor = sf::BlendMode::Factor::SrcAlpha;
180
+ render_state->blendMode.colorDstFactor = sf::BlendMode::Factor::OneMinusSrcAlpha;
181
+ render_state->blendMode.alphaSrcFactor = sf::BlendMode::Factor::One;
182
+ render_state->blendMode.alphaDstFactor = sf::BlendMode::Factor::OneMinusSrcAlpha;
183
+ break;
184
+ }
185
+ return self;
186
+ }
187
+
188
+ VALUE rb_BlendMode_getBlendType(VALUE self)
189
+ {
190
+ GET_BLENDMODE;
191
+ if (render_state->blendMode.colorEquation == sf::BlendMode::Equation::ReverseSubtract)
192
+ return LONG2FIX(2);
193
+ if (render_state->blendMode.alphaDstFactor == sf::BlendMode::Factor::One)
194
+ return LONG2FIX(1);
195
+ return LONG2FIX(0);
196
+ }
197
+
198
+ VALUE rb_BlendMode_Copy(VALUE self)
199
+ {
200
+ rb_raise(rb_eRGSSError, "BlendMode cannot be cloned or duplicated.");
201
+ return self;
202
+ }