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/font.cpp
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
#include "ray.hpp"
|
2
|
-
|
3
|
-
typedef struct {
|
4
|
-
unsigned long style;
|
5
|
-
int font_size;
|
6
|
-
} ray_font_style;
|
7
|
-
|
8
|
-
VALUE ray_cFont = Qnil;
|
9
|
-
|
10
|
-
void ray_free_font(ray_font *font) {
|
11
|
-
delete font;
|
12
|
-
}
|
13
|
-
|
14
|
-
VALUE ray_font2rb(const ray_font &font) {
|
15
|
-
ray_font *ptr = new ray_font(font);
|
16
|
-
return Data_Wrap_Struct(ray_cFont, 0, ray_free_font, ptr);
|
17
|
-
}
|
18
|
-
|
19
|
-
ray_font *ray_rb2font(VALUE object) {
|
20
|
-
if (!RAY_IS_A(object, ray_cFont)) {
|
21
|
-
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Font",
|
22
|
-
RAY_OBJ_CLASSNAME(object));
|
23
|
-
}
|
24
|
-
|
25
|
-
ray_font *ptr = NULL;
|
26
|
-
Data_Get_Struct(object, ray_font, ptr);
|
27
|
-
|
28
|
-
return ptr;
|
29
|
-
}
|
30
|
-
|
31
|
-
VALUE ray_alloc_font(VALUE self) {
|
32
|
-
ray_font *ptr = new ray_font;
|
33
|
-
VALUE ret = Data_Wrap_Struct(self, 0, ray_free_font, ptr);
|
34
|
-
|
35
|
-
return ret;
|
36
|
-
}
|
37
|
-
|
38
|
-
/* @return [Ray::Font] The default font */
|
39
|
-
VALUE ray_font_default(VALUE self) {
|
40
|
-
return ray_font2rb(sf::Font::GetDefaultFont());
|
41
|
-
}
|
42
|
-
|
43
|
-
void ray_init_font_with_filename(VALUE self, VALUE filename) {
|
44
|
-
ray_font *font = NULL;
|
45
|
-
Data_Get_Struct(self, ray_font, font);
|
46
|
-
|
47
|
-
if (!font->LoadFromFile(StringValuePtr(filename))) {
|
48
|
-
rb_raise(rb_eRuntimeError, "Could not load the font");
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
void ray_init_font_with_io(VALUE self, VALUE io) {
|
53
|
-
ray_font *font = NULL;
|
54
|
-
Data_Get_Struct(self, ray_font, font);
|
55
|
-
|
56
|
-
VALUE string = rb_funcall2(io, RAY_METH("read"), 0, NULL);
|
57
|
-
char *content = StringValuePtr(string);
|
58
|
-
|
59
|
-
if (!font->LoadFromMemory(content, (int)RSTRING_LEN(string))) {
|
60
|
-
rb_raise(rb_eRuntimeError, "Could not load the font");
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
/*
|
65
|
-
Creates a new font.
|
66
|
-
@param [String, #read] arg Filename or IO object.
|
67
|
-
*/
|
68
|
-
VALUE ray_init_font(VALUE self, VALUE arg) {
|
69
|
-
if (rb_respond_to(arg, RAY_METH("to_str")))
|
70
|
-
ray_init_font_with_filename(self, rb_String(arg));
|
71
|
-
else if (rb_respond_to(arg, RAY_METH("read")))
|
72
|
-
ray_init_font_with_io(self, arg);
|
73
|
-
else {
|
74
|
-
rb_raise(rb_eTypeError, "Can't convert %s into String",
|
75
|
-
RAY_OBJ_CLASSNAME(arg));
|
76
|
-
}
|
77
|
-
|
78
|
-
return Qnil;
|
79
|
-
}
|
80
|
-
|
81
|
-
ray_font_style ray_parse_font_style(VALUE opts) {
|
82
|
-
ray_font_style style;
|
83
|
-
|
84
|
-
VALUE font_size = rb_hash_aref(opts, RAY_SYM("size"));
|
85
|
-
if (!NIL_P(font_size))
|
86
|
-
style.font_size = NUM2INT(font_size);
|
87
|
-
else
|
88
|
-
rb_raise(rb_eArgError, "Character size not specified");
|
89
|
-
|
90
|
-
style.style = sf::Text::Regular;
|
91
|
-
VALUE font_style = Qnil;
|
92
|
-
if (!NIL_P(font_style = rb_hash_aref(opts, RAY_SYM("style"))))
|
93
|
-
style.style = NUM2INT(font_style);
|
94
|
-
|
95
|
-
return style;
|
96
|
-
}
|
97
|
-
|
98
|
-
/* @return [Integer] the recommended spacing between lines for this font */
|
99
|
-
VALUE ray_font_line_skip(VALUE self, VALUE size) {
|
100
|
-
ray_font *font = ray_rb2font(self);
|
101
|
-
return INT2FIX(font->GetLineSpacing(NUM2INT(size)));
|
102
|
-
}
|
103
|
-
|
104
|
-
VALUE ray_font_simple_size_of(VALUE self, VALUE str, VALUE opts) {
|
105
|
-
ray_font *font = ray_rb2font(self);
|
106
|
-
ray_font_style style = ray_parse_font_style(opts);
|
107
|
-
|
108
|
-
char *c_str = StringValuePtr(str);
|
109
|
-
sf::String string((uint32_t*)c_str);
|
110
|
-
|
111
|
-
sf::Text text(string, *font);
|
112
|
-
text.SetStyle(style.style);
|
113
|
-
text.SetCharacterSize(style.font_size);
|
114
|
-
|
115
|
-
ray_rect rect = RAY_RECT(text.GetRect());
|
116
|
-
return ray_vector2_to_rb(sf::Vector2f(rect.Width, rect.Height));
|
117
|
-
}
|
118
|
-
|
119
|
-
VALUE ray_font_simple_draw(VALUE self, VALUE str, VALUE hash) {
|
120
|
-
ray_font *font = ray_rb2font(self);
|
121
|
-
ray_font_style style = ray_parse_font_style(hash);
|
122
|
-
|
123
|
-
VALUE rb_color = rb_hash_aref(hash, RAY_SYM("color"));
|
124
|
-
ray_color c_color(255, 255, 255, 255);
|
125
|
-
if (!NIL_P(rb_color))
|
126
|
-
c_color = ray_rb2col(rb_color);
|
127
|
-
|
128
|
-
char *c_str = StringValuePtr(str);
|
129
|
-
sf::String string((uint32_t*)c_str);
|
130
|
-
|
131
|
-
sf::Text text(string, *font);
|
132
|
-
text.SetStyle(style.style);
|
133
|
-
text.SetCharacterSize(style.font_size);
|
134
|
-
text.SetColor(c_color);
|
135
|
-
|
136
|
-
ray_rect rect = RAY_RECT(text.GetRect());
|
137
|
-
|
138
|
-
ray_vector2 pos(0, 0);
|
139
|
-
VALUE rb_pos = rb_hash_aref(hash, RAY_SYM("at"));
|
140
|
-
if (NIL_P(rb_pos))
|
141
|
-
rb_pos = rb_hash_aref(hash, RAY_SYM("to"));
|
142
|
-
if (!NIL_P(rb_pos))
|
143
|
-
pos = ray_convert_to_vector2(rb_pos);
|
144
|
-
|
145
|
-
text.SetPosition(pos.x, pos.y);
|
146
|
-
|
147
|
-
VALUE on = rb_hash_aref(hash, RAY_SYM("on"));
|
148
|
-
if (NIL_P(on)) {
|
149
|
-
VALUE image_hash = rb_hash_new();
|
150
|
-
rb_hash_aset(image_hash, RAY_SYM("width"), INT2FIX(rect.Width));
|
151
|
-
rb_hash_aset(image_hash, RAY_SYM("height"), INT2FIX(rect.Height));
|
152
|
-
|
153
|
-
on = rb_funcall(ray_cImage, RAY_METH("new"), 1, image_hash);
|
154
|
-
}
|
155
|
-
|
156
|
-
ray_image *image = ray_rb2image(on);
|
157
|
-
image->draw(text);
|
158
|
-
|
159
|
-
return on;
|
160
|
-
}
|
161
|
-
|
162
|
-
/*
|
163
|
-
Doucment-class: Ray::Font
|
164
|
-
|
165
|
-
Class used to draw text.
|
166
|
-
It can render text on an image:
|
167
|
-
font.draw("Hello world!", :on => image, :at => [10, 20]) # => image
|
168
|
-
Or create a new image containing the text, to use it later (which is
|
169
|
-
potentially better than rendering the same string a great amount of
|
170
|
-
times):
|
171
|
-
font.draw("Hello world!") # => a new image
|
172
|
-
*/
|
173
|
-
|
174
|
-
void Init_ray_font() {
|
175
|
-
ray_cFont = rb_define_class_under(ray_mRay, "Font", rb_cObject);
|
176
|
-
rb_define_alloc_func(ray_cFont, ray_alloc_font);
|
177
|
-
rb_define_method(ray_cFont, "initialize", ray_init_font, 1);
|
178
|
-
|
179
|
-
rb_define_singleton_method(ray_cFont, "default", ray_font_default, 0);
|
180
|
-
|
181
|
-
rb_define_method(ray_cFont, "line_skip", ray_font_line_skip, 1);
|
182
|
-
rb_define_method(ray_cFont, "simple_size_of", ray_font_simple_size_of, 2);
|
183
|
-
|
184
|
-
rb_define_method(ray_cFont, "simple_draw", ray_font_simple_draw, 2);
|
185
|
-
|
186
|
-
rb_define_const(ray_cFont, "STYLE_NORMAL", INT2FIX(sf::Text::Regular));
|
187
|
-
rb_define_const(ray_cFont, "STYLE_ITALIC", INT2FIX(sf::Text::Italic));
|
188
|
-
rb_define_const(ray_cFont, "STYLE_BOLD", INT2FIX(sf::Text::Bold));
|
189
|
-
rb_define_const(ray_cFont, "STYLE_UNDERLINE", INT2FIX(sf::Text::Underlined));
|
190
|
-
}
|
data/ext/image.cpp
DELETED
@@ -1,733 +0,0 @@
|
|
1
|
-
#include "ray.hpp"
|
2
|
-
|
3
|
-
VALUE ray_cImage = Qnil;
|
4
|
-
|
5
|
-
ray_image::ray_image(bool should_be_screen):
|
6
|
-
is_screen(should_be_screen),
|
7
|
-
pixel_modifier(NULL)
|
8
|
-
{}
|
9
|
-
|
10
|
-
ray_image::~ray_image() {
|
11
|
-
if (pixel_modifier) delete pixel_modifier;
|
12
|
-
}
|
13
|
-
|
14
|
-
bool ray_image::create_with_size(int w, int h) {
|
15
|
-
return render_image.Create(w, h);
|
16
|
-
}
|
17
|
-
|
18
|
-
bool ray_image::create_with_filename(const std::string &filename) {
|
19
|
-
sf::Image temp_image;
|
20
|
-
if (!temp_image.LoadFromFile(filename))
|
21
|
-
return false;
|
22
|
-
|
23
|
-
sf::Sprite temp_sprite(temp_image);
|
24
|
-
|
25
|
-
if (!create_with_size(temp_image.GetWidth(), temp_image.GetHeight()))
|
26
|
-
return false;
|
27
|
-
|
28
|
-
render_image.Draw(temp_sprite);
|
29
|
-
sprite.SetImage(render_image.GetImage());
|
30
|
-
|
31
|
-
update();
|
32
|
-
|
33
|
-
return true;
|
34
|
-
}
|
35
|
-
|
36
|
-
bool ray_image::create_with_io(VALUE io) {
|
37
|
-
VALUE string = rb_funcall2(io, RAY_METH("read"), 0, NULL);
|
38
|
-
char *content = StringValuePtr(string);
|
39
|
-
|
40
|
-
sf::Image temp_image;
|
41
|
-
if (!temp_image.LoadFromMemory(content, RSTRING_LEN(string)))
|
42
|
-
return false;
|
43
|
-
|
44
|
-
sf::Sprite temp_sprite(temp_image);
|
45
|
-
|
46
|
-
if (!create_with_size(temp_image.GetWidth(), temp_image.GetHeight()))
|
47
|
-
return false;
|
48
|
-
|
49
|
-
render_image.Draw(temp_sprite);
|
50
|
-
sprite.SetImage(render_image.GetImage());
|
51
|
-
|
52
|
-
update();
|
53
|
-
|
54
|
-
return true;
|
55
|
-
}
|
56
|
-
|
57
|
-
bool ray_image::create_with_image(ray_image &src) {
|
58
|
-
sf::Sprite &src_sprite = src.get_sprite();
|
59
|
-
sf::Vector2f size = src_sprite.GetSize();
|
60
|
-
|
61
|
-
if (!create_with_size(src.width(), src.height()))
|
62
|
-
return false;
|
63
|
-
|
64
|
-
draw_image(src, ray_rect(0, 0, src.width(), src.height()),
|
65
|
-
ray_vector2(0, 0),
|
66
|
-
0.f, ray_vector2(1.f, 1.f));
|
67
|
-
update();
|
68
|
-
|
69
|
-
return true;
|
70
|
-
}
|
71
|
-
|
72
|
-
bool ray_image::save_as(const std::string &filename) const {
|
73
|
-
if (is_screen) {
|
74
|
-
sf::Image screen_copy;
|
75
|
-
|
76
|
-
if (!screen_copy.CopyScreen(ray_screen, sf::IntRect(0, 0, width(),
|
77
|
-
height()))) {
|
78
|
-
return false;
|
79
|
-
}
|
80
|
-
|
81
|
-
return screen_copy.SaveToFile(filename);
|
82
|
-
}
|
83
|
-
else {
|
84
|
-
return render_image.GetImage().SaveToFile(filename);
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
int ray_image::width() const { return target().GetWidth(); }
|
89
|
-
int ray_image::height() const { return target().GetHeight(); }
|
90
|
-
|
91
|
-
void ray_image::update() {
|
92
|
-
if (is_screen)
|
93
|
-
ray_screen.Display();
|
94
|
-
else
|
95
|
-
render_image.Display();
|
96
|
-
}
|
97
|
-
|
98
|
-
void ray_image::fill(sf::Color color) {
|
99
|
-
target().Clear(color);
|
100
|
-
}
|
101
|
-
|
102
|
-
void ray_image::draw(const sf::Drawable &drawable,
|
103
|
-
sf::Shader *shader) {
|
104
|
-
if (shader)
|
105
|
-
target().Draw(drawable, *shader);
|
106
|
-
else
|
107
|
-
target().Draw(drawable);
|
108
|
-
}
|
109
|
-
|
110
|
-
void ray_image::draw_image(ray_image &image,
|
111
|
-
const ray_rect &src_rect,
|
112
|
-
const ray_vector2 &dest_pos,
|
113
|
-
float angle, const ray_vector2 &zoom,
|
114
|
-
sf::Shader *shader,
|
115
|
-
const ray_color &color) {
|
116
|
-
sf::Image screen_copy;
|
117
|
-
|
118
|
-
if (image.is_screen) {
|
119
|
-
if (!screen_copy.CopyScreen(ray_screen, sf::IntRect(0, 0, image.width(),
|
120
|
-
image.height()))) {
|
121
|
-
return;
|
122
|
-
}
|
123
|
-
|
124
|
-
sprite = sf::Sprite(screen_copy);
|
125
|
-
}
|
126
|
-
else {
|
127
|
-
sprite = sf::Sprite(image.render_image.GetImage());
|
128
|
-
}
|
129
|
-
|
130
|
-
sprite.SetSubRect(RAY_INT_RECT(src_rect));
|
131
|
-
|
132
|
-
sprite.SetPosition(dest_pos);
|
133
|
-
|
134
|
-
sprite.SetScale(zoom);
|
135
|
-
sprite.SetRotation(angle);
|
136
|
-
|
137
|
-
sprite.SetColor(color);
|
138
|
-
|
139
|
-
if (!shader)
|
140
|
-
target().Draw(sprite);
|
141
|
-
else
|
142
|
-
target().Draw(sprite, *shader);
|
143
|
-
}
|
144
|
-
|
145
|
-
ray_color ray_image::at(int x, int y) const {
|
146
|
-
if (pixel_modifier)
|
147
|
-
return pixel_modifier->GetPixel(x, y);
|
148
|
-
|
149
|
-
if (is_screen) {
|
150
|
-
sf::Image img;
|
151
|
-
img.CopyScreen(ray_screen, sf::IntRect(x, y, 1, 1));
|
152
|
-
return img.GetPixel(0, 0);
|
153
|
-
}
|
154
|
-
|
155
|
-
return render_image.GetImage().GetPixel(x, y);
|
156
|
-
}
|
157
|
-
|
158
|
-
bool ray_image::set_at(int x, int y, const ray_color &color) {
|
159
|
-
if (!pixel_modifier) return false;
|
160
|
-
|
161
|
-
pixel_modifier->SetPixel(x, y, color);
|
162
|
-
return true;
|
163
|
-
}
|
164
|
-
|
165
|
-
const uint8_t *ray_image::pixels() const {
|
166
|
-
return render_image.GetImage().GetPixelsPtr();
|
167
|
-
}
|
168
|
-
|
169
|
-
ray_rect ray_image::clip() const {
|
170
|
-
sf::FloatRect rect = target().GetView().GetViewport();
|
171
|
-
return ray_rect(rect.Left * width(), rect.Top * height(),
|
172
|
-
rect.Width * width(), rect.Height * height());
|
173
|
-
}
|
174
|
-
|
175
|
-
void ray_image::set_clip(const ray_rect &other) {
|
176
|
-
sf::FloatRect rect(other.Left / (float)width(),
|
177
|
-
other.Top / (float)height(),
|
178
|
-
other.Width / (float)width(),
|
179
|
-
other.Height / (float)height());
|
180
|
-
sf::View view(target().GetDefaultView());
|
181
|
-
view.SetViewport(rect);
|
182
|
-
|
183
|
-
target().SetView(view);
|
184
|
-
}
|
185
|
-
|
186
|
-
bool ray_image::lock() {
|
187
|
-
if (pixel_modifier) return true;
|
188
|
-
|
189
|
-
if (is_screen) {
|
190
|
-
pixel_modifier = new sf::Image;
|
191
|
-
|
192
|
-
if (!pixel_modifier->CopyScreen(ray_screen,
|
193
|
-
sf::IntRect(0, 0, width(), height()))) {
|
194
|
-
delete pixel_modifier;
|
195
|
-
pixel_modifier = NULL;
|
196
|
-
|
197
|
-
return false;
|
198
|
-
}
|
199
|
-
}
|
200
|
-
else
|
201
|
-
pixel_modifier = new sf::Image(render_image.GetImage());
|
202
|
-
|
203
|
-
return true;
|
204
|
-
}
|
205
|
-
|
206
|
-
void ray_image::unlock() {
|
207
|
-
if (!pixel_modifier) return;
|
208
|
-
|
209
|
-
target().Clear(ray_color(0, 0, 0, 0));
|
210
|
-
sf::Sprite tmp_sprite(*pixel_modifier);
|
211
|
-
target().Draw(tmp_sprite);
|
212
|
-
|
213
|
-
delete pixel_modifier;
|
214
|
-
pixel_modifier = NULL;
|
215
|
-
}
|
216
|
-
|
217
|
-
void ray_image::activate() {
|
218
|
-
if (is_screen)
|
219
|
-
ray_screen.SetActive();
|
220
|
-
else
|
221
|
-
render_image.SetActive();
|
222
|
-
}
|
223
|
-
|
224
|
-
void ray_image::bind() {
|
225
|
-
render_image.GetImage().Bind();
|
226
|
-
}
|
227
|
-
|
228
|
-
bool ray_image::is_image() const {
|
229
|
-
return !is_screen;
|
230
|
-
}
|
231
|
-
|
232
|
-
const sf::Image &ray_image::image() const {
|
233
|
-
return render_image.GetImage();
|
234
|
-
}
|
235
|
-
|
236
|
-
bool ray_image::operator==(const ray_image &other) const {
|
237
|
-
return (&(target()) == &(other.target()));
|
238
|
-
}
|
239
|
-
|
240
|
-
sf::RenderTarget &ray_image::target() {
|
241
|
-
return is_screen ? (sf::RenderTarget&)ray_screen :
|
242
|
-
(sf::RenderTarget&)render_image;
|
243
|
-
}
|
244
|
-
|
245
|
-
const sf::RenderTarget &ray_image::target() const {
|
246
|
-
return is_screen ? (sf::RenderTarget&)ray_screen :
|
247
|
-
(sf::RenderTarget&)render_image;
|
248
|
-
}
|
249
|
-
|
250
|
-
ray_image *ray_rb2image(VALUE object) {
|
251
|
-
if (!RAY_IS_A(object, ray_cImage)) {
|
252
|
-
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Image",
|
253
|
-
RAY_OBJ_CLASSNAME(object));
|
254
|
-
}
|
255
|
-
|
256
|
-
ray_image *ptr = NULL;
|
257
|
-
Data_Get_Struct(object, ray_image, ptr);
|
258
|
-
|
259
|
-
return ptr;
|
260
|
-
}
|
261
|
-
|
262
|
-
/*
|
263
|
-
@return [true, false] True if it is possible to draw on an image.
|
264
|
-
If this is false, many methods won't work as expected.
|
265
|
-
*/
|
266
|
-
VALUE ray_image_available(VALUE self) {
|
267
|
-
return sf::RenderImage::IsAvailable() ? Qtrue : Qfalse;
|
268
|
-
}
|
269
|
-
|
270
|
-
void ray_init_image_with_hash(VALUE self, VALUE arg) {
|
271
|
-
VALUE width = rb_hash_aref(arg, RAY_SYM("width"));
|
272
|
-
if (NIL_P(width)) width = rb_hash_aref(arg, RAY_SYM("w"));
|
273
|
-
|
274
|
-
VALUE height = rb_hash_aref(arg, RAY_SYM("height"));
|
275
|
-
if (NIL_P(height)) height = rb_hash_aref(arg, RAY_SYM("h"));
|
276
|
-
|
277
|
-
ray_image *image = ray_rb2image(self);
|
278
|
-
bool res = image->create_with_size(NUM2INT(width), NUM2INT(height));
|
279
|
-
|
280
|
-
if (!res)
|
281
|
-
rb_raise(rb_eRuntimeError, "Could not create the image");
|
282
|
-
}
|
283
|
-
|
284
|
-
void ray_init_image_with_filename(VALUE self, VALUE filename) {
|
285
|
-
char *c_filename = StringValuePtr(filename);
|
286
|
-
ray_image *image = ray_rb2image(self);
|
287
|
-
|
288
|
-
if (!image->create_with_filename(c_filename))
|
289
|
-
rb_raise(rb_eRuntimeError, "Could not create the image");
|
290
|
-
}
|
291
|
-
|
292
|
-
void ray_init_image_with_io(VALUE self, VALUE io) {
|
293
|
-
ray_image *image = ray_rb2image(self);
|
294
|
-
if (!image->create_with_io(io))
|
295
|
-
rb_raise(rb_eRuntimeError, "Could not create the image");
|
296
|
-
}
|
297
|
-
|
298
|
-
/*
|
299
|
-
Creates a new image.
|
300
|
-
|
301
|
-
@overload initialize(hash)
|
302
|
-
@option hash [Integer] :width Width of the surface
|
303
|
-
@option hash [Integer] :height Height of the surface
|
304
|
-
|
305
|
-
@option hash [Integer] :w Alias for width
|
306
|
-
@option hash [Integer] :h Alias for height
|
307
|
-
|
308
|
-
@overload initialize(filename)
|
309
|
-
Loads the image from a file.
|
310
|
-
@param [String, #to_str] filename The name of the file to open
|
311
|
-
|
312
|
-
@overload initialize(io)
|
313
|
-
Loads the image friom an IO object.
|
314
|
-
@param [IO, #read] io Object the data will be loaded from.
|
315
|
-
*/
|
316
|
-
VALUE ray_init_image(VALUE self, VALUE arg) {
|
317
|
-
if (RAY_IS_A(arg, rb_cHash))
|
318
|
-
ray_init_image_with_hash(self, arg);
|
319
|
-
else if (rb_respond_to(arg, RAY_METH("to_str")))
|
320
|
-
ray_init_image_with_filename(self, rb_String(arg));
|
321
|
-
else if (rb_respond_to(arg, RAY_METH("read")))
|
322
|
-
ray_init_image_with_io(self, arg);
|
323
|
-
else {
|
324
|
-
rb_raise(rb_eTypeError, "Can't convert %s into Hash",
|
325
|
-
RAY_OBJ_CLASSNAME(arg));
|
326
|
-
}
|
327
|
-
|
328
|
-
return Qnil;
|
329
|
-
}
|
330
|
-
|
331
|
-
VALUE ray_init_image_copy(VALUE self, VALUE obj) {
|
332
|
-
ray_image *img = ray_rb2image(self);
|
333
|
-
ray_image *src = ray_rb2image(obj);
|
334
|
-
|
335
|
-
if (!img->create_with_image(*src))
|
336
|
-
rb_raise(rb_eRuntimeError, "Could not create the image");
|
337
|
-
|
338
|
-
return self;
|
339
|
-
}
|
340
|
-
|
341
|
-
void ray_free_image(ray_image *ptr) {
|
342
|
-
delete ptr;
|
343
|
-
}
|
344
|
-
|
345
|
-
VALUE ray_alloc_image(VALUE self) {
|
346
|
-
ray_image *ptr = new ray_image(false);
|
347
|
-
VALUE ret = Data_Wrap_Struct(self, 0, ray_free_image, ptr);
|
348
|
-
|
349
|
-
return ret;
|
350
|
-
}
|
351
|
-
|
352
|
-
VALUE ray_create_screen() {
|
353
|
-
ray_image *ptr = new ray_image(true);
|
354
|
-
VALUE ret = Data_Wrap_Struct(ray_cImage, 0, ray_free_image, ptr);
|
355
|
-
|
356
|
-
return ret;
|
357
|
-
}
|
358
|
-
|
359
|
-
/*
|
360
|
-
@overload save_as(filename)
|
361
|
-
Saves the image in a file.
|
362
|
-
*/
|
363
|
-
VALUE ray_image_save_as(VALUE self, VALUE filename) {
|
364
|
-
if (!ray_rb2image(self)->save_as(StringValuePtr(filename))) {
|
365
|
-
rb_raise(rb_eRuntimeError, "Couldn't save image to file");
|
366
|
-
}
|
367
|
-
|
368
|
-
return self;
|
369
|
-
}
|
370
|
-
|
371
|
-
/*
|
372
|
-
@overload fill(col)
|
373
|
-
Fills the image with a given color.
|
374
|
-
@param [Ray::Color] col The color used to fill the image.
|
375
|
-
*/
|
376
|
-
VALUE ray_image_fill(VALUE self, VALUE col) {
|
377
|
-
rb_check_frozen(self);
|
378
|
-
|
379
|
-
ray_image *img = ray_rb2image(self);
|
380
|
-
img->fill(ray_rb2col(col));
|
381
|
-
|
382
|
-
return self;
|
383
|
-
}
|
384
|
-
|
385
|
-
/* Updates the image. */
|
386
|
-
VALUE ray_image_flip(VALUE self) {
|
387
|
-
rb_check_frozen(self);
|
388
|
-
ray_rb2image(self)->update();
|
389
|
-
return self;
|
390
|
-
}
|
391
|
-
|
392
|
-
/*
|
393
|
-
@overload blit(hash)
|
394
|
-
Blits the receiver on another image.
|
395
|
-
|
396
|
-
@option hash [Ray::Vector2, #to_vector2] :at Position where the receiver
|
397
|
-
should be drawn.
|
398
|
-
@option hash [Ray::Rect, Array] :rect Rects that will be copied.
|
399
|
-
If an array is given, it
|
400
|
-
passed to Ray::Rect.new.
|
401
|
-
If the size is (0, 0), it will
|
402
|
-
be reset to the image's size.
|
403
|
-
@option hash [Ray::Rect, Array] :from Alias for rect
|
404
|
-
|
405
|
-
@option hash [Ray::Image, required] :on The image on which the receiver should
|
406
|
-
be drawn.
|
407
|
-
|
408
|
-
@option hash [Ray::Image] :to Alias for on.
|
409
|
-
|
410
|
-
@option hash [Float] :angle Rotation in degrees.
|
411
|
-
@option hash [Ray::Vector2, Float] :zoom Zoom level. If a float is
|
412
|
-
specified, Vector2[zoom, zoom] will be used.
|
413
|
-
|
414
|
-
@option hash [Ray::Shader] :shader Shader to be used.
|
415
|
-
|
416
|
-
@option hash [Ray::Color] :color (Ray::Color.white) Color used, affecting
|
417
|
-
the whole image. Each pixel is multiplied by this color.
|
418
|
-
*/
|
419
|
-
VALUE ray_image_blit(VALUE self, VALUE hash) {
|
420
|
-
ray_image *origin = ray_rb2image(self);
|
421
|
-
|
422
|
-
ray_rect from_rect;
|
423
|
-
ray_vector2 dest_pos;
|
424
|
-
|
425
|
-
VALUE pos = rb_hash_aref(hash, RAY_SYM("at"));
|
426
|
-
if (!NIL_P(pos))
|
427
|
-
dest_pos = ray_convert_to_vector2(pos);
|
428
|
-
|
429
|
-
VALUE rect = rb_hash_aref(hash, RAY_SYM("rect"));
|
430
|
-
if (NIL_P(rect)) rect = rb_hash_aref(hash, RAY_SYM("from"));
|
431
|
-
|
432
|
-
if (!NIL_P(rect))
|
433
|
-
from_rect = ray_convert_to_rect(rect);
|
434
|
-
|
435
|
-
VALUE surf = rb_hash_aref(hash, RAY_SYM("on"));
|
436
|
-
if (surf == Qnil) surf = rb_hash_aref(hash, RAY_SYM("to"));
|
437
|
-
|
438
|
-
rb_check_frozen(surf);
|
439
|
-
|
440
|
-
ray_image *target = ray_rb2image(surf);
|
441
|
-
|
442
|
-
VALUE rb_angle = Qnil, rb_zoom = Qnil;
|
443
|
-
float angle = 0.0f;
|
444
|
-
ray_vector2 zoom(1.0f, 1.0f);
|
445
|
-
|
446
|
-
if (!NIL_P(rb_angle = rb_hash_aref(hash, RAY_SYM("angle"))))
|
447
|
-
angle = (float)NUM2DBL(rb_angle);
|
448
|
-
|
449
|
-
if (!NIL_P(rb_zoom = rb_hash_aref(hash, RAY_SYM("zoom")))) {
|
450
|
-
if (RAY_IS_A(rb_zoom, rb_cFloat)) {
|
451
|
-
float zoom_val = (float)NUM2DBL(rb_zoom);
|
452
|
-
zoom = ray_vector2(zoom_val, zoom_val);
|
453
|
-
}
|
454
|
-
else
|
455
|
-
zoom = ray_convert_to_vector2(rb_zoom);
|
456
|
-
}
|
457
|
-
|
458
|
-
if (from_rect.Width == 0 && from_rect.Height == 0) {
|
459
|
-
from_rect.Width = origin->width();
|
460
|
-
from_rect.Height = origin->height();
|
461
|
-
}
|
462
|
-
|
463
|
-
VALUE rb_shader = rb_hash_aref(hash, RAY_SYM("shader"));
|
464
|
-
sf::Shader *shader = NULL;
|
465
|
-
if (!NIL_P(rb_shader))
|
466
|
-
shader = ray_rb2shader(rb_shader);
|
467
|
-
|
468
|
-
ray_color color(255, 255, 255);
|
469
|
-
VALUE rb_color = rb_hash_aref(hash, RAY_SYM("color"));
|
470
|
-
if (!NIL_P(rb_color))
|
471
|
-
color = ray_rb2col(rb_color);
|
472
|
-
|
473
|
-
target->draw_image(*origin, from_rect, dest_pos, angle, zoom,
|
474
|
-
shader, color);
|
475
|
-
|
476
|
-
return surf;
|
477
|
-
}
|
478
|
-
|
479
|
-
/* @return [Integer] Width of the surface */
|
480
|
-
VALUE ray_image_width(VALUE self) {
|
481
|
-
return INT2FIX(ray_rb2image(self)->width());
|
482
|
-
}
|
483
|
-
|
484
|
-
/* @return [Integer] Height of the surface */
|
485
|
-
VALUE ray_image_height(VALUE self) {
|
486
|
-
return INT2FIX(ray_rb2image(self)->height());
|
487
|
-
}
|
488
|
-
|
489
|
-
/*
|
490
|
-
@overload ==(obj)
|
491
|
-
@return [true, false] true if obj manipulates the same surface as the
|
492
|
-
receiver.
|
493
|
-
*/
|
494
|
-
VALUE ray_image_is_equal(VALUE self, VALUE obj) {
|
495
|
-
if (!RAY_IS_A(obj, ray_cImage))
|
496
|
-
return Qfalse;
|
497
|
-
|
498
|
-
ray_image *first_img = ray_rb2image(self);
|
499
|
-
ray_image *sec_img = ray_rb2image(obj);
|
500
|
-
|
501
|
-
return (*first_img == *sec_img) ? Qtrue : Qfalse;
|
502
|
-
}
|
503
|
-
|
504
|
-
|
505
|
-
VALUE ray_image_ensure_unlock(VALUE self) {
|
506
|
-
rb_check_frozen(self);
|
507
|
-
ray_rb2image(self)->unlock();
|
508
|
-
return self;
|
509
|
-
}
|
510
|
-
|
511
|
-
/*
|
512
|
-
Locks the image (allow pixel-per-pixel modifications).
|
513
|
-
Don't forget to call unlock when you're done. You can also
|
514
|
-
pass a bock which will be called before the image gets unlocked
|
515
|
-
automatically.
|
516
|
-
*/
|
517
|
-
VALUE ray_image_lock(VALUE self) {
|
518
|
-
rb_check_frozen(self);
|
519
|
-
|
520
|
-
ray_image *image = ray_rb2image(self);
|
521
|
-
if (!image->lock())
|
522
|
-
rb_raise(rb_eRuntimeError, "Couldn't lock the image");
|
523
|
-
|
524
|
-
if (rb_block_given_p())
|
525
|
-
rb_ensure(rb_yield, Qnil, ray_image_ensure_unlock, self);
|
526
|
-
|
527
|
-
return self;
|
528
|
-
}
|
529
|
-
|
530
|
-
/*
|
531
|
-
Unlocks the image. You must call this once you are done
|
532
|
-
modifying the image.
|
533
|
-
*/
|
534
|
-
VALUE ray_image_unlock(VALUE self) {
|
535
|
-
return ray_image_ensure_unlock(self);
|
536
|
-
}
|
537
|
-
|
538
|
-
/*
|
539
|
-
@overload [](x, y)
|
540
|
-
@return [Ray::Color, nil] Pixel at (x, y). Nil if the point is outside the
|
541
|
-
image.
|
542
|
-
*/
|
543
|
-
VALUE ray_image_at(VALUE self, VALUE rb_x, VALUE rb_y) {
|
544
|
-
ray_image *image = ray_rb2image(self);
|
545
|
-
|
546
|
-
int x = NUM2INT(rb_x);
|
547
|
-
int y = NUM2INT(rb_y);
|
548
|
-
|
549
|
-
/* (w, h) is not a valid point. Surfaces use 0-based indexing. */
|
550
|
-
if (x >= image->width() || y >= image->height())
|
551
|
-
return Qnil;
|
552
|
-
|
553
|
-
return ray_col2rb(image->at(x, y));
|
554
|
-
}
|
555
|
-
|
556
|
-
/*
|
557
|
-
@overload []=(x, y, color)
|
558
|
-
Sets the color of the point at (x, y)
|
559
|
-
@raise ArgumentError If (x, y) is outside the image.
|
560
|
-
@note Don't call this if the image isn't locked.
|
561
|
-
@example
|
562
|
-
img.lock { img[0, 0] = Ray::Color.red }
|
563
|
-
*/
|
564
|
-
VALUE ray_image_set_at(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_col) {
|
565
|
-
rb_check_frozen(self);
|
566
|
-
|
567
|
-
ray_image *image = ray_rb2image(self);
|
568
|
-
|
569
|
-
int x = NUM2INT(rb_x);
|
570
|
-
int y = NUM2INT(rb_y);
|
571
|
-
|
572
|
-
if (x >= image->width() || y >= image->height()) {
|
573
|
-
VALUE inspect = rb_inspect(self);
|
574
|
-
rb_raise(rb_eArgError, "(%d, %d) is outside %s",
|
575
|
-
x, y, StringValuePtr(inspect));
|
576
|
-
}
|
577
|
-
|
578
|
-
if (!image->set_at(x, y, ray_rb2col(rb_col)))
|
579
|
-
rb_raise(rb_eRuntimeError, "Trying to set pixel on a non locked image");
|
580
|
-
|
581
|
-
return rb_col;
|
582
|
-
}
|
583
|
-
|
584
|
-
VALUE ray_image_ensure_unclip(VALUE ary) {
|
585
|
-
ray_image *image = ray_rb2image(rb_ary_entry(ary, 0));
|
586
|
-
ray_rect rect = ray_rb2rect(rb_ary_entry(ary, 1));
|
587
|
-
|
588
|
-
image->set_clip(rect);
|
589
|
-
rb_gc_unregister_address(&ary);
|
590
|
-
|
591
|
-
return Qnil;
|
592
|
-
}
|
593
|
-
|
594
|
-
/*
|
595
|
-
@overload clip
|
596
|
-
@return [Ray::Rect] The current clipping rect
|
597
|
-
|
598
|
-
@overload clip(rect)
|
599
|
-
Changes the clipping rect (the rect which will be changed if something is
|
600
|
-
drawn on this image, the rest of the image being ignored.)
|
601
|
-
|
602
|
-
If a block is given, it is executed, and the old clipping rect is reset
|
603
|
-
afterwards.
|
604
|
-
|
605
|
-
@param [Ray::Rect, Array<Integer>] rect New clipping rect.
|
606
|
-
*/
|
607
|
-
VALUE ray_image_clip(int argc, VALUE *argv, VALUE self) {
|
608
|
-
VALUE rb_rect = Qnil;
|
609
|
-
rb_scan_args(argc, argv, "01", &rb_rect);
|
610
|
-
|
611
|
-
ray_image *image = ray_rb2image(self);
|
612
|
-
|
613
|
-
ray_rect old_rect = image->clip();
|
614
|
-
|
615
|
-
if (NIL_P(rb_rect))
|
616
|
-
return ray_rect2rb(old_rect);
|
617
|
-
|
618
|
-
rb_check_frozen(self);
|
619
|
-
|
620
|
-
ray_rect rect = ray_convert_to_rect(rb_rect);
|
621
|
-
image->set_clip(rect);
|
622
|
-
|
623
|
-
if (rb_block_given_p()) {
|
624
|
-
VALUE ary = rb_ary_new();
|
625
|
-
rb_ary_push(ary, self);
|
626
|
-
rb_ary_push(ary, ray_rect2rb(old_rect));
|
627
|
-
|
628
|
-
rb_gc_register_address(&ary);
|
629
|
-
|
630
|
-
rb_ensure(rb_yield, Qnil, ray_image_ensure_unclip, ary);
|
631
|
-
}
|
632
|
-
|
633
|
-
return ray_rect2rb(rect);
|
634
|
-
}
|
635
|
-
|
636
|
-
/*
|
637
|
-
Binds the image to use it as an OpenGL texture.
|
638
|
-
*/
|
639
|
-
VALUE ray_image_bind(VALUE self) {
|
640
|
-
ray_image *img = ray_rb2image(self);
|
641
|
-
if (!img->is_image())
|
642
|
-
rb_raise(rb_eRuntimeError, "Can't bind screen");
|
643
|
-
|
644
|
-
img->bind();
|
645
|
-
return self;
|
646
|
-
}
|
647
|
-
|
648
|
-
/* Activates the image to draw on it using OpenGL. */
|
649
|
-
VALUE ray_image_activate(VALUE self) {
|
650
|
-
rb_check_frozen(self);
|
651
|
-
ray_rb2image(self)->activate();
|
652
|
-
|
653
|
-
return self;
|
654
|
-
}
|
655
|
-
|
656
|
-
/*
|
657
|
-
@overload draw_shape(shape, shader = nil, color = Ray::Color.white)
|
658
|
-
Draws a shape on the image
|
659
|
-
|
660
|
-
@param [Ray::Shape] shape The shape to be drawn
|
661
|
-
@param [Ray::Shader] shader The shader to use with the shape
|
662
|
-
@param [Ray::Color] color The color used to multiply each pixel of the
|
663
|
-
shape.
|
664
|
-
*/
|
665
|
-
VALUE ray_image_draw_shape(int argc, VALUE *argv, VALUE self) {
|
666
|
-
rb_check_frozen(self);
|
667
|
-
|
668
|
-
VALUE shape, shader, color;
|
669
|
-
rb_scan_args(argc, argv, "12", &shape, &shader, &color);
|
670
|
-
|
671
|
-
rb_check_frozen(self);
|
672
|
-
|
673
|
-
ray_image *image = ray_rb2image(self);
|
674
|
-
|
675
|
-
sf::Shape *c_shape = ray_rb2shape(shape);
|
676
|
-
sf::Shader *c_shader = NULL;
|
677
|
-
if (!NIL_P(shader)) c_shader = ray_rb2shader(shader);
|
678
|
-
|
679
|
-
ray_color c_color(sf::Color::White);
|
680
|
-
if (!NIL_P(color)) c_color = ray_rb2col(color);
|
681
|
-
|
682
|
-
c_shape->SetColor(c_color);
|
683
|
-
|
684
|
-
image->draw(*c_shape, c_shader);
|
685
|
-
return self;
|
686
|
-
}
|
687
|
-
|
688
|
-
/*
|
689
|
-
@overload draw_drawable(drawable)
|
690
|
-
Draws a drawable on the image
|
691
|
-
*/
|
692
|
-
VALUE ray_image_draw_drawable(VALUE self, VALUE drawable) {
|
693
|
-
rb_check_frozen(self);
|
694
|
-
|
695
|
-
ray_drawable *c_drawable = ray_rb2drawable(drawable);
|
696
|
-
c_drawable->render(self);
|
697
|
-
|
698
|
-
return self;
|
699
|
-
}
|
700
|
-
|
701
|
-
void Init_ray_image() {
|
702
|
-
ray_cImage = rb_define_class_under(ray_mRay, "Image", rb_cObject);
|
703
|
-
rb_define_alloc_func(ray_cImage, ray_alloc_image);
|
704
|
-
rb_define_method(ray_cImage, "initialize", ray_init_image, 1);
|
705
|
-
rb_define_method(ray_cImage, "initialize_copy", ray_init_image_copy, 1);
|
706
|
-
|
707
|
-
rb_define_singleton_method(ray_cImage, "available?", ray_image_available, 0);
|
708
|
-
|
709
|
-
rb_define_method(ray_cImage, "save_as", ray_image_save_as, 1);
|
710
|
-
|
711
|
-
rb_define_method(ray_cImage, "fill", ray_image_fill, 1);
|
712
|
-
rb_define_method(ray_cImage, "flip", ray_image_flip, 0);
|
713
|
-
|
714
|
-
rb_define_method(ray_cImage, "blit", ray_image_blit, 1);
|
715
|
-
|
716
|
-
rb_define_method(ray_cImage, "width", ray_image_width, 0);
|
717
|
-
rb_define_method(ray_cImage, "height", ray_image_height, 0);
|
718
|
-
|
719
|
-
rb_define_method(ray_cImage, "==", ray_image_is_equal, 1);
|
720
|
-
|
721
|
-
rb_define_method(ray_cImage, "lock", ray_image_lock, 0);
|
722
|
-
rb_define_method(ray_cImage, "unlock", ray_image_unlock, 0);
|
723
|
-
rb_define_method(ray_cImage, "[]", ray_image_at, 2);
|
724
|
-
rb_define_method(ray_cImage, "[]=", ray_image_set_at, 3);
|
725
|
-
|
726
|
-
rb_define_method(ray_cImage, "clip", ray_image_clip, -1);
|
727
|
-
|
728
|
-
rb_define_method(ray_cImage, "bind", ray_image_bind, 0);
|
729
|
-
rb_define_method(ray_cImage, "activate", ray_image_activate, 0);
|
730
|
-
|
731
|
-
rb_define_method(ray_cImage, "draw_shape", ray_image_draw_shape, -1);
|
732
|
-
rb_define_method(ray_cImage, "draw_drawable", ray_image_draw_drawable, 1);
|
733
|
-
}
|