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,29 @@
1
+ #ifndef L_TABLE32_HEADER
2
+ #define L_TABLE32_HEADER
3
+
4
+ struct rb_Table32_Struct_Header {
5
+ unsigned int dim;
6
+ unsigned int xsize;
7
+ unsigned int ysize;
8
+ unsigned int zsize;
9
+ unsigned int data_size;
10
+ };
11
+
12
+ struct rb_Table32_Struct {
13
+ rb_Table32_Struct_Header header;
14
+ long* heap;
15
+ };
16
+
17
+ VALUE rb_Table32_initialize(int argc, VALUE* argv, VALUE self);
18
+ VALUE rb_Table32_get(int argc, VALUE* argv, VALUE self);
19
+ VALUE rb_Table32_set(int argc, VALUE* argv, VALUE self);
20
+ VALUE rb_Table32_xSize(VALUE self);
21
+ VALUE rb_Table32_ySize(VALUE self);
22
+ VALUE rb_Table32_zSize(VALUE self);
23
+ VALUE rb_Table32_dim(VALUE self);
24
+ VALUE rb_Table32_resize(int argc, VALUE* argv, VALUE self);
25
+ VALUE rb_Table32_Load(VALUE self, VALUE str);
26
+ VALUE rb_Table32_Save(VALUE self, VALUE limit);
27
+ VALUE rb_Table32_Fill(VALUE self, VALUE val);
28
+
29
+ #endif
@@ -0,0 +1,574 @@
1
+ #include "LiteRGSS.h"
2
+
3
+ VALUE rb_cText = Qnil;
4
+
5
+ #define TEXT_PROTECT if(RDATA(self)->data == nullptr) \
6
+ {\
7
+ rb_raise(rb_eRGSSError, "Disposed Text."); \
8
+ return self; \
9
+ }
10
+
11
+ #define GET_TEXT CText_Element* text; \
12
+ Data_Get_Struct(self, CText_Element, text); \
13
+ TEXT_PROTECT
14
+
15
+
16
+ void rb_Text_Free(void* data)
17
+ {
18
+ CText_Element* text = reinterpret_cast<CText_Element*>(data);
19
+ if(text)
20
+ {
21
+ if(NIL_P(text->rViewport))
22
+ text->setOriginStack(nullptr);
23
+ delete text;
24
+ }
25
+ }
26
+
27
+ void rb_Text_Mark(CText_Element* text)
28
+ {
29
+ if(text == nullptr)
30
+ return;
31
+ rb_gc_mark(text->rViewport);
32
+ rb_gc_mark(text->rwidth);
33
+ rb_gc_mark(text->rheight);
34
+ rb_gc_mark(text->rtext);
35
+ rb_gc_mark(text->rAlign);
36
+ rb_gc_mark(text->rX);
37
+ rb_gc_mark(text->rY);
38
+ rb_gc_mark(text->rZ);
39
+ }
40
+
41
+ VALUE rb_Text_Alloc(VALUE klass)
42
+ {
43
+ CText_Element* text = new CText_Element();
44
+ text->rAlign = LONG2FIX(0);
45
+ text->rZ = LONG2FIX(0);
46
+ text->rtext = Qnil;
47
+ return Data_Wrap_Struct(klass, rb_Text_Mark, rb_Text_Free, text);
48
+ }
49
+
50
+ void Init_Text()
51
+ {
52
+ rb_cText = rb_define_class_under(rb_mLiteRGSS, "Text", rb_cObject);
53
+
54
+ rb_define_alloc_func(rb_cText, rb_Text_Alloc);
55
+
56
+ rb_define_method(rb_cText, "initialize", _rbf rb_Text_Initialize, -1);
57
+ rb_define_method(rb_cText, "dispose", _rbf rb_Text_Dispose, 0);
58
+ rb_define_method(rb_cText, "disposed?", _rbf rb_Text_Disposed, 0);
59
+ rb_define_method(rb_cText, "set_position", _rbf rb_Text_setPosition, 2);
60
+ rb_define_method(rb_cText, "x", _rbf rb_Text_get_x, 0);
61
+ rb_define_method(rb_cText, "x=", _rbf rb_Text_set_x, 1);
62
+ rb_define_method(rb_cText, "y", _rbf rb_Text_get_y, 0);
63
+ rb_define_method(rb_cText, "y=", _rbf rb_Text_set_y, 1);
64
+ rb_define_method(rb_cText, "width", _rbf rb_Text_get_width, 0);
65
+ rb_define_method(rb_cText, "width=", _rbf rb_Text_set_width, 1);
66
+ rb_define_method(rb_cText, "height", _rbf rb_Text_get_height, 0);
67
+ rb_define_method(rb_cText, "height=", _rbf rb_Text_set_height, 1);
68
+ rb_define_method(rb_cText, "fill_color", _rbf rb_Text_get_fill_color, 0);
69
+ rb_define_method(rb_cText, "fill_color=", _rbf rb_Text_set_fill_color, 1);
70
+ rb_define_method(rb_cText, "outline_color", _rbf rb_Text_get_outline_color, 0);
71
+ rb_define_method(rb_cText, "outline_color=", _rbf rb_Text_set_outline_color, 1);
72
+ rb_define_method(rb_cText, "outline_thickness", _rbf rb_Text_get_outline_thickness, 0);
73
+ rb_define_method(rb_cText, "outline_thickness=", _rbf rb_Text_set_outline_thickness, 1);
74
+ rb_define_method(rb_cText, "load_color", _rbf rb_Text_load_color, 1);
75
+ rb_define_method(rb_cText, "align", _rbf rb_Text_get_align, 0);
76
+ rb_define_method(rb_cText, "align=", _rbf rb_Text_set_align, 1);
77
+ rb_define_method(rb_cText, "size", _rbf rb_Text_get_size, 0);
78
+ rb_define_method(rb_cText, "size=", _rbf rb_Text_set_size, 1);
79
+ rb_define_method(rb_cText, "set_size", _rbf rb_Text_set_size, 1);
80
+ rb_define_method(rb_cText, "text", _rbf rb_Text_get_Text, 0);
81
+ rb_define_method(rb_cText, "text=", _rbf rb_Text_set_Text, 1);
82
+ rb_define_method(rb_cText, "visible", _rbf rb_Text_get_visible, 0);
83
+ rb_define_method(rb_cText, "visible=", _rbf rb_Text_set_visible, 1);
84
+ rb_define_method(rb_cText, "draw_shadow", _rbf rb_Text_get_draw_shadow, 0);
85
+ rb_define_method(rb_cText, "draw_shadow=", _rbf rb_Text_set_draw_shadow, 1);
86
+ rb_define_method(rb_cText, "nchar_draw", _rbf rb_Text_get_num_char, 0);
87
+ rb_define_method(rb_cText, "nchar_draw=", _rbf rb_Text_set_num_char, 1);
88
+ rb_define_method(rb_cText, "real_width", _rbf rb_Text_getRealWidth, 0);
89
+ rb_define_method(rb_cText, "opacity", _rbf rb_Text_getOpacity, 0);
90
+ rb_define_method(rb_cText, "opacity=", _rbf rb_Text_setOpacity, 1);
91
+ rb_define_method(rb_cText, "text_width", _rbf rb_Text_get_text_width, 1);
92
+ rb_define_method(rb_cText, "z", _rbf rb_Text_getZ, 0);
93
+ rb_define_method(rb_cText, "z=", _rbf rb_Text_setZ, 1);
94
+ rb_define_method(rb_cText, "__index__", _rbf rb_Text_Index, 0);
95
+ rb_define_method(rb_cText, "viewport", _rbf rb_Text_Viewport, 0);
96
+ rb_define_method(rb_cText, "italic", _rbf rb_Text_getItalic, 0);
97
+ rb_define_method(rb_cText, "italic=", _rbf rb_Text_setItalic, 1);
98
+ rb_define_method(rb_cText, "bold", _rbf rb_Text_getBold, 0);
99
+ rb_define_method(rb_cText, "bold=", _rbf rb_Text_setBold, 1);
100
+
101
+ rb_define_method(rb_cText, "clone", _rbf rb_Text_Copy, 0);
102
+ rb_define_method(rb_cText, "dup", _rbf rb_Text_Copy, 0);
103
+ }
104
+
105
+ VALUE rb_Text_Initialize(int argc, VALUE* argv, VALUE self)
106
+ {
107
+ GET_TEXT
108
+ VALUE fontid, viewport, x, y, width, height, str, align, outlinesize, table;
109
+ rb_scan_args(argc, argv,"72", &fontid, &viewport, &x, &y, &width, &height, &str, &align, &outlinesize);
110
+ /* Viewport */
111
+ if(rb_obj_is_kind_of(viewport, rb_cViewport) == Qtrue)
112
+ {
113
+ text->rViewport = viewport;
114
+
115
+ CViewport_Element* viewporte;
116
+ Data_Get_Struct(viewport, CViewport_Element, viewporte);
117
+ viewporte->bind(text);
118
+ table = rb_ivar_get(viewport, rb_iElementTable);
119
+ }
120
+ else
121
+ {
122
+ global_Graphics_Bind(text);
123
+ table = rb_ivar_get(rb_mGraphics, rb_iElementTable);
124
+ text->rViewport = Qnil;
125
+ }
126
+ rb_ary_push(table, self);
127
+ /* Surface */
128
+ rb_check_type(x, T_FIXNUM);
129
+ text->rX = x;
130
+ rb_check_type(y, T_FIXNUM);
131
+ text->rY = y;
132
+ rb_check_type(width, T_FIXNUM);
133
+ text->rwidth = width;
134
+ rb_check_type(height, T_FIXNUM);
135
+ text->rheight = height;
136
+ /* Aligment */
137
+ if(!NIL_P(align))
138
+ {
139
+ long ralign = rb_num2long(align);
140
+ if(ralign <= 2 && ralign >= 0)
141
+ text->rAlign = align;
142
+ }
143
+ /* Outline size */
144
+ if(!NIL_P(outlinesize))
145
+ {
146
+ text->getText()->setOutlineThickness(static_cast<float>(rb_num2dbl(outlinesize)));
147
+ }
148
+ /* Font */
149
+ VALUE fcol = rb_Fonts_get_fill_color(rb_mFonts, fontid);
150
+ if(rb_obj_is_kind_of(fcol, rb_cColor) == Qtrue)
151
+ rb_Text_set_fill_color(self, fcol);
152
+ VALUE ocol;
153
+ if(text->getText()->getOutlineThickness() < 1.0f)
154
+ ocol = rb_Fonts_get_shadow_color(rb_mFonts, fontid);
155
+ else
156
+ ocol = rb_Fonts_get_outline_color(rb_mFonts, fontid);
157
+ if(rb_obj_is_kind_of(ocol, rb_cColor) == Qtrue)
158
+ rb_Text_set_outline_color(self, ocol);
159
+ text->getText()->setFont(rb_Fonts_get_font(rb_num2long(fontid)));
160
+ /* Size */
161
+ VALUE size = rb_Fonts_get_default_size(rb_mFonts, fontid);
162
+ if(!NIL_P(size))
163
+ text->getText()->setCharacterSize(static_cast<unsigned int>(normalize_long(rb_num2long(size), 1, 0xFFFF)));
164
+ /* Text */
165
+ rb_Text_set_Text(self, str); /* Invokes rb_Text_UpdateI */
166
+ return self;
167
+ }
168
+
169
+ VALUE rb_Text_Copy(VALUE self)
170
+ {
171
+ rb_raise(rb_eRGSSError, "Text can not be cloned or duplicated.");
172
+ return self;
173
+ }
174
+
175
+ VALUE rb_Text_Dispose(VALUE self)
176
+ {
177
+ GET_TEXT
178
+ RDATA(self)->data = nullptr;
179
+ /* Suppression du sprite de ses stacks */
180
+ VALUE viewport = text->rViewport;
181
+ VALUE table;
182
+ if(NIL_P(viewport))
183
+ table = rb_ivar_get(rb_mGraphics, rb_iElementTable);
184
+ else
185
+ table = rb_ivar_get(viewport, rb_iElementTable);
186
+ rb_ary_delete(table, self);
187
+ text->setOriginStack(nullptr); // Ensure the text is removed from the sprite stack
188
+ rb_Text_Free(reinterpret_cast<void*>(text));
189
+ return self;
190
+ }
191
+
192
+ VALUE rb_Text_DisposeFromViewport(VALUE self)
193
+ {
194
+ if(RDATA(self)->data == nullptr)
195
+ return self;
196
+ GET_TEXT
197
+ RDATA(self)->data = nullptr;
198
+ rb_Text_Free(reinterpret_cast<void*>(text));
199
+ return self;
200
+ }
201
+
202
+ VALUE rb_Text_Disposed(VALUE self)
203
+ {
204
+ rb_check_type(self, T_DATA);
205
+ return (RDATA(self)->data == nullptr ? Qtrue : Qfalse);
206
+ }
207
+
208
+
209
+ VALUE rb_Text_setPosition(VALUE self, VALUE x, VALUE y)
210
+ {
211
+ GET_TEXT
212
+ rb_check_type(x, T_FIXNUM);
213
+ rb_check_type(y, T_FIXNUM);
214
+ text->rX = x;
215
+ text->rY = y;
216
+ rb_Text_UpdateI(text);
217
+ return self;
218
+ }
219
+
220
+ VALUE rb_Text_get_x(VALUE self)
221
+ {
222
+ GET_TEXT
223
+ return text->rX;
224
+ }
225
+
226
+ VALUE rb_Text_set_x(VALUE self, VALUE val)
227
+ {
228
+ GET_TEXT
229
+ rb_check_type(val, T_FIXNUM);
230
+ text->rX = val;
231
+ rb_Text_UpdateI(text);
232
+ return val;
233
+ }
234
+
235
+ VALUE rb_Text_get_y(VALUE self)
236
+ {
237
+ GET_TEXT
238
+ return text->rY;
239
+ }
240
+
241
+ VALUE rb_Text_set_y(VALUE self, VALUE val)
242
+ {
243
+ GET_TEXT
244
+ rb_check_type(val, T_FIXNUM);
245
+ text->rY = val;
246
+ rb_Text_UpdateI(text);
247
+ return val;
248
+ }
249
+
250
+ VALUE rb_Text_get_width(VALUE self)
251
+ {
252
+ GET_TEXT
253
+ return text->rwidth;
254
+ }
255
+
256
+ VALUE rb_Text_set_width(VALUE self, VALUE val)
257
+ {
258
+ rb_check_type(val, T_FIXNUM);
259
+ GET_TEXT
260
+ text->rwidth = val;
261
+ rb_Text_UpdateI(text);
262
+ return val;
263
+ }
264
+
265
+ VALUE rb_Text_get_height(VALUE self)
266
+ {
267
+ GET_TEXT
268
+ return text->rheight;
269
+ }
270
+
271
+ VALUE rb_Text_set_height(VALUE self, VALUE val)
272
+ {
273
+ rb_check_type(val, T_FIXNUM);
274
+ GET_TEXT
275
+ text->rheight = val;
276
+ rb_Text_UpdateI(text);
277
+ return val;
278
+ }
279
+
280
+ VALUE rb_Text_get_fill_color(VALUE self)
281
+ {
282
+ GET_TEXT
283
+ VALUE argv[4];
284
+ sf::Color col = text->getText()->getFillColor();
285
+ argv[0] = LONG2FIX(col.r);
286
+ argv[1] = LONG2FIX(col.g);
287
+ argv[2] = LONG2FIX(col.b);
288
+ argv[3] = LONG2FIX(col.a);
289
+ return rb_class_new_instance(4, argv, rb_cColor);
290
+ }
291
+
292
+ VALUE rb_Text_set_fill_color(VALUE self, VALUE val)
293
+ {
294
+ GET_TEXT
295
+ if(rb_obj_is_kind_of(val, rb_cColor) == Qfalse)
296
+ rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(val))));
297
+ sf::Color* color;
298
+ Data_Get_Struct(val, sf::Color, color);
299
+ if(color == nullptr)
300
+ return Qnil;
301
+ text->getText()->setFillColor(*color);
302
+ return val;
303
+ }
304
+
305
+ VALUE rb_Text_get_outline_color(VALUE self)
306
+ {
307
+ GET_TEXT
308
+ VALUE argv[4];
309
+ sf::Color col = text->getText()->getOutlineColor();
310
+ argv[0] = LONG2FIX(col.r);
311
+ argv[1] = LONG2FIX(col.g);
312
+ argv[2] = LONG2FIX(col.b);
313
+ argv[3] = LONG2FIX(col.a);
314
+ return rb_class_new_instance(4, argv, rb_cColor);
315
+ }
316
+
317
+ VALUE rb_Text_set_outline_color(VALUE self, VALUE val)
318
+ {
319
+ GET_TEXT
320
+ if(rb_obj_is_kind_of(val, rb_cColor) == Qfalse)
321
+ rb_raise(rb_eTypeError, "Expected Color got %s.", RSTRING_PTR(rb_class_name(CLASS_OF(val))));
322
+ sf::Color* color;
323
+ Data_Get_Struct(val, sf::Color, color);
324
+ if(color == nullptr)
325
+ return Qnil;
326
+ text->getText()->setOutlineColor(*color);
327
+ return val;
328
+ }
329
+
330
+ VALUE rb_Text_get_outline_thickness(VALUE self)
331
+ {
332
+ GET_TEXT
333
+ return rb_float_new(static_cast<double>(text->getText()->getOutlineThickness()));
334
+ }
335
+
336
+ VALUE rb_Text_set_outline_thickness(VALUE self, VALUE val)
337
+ {
338
+ GET_TEXT
339
+ text->getText()->setOutlineThickness(static_cast<float>(rb_num2dbl(val)));
340
+ return val;
341
+ }
342
+
343
+ VALUE rb_Text_load_color(VALUE self, VALUE id)
344
+ {
345
+ GET_TEXT
346
+ rb_Text_set_fill_color(self, rb_Fonts_get_fill_color(rb_mFonts, id));
347
+ if(text->getText()->getDrawShadow())
348
+ rb_Text_set_outline_color(self, rb_Fonts_get_shadow_color(rb_mFonts, id));
349
+ else
350
+ rb_Text_set_outline_color(self, rb_Fonts_get_outline_color(rb_mFonts, id));
351
+ return self;
352
+ }
353
+
354
+ VALUE rb_Text_get_align(VALUE self)
355
+ {
356
+ GET_TEXT
357
+ return text->rAlign;
358
+ }
359
+
360
+ VALUE rb_Text_set_align(VALUE self, VALUE val)
361
+ {
362
+ GET_TEXT
363
+ long align = rb_num2long(val);
364
+ if(align == 1 || align == 2)
365
+ text->rAlign = val;
366
+ else
367
+ text->rAlign = LONG2FIX(0);
368
+ rb_Text_UpdateI(text);
369
+ }
370
+
371
+ VALUE rb_Text_get_size(VALUE self)
372
+ {
373
+ GET_TEXT
374
+ return rb_int2inum(static_cast<long>(text->getText()->getCharacterSize()));
375
+ }
376
+
377
+ VALUE rb_Text_set_size(VALUE self, VALUE val)
378
+ {
379
+ GET_TEXT
380
+ text->getText()->setCharacterSize(static_cast<unsigned int>(normalize_long(rb_num2long(val), 1, 0xFFFF)));
381
+ rb_Text_UpdateI(text);
382
+ return self;
383
+ }
384
+
385
+ VALUE rb_Text_set_Text(VALUE self, VALUE str)
386
+ {
387
+ GET_TEXT
388
+ rb_check_type(str, T_STRING);
389
+ text->rtext = str;
390
+ text->getText()->setLineHeight(rb_num2dbl(text->rheight));
391
+ std::string stru8(RSTRING_PTR(str));
392
+ text->getText()->setString(sf::String::fromUtf8(stru8.begin(), stru8.end()));
393
+ rb_Text_UpdateI(text);
394
+ return str;
395
+ }
396
+
397
+ VALUE rb_Text_get_text_width(VALUE self, VALUE val)
398
+ {
399
+ GET_TEXT
400
+ rb_check_type(val, T_STRING);
401
+ std::string stru8(RSTRING_PTR(val));
402
+ sf::Uint32 width = text->getText()->getTextWidth(sf::String::fromUtf8(stru8.begin(), stru8.end()));
403
+ return RB_UINT2NUM(width);
404
+ }
405
+
406
+ VALUE rb_Text_get_Text(VALUE self)
407
+ {
408
+ GET_TEXT
409
+ return text->rtext;
410
+ }
411
+
412
+ VALUE rb_Text_get_visible(VALUE self)
413
+ {
414
+ GET_TEXT
415
+ return (text->getVisible() ? Qtrue : Qfalse);
416
+ }
417
+
418
+ VALUE rb_Text_set_visible(VALUE self, VALUE val)
419
+ {
420
+ GET_TEXT
421
+ text->setVisible(RTEST(val));
422
+ return self;
423
+ }
424
+
425
+ VALUE rb_Text_set_num_char(VALUE self, VALUE val)
426
+ {
427
+ GET_TEXT
428
+ text->getText()->setNumCharToDraw(rb_num2ulong(val));
429
+ rb_Text_UpdateI(text);
430
+ return self;
431
+ }
432
+
433
+ VALUE rb_Text_get_num_char(VALUE self)
434
+ {
435
+ GET_TEXT
436
+ return RB_UINT2NUM(text->getText()->getNumCharToDraw());
437
+ }
438
+
439
+ VALUE rb_Text_set_draw_shadow(VALUE self, VALUE val)
440
+ {
441
+ GET_TEXT
442
+ text->getText()->setDrawShadow(RTEST(val));
443
+ return self;
444
+ }
445
+
446
+ VALUE rb_Text_get_draw_shadow(VALUE self)
447
+ {
448
+ GET_TEXT
449
+ return (text->getText()->getDrawShadow() ? Qtrue : Qfalse);
450
+ }
451
+
452
+ VALUE rb_Text_getRealWidth(VALUE self)
453
+ {
454
+ GET_TEXT
455
+ return rb_int2inum(text->getText()->getLocalBounds().width);
456
+ }
457
+
458
+ VALUE rb_Text_getOpacity(VALUE self)
459
+ {
460
+ GET_TEXT
461
+ return rb_int2inum(text->getText()->getFillColor().a);
462
+ }
463
+
464
+ VALUE rb_Text_setOpacity(VALUE self, VALUE val)
465
+ {
466
+ GET_TEXT
467
+ long opacity = normalize_long(rb_num2long(val), 0, 255);
468
+ sf::Text2* t = text->getText();
469
+ sf::Color col = t->getFillColor();
470
+ col.a = opacity;
471
+ t->setFillColor(col);
472
+ if(text->getText()->getOutlineThickness() < 1.0f && opacity != 255)
473
+ {
474
+ col = t->getOutlineColor();
475
+ col.a = opacity / 3;
476
+ t->setOutlineColor(col);
477
+ }
478
+ return self;
479
+ }
480
+
481
+ VALUE rb_Text_getZ(VALUE self)
482
+ {
483
+ GET_TEXT
484
+ return text->rZ;
485
+ }
486
+
487
+ VALUE rb_Text_setZ(VALUE self, VALUE val)
488
+ {
489
+ GET_TEXT
490
+ rb_num2long(val);
491
+ text->rZ = val;
492
+ return self;
493
+ }
494
+
495
+ VALUE rb_Text_Index(VALUE self)
496
+ {
497
+ GET_TEXT
498
+ return rb_uint2inum(text->getIndex());
499
+ }
500
+
501
+ VALUE rb_Text_Viewport(VALUE self)
502
+ {
503
+ GET_TEXT
504
+ return text->rViewport;
505
+ }
506
+
507
+ VALUE rb_Text_getItalic(VALUE self)
508
+ {
509
+ GET_TEXT
510
+ return ((text->getText()->getStyle() & sf::Text2::Style::Italic) ? Qtrue : Qfalse);
511
+ }
512
+
513
+ VALUE rb_Text_setItalic(VALUE self, VALUE val)
514
+ {
515
+ GET_TEXT
516
+ sf::Uint32 style = text->getText()->getStyle();
517
+ if (RTEST(val))
518
+ style |= sf::Text2::Style::Italic;
519
+ else
520
+ style &= ~(sf::Text2::Style::Italic);
521
+ text->getText()->setStyle(style);
522
+ return self;
523
+ }
524
+
525
+ VALUE rb_Text_getBold(VALUE self)
526
+ {
527
+ GET_TEXT
528
+ return ((text->getText()->getStyle() & sf::Text2::Style::Bold) ? Qtrue : Qfalse);
529
+ }
530
+
531
+ VALUE rb_Text_setBold(VALUE self, VALUE val)
532
+ {
533
+ GET_TEXT
534
+ sf::Uint32 style = text->getText()->getStyle();
535
+ if (RTEST(val))
536
+ style |= sf::Text2::Style::Bold;
537
+ else
538
+ style &= ~(sf::Text2::Style::Bold);
539
+ text->getText()->setStyle(style);
540
+ return self;
541
+ }
542
+
543
+ VALUE rb_Text_UpdateI(CText_Element* text)
544
+ {
545
+ sf::Text2* sftext = text->getText();
546
+ float x, y, width, height, ox;
547
+ long align;
548
+ VALUE zero = LONG2FIX(0);
549
+ x = rb_num2long(text->rX);
550
+ y = rb_num2long(text->rY);
551
+ height = rb_num2long(text->rheight);// / 2.0f;//static_cast<float>(rb_num2long(text->rheight)) / 2;
552
+ sf::FloatRect bounds = sftext->getLocalBounds();
553
+ align = rb_num2long(text->rAlign);
554
+ width = rb_num2long(text->rwidth);
555
+ switch(align)
556
+ {
557
+ case 1: /* Center */
558
+ ox = round(bounds.width / 2);
559
+ x = round(x + width / 2);
560
+ break;
561
+ case 2: /* Right */
562
+ ox = round(bounds.width);
563
+ x = round(x + width);
564
+ break;
565
+ default: /* Left */
566
+ ox = 0.0f;
567
+ }
568
+ y = round(y + height / 2);// + (height - bounds.height));
569
+ /* Position update */
570
+ sftext->setPosition(x, y);
571
+ sftext->setOrigin(ox, round(sftext->getCharacterSize() / 2.0f));
572
+ //std::cout << "(" << x << "," << y << ") / (" << ox << ", " << height << ") ->" << sftext->getCharacterSize() << " // " << bounds.height << std::endl;
573
+ return Qnil;
574
+ }