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
@@ -14,17 +14,16 @@
14
14
 
15
15
  static VALUE rb_cVertexArray;
16
16
 
17
- static void VertexArray_free(void *ptr) {
17
+ static void VertexArray_free(void* ptr) {
18
18
  sfVertexArray_destroy(ptr);
19
19
  }
20
20
 
21
21
  static const rb_data_type_t VertexArray_data_type = {
22
22
  .wrap_struct_name = "SFML::VertexArray",
23
23
  .function = {.dmark = NULL, .dfree = VertexArray_free, .dsize = NULL},
24
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
25
- };
24
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
26
25
 
27
- static VALUE VertexArray_wrap(VALUE klass, sfVertexArray *array) {
26
+ static VALUE VertexArray_wrap(VALUE klass, sfVertexArray* array) {
28
27
  if (array == NULL) {
29
28
  rb_raise(rb_eRuntimeError, "failed to create vertex array");
30
29
  }
@@ -32,61 +31,163 @@ static VALUE VertexArray_wrap(VALUE klass, sfVertexArray *array) {
32
31
  return TypedData_Wrap_Struct(klass, &VertexArray_data_type, array);
33
32
  }
34
33
 
35
- static sfVertexArray *Get_VertexArray_Struct(VALUE self) {
36
- sfVertexArray *ptr;
34
+ static sfVertexArray* Get_VertexArray_Struct(VALUE self) {
35
+ sfVertexArray* ptr;
37
36
  TypedData_Get_Struct(self, sfVertexArray, &VertexArray_data_type, ptr);
38
37
  return ptr;
39
38
  }
40
39
 
40
+ /* call-seq:
41
+ * VertexArray.new -> VertexArray
42
+ *
43
+ * Creates a vertex array using the given +primitive+ type.
44
+ *
45
+ * @return [VertexArray] an empty array of :points primitives
46
+ */
41
47
  static VALUE VertexArray_new(VALUE klass) {
42
48
  return VertexArray_wrap(klass, sfVertexArray_create());
43
49
  }
44
50
 
51
+ /* call-seq: copy -> VertexArray
52
+ *
53
+ * Returns a deep copy of the object.
54
+ *
55
+ * @return [VertexArray] an independent copy
56
+ */
45
57
  static VALUE VertexArray_copy(VALUE self) {
46
- return VertexArray_wrap(Get_Klass_VertexArray(), sfVertexArray_copy(Get_VertexArray_Struct(self)));
58
+ return VertexArray_wrap(Get_Klass_VertexArray(),
59
+ sfVertexArray_copy(Get_VertexArray_Struct(self)));
47
60
  }
48
61
 
62
+ /* call-seq: vertex_count -> Integer
63
+ *
64
+ * Returns the number of vertices stored.
65
+ *
66
+ * @return [Integer]
67
+ */
49
68
  static VALUE VertexArray_get_vertex_count(VALUE self) {
50
69
  return SIZET2NUM(sfVertexArray_getVertexCount(Get_VertexArray_Struct(self)));
51
70
  }
52
71
 
53
- static VALUE VertexArray_get_vertex(VALUE self, VALUE rb_index) {
54
- return vertex_to_rb(*sfVertexArray_getVertex(Get_VertexArray_Struct(self), (size_t) NUM2SIZET(rb_index)));
72
+ static size_t VertexArray_check_index(VALUE self, VALUE rb_index) {
73
+ void* array = Get_VertexArray_Struct(self);
74
+ size_t index = (size_t)NUM2SIZET(rb_index);
75
+ size_t count = sfVertexArray_getVertexCount(array);
76
+
77
+ if (index >= count) {
78
+ rb_raise(rb_eIndexError, "index %zu outside of vertex count %zu", index, count);
79
+ }
80
+
81
+ return index;
55
82
  }
56
83
 
84
+ /* call-seq:
85
+ * vertex(index) -> Vertex
86
+ *
87
+ * Returns the vertex at +index+.
88
+ *
89
+ * @return [Vertex] a copy of the vertex at +index+
90
+ * @raise [IndexError] if +index+ is out of range
91
+ */
92
+ static VALUE VertexArray_get_vertex(VALUE self, VALUE rb_index) {
93
+ return vertex_to_rb(*sfVertexArray_getVertex(Get_VertexArray_Struct(self),
94
+ VertexArray_check_index(self, rb_index)));
95
+ }
96
+
97
+ /* call-seq:
98
+ * set_vertex(index, vertex) -> Vertex
99
+ *
100
+ * Replaces the vertex at +index+ with +vertex+.
101
+ *
102
+ * @return [Vertex] +vertex+
103
+ * @raise [IndexError] if +index+ is out of range
104
+ */
57
105
  static VALUE VertexArray_set_vertex(VALUE self, VALUE rb_index, VALUE rb_vertex) {
58
- *sfVertexArray_getVertex(Get_VertexArray_Struct(self), (size_t) NUM2SIZET(rb_index)) = vertex_from_rb(rb_vertex);
106
+ *sfVertexArray_getVertex(Get_VertexArray_Struct(self),
107
+ VertexArray_check_index(self, rb_index)) = vertex_from_rb(rb_vertex);
59
108
  return rb_vertex;
60
109
  }
61
110
 
111
+ /* call-seq:
112
+ * append(vertex) -> self
113
+ *
114
+ * Appends +vertex+ to the array.
115
+ *
116
+ * @return [self]
117
+ */
62
118
  static VALUE VertexArray_append(VALUE self, VALUE rb_vertex) {
63
119
  sfVertexArray_append(Get_VertexArray_Struct(self), vertex_from_rb(rb_vertex));
64
120
  return self;
65
121
  }
66
122
 
123
+ /* call-seq: clear! -> self
124
+ *
125
+ * Removes all vertices.
126
+ *
127
+ * @return [self]
128
+ */
67
129
  static VALUE VertexArray_clear(VALUE self) {
68
130
  sfVertexArray_clear(Get_VertexArray_Struct(self));
69
131
  return self;
70
132
  }
71
133
 
134
+ /* call-seq:
135
+ * resize(count) -> self
136
+ *
137
+ * Grows or shrinks the array to +count+ vertices; new vertices are default
138
+ * ones.
139
+ *
140
+ * @return [self]
141
+ */
72
142
  static VALUE VertexArray_resize(VALUE self, VALUE rb_count) {
73
- sfVertexArray_resize(Get_VertexArray_Struct(self), (size_t) NUM2SIZET(rb_count));
143
+ sfVertexArray_resize(Get_VertexArray_Struct(self), (size_t)NUM2SIZET(rb_count));
74
144
  return self;
75
145
  }
76
146
 
147
+ /* call-seq: primitive -> Symbol
148
+ *
149
+ * Returns the primitive type used to draw the vertices.
150
+ *
151
+ * @return [Symbol] the primitive type vertices are interpreted as (e.g.
152
+ * :points, :lines, :triangles)
153
+ */
77
154
  static VALUE VertexArray_get_primitive_type(VALUE self) {
78
- return ID2SYM(rb_intern(primitive_type_name(sfVertexArray_getPrimitiveType(Get_VertexArray_Struct(self)))));
155
+ return ID2SYM(rb_intern(
156
+ primitive_type_name(sfVertexArray_getPrimitiveType(Get_VertexArray_Struct(self)))));
79
157
  }
80
158
 
159
+ /* call-seq:
160
+ * primitive=(value) -> Symbol
161
+ *
162
+ * Sets the primitive type used to draw the vertices.
163
+ *
164
+ * @return [Symbol] +value+
165
+ */
81
166
  static VALUE VertexArray_set_primitive_type(VALUE self, VALUE rb_type) {
82
167
  sfVertexArray_setPrimitiveType(Get_VertexArray_Struct(self), primitive_type_from_rb(rb_type));
83
168
  return rb_type;
84
169
  }
85
170
 
171
+ /* call-seq: bounds -> Rect
172
+ *
173
+ * Returns the axis-aligned bounding box of all vertices.
174
+ *
175
+ * @return [Rect] the axis-aligned bounding box of all vertices
176
+ */
86
177
  static VALUE VertexArray_get_bounds(VALUE self) {
87
178
  return rect_to_rb(sfVertexArray_getBounds(Get_VertexArray_Struct(self)));
88
179
  }
89
180
 
181
+ /* call-seq:
182
+ * draw(target, state) -> nil
183
+ *
184
+ * Part of the Drawable interface; call Target#draw instead of this
185
+ * directly.
186
+ *
187
+ * @return [nil]
188
+ * @raise [TypeError] if +target+ is not a Target or +state+ is not a
189
+ * RenderState
190
+ */
90
191
  static VALUE VertexArray_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
91
192
  if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
92
193
  raise_invalid_argument_class(Get_Klass_Target());
@@ -96,14 +197,25 @@ static VALUE VertexArray_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
96
197
  raise_invalid_argument_class(Get_Klass_RenderState());
97
198
  }
98
199
 
99
- TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawVertexArray, sfRenderTexture_drawVertexArray,
100
- Get_VertexArray_Struct(self), Get_RenderState_Struct(rb_state));
200
+ TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawVertexArray,
201
+ sfRenderTexture_drawVertexArray, Get_VertexArray_Struct(self),
202
+ Get_RenderState_Struct(rb_state));
101
203
 
102
204
  return Qnil;
103
205
  }
104
206
 
105
- void Init_VertexArray(VALUE rb_module) {
106
- rb_cVertexArray = rb_define_class_under(rb_module, "VertexArray", rb_cObject);
207
+ /* Document-class: SFML::VertexArray
208
+ * A resizable, drawable set of Vertex objects interpreted as a given
209
+ * primitive type (points, lines, triangles, ...).
210
+ *
211
+ * Includes +Drawable+.
212
+ *
213
+ * @!attribute primitive
214
+ * The primitive type used to draw the vertices.
215
+ * @return [Symbol]
216
+ */
217
+ void Init_VertexArray(VALUE rb_mSFML) {
218
+ rb_cVertexArray = rb_define_class_under(rb_mSFML, "VertexArray", rb_cObject);
107
219
 
108
220
  rb_include_module(rb_cVertexArray, Get_Module_Drawable());
109
221
 
@@ -60,6 +60,20 @@ static sfVertexBufferUsage usage_from_rb(VALUE rb_usage) {
60
60
  return sfVertexBufferStatic;
61
61
  }
62
62
 
63
+ /* call-seq:
64
+ * VertexBuffer.new -> VertexBuffer
65
+ * VertexBuffer.new(count) -> VertexBuffer
66
+ * VertexBuffer.new(count, primitive) -> VertexBuffer
67
+ * VertexBuffer.new(count, primitive, usage) -> VertexBuffer
68
+ *
69
+ * Creates a GPU-side vertex buffer holding +count+ vertices (default 0),
70
+ * interpreted as +primitive+ (default :points, see VertexArray#primitive),
71
+ * with the given +usage+ hint (one of :stream, :dynamic, :static; default
72
+ * :static).
73
+ *
74
+ * @return [VertexBuffer]
75
+ * @raise [RuntimeError] if creation fails
76
+ */
63
77
  static VALUE VertexBuffer_new(int argc, VALUE* argv, VALUE klass) {
64
78
  VALUE rb_count, rb_primitive, rb_usage;
65
79
  size_t count = 0;
@@ -83,15 +97,37 @@ static VALUE VertexBuffer_new(int argc, VALUE* argv, VALUE klass) {
83
97
  return VertexBuffer_wrap(klass, sfVertexBuffer_create(count, primitive, usage));
84
98
  }
85
99
 
100
+ /* call-seq: copy -> VertexBuffer
101
+ *
102
+ * Returns a deep copy of the object.
103
+ *
104
+ * @return [VertexBuffer] an independent copy
105
+ */
86
106
  static VALUE VertexBuffer_copy(VALUE self) {
87
107
  return VertexBuffer_wrap(Get_Klass_VertexBuffer(),
88
108
  sfVertexBuffer_copy(Get_VertexBuffer_Struct(self)));
89
109
  }
90
110
 
111
+ /* call-seq: vertex_count -> Integer
112
+ *
113
+ * Returns the number of vertices stored.
114
+ *
115
+ * @return [Integer]
116
+ */
91
117
  static VALUE VertexBuffer_get_vertex_count(VALUE self) {
92
118
  return SIZET2NUM(sfVertexBuffer_getVertexCount(Get_VertexBuffer_Struct(self)));
93
119
  }
94
120
 
121
+ /* call-seq:
122
+ * update(vertices) -> true or false
123
+ * update(vertices, offset) -> true or false
124
+ *
125
+ * Uploads +vertices+ (an Array of Vertex, or of anything Vertex.new
126
+ * accepts) into the buffer starting at +offset+ (default 0). The buffer
127
+ * must have enough room; use #resize (via .new) if not.
128
+ *
129
+ * @return [Boolean] whether the update succeeded
130
+ */
95
131
  static VALUE VertexBuffer_update(int argc, VALUE* argv, VALUE self) {
96
132
  VALUE rb_vertices, rb_offset;
97
133
  unsigned int offset = 0;
@@ -115,6 +151,15 @@ static VALUE VertexBuffer_update(int argc, VALUE* argv, VALUE self) {
115
151
  return BOOL2RB(result);
116
152
  }
117
153
 
154
+ /* call-seq:
155
+ * update_from(other) -> true or false
156
+ *
157
+ * Copies the contents of +other+ (a VertexBuffer of the same vertex count)
158
+ * into this buffer.
159
+ *
160
+ * @return [Boolean] whether the update succeeded
161
+ * @raise [TypeError] if +other+ is not a VertexBuffer
162
+ */
118
163
  static VALUE VertexBuffer_update_from(VALUE self, VALUE rb_other) {
119
164
  if (!rb_obj_is_kind_of(rb_other, rb_cVertexBuffer)) {
120
165
  raise_invalid_argument_class(rb_cVertexBuffer);
@@ -126,6 +171,14 @@ static VALUE VertexBuffer_update_from(VALUE self, VALUE rb_other) {
126
171
 
127
172
  /* Exchanges the two buffers' contents in place, so anything already holding
128
173
  either object sees the swap. */
174
+ /* call-seq:
175
+ * swap(other) -> self
176
+ *
177
+ * Swaps the contents with +other+.
178
+ *
179
+ * @return [self]
180
+ * @raise [TypeError] if +other+ is not a VertexBuffer
181
+ */
129
182
  static VALUE VertexBuffer_swap(VALUE self, VALUE rb_other) {
130
183
  if (!rb_obj_is_kind_of(rb_other, rb_cVertexBuffer)) {
131
184
  raise_invalid_argument_class(rb_cVertexBuffer);
@@ -136,38 +189,93 @@ static VALUE VertexBuffer_swap(VALUE self, VALUE rb_other) {
136
189
  return self;
137
190
  }
138
191
 
192
+ /* call-seq: primitive -> Symbol
193
+ *
194
+ * Returns the primitive type used to draw the vertices.
195
+ *
196
+ * @return [Symbol] see VertexArray#primitive
197
+ */
139
198
  static VALUE VertexBuffer_get_primitive_type(VALUE self) {
140
199
  return ID2SYM(rb_intern(
141
200
  primitive_type_name(sfVertexBuffer_getPrimitiveType(Get_VertexBuffer_Struct(self)))));
142
201
  }
143
202
 
203
+ /* call-seq:
204
+ * primitive=(value) -> Symbol
205
+ *
206
+ * Sets the primitive type used to draw the vertices.
207
+ *
208
+ * @return [Symbol] +value+
209
+ */
144
210
  static VALUE VertexBuffer_set_primitive_type(VALUE self, VALUE rb_type) {
145
211
  sfVertexBuffer_setPrimitiveType(Get_VertexBuffer_Struct(self), primitive_type_from_rb(rb_type));
146
212
  return rb_type;
147
213
  }
148
214
 
215
+ /* call-seq: usage -> Symbol
216
+ *
217
+ * Returns the buffer's usage hint.
218
+ *
219
+ * @return [Symbol] one of :stream, :dynamic, :static
220
+ */
149
221
  static VALUE VertexBuffer_get_usage(VALUE self) {
150
222
  return ID2SYM(rb_intern(usage_names[sfVertexBuffer_getUsage(Get_VertexBuffer_Struct(self))]));
151
223
  }
152
224
 
225
+ /* call-seq:
226
+ * usage=(value) -> Symbol
227
+ *
228
+ * Sets the buffer's usage hint.
229
+ *
230
+ * @return [Symbol] +value+
231
+ */
153
232
  static VALUE VertexBuffer_set_usage(VALUE self, VALUE rb_usage) {
154
233
  sfVertexBuffer_setUsage(Get_VertexBuffer_Struct(self), usage_from_rb(rb_usage));
155
234
  return rb_usage;
156
235
  }
157
236
 
237
+ /* call-seq: native_handle -> Integer
238
+ *
239
+ * Returns the underlying OpenGL handle.
240
+ *
241
+ * @return [Integer] the underlying OpenGL buffer handle
242
+ */
158
243
  static VALUE VertexBuffer_get_native_handle(VALUE self) {
159
244
  return UINT2NUM(sfVertexBuffer_getNativeHandle(Get_VertexBuffer_Struct(self)));
160
245
  }
161
246
 
247
+ /* call-seq: bind -> self
248
+ *
249
+ * Binds the buffer for drawing.
250
+ *
251
+ * @return [self]
252
+ */
162
253
  static VALUE VertexBuffer_bind(VALUE self) {
163
254
  sfVertexBuffer_bind(Get_VertexBuffer_Struct(self));
164
255
  return self;
165
256
  }
166
257
 
258
+ /* call-seq:
259
+ * VertexBuffer.available? -> true or false
260
+ *
261
+ * Returns +true+ if vertex buffers are supported.
262
+ *
263
+ * @return [Boolean] whether the system supports vertex buffers
264
+ */
167
265
  static VALUE VertexBuffer_is_available(VALUE klass) {
168
266
  return BOOL2RB(sfVertexBuffer_isAvailable());
169
267
  }
170
268
 
269
+ /* call-seq:
270
+ * draw(target, state) -> nil
271
+ *
272
+ * Part of the Drawable interface; call Target#draw instead of this
273
+ * directly.
274
+ *
275
+ * @return [nil]
276
+ * @raise [TypeError] if +target+ is not a Target or +state+ is not a
277
+ * RenderState
278
+ */
171
279
  static VALUE VertexBuffer_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
172
280
  if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
173
281
  raise_invalid_argument_class(Get_Klass_Target());
@@ -184,8 +292,22 @@ static VALUE VertexBuffer_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
184
292
  return Qnil;
185
293
  }
186
294
 
187
- void Init_VertexBuffer(VALUE rb_module) {
188
- rb_cVertexBuffer = rb_define_class_under(rb_module, "VertexBuffer", rb_cObject);
295
+ /* Document-class: SFML::VertexBuffer
296
+ * Like VertexArray, but the vertex data lives in GPU memory rather than
297
+ * being re-uploaded on every draw -- more efficient for large, static
298
+ * or semi-static vertex sets.
299
+ *
300
+ * Includes +Drawable+.
301
+ *
302
+ * @!attribute primitive
303
+ * The primitive type used to draw the vertices.
304
+ * @return [Symbol]
305
+ * @!attribute usage
306
+ * The buffer's usage hint.
307
+ * @return [Symbol] one of :stream, :dynamic, :static
308
+ */
309
+ void Init_VertexBuffer(VALUE rb_mSFML) {
310
+ rb_cVertexBuffer = rb_define_class_under(rb_mSFML, "VertexBuffer", rb_cObject);
189
311
 
190
312
  rb_include_module(rb_cVertexBuffer, Get_Module_Drawable());
191
313
 
data/ext/graphics/view.c CHANGED
@@ -42,12 +42,27 @@ static VALUE View_new_from(VALUE klass, sfView* c_view) {
42
42
  return self;
43
43
  }
44
44
 
45
+ /* call-seq:
46
+ * View.new -> View
47
+ *
48
+ * Creates a default view covering the (0, 0) - (1000, 1000) region.
49
+ *
50
+ * @return [View]
51
+ */
45
52
  static VALUE View_new(VALUE klass) {
46
53
  return View_new_from(klass, NULL);
47
54
  }
48
55
 
49
56
  /* The rect is the visible area: position is the top-left corner, not the
50
57
  centre, which is what distinguishes this from new + center=/size=. */
58
+ /* call-seq:
59
+ * View.from_rect(rect) -> View
60
+ *
61
+ * Creates a view covering the given rectangle.
62
+ *
63
+ * @return [View] a view whose visible area is +rect+ (position is the
64
+ * top-left corner)
65
+ */
51
66
  static VALUE View_s_from_rect(VALUE klass, VALUE rb_rect) {
52
67
  return View_new_from(klass, sfView_createFromRect(rect_from_rb(rb_rect)));
53
68
  }
@@ -56,22 +71,51 @@ static VALUE View_init(VALUE self) {
56
71
  return self;
57
72
  }
58
73
 
74
+ /* call-seq:
75
+ * rotation=(value) -> self
76
+ *
77
+ * Sets the object's rotation, in degrees.
78
+ *
79
+ * @return [self]
80
+ */
59
81
  static VALUE View_set_rotation(VALUE self, VALUE rb_rotation) {
60
82
  sfView_setRotation(Get_View_Struct(self), NUM2DBL(rb_rotation));
61
83
  return self;
62
84
  }
63
85
 
86
+ /* call-seq:
87
+ * size=(value) -> self
88
+ *
89
+ * Sets the object's size.
90
+ *
91
+ * @return [self]
92
+ */
64
93
  static VALUE View_set_size(VALUE self, VALUE rb_scale) {
65
94
  sfView_setSize(Get_View_Struct(self), vec2f_from_rb(rb_scale));
66
95
  return self;
67
96
  }
68
97
 
98
+ /* call-seq:
99
+ * center=(value) -> self
100
+ *
101
+ * Sets the view's center.
102
+ *
103
+ * @return [self]
104
+ */
69
105
  static VALUE View_set_center(VALUE self, VALUE rb_origin) {
70
106
  sfVector2f origin = VEC2_RB2C(rb_origin);
71
107
  sfView_setCenter(Get_View_Struct(self), origin);
72
108
  return self;
73
109
  }
74
110
 
111
+ /* call-seq:
112
+ * viewport=(value) -> self
113
+ *
114
+ * Sets the viewport: the target-relative (0..1) rectangle this view is
115
+ * rendered into.
116
+ *
117
+ * @return [self]
118
+ */
75
119
  static VALUE View_set_viewport(VALUE self, VALUE rb_viewport) {
76
120
  sfFloatRect viewport = RECT_RB2C(rb_viewport);
77
121
  sfView_setViewport(Get_View_Struct(self), viewport);
@@ -79,55 +123,139 @@ static VALUE View_set_viewport(VALUE self, VALUE rb_viewport) {
79
123
  return self;
80
124
  }
81
125
 
126
+ /* call-seq: rotation -> Float
127
+ *
128
+ * Returns the object's rotation, in degrees.
129
+ *
130
+ * @return [Float] degrees
131
+ */
82
132
  static VALUE View_get_rotation(VALUE self) {
83
133
  return DBL2NUM(sfView_getRotation(Get_View_Struct(self)));
84
134
  }
85
135
 
136
+ /* call-seq: size -> Vector2
137
+ *
138
+ * Returns the object's size.
139
+ *
140
+ * @return [Vector2]
141
+ */
86
142
  static VALUE View_get_size(VALUE self) {
87
143
  return vec2f_to_rb(sfView_getSize(Get_View_Struct(self)));
88
144
  }
89
145
 
146
+ /* call-seq: center -> Vector2
147
+ *
148
+ * Returns the view's center.
149
+ *
150
+ * @return [Vector2]
151
+ */
90
152
  static VALUE View_get_center(VALUE self) {
91
153
  return vec2f_to_rb(sfView_getCenter(Get_View_Struct(self)));
92
154
  }
93
155
 
156
+ /* call-seq: viewport -> Rect
157
+ *
158
+ * Returns the target's viewport rectangle, or +nil+ if none is set.
159
+ *
160
+ * @return [Rect]
161
+ */
94
162
  static VALUE View_get_viewport(VALUE self) {
95
163
  return RECT_C2RB(sfView_getViewport(Get_View_Struct(self)));
96
164
  }
97
165
 
166
+ /* call-seq:
167
+ * scissor=(value) -> self
168
+ *
169
+ * Sets the target's scissor rectangle.
170
+ *
171
+ * @return [self]
172
+ */
98
173
  static VALUE View_set_scissor(VALUE self, VALUE rb_scissor) {
99
174
  sfView_setScissor(Get_View_Struct(self), RECT_RB2C(rb_scissor));
100
175
 
101
176
  return self;
102
177
  }
103
178
 
179
+ /* call-seq: scissor -> Rect
180
+ *
181
+ * Returns the target's scissor rectangle, or +nil+ if none is set.
182
+ *
183
+ * @return [Rect]
184
+ */
104
185
  static VALUE View_get_scissor(VALUE self) {
105
186
  return RECT_C2RB(sfView_getScissor(Get_View_Struct(self)));
106
187
  }
107
188
 
189
+ /* call-seq:
190
+ * move(offset) -> self
191
+ *
192
+ * Moves the object by +offset+.
193
+ *
194
+ * @return [self]
195
+ */
108
196
  static VALUE View_move(VALUE self, VALUE rb_move) {
109
197
  sfView_move(Get_View_Struct(self), vec2f_from_rb(rb_move));
110
198
  return self;
111
199
  }
112
200
 
201
+ /* call-seq:
202
+ * rotate(angle) -> self
203
+ *
204
+ * Rotates the object by +angle+ degrees.
205
+ *
206
+ * @return [self]
207
+ */
113
208
  static VALUE View_rotate(VALUE self, VALUE rb_angle) {
114
209
  sfView_rotate(Get_View_Struct(self), NUM2DBL(rb_angle));
115
210
 
116
211
  return self;
117
212
  }
118
213
 
214
+ /* call-seq:
215
+ * zoom(factor) -> self
216
+ *
217
+ * Multiplies the view's size by +factor+.
218
+ *
219
+ * @return [self]
220
+ */
119
221
  static VALUE View_zoom(VALUE self, VALUE rb_zoom) {
120
222
  sfView_zoom(Get_View_Struct(self), NUM2DBL(rb_zoom));
121
223
 
122
224
  return self;
123
225
  }
124
226
 
227
+ /* call-seq: copy -> View
228
+ *
229
+ * Returns a deep copy of the object.
230
+ *
231
+ * @return [View] an independent copy
232
+ */
125
233
  static VALUE View_copy(VALUE self) {
126
234
  return Get_Casting_View(sfView_copy(Get_View_Struct(self)));
127
235
  }
128
236
 
129
- void Init_View(VALUE rb_module) {
130
- rb_cView = rb_define_class_under(rb_module, "View", rb_cObject);
237
+ /* Document-class: SFML::View
238
+ * A 2D camera: the region of the scene visible on a render target, and
239
+ * where on that target it is shown.
240
+ *
241
+ * @!attribute rotation
242
+ * The object's rotation, in degrees.
243
+ * @return [Float] degrees
244
+ * @!attribute size
245
+ * The object's size.
246
+ * @return [Vector2]
247
+ * @!attribute center
248
+ * The view's center.
249
+ * @return [Vector2]
250
+ * @!attribute viewport
251
+ * The view's viewport rectangle.
252
+ * @return [Rect] the target-relative (0..1) rectangle this view renders into
253
+ * @!attribute scissor
254
+ * The view's scissor rectangle.
255
+ * @return [Rect]
256
+ */
257
+ void Init_View(VALUE rb_mSFML) {
258
+ rb_cView = rb_define_class_under(rb_mSFML, "View", rb_cObject);
131
259
 
132
260
  rb_define_singleton_method(rb_cView, "new", View_new, 0);
133
261
  rb_define_singleton_method(rb_cView, "from_rect", View_s_from_rect, 1);