ray 0.1.0.pre1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +235 -32
- data/Rakefile +20 -49
- data/ext/audio.c +68 -0
- data/ext/audio_source.c +197 -0
- data/ext/buffer_renderer.c +130 -0
- data/ext/color.c +179 -0
- data/ext/drawable.c +446 -0
- data/ext/event.c +337 -0
- data/ext/extconf.rb +80 -6
- data/ext/font.c +97 -0
- data/ext/gl.c +114 -0
- data/ext/gl_buffer.c +224 -0
- data/ext/gl_index_buffer.c +202 -0
- data/ext/gl_int_array.c +139 -0
- data/ext/gl_vertex.c +157 -0
- data/ext/image.c +263 -0
- data/ext/image_target.c +84 -0
- data/ext/input.c +53 -0
- data/ext/matrix.c +374 -0
- data/ext/music.c +113 -0
- data/ext/polygon.c +426 -0
- data/ext/ray.c +59 -0
- data/ext/ray.h +168 -0
- data/ext/rect.c +255 -0
- data/ext/say.h +31 -0
- data/ext/say_all.h +77 -0
- data/ext/say_arial.h +14689 -0
- data/ext/say_array.c +124 -0
- data/ext/say_array.h +34 -0
- data/ext/say_audio.c +64 -0
- data/ext/say_audio.h +170 -0
- data/ext/say_audio_context.c +40 -0
- data/ext/say_audio_source.c +96 -0
- data/ext/say_basic_type.c +17 -0
- data/ext/say_basic_type.h +47 -0
- data/ext/say_buffer.c +277 -0
- data/ext/say_buffer.h +37 -0
- data/ext/say_buffer_renderer.c +121 -0
- data/ext/say_buffer_renderer.h +33 -0
- data/ext/say_buffer_slice.c +247 -0
- data/ext/say_buffer_slice.h +29 -0
- data/ext/say_clean_up.c +14 -0
- data/ext/say_context.c +163 -0
- data/ext/say_context.h +26 -0
- data/ext/say_drawable.c +350 -0
- data/ext/say_drawable.h +100 -0
- data/ext/say_error.c +27 -0
- data/ext/say_event.h +213 -0
- data/ext/say_font.c +335 -0
- data/ext/say_font.h +51 -0
- data/ext/say_image.c +283 -0
- data/ext/say_image.h +52 -0
- data/ext/say_image_target.c +134 -0
- data/ext/say_image_target.h +25 -0
- data/ext/say_imp.h +70 -0
- data/ext/say_index_buffer.c +90 -0
- data/ext/say_index_buffer.h +29 -0
- data/ext/say_index_buffer_slice.c +227 -0
- data/ext/say_index_buffer_slice.h +28 -0
- data/ext/say_input.c +35 -0
- data/ext/say_matrix.c +314 -0
- data/ext/say_matrix.h +55 -0
- data/ext/say_music.c +225 -0
- data/ext/say_osx.h +62 -0
- data/ext/say_osx_context.h +98 -0
- data/ext/say_osx_window.h +766 -0
- data/ext/say_polygon.c +358 -0
- data/ext/say_polygon.h +62 -0
- data/ext/say_renderer.c +42 -0
- data/ext/say_renderer.h +22 -0
- data/ext/say_shader.c +375 -0
- data/ext/say_shader.h +91 -0
- data/ext/say_sound.c +67 -0
- data/ext/say_sound_buffer.c +96 -0
- data/ext/say_sprite.c +273 -0
- data/ext/say_sprite.h +53 -0
- data/ext/say_string.c +9 -0
- data/ext/say_table.c +86 -0
- data/ext/say_table.h +24 -0
- data/ext/say_target.c +264 -0
- data/ext/say_target.h +67 -0
- data/ext/say_text.c +441 -0
- data/ext/say_text.h +56 -0
- data/ext/say_thread.c +46 -0
- data/ext/say_thread.h +39 -0
- data/ext/say_thread_variable.c +44 -0
- data/ext/say_utf.c +62 -0
- data/ext/say_vertex_type.c +113 -0
- data/ext/say_vertex_type.h +40 -0
- data/ext/say_vfile.c +57 -0
- data/ext/say_view.c +150 -0
- data/ext/say_view.h +44 -0
- data/ext/say_win.h +24 -0
- data/ext/say_win_context.h +91 -0
- data/ext/say_win_window.h +670 -0
- data/ext/say_window.c +155 -0
- data/ext/say_window.h +43 -0
- data/ext/say_x11.h +41 -0
- data/ext/say_x11_context.h +96 -0
- data/ext/say_x11_window.h +818 -0
- data/ext/shader.c +302 -0
- data/ext/sound.c +118 -0
- data/ext/sound_buffer.c +75 -0
- data/ext/sprite.c +241 -0
- data/ext/stb_image.h +4971 -0
- data/ext/stb_image_write.h +511 -0
- data/ext/target.c +184 -0
- data/ext/text.c +162 -0
- data/ext/utils.c +10 -0
- data/ext/vector.c +261 -0
- data/ext/vendor/freetype/bin/freetype6.dll +0 -0
- data/ext/vendor/freetype/bin/zlib1.dll +0 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftconfig.h +350 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftheader.h +729 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftmodule.h +22 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftoption.h +695 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftstdlib.h +180 -0
- data/ext/vendor/freetype/include/freetype2/freetype/freetype.h +3434 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftbbox.h +94 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftbdf.h +200 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftbitmap.h +206 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftcache.h +1110 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftchapters.h +100 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fterrdef.h +239 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fterrors.h +206 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftgasp.h +113 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftglyph.h +575 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftgxval.h +358 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftgzip.h +102 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftimage.h +1237 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftincrem.h +331 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftlcdfil.h +166 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftlist.h +273 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftlzw.h +99 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmac.h +272 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmm.h +378 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmodapi.h +406 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmoderr.h +155 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftotval.h +198 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftoutln.h +526 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftpfr.h +172 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftrender.h +229 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsizes.h +159 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsnames.h +170 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftstroke.h +716 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsynth.h +73 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsystem.h +346 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fttrigon.h +350 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fttypes.h +583 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftwinfnt.h +263 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftxf86.h +80 -0
- data/ext/vendor/freetype/include/freetype2/freetype/t1tables.h +450 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ttnameid.h +1132 -0
- data/ext/vendor/freetype/include/freetype2/freetype/tttables.h +756 -0
- data/ext/vendor/freetype/include/freetype2/freetype/tttags.h +99 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ttunpat.h +59 -0
- data/ext/vendor/freetype/include/ft2build.h +61 -0
- data/ext/vendor/freetype/lib/freetype-bcc.lib +0 -0
- data/ext/vendor/freetype/lib/freetype6.def +249 -0
- data/ext/vendor/freetype/lib/libfreetype.dll.a +0 -0
- data/ext/vendor/freetype/lib/tmp.freetype.lib +0 -0
- data/ext/vendor/glew/LICENSE.txt +73 -0
- data/ext/vendor/glew/README.txt +18 -0
- data/ext/vendor/glew/include/GL/glew.h +15507 -0
- data/ext/vendor/glew/include/GL/glxew.h +1568 -0
- data/ext/vendor/glew/include/GL/wglew.h +1361 -0
- data/ext/vendor/glew/lib/glew32.dll +0 -0
- data/ext/vendor/glew/lib/glew32mx.dll +0 -0
- data/ext/vendor/glew/lib/libglew32.a +0 -0
- data/ext/vendor/glew/lib/libglew32.dll.a +0 -0
- data/ext/vendor/glew/lib/libglew32mx.a +0 -0
- data/ext/vendor/glew/lib/libglew32mx.dll.a +0 -0
- data/ext/vendor/openal/COPYING +484 -0
- data/ext/vendor/openal/Win32/soft_oal.dll +0 -0
- data/ext/vendor/openal/include/AL/al.h +724 -0
- data/ext/vendor/openal/include/AL/alc.h +277 -0
- data/ext/vendor/openal/include/AL/alext.h +165 -0
- data/ext/vendor/openal/include/AL/efx-creative.h +3 -0
- data/ext/vendor/openal/include/AL/efx.h +758 -0
- data/ext/vendor/openal/lib/libOpenAL32.dll.a +0 -0
- data/ext/vendor/sndfile/bin/libsndfile-1.dll +0 -0
- data/ext/vendor/sndfile/include/sndfile.h +666 -0
- data/ext/vendor/sndfile/include/sndfile.hh +422 -0
- data/ext/vendor/sndfile/lib/libsndfile-1.def +41 -0
- data/ext/vendor/sndfile/lib/libsndfile-1.lib +0 -0
- data/ext/vertex.c +96 -0
- data/ext/view.c +131 -0
- data/ext/window.c +183 -0
- data/lib/ray/animation.rb +248 -0
- data/lib/ray/animation/block_animation.rb +36 -0
- data/lib/ray/animation/circular_motion.rb +57 -0
- data/lib/ray/animation/color_variation.rb +102 -0
- data/lib/ray/animation/combination.rb +71 -0
- data/lib/ray/animation/float_variation.rb +76 -0
- data/lib/ray/animation/sequence.rb +65 -0
- data/lib/ray/animation/sprite_animation.rb +68 -0
- data/lib/ray/animation/vector_variation.rb +111 -0
- data/lib/ray/animation_list.rb +50 -0
- data/lib/ray/audio.rb +4 -7
- data/lib/ray/buffer_renderer.rb +9 -0
- data/lib/ray/color.rb +41 -6
- data/lib/ray/drawable.rb +34 -9
- data/lib/ray/dsl.rb +6 -0
- data/lib/ray/dsl/event.rb +1 -1
- data/lib/ray/dsl/event_listener.rb +14 -10
- data/lib/ray/dsl/event_raiser.rb +5 -2
- data/lib/ray/dsl/event_runner.rb +4 -10
- data/lib/ray/dsl/event_translator.rb +67 -99
- data/lib/ray/dsl/handler.rb +1 -1
- data/lib/ray/dsl/matcher.rb +40 -27
- data/lib/ray/event.rb +22 -0
- data/lib/ray/font.rb +0 -42
- data/lib/ray/font_set.rb +3 -7
- data/lib/ray/game.rb +33 -73
- data/lib/ray/gl/int_array.rb +24 -0
- data/lib/ray/gl/vertex.rb +106 -0
- data/lib/ray/helper.rb +25 -11
- data/lib/ray/image.rb +9 -154
- data/lib/ray/image_set.rb +3 -8
- data/lib/ray/image_target.rb +12 -0
- data/lib/ray/matrix.rb +90 -0
- data/lib/ray/music.rb +12 -0
- data/lib/ray/polygon.rb +77 -0
- data/lib/ray/ray.rb +45 -13
- data/lib/ray/rect.rb +14 -3
- data/lib/ray/resource_set.rb +18 -35
- data/lib/ray/scene.rb +43 -81
- data/lib/ray/scene_list.rb +12 -5
- data/lib/ray/shader.rb +82 -0
- data/lib/ray/sound.rb +18 -0
- data/lib/ray/sound_buffer.rb +6 -0
- data/lib/ray/sound_buffer_set.rb +32 -0
- data/lib/ray/sprite.rb +111 -97
- data/lib/ray/target.rb +18 -0
- data/lib/ray/text.rb +80 -58
- data/lib/ray/text_helper.rb +21 -27
- data/lib/ray/turtle.rb +49 -38
- data/lib/ray/vector.rb +76 -1
- data/lib/ray/vertex.rb +24 -0
- data/lib/ray/view.rb +47 -0
- data/lib/ray/window.rb +23 -0
- data/samples/_media/Beep.wav +0 -0
- data/samples/_media/CptnRuby Gem.png +0 -0
- data/samples/_media/CptnRuby Map.txt +25 -0
- data/samples/_media/CptnRuby Tileset.png +0 -0
- data/samples/_media/CptnRuby.png +0 -0
- data/samples/_media/Space.png +0 -0
- data/samples/_media/Star.png +0 -0
- data/samples/_media/Starfighter.png +0 -0
- data/samples/animation/chain.rb +33 -0
- data/samples/animation/circle.rb +38 -0
- data/samples/animation/color.rb +18 -0
- data/samples/animation/rotation.rb +17 -0
- data/samples/animation/sequence.rb +33 -0
- data/samples/animation/shader.rb +65 -0
- data/samples/animation/sprite_motion.rb +103 -0
- data/samples/animation/translation.rb +23 -0
- data/samples/audio/spacial.rb +25 -11
- data/samples/buffer/buffer.rb +28 -0
- data/samples/buffer/index_buffer.rb +36 -0
- data/samples/buffer/renderer.rb +27 -0
- data/samples/cptn_ruby/cptn_ruby.rb +279 -0
- data/samples/hello_world/hello.rb +2 -2
- data/samples/hello_world/hello_dsl.rb +3 -3
- data/samples/hello_world/text.rb +2 -2
- data/samples/opengl/cube.rb +124 -0
- data/samples/opengl/image.rb +36 -16
- data/samples/opengl/obj_loader.rb +99 -0
- data/samples/opengl/opengl.rb +24 -18
- data/samples/opengl/shader.rb +36 -26
- data/samples/pong/pong.rb +41 -39
- data/samples/{run_scene.rb → scenes/run_scene.rb} +21 -7
- data/samples/shaders/geometry.rb +98 -0
- data/samples/shaders/scene.rb +19 -12
- data/samples/shaders/shaders.rb +34 -17
- data/samples/shaders/shape.rb +12 -7
- data/samples/sokoban/level_1 +11 -7
- data/samples/sokoban/sokoban.rb +36 -63
- data/samples/starfighter/starfighter.rb +159 -0
- data/samples/test/actual_scene.rb +3 -3
- data/samples/test/scene_riot.rb +4 -4
- data/samples/test/scene_spec.rb +3 -3
- data/samples/test/scene_test_unit.rb +1 -1
- data/samples/turtle/byzantium.rb +10 -5
- data/samples/turtle/hilbert.rb +16 -11
- data/samples/turtle/koch.rb +16 -11
- data/samples/turtle/mandala.rb +43 -38
- data/samples/turtle/tree.rb +13 -8
- data/samples/view/resize.rb +26 -0
- data/samples/view/view.rb +35 -0
- data/samples/window/all_events.rb +44 -0
- data/samples/window/change_title.rb +16 -0
- data/samples/window/fullscreen.rb +18 -0
- data/samples/window/get_pixel.rb +29 -0
- data/samples/window/icon.rb +88 -0
- data/samples/window/input.rb +27 -0
- data/samples/window/no_border.rb +16 -0
- data/samples/window/resize.rb +24 -0
- data/test/animation/color_variation_test.rb +64 -0
- data/test/animation/combination_test.rb +35 -0
- data/test/animation/float_variation_test.rb +75 -0
- data/test/animation/vector_variation_test.rb +123 -0
- data/test/animation_list_test.rb +122 -0
- data/test/animation_test.rb +83 -0
- data/test/audio_test.rb +88 -33
- data/test/buffer_renderer_test.rb +38 -0
- data/test/color_test.rb +31 -22
- data/test/drawable_test.rb +207 -7
- data/test/dsl_test.rb +25 -7
- data/test/font_test.rb +6 -40
- data/test/game_test.rb +76 -0
- data/test/gl_buffer_test.rb +26 -0
- data/test/gl_index_buffer_test.rb +17 -0
- data/test/gl_vertex_test.rb +117 -0
- data/test/helpers.rb +45 -5
- data/test/image_target_test.rb +19 -0
- data/test/image_test.rb +73 -53
- data/test/int_array_test.rb +64 -0
- data/test/matrix_test.rb +134 -0
- data/test/polygon_test.rb +126 -0
- data/test/rect_test.rb +6 -8
- data/test/res/frag.c +14 -0
- data/test/res/frag3d.c +10 -0
- data/test/res/frag_gray.c +17 -0
- data/test/res/frag_light3d.c +20 -0
- data/test/res/light3d.c +20 -0
- data/test/res/sprite.png +0 -0
- data/test/res/teapot.obj +12831 -0
- data/test/res/vert.c +17 -0
- data/test/res/vertex3d.c +14 -0
- data/test/resource_set_test.rb +8 -45
- data/test/run_all.rb +1 -1
- data/test/scene_list_test.rb +79 -0
- data/test/scene_test.rb +168 -0
- data/test/shader_test.rb +58 -0
- data/test/sprite_test.rb +46 -41
- data/test/target_test.rb +34 -0
- data/test/text_test.rb +20 -31
- data/test/turtle_test.rb +35 -20
- data/test/vector_test.rb +61 -19
- data/test/vertex_test.rb +43 -0
- data/test/view_test.rb +61 -0
- metadata +347 -126
- data/.yardopts +0 -4
- data/VERSION +0 -1
- data/ext/audio.cpp +0 -723
- data/ext/color.cpp +0 -159
- data/ext/drawable.cpp +0 -91
- data/ext/event.cpp +0 -460
- data/ext/font.cpp +0 -190
- data/ext/image.cpp +0 -733
- data/ext/input.cpp +0 -74
- data/ext/ray.cpp +0 -168
- data/ext/ray.hpp +0 -356
- data/ext/rect.cpp +0 -245
- data/ext/shader.cpp +0 -169
- data/ext/shape.cpp +0 -409
- data/ext/sprite.cpp +0 -306
- data/ext/text.cpp +0 -181
- data/ext/vector.cpp +0 -215
- data/guide.md +0 -619
- data/lib/ray/input.rb +0 -10
- data/lib/ray/music_set.rb +0 -37
- data/lib/ray/rmagick.rb +0 -41
- data/lib/ray/shape.rb +0 -132
- data/lib/ray/sound_set.rb +0 -37
- data/samples/opengl/binding.rb +0 -38
- data/test/ray_test.rb +0 -25
- data/test/shape_test.rb +0 -101
- data/yard_ext.rb +0 -63
data/ext/rect.cpp
DELETED
@@ -1,245 +0,0 @@
|
|
1
|
-
#include "ray.hpp"
|
2
|
-
|
3
|
-
VALUE ray_cRect = Qnil;
|
4
|
-
|
5
|
-
void ray_free_rect(ray_rect *ptr) {
|
6
|
-
delete ptr;
|
7
|
-
}
|
8
|
-
|
9
|
-
VALUE ray_rect2rb(const ray_rect &rect) {
|
10
|
-
ray_rect *ptr = new ray_rect(rect);
|
11
|
-
|
12
|
-
VALUE obj = Data_Wrap_Struct(ray_cRect, NULL, ray_free_rect, ptr);
|
13
|
-
return obj;
|
14
|
-
}
|
15
|
-
|
16
|
-
ray_rect ray_rb2rect(VALUE obj) {
|
17
|
-
if (!RAY_IS_A(obj, ray_cRect)) {
|
18
|
-
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Rect",
|
19
|
-
RAY_OBJ_CLASSNAME(obj));
|
20
|
-
}
|
21
|
-
|
22
|
-
ray_rect *rect;
|
23
|
-
Data_Get_Struct(obj, ray_rect, rect);
|
24
|
-
|
25
|
-
return *rect;
|
26
|
-
}
|
27
|
-
|
28
|
-
ray_rect ray_convert_to_rect(VALUE obj) {
|
29
|
-
if (RAY_IS_A(obj, ray_cRect))
|
30
|
-
return ray_rb2rect(obj);
|
31
|
-
else {
|
32
|
-
obj = rb_funcall(obj, RAY_METH("to_rect"), 0);
|
33
|
-
return ray_rb2rect(obj);
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
VALUE ray_alloc_rect(VALUE self) {
|
38
|
-
ray_rect *rect = new ray_rect;
|
39
|
-
VALUE ret = Data_Wrap_Struct(self, 0, ray_free_rect, rect);
|
40
|
-
|
41
|
-
return ret;
|
42
|
-
}
|
43
|
-
|
44
|
-
/*
|
45
|
-
@overload initialize(x, y)
|
46
|
-
Creates a new rect with size set to 0, 0.
|
47
|
-
|
48
|
-
@overload initialize(x, y, w, h)
|
49
|
-
Creates a new rect with the specified size.
|
50
|
-
|
51
|
-
@overload initialize(hash)
|
52
|
-
Creates a new rect according to the keys specified in hash.
|
53
|
-
|
54
|
-
@option hash [Float] :x
|
55
|
-
@option hash [Float] :y
|
56
|
-
@option hash [Float, optional] :width
|
57
|
-
@option hash [Float, optional] :height required if width is set
|
58
|
-
|
59
|
-
@option hash [Float, optional] :w alias for :width
|
60
|
-
@option hash [Float, optional] :h alias for :height
|
61
|
-
*/
|
62
|
-
VALUE ray_init_rect(int argc, VALUE *argv, VALUE self) {
|
63
|
-
VALUE x_or_hash, y, w, h;
|
64
|
-
rb_scan_args(argc, argv, "13", &x_or_hash, &y, &w, &h);
|
65
|
-
|
66
|
-
int type = TYPE(x_or_hash);
|
67
|
-
if (type == T_HASH) {
|
68
|
-
if (!NIL_P(y)) {
|
69
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
70
|
-
argc);
|
71
|
-
}
|
72
|
-
|
73
|
-
VALUE hash = x_or_hash;
|
74
|
-
|
75
|
-
x_or_hash = rb_hash_aref(hash, RAY_SYM("x"));
|
76
|
-
y = rb_hash_aref(hash, RAY_SYM("y"));
|
77
|
-
|
78
|
-
w = rb_hash_aref(hash, RAY_SYM("width"));
|
79
|
-
h = rb_hash_aref(hash, RAY_SYM("height"));
|
80
|
-
|
81
|
-
if (NIL_P(w)) w = rb_hash_aref(hash, RAY_SYM("w"));
|
82
|
-
if (NIL_P(h)) h = rb_hash_aref(hash, RAY_SYM("h"));
|
83
|
-
|
84
|
-
if (NIL_P(y)) {
|
85
|
-
rb_raise(rb_eArgError, "Missing argument 'y'");
|
86
|
-
}
|
87
|
-
|
88
|
-
if (!NIL_P(w) && NIL_P(h)) {
|
89
|
-
rb_raise(rb_eArgError, "missing argument 'height'");
|
90
|
-
}
|
91
|
-
}
|
92
|
-
else {
|
93
|
-
if (NIL_P(y)) {
|
94
|
-
rb_raise(rb_eArgError, "wrong number of arguments (1 for 2)");
|
95
|
-
}
|
96
|
-
|
97
|
-
if (!NIL_P(w) && NIL_P(h)) {
|
98
|
-
rb_raise(rb_eArgError, "wrong number of arguments (3 for 4)");
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
ray_rect *rect;
|
103
|
-
Data_Get_Struct(self, ray_rect, rect);
|
104
|
-
|
105
|
-
rect->Left = NUM2DBL(x_or_hash);
|
106
|
-
rect->Top = NUM2DBL(y);
|
107
|
-
|
108
|
-
if (!NIL_P(w)) {
|
109
|
-
rect->Width = NUM2DBL(w);
|
110
|
-
rect->Height = NUM2DBL(h);
|
111
|
-
}
|
112
|
-
else {
|
113
|
-
rect->Width = 0;
|
114
|
-
rect->Height = 0;
|
115
|
-
}
|
116
|
-
|
117
|
-
return Qnil;
|
118
|
-
}
|
119
|
-
|
120
|
-
VALUE ray_init_rect_copy(VALUE self, VALUE other) {
|
121
|
-
ray_rect *rect = NULL, *source = NULL;
|
122
|
-
Data_Get_Struct(self, ray_rect, rect);
|
123
|
-
Data_Get_Struct(other, ray_rect, source);
|
124
|
-
|
125
|
-
*rect = *source;
|
126
|
-
return self;
|
127
|
-
}
|
128
|
-
|
129
|
-
/* @return [Float] position of the rect */
|
130
|
-
VALUE ray_rect_x(VALUE self) {
|
131
|
-
ray_rect *rect;
|
132
|
-
Data_Get_Struct(self, ray_rect, rect);
|
133
|
-
|
134
|
-
return rb_float_new(rect->Left);
|
135
|
-
}
|
136
|
-
|
137
|
-
/* @return [Float] position of the rect */
|
138
|
-
VALUE ray_rect_y(VALUE self) {
|
139
|
-
ray_rect *rect;
|
140
|
-
Data_Get_Struct(self, ray_rect, rect);
|
141
|
-
|
142
|
-
return rb_float_new(rect->Top);
|
143
|
-
}
|
144
|
-
|
145
|
-
/* @return [Float] size of the rect */
|
146
|
-
VALUE ray_rect_w(VALUE self) {
|
147
|
-
ray_rect *rect;
|
148
|
-
Data_Get_Struct(self, ray_rect, rect);
|
149
|
-
|
150
|
-
return rb_float_new(rect->Width);
|
151
|
-
}
|
152
|
-
|
153
|
-
/* @return [Float] size of the rect */
|
154
|
-
VALUE ray_rect_h(VALUE self) {
|
155
|
-
ray_rect *rect;
|
156
|
-
Data_Get_Struct(self, ray_rect, rect);
|
157
|
-
|
158
|
-
return rb_float_new(rect->Height);
|
159
|
-
}
|
160
|
-
|
161
|
-
/*
|
162
|
-
@overload x=(val)
|
163
|
-
Sets the position of the rect
|
164
|
-
*/
|
165
|
-
VALUE ray_rect_set_x(VALUE self, VALUE val) {
|
166
|
-
rb_check_frozen(self);
|
167
|
-
|
168
|
-
ray_rect *rect;
|
169
|
-
Data_Get_Struct(self, ray_rect, rect);
|
170
|
-
|
171
|
-
rect->Left = NUM2DBL(val);
|
172
|
-
|
173
|
-
return val;
|
174
|
-
}
|
175
|
-
|
176
|
-
/*
|
177
|
-
@overload y=(val)
|
178
|
-
Sets the position of the rect
|
179
|
-
*/
|
180
|
-
VALUE ray_rect_set_y(VALUE self, VALUE val) {
|
181
|
-
rb_check_frozen(self);
|
182
|
-
|
183
|
-
ray_rect *rect;
|
184
|
-
Data_Get_Struct(self, ray_rect, rect);
|
185
|
-
|
186
|
-
rect->Top = NUM2DBL(val);
|
187
|
-
|
188
|
-
return val;
|
189
|
-
}
|
190
|
-
|
191
|
-
/*
|
192
|
-
@overload w=(val)
|
193
|
-
Sets the size of the rect
|
194
|
-
*/
|
195
|
-
VALUE ray_rect_set_w(VALUE self, VALUE val) {
|
196
|
-
rb_check_frozen(self);
|
197
|
-
|
198
|
-
ray_rect *rect;
|
199
|
-
Data_Get_Struct(self, ray_rect, rect);
|
200
|
-
|
201
|
-
rect->Width = NUM2DBL(val);
|
202
|
-
|
203
|
-
return val;
|
204
|
-
}
|
205
|
-
|
206
|
-
/*
|
207
|
-
@overload h=(val)
|
208
|
-
Sets the size of the rect
|
209
|
-
*/
|
210
|
-
VALUE ray_rect_set_h(VALUE self, VALUE val) {
|
211
|
-
rb_check_frozen(self);
|
212
|
-
|
213
|
-
ray_rect *rect;
|
214
|
-
Data_Get_Struct(self, ray_rect, rect);
|
215
|
-
|
216
|
-
rect->Height = NUM2DBL(val);
|
217
|
-
|
218
|
-
return val;
|
219
|
-
}
|
220
|
-
|
221
|
-
/*
|
222
|
-
Document-class: Ray::Rect
|
223
|
-
|
224
|
-
Rects are used to represent a part of an image, using
|
225
|
-
two attributes to represent its position, and two
|
226
|
-
others to represent its size.
|
227
|
-
*/
|
228
|
-
|
229
|
-
void Init_ray_rect() {
|
230
|
-
ray_cRect = rb_define_class_under(ray_mRay, "Rect", rb_cObject);
|
231
|
-
|
232
|
-
rb_define_alloc_func(ray_cRect, ray_alloc_rect);
|
233
|
-
rb_define_method(ray_cRect, "initialize", ray_init_rect, -1);
|
234
|
-
rb_define_method(ray_cRect, "initialize_copy", ray_init_rect_copy, 1);
|
235
|
-
|
236
|
-
rb_define_method(ray_cRect, "x", ray_rect_x, 0);
|
237
|
-
rb_define_method(ray_cRect, "y", ray_rect_y, 0);
|
238
|
-
rb_define_method(ray_cRect, "width", ray_rect_w, 0);
|
239
|
-
rb_define_method(ray_cRect, "height", ray_rect_h, 0);
|
240
|
-
|
241
|
-
rb_define_method(ray_cRect, "x=", ray_rect_set_x, 1);
|
242
|
-
rb_define_method(ray_cRect, "y=", ray_rect_set_y, 1);
|
243
|
-
rb_define_method(ray_cRect, "width=", ray_rect_set_w, 1);
|
244
|
-
rb_define_method(ray_cRect, "height=", ray_rect_set_h, 1);
|
245
|
-
}
|
data/ext/shader.cpp
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
#include "ray.hpp"
|
2
|
-
|
3
|
-
VALUE ray_cShader = Qnil;
|
4
|
-
|
5
|
-
void ray_free_shader(sf::Shader *shader) {
|
6
|
-
delete shader;
|
7
|
-
}
|
8
|
-
|
9
|
-
VALUE ray_alloc_shader(VALUE self) {
|
10
|
-
sf::Shader *shader = new sf::Shader;
|
11
|
-
return Data_Wrap_Struct(self, 0, ray_free_shader, shader);
|
12
|
-
}
|
13
|
-
|
14
|
-
sf::Shader *ray_rb2shader(VALUE self) {
|
15
|
-
if (!RAY_IS_A(self, ray_cShader)) {
|
16
|
-
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Shader",
|
17
|
-
RAY_OBJ_CLASSNAME(self));
|
18
|
-
}
|
19
|
-
|
20
|
-
sf::Shader *shader = NULL;
|
21
|
-
Data_Get_Struct(self, sf::Shader, shader);
|
22
|
-
|
23
|
-
return shader;
|
24
|
-
}
|
25
|
-
|
26
|
-
/*
|
27
|
-
@return [true, false] True if it is possible to use shaders.
|
28
|
-
*/
|
29
|
-
VALUE ray_shader_available(VALUE self) {
|
30
|
-
return sf::Shader::IsAvailable() ? Qtrue : Qfalse;
|
31
|
-
}
|
32
|
-
|
33
|
-
/*
|
34
|
-
@overload initialize(filename_or_io)
|
35
|
-
Creates a new Shader with the source code found
|
36
|
-
in a file or in an IO object.
|
37
|
-
|
38
|
-
@example
|
39
|
-
shader = Ray::Shader.new StringIO.new(<<-SHADER)
|
40
|
-
// Code of the shader
|
41
|
-
SHADER
|
42
|
-
*/
|
43
|
-
VALUE ray_init_shader(VALUE self, VALUE argument) {
|
44
|
-
sf::Shader *shader = ray_rb2shader(self);
|
45
|
-
|
46
|
-
if (RAY_IS_A(argument, rb_cString)) {
|
47
|
-
if (!shader->LoadFromFile(StringValuePtr(argument)))
|
48
|
-
rb_raise(rb_eRuntimeError, "Couldn't load the shader");
|
49
|
-
}
|
50
|
-
else if (rb_respond_to(argument, RAY_METH("read"))) {
|
51
|
-
VALUE string = rb_funcall2(argument, RAY_METH("read"), 0, NULL);
|
52
|
-
char *c_string = StringValuePtr(string);
|
53
|
-
|
54
|
-
if (!shader->LoadFromMemory(c_string))
|
55
|
-
rb_raise(rb_eRuntimeError, "Couldn't load the shader");
|
56
|
-
}
|
57
|
-
else {
|
58
|
-
rb_raise(rb_eArgError, "Can't convert %s into String",
|
59
|
-
RAY_OBJ_CLASSNAME(argument));
|
60
|
-
}
|
61
|
-
|
62
|
-
return self;
|
63
|
-
}
|
64
|
-
|
65
|
-
/*
|
66
|
-
@overload []=(name, argument)
|
67
|
-
Sets one of the variables of the shader.
|
68
|
-
argument can be:
|
69
|
-
- a float
|
70
|
-
- an array of 1, 2, 3, or 4 floats (for vectors)
|
71
|
-
- a Vector2 or Vector3
|
72
|
-
- an image, or :current which is a magic value to set a
|
73
|
-
texture to the current one.
|
74
|
-
*/
|
75
|
-
VALUE ray_shader_set(VALUE self, VALUE param, VALUE arg) {
|
76
|
-
rb_check_frozen(self);
|
77
|
-
|
78
|
-
sf::Shader *shader = ray_rb2shader(self);
|
79
|
-
char *name = StringValuePtr(param);
|
80
|
-
|
81
|
-
if (RAY_IS_A(arg, rb_cArray)) {
|
82
|
-
switch (RARRAY_LEN(arg)) {
|
83
|
-
case 1:
|
84
|
-
shader->SetParameter(name, NUM2DBL(rb_ary_entry(arg, 0)));
|
85
|
-
break;
|
86
|
-
case 2:
|
87
|
-
shader->SetParameter(name, NUM2DBL(rb_ary_entry(arg, 0)),
|
88
|
-
NUM2DBL(rb_ary_entry(arg, 1)));
|
89
|
-
break;
|
90
|
-
case 3:
|
91
|
-
shader->SetParameter(name, NUM2DBL(rb_ary_entry(arg, 0)),
|
92
|
-
NUM2DBL(rb_ary_entry(arg, 1)),
|
93
|
-
NUM2DBL(rb_ary_entry(arg, 2)));
|
94
|
-
break;
|
95
|
-
case 4:
|
96
|
-
shader->SetParameter(name, NUM2DBL(rb_ary_entry(arg, 0)),
|
97
|
-
NUM2DBL(rb_ary_entry(arg, 1)),
|
98
|
-
NUM2DBL(rb_ary_entry(arg, 2)),
|
99
|
-
NUM2DBL(rb_ary_entry(arg, 3)));
|
100
|
-
break;
|
101
|
-
default:
|
102
|
-
rb_raise(rb_eArgError, "Can't set vectors of %ld components",
|
103
|
-
RARRAY_LEN(arg));
|
104
|
-
break;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
else {
|
108
|
-
if (RAY_IS_A(arg, ray_cImage)) {
|
109
|
-
ray_image *img = ray_rb2image(arg);
|
110
|
-
if (img->is_image())
|
111
|
-
shader->SetTexture(name, img->image());
|
112
|
-
else
|
113
|
-
rb_raise(rb_eArgError, "Can't set the screen as a texture");
|
114
|
-
}
|
115
|
-
else if (arg == RAY_SYM("current"))
|
116
|
-
shader->SetTexture(name, sf::Shader::CurrentTexture);
|
117
|
-
else if (RAY_IS_A(arg, ray_cVector2))
|
118
|
-
shader->SetParameter(name, ray_convert_to_vector2(arg));
|
119
|
-
else if (RAY_IS_A(arg, ray_cVector3))
|
120
|
-
shader->SetParameter(name, ray_convert_to_vector3(arg));
|
121
|
-
else
|
122
|
-
shader->SetParameter(name, NUM2DBL(arg));
|
123
|
-
}
|
124
|
-
|
125
|
-
return arg;
|
126
|
-
}
|
127
|
-
|
128
|
-
VALUE ray_shader_ensure_unbind(VALUE self) {
|
129
|
-
ray_rb2shader(self)->Unbind();
|
130
|
-
return self;
|
131
|
-
}
|
132
|
-
|
133
|
-
/*
|
134
|
-
Binds the shader (for custom OpenGL drawing).
|
135
|
-
If a block is given, it is executed. The shader is then unbound.
|
136
|
-
*/
|
137
|
-
VALUE ray_shader_bind(VALUE self) {
|
138
|
-
ray_rb2shader(self)->Bind();
|
139
|
-
|
140
|
-
if (rb_block_given_p())
|
141
|
-
rb_ensure(rb_yield, Qnil, ray_shader_ensure_unbind, self);
|
142
|
-
|
143
|
-
return self;
|
144
|
-
}
|
145
|
-
|
146
|
-
/* Unbinds the shader (useful when doing custom OpenGL drawing) */
|
147
|
-
VALUE ray_shader_unbind(VALUE self) {
|
148
|
-
return ray_shader_ensure_unbind(self);
|
149
|
-
}
|
150
|
-
|
151
|
-
/*
|
152
|
-
Document-class: Ray::Shader
|
153
|
-
|
154
|
-
Class used to load OpenGL pixel shaders, which are written
|
155
|
-
in the GLSL language (a C-like language).
|
156
|
-
*/
|
157
|
-
|
158
|
-
void Init_ray_shader() {
|
159
|
-
ray_cShader = rb_define_class_under(ray_mRay, "Shader", rb_cObject);
|
160
|
-
rb_define_alloc_func(ray_cShader, ray_alloc_shader);
|
161
|
-
rb_define_method(ray_cShader, "initialize", ray_init_shader, 1);
|
162
|
-
|
163
|
-
rb_define_singleton_method(ray_cShader, "available?", ray_shader_available, 0);
|
164
|
-
|
165
|
-
rb_define_method(ray_cShader, "[]=", ray_shader_set, 2);
|
166
|
-
|
167
|
-
rb_define_method(ray_cShader, "bind", ray_shader_bind, 0);
|
168
|
-
rb_define_method(ray_cShader, "unbind", ray_shader_unbind, 0);
|
169
|
-
}
|
data/ext/shape.cpp
DELETED
@@ -1,409 +0,0 @@
|
|
1
|
-
#include "ray.hpp"
|
2
|
-
|
3
|
-
VALUE ray_cShape = Qnil;
|
4
|
-
|
5
|
-
void ray_free_shape(sf::Shape *shape) {
|
6
|
-
delete shape;
|
7
|
-
}
|
8
|
-
|
9
|
-
VALUE ray_alloc_shape(VALUE self) {
|
10
|
-
sf::Shape *shape = new sf::Shape;
|
11
|
-
return Data_Wrap_Struct(self, 0, ray_free_shape, shape);
|
12
|
-
}
|
13
|
-
|
14
|
-
sf::Shape *ray_rb2shape(VALUE self) {
|
15
|
-
if (!RAY_IS_A(self, ray_cShape)) {
|
16
|
-
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Shape",
|
17
|
-
RAY_OBJ_CLASSNAME(self));
|
18
|
-
}
|
19
|
-
|
20
|
-
sf::Shape *shape = NULL;
|
21
|
-
Data_Get_Struct(self, sf::Shape, shape);
|
22
|
-
|
23
|
-
return shape;
|
24
|
-
}
|
25
|
-
|
26
|
-
VALUE ray_shape2rb(const sf::Shape &shape) {
|
27
|
-
sf::Shape *copy = new sf::Shape(shape);
|
28
|
-
return Data_Wrap_Struct(ray_cShape, 0, ray_free_shape, copy);
|
29
|
-
}
|
30
|
-
|
31
|
-
VALUE ray_init_shape_copy(VALUE self, VALUE other) {
|
32
|
-
*ray_rb2shape(self) = *ray_rb2shape(other);
|
33
|
-
return self;
|
34
|
-
}
|
35
|
-
|
36
|
-
/*
|
37
|
-
@overload line(from, to, size = 1.0, color = Ray::Color.white,
|
38
|
-
outline_width = 0.0, outline_color = Ray::Color.none)
|
39
|
-
@param [Ray::Vector2, #to_vector2] from First point of the line
|
40
|
-
@param [Ray::Vector2, #to_vector2] to Last point of the line
|
41
|
-
|
42
|
-
@param [Float] size Width of the line
|
43
|
-
@param [Color] color Color of the line
|
44
|
-
|
45
|
-
@param [Float] outline_width Width of the outline
|
46
|
-
@param [Color] outline_color Color of the outline
|
47
|
-
|
48
|
-
@return [Shape] a line.
|
49
|
-
*/
|
50
|
-
VALUE ray_shape_line(int argc, VALUE *argv, VALUE self) {
|
51
|
-
VALUE from, to, size;
|
52
|
-
VALUE color;
|
53
|
-
VALUE outline_width, outline_color;
|
54
|
-
|
55
|
-
rb_scan_args(argc, argv, "24", &from, &to, &size, &color, &outline_width,
|
56
|
-
&outline_color);
|
57
|
-
|
58
|
-
ray_vector2 from_point = ray_convert_to_vector2(from);
|
59
|
-
ray_vector2 to_point = ray_convert_to_vector2(to);
|
60
|
-
|
61
|
-
float c_size = 1.0f;
|
62
|
-
if (!NIL_P(size)) c_size = (float)NUM2DBL(size);
|
63
|
-
|
64
|
-
float c_outline_width = 1.0f;
|
65
|
-
if (!NIL_P(outline_width)) c_outline_width = (float)NUM2DBL(outline_width);
|
66
|
-
|
67
|
-
ray_color sf_color(0, 0, 0);
|
68
|
-
if (!NIL_P(color)) sf_color = ray_rb2col(color);
|
69
|
-
|
70
|
-
ray_color sf_outline_color(0, 0, 0);
|
71
|
-
if (!NIL_P(outline_color)) sf_outline_color = ray_rb2col(outline_color);
|
72
|
-
|
73
|
-
return ray_shape2rb(sf::Shape::Line(from_point, to_point,
|
74
|
-
c_size, sf_color,
|
75
|
-
c_outline_width, sf_outline_color));
|
76
|
-
}
|
77
|
-
|
78
|
-
/*
|
79
|
-
@overload rectangle(rect, color = Ray::Color.white,
|
80
|
-
outline_width = 0.0, outline_color = Ray::Color.none)
|
81
|
-
@param [Ray::Rect, Array<Integer>] Rect used by this shape
|
82
|
-
@param [Color] color Color of the rect
|
83
|
-
@param [Float] outline_width (See Shape.line)
|
84
|
-
@param [Color] outline_color (See Shape.line)
|
85
|
-
|
86
|
-
@return [Shape] A rectangle.
|
87
|
-
*/
|
88
|
-
VALUE ray_shape_rectangle(int argc, VALUE *argv, VALUE self) {
|
89
|
-
VALUE rect, color, outline_width, outline_color;
|
90
|
-
rb_scan_args(argc, argv, "13", &rect, &color, &outline_width, &outline_color);
|
91
|
-
|
92
|
-
ray_rect c_rect = ray_convert_to_rect(rect);
|
93
|
-
|
94
|
-
ray_color c_color = ray_rb2col(color);
|
95
|
-
ray_color c_outline_color(0, 0, 0);
|
96
|
-
if (!NIL_P(outline_color))
|
97
|
-
c_outline_color = ray_rb2col(outline_color);
|
98
|
-
|
99
|
-
float c_outline_width = 0;
|
100
|
-
if (!NIL_P(outline_width))
|
101
|
-
c_outline_width = (float)NUM2DBL(outline_width);
|
102
|
-
|
103
|
-
return ray_shape2rb(sf::Shape::Rectangle(c_rect.Left, c_rect.Top,
|
104
|
-
c_rect.Width, c_rect.Height,
|
105
|
-
c_color, c_outline_width,
|
106
|
-
c_outline_color));
|
107
|
-
}
|
108
|
-
|
109
|
-
/*
|
110
|
-
@overload circle(center, radius, color = Ray::Color.white,
|
111
|
-
outline_width = 0.0, outline_color = Ray::Color.none)
|
112
|
-
@param [Ray::Vector2, #to_vector2] center Center of the circle
|
113
|
-
@param [Float] radius Radius of the circle.
|
114
|
-
@param [Color] color Color of the cirlce.
|
115
|
-
|
116
|
-
@param [Float] outline_width (See Shape.line)
|
117
|
-
@param [Color] outline_color (See Shape.line)
|
118
|
-
|
119
|
-
@return [Shape] A circle.
|
120
|
-
*/
|
121
|
-
VALUE ray_shape_circle(int argc, VALUE *argv, VALUE self) {
|
122
|
-
VALUE center, radius, color, outline_width, outline_color;
|
123
|
-
rb_scan_args(argc, argv, "23", ¢er, &radius, &color,
|
124
|
-
&outline_width, &outline_color);
|
125
|
-
|
126
|
-
ray_vector2 c_center = ray_convert_to_vector2(center);
|
127
|
-
float c_radius = (float)NUM2DBL(radius);
|
128
|
-
|
129
|
-
ray_color c_color = ray_rb2col(color);
|
130
|
-
ray_color c_outline_color(0, 0, 0);
|
131
|
-
if (!NIL_P(outline_color))
|
132
|
-
c_outline_color = ray_rb2col(outline_color);
|
133
|
-
|
134
|
-
float c_outline_width = 0;
|
135
|
-
if (!NIL_P(outline_width))
|
136
|
-
c_outline_width = (float)NUM2DBL(outline_width);
|
137
|
-
|
138
|
-
return ray_shape2rb(sf::Shape::Circle(c_center, c_radius,
|
139
|
-
c_color, c_outline_width,
|
140
|
-
c_outline_color));
|
141
|
-
}
|
142
|
-
|
143
|
-
/* @return [Ray::Vector2] Position of the shape */
|
144
|
-
VALUE ray_shape_pos(VALUE self) {
|
145
|
-
return ray_vector2_to_rb(ray_rb2shape(self)->GetPosition());
|
146
|
-
}
|
147
|
-
|
148
|
-
/* Sets the position of the shape */
|
149
|
-
VALUE ray_shape_set_pos(VALUE self, VALUE pos) {
|
150
|
-
rb_check_frozen(self);
|
151
|
-
ray_rb2shape(self)->SetPosition(ray_convert_to_vector2(pos));
|
152
|
-
return pos;
|
153
|
-
}
|
154
|
-
|
155
|
-
/*
|
156
|
-
@overload add_point(pos, color = Ray::Color.white, outline_color = Ray::Color.none)
|
157
|
-
Adds a new point to the shape.
|
158
|
-
|
159
|
-
@param [Ray::Vector2, #to_vector2] Position of the point.
|
160
|
-
@param [Color] color Color of the shape at that point.
|
161
|
-
@param [Color] outline_color Color of the outline at that point.
|
162
|
-
*/
|
163
|
-
VALUE ray_shape_add_point(int argc, VALUE *argv, VALUE self) {
|
164
|
-
rb_check_frozen(self);
|
165
|
-
|
166
|
-
sf::Shape *shape = ray_rb2shape(self);
|
167
|
-
|
168
|
-
VALUE rb_pos, rb_color, rb_outline_color;
|
169
|
-
|
170
|
-
ray_vector2 pos;
|
171
|
-
ray_color color(255, 255, 255), outline_color(255, 255, 255);
|
172
|
-
|
173
|
-
rb_scan_args(argc, argv, "12", &rb_pos, &rb_color, &rb_outline_color);
|
174
|
-
|
175
|
-
pos = ray_convert_to_vector2(rb_pos);
|
176
|
-
|
177
|
-
if (!NIL_P(rb_color))
|
178
|
-
color = ray_rb2col(rb_color);
|
179
|
-
|
180
|
-
if (!NIL_P(rb_outline_color))
|
181
|
-
outline_color = ray_rb2col(rb_outline_color);
|
182
|
-
|
183
|
-
shape->AddPoint(pos, color, outline_color);
|
184
|
-
return self;
|
185
|
-
}
|
186
|
-
|
187
|
-
/*
|
188
|
-
@return [Integer] the amount of points in this shape.
|
189
|
-
*/
|
190
|
-
VALUE ray_shape_point_count(VALUE self) {
|
191
|
-
sf::Shape *shape = ray_rb2shape(self);
|
192
|
-
return INT2FIX(shape->GetPointsCount());
|
193
|
-
}
|
194
|
-
|
195
|
-
/*
|
196
|
-
Sets whether the shape should be filled. Defaults to true.
|
197
|
-
*/
|
198
|
-
VALUE ray_shape_set_filled(VALUE self, VALUE val) {
|
199
|
-
rb_check_frozen(self);
|
200
|
-
|
201
|
-
sf::Shape *shape = ray_rb2shape(self);
|
202
|
-
shape->EnableFill(RTEST(val));
|
203
|
-
|
204
|
-
return val;
|
205
|
-
}
|
206
|
-
|
207
|
-
/*
|
208
|
-
Sets whether the outline of the shape should be drawn. Defaults to true.
|
209
|
-
*/
|
210
|
-
VALUE ray_shape_set_outlined(VALUE self, VALUE val) {
|
211
|
-
rb_check_frozen(self);
|
212
|
-
|
213
|
-
sf::Shape *shape = ray_rb2shape(self);
|
214
|
-
shape->EnableOutline(RTEST(val));
|
215
|
-
|
216
|
-
return val;
|
217
|
-
}
|
218
|
-
|
219
|
-
/*
|
220
|
-
@overload set_position_of(id, pos)
|
221
|
-
Changes the position of a point.
|
222
|
-
|
223
|
-
@param [Integer] id Id of the point to modify.
|
224
|
-
@param [Ray::Vector2, #to_vector2] pos New position of that point.
|
225
|
-
*/
|
226
|
-
VALUE ray_shape_set_position_of(VALUE self, VALUE id, VALUE pos) {
|
227
|
-
rb_check_frozen(self);
|
228
|
-
|
229
|
-
sf::Shape *shape = ray_rb2shape(self);
|
230
|
-
|
231
|
-
unsigned int c_id = NUM2UINT(id);
|
232
|
-
if (c_id >= shape->GetPointsCount())
|
233
|
-
rb_raise(rb_eArgError, "%d out of bounds", c_id);
|
234
|
-
|
235
|
-
shape->SetPointPosition(c_id, ray_convert_to_vector2(pos));
|
236
|
-
|
237
|
-
return pos;
|
238
|
-
}
|
239
|
-
|
240
|
-
/*
|
241
|
-
@overload set_color_of(id, col)
|
242
|
-
Changes the color of a point.
|
243
|
-
|
244
|
-
@param [Integer] id Id of the point to modify.
|
245
|
-
@param [Color] col New color of that point.
|
246
|
-
*/
|
247
|
-
VALUE ray_shape_set_color_of(VALUE self, VALUE id, VALUE col) {
|
248
|
-
rb_check_frozen(self);
|
249
|
-
|
250
|
-
sf::Shape *shape = ray_rb2shape(self);
|
251
|
-
|
252
|
-
unsigned int c_id = NUM2UINT(id);
|
253
|
-
if (c_id >= shape->GetPointsCount())
|
254
|
-
rb_raise(rb_eArgError, "%d out of bounds", c_id);
|
255
|
-
|
256
|
-
shape->SetPointColor(c_id, ray_rb2col(col));
|
257
|
-
return col;
|
258
|
-
}
|
259
|
-
|
260
|
-
/*
|
261
|
-
@overload set_outline_of(id, col)
|
262
|
-
Changes the outline color of a point.
|
263
|
-
|
264
|
-
@param [Integer] id Id of the point to modify.
|
265
|
-
@param [Color] col New outline color of that point.
|
266
|
-
*/
|
267
|
-
VALUE ray_shape_set_outline_of(VALUE self, VALUE id, VALUE col) {
|
268
|
-
rb_check_frozen(self);
|
269
|
-
|
270
|
-
sf::Shape *shape = ray_rb2shape(self);
|
271
|
-
|
272
|
-
unsigned int c_id = NUM2UINT(id);
|
273
|
-
if (c_id >= shape->GetPointsCount())
|
274
|
-
rb_raise(rb_eArgError, "%d out of bounds", c_id);
|
275
|
-
|
276
|
-
shape->SetPointOutlineColor(c_id, ray_rb2col(col));
|
277
|
-
return col;
|
278
|
-
}
|
279
|
-
|
280
|
-
/*
|
281
|
-
Sets the width of the outline of this shape.
|
282
|
-
*/
|
283
|
-
VALUE ray_shape_set_outline_width(VALUE self, VALUE width) {
|
284
|
-
rb_check_frozen(self);
|
285
|
-
|
286
|
-
sf::Shape *shape = ray_rb2shape(self);
|
287
|
-
shape->SetOutlineThickness(NUM2INT(width));
|
288
|
-
|
289
|
-
return width;
|
290
|
-
}
|
291
|
-
|
292
|
-
/*
|
293
|
-
@overload position_of(id)
|
294
|
-
@return [Ray::Vector2] Position of that point.
|
295
|
-
*/
|
296
|
-
VALUE ray_shape_position_of(VALUE self, VALUE id) {
|
297
|
-
sf::Shape *shape = ray_rb2shape(self);
|
298
|
-
|
299
|
-
unsigned int c_id = NUM2UINT(id);
|
300
|
-
if (c_id >= shape->GetPointsCount())
|
301
|
-
return Qnil;
|
302
|
-
|
303
|
-
sf::Vector2f point = shape->GetPointPosition(c_id);
|
304
|
-
return ray_vector2_to_rb(point);
|
305
|
-
}
|
306
|
-
|
307
|
-
/*
|
308
|
-
@overload color_of(id)
|
309
|
-
@return [Color] Color of that point.
|
310
|
-
*/
|
311
|
-
VALUE ray_shape_color_of(VALUE self, VALUE id) {
|
312
|
-
sf::Shape *shape = ray_rb2shape(self);
|
313
|
-
|
314
|
-
unsigned int c_id = NUM2UINT(id);
|
315
|
-
if (c_id >= shape->GetPointsCount())
|
316
|
-
return Qnil;
|
317
|
-
|
318
|
-
return ray_col2rb(shape->GetPointColor(c_id));
|
319
|
-
}
|
320
|
-
|
321
|
-
/*
|
322
|
-
@overload outline_of(id)
|
323
|
-
@return [Color] Outline of that point.
|
324
|
-
*/
|
325
|
-
VALUE ray_shape_outline_of(VALUE self, VALUE id) {
|
326
|
-
sf::Shape *shape = ray_rb2shape(self);
|
327
|
-
|
328
|
-
unsigned int c_id = NUM2UINT(id);
|
329
|
-
if (c_id >= shape->GetPointsCount())
|
330
|
-
return Qnil;
|
331
|
-
|
332
|
-
return ray_col2rb(shape->GetPointOutlineColor(c_id));
|
333
|
-
}
|
334
|
-
|
335
|
-
/* @return [Float] Outline width of this shape */
|
336
|
-
VALUE ray_shape_outline_width(VALUE self) {
|
337
|
-
sf::Shape *shape = ray_rb2shape(self);
|
338
|
-
return INT2FIX((int)(shape->GetOutlineThickness()));
|
339
|
-
}
|
340
|
-
|
341
|
-
/* @return [Float] Rotation applied to this shape when it is drawn (in degrees) */
|
342
|
-
VALUE ray_shape_angle(VALUE self) {
|
343
|
-
sf::Shape *shape = ray_rb2shape(self);
|
344
|
-
return rb_float_new(shape->GetRotation());
|
345
|
-
}
|
346
|
-
|
347
|
-
/* Sets the rotation applied to this object when it is drawn (in degrees) */
|
348
|
-
VALUE ray_shape_set_angle(VALUE self, VALUE angle) {
|
349
|
-
rb_check_frozen(self);
|
350
|
-
|
351
|
-
sf::Shape *shape = ray_rb2shape(self);
|
352
|
-
shape->SetRotation((float)NUM2DBL(angle));
|
353
|
-
|
354
|
-
return angle;
|
355
|
-
}
|
356
|
-
|
357
|
-
/* @return [Ray::Vector2] scale for width and height. */
|
358
|
-
VALUE ray_shape_scale(VALUE self) {
|
359
|
-
sf::Shape *shape = ray_rb2shape(self);
|
360
|
-
sf::Vector2f scale(shape->GetScale());
|
361
|
-
|
362
|
-
return ray_vector2_to_rb(scale);
|
363
|
-
}
|
364
|
-
|
365
|
-
/* Sets scale for width and height, using a vector. */
|
366
|
-
VALUE ray_shape_set_scale(VALUE self, VALUE val) {
|
367
|
-
rb_check_frozen(self);
|
368
|
-
|
369
|
-
sf::Shape *shape = ray_rb2shape(self);
|
370
|
-
shape->SetScale(ray_convert_to_vector2(val));
|
371
|
-
|
372
|
-
return val;
|
373
|
-
}
|
374
|
-
|
375
|
-
void Init_ray_shape() {
|
376
|
-
ray_cShape = rb_define_class_under(ray_mRay, "Shape", rb_cObject);
|
377
|
-
rb_define_alloc_func(ray_cShape, ray_alloc_shape);
|
378
|
-
rb_define_method(ray_cShape, "initialize_copy", ray_init_shape_copy, 1);
|
379
|
-
|
380
|
-
rb_define_singleton_method(ray_cShape, "line", ray_shape_line, -1);
|
381
|
-
rb_define_singleton_method(ray_cShape, "rectangle", ray_shape_rectangle, -1);
|
382
|
-
rb_define_singleton_method(ray_cShape, "circle", ray_shape_circle, -1);
|
383
|
-
|
384
|
-
rb_define_method(ray_cShape, "pos", ray_shape_pos, 0);
|
385
|
-
rb_define_method(ray_cShape, "pos=", ray_shape_set_pos, 1);
|
386
|
-
|
387
|
-
rb_define_method(ray_cShape, "add_point", ray_shape_add_point, -1);
|
388
|
-
rb_define_method(ray_cShape, "point_count", ray_shape_point_count, 0);
|
389
|
-
|
390
|
-
rb_define_method(ray_cShape, "filled=", ray_shape_set_filled, 1);
|
391
|
-
rb_define_method(ray_cShape, "outlined=", ray_shape_set_outlined, 1);
|
392
|
-
|
393
|
-
rb_define_method(ray_cShape, "outline_width=", ray_shape_set_outline_width, 1);
|
394
|
-
rb_define_method(ray_cShape, "outline_width", ray_shape_outline_width, 0);
|
395
|
-
|
396
|
-
rb_define_method(ray_cShape, "set_position_of", ray_shape_set_position_of, 2);
|
397
|
-
rb_define_method(ray_cShape, "set_color_of", ray_shape_set_color_of, 2);
|
398
|
-
rb_define_method(ray_cShape, "set_outline_of", ray_shape_set_outline_of, 2);
|
399
|
-
|
400
|
-
rb_define_method(ray_cShape, "position_of", ray_shape_position_of, 1);
|
401
|
-
rb_define_method(ray_cShape, "color_of", ray_shape_color_of, 1);
|
402
|
-
rb_define_method(ray_cShape, "outline_of", ray_shape_outline_of, 1);
|
403
|
-
|
404
|
-
rb_define_method(ray_cShape, "angle", ray_shape_angle, 0);
|
405
|
-
rb_define_method(ray_cShape, "angle=", ray_shape_set_angle, 1);
|
406
|
-
|
407
|
-
rb_define_method(ray_cShape, "scale", ray_shape_scale, 0);
|
408
|
-
rb_define_method(ray_cShape, "scale=", ray_shape_set_scale, 1);
|
409
|
-
}
|