sfml3-rb 0.2.2 → 0.3.1

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +67 -16
  4. data/README.md +123 -32
  5. data/TODO.md +18 -11
  6. data/ext/audio/audio_enums.c +58 -20
  7. data/ext/audio/listener.c +89 -6
  8. data/ext/audio/music.c +212 -5
  9. data/ext/audio/sound.c +218 -9
  10. data/ext/audio/sound_buffer.c +197 -47
  11. data/ext/audio/sound_buffer_recorder.c +90 -18
  12. data/ext/audio/sound_recorder.c +188 -58
  13. data/ext/audio/sound_source_cone.c +127 -33
  14. data/ext/audio/sound_stream.c +204 -21
  15. data/ext/core/exceptions.c +10 -8
  16. data/ext/core/unicode.c +12 -2
  17. data/ext/ext.c +8 -0
  18. data/ext/graphics/blend_mode.c +218 -60
  19. data/ext/graphics/circle.c +300 -16
  20. data/ext/graphics/color.c +253 -94
  21. data/ext/graphics/drawable.c +16 -4
  22. data/ext/graphics/font.c +144 -25
  23. data/ext/graphics/glyph.c +38 -8
  24. data/ext/graphics/image.c +205 -41
  25. data/ext/graphics/polygon.c +317 -30
  26. data/ext/graphics/rect.c +225 -60
  27. data/ext/graphics/rectangle.c +307 -35
  28. data/ext/graphics/render_state.c +124 -12
  29. data/ext/graphics/render_texture.c +191 -14
  30. data/ext/graphics/render_window.c +55 -0
  31. data/ext/graphics/render_window.h +10 -0
  32. data/ext/graphics/shader.c +289 -17
  33. data/ext/graphics/shape.c +265 -32
  34. data/ext/graphics/sprite.c +245 -30
  35. data/ext/graphics/stencil_mode.c +163 -46
  36. data/ext/graphics/target.c +121 -43
  37. data/ext/graphics/target.h +31 -17
  38. data/ext/graphics/text.c +339 -19
  39. data/ext/graphics/texture.c +291 -6
  40. data/ext/graphics/transform.c +178 -5
  41. data/ext/graphics/transformable.c +127 -12
  42. data/ext/graphics/vertex.c +98 -6
  43. data/ext/graphics/vertex_array.c +142 -21
  44. data/ext/graphics/vertex_buffer.c +154 -12
  45. data/ext/graphics/view.c +140 -6
  46. data/ext/network/ftp.c +278 -12
  47. data/ext/network/http.c +179 -44
  48. data/ext/network/ip_address.c +127 -35
  49. data/ext/network/network_enums.c +248 -141
  50. data/ext/network/packet.c +280 -41
  51. data/ext/network/socket_selector.c +98 -21
  52. data/ext/network/tcp_listener.c +82 -18
  53. data/ext/network/tcp_socket.c +135 -27
  54. data/ext/network/udp_socket.c +129 -28
  55. data/ext/ports.rb +7 -0
  56. data/ext/system/buffer.c +47 -16
  57. data/ext/system/clock.c +77 -12
  58. data/ext/system/input_stream.c +113 -51
  59. data/ext/system/sleep.c +10 -2
  60. data/ext/system/time.c +182 -40
  61. data/ext/system/vec2.c +166 -39
  62. data/ext/system/vec3.c +177 -39
  63. data/ext/window/clipboard.c +47 -17
  64. data/ext/window/context.c +66 -13
  65. data/ext/window/context_settings.c +132 -42
  66. data/ext/window/cursor.c +45 -9
  67. data/ext/window/event.c +164 -53
  68. data/ext/window/joystick.c +69 -3
  69. data/ext/window/keyboard.c +168 -116
  70. data/ext/window/mouse.c +64 -13
  71. data/ext/window/sensor.c +28 -2
  72. data/ext/window/touch.c +32 -12
  73. data/ext/window/video_mode.c +93 -31
  74. data/ext/window/vulkan.c +34 -6
  75. data/ext/window/window.c +228 -229
  76. data/ext/window/window.h +4 -4
  77. data/ext/window/window_base.c +251 -0
  78. data/ext/window/window_base.h +43 -0
  79. data/ext/window/window_base.inc +236 -0
  80. data/lib/sfml/version.rb +1 -1
  81. data/sig/audio/audio_enums.rbs +30 -0
  82. data/sig/audio/listener.rbs +16 -0
  83. data/sig/audio/music.rbs +56 -0
  84. data/sig/audio/sound.rbs +51 -0
  85. data/sig/audio/sound_buffer.rbs +17 -0
  86. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  87. data/sig/audio/sound_recorder.rbs +17 -0
  88. data/sig/audio/sound_source_cone.rbs +14 -0
  89. data/sig/audio/sound_stream.rbs +51 -0
  90. data/sig/graphics/blend_mode.rbs +29 -0
  91. data/sig/graphics/circle.rbs +44 -0
  92. data/sig/graphics/color.rbs +39 -0
  93. data/sig/graphics/drawable.rbs +5 -0
  94. data/sig/graphics/font.rbs +20 -0
  95. data/sig/graphics/glyph.rbs +7 -0
  96. data/sig/graphics/image.rbs +22 -0
  97. data/sig/graphics/polygon.rbs +42 -0
  98. data/sig/graphics/rect.rbs +33 -0
  99. data/sig/graphics/rectangle.rbs +42 -0
  100. data/sig/graphics/render_state.rbs +21 -0
  101. data/sig/graphics/render_target.rbs +18 -0
  102. data/sig/graphics/render_texture.rbs +39 -0
  103. data/sig/graphics/render_window.rbs +7 -0
  104. data/sig/graphics/shader.rbs +39 -0
  105. data/sig/graphics/shape.rbs +38 -0
  106. data/sig/graphics/sprite.rbs +34 -0
  107. data/sig/graphics/stencil_mode.rbs +18 -0
  108. data/sig/graphics/target.rbs +8 -0
  109. data/sig/graphics/text.rbs +48 -0
  110. data/sig/graphics/texture.rbs +34 -0
  111. data/sig/graphics/transform.rbs +37 -0
  112. data/sig/graphics/transformable.rbs +25 -0
  113. data/sig/graphics/vertex.rbs +17 -0
  114. data/sig/graphics/vertex_array.rbs +17 -0
  115. data/sig/graphics/vertex_buffer.rbs +22 -0
  116. data/sig/graphics/view.rbs +23 -0
  117. data/sig/network/ftp.rbs +46 -0
  118. data/sig/network/http.rbs +27 -0
  119. data/sig/network/ip_address.rbs +22 -0
  120. data/sig/network/network_enums.rbs +95 -0
  121. data/sig/network/packet.rbs +40 -0
  122. data/sig/network/socket_selector.rbs +14 -0
  123. data/sig/network/tcp_listener.rbs +13 -0
  124. data/sig/network/tcp_socket.rbs +18 -0
  125. data/sig/network/udp_socket.rbs +17 -0
  126. data/sig/sfml/version.rbs +3 -0
  127. data/sig/system/buffer.rbs +11 -0
  128. data/sig/system/clock.rbs +13 -0
  129. data/sig/system/input_stream.rbs +7 -0
  130. data/sig/system/sleep.rbs +3 -0
  131. data/sig/system/time.rbs +28 -0
  132. data/sig/system/vec2.rbs +26 -0
  133. data/sig/system/vec3.rbs +27 -0
  134. data/sig/window/clipboard.rbs +8 -0
  135. data/sig/window/context.rbs +11 -0
  136. data/sig/window/context_settings.rbs +20 -0
  137. data/sig/window/cursor.rbs +6 -0
  138. data/sig/window/event.rbs +20 -0
  139. data/sig/window/joystick.rbs +15 -0
  140. data/sig/window/keyboard.rbs +10 -0
  141. data/sig/window/mouse.rbs +9 -0
  142. data/sig/window/sensor.rbs +8 -0
  143. data/sig/window/touch.rbs +6 -0
  144. data/sig/window/video_mode.rbs +16 -0
  145. data/sig/window/vulkan.rbs +7 -0
  146. data/sig/window/window.rbs +34 -0
  147. data/sig/window/window_base.rbs +33 -0
  148. metadata +76 -3
@@ -13,27 +13,25 @@ typedef struct {
13
13
 
14
14
  static VALUE rb_cBlendMode;
15
15
 
16
- static const char *factor_names[] = {
17
- "zero", "one", "src_color", "one_minus_src_color", "dst_color",
18
- "one_minus_dst_color", "src_alpha", "one_minus_src_alpha", "dst_alpha", "one_minus_dst_alpha"
19
- };
16
+ static const char* factor_names[] = {"zero", "one",
17
+ "src_color", "one_minus_src_color",
18
+ "dst_color", "one_minus_dst_color",
19
+ "src_alpha", "one_minus_src_alpha",
20
+ "dst_alpha", "one_minus_dst_alpha"};
20
21
 
21
- static const char *equation_names[] = {
22
- "add", "subtract", "reverse_subtract", "min", "max"
23
- };
22
+ static const char* equation_names[] = {"add", "subtract", "reverse_subtract", "min", "max"};
24
23
 
25
- static void BlendMode_free(void *ptr) {
24
+ static void BlendMode_free(void* ptr) {
26
25
  free(ptr);
27
26
  }
28
27
 
29
28
  static const rb_data_type_t BlendMode_data_type = {
30
29
  .wrap_struct_name = "SFML::BlendMode",
31
30
  .function = {.dmark = NULL, .dfree = BlendMode_free, .dsize = NULL},
32
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
33
- };
31
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
34
32
 
35
33
  static VALUE BlendMode_wrap(sfBlendMode mode) {
36
- BlendMode *ptr = malloc(sizeof(BlendMode));
34
+ BlendMode* ptr = malloc(sizeof(BlendMode));
37
35
 
38
36
  ptr->mode = mode;
39
37
 
@@ -44,15 +42,15 @@ static sfBlendFactor factor_from_rb(VALUE rb_factor) {
44
42
  size_t i;
45
43
 
46
44
  if (RB_INTEGER_TYPE_P(rb_factor)) {
47
- return (sfBlendFactor) NUM2INT(rb_factor);
45
+ return (sfBlendFactor)NUM2INT(rb_factor);
48
46
  }
49
47
 
50
48
  if (SYMBOL_P(rb_factor)) {
51
- const char *name = rb_id2name(SYM2ID(rb_factor));
49
+ const char* name = rb_id2name(SYM2ID(rb_factor));
52
50
 
53
51
  for (i = 0; i < sizeof(factor_names) / sizeof(factor_names[0]); i++) {
54
52
  if (strcmp(name, factor_names[i]) == 0) {
55
- return (sfBlendFactor) i;
53
+ return (sfBlendFactor)i;
56
54
  }
57
55
  }
58
56
  }
@@ -65,15 +63,15 @@ static sfBlendEquation equation_from_rb(VALUE rb_equation) {
65
63
  size_t i;
66
64
 
67
65
  if (RB_INTEGER_TYPE_P(rb_equation)) {
68
- return (sfBlendEquation) NUM2INT(rb_equation);
66
+ return (sfBlendEquation)NUM2INT(rb_equation);
69
67
  }
70
68
 
71
69
  if (SYMBOL_P(rb_equation)) {
72
- const char *name = rb_id2name(SYM2ID(rb_equation));
70
+ const char* name = rb_id2name(SYM2ID(rb_equation));
73
71
 
74
72
  for (i = 0; i < sizeof(equation_names) / sizeof(equation_names[0]); i++) {
75
73
  if (strcmp(name, equation_names[i]) == 0) {
76
- return (sfBlendEquation) i;
74
+ return (sfBlendEquation)i;
77
75
  }
78
76
  }
79
77
  }
@@ -82,105 +80,245 @@ static sfBlendEquation equation_from_rb(VALUE rb_equation) {
82
80
  return sfBlendEquationAdd;
83
81
  }
84
82
 
85
- static VALUE BlendMode_new(int argc, VALUE *argv, VALUE klass) {
86
- VALUE self;
87
- BlendMode *ptr;
83
+ static VALUE BlendMode_alloc(VALUE klass) {
84
+ BlendMode* ptr = malloc(sizeof(BlendMode));
85
+
86
+ if (ptr == NULL) {
87
+ rb_raise(rb_eNoMemError, "failed to allocate blend mode");
88
+ }
89
+
90
+ ptr->mode = sfBlendAlpha;
91
+
92
+ return TypedData_Wrap_Struct(klass, &BlendMode_data_type, ptr);
93
+ }
94
+
95
+ /* call-seq:
96
+ * BlendMode.new -> BlendMode(ALPHA)
97
+ * BlendMode.new(color_src_factor, color_dst_factor, color_equation, alpha_src_factor,
98
+ * alpha_dst_factor, alpha_equation) -> BlendMode
99
+ *
100
+ * Each factor argument is a Symbol (one of +:zero+, +:one+, +:src_color+,
101
+ * +:one_minus_src_color+, +:dst_color+, +:one_minus_dst_color+,
102
+ * +:src_alpha+, +:one_minus_src_alpha+, +:dst_alpha+,
103
+ * +:one_minus_dst_alpha+) or the equivalent Integer. Each equation argument
104
+ * is a Symbol (+:add+, +:subtract+, +:reverse_subtract+, +:min+, +:max+) or
105
+ * the equivalent Integer.
106
+ *
107
+ * @return [BlendMode]
108
+ * @raise [ArgumentError] if given an argument count other than 0 or 6
109
+ */
110
+ static VALUE BlendMode_initialize(int argc, VALUE* argv, VALUE self) {
88
111
  sfBlendMode mode = sfBlendAlpha;
89
112
 
90
113
  if (argc == 6) {
91
- mode = (sfBlendMode) {
92
- factor_from_rb(argv[0]), factor_from_rb(argv[1]), equation_from_rb(argv[2]),
93
- factor_from_rb(argv[3]), factor_from_rb(argv[4]), equation_from_rb(argv[5])
94
- };
114
+ mode = (sfBlendMode){factor_from_rb(argv[0]), factor_from_rb(argv[1]),
115
+ equation_from_rb(argv[2]), factor_from_rb(argv[3]),
116
+ factor_from_rb(argv[4]), equation_from_rb(argv[5])};
95
117
  } else if (argc != 0) {
96
118
  raise_invalid_arguments_excepted(6, argc);
97
119
  }
98
120
 
99
- ptr = malloc(sizeof(BlendMode));
100
- ptr->mode = mode;
101
-
102
- self = TypedData_Wrap_Struct(klass, &BlendMode_data_type, ptr);
121
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode = mode;
103
122
 
104
123
  return self;
105
124
  }
106
125
 
126
+ /* call-seq: color_src_factor -> Symbol
127
+ *
128
+ * Returns the source blend factor for color components.
129
+ *
130
+ * @return [Symbol] the source blending factor for the color/RGB channels
131
+ */
107
132
  static VALUE BlendMode_get_color_src_factor(VALUE self) {
108
- return ID2SYM(rb_intern(factor_names[((BlendMode *) Get_BlendMode_Struct(self))->mode.colorSrcFactor]));
133
+ return ID2SYM(
134
+ rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.colorSrcFactor]));
109
135
  }
110
136
 
137
+ /* call-seq: color_dst_factor -> Symbol
138
+ *
139
+ * Returns the destination blend factor for color components.
140
+ *
141
+ * @return [Symbol] the destination blending factor for the color/RGB channels
142
+ */
111
143
  static VALUE BlendMode_get_color_dst_factor(VALUE self) {
112
- return ID2SYM(rb_intern(factor_names[((BlendMode *) Get_BlendMode_Struct(self))->mode.colorDstFactor]));
144
+ return ID2SYM(
145
+ rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.colorDstFactor]));
113
146
  }
114
147
 
148
+ /* call-seq: color_equation -> Symbol
149
+ *
150
+ * Returns the blend equation for color components.
151
+ *
152
+ * @return [Symbol] the blending equation for the color/RGB channels
153
+ */
115
154
  static VALUE BlendMode_get_color_equation(VALUE self) {
116
- return ID2SYM(rb_intern(equation_names[((BlendMode *) Get_BlendMode_Struct(self))->mode.colorEquation]));
155
+ return ID2SYM(
156
+ rb_intern(equation_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.colorEquation]));
117
157
  }
118
158
 
159
+ /* call-seq: alpha_src_factor -> Symbol
160
+ *
161
+ * Returns the source blend factor for alpha.
162
+ *
163
+ * @return [Symbol] the source blending factor for the alpha channel
164
+ */
119
165
  static VALUE BlendMode_get_alpha_src_factor(VALUE self) {
120
- return ID2SYM(rb_intern(factor_names[((BlendMode *) Get_BlendMode_Struct(self))->mode.alphaSrcFactor]));
166
+ return ID2SYM(
167
+ rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaSrcFactor]));
121
168
  }
122
169
 
170
+ /* call-seq: alpha_dst_factor -> Symbol
171
+ *
172
+ * Returns the destination blend factor for alpha.
173
+ *
174
+ * @return [Symbol] the destination blending factor for the alpha channel
175
+ */
123
176
  static VALUE BlendMode_get_alpha_dst_factor(VALUE self) {
124
- return ID2SYM(rb_intern(factor_names[((BlendMode *) Get_BlendMode_Struct(self))->mode.alphaDstFactor]));
177
+ return ID2SYM(
178
+ rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaDstFactor]));
125
179
  }
126
180
 
181
+ /* call-seq: alpha_equation -> Symbol
182
+ *
183
+ * Returns the blend equation for alpha.
184
+ *
185
+ * @return [Symbol] the blending equation for the alpha channel
186
+ */
127
187
  static VALUE BlendMode_get_alpha_equation(VALUE self) {
128
- return ID2SYM(rb_intern(equation_names[((BlendMode *) Get_BlendMode_Struct(self))->mode.alphaEquation]));
188
+ return ID2SYM(
189
+ rb_intern(equation_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaEquation]));
129
190
  }
130
191
 
192
+ /* call-seq:
193
+ * color_src_factor=(value) -> Symbol
194
+ *
195
+ * Sets the source blend factor for color components.
196
+ *
197
+ * @return [Symbol] +value+
198
+ */
131
199
  static VALUE BlendMode_set_color_src_factor(VALUE self, VALUE rb_value) {
132
- ((BlendMode *) Get_BlendMode_Struct(self))->mode.colorSrcFactor = factor_from_rb(rb_value);
200
+ rb_check_frozen(self);
201
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode.colorSrcFactor = factor_from_rb(rb_value);
133
202
  return rb_value;
134
203
  }
135
204
 
205
+ /* call-seq:
206
+ * color_dst_factor=(value) -> Symbol
207
+ *
208
+ * Sets the destination blend factor for color components.
209
+ *
210
+ * @return [Symbol] +value+
211
+ */
136
212
  static VALUE BlendMode_set_color_dst_factor(VALUE self, VALUE rb_value) {
137
- ((BlendMode *) Get_BlendMode_Struct(self))->mode.colorDstFactor = factor_from_rb(rb_value);
213
+ rb_check_frozen(self);
214
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode.colorDstFactor = factor_from_rb(rb_value);
138
215
  return rb_value;
139
216
  }
140
217
 
218
+ /* call-seq:
219
+ * color_equation=(value) -> Symbol
220
+ *
221
+ * Sets the blend equation for color components.
222
+ *
223
+ * @return [Symbol] +value+
224
+ */
141
225
  static VALUE BlendMode_set_color_equation(VALUE self, VALUE rb_value) {
142
- ((BlendMode *) Get_BlendMode_Struct(self))->mode.colorEquation = equation_from_rb(rb_value);
226
+ rb_check_frozen(self);
227
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode.colorEquation = equation_from_rb(rb_value);
143
228
  return rb_value;
144
229
  }
145
230
 
231
+ /* call-seq:
232
+ * alpha_src_factor=(value) -> Symbol
233
+ *
234
+ * Sets the source blend factor for alpha.
235
+ *
236
+ * @return [Symbol] +value+
237
+ */
146
238
  static VALUE BlendMode_set_alpha_src_factor(VALUE self, VALUE rb_value) {
147
- ((BlendMode *) Get_BlendMode_Struct(self))->mode.alphaSrcFactor = factor_from_rb(rb_value);
239
+ rb_check_frozen(self);
240
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaSrcFactor = factor_from_rb(rb_value);
148
241
  return rb_value;
149
242
  }
150
243
 
244
+ /* call-seq:
245
+ * alpha_dst_factor=(value) -> Symbol
246
+ *
247
+ * Sets the destination blend factor for alpha.
248
+ *
249
+ * @return [Symbol] +value+
250
+ */
151
251
  static VALUE BlendMode_set_alpha_dst_factor(VALUE self, VALUE rb_value) {
152
- ((BlendMode *) Get_BlendMode_Struct(self))->mode.alphaDstFactor = factor_from_rb(rb_value);
252
+ rb_check_frozen(self);
253
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaDstFactor = factor_from_rb(rb_value);
153
254
  return rb_value;
154
255
  }
155
256
 
257
+ /* call-seq:
258
+ * alpha_equation=(value) -> Symbol
259
+ *
260
+ * Sets the blend equation for alpha.
261
+ *
262
+ * @return [Symbol] +value+
263
+ */
156
264
  static VALUE BlendMode_set_alpha_equation(VALUE self, VALUE rb_value) {
157
- ((BlendMode *) Get_BlendMode_Struct(self))->mode.alphaEquation = equation_from_rb(rb_value);
265
+ rb_check_frozen(self);
266
+ ((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaEquation = equation_from_rb(rb_value);
158
267
  return rb_value;
159
268
  }
160
269
 
270
+ /* call-seq:
271
+ * self == other -> true or false
272
+ *
273
+ * Returns +true+ if the two objects are equal.
274
+ *
275
+ * @return [Boolean]
276
+ */
161
277
  static VALUE BlendMode_eql(VALUE self, VALUE rb_other) {
162
- sfBlendMode a = ((BlendMode *) Get_BlendMode_Struct(self))->mode;
278
+ sfBlendMode a = ((BlendMode*)Get_BlendMode_Struct(self))->mode;
163
279
  sfBlendMode b;
164
280
 
165
281
  if (!rb_obj_is_kind_of(rb_other, rb_cBlendMode)) {
166
282
  return Qfalse;
167
283
  }
168
284
 
169
- b = ((BlendMode *) Get_BlendMode_Struct(rb_other))->mode;
285
+ b = ((BlendMode*)Get_BlendMode_Struct(rb_other))->mode;
170
286
 
171
287
  return BOOL2RB(a.colorSrcFactor == b.colorSrcFactor && a.colorDstFactor == b.colorDstFactor &&
172
288
  a.colorEquation == b.colorEquation && a.alphaSrcFactor == b.alphaSrcFactor &&
173
289
  a.alphaDstFactor == b.alphaDstFactor && a.alphaEquation == b.alphaEquation);
174
290
  }
175
291
 
176
- static void BlendMode_define_const(VALUE klass, const char *name, sfBlendMode mode) {
177
- rb_define_const(klass, name, BlendMode_wrap(mode));
178
- }
179
-
180
- void Init_BlendMode(VALUE rb_module) {
181
- rb_cBlendMode = rb_define_class_under(rb_module, "BlendMode", rb_cObject);
182
-
183
- rb_define_singleton_method(rb_cBlendMode, "new", BlendMode_new, -1);
292
+ /* Document-class: SFML::BlendMode
293
+ * Describes how the colors of a drawn object are combined with the colors
294
+ * already in the render target, via two triples of (source factor,
295
+ * destination factor, equation) -- one for the color/RGB channels, one for
296
+ * the alpha channel.
297
+ *
298
+ * @!attribute color_src_factor
299
+ * The source blend factor for color components.
300
+ * @return [Symbol] the source blending factor for the color channels
301
+ * @!attribute color_dst_factor
302
+ * The destination blend factor for color components.
303
+ * @return [Symbol] the destination blending factor for the color channels
304
+ * @!attribute color_equation
305
+ * The blend equation for color components.
306
+ * @return [Symbol] the blending equation for the color channels
307
+ * @!attribute alpha_src_factor
308
+ * The source blend factor for alpha.
309
+ * @return [Symbol] the source blending factor for the alpha channel
310
+ * @!attribute alpha_dst_factor
311
+ * The destination blend factor for alpha.
312
+ * @return [Symbol] the destination blending factor for the alpha channel
313
+ * @!attribute alpha_equation
314
+ * The blend equation for alpha.
315
+ * @return [Symbol] the blending equation for the alpha channel
316
+ */
317
+ void Init_BlendMode(VALUE rb_mSFML) {
318
+ rb_cBlendMode = rb_define_class_under(rb_mSFML, "BlendMode", rb_cObject);
319
+
320
+ rb_define_alloc_func(rb_cBlendMode, BlendMode_alloc);
321
+ rb_define_method(rb_cBlendMode, "initialize", BlendMode_initialize, -1);
184
322
 
185
323
  rb_define_method(rb_cBlendMode, "color_src_factor", BlendMode_get_color_src_factor, 0);
186
324
  rb_define_method(rb_cBlendMode, "color_dst_factor", BlendMode_get_color_dst_factor, 0);
@@ -198,27 +336,47 @@ void Init_BlendMode(VALUE rb_module) {
198
336
 
199
337
  rb_define_method(rb_cBlendMode, "==", BlendMode_eql, 1);
200
338
 
201
- BlendMode_define_const(rb_cBlendMode, "NONE", sfBlendNone);
202
- BlendMode_define_const(rb_cBlendMode, "ALPHA", sfBlendAlpha);
203
- BlendMode_define_const(rb_cBlendMode, "ADD", sfBlendAdd);
204
- BlendMode_define_const(rb_cBlendMode, "MULTIPLY", sfBlendMultiply);
205
- BlendMode_define_const(rb_cBlendMode, "MIN", sfBlendMin);
206
- BlendMode_define_const(rb_cBlendMode, "MAX", sfBlendMax);
339
+ /* No blending: source pixels overwrite destination pixels unchanged
340
+ * (One, Zero, Add for both the color and alpha channels). */
341
+ rb_define_const(rb_cBlendMode, "NONE", rb_obj_freeze(BlendMode_wrap(sfBlendNone)));
342
+
343
+ /* Standard alpha blending: the source is blended over the destination
344
+ * using the source alpha (SrcAlpha, OneMinusSrcAlpha, Add for color;
345
+ * One, OneMinusSrcAlpha, Add for alpha). The default blend mode. */
346
+ rb_define_const(rb_cBlendMode, "ALPHA", rb_obj_freeze(BlendMode_wrap(sfBlendAlpha)));
347
+
348
+ /* Additive blending: the source color, scaled by its alpha, is added to
349
+ * the destination (SrcAlpha, One, Add for color; One, One, Add for
350
+ * alpha). */
351
+ rb_define_const(rb_cBlendMode, "ADD", rb_obj_freeze(BlendMode_wrap(sfBlendAdd)));
352
+
353
+ /* Multiplicative blending: source and destination colors are multiplied
354
+ * together (DstColor, Zero, Add for both the color and alpha
355
+ * channels). */
356
+ rb_define_const(rb_cBlendMode, "MULTIPLY", rb_obj_freeze(BlendMode_wrap(sfBlendMultiply)));
357
+
358
+ /* Component-wise minimum of the source and destination colors (One,
359
+ * One, Min for both the color and alpha channels). */
360
+ rb_define_const(rb_cBlendMode, "MIN", rb_obj_freeze(BlendMode_wrap(sfBlendMin)));
361
+
362
+ /* Component-wise maximum of the source and destination colors (One,
363
+ * One, Max for both the color and alpha channels). */
364
+ rb_define_const(rb_cBlendMode, "MAX", rb_obj_freeze(BlendMode_wrap(sfBlendMax)));
207
365
  }
208
366
 
209
367
  VALUE Get_Klass_BlendMode(void) {
210
368
  return rb_cBlendMode;
211
369
  }
212
370
 
213
- void *Get_BlendMode_Struct(VALUE self) {
214
- BlendMode *ptr;
371
+ void* Get_BlendMode_Struct(VALUE self) {
372
+ BlendMode* ptr;
215
373
  TypedData_Get_Struct(self, BlendMode, &BlendMode_data_type, ptr);
216
374
  return ptr;
217
375
  }
218
376
 
219
377
  sfBlendMode blend_mode_from_rb(VALUE rb_mode) {
220
378
  if (rb_obj_is_kind_of(rb_mode, rb_cBlendMode)) {
221
- return ((BlendMode *) Get_BlendMode_Struct(rb_mode))->mode;
379
+ return ((BlendMode*)Get_BlendMode_Struct(rb_mode))->mode;
222
380
  }
223
381
 
224
382
  if (RB_INTEGER_TYPE_P(rb_mode) == 0 && !SYMBOL_P(rb_mode)) {
@@ -226,7 +384,7 @@ sfBlendMode blend_mode_from_rb(VALUE rb_mode) {
226
384
  }
227
385
 
228
386
  if (SYMBOL_P(rb_mode)) {
229
- const char *name = rb_id2name(SYM2ID(rb_mode));
387
+ const char* name = rb_id2name(SYM2ID(rb_mode));
230
388
 
231
389
  if (strcmp(name, "none") == 0) {
232
390
  return sfBlendNone;