sfml3-rb 0.2.2 → 0.3.0

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