├── .gitignore ├── README.markdown ├── Rakefile ├── ext └── rbsfml │ ├── base.cpp │ ├── base.hpp │ ├── class.cpp │ ├── class.hpp │ ├── class.inc │ ├── error.cpp │ ├── error.hpp │ ├── error.inc │ ├── macros.cpp │ ├── macros.hpp │ ├── macros.inc │ ├── module.hpp │ ├── module.inc │ ├── object.cpp │ ├── object.hpp │ ├── rbblendmode.cpp │ ├── rbblendmode.hpp │ ├── rbclock.cpp │ ├── rbclock.hpp │ ├── rbcolor.cpp │ ├── rbcolor.hpp │ ├── rbcontext.cpp │ ├── rbcontext.hpp │ ├── rbcontextsettings.cpp │ ├── rbcontextsettings.hpp │ ├── rbdataptr.cpp │ ├── rbdataptr.hpp │ ├── rbdrawable.cpp │ ├── rbdrawable.hpp │ ├── rbdrawablebasetype.cpp │ ├── rbdrawablebasetype.hpp │ ├── rbevent.cpp │ ├── rbevent.hpp │ ├── rbfont.cpp │ ├── rbfont.hpp │ ├── rbimage.cpp │ ├── rbimage.hpp │ ├── rbjoystick.cpp │ ├── rbjoystick.hpp │ ├── rbkeyboard.cpp │ ├── rbkeyboard.hpp │ ├── rbmouse.cpp │ ├── rbmouse.hpp │ ├── rbnoncopyable.cpp │ ├── rbnoncopyable.hpp │ ├── rbrect.cpp │ ├── rbrect.hpp │ ├── rbrenderbasetype.cpp │ ├── rbrenderbasetype.hpp │ ├── rbrenderstates.cpp │ ├── rbrenderstates.hpp │ ├── rbrendertarget.cpp │ ├── rbrendertarget.hpp │ ├── rbrendertexture.cpp │ ├── rbrendertexture.hpp │ ├── rbrenderwindow.cpp │ ├── rbrenderwindow.hpp │ ├── rbsensor.cpp │ ├── rbsensor.hpp │ ├── rbsfml.cpp │ ├── rbshader.cpp │ ├── rbshader.hpp │ ├── rbshape.cpp │ ├── rbshape.hpp │ ├── rbsprite.cpp │ ├── rbsprite.hpp │ ├── rbtext.cpp │ ├── rbtext.hpp │ ├── rbtexture.cpp │ ├── rbtexture.hpp │ ├── rbtime.cpp │ ├── rbtime.hpp │ ├── rbtouch.cpp │ ├── rbtouch.hpp │ ├── rbtransform.cpp │ ├── rbtransform.hpp │ ├── rbtransformable.cpp │ ├── rbtransformable.hpp │ ├── rbvector2.cpp │ ├── rbvector2.hpp │ ├── rbvector3.cpp │ ├── rbvector3.hpp │ ├── rbvertex.cpp │ ├── rbvertex.hpp │ ├── rbvertexarray.cpp │ ├── rbvertexarray.hpp │ ├── rbvideomode.cpp │ ├── rbvideomode.hpp │ ├── rbview.cpp │ ├── rbview.hpp │ ├── rbwindow.cpp │ ├── rbwindow.hpp │ ├── value.cpp │ ├── value.hpp │ └── value.inc ├── license.txt ├── rbsfml.gemspec └── spec ├── blend_mode_spec.rb ├── clock_spec.rb ├── color_spec.rb ├── context_settings_spec.rb ├── context_spec.rb ├── renderwindow_spec.rb ├── time_spec.rb ├── vector2_spec.rb ├── vector3_spec.rb ├── video_mode_spec.rb └── window_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | tmp/* 2 | obj/* 3 | lib/* 4 | .idea/* 5 | 6 | *.log 7 | */*.log 8 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | This is the Ruby bindings of the [SFML library](https://github.com/SFML/SFML) developed and maintained by Groogy 2 | 3 | I hope you enjoy using rbSFML. If you make anything in it then we are very interested in hearing about it. 4 | We can always be reached at http://www.sfml-dev.org/forum for support, ideas or just have a nice chat. 5 | 6 | If you have questions or need help then please post it on the forum or write us an email. The issue tracker is for bugs 7 | and suggestions only please. If you are uncertain then write it on the forum instead. 8 | 9 | Dependencies 10 | ============ 11 | 12 | Of course this means this library depends on SFML so you'll have to install SFML2 on your development machine in order to compile rbSFML. 13 | 14 | Recommended is this setup: (lowers or highers versions might work too) 15 | 16 | - [SFML - commit 01d7243](https://github.com/SFML/SFML/commit/01d72438debdf0ecc75260a3e7d7201c130537d5) 17 | - [Ruby 2.2.3p173](http://www.ruby-lang.org/en/downloads/) 18 | - [Rake 10.4.2](https://rubygems.org/gems/rake) 19 | - [Git 2.5.0.1](http://git-scm.com/download) 20 | 21 | Installation 22 | ============ 23 | 24 | Windows 25 | ------- 26 | 27 | 1. Install Ruby. The simple [Ruby Installer](http://rubyinstaller.org/downloads) works fine. 28 | 29 | 2. [Download](https://github.com/SFML/SFML) and [compile](http://sfml-dev.org/tutorials/2.0/compile-with-cmake.php) SFML. 30 | 31 | 3. Open `cmd` and navigate to a folder where you want to install rbSFML source files. 32 | 33 | 4. Clone this repository with `git clone git@github.com:Groogy/rbSFML.git`. 34 | 35 | 5. Ensure that your C++ compiler's location is in your PATH environment variable. Run `rake verbose` to see what compiler Ruby thinks you have. If the SFML headers and libraries are not in your compiler's default search paths, set the `SFML_INCLUDE` and `SFML_LIB` environment variables to their locations. You might have to do this as ell for GLEW if it as well is not in the search path. 36 | 37 | 6. Run one of the following commands in your terminal: 38 | 39 | * `rake` - Build all SFML as shared libraries (need DLLs) - recommended. 40 | * `rake static` - Build all SFML as static libraries (don't need DLLs). 41 | 42 | 7. If you built SFML as a shared library, you will need the SFML DLLs in your PATH in order to `require` any of the rbSFML files (this can be accomplished by copying them to the directory where rbSFML is being `require`d). 43 | 44 | 8. Run `rake test` to ensure everything is working and then `rake install` to put the generated files somewhere Ruby can find it. 45 | 46 | Linux 47 | ----- 48 | 49 | 1. Install Ruby. If your flavor of Linux does not provide a package for this (which is unlikely), you can compile Ruby from [source](http://www.ruby-lang.org/pt/downloads/) and follow its instructions for installation. 50 | 51 | 2. You must have a recent build of SFML installed. If your flavor of Linux does not provide a package for this (which **is** likely), you will need to compile SFML from [source](https://github.com/SFML/SFML) and follow its [instructions](http://sfml-dev.org/tutorials/2.0/compile-with-cmake.php) for installation. 52 | 53 | 3. Ensure that the SFML headers and libraries are in your C++ compiler's search paths. The easiest way is to try compiling and running a simple SFML app. 54 | 55 | 4. Navigate to a folder where you want to install rbSFML source files. 56 | 57 | 5. Clone this repository with `git clone git@github.com:Groogy/rbSFML.git`. 58 | 59 | 6. From the rbSFML directory, run one of the following commands in your terminal: 60 | 61 | * `rake` - Build all SFML as shared libraries. 62 | 63 | 7. Run `rake test` to ensure everything is working and then `rake install` to put the generated files somewhere Ruby can find it. 64 | 65 | 8. You can build the documentation (at doc/frames.html) with `rake doc` and run the samples with `rake samples`. 66 | 67 | Questions? 68 | ========== 69 | 70 | [Open a issue](https://github.com/Groogy/rbSFML/issues/new). 71 | 72 | Contact 73 | ======= 74 | 75 | **Groogy:** 76 | 77 | - E-mail: groogy@groogy.se 78 | - Forum: http://www.sfml-dev.org/forum/profile.php?mode=viewprofile&u=921 79 | - Github: https://github.com/Groogy -------------------------------------------------------------------------------- /ext/rbsfml/base.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | #include "base.hpp" 22 | 23 | namespace 24 | { 25 | constexpr char symMore[] = ">"; 26 | constexpr char symLess[] = "<"; 27 | } 28 | 29 | namespace rb 30 | { 31 | 32 | Value Float(rb_cFloat); 33 | Value Fixnum(rb_cFixnum); 34 | 35 | Value yield(const Value& value) 36 | { 37 | return rb::Value(rb_yield(value.to())); 38 | } 39 | 40 | Value getEnumerator(const Value& value) 41 | { 42 | VALUE enumerator = SIZED_ENUMERATOR(value.to(), 0, nullptr, 0); 43 | return rb::Value(enumerator); 44 | } 45 | 46 | bool blockGiven() 47 | { 48 | return rb_block_given_p(); 49 | } 50 | 51 | Value max(Value a, Value b) 52 | { 53 | return a.call(b) == True ? a : b; 54 | } 55 | 56 | Value min(Value a, Value b) 57 | { 58 | return a.call(b) == True ? a : b; 59 | } 60 | 61 | Value callSuper(const std::vector& args) 62 | { 63 | VALUE* argArray = new VALUE[args.size()]; 64 | for(int index = 0, size = args.size(); index < size; index++) 65 | { 66 | argArray[index] = args[index].to(); 67 | } 68 | return rb::Value(rb_call_super(args.size(), argArray)); 69 | } 70 | 71 | Value eval(const std::string& script) 72 | { 73 | return rb::Value::create(rb_eval_string(script.c_str())); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /ext/rbsfml/base.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_BASE_HEADER_ 23 | #define RBSFML_BASE_HEADER_ 24 | 25 | #include 26 | #include "value.hpp" 27 | 28 | namespace rb 29 | { 30 | extern Value Float; 31 | extern Value Fixnum; 32 | 33 | Value yield(const Value& value); 34 | Value getEnumerator(const Value& object); 35 | bool blockGiven(); 36 | 37 | Value max(Value a, Value b); 38 | Value min(Value a, Value b); 39 | 40 | Value callSuper(const std::vector& args); 41 | 42 | Value eval(const std::string& script); 43 | } 44 | 45 | #endif // RBSFML_BASE_HEADER_ -------------------------------------------------------------------------------- /ext/rbsfml/class.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "class.hpp" 23 | 24 | namespace rb 25 | { 26 | VALUE RubyObjAllocator::allocate(VALUE klass) 27 | { 28 | NEWOBJ_OF(obj, struct RObject, klass, T_OBJECT | (RGENGC_WB_PROTECTED_OBJECT ? FL_WB_PROTECTED : 0)); 29 | return (VALUE)obj; 30 | } 31 | 32 | VALUE AbstractAllocator::allocate(VALUE klass) 33 | { 34 | rb::raise(rb::RuntimeError, "Tried to allocate object of abstract class!"); 35 | return Qnil; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ext/rbsfml/class.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_CLASS_HPP_ 23 | #define RBSFML_CLASS_HPP_ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "module.hpp" 30 | #include "object.hpp" 31 | 32 | namespace rb 33 | { 34 | template 35 | void defineAllocator(const rb::Value& klass); 36 | 37 | template 38 | class DefaultAllocator 39 | { 40 | public: 41 | static Base* allocate(); 42 | static VALUE allocate(VALUE klass); 43 | static void free(void* memory); 44 | }; 45 | 46 | class RubyObjAllocator 47 | { 48 | public: 49 | static VALUE allocate(VALUE klass); 50 | }; 51 | 52 | class AbstractAllocator 53 | { 54 | public: 55 | static VALUE allocate(VALUE klass); 56 | }; 57 | 58 | template 59 | class Class : public Module 60 | { 61 | public: 62 | static Module defineModule(const std::string& name) = delete; 63 | static Module defineModuleUnder(const std::string& name, const Value& otherModule) = delete; 64 | 65 | template> 66 | static Class defineClass(const std::string& name, const Value& parent = Value(rb_cObject)); 67 | template> 68 | static Class defineClassUnder(const std::string& name, const Value& otherModule, const Value& parent = Value(rb_cObject)); 69 | 70 | Class(); 71 | 72 | template 73 | Value newObject(Args... args) const; 74 | 75 | template> 76 | Value newObjectWithObject(rb::Object* object) const; 77 | 78 | protected: 79 | static Value myParent; 80 | }; 81 | } 82 | 83 | #include "class.inc" 84 | 85 | #endif // RBSFML_CLASS_HPP_ 86 | -------------------------------------------------------------------------------- /ext/rbsfml/class.inc: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | namespace rb 23 | { 24 | 25 | template 26 | void defineAllocator(const rb::Value& klass) 27 | { 28 | rb_define_alloc_func(klass.to(), &Allocator::allocate); 29 | } 30 | 31 | template 32 | Base* DefaultAllocator::allocate() 33 | { 34 | void* memory = xmalloc(sizeof(Base)); 35 | if(memory == nullptr) rb_memerror(); 36 | Base* object = new(memory) Base; 37 | return object; 38 | } 39 | 40 | template 41 | VALUE DefaultAllocator::allocate(VALUE klass) 42 | { 43 | Base* memory = allocate(); 44 | VALUE object = rb_data_object_alloc(klass, memory, NULL, &free); 45 | memory->setValue(object); 46 | return object; 47 | } 48 | 49 | template 50 | void DefaultAllocator::free(void* memory) 51 | { 52 | Base* object = static_cast(memory); 53 | object->~Base(); 54 | xfree(memory); 55 | } 56 | 57 | template 58 | Value Class::myParent(Qnil); 59 | 60 | template 61 | template 62 | Class Class::defineClass(const std::string& name, const Value& parent) 63 | { 64 | Module::myDefinition = rb_define_class(name.c_str(), parent.to()); 65 | Module::myName = name; 66 | Module::myParent = parent; 67 | 68 | defineAllocator(Module::myDefinition); 69 | 70 | return Class(); 71 | } 72 | 73 | template 74 | template 75 | Class Class::defineClassUnder(const std::string& name, const Value& otherModule, const Value& parent) 76 | { 77 | Module::myDefinition = rb_define_class_under(otherModule.to(), name.c_str(), parent.to()); 78 | Module::myName = name; 79 | Module::myNamespace = otherModule; 80 | myParent = parent; 81 | 82 | rb_define_alloc_func(Module::myDefinition, &Allocator::allocate); 83 | 84 | return Class(); 85 | } 86 | 87 | template 88 | Class::Class() 89 | : Module() 90 | { 91 | } 92 | 93 | constexpr char symNew[] = "new"; 94 | 95 | template 96 | template 97 | Value Class::newObject(Args... args) const 98 | { 99 | Value obj(Module::myDefinition); 100 | return obj.call(args...); 101 | } 102 | 103 | template 104 | template 105 | Value Class::newObjectWithObject(rb::Object* object) const 106 | { 107 | return rb::Value::create(rb_data_object_alloc(Module::myDefinition, object, NULL, &Allocator::free)); 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /ext/rbsfml/error.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | #include "error.hpp" 22 | 23 | namespace rb 24 | { 25 | 26 | rb::Value TypeError(rb_eTypeError); 27 | rb::Value RuntimeError(rb_eRuntimeError); 28 | rb::Value ArgumentError(rb_eArgError); 29 | 30 | void raise(const rb::Value& exception) 31 | { 32 | rb_exc_raise(exception.to()); 33 | } 34 | 35 | void expectedNumArgs(int argCount, int count) 36 | { 37 | raise(ArgumentError, "wrong number of arguments(%i for %i)", argCount, count); 38 | } 39 | 40 | void expectedNumArgs(int argCount, int minCount, int maxCount) 41 | { 42 | raise(ArgumentError, "wrong number of arguments(%i for %i...%i)", argCount, minCount, maxCount); 43 | } 44 | 45 | void expectedNumArgs(int argCount, const std::string& customText) 46 | { 47 | raise(ArgumentError, "wrong number of arguments(%i for %s)", argCount, customText.c_str()); 48 | } 49 | 50 | void modifiedFrozen(rb::Value object) 51 | { 52 | raise(RuntimeError, "can't modify frozen %s", object.getClassName().c_str()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ext/rbsfml/error.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_ERROR_HEADER_ 23 | #define RBSFML_ERROR_HEADER_ 24 | 25 | #include 26 | #include "value.hpp" 27 | 28 | namespace rb 29 | { 30 | extern rb::Value TypeError; 31 | extern rb::Value RuntimeError; 32 | extern rb::Value ArgumentError; 33 | 34 | template 35 | void raise(const rb::Value& value, const char* fmt, Args... args); 36 | void raise(const rb::Value& value); 37 | 38 | template 39 | void expectedTypes(Args... args); 40 | 41 | void expectedNumArgs(int argCount, int count); 42 | void expectedNumArgs(int argCount, int minCount, int maxCount); 43 | void expectedNumArgs(int argCount, const std::string& customText); 44 | 45 | void modifiedFrozen(rb::Value object); 46 | } 47 | 48 | #include "error.inc" 49 | 50 | #endif // RBSFML_ERROR_HEADER_ -------------------------------------------------------------------------------- /ext/rbsfml/error.inc: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | #include "error.hpp" 22 | 23 | namespace rb 24 | { 25 | 26 | template 27 | void raise(const rb::Value& value, const char* fmt, Args... args) 28 | { 29 | rb_raise(value.to(), fmt, args...); 30 | } 31 | 32 | template 33 | void expectedTypes(Args... args) 34 | { 35 | std::string result; 36 | std::string types[]{args...}; 37 | for(int index = 0, num = sizeof...(args); index < num; index++) 38 | { 39 | result += types[index]; 40 | if(num < num - 1) 41 | result += ", "; 42 | } 43 | raise(TypeError, "Did not receive expected types ( %s )", result.c_str()); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /ext/rbsfml/macros.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "macros.hpp" 23 | 24 | namespace rb 25 | { 26 | 27 | template<> 28 | sf::PrimitiveType Value::to() const 29 | { 30 | unsigned int value = to(); 31 | return static_cast(value); 32 | } 33 | 34 | template<> 35 | Value Value::create( sf::PrimitiveType value ) 36 | { 37 | return create(static_cast(value)); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /ext/rbsfml/macros.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_MACROS_HEADER_ 23 | #define RBSFML_MACROS_HEADER_ 24 | 25 | #include 26 | #include 27 | #include "value.hpp" 28 | 29 | namespace macro 30 | { 31 | template 32 | std::string toString(const Type& value); 33 | } 34 | 35 | namespace rb 36 | { 37 | template<> 38 | sf::PrimitiveType Value::to() const; 39 | template<> 40 | Value Value::create( sf::PrimitiveType value ); 41 | } 42 | 43 | #include "macros.inc" 44 | 45 | #endif // RBSFML_MACROS_HEADER_ -------------------------------------------------------------------------------- /ext/rbsfml/macros.inc: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "macros.hpp" 23 | #include 24 | 25 | namespace macro 26 | { 27 | template 28 | std::string toString(const Type& value) 29 | { 30 | std::stringstream stream; 31 | stream << value; 32 | return stream.str(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ext/rbsfml/object.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | /* rbSFML 22 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 23 | * This software is provided 'as-is', without any express or implied warranty. 24 | * In no event will the authors be held liable for any damages arising from 25 | * the use of this software. 26 | * 27 | * Permission is granted to anyone to use this software for any purpose, 28 | * including commercial applications, and to alter it and redistribute it 29 | * freely, subject to the following restrictions: 30 | * 31 | * 1. The origin of this software must not be misrepresented; you must not 32 | * claim that you wrote the original software. If you use this software in 33 | * a product, an acknowledgment in the product documentation would be 34 | * appreciated but is not required. 35 | * 36 | * 2. Altered source versions must be plainly marked as such, and must not be 37 | * misrepresented as being the original software. 38 | * 39 | * 3. This notice may not be removed or altered from any source distribution. 40 | */ 41 | #include "object.hpp" 42 | 43 | namespace rb 44 | { 45 | 46 | Object::Object() 47 | : myValue() 48 | { 49 | } 50 | 51 | Object::~Object() 52 | { 53 | } 54 | 55 | void Object::setValue(VALUE value) 56 | { 57 | myValue = rb::Value(value); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /ext/rbsfml/object.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_OBJECT_HEADER_ 23 | #define RBSFML_OBJECT_HEADER_ 24 | 25 | #include 26 | #include "value.hpp" 27 | 28 | namespace rb 29 | { 30 | class Object 31 | { 32 | public: 33 | Object(); 34 | virtual ~Object(); 35 | 36 | void setValue(VALUE value); 37 | 38 | protected: 39 | friend class Value; 40 | 41 | rb::Value myValue; 42 | }; 43 | } 44 | 45 | #endif // RBSFML_OBJECT_HEADER_ -------------------------------------------------------------------------------- /ext/rbsfml/rbblendmode.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBBLENDMODE_HPP 23 | #define RBSFML_RBBLENDMODE_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | #include "macros.hpp" 29 | 30 | class rbBlendMode; 31 | 32 | typedef rb::Class rbBlendModeClass; 33 | 34 | class rbBlendMode 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static const rbBlendModeClass& getDefinition(); 39 | 40 | static rb::Value initialize(rb::Value self, const std::vector& args); 41 | 42 | static bool equal(const rb::Value& self, const rb::Value& other); 43 | static std::string inspect(const rb::Value& self); 44 | 45 | private: 46 | static rbBlendModeClass ourDefinition; 47 | }; 48 | 49 | namespace macro 50 | { 51 | template<> 52 | std::string toString(const sf::BlendMode::Factor& value); 53 | template<> 54 | std::string toString(const sf::BlendMode::Equation& value); 55 | } 56 | 57 | namespace rb 58 | { 59 | template<> 60 | sf::BlendMode::Factor Value::to() const; 61 | 62 | template<> 63 | Value Value::create( sf::BlendMode::Factor value ); 64 | 65 | template<> 66 | sf::BlendMode::Equation Value::to() const; 67 | 68 | template<> 69 | Value Value::create( sf::BlendMode::Equation value ); 70 | 71 | template<> 72 | sf::BlendMode Value::to() const; 73 | 74 | template<> 75 | Value Value::create( const sf::BlendMode& value ); 76 | } 77 | 78 | #endif // RBSFML_RBBLENDMODE_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbclock.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbclock.hpp" 23 | #include "error.hpp" 24 | #include "macros.hpp" 25 | #include "rbtime.hpp" 26 | 27 | rbClockClass rbClock::ourDefinition; 28 | 29 | void rbClock::defineClass(const rb::Value& sfml) 30 | { 31 | ourDefinition = rbClockClass::defineClassUnder("Clock", sfml); 32 | ourDefinition.defineMethod<0>("initialize_copy", &rbClock::initializeCopy); 33 | ourDefinition.defineMethod<1>("elapsed_time", &rbClock::getElapsedTime); 34 | ourDefinition.defineMethod<2>("restart", &rbClock::restart); 35 | ourDefinition.defineMethod<3>("marshal_dump", &rbClock::marshalDump); 36 | ourDefinition.defineMethod<4>("inspect", &rbClock::inspect); 37 | 38 | ourDefinition.aliasMethod("inspect", "to_s"); 39 | } 40 | 41 | rbClock::rbClock() 42 | : rb::Object() 43 | , myObject() 44 | { 45 | } 46 | 47 | rbClock::~rbClock() 48 | { 49 | } 50 | 51 | rbClock* rbClock::initializeCopy(const rbClock* value) 52 | { 53 | myObject = value->myObject; 54 | return this; 55 | } 56 | 57 | rbTime* rbClock::getElapsedTime() const 58 | { 59 | sf::Time time = myObject.getElapsedTime(); 60 | rbTime* timeObject = rbTime::ourDefinition.newObject().to(); 61 | timeObject->myObject = time; 62 | return timeObject; 63 | } 64 | 65 | rbTime* rbClock::restart() 66 | { 67 | sf::Time time = myObject.restart(); 68 | rbTime* timeObject = rbTime::ourDefinition.newObject().to(); 69 | timeObject->myObject = time; 70 | return timeObject; 71 | } 72 | 73 | rb::Value rbClock::marshalDump() const 74 | { 75 | rb::raise(rb::TypeError, "can't dump %s", ourDefinition.getName().c_str() ); 76 | return rb::Nil; 77 | } 78 | 79 | std::string rbClock::inspect() const 80 | { 81 | sf::Time time = myObject.getElapsedTime(); 82 | return ourDefinition.getName() + "(" + macro::toString(time.asSeconds()) + ")"; 83 | } 84 | 85 | namespace rb 86 | { 87 | 88 | template<> 89 | rbClock* Value::to() const 90 | { 91 | errorHandling(T_DATA); 92 | rbClock* object = nullptr; 93 | if(myValue != Qnil) 94 | Data_Get_Struct(myValue, rbClock, object); 95 | return object; 96 | } 97 | 98 | template<> 99 | const rbClock* Value::to() const 100 | { 101 | errorHandling(T_DATA); 102 | const rbClock* object = nullptr; 103 | if(myValue != Qnil) 104 | Data_Get_Struct(myValue, rbClock, object); 105 | return object; 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbclock.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBCLOCK_HPP_ 23 | #define RBSFML_RBCLOCK_HPP_ 24 | 25 | #include 26 | #include 27 | #include "class.hpp" 28 | #include "object.hpp" 29 | 30 | class rbClock; 31 | class rbTime; 32 | 33 | typedef rb::Class rbClockClass; 34 | 35 | class rbClock : public rb::Object 36 | { 37 | public: 38 | static void defineClass(const rb::Value& sfml); 39 | 40 | rbClock(); 41 | ~rbClock(); 42 | 43 | rbClock* initializeCopy(const rbClock* value); 44 | 45 | rbTime* getElapsedTime() const; 46 | rbTime* restart(); 47 | 48 | rb::Value marshalDump() const; 49 | std::string inspect() const; 50 | 51 | private: 52 | static rbClockClass ourDefinition; 53 | 54 | sf::Clock myObject; 55 | }; 56 | 57 | namespace rb 58 | { 59 | template<> 60 | rbClock* Value::to() const; 61 | template<> 62 | const rbClock* Value::to() const; 63 | } 64 | 65 | #endif // RBSFML_RBCLOCK_HPP_ 66 | -------------------------------------------------------------------------------- /ext/rbsfml/rbcolor.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBCOLOR_HPP 23 | #define RBSFML_RBCOLOR_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | 28 | class rbColor; 29 | 30 | typedef rb::Class rbColorClass; 31 | 32 | class rbColor 33 | { 34 | public: 35 | static void defineClass(const rb::Value& sfml); 36 | static const rbColorClass& getDefinition(); 37 | 38 | static rb::Value initialize(rb::Value self, const std::vector& args); 39 | static rb::Value initializeCopy(rb::Value self, const rb::Value& value); 40 | static std::vector marshalDump(const rb::Value& self); 41 | static rb::Value marshalLoad(rb::Value self, const rb::Value& data); 42 | 43 | static unsigned int toInteger(rb::Value self); 44 | 45 | static rb::Value add(const rb::Value& self, const rb::Value& other); 46 | static rb::Value subtract(const rb::Value& self, const rb::Value& other); 47 | static rb::Value multiply(const rb::Value& self, const rb::Value& other); 48 | 49 | static bool equal(const rb::Value& self, const rb::Value& other); 50 | static bool strictEqual(const rb::Value& self, const rb::Value& other); 51 | 52 | static std::string inspect(const rb::Value& self); 53 | 54 | private: 55 | static rbColorClass ourDefinition; 56 | }; 57 | 58 | namespace rb 59 | { 60 | template<> 61 | sf::Color Value::to() const; 62 | 63 | template<> 64 | Value Value::create( sf::Color value ); 65 | template<> 66 | Value Value::create( const sf::Color& value ); 67 | } 68 | 69 | #endif // RBSFML_RBCOLOR_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbcontext.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbcontext.hpp" 23 | #include "rbcontextsettings.hpp" 24 | #include "rbnoncopyable.hpp" 25 | #include "error.hpp" 26 | #include "macros.hpp" 27 | 28 | rbContextClass rbContext::ourDefinition; 29 | 30 | void rbContext::defineClass(const rb::Value& sfml) 31 | { 32 | ourDefinition = rbContextClass::defineClassUnder("Context", sfml); 33 | ourDefinition.includeModule(rb::Value(rbNonCopyable::getDefinition())); 34 | ourDefinition.defineMethod<0>("initialize", &rbContext::initialize); 35 | ourDefinition.defineMethod<1>("set_active", &rbContext::setActive); 36 | } 37 | 38 | rbContext::rbContext() 39 | : rb::Object() 40 | , myObject(nullptr) 41 | { 42 | } 43 | 44 | rbContext::~rbContext() 45 | { 46 | delete myObject; 47 | } 48 | 49 | void rbContext::initialize(rbContextSettings* settings, unsigned int width, unsigned int height) 50 | { 51 | myObject = new sf::Context(settings->myObject, width, height); 52 | } 53 | 54 | bool rbContext::setActive(bool flag) 55 | { 56 | return myObject->setActive(flag); 57 | } 58 | 59 | namespace rb 60 | { 61 | 62 | template<> 63 | rbContext* Value::to() const 64 | { 65 | errorHandling(T_DATA); 66 | rbContext* object = nullptr; 67 | if(myValue != Qnil) 68 | Data_Get_Struct(myValue, rbContext, object); 69 | return object; 70 | } 71 | 72 | template<> 73 | const rbContext* Value::to() const 74 | { 75 | errorHandling(T_DATA); 76 | const rbContext* object = nullptr; 77 | if(myValue != Qnil) 78 | Data_Get_Struct(myValue, rbContext, object); 79 | return object; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbcontext.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBCONTEXT_HPP_ 23 | #define RBSFML_RBCONTEXT_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbContext; 30 | class rbContextSettings; 31 | 32 | typedef rb::Class rbContextClass; 33 | 34 | class rbContext : public rb::Object 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | 39 | rbContext(); 40 | ~rbContext(); 41 | 42 | void initialize(rbContextSettings* settings, unsigned int width, unsigned int height); 43 | 44 | bool setActive(bool flag); 45 | 46 | private: 47 | static rbContextClass ourDefinition; 48 | 49 | sf::Context* myObject; 50 | }; 51 | 52 | namespace rb 53 | { 54 | template<> 55 | rbContext* Value::to() const; 56 | template<> 57 | const rbContext* Value::to() const; 58 | } 59 | 60 | #endif // RBSFML_RBCONTEXT_HPP_ 61 | -------------------------------------------------------------------------------- /ext/rbsfml/rbcontextsettings.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBCONTEXTSETTINGS_HPP_ 23 | #define RBSFML_RBCONTEXTSETTINGS_HPP_ 24 | 25 | #include 26 | #include 27 | #include "class.hpp" 28 | #include "object.hpp" 29 | 30 | class rbContextSettings; 31 | 32 | typedef rb::Class rbContextSettingsClass; 33 | 34 | class rbContextSettings : public rb::Object 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | 39 | rbContextSettings(); 40 | ~rbContextSettings(); 41 | 42 | static rb::Value initialize(rb::Value self, const std::vector& args); 43 | rbContextSettings* initializeCopy(const rbContextSettings* value); 44 | 45 | void setDepthBits(unsigned int value); 46 | unsigned int getDepthBits() const; 47 | void setStencilBits(unsigned int value); 48 | unsigned int getStencilBits() const; 49 | void setAntialiasingLevel(unsigned int value); 50 | unsigned int getAntialiasingLevel() const; 51 | void setMajorVersion(unsigned int value); 52 | unsigned int getMajorVersion() const; 53 | void setMinorVersion(unsigned int value); 54 | unsigned int getMinorVersion() const; 55 | void setAttributeFlags(unsigned int value); 56 | unsigned int getAttributeFlags() const; 57 | 58 | rb::Value marshalDump() const; 59 | std::string inspect() const; 60 | 61 | private: 62 | friend class rbContext; 63 | friend class rbWindow; 64 | 65 | static rbContextSettingsClass ourDefinition; 66 | 67 | sf::ContextSettings myObject; 68 | }; 69 | 70 | namespace rb 71 | { 72 | template<> 73 | rbContextSettings* Value::to() const; 74 | template<> 75 | const rbContextSettings* Value::to() const; 76 | } 77 | 78 | #endif // RBSFML_RBCONTEXTSETTINGS_HPP_ 79 | -------------------------------------------------------------------------------- /ext/rbsfml/rbdataptr.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbdataptr.hpp" 23 | #include "rbnoncopyable.hpp" 24 | #include "error.hpp" 25 | #include "macros.hpp" 26 | 27 | rbDataPtrClass rbDataPtr::ourDefinition; 28 | 29 | void rbDataPtr::defineClass(const rb::Value& sfml) 30 | { 31 | ourDefinition = rbDataPtrClass::defineClassUnder("DataPtr", sfml); 32 | ourDefinition.includeModule(rb::Value(rbNonCopyable::getDefinition())); 33 | ourDefinition.defineMethod<0>("inspect", &rbDataPtr::inspect); 34 | ourDefinition.defineMethod<1>("ptr", &rbDataPtr::getPtr); 35 | 36 | ourDefinition.aliasMethod("inspect", "to_s"); 37 | } 38 | 39 | rbDataPtrClass& rbDataPtr::getDefinition() 40 | { 41 | return ourDefinition; 42 | } 43 | 44 | rbDataPtr::rbDataPtr() 45 | : rb::Object() 46 | , myObject(0) 47 | { 48 | } 49 | 50 | rbDataPtr::~rbDataPtr() 51 | { 52 | } 53 | 54 | std::string rbDataPtr::inspect() const 55 | { 56 | return ourDefinition.getName() + "(" + macro::toString( myObject ) + ")"; 57 | } 58 | 59 | intptr_t rbDataPtr::getPtr() const 60 | { 61 | return myObject; 62 | } 63 | 64 | void rbDataPtr::setPtr(intptr_t ptr) 65 | { 66 | myObject = ptr; 67 | } 68 | 69 | namespace rb 70 | { 71 | 72 | template<> 73 | rbDataPtr* Value::to() const 74 | { 75 | errorHandling(T_DATA); 76 | rbDataPtr* object = nullptr; 77 | if(myValue != Qnil) 78 | Data_Get_Struct(myValue, rbDataPtr, object); 79 | return object; 80 | } 81 | 82 | template<> 83 | const rbDataPtr* Value::to() const 84 | { 85 | errorHandling(T_DATA); 86 | const rbDataPtr* object = nullptr; 87 | if(myValue != Qnil) 88 | Data_Get_Struct(myValue, rbDataPtr, object); 89 | return object; 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbdataptr.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBDATAPTR_HPP_ 23 | #define RBSFML_RBDATAPTR_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "object.hpp" 27 | 28 | class rbDataPtr; 29 | 30 | typedef rb::Class rbDataPtrClass; 31 | 32 | class rbDataPtr : public rb::Object 33 | { 34 | public: 35 | static void defineClass(const rb::Value& sfml); 36 | static rbDataPtrClass& getDefinition(); 37 | 38 | rbDataPtr(); 39 | ~rbDataPtr(); 40 | 41 | std::string inspect() const; 42 | 43 | intptr_t getPtr() const; 44 | void setPtr(intptr_t ptr); 45 | 46 | private: 47 | friend class rb::Value; 48 | 49 | static rbDataPtrClass ourDefinition; 50 | 51 | intptr_t myObject; 52 | }; 53 | 54 | namespace rb 55 | { 56 | template<> 57 | rbDataPtr* Value::to() const; 58 | template<> 59 | const rbDataPtr* Value::to() const; 60 | } 61 | 62 | #endif // RBSFML_RBDATAPTR_HPP_ 63 | -------------------------------------------------------------------------------- /ext/rbsfml/rbdrawable.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbdrawable.hpp" 23 | #include "rbrendertarget.hpp" 24 | #include "rbrenderstates.hpp" 25 | #include "error.hpp" 26 | #include "macros.hpp" 27 | 28 | #include 29 | 30 | namespace 31 | { 32 | constexpr char symVarInternalDrawStack[] = "@@__internal_draw_stack"; 33 | 34 | constexpr char symDraw[] = "draw"; 35 | constexpr char symLast[] = "last"; 36 | constexpr char symDup[] = "dup"; 37 | } 38 | 39 | class rbDrawableBridge; 40 | 41 | class rbDrawableImpl : public sf::Drawable 42 | { 43 | public: 44 | rbDrawableImpl(rbDrawableBridge& owner); 45 | 46 | protected: 47 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; 48 | 49 | private: 50 | rbDrawableBridge& myOwner; 51 | }; 52 | 53 | class rbDrawableBridge : public rbDrawable 54 | { 55 | public: 56 | rbDrawableBridge(); 57 | void onDraw(sf::RenderTarget& target, sf::RenderStates states) const; 58 | 59 | protected: 60 | sf::Drawable* getDrawable(); 61 | const sf::Drawable* getDrawable() const; 62 | 63 | private: 64 | rbDrawableImpl myObject; 65 | }; 66 | 67 | rbDrawableImpl::rbDrawableImpl(rbDrawableBridge& owner) 68 | : myOwner(owner) 69 | { 70 | } 71 | 72 | void rbDrawableImpl::draw(sf::RenderTarget& target, sf::RenderStates states) const 73 | { 74 | myOwner.onDraw(target, states); 75 | } 76 | 77 | rbDrawableBridge::rbDrawableBridge() 78 | : myObject(*this) 79 | { 80 | } 81 | 82 | void rbDrawableBridge::onDraw(sf::RenderTarget& target, sf::RenderStates states) const 83 | { 84 | rb::Value drawStack = rb::Value(rbRenderTarget::getDefinition()).getVar(); 85 | rb::Value self(myValue); 86 | rb::Value targetRef = rbRenderTarget::getRefDefinition().newObject(); 87 | targetRef.to()->setRef(&target); 88 | self.call(targetRef, drawStack.call().call()); 89 | } 90 | 91 | sf::Drawable* rbDrawableBridge::getDrawable() 92 | { 93 | return &myObject; 94 | } 95 | 96 | const sf::Drawable* rbDrawableBridge::getDrawable() const 97 | { 98 | return &myObject; 99 | } 100 | 101 | rbDrawableModule rbDrawable::ourDefinition; 102 | 103 | void rbDrawable::defineModule(const rb::Value& sfml) 104 | { 105 | ourDefinition = rbDrawableModule::defineModuleUnder("Drawable", sfml); 106 | } 107 | 108 | void rbDrawable::defineIncludeFunction() 109 | { 110 | ourDefinition.defineFunction<0>("included", &rbDrawable::included); 111 | } 112 | 113 | rbDrawableModule& rbDrawable::getDefinition() 114 | { 115 | return ourDefinition; 116 | } 117 | 118 | void rbDrawable::included(const rb::Value& base) 119 | { 120 | if(base.getType() == rb::ValueType::Class) 121 | { 122 | rb::defineAllocator>(base); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /ext/rbsfml/rbdrawable.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBDRAWABLE_HPP_ 23 | #define RBSFML_RBDRAWABLE_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "rbdrawablebasetype.hpp" 28 | 29 | class rbDrawable; 30 | 31 | typedef rb::Module rbDrawableModule; 32 | 33 | class rbDrawable : public rbDrawableBaseType 34 | { 35 | public: 36 | static void defineModule(const rb::Value& sfml); 37 | static void defineIncludeFunction(); 38 | static rbDrawableModule& getDefinition(); 39 | 40 | static void included(const rb::Value& base); 41 | 42 | private: 43 | static rbDrawableModule ourDefinition; 44 | }; 45 | 46 | #endif // RBSFML_RBDRAWABLE_HPP_ 47 | -------------------------------------------------------------------------------- /ext/rbsfml/rbdrawablebasetype.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbdrawablebasetype.hpp" 23 | #include "error.hpp" 24 | #include "macros.hpp" 25 | #include "base.hpp" 26 | 27 | rbDrawableBaseType::~rbDrawableBaseType() 28 | { 29 | } 30 | 31 | rbDrawableBaseType::rbDrawableBaseType() 32 | { 33 | } 34 | 35 | sf::Drawable* rbDrawableBaseType::getDrawable() { return nullptr; } 36 | const sf::Drawable* rbDrawableBaseType::getDrawable() const { return nullptr; } 37 | 38 | sf::Transformable* rbDrawableBaseType::getTransformable() { return nullptr; } 39 | const sf::Transformable* rbDrawableBaseType::getTransformable() const { return nullptr; } 40 | 41 | namespace rb 42 | { 43 | 44 | template<> 45 | rbDrawableBaseType* Value::to() const 46 | { 47 | errorHandling(T_DATA); 48 | rbDrawableBaseType* object = nullptr; 49 | if(myValue != Qnil) 50 | Data_Get_Struct(myValue, rbDrawableBaseType, object); 51 | return object; 52 | } 53 | 54 | template<> 55 | const rbDrawableBaseType* Value::to() const 56 | { 57 | errorHandling(T_DATA); 58 | const rbDrawableBaseType* object = nullptr; 59 | if(myValue != Qnil) 60 | Data_Get_Struct(myValue, rbDrawableBaseType, object); 61 | return object; 62 | } 63 | 64 | template<> 65 | sf::Drawable& Value::to() const 66 | { 67 | return *to()->getDrawable(); 68 | } 69 | 70 | template<> 71 | const sf::Drawable& Value::to() const 72 | { 73 | return *to()->getDrawable(); 74 | } 75 | 76 | template<> 77 | sf::Transformable& Value::to() const 78 | { 79 | return *to()->getTransformable(); 80 | } 81 | 82 | template<> 83 | const sf::Transformable& Value::to() const 84 | { 85 | return *to()->getTransformable(); 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbdrawablebasetype.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBDRAWABLEBASETYPE_HPP_ 23 | #define RBSFML_RBDRAWABLEBASETYPE_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "object.hpp" 27 | 28 | namespace sf 29 | { 30 | class Drawable; 31 | class Transformable; 32 | } 33 | 34 | class rbDrawableBaseType : public rb::Object 35 | { 36 | public: 37 | virtual ~rbDrawableBaseType(); 38 | 39 | protected: 40 | friend class rb::Value; 41 | 42 | rbDrawableBaseType(); 43 | 44 | virtual sf::Drawable* getDrawable(); 45 | virtual const sf::Drawable* getDrawable() const; 46 | 47 | virtual sf::Transformable* getTransformable(); 48 | virtual const sf::Transformable* getTransformable() const; 49 | }; 50 | 51 | namespace rb 52 | { 53 | template<> 54 | rbDrawableBaseType* Value::to() const; 55 | template<> 56 | const rbDrawableBaseType* Value::to() const; 57 | 58 | template<> 59 | sf::Drawable& Value::to() const; 60 | template<> 61 | const sf::Drawable& Value::to() const; 62 | 63 | template<> 64 | sf::Transformable& Value::to() const; 65 | template<> 66 | const sf::Transformable& Value::to() const; 67 | } 68 | 69 | #endif // RBSFML_RBDRAWABLEBASETYPE_HPP_ 70 | -------------------------------------------------------------------------------- /ext/rbsfml/rbfont.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBFONT_HPP_ 23 | #define RBSFML_RBFONT_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbFont; 30 | 31 | typedef rb::Class rbFontClass; 32 | typedef rb::Class rbFontInfoClass; 33 | typedef rb::Class rbGlyphClass; 34 | 35 | class rbFont : public rb::Object 36 | { 37 | public: 38 | static void defineClass(const rb::Value& sfml); 39 | static rbFontClass& getDefinition(); 40 | 41 | rbFont(); 42 | ~rbFont(); 43 | 44 | static rb::Value initialize(rb::Value self, const std::vector& args); 45 | rbFont* initializeCopy(const rbFont* value); 46 | 47 | rb::Value marshalDump() const; 48 | 49 | bool loadFromFile(const std::string& filename); 50 | bool loadFromMemory(std::vector data); 51 | 52 | const sf::Font::Info& getInfo() const; 53 | const sf::Glyph& getGlyph(unsigned int codePoint, unsigned int characterSize, bool bold) const; 54 | float getKerning(unsigned int first, unsigned int second, unsigned int characterSize) const; 55 | float getLineSpacing(unsigned int characterSize) const; 56 | float getUnderlinePosition(unsigned int characterSize) const; 57 | float getUnderlineThickness(unsigned int characterSize) const; 58 | 59 | rb::Value getTexture(unsigned int characterSize) const; 60 | 61 | private: 62 | friend class rb::Value; 63 | static rbFontClass ourDefinition; 64 | static rbFontInfoClass ourInfoDefinition; 65 | static rbGlyphClass ourGlyphDefinition; 66 | 67 | sf::Font myObject; 68 | }; 69 | 70 | namespace rb 71 | { 72 | template<> 73 | rbFont* Value::to() const; 74 | template<> 75 | const rbFont* Value::to() const; 76 | template<> 77 | sf::Font& Value::to() const; 78 | template<> 79 | const sf::Font& Value::to() const; 80 | 81 | template<> 82 | sf::Font::Info Value::to() const; 83 | template<> 84 | sf::Glyph Value::to() const; 85 | template<> 86 | Value Value::create(const sf::Font::Info& info); 87 | template<> 88 | Value Value::create(sf::Font::Info glyph); 89 | template<> 90 | Value Value::create(const sf::Glyph& glyph); 91 | template<> 92 | Value Value::create(sf::Glyph info); 93 | } 94 | 95 | #endif // RBSFML_RBFONT_HPP_ 96 | -------------------------------------------------------------------------------- /ext/rbsfml/rbimage.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBIMAGE_HPP_ 23 | #define RBSFML_RBIMAGE_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbImage; 30 | 31 | typedef rb::Class rbImageClass; 32 | 33 | class rbImage : public rb::Object 34 | { 35 | public: 36 | static void defineClass(const rb::Value& sfml); 37 | static rbImageClass& getDefinition(); 38 | 39 | rbImage(); 40 | ~rbImage(); 41 | 42 | static rb::Value initialize(rb::Value self, const std::vector& args); 43 | rbImage* initializeCopy(const rbImage* value); 44 | 45 | rb::Value marshalDump() const; 46 | void marshalLoad(const std::vector& data); 47 | 48 | std::string inspect() const; 49 | 50 | void createFromColor(unsigned int width, unsigned int height, sf::Color color); 51 | void createFromData(unsigned int width, unsigned int height, const std::vector& data); 52 | 53 | bool loadFromFile(const std::string& filename); 54 | bool loadFromMemory(const std::vector& data); 55 | bool saveToFile(const std::string& filename) const; 56 | 57 | sf::Vector2u getSize() const; 58 | 59 | static rb::Value createMaskFromColor(rb::Value self, const std::vector& args); 60 | static rb::Value copy(rb::Value self, const std::vector& args); 61 | 62 | void setPixel(unsigned int x, unsigned int y, sf::Color color); 63 | sf::Color getPixel(unsigned int x, unsigned int y) const; 64 | rb::Value getPixels() const; 65 | 66 | void flipHorizontally(); 67 | void flipVertically(); 68 | 69 | private: 70 | friend class rb::Value; 71 | static rbImageClass ourDefinition; 72 | 73 | sf::Image myObject; 74 | }; 75 | 76 | namespace rb 77 | { 78 | template<> 79 | rbImage* Value::to() const; 80 | template<> 81 | const rbImage* Value::to() const; 82 | template<> 83 | sf::Image& Value::to() const; 84 | template<> 85 | const sf::Image& Value::to() const; 86 | } 87 | 88 | #endif // RBSFML_RBIMAGE_HPP_ 89 | -------------------------------------------------------------------------------- /ext/rbsfml/rbjoystick.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbjoystick.hpp" 23 | #include "error.hpp" 24 | #include "macros.hpp" 25 | 26 | namespace 27 | { 28 | constexpr char symVarName[] = "@name"; 29 | constexpr char symVarVendorId[] = "@vendorId"; 30 | constexpr char symVarProductId[] = "@productId"; 31 | } 32 | 33 | rbJoystickModule rbJoystick::ourDefinition; 34 | rbJoystickIdentificationClass rbJoystickIdentification::ourDefinition; 35 | 36 | void rbJoystick::defineModule(const rb::Value& sfml) 37 | { 38 | ourDefinition = rbJoystickModule::defineModuleUnder("Joystick", sfml); 39 | ourDefinition.defineFunction<0>("connected=", &sf::Joystick::isConnected); 40 | ourDefinition.defineFunction<1>("get_button_count", &sf::Joystick::getButtonCount); 41 | ourDefinition.defineFunction<2>("has_axis?", &sf::Joystick::hasAxis); 42 | ourDefinition.defineFunction<3>("button_pressed?", &sf::Joystick::isButtonPressed); 43 | ourDefinition.defineFunction<4>("get_axis_position", &sf::Joystick::getAxisPosition); 44 | ourDefinition.defineFunction<5>("update", &sf::Joystick::update); 45 | ourDefinition.defineFunction<6>("get_identification", &sf::Joystick::getIdentification); 46 | 47 | ourDefinition.defineConstant("Count", rb::Value(sf::Joystick::Count)); 48 | ourDefinition.defineConstant("ButtonCount", rb::Value(sf::Joystick::ButtonCount)); 49 | ourDefinition.defineConstant("AxisCount", rb::Value(sf::Joystick::AxisCount)); 50 | ourDefinition.defineConstant("X", rb::Value(sf::Joystick::X)); 51 | ourDefinition.defineConstant("Y", rb::Value(sf::Joystick::Y)); 52 | ourDefinition.defineConstant("Z", rb::Value(sf::Joystick::Z)); 53 | ourDefinition.defineConstant("R", rb::Value(sf::Joystick::R)); 54 | ourDefinition.defineConstant("U", rb::Value(sf::Joystick::U)); 55 | ourDefinition.defineConstant("V", rb::Value(sf::Joystick::V)); 56 | ourDefinition.defineConstant("PovX", rb::Value(sf::Joystick::PovX)); 57 | ourDefinition.defineConstant("PovY", rb::Value(sf::Joystick::PovY)); 58 | 59 | rbJoystickIdentification::defineClass(sfml); 60 | } 61 | 62 | void rbJoystickIdentification::defineClass(const rb::Value& sfml) 63 | { 64 | ourDefinition = rbJoystickIdentificationClass::defineClassUnder("Identification", rb::Value(rbJoystick::ourDefinition)); 65 | ourDefinition.defineMethod<0>("initialize", &rbJoystickIdentification::initialize); 66 | ourDefinition.defineMethod<1>("initialize_copy", &rbJoystickIdentification::initializeCopy); 67 | ourDefinition.defineMethod<2>("marshal_dump", &rbJoystickIdentification::marshalDump); 68 | ourDefinition.defineMethod<3>("marshal_load", &rbJoystickIdentification::marshalLoad); 69 | 70 | ourDefinition.defineAttribute("x", true, true); 71 | ourDefinition.defineAttribute("y", true, true); 72 | } 73 | 74 | const rbJoystickIdentificationClass& rbJoystickIdentification::getDefinition() 75 | { 76 | return ourDefinition; 77 | } 78 | 79 | void rbJoystickIdentification::initialize(rb::Value self) 80 | { 81 | self.setVar(""); 82 | self.setVar(0); 83 | self.setVar(0); 84 | } 85 | 86 | rb::Value rbJoystickIdentification::initializeCopy(rb::Value self, const rb::Value& value) 87 | { 88 | self.setVar(value.getVar()); 89 | self.setVar(value.getVar()); 90 | self.setVar(value.getVar()); 91 | return self; 92 | } 93 | 94 | std::vector rbJoystickIdentification::marshalDump(const rb::Value& self) 95 | { 96 | std::vector array; 97 | array.push_back(self.getVar()); 98 | array.push_back(self.getVar()); 99 | array.push_back(self.getVar()); 100 | return array; 101 | } 102 | 103 | rb::Value rbJoystickIdentification::marshalLoad(rb::Value self, const rb::Value& data) 104 | { 105 | std::vector array = data.to>(); 106 | self.setVar(array[0]); 107 | self.setVar(array[1]); 108 | self.setVar(array[2]); 109 | return rb::Nil; 110 | } 111 | 112 | 113 | namespace rb 114 | { 115 | template<> 116 | sf::Joystick::Axis Value::to() const 117 | { 118 | unsigned int value = to(); 119 | return static_cast(value); 120 | } 121 | 122 | template<> 123 | Value Value::create( sf::Joystick::Axis value ) 124 | { 125 | return create(static_cast(value)); 126 | } 127 | 128 | template<> 129 | sf::Joystick::Identification Value::to() const 130 | { 131 | errorHandling(T_OBJECT); 132 | sf::Joystick::Identification identification; 133 | identification.name = getVar(); 134 | identification.vendorId = getVar(); 135 | identification.productId = getVar(); 136 | return identification; 137 | } 138 | 139 | template<> 140 | Value Value::create( sf::Joystick::Identification value ) 141 | { 142 | rb::Value object = rbJoystickIdentification::getDefinition().newObject(); 143 | object.setVar(value.name); 144 | object.setVar(value.productId); 145 | object.setVar(value.vendorId); 146 | return object; 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbjoystick.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBJOYSTICK_HPP 23 | #define RBSFML_RBJOYSTICK_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbJoystick; 30 | class rbJoystickIdentification; 31 | 32 | typedef rb::Module rbJoystickModule; 33 | typedef rb::Class rbJoystickIdentificationClass; 34 | 35 | class rbJoystick 36 | { 37 | public: 38 | static void defineModule(const rb::Value& sfml); 39 | 40 | private: 41 | friend class rbJoystickIdentification; 42 | 43 | static rbJoystickModule ourDefinition; 44 | }; 45 | 46 | 47 | class rbJoystickIdentification 48 | { 49 | public: 50 | static void defineClass(const rb::Value& sfml); 51 | static const rbJoystickIdentificationClass& getDefinition(); 52 | 53 | static void initialize(rb::Value self); 54 | static rb::Value initializeCopy(rb::Value self, const rb::Value& value); 55 | static std::vector marshalDump(const rb::Value& self); 56 | static rb::Value marshalLoad(rb::Value self, const rb::Value& data); 57 | 58 | private: 59 | friend class rbJoystick; 60 | 61 | static rbJoystickIdentificationClass ourDefinition; 62 | }; 63 | 64 | namespace rb 65 | { 66 | template<> 67 | sf::Joystick::Axis Value::to() const; 68 | 69 | template<> 70 | Value Value::create( sf::Joystick::Axis value ); 71 | 72 | template<> 73 | sf::Joystick::Identification Value::to() const; 74 | 75 | template<> 76 | Value Value::create( sf::Joystick::Identification value ); 77 | } 78 | 79 | #endif // RBSFML_RBJOYSTICK_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbkeyboard.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBKEYBOARD_HPP 23 | #define RBSFML_RBKEYBOARD_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbKeyboard; 30 | 31 | typedef rb::Module rbKeyboardModule; 32 | 33 | class rbKeyboard 34 | { 35 | public: 36 | static void defineModule(const rb::Value& sfml); 37 | 38 | private: 39 | static rbKeyboardModule ourDefinition; 40 | }; 41 | 42 | namespace rb 43 | { 44 | template<> 45 | sf::Keyboard::Key Value::to() const; 46 | 47 | template<> 48 | Value Value::create( sf::Keyboard::Key value ); 49 | } 50 | 51 | #endif // RBSFML_RBKEYBOARD_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbmouse.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbmouse.hpp" 23 | #include "rbvector2.hpp" 24 | #include "error.hpp" 25 | #include "macros.hpp" 26 | 27 | rbMouseModule rbMouse::ourDefinition; 28 | 29 | void rbMouse::defineModule(const rb::Value& sfml) 30 | { 31 | ourDefinition = rbMouseModule::defineModuleUnder("Mouse", sfml); 32 | ourDefinition.defineFunction<0>("button_pressed?", &sf::Mouse::isButtonPressed); 33 | ourDefinition.defineFunction<1>("get_position", &rbMouse::getPosition); 34 | ourDefinition.defineFunction<2>("set_position", &rbMouse::setPosition); 35 | 36 | ourDefinition.defineConstant("Left", rb::Value(sf::Mouse::Left)); 37 | ourDefinition.defineConstant("Right", rb::Value(sf::Mouse::Right)); 38 | ourDefinition.defineConstant("Middle", rb::Value(sf::Mouse::Middle)); 39 | ourDefinition.defineConstant("XButton1", rb::Value(sf::Mouse::XButton1)); 40 | ourDefinition.defineConstant("XButton2", rb::Value(sf::Mouse::XButton2)); 41 | ourDefinition.defineConstant("ButtonCount", rb::Value(sf::Mouse::ButtonCount)); 42 | ourDefinition.defineConstant("VerticalWheel", rb::Value(sf::Mouse::VerticalWheel)); 43 | ourDefinition.defineConstant("HorizontalWheel", rb::Value(sf::Mouse::HorizontalWheel)); 44 | } 45 | 46 | rb::Value rbMouse::getPosition(const std::vector& arguments) 47 | { 48 | sf::Vector2i result; 49 | switch(arguments.size()) 50 | { 51 | case 0: 52 | result = sf::Mouse::getPosition(); 53 | break; 54 | case 1: 55 | result = sf::Mouse::getPosition(arguments[0].to()); 56 | break; 57 | default: 58 | rb::expectedNumArgs(arguments.size(), 0, 1); 59 | } 60 | return rb::Value::create(result); 61 | } 62 | 63 | rb::Value rbMouse::setPosition(const std::vector& arguments) 64 | { 65 | switch(arguments.size()) 66 | { 67 | case 1: 68 | sf::Mouse::setPosition(arguments[0].to()); 69 | break; 70 | case 2: 71 | sf::Mouse::setPosition(arguments[0].to(), arguments[1].to()); 72 | break; 73 | default: 74 | rb::expectedNumArgs(arguments.size(), 1, 2); 75 | } 76 | return rb::Nil; 77 | } 78 | 79 | namespace rb 80 | { 81 | 82 | template<> 83 | sf::Mouse::Button Value::to() const 84 | { 85 | unsigned int value = to(); 86 | return static_cast(value); 87 | } 88 | 89 | template<> 90 | Value Value::create(sf::Mouse::Button value) 91 | { 92 | return create(static_cast(value)); 93 | } 94 | 95 | template<> 96 | sf::Mouse::Wheel Value::to() const 97 | { 98 | unsigned int value = to(); 99 | return static_cast(value); 100 | } 101 | 102 | template<> 103 | Value Value::create(sf::Mouse::Wheel value) 104 | { 105 | return create(static_cast(value)); 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbmouse.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBMOUSE_HPP 23 | #define RBSFML_RBMOUSE_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbMouse; 30 | 31 | typedef rb::Module rbMouseModule; 32 | 33 | class rbMouse 34 | { 35 | public: 36 | static void defineModule(const rb::Value& sfml); 37 | 38 | static rb::Value getPosition(const std::vector& arguments); 39 | static rb::Value setPosition(const std::vector& arguments); 40 | 41 | private: 42 | static rbMouseModule ourDefinition; 43 | }; 44 | 45 | namespace rb 46 | { 47 | template<> 48 | sf::Mouse::Button Value::to() const; 49 | template<> 50 | sf::Mouse::Wheel Value::to() const; 51 | 52 | template<> 53 | Value Value::create( sf::Mouse::Button value ); 54 | template<> 55 | Value Value::create( sf::Mouse::Wheel value ); 56 | } 57 | 58 | #endif // RBSFML_RBMOUSE_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbnoncopyable.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbnoncopyable.hpp" 23 | #include "error.hpp" 24 | #include "macros.hpp" 25 | 26 | rbNonCopyableModule rbNonCopyable::ourDefinition; 27 | 28 | void rbNonCopyable::defineModule(const rb::Value& sfml) 29 | { 30 | ourDefinition = rbNonCopyableModule::defineModuleUnder("NonCopyable", sfml); 31 | ourDefinition.defineMethod<0>("initialize_copy", &rbNonCopyable::initializeCopy); 32 | ourDefinition.defineMethod<1>("marshal_dump", &rbNonCopyable::marshalDump); 33 | } 34 | 35 | rbNonCopyableModule rbNonCopyable::getDefinition() 36 | { 37 | return ourDefinition; 38 | } 39 | 40 | const rb::Value& rbNonCopyable::initializeCopy(const rb::Value& self, const rb::Value& value) 41 | { 42 | std::string type = self.getClassName(); 43 | rb::raise(rb::RuntimeError, "%s can not be copied!", type.c_str()); 44 | return rb::Nil; 45 | } 46 | 47 | const rb::Value& rbNonCopyable::marshalDump(const rb::Value& self) 48 | { 49 | std::string type = self.getClassName(); 50 | rb::raise(rb::TypeError, "can't dump %s", type.c_str()); 51 | return rb::Nil; 52 | } 53 | -------------------------------------------------------------------------------- /ext/rbsfml/rbnoncopyable.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBNONCOPYABLE_HPP 23 | #define RBSFML_RBNONCOPYABLE_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbNonCopyable; 30 | 31 | typedef rb::Module rbNonCopyableModule; 32 | 33 | class rbNonCopyable 34 | { 35 | public: 36 | static void defineModule(const rb::Value& sfml); 37 | static rbNonCopyableModule getDefinition(); 38 | 39 | static const rb::Value& initializeCopy(const rb::Value& self, const rb::Value& value); 40 | static const rb::Value& marshalDump(const rb::Value& self); 41 | 42 | private: 43 | static rbNonCopyableModule ourDefinition; 44 | }; 45 | 46 | #endif // RBSFML_RBNONCOPYABLE_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbrect.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBRECT_HPP 23 | #define RBSFML_RBRECT_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbRect; 30 | 31 | typedef rb::Class rbRectClass; 32 | 33 | class rbRect 34 | { 35 | public: 36 | static void defineClass(const rb::Value& sfml); 37 | static const rbRectClass& getDefinition(); 38 | 39 | static rb::Value initialize(rb::Value self, const std::vector& args); 40 | static rb::Value initializeCopy(rb::Value self, const rb::Value& value); 41 | static std::vector marshalDump(const rb::Value& self); 42 | static rb::Value marshalLoad(rb::Value self, const rb::Value& data); 43 | 44 | static rb::Value contains(rb::Value self, const std::vector& args); 45 | static rb::Value intersects(const rb::Value& self, const rb::Value& other); 46 | 47 | static bool equal(const rb::Value& self, const rb::Value& other); 48 | static bool strictEqual(const rb::Value& self, const rb::Value& other); 49 | 50 | static std::string inspect(const rb::Value& self); 51 | 52 | private: 53 | static rbRectClass ourDefinition; 54 | }; 55 | 56 | namespace rb 57 | { 58 | template<> 59 | sf::FloatRect Value::to() const; 60 | template<> 61 | sf::IntRect Value::to() const; 62 | 63 | template<> 64 | Value Value::create( sf::FloatRect value ); 65 | template<> 66 | Value Value::create( const sf::FloatRect& value ); 67 | template<> 68 | Value Value::create( sf::IntRect value ); 69 | template<> 70 | Value Value::create( const sf::IntRect& value ); 71 | } 72 | 73 | #endif // RBSFML_RBRECT_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbrenderbasetype.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbrenderbasetype.hpp" 23 | #include "error.hpp" 24 | #include "macros.hpp" 25 | #include "base.hpp" 26 | 27 | rbRenderBaseType::~rbRenderBaseType() 28 | { 29 | } 30 | 31 | rbRenderBaseType::rbRenderBaseType() 32 | { 33 | } 34 | 35 | sf::RenderTarget* rbRenderBaseType::getRenderTarget() { return nullptr; } 36 | const sf::RenderTarget* rbRenderBaseType::getRenderTarget() const { return nullptr; } 37 | 38 | sf::Window* rbRenderBaseType::getWindow() { return nullptr; } 39 | const sf::Window* rbRenderBaseType::getWindow() const { return nullptr; } 40 | 41 | sf::RenderWindow* rbRenderBaseType::getRenderWindow() { return nullptr; } 42 | const sf::RenderWindow* rbRenderBaseType::getRenderWindow() const { return nullptr; } 43 | 44 | namespace rb 45 | { 46 | 47 | template<> 48 | rbRenderBaseType* Value::to() const 49 | { 50 | errorHandling(T_DATA); 51 | rbRenderBaseType* object = nullptr; 52 | if(myValue != Qnil) 53 | Data_Get_Struct(myValue, rbRenderBaseType, object); 54 | return object; 55 | } 56 | 57 | template<> 58 | const rbRenderBaseType* Value::to() const 59 | { 60 | errorHandling(T_DATA); 61 | const rbRenderBaseType* object = nullptr; 62 | if(myValue != Qnil) 63 | Data_Get_Struct(myValue, rbRenderBaseType, object); 64 | return object; 65 | } 66 | 67 | template<> 68 | sf::RenderTarget& Value::to() const 69 | { 70 | return *to()->getRenderTarget(); 71 | } 72 | 73 | template<> 74 | const sf::RenderTarget& Value::to() const 75 | { 76 | return *to()->getRenderTarget(); 77 | } 78 | 79 | template<> 80 | sf::Window& Value::to() const 81 | { 82 | return *to()->getWindow(); 83 | } 84 | 85 | template<> 86 | const sf::Window& Value::to() const 87 | { 88 | return *to()->getWindow(); 89 | } 90 | 91 | template<> 92 | sf::RenderWindow& Value::to() const 93 | { 94 | return *to()->getRenderWindow(); 95 | } 96 | 97 | template<> 98 | const sf::RenderWindow& Value::to() const 99 | { 100 | return *to()->getRenderWindow(); 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbrenderbasetype.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBRENDERBASETYPE_HPP_ 23 | #define RBSFML_RBRENDERBASETYPE_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "object.hpp" 27 | 28 | namespace sf 29 | { 30 | class RenderTarget; 31 | class Window; 32 | class RenderWindow; 33 | } 34 | 35 | class rbRenderBaseType : public rb::Object 36 | { 37 | public: 38 | virtual ~rbRenderBaseType(); 39 | 40 | protected: 41 | friend class rb::Value; 42 | 43 | rbRenderBaseType(); 44 | 45 | virtual sf::RenderTarget* getRenderTarget(); 46 | virtual const sf::RenderTarget* getRenderTarget() const; 47 | 48 | virtual sf::Window* getWindow(); 49 | virtual const sf::Window* getWindow() const; 50 | 51 | virtual sf::RenderWindow* getRenderWindow(); 52 | virtual const sf::RenderWindow* getRenderWindow() const; 53 | }; 54 | 55 | namespace rb 56 | { 57 | template<> 58 | rbRenderBaseType* Value::to() const; 59 | template<> 60 | const rbRenderBaseType* Value::to() const; 61 | 62 | template<> 63 | sf::RenderTarget& Value::to() const; 64 | template<> 65 | const sf::RenderTarget& Value::to() const; 66 | 67 | template<> 68 | sf::Window& Value::to() const; 69 | template<> 70 | const sf::Window& Value::to() const; 71 | 72 | template<> 73 | sf::RenderWindow& Value::to() const; 74 | template<> 75 | const sf::RenderWindow& Value::to() const; 76 | } 77 | 78 | #endif // RBSFML_RBRENDERTARGET_HPP_ 79 | -------------------------------------------------------------------------------- /ext/rbsfml/rbrenderstates.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbrenderstates.hpp" 23 | #include "rbblendmode.hpp" 24 | #include "rbtransform.hpp" 25 | #include "rbtexture.hpp" 26 | #include "rbshader.hpp" 27 | #include "error.hpp" 28 | #include "macros.hpp" 29 | #include "base.hpp" 30 | 31 | namespace 32 | { 33 | constexpr char symVarBlendMode[] = "@blend_mode"; 34 | constexpr char symVarTransform[] = "@transform"; 35 | constexpr char symVarTexture[] = "@texture"; 36 | constexpr char symVarShader[] = "@shader"; 37 | } 38 | 39 | rbRenderStatesClass rbRenderStates::ourDefinition; 40 | 41 | void rbRenderStates::defineClass(const rb::Value& sfml) 42 | { 43 | ourDefinition = rbRenderStatesClass::defineClassUnder("RenderStates", sfml); 44 | ourDefinition.defineMethod<0>("initialize", &rbRenderStates::initialize); 45 | ourDefinition.defineMethod<1>("initialize_copy", &rbRenderStates::initializeCopy); 46 | ourDefinition.defineMethod<2>("marshal_dump", &rbRenderStates::marshalDump); 47 | 48 | ourDefinition.defineAttribute("blend_mode", true, true); 49 | ourDefinition.defineAttribute("transform", true, true); 50 | ourDefinition.defineAttribute("texture", true, true); 51 | ourDefinition.defineAttribute("shader", true, true); 52 | } 53 | 54 | const rbRenderStatesClass& rbRenderStates::getDefinition() 55 | { 56 | return ourDefinition; 57 | } 58 | 59 | rb::Value rbRenderStates::initialize(rb::Value self, const std::vector& args) 60 | { 61 | self.setVar(rbBlendMode::getDefinition().newObject()); 62 | self.setVar(rbTransform::getDefinition().newObject()); 63 | self.setVar(rb::Nil); 64 | self.setVar(rb::Nil); 65 | switch( args.size() ) 66 | { 67 | case 0: 68 | break; 69 | case 1: 70 | if(args[0].isKindOf(rb::Value(rbBlendMode::getDefinition()))) 71 | { 72 | self.setVar(args[0]); 73 | } 74 | else if(args[0].isKindOf(rb::Value(rbTransform::getDefinition()))) 75 | { 76 | self.setVar(args[0]); 77 | } 78 | else if(args[0].isKindOf(rb::Value(rbTexture::getDefinition()))) 79 | { 80 | self.setVar(args[0]); 81 | } 82 | else if(args[0].isKindOf(rb::Value(rbShader::getDefinition()))) 83 | { 84 | self.setVar(args[0]); 85 | } 86 | else 87 | { 88 | rbRenderStates::initializeCopy(self, args[0]); 89 | } 90 | break; 91 | case 4: 92 | self.setVar(args[0]); 93 | self.setVar(args[1]); 94 | self.setVar(args[2]); 95 | self.setVar(args[3]); 96 | break; 97 | default: 98 | rb::expectedNumArgs( args.size(), "0, 1 or 4" ); 99 | break; 100 | } 101 | 102 | return self; 103 | } 104 | 105 | rb::Value rbRenderStates::initializeCopy(rb::Value self, const rb::Value& value) 106 | { 107 | self.setVar(value.getVar()); 108 | self.setVar(value.getVar()); 109 | self.setVar(value.getVar()); 110 | self.setVar(value.getVar()); 111 | return self; 112 | } 113 | 114 | rb::Value rbRenderStates::marshalDump() const 115 | { 116 | rb::raise(rb::TypeError, "can't dump %s", ourDefinition.getName().c_str() ); 117 | return rb::Nil; 118 | } 119 | 120 | namespace rb 121 | { 122 | 123 | template<> 124 | sf::RenderStates Value::to() const 125 | { 126 | errorHandling(T_OBJECT); 127 | sf::RenderStates states( 128 | getVar(), getVar(), 129 | nullptr, nullptr 130 | ); 131 | if(getVar() != rb::Nil) 132 | states.texture = &getVar(); 133 | if(getVar() != rb::Nil) 134 | states.shader = &getVar(); 135 | return states; 136 | } 137 | 138 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbrenderstates.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBRENDERSTATES_HPP 23 | #define RBSFML_RBRENDERSTATES_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbRenderStates; 30 | 31 | typedef rb::Class rbRenderStatesClass; 32 | 33 | class rbRenderStates 34 | { 35 | public: 36 | static void defineClass(const rb::Value& sfml); 37 | static const rbRenderStatesClass& getDefinition(); 38 | 39 | static rb::Value initialize(rb::Value self, const std::vector& args); 40 | static rb::Value initializeCopy(rb::Value self, const rb::Value& value); 41 | rb::Value marshalDump() const; 42 | 43 | private: 44 | static rbRenderStatesClass ourDefinition; 45 | }; 46 | 47 | namespace rb 48 | { 49 | template<> 50 | sf::RenderStates Value::to() const; 51 | } 52 | 53 | #endif // RBSFML_RBRENDERSTATES_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbrendertarget.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBRENDERTARGET_HPP_ 23 | #define RBSFML_RBRENDERTARGET_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "rbrenderbasetype.hpp" 28 | 29 | class rbView; 30 | class rbRenderTarget; 31 | class rbRenderTargetRef; 32 | 33 | typedef rb::Module rbRenderTargetModule; 34 | typedef rb::Class rbRenderTargetRefClass; 35 | 36 | class rbRenderTarget : public virtual rbRenderBaseType 37 | { 38 | public: 39 | static void defineModule(const rb::Value& sfml); 40 | static rbRenderTargetModule& getDefinition(); 41 | static rbRenderTargetRefClass& getRefDefinition(); 42 | 43 | rbRenderTarget(); 44 | virtual ~rbRenderTarget(); 45 | 46 | static rb::Value clear(rb::Value self, const std::vector& args); 47 | 48 | void setView(const rbView* view); 49 | rbView* getView() const; 50 | rbView* getDefaultView() const; 51 | 52 | sf::IntRect getViewport(const rbView* view); 53 | 54 | static rb::Value mapPixelToCoords(rb::Value self, const std::vector& args); 55 | static rb::Value mapCoordsToPixel(rb::Value self, const std::vector& args); 56 | 57 | sf::Vector2u getSize() const; 58 | 59 | void pushGLStates(); 60 | void popGLStates(); 61 | void resetGLStates(); 62 | 63 | static rb::Value draw(rb::Value self, const std::vector& args); 64 | 65 | private: 66 | friend class rb::Value; 67 | static rbRenderTargetModule ourDefinition; 68 | static rbRenderTargetRefClass ourRefDefinition; 69 | }; 70 | 71 | class rbRenderTargetRef : public rbRenderTarget 72 | { 73 | public: 74 | rbRenderTargetRef(); 75 | 76 | void setRef(sf::RenderTarget* object); 77 | 78 | protected: 79 | virtual sf::RenderTarget* getRenderTarget(); 80 | virtual const sf::RenderTarget* getRenderTarget() const; 81 | 82 | private: 83 | sf::RenderTarget* myObject; 84 | }; 85 | 86 | namespace rb 87 | { 88 | template<> 89 | rbRenderTarget* Value::to() const; 90 | template<> 91 | const rbRenderTarget* Value::to() const; 92 | 93 | template<> 94 | rbRenderTargetRef* Value::to() const; 95 | template<> 96 | const rbRenderTargetRef* Value::to() const; 97 | } 98 | 99 | #endif // RBSFML_RBRENDERTARGET_HPP_ 100 | -------------------------------------------------------------------------------- /ext/rbsfml/rbrendertexture.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBRENDERTEXTURE_HPP_ 23 | #define RBSFML_RBRENDERTEXTURE_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "rbrendertarget.hpp" 28 | 29 | class rbRenderTexture; 30 | class rbTexture; 31 | 32 | typedef rb::Class rbRenderTextureClass; 33 | 34 | class rbRenderTexture : public rbRenderTarget 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static rbRenderTextureClass& getDefinition(); 39 | 40 | rbRenderTexture(); 41 | ~rbRenderTexture(); 42 | 43 | static rb::Value initialize(rb::Value self, const std::vector& args); 44 | static rb::Value create(rb::Value self, const std::vector& args); 45 | 46 | void setSmooth(bool smooth); 47 | bool isSmooth() const; 48 | 49 | void setRepeated(bool repeated); 50 | bool isRepeated() const; 51 | 52 | static rb::Value setActive(rb::Value self, const std::vector& args); 53 | 54 | void display(); 55 | 56 | sf::Vector2u getSize() const; 57 | 58 | rb::Value getTexture() const; 59 | 60 | protected: 61 | sf::RenderTarget* getRenderTarget(); 62 | const sf::RenderTarget* getRenderTarget() const; 63 | 64 | private: 65 | friend class rb::Value; 66 | 67 | static rbRenderTextureClass ourDefinition; 68 | 69 | sf::RenderTexture myObject; 70 | }; 71 | 72 | namespace rb 73 | { 74 | template<> 75 | rbRenderTexture* Value::to() const; 76 | template<> 77 | const rbRenderTexture* Value::to() const; 78 | } 79 | 80 | #endif // RBSFML_RBRENDERTEXTURE_HPP_ 81 | -------------------------------------------------------------------------------- /ext/rbsfml/rbrenderwindow.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbrenderwindow.hpp" 23 | #include "rbimage.hpp" 24 | #include "rbvector2.hpp" 25 | #include "error.hpp" 26 | #include "macros.hpp" 27 | #include "base.hpp" 28 | 29 | rbRenderWindowClass rbRenderWindow::ourDefinition; 30 | 31 | void rbRenderWindow::defineClass(const rb::Value& sfml) 32 | { 33 | ourDefinition = rbRenderWindowClass::defineClassUnder("RenderWindow", sfml, rb::Value(rbWindow::getDefinition())); 34 | ourDefinition.includeModule(rb::Value(rbRenderTarget::getDefinition())); 35 | ourDefinition.defineMethod<0>("size", &rbRenderWindow::getSize); 36 | ourDefinition.defineMethod<1>("capture", &rbRenderWindow::capture); 37 | } 38 | 39 | rbRenderWindowClass& rbRenderWindow::getDefinition() 40 | { 41 | return ourDefinition; 42 | } 43 | 44 | rbRenderWindow::rbRenderWindow() 45 | : rbWindow() 46 | , rbRenderTarget() 47 | , myObject() 48 | { 49 | } 50 | 51 | rbRenderWindow::~rbRenderWindow() 52 | { 53 | } 54 | 55 | sf::Vector2u rbRenderWindow::getSize() const 56 | { 57 | return myObject.getSize(); 58 | } 59 | 60 | rb::Value rbRenderWindow::capture() const 61 | { 62 | rb::Value value = rbImage::getDefinition().newObject(); 63 | value.to() = myObject.capture(); 64 | return value; 65 | } 66 | 67 | sf::RenderTarget* rbRenderWindow::getRenderTarget() 68 | { 69 | return &myObject; 70 | } 71 | 72 | const sf::RenderTarget* rbRenderWindow::getRenderTarget() const 73 | { 74 | return &myObject; 75 | } 76 | 77 | sf::Window* rbRenderWindow::getWindow() 78 | { 79 | return &myObject; 80 | } 81 | 82 | const sf::Window* rbRenderWindow::getWindow() const 83 | { 84 | return &myObject; 85 | } 86 | 87 | sf::RenderWindow* rbRenderWindow::getRenderWindow() 88 | { 89 | return &myObject; 90 | } 91 | 92 | const sf::RenderWindow* rbRenderWindow::getRenderWindow() const 93 | { 94 | return &myObject; 95 | } 96 | 97 | namespace rb 98 | { 99 | 100 | template<> 101 | rbRenderWindow* Value::to() const 102 | { 103 | errorHandling(T_DATA); 104 | rbRenderWindow* object = nullptr; 105 | if(myValue != Qnil) 106 | Data_Get_Struct(myValue, rbRenderWindow, object); 107 | return object; 108 | } 109 | 110 | template<> 111 | const rbRenderWindow* Value::to() const 112 | { 113 | errorHandling(T_DATA); 114 | const rbRenderWindow* object = nullptr; 115 | if(myValue != Qnil) 116 | Data_Get_Struct(myValue, rbRenderWindow, object); 117 | return object; 118 | } 119 | 120 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbrenderwindow.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBRENDERWINDOW_HPP_ 23 | #define RBSFML_RBRENDERWINDOW_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "rbwindow.hpp" 28 | #include "rbrendertarget.hpp" 29 | 30 | class rbRenderWindow; 31 | class rbContextSettings; 32 | class rbEvent; 33 | 34 | typedef rb::Class rbRenderWindowClass; 35 | 36 | class rbRenderWindow : public rbWindow, public rbRenderTarget 37 | { 38 | public: 39 | static void defineClass(const rb::Value& sfml); 40 | static rbRenderWindowClass& getDefinition(); 41 | 42 | rbRenderWindow(); 43 | ~rbRenderWindow(); 44 | 45 | sf::Vector2u getSize() const; 46 | 47 | rb::Value capture() const; 48 | 49 | protected: 50 | sf::RenderTarget* getRenderTarget(); 51 | const sf::RenderTarget* getRenderTarget() const; 52 | 53 | sf::Window* getWindow(); 54 | const sf::Window* getWindow() const; 55 | 56 | sf::RenderWindow* getRenderWindow(); 57 | const sf::RenderWindow* getRenderWindow() const; 58 | 59 | private: 60 | friend class rb::Value; 61 | 62 | static rbRenderWindowClass ourDefinition; 63 | 64 | sf::RenderWindow myObject; 65 | }; 66 | 67 | namespace rb 68 | { 69 | template<> 70 | rbRenderWindow* Value::to() const; 71 | template<> 72 | const rbRenderWindow* Value::to() const; 73 | } 74 | 75 | #endif // RBSFML_RBRENDERWINDOW_HPP_ 76 | -------------------------------------------------------------------------------- /ext/rbsfml/rbsensor.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbsensor.hpp" 23 | #include "rbvector3.hpp" 24 | #include "error.hpp" 25 | #include "macros.hpp" 26 | 27 | rbSensorModule rbSensor::ourDefinition; 28 | 29 | void rbSensor::defineModule(const rb::Value& sfml) 30 | { 31 | ourDefinition = rbSensorModule::defineModuleUnder("Sensor", sfml); 32 | ourDefinition.defineFunction<0>("available?", &sf::Sensor::isAvailable); 33 | ourDefinition.defineFunction<1>("set_enabled", &sf::Sensor::setEnabled); 34 | ourDefinition.defineFunction<2>("get_value", &sf::Sensor::getValue); 35 | 36 | ourDefinition.defineConstant("Accelerometer", rb::Value(sf::Sensor::Accelerometer)); 37 | ourDefinition.defineConstant("Gyroscope", rb::Value(sf::Sensor::Gyroscope)); 38 | ourDefinition.defineConstant("Magnetometer", rb::Value(sf::Sensor::Magnetometer)); 39 | ourDefinition.defineConstant("Gravity", rb::Value(sf::Sensor::Gravity)); 40 | ourDefinition.defineConstant("UserAcceleration", rb::Value(sf::Sensor::UserAcceleration)); 41 | ourDefinition.defineConstant("Orientation", rb::Value(sf::Sensor::Orientation)); 42 | ourDefinition.defineConstant("Count", rb::Value(sf::Sensor::Count)); 43 | } 44 | 45 | namespace rb 46 | { 47 | 48 | template<> 49 | sf::Sensor::Type Value::to() const 50 | { 51 | unsigned int value = to(); 52 | return static_cast(value); 53 | } 54 | 55 | template<> 56 | Value Value::create(sf::Sensor::Type value) 57 | { 58 | return create(static_cast(value)); 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbsensor.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBSENSOR_HPP 23 | #define RBSFML_RBSENSOR_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbSensor; 30 | 31 | typedef rb::Module rbSensorModule; 32 | 33 | class rbSensor 34 | { 35 | public: 36 | static void defineModule(const rb::Value& sfml); 37 | 38 | private: 39 | static rbSensorModule ourDefinition; 40 | }; 41 | 42 | namespace rb 43 | { 44 | template<> 45 | sf::Sensor::Type Value::to() const; 46 | 47 | template<> 48 | Value Value::create( sf::Sensor::Type value ); 49 | } 50 | 51 | #endif // RBSFML_RBSENSOR_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbsfml.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include 23 | #include 24 | #include "module.hpp" 25 | #include "class.hpp" 26 | #include "rbtime.hpp" 27 | #include "rbclock.hpp" 28 | #include "rbnoncopyable.hpp" 29 | #include "rbvector2.hpp" 30 | #include "rbvector3.hpp" 31 | #include "rbvideomode.hpp" 32 | #include "rbcontextsettings.hpp" 33 | #include "rbcontext.hpp" 34 | #include "rbwindow.hpp" 35 | #include "rbevent.hpp" 36 | #include "rbjoystick.hpp" 37 | #include "rbkeyboard.hpp" 38 | #include "rbmouse.hpp" 39 | #include "rbsensor.hpp" 40 | #include "rbtouch.hpp" 41 | #include "rbcolor.hpp" 42 | #include "rbblendmode.hpp" 43 | #include "rbtransform.hpp" 44 | #include "rbview.hpp" 45 | #include "rbimage.hpp" 46 | #include "rbtexture.hpp" 47 | #include "rbshader.hpp" 48 | #include "rbrenderstates.hpp" 49 | #include "rbrendertarget.hpp" 50 | #include "rbvertex.hpp" 51 | #include "rbrenderwindow.hpp" 52 | #include "rbtransformable.hpp" 53 | #include "rbdrawable.hpp" 54 | #include "rbsprite.hpp" 55 | #include "rbvertex.hpp" 56 | #include "rbfont.hpp" 57 | #include "rbtext.hpp" 58 | #include "rbshape.hpp" 59 | #include "rbdataptr.hpp" 60 | #include "rbrect.hpp" 61 | #include "rbrendertexture.hpp" 62 | #include "rbvertexarray.hpp" 63 | 64 | class rbSFML 65 | { 66 | public: 67 | static void sleep(rbTime* time) 68 | { 69 | sf::sleep(time->getObject()); 70 | } 71 | }; 72 | 73 | extern "C" void Init_rbsfml() { 74 | auto sfml = rb::Module::defineModule("SFML"); 75 | 76 | sfml.defineFunction<0>("seconds", &rbTime::seconds); 77 | sfml.defineFunction<1>("milliseconds", &rbTime::milliseconds); 78 | sfml.defineFunction<2>("microseconds", &rbTime::microseconds); 79 | sfml.defineFunction<3>("sleep", &rbSFML::sleep); 80 | 81 | sfml.defineConstant("Points", rb::Value::create(sf::Points)); 82 | sfml.defineConstant("Lines", rb::Value::create(sf::Lines)); 83 | sfml.defineConstant("LinesStrip", rb::Value::create(sf::LinesStrip)); 84 | sfml.defineConstant("Triangles", rb::Value::create(sf::Triangles)); 85 | sfml.defineConstant("TrianglesStrip", rb::Value::create(sf::TrianglesStrip)); 86 | sfml.defineConstant("TrianglesFan", rb::Value::create(sf::TrianglesFan)); 87 | sfml.defineConstant("Quads", rb::Value::create(sf::Quads)); 88 | 89 | // System 90 | rbNonCopyable::defineModule(rb::Value(sfml)); 91 | rbDataPtr::defineClass(rb::Value(sfml)); 92 | rbVector2::defineClass(rb::Value(sfml)); 93 | rbVector3::defineClass(rb::Value(sfml)); 94 | rbTime::defineClass(rb::Value(sfml)); 95 | rbClock::defineClass(rb::Value(sfml)); 96 | 97 | // Window 98 | rbVideoMode::defineClass(rb::Value(sfml)); 99 | rbContextSettings::defineClass(rb::Value(sfml)); 100 | rbContext::defineClass(rb::Value(sfml)); 101 | rbWindow::defineClass(rb::Value(sfml)); 102 | rbEvent::defineClass(rb::Value(sfml)); 103 | rbJoystick::defineModule(rb::Value(sfml)); 104 | rbKeyboard::defineModule(rb::Value(sfml)); 105 | rbMouse::defineModule(rb::Value(sfml)); 106 | rbSensor::defineModule(rb::Value(sfml)); 107 | rbTouch::defineModule(rb::Value(sfml)); 108 | 109 | // Graphics 110 | rbRect::defineClass(rb::Value(sfml)); 111 | rbColor::defineClass(rb::Value(sfml)); 112 | rbBlendMode::defineClass(rb::Value(sfml)); 113 | rbTransform::defineClass(rb::Value(sfml)); 114 | rbView::defineClass(rb::Value(sfml)); 115 | rbImage::defineClass(rb::Value(sfml)); 116 | rbTexture::defineClass(rb::Value(sfml)); 117 | rbShader::defineClass(rb::Value(sfml)); 118 | rbRenderStates::defineClass(rb::Value(sfml)); 119 | rbRenderTarget::defineModule(rb::Value(sfml)); 120 | rbVertex::defineClass(rb::Value(sfml)); 121 | rbRenderWindow::defineClass(rb::Value(sfml)); 122 | rbTransformable::defineModule(rb::Value(sfml)); 123 | rbDrawable::defineModule(rb::Value(sfml)); 124 | rbSprite::defineClass(rb::Value(sfml)); 125 | rbVertex::defineClass(rb::Value(sfml)); 126 | rbFont::defineClass(rb::Value(sfml)); 127 | rbText::defineClass(rb::Value(sfml)); 128 | rbShape::defineClass(rb::Value(sfml)); 129 | rbRenderTexture::defineClass(rb::Value(sfml)); 130 | rbVertexArray::defineClass(rb::Value(sfml)); 131 | 132 | rbDrawable::defineIncludeFunction(); 133 | rbTransformable::defineIncludeFunction(); 134 | } 135 | -------------------------------------------------------------------------------- /ext/rbsfml/rbshader.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBSHADER_HPP_ 23 | #define RBSFML_RBSHADER_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbShader; 30 | 31 | typedef rb::Class rbShaderClass; 32 | 33 | class rbShader : public rb::Object 34 | { 35 | public: 36 | static void defineClass(const rb::Value& sfml); 37 | static rbShaderClass& getDefinition(); 38 | 39 | rbShader(); 40 | ~rbShader(); 41 | 42 | bool loadFromFile(rb::Value arg1, rb::Value arg2); 43 | bool loadFromMemory(rb::Value arg1, rb::Value arg2); 44 | 45 | static rb::Value setParameter(rb::Value self, const std::vector& args); 46 | 47 | unsigned int getNativeHandle() const; 48 | 49 | static void bind(const rbShader* shader); 50 | static bool isAvailable(); 51 | 52 | private: 53 | friend class rb::Value; 54 | static rbShaderClass ourDefinition; 55 | static rb::Module ourCurrentTextureTypeDefinition; 56 | 57 | sf::Shader myObject; 58 | }; 59 | 60 | namespace rb 61 | { 62 | template<> 63 | rbShader* Value::to() const; 64 | template<> 65 | const rbShader* Value::to() const; 66 | template<> 67 | sf::Shader& Value::to() const; 68 | template<> 69 | const sf::Shader& Value::to() const; 70 | 71 | template<> 72 | sf::Shader::Type Value::to() const; 73 | template<> 74 | Value Value::create(sf::Shader::Type value); 75 | } 76 | 77 | #endif // RBSFML_RBSHADER_HPP_ 78 | -------------------------------------------------------------------------------- /ext/rbsfml/rbshape.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBSHAPE_HPP_ 23 | #define RBSFML_RBSHAPE_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "rbdrawable.hpp" 27 | #include "rbtransformable.hpp" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | class rbShape; 35 | class rbCircleShape; 36 | class rbRectangleShape; 37 | class rbConvexShape; 38 | 39 | typedef rb::Class rbShapeClass; 40 | typedef rb::Class rbCircleShapeClass; 41 | typedef rb::Class rbRectangleShapeClass; 42 | typedef rb::Class rbConvexShapeClass; 43 | 44 | class rbShape : public rbTransformable 45 | { 46 | public: 47 | static void defineClass(const rb::Value& sfml); 48 | static rbShapeClass& getDefinition(); 49 | 50 | rbShape(); 51 | ~rbShape(); 52 | 53 | rb::Value marshalDump() const; 54 | 55 | static rb::Value setTexture(rb::Value self, const std::vector& args); 56 | rb::Value getTexture() const; 57 | 58 | void setTextureRect(sf::IntRect rect); 59 | const sf::IntRect& getTextureRect() const; 60 | 61 | void setFillColor(sf::Color color); 62 | const sf::Color& getFillColor() const; 63 | void setOutlineColor(sf::Color color); 64 | const sf::Color& getOutlineColor() const; 65 | 66 | void setOutlineThickness(float thickness); 67 | float getOutlineThickness() const; 68 | 69 | sf::FloatRect getLocalBounds() const; 70 | sf::FloatRect getGlobalBounds() const; 71 | 72 | unsigned int getPointCount() const; 73 | sf::Vector2f getPoint(unsigned int index); 74 | 75 | protected: 76 | virtual sf::Drawable* getDrawable(); 77 | virtual const sf::Drawable* getDrawable() const; 78 | 79 | virtual sf::Transformable* getTransformable(); 80 | virtual const sf::Transformable* getTransformable() const; 81 | 82 | virtual sf::Shape& getShape() = 0; 83 | virtual const sf::Shape& getShape() const = 0; 84 | 85 | private: 86 | friend class rb::Value; 87 | 88 | static rbShapeClass ourDefinition; 89 | static rbCircleShapeClass ourCircleDefinition; 90 | static rbRectangleShapeClass ourRectangleDefinition; 91 | static rbConvexShapeClass ourConvexDefinition; 92 | }; 93 | 94 | class rbCircleShape : public rbShape 95 | { 96 | public: 97 | static rb::Value initialize(rb::Value self, const std::vector& args); 98 | 99 | void setRadius(float radius); 100 | float getRadius() const; 101 | void setPointCount(unsigned int count); 102 | 103 | protected: 104 | sf::Shape& getShape(); 105 | const sf::Shape& getShape() const; 106 | 107 | private: 108 | sf::CircleShape myObject; 109 | }; 110 | 111 | class rbRectangleShape : public rbShape 112 | { 113 | public: 114 | static rb::Value initialize(rb::Value self, const std::vector& args); 115 | 116 | void setSize(sf::Vector2f size); 117 | const sf::Vector2f& getSize() const; 118 | 119 | protected: 120 | sf::Shape& getShape(); 121 | const sf::Shape& getShape() const; 122 | 123 | private: 124 | sf::RectangleShape myObject; 125 | }; 126 | 127 | class rbConvexShape : public rbShape 128 | { 129 | public: 130 | static rb::Value initialize(rb::Value self, const std::vector& args); 131 | 132 | void setPointCount(unsigned int count); 133 | void setPoint(unsigned int index, sf::Vector2f point); 134 | 135 | protected: 136 | sf::Shape& getShape(); 137 | const sf::Shape& getShape() const; 138 | 139 | private: 140 | sf::ConvexShape myObject; 141 | }; 142 | 143 | namespace rb 144 | { 145 | template<> 146 | rbShape* Value::to() const; 147 | template<> 148 | const rbShape* Value::to() const; 149 | template<> 150 | rbCircleShape* Value::to() const; 151 | template<> 152 | const rbCircleShape* Value::to() const; 153 | template<> 154 | rbRectangleShape* Value::to() const; 155 | template<> 156 | const rbRectangleShape* Value::to() const; 157 | template<> 158 | rbConvexShape* Value::to() const; 159 | template<> 160 | const rbConvexShape* Value::to() const; 161 | 162 | template<> 163 | sf::Shape& Value::to() const; 164 | template<> 165 | const sf::Shape& Value::to() const; 166 | } 167 | 168 | #endif // RBSFML_RBSHAPE_HPP_ 169 | -------------------------------------------------------------------------------- /ext/rbsfml/rbsprite.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBSPRITE_HPP_ 23 | #define RBSFML_RBSPRITE_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "rbdrawable.hpp" 27 | #include "rbtransformable.hpp" 28 | 29 | #include 30 | 31 | class rbSprite; 32 | 33 | typedef rb::Class rbSpriteClass; 34 | 35 | class rbSprite : public rbTransformable 36 | { 37 | public: 38 | static void defineClass(const rb::Value& sfml); 39 | static rbSpriteClass& getDefinition(); 40 | 41 | rbSprite(); 42 | ~rbSprite(); 43 | 44 | static rb::Value initialize(rb::Value self, const std::vector& args); 45 | rbSprite* initializeCopy(const rbSprite* value); 46 | 47 | rb::Value marshalDump() const; 48 | 49 | static rb::Value setTexture(rb::Value self, const std::vector& args); 50 | rb::Value getTexture() const; 51 | 52 | void setTextureRect(sf::IntRect rect); 53 | const sf::IntRect& getTextureRect() const; 54 | 55 | void setColor(sf::Color color); 56 | const sf::Color& getColor() const; 57 | 58 | sf::FloatRect getLocalBounds() const; 59 | sf::FloatRect getGlobalBounds() const; 60 | 61 | protected: 62 | virtual sf::Drawable* getDrawable(); 63 | virtual const sf::Drawable* getDrawable() const; 64 | 65 | virtual sf::Transformable* getTransformable(); 66 | virtual const sf::Transformable* getTransformable() const; 67 | 68 | private: 69 | friend class rb::Value; 70 | static rbSpriteClass ourDefinition; 71 | 72 | sf::Sprite myObject; 73 | }; 74 | 75 | namespace rb 76 | { 77 | template<> 78 | rbSprite* Value::to() const; 79 | template<> 80 | const rbSprite* Value::to() const; 81 | template<> 82 | sf::Sprite& Value::to() const; 83 | template<> 84 | const sf::Sprite& Value::to() const; 85 | } 86 | 87 | #endif // RBSFML_RBSPRITE_HPP_ 88 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtext.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBTEXT_HPP_ 23 | #define RBSFML_RBTEXT_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "rbdrawable.hpp" 27 | #include "rbtransformable.hpp" 28 | 29 | #include 30 | 31 | class rbText; 32 | 33 | typedef rb::Class rbTextClass; 34 | 35 | class rbText : public rbTransformable 36 | { 37 | public: 38 | static void defineClass(const rb::Value& sfml); 39 | static rbTextClass& getDefinition(); 40 | 41 | rbText(); 42 | ~rbText(); 43 | 44 | static rb::Value initialize(rb::Value self, const std::vector& args); 45 | rbText* initializeCopy(const rbText* value); 46 | 47 | rb::Value marshalDump() const; 48 | 49 | void setColor(sf::Color color); 50 | const sf::Color& getColor() const; 51 | 52 | sf::FloatRect getLocalBounds() const; 53 | sf::FloatRect getGlobalBounds() const; 54 | 55 | void setString(const std::string& text); 56 | std::string getString() const; 57 | 58 | void setFont(rb::Value font); 59 | rb::Value getFont() const; 60 | 61 | void setCharacterSize(unsigned int size); 62 | unsigned int getCharacterSize() const; 63 | 64 | void setStyle(sf::Uint32 style); 65 | sf::Uint32 getStyle() const; 66 | 67 | sf::Vector2f findCharacterPos(unsigned int index) const; 68 | 69 | protected: 70 | virtual sf::Drawable* getDrawable(); 71 | virtual const sf::Drawable* getDrawable() const; 72 | 73 | virtual sf::Transformable* getTransformable(); 74 | virtual const sf::Transformable* getTransformable() const; 75 | 76 | private: 77 | friend class rb::Value; 78 | static rbTextClass ourDefinition; 79 | 80 | sf::Text myObject; 81 | }; 82 | 83 | namespace rb 84 | { 85 | template<> 86 | rbText* Value::to() const; 87 | template<> 88 | const rbText* Value::to() const; 89 | template<> 90 | sf::Text& Value::to() const; 91 | template<> 92 | const sf::Text& Value::to() const; 93 | 94 | template<> 95 | sf::Text::Style Value::to() const; 96 | template<> 97 | Value Value::create(sf::Text::Style style); 98 | } 99 | 100 | #endif // RBSFML_RBTEXT_HPP_ 101 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtexture.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBTEXTURE_HPP_ 23 | #define RBSFML_RBTEXTURE_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbTexture; 30 | class rbDataPtr; 31 | 32 | typedef rb::Class rbTextureClass; 33 | 34 | class rbTexture : public rb::Object 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static rbTextureClass& getDefinition(); 39 | 40 | rbTexture(); 41 | rbTexture(sf::Texture* texture); 42 | ~rbTexture(); 43 | 44 | static rb::Value initialize(rb::Value self, const std::vector& args); 45 | rbTexture* initializeCopy(const rbTexture* value); 46 | 47 | rb::Value marshalDump() const; 48 | 49 | void create(unsigned int width, unsigned int height); 50 | static rb::Value loadFromFile(rb::Value self, const std::vector& args); 51 | static rb::Value loadFromMemory(rb::Value self, const std::vector& args); 52 | static rb::Value loadFromImage(rb::Value self, const std::vector& args); 53 | 54 | sf::Vector2u getSize() const; 55 | 56 | rb::Value copyToImage() const; 57 | 58 | static rb::Value update(rb::Value self, const std::vector& args); 59 | 60 | void setSmooth(bool smooth); 61 | bool isSmooth() const; 62 | 63 | void setRepeated(bool repeated); 64 | bool isRepeated() const; 65 | 66 | unsigned int getNativeHandle() const; 67 | 68 | static void bind(const rbTexture* texture, sf::Texture::CoordinateType type); 69 | static unsigned int getMaximumSize(); 70 | 71 | rbDataPtr* getNativePtr() const; 72 | 73 | private: 74 | friend class rb::Value; 75 | static rbTextureClass ourDefinition; 76 | 77 | sf::Texture* myObject; 78 | bool myOwnsObject; 79 | }; 80 | 81 | namespace rb 82 | { 83 | template<> 84 | rbTexture* Value::to() const; 85 | template<> 86 | const rbTexture* Value::to() const; 87 | template<> 88 | sf::Texture& Value::to() const; 89 | template<> 90 | const sf::Texture& Value::to() const; 91 | 92 | template<> 93 | sf::Texture::CoordinateType Value::to() const; 94 | template<> 95 | Value Value::create(sf::Texture::CoordinateType value); 96 | } 97 | 98 | #endif // RBSFML_RBTEXTURE_HPP_ 99 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtime.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBTIME_HPP_ 23 | #define RBSFML_RBTIME_HPP_ 24 | 25 | #include 26 | #include 27 | #include "class.hpp" 28 | #include "object.hpp" 29 | 30 | class rbTime; 31 | class rbClock; 32 | 33 | typedef rb::Class rbTimeClass; 34 | 35 | class rbTime : public rb::Object 36 | { 37 | public: 38 | static void defineClass(const rb::Value& sfml); 39 | 40 | static rbTime* seconds(float val); 41 | static rbTime* milliseconds(sf::Int32 val); 42 | static rbTime* microseconds(sf::Int64 val); 43 | 44 | rbTime(); 45 | ~rbTime(); 46 | 47 | rbTime* initializeCopy(const rbTime* value); 48 | 49 | float asSeconds() const; 50 | sf::Int32 asMilliseconds() const; 51 | sf::Int64 asMicroseconds() const; 52 | 53 | rb::Value marshalDump() const; 54 | std::string inspect() const; 55 | 56 | rbTime* negate() const; 57 | rbTime* addition(const rbTime* other) const; 58 | rbTime* subtract(const rbTime* other) const; 59 | rbTime* multiply(const rb::Value& other) const; 60 | rb::Value divide(const rb::Value& other) const; 61 | 62 | int compare(const rbTime* other) const; 63 | 64 | inline const sf::Time& getObject() const 65 | { 66 | return myObject; 67 | } 68 | 69 | private: 70 | friend class rbClock; 71 | 72 | static rbTimeClass ourDefinition; 73 | 74 | sf::Time myObject; 75 | }; 76 | 77 | namespace rb 78 | { 79 | template<> 80 | rbTime* Value::to() const; 81 | template<> 82 | const rbTime* Value::to() const; 83 | } 84 | 85 | #endif // RBSFML_RBTIME_HPP_ 86 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtouch.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbtouch.hpp" 23 | #include "rbvector2.hpp" 24 | #include "error.hpp" 25 | #include "macros.hpp" 26 | 27 | rbTouchModule rbTouch::ourDefinition; 28 | 29 | void rbTouch::defineModule(const rb::Value& sfml) 30 | { 31 | ourDefinition = rbTouchModule::defineModuleUnder("Touch", sfml); 32 | ourDefinition.defineFunction<0>("down?", &sf::Touch::isDown); 33 | ourDefinition.defineFunction<1>("get_position", &rbTouch::getPosition); 34 | } 35 | 36 | rb::Value rbTouch::getPosition(const std::vector& arguments) 37 | { 38 | sf::Vector2i result; 39 | switch(arguments.size()) 40 | { 41 | case 1: 42 | result = sf::Touch::getPosition(arguments[0].to()); 43 | break; 44 | case 2: 45 | result = sf::Touch::getPosition(arguments[0].to(), arguments[1].to()); 46 | break; 47 | default: 48 | rb::expectedNumArgs(arguments.size(), 1, 2); 49 | } 50 | return rb::Value::create(result); 51 | } 52 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtouch.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBTOUCH_HPP 23 | #define RBSFML_RBTOUCH_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbTouch; 30 | 31 | typedef rb::Module rbTouchModule; 32 | 33 | class rbTouch 34 | { 35 | public: 36 | static void defineModule(const rb::Value& sfml); 37 | 38 | static rb::Value getPosition(const std::vector& arguments); 39 | 40 | private: 41 | static rbTouchModule ourDefinition; 42 | }; 43 | 44 | #endif // RBSFML_RBTOUCH_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbtransform.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBTRANSFORM_HPP_ 23 | #define RBSFML_RBTRANSFORM_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbTransform; 30 | class rbDataPtr; 31 | 32 | typedef rb::Class rbTransformClass; 33 | 34 | class rbTransform : public rb::Object 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static rbTransformClass& getDefinition(); 39 | 40 | rbTransform(); 41 | ~rbTransform(); 42 | 43 | static rb::Value initialize(rb::Value self, const std::vector& args); 44 | rbTransform* initializeCopy(const rbTransform* value); 45 | 46 | rb::Value marshalDump() const; 47 | void marshalLoad(const std::vector& data); 48 | 49 | std::string inspect() const; 50 | 51 | rb::Value getMatrix() const; 52 | rbTransform* getInverse() const; 53 | 54 | sf::Vector2f transformPoint(sf::Vector2f point) const; 55 | sf::FloatRect transformRect(sf::FloatRect rect) const; 56 | 57 | rbTransform* combine(const sf::Transform& transform) const; 58 | rbTransform* combineBang(const sf::Transform& transform); 59 | 60 | rbTransform* translate(sf::Vector2f offset) const; 61 | rbTransform* translateBang(sf::Vector2f offset); 62 | 63 | rbTransform* rotate(float angle) const; 64 | rbTransform* rotateBang(float angle); 65 | rbTransform* rotateAround(float angle, sf::Vector2f center) const; 66 | rbTransform* rotateAroundBang(float angle, sf::Vector2f center); 67 | 68 | rbTransform* scale(sf::Vector2f factors) const; 69 | rbTransform* scaleBang(sf::Vector2f factors); 70 | rbTransform* scaleAround(sf::Vector2f factors, sf::Vector2f center) const; 71 | rbTransform* scaleAroundBang(sf::Vector2f factors, sf::Vector2f center); 72 | 73 | rb::Value multiply(const rb::Value& other) const; 74 | 75 | rbDataPtr* getNativePtr(); 76 | 77 | private: 78 | friend class rb::Value; 79 | friend class rbView; 80 | 81 | static rbTransformClass ourDefinition; 82 | 83 | sf::Transform myObject; 84 | }; 85 | 86 | namespace rb 87 | { 88 | template<> 89 | rbTransform* Value::to() const; 90 | template<> 91 | const rbTransform* Value::to() const; 92 | template<> 93 | sf::Transform& Value::to() const; 94 | template<> 95 | const sf::Transform& Value::to() const; 96 | } 97 | 98 | #endif // RBSFML_RBTRANSFORM_HPP_ 99 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtransformable.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbtransformable.hpp" 23 | #include "rbvector2.hpp" 24 | #include "rbtransform.hpp" 25 | #include "error.hpp" 26 | #include "macros.hpp" 27 | 28 | #include 29 | 30 | rbTransformableModule rbTransformable::ourDefinition; 31 | 32 | class rbTransformableImpl : public rbTransformable, sf::Transformable 33 | { 34 | public: 35 | protected: 36 | sf::Transformable* getTransformable() { return this; } 37 | const sf::Transformable* getTransformable() const { return this; } 38 | }; 39 | 40 | void rbTransformable::defineModule(const rb::Value& sfml) 41 | { 42 | ourDefinition = rbTransformableModule::defineModuleUnder("Transformable", sfml); 43 | ourDefinition.defineMethod<1>("position=", &rbTransformable::setPosition); 44 | ourDefinition.defineMethod<2>("position", &rbTransformable::getPosition); 45 | ourDefinition.defineMethod<3>("rotation=", &rbTransformable::setRotation); 46 | ourDefinition.defineMethod<4>("rotation", &rbTransformable::getRotation); 47 | ourDefinition.defineMethod<5>("scale=", &rbTransformable::setScale); 48 | ourDefinition.defineMethod<6>("scale", &rbTransformable::getScale); 49 | ourDefinition.defineMethod<7>("origin=", &rbTransformable::setOrigin); 50 | ourDefinition.defineMethod<8>("origin", &rbTransformable::getOrigin); 51 | ourDefinition.defineMethod<9>("move", &rbTransformable::move); 52 | ourDefinition.defineMethod<10>("rotate", &rbTransformable::rotate); 53 | ourDefinition.defineMethod<11>("zoom", &rbTransformable::zoom); 54 | ourDefinition.defineMethod<12>("transform", &rbTransformable::getTransform); 55 | ourDefinition.defineMethod<13>("inverse_transform", &rbTransformable::getInverseTransform); 56 | } 57 | 58 | void rbTransformable::defineIncludeFunction() 59 | { 60 | ourDefinition.defineFunction<0>("included", &rbTransformable::included); 61 | } 62 | 63 | rbTransformableModule& rbTransformable::getDefinition() 64 | { 65 | return ourDefinition; 66 | } 67 | 68 | void rbTransformable::included(const rb::Value& base) 69 | { 70 | if(base.getType() == rb::ValueType::Class) 71 | { 72 | rb::defineAllocator>(base); 73 | } 74 | } 75 | 76 | void rbTransformable::setPosition(sf::Vector2f value) 77 | { 78 | getTransformable()->setPosition(value); 79 | } 80 | 81 | const sf::Vector2f& rbTransformable::getPosition() const 82 | { 83 | return getTransformable()->getPosition(); 84 | } 85 | 86 | void rbTransformable::setRotation(float value) 87 | { 88 | getTransformable()->setRotation(value); 89 | } 90 | 91 | float rbTransformable::getRotation() const 92 | { 93 | return getTransformable()->getRotation(); 94 | } 95 | 96 | void rbTransformable::setScale(sf::Vector2f value) 97 | { 98 | getTransformable()->setScale(value); 99 | } 100 | 101 | const sf::Vector2f& rbTransformable::getScale() const 102 | { 103 | return getTransformable()->getScale(); 104 | } 105 | 106 | void rbTransformable::setOrigin(sf::Vector2f value) 107 | { 108 | getTransformable()->setOrigin(value); 109 | } 110 | 111 | const sf::Vector2f& rbTransformable::getOrigin() const 112 | { 113 | return getTransformable()->getOrigin(); 114 | } 115 | 116 | void rbTransformable::move(sf::Vector2f value) 117 | { 118 | getTransformable()->move(value); 119 | } 120 | 121 | void rbTransformable::rotate(float value) 122 | { 123 | getTransformable()->rotate(value); 124 | } 125 | 126 | void rbTransformable::zoom(sf::Vector2f value) 127 | { 128 | getTransformable()->scale(value); 129 | } 130 | 131 | rb::Value rbTransformable::getTransform() const 132 | { 133 | rb::Value object = rbTransform::getDefinition().newObject(); 134 | object.to() = getTransformable()->getTransform(); 135 | return object; 136 | } 137 | 138 | rb::Value rbTransformable::getInverseTransform() const 139 | { 140 | rb::Value object = rbTransform::getDefinition().newObject(); 141 | object.to() = getTransformable()->getInverseTransform(); 142 | return object; 143 | } 144 | -------------------------------------------------------------------------------- /ext/rbsfml/rbtransformable.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBTRANSFORMABLE_HPP_ 23 | #define RBSFML_RBTRANSFORMABLE_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "rbdrawablebasetype.hpp" 27 | 28 | #include 29 | 30 | class rbTransformable; 31 | 32 | typedef rb::Module rbTransformableModule; 33 | 34 | class rbTransformable : public virtual rbDrawableBaseType 35 | { 36 | public: 37 | static void defineModule(const rb::Value& sfml); 38 | static void defineIncludeFunction(); 39 | static rbTransformableModule& getDefinition(); 40 | 41 | static void included(const rb::Value& base); 42 | 43 | void setPosition(sf::Vector2f value); 44 | const sf::Vector2f& getPosition() const; 45 | 46 | void setRotation(float value); 47 | float getRotation() const; 48 | 49 | void setScale(sf::Vector2f value); 50 | const sf::Vector2f& getScale() const; 51 | 52 | void setOrigin(sf::Vector2f value); 53 | const sf::Vector2f& getOrigin() const; 54 | 55 | void move(sf::Vector2f value); 56 | void rotate(float value); 57 | void zoom(sf::Vector2f value); 58 | 59 | rb::Value getTransform() const; 60 | rb::Value getInverseTransform() const;; 61 | 62 | private: 63 | friend class rb::Value; 64 | static rbTransformableModule ourDefinition; 65 | }; 66 | 67 | #endif // RBSFML_RBTRANSFORMABLE_HPP_ 68 | -------------------------------------------------------------------------------- /ext/rbsfml/rbvector2.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBVECTOR2_HPP 23 | #define RBSFML_RBVECTOR2_HPP 24 | 25 | #include 26 | #include 27 | #include "class.hpp" 28 | #include "object.hpp" 29 | 30 | class rbVector2; 31 | 32 | typedef rb::Class rbVector2Class; 33 | 34 | class rbVector2 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static const rbVector2Class& getDefinition(); 39 | 40 | static rb::Value initialize(rb::Value self, const std::vector& args); 41 | static rb::Value initializeCopy(rb::Value self, const rb::Value& value); 42 | static std::vector marshalDump(const rb::Value& self); 43 | static rb::Value marshalLoad(rb::Value self, const rb::Value& data); 44 | 45 | static rb::Value negate(const rb::Value& self); 46 | static rb::Value add(const rb::Value& self, const rb::Value& other); 47 | static rb::Value subtract(const rb::Value& self, const rb::Value& other); 48 | static rb::Value multiply(const rb::Value& self, const rb::Value& other); 49 | static rb::Value divide(const rb::Value& self, const rb::Value& other); 50 | 51 | static bool equal(const rb::Value& self, const rb::Value& other); 52 | static bool strictEqual(const rb::Value& self, const rb::Value& other); 53 | 54 | static std::string inspect(const rb::Value& self); 55 | 56 | private: 57 | static rbVector2Class ourDefinition; 58 | }; 59 | 60 | namespace rb 61 | { 62 | template<> 63 | sf::Vector2f Value::to() const; 64 | template<> 65 | sf::Vector2i Value::to() const; 66 | template<> 67 | sf::Vector2u Value::to() const; 68 | 69 | template<> 70 | Value Value::create( sf::Vector2f value ); 71 | template<> 72 | Value Value::create( const sf::Vector2f& value ); 73 | template<> 74 | Value Value::create( sf::Vector2i value ); 75 | template<> 76 | Value Value::create( const sf::Vector2i& value ); 77 | template<> 78 | Value Value::create( sf::Vector2u value ); 79 | template<> 80 | Value Value::create( const sf::Vector2u& value ); 81 | } 82 | 83 | #endif // RBSFML_RBVECTOR2_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbvector3.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBVECTOR3_HPP 23 | #define RBSFML_RBVECTOR3_HPP 24 | 25 | #include 26 | #include 27 | #include "class.hpp" 28 | #include "object.hpp" 29 | 30 | class rbVector3; 31 | 32 | typedef rb::Class rbVector3Class; 33 | 34 | class rbVector3 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static const rbVector3Class& getDefinition(); 39 | 40 | static rb::Value initialize(rb::Value self, const std::vector& args); 41 | static rb::Value initializeCopy(rb::Value self, const rb::Value& value); 42 | static std::vector marshalDump(const rb::Value& self); 43 | static rb::Value marshalLoad(rb::Value self, const rb::Value& data); 44 | 45 | static rb::Value negate(const rb::Value& self); 46 | static rb::Value add(const rb::Value& self, const rb::Value& other); 47 | static rb::Value subtract(const rb::Value& self, const rb::Value& other); 48 | static rb::Value multiply(const rb::Value& self, const rb::Value& other); 49 | static rb::Value divide(const rb::Value& self, const rb::Value& other); 50 | 51 | static bool equal(const rb::Value& self, const rb::Value& other); 52 | static bool strictEqual(const rb::Value& self, const rb::Value& other); 53 | 54 | static std::string inspect(const rb::Value& self); 55 | 56 | private: 57 | static rbVector3Class ourDefinition; 58 | }; 59 | 60 | namespace rb 61 | { 62 | template<> 63 | sf::Vector3f Value::to() const; 64 | template<> 65 | sf::Vector3i Value::to() const; 66 | 67 | template<> 68 | Value Value::create( sf::Vector3f value ); 69 | template<> 70 | Value Value::create( const sf::Vector3f& value ); 71 | template<> 72 | Value Value::create( sf::Vector3i value ); 73 | template<> 74 | Value Value::create( const sf::Vector3i& value ); 75 | } 76 | 77 | #endif // RBSFML_RBVECTOR3_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbvertex.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbvertex.hpp" 23 | #include "rbvector2.hpp" 24 | #include "rbcolor.hpp" 25 | #include "error.hpp" 26 | #include "macros.hpp" 27 | #include "base.hpp" 28 | 29 | namespace 30 | { 31 | constexpr char symVarPosition[] = "@position"; 32 | constexpr char symVarColor[] = "@color"; 33 | constexpr char symVarTexCoords[] = "@tex_coords"; 34 | } 35 | 36 | rbVertexClass rbVertex::ourDefinition; 37 | 38 | void rbVertex::defineClass(const rb::Value& sfml) 39 | { 40 | ourDefinition = rbVertexClass::defineClassUnder("Vertex", sfml); 41 | ourDefinition.defineMethod<0>("initialize", &rbVertex::initialize); 42 | ourDefinition.defineMethod<2>("marshal_dump", &rbVertex::marshalDump); 43 | 44 | ourDefinition.defineAttribute("position", true, true); 45 | ourDefinition.defineAttribute("color", true, true); 46 | ourDefinition.defineAttribute("tex_coords", true, true); 47 | } 48 | 49 | const rbVertexClass& rbVertex::getDefinition() 50 | { 51 | return ourDefinition; 52 | } 53 | 54 | rb::Value rbVertex::initialize(rb::Value self, const std::vector& args) 55 | { 56 | self.setVar(rbVector2::getDefinition().newObject(0.0, 0.0)); 57 | self.setVar(rbColor::getDefinition().newObject()); 58 | self.setVar(rbVector2::getDefinition().newObject(0.0, 0.0)); 59 | switch( args.size() ) 60 | { 61 | case 0: 62 | break; 63 | case 3: 64 | self.setVar(args[2]); 65 | case 2: 66 | self.setVar(args[1]); 67 | case 1: 68 | self.setVar(args[0]); 69 | break; 70 | default: 71 | rb::expectedNumArgs( args.size(), 0, 3); 72 | break; 73 | } 74 | 75 | return self; 76 | } 77 | 78 | rb::Value rbVertex::marshalDump(const rb::Value& self) 79 | { 80 | std::vector data; 81 | data.push_back(self.getVar()); 82 | data.push_back(self.getVar()); 83 | data.push_back(self.getVar()); 84 | return rb::Value::create(data); 85 | } 86 | 87 | void rbVertex::marshalLoad(rb::Value self, const std::vector& data) 88 | { 89 | self.setVar(data[0]); 90 | self.setVar(data[1]); 91 | self.setVar(data[2]); 92 | } 93 | 94 | namespace rb 95 | { 96 | 97 | template<> 98 | sf::Vertex Value::to() const 99 | { 100 | errorHandling(T_OBJECT); 101 | sf::Vertex vertex( 102 | getVar(), getVar(), getVar() 103 | ); 104 | return vertex; 105 | } 106 | 107 | template<> 108 | Value Value::create(sf::Vertex vertex) 109 | { 110 | return rbVertex::getDefinition().newObject(rb::Value::create(vertex.position), rb::Value::create(vertex.color), rb::Value::create(vertex.texCoords)); 111 | } 112 | 113 | template<> 114 | Value Value::create(const sf::Vertex& vertex) 115 | { 116 | return rbVertex::getDefinition().newObject(rb::Value::create(vertex.position), rb::Value::create(vertex.color), rb::Value::create(vertex.texCoords)); 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbvertex.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBVERTEX_HPP 23 | #define RBSFML_RBVERTEX_HPP 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbVertex; 30 | 31 | typedef rb::Class rbVertexClass; 32 | 33 | class rbVertex 34 | { 35 | public: 36 | static void defineClass(const rb::Value& sfml); 37 | static const rbVertexClass& getDefinition(); 38 | 39 | static rb::Value initialize(rb::Value self, const std::vector& args); 40 | static rb::Value marshalDump(const rb::Value& self); 41 | static void marshalLoad(rb::Value self, const std::vector& data); 42 | 43 | private: 44 | static rbVertexClass ourDefinition; 45 | }; 46 | 47 | namespace rb 48 | { 49 | template<> 50 | sf::Vertex Value::to() const; 51 | template<> 52 | Value Value::create(sf::Vertex vertex); 53 | template<> 54 | Value Value::create(const sf::Vertex& vertex); 55 | } 56 | 57 | #endif // RBSFML_RBVERTEX_HPP -------------------------------------------------------------------------------- /ext/rbsfml/rbvertexarray.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbvertexarray.hpp" 23 | #include "rbvertex.hpp" 24 | #include "rbrect.hpp" 25 | #include "error.hpp" 26 | #include "macros.hpp" 27 | 28 | rbVertexArrayClass rbVertexArray::ourDefinition; 29 | 30 | void rbVertexArray::defineClass(const rb::Value& sfml) 31 | { 32 | ourDefinition = rbVertexArrayClass::defineClassUnder("VertexArray", sfml); 33 | ourDefinition.includeModule(rb::Value(rbDrawable::getDefinition())); 34 | ourDefinition.defineMethod<0>("initialize", &rbVertexArray::initialize); 35 | ourDefinition.defineMethod<1>("initialize_copy", &rbVertexArray::initializeCopy); 36 | ourDefinition.defineMethod<2>("marshal_dump", &rbVertexArray::marshalDump); 37 | ourDefinition.defineMethod<3>("vertex_count", &rbVertexArray::getVertexCount); 38 | ourDefinition.defineMethod<4>("[]=", &rbVertexArray::setAtIndex); 39 | ourDefinition.defineMethod<5>("[]", &rbVertexArray::getAtIndex); 40 | ourDefinition.defineMethod<6>("clear", &rbVertexArray::clear); 41 | ourDefinition.defineMethod<7>("resize", &rbVertexArray::resize); 42 | ourDefinition.defineMethod<8>("append", &rbVertexArray::append); 43 | ourDefinition.defineMethod<9>("primitive_type=", &rbVertexArray::setPrimitiveType); 44 | ourDefinition.defineMethod<10>("primitive_type", &rbVertexArray::getPrimitiveType); 45 | ourDefinition.defineMethod<11>("bounds", &rbVertexArray::getBounds); 46 | } 47 | 48 | rbVertexArrayClass& rbVertexArray::getDefinition() 49 | { 50 | return ourDefinition; 51 | } 52 | 53 | rbVertexArray::rbVertexArray() 54 | : rbDrawableBaseType() 55 | , myObject() 56 | { 57 | } 58 | 59 | rbVertexArray::~rbVertexArray() 60 | { 61 | } 62 | 63 | rb::Value rbVertexArray::initialize(rb::Value self, const std::vector& args) 64 | { 65 | sf::VertexArray& object = self.to(); 66 | switch(args.size()) 67 | { 68 | case 0: 69 | break; 70 | case 2: 71 | object.resize(args[1].to()); 72 | case 1: 73 | object.setPrimitiveType(args[0].to()); 74 | break; 75 | default: 76 | rb::expectedNumArgs(args.size(), 0, 2); 77 | break; 78 | } 79 | 80 | return self; 81 | } 82 | 83 | rbVertexArray* rbVertexArray::initializeCopy(const rbVertexArray* value) 84 | { 85 | myObject = value->myObject; 86 | return this; 87 | } 88 | 89 | rb::Value rbVertexArray::marshalDump() const 90 | { 91 | rb::raise(rb::TypeError, "can't dump %s", ourDefinition.getName().c_str() ); 92 | return rb::Nil; 93 | } 94 | 95 | unsigned int rbVertexArray::getVertexCount() const 96 | { 97 | return myObject.getVertexCount(); 98 | } 99 | 100 | void rbVertexArray::setAtIndex(unsigned int index, sf::Vertex vertex) 101 | { 102 | myObject[index] = vertex; 103 | } 104 | 105 | const sf::Vertex& rbVertexArray::getAtIndex(unsigned int index) 106 | { 107 | return myObject[index]; 108 | } 109 | 110 | void rbVertexArray::clear() 111 | { 112 | myObject.clear(); 113 | } 114 | 115 | void rbVertexArray::resize(unsigned int size) 116 | { 117 | myObject.resize(size); 118 | } 119 | 120 | void rbVertexArray::append(sf::Vertex vertex) 121 | { 122 | myObject.append(vertex); 123 | } 124 | 125 | void rbVertexArray::setPrimitiveType(sf::PrimitiveType type) 126 | { 127 | myObject.setPrimitiveType(type); 128 | } 129 | 130 | sf::PrimitiveType rbVertexArray::getPrimitiveType() const 131 | { 132 | return myObject.getPrimitiveType(); 133 | } 134 | 135 | sf::FloatRect rbVertexArray::getBounds() const 136 | { 137 | return myObject.getBounds(); 138 | } 139 | 140 | sf::Drawable* rbVertexArray::getDrawable() 141 | { 142 | return &myObject; 143 | } 144 | 145 | const sf::Drawable* rbVertexArray::getDrawable() const 146 | { 147 | return &myObject; 148 | } 149 | 150 | namespace rb 151 | { 152 | 153 | template<> 154 | rbVertexArray* Value::to() const 155 | { 156 | errorHandling(T_DATA); 157 | rbVertexArray* object = nullptr; 158 | if(myValue != Qnil) 159 | Data_Get_Struct(myValue, rbVertexArray, object); 160 | return object; 161 | } 162 | 163 | template<> 164 | const rbVertexArray* Value::to() const 165 | { 166 | errorHandling(T_DATA); 167 | const rbVertexArray* object = nullptr; 168 | if(myValue != Qnil) 169 | Data_Get_Struct(myValue, rbVertexArray, object); 170 | return object; 171 | } 172 | 173 | template<> 174 | sf::VertexArray& Value::to() const 175 | { 176 | return to()->myObject; 177 | } 178 | 179 | template<> 180 | const sf::VertexArray& Value::to() const 181 | { 182 | return to()->myObject; 183 | } 184 | 185 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbvertexarray.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBVERTEXARRAY_HPP_ 23 | #define RBSFML_RBVERTEXARRAY_HPP_ 24 | 25 | #include "class.hpp" 26 | #include "rbdrawable.hpp" 27 | 28 | #include 29 | 30 | class rbVertexArray; 31 | 32 | typedef rb::Class rbVertexArrayClass; 33 | 34 | class rbVertexArray : public rbDrawableBaseType 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static rbVertexArrayClass& getDefinition(); 39 | 40 | rbVertexArray(); 41 | ~rbVertexArray(); 42 | 43 | static rb::Value initialize(rb::Value self, const std::vector& args); 44 | rbVertexArray* initializeCopy(const rbVertexArray* value); 45 | 46 | rb::Value marshalDump() const; 47 | 48 | unsigned int getVertexCount() const; 49 | 50 | void setAtIndex(unsigned int index, sf::Vertex vertex); 51 | const sf::Vertex& getAtIndex(unsigned int index); 52 | 53 | void clear(); 54 | void resize(unsigned int size); 55 | void append(sf::Vertex vertex); 56 | 57 | void setPrimitiveType(sf::PrimitiveType type); 58 | sf::PrimitiveType getPrimitiveType() const; 59 | 60 | sf::FloatRect getBounds() const; 61 | 62 | protected: 63 | virtual sf::Drawable* getDrawable(); 64 | virtual const sf::Drawable* getDrawable() const; 65 | 66 | private: 67 | friend class rb::Value; 68 | static rbVertexArrayClass ourDefinition; 69 | 70 | sf::VertexArray myObject; 71 | }; 72 | 73 | namespace rb 74 | { 75 | template<> 76 | rbVertexArray* Value::to() const; 77 | template<> 78 | const rbVertexArray* Value::to() const; 79 | template<> 80 | sf::VertexArray& Value::to() const; 81 | template<> 82 | const sf::VertexArray& Value::to() const; 83 | } 84 | 85 | #endif // RBSFML_RBVERTEXARRAY_HPP_ 86 | -------------------------------------------------------------------------------- /ext/rbsfml/rbvideomode.cpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #include "rbvideomode.hpp" 23 | #include "error.hpp" 24 | #include "macros.hpp" 25 | 26 | rbVideoModeClass rbVideoMode::ourDefinition; 27 | 28 | void rbVideoMode::defineClass(const rb::Value& sfml) 29 | { 30 | ourDefinition = rbVideoModeClass::defineClassUnder("VideoMode", sfml); 31 | ourDefinition.includeModule(rb::Value(rb_mComparable)); 32 | ourDefinition.defineFunction<0>("desktop_mode", &rbVideoMode::getDesktopMode); 33 | ourDefinition.defineFunction<1>("fullscreen_modes", &rbVideoMode::getFullscreenModes); 34 | ourDefinition.defineMethod<2>("initialize", &rbVideoMode::initialize); 35 | ourDefinition.defineMethod<3>("initialize_copy", &rbVideoMode::initializeCopy); 36 | ourDefinition.defineMethod<4>("valid?", &rbVideoMode::isValid); 37 | ourDefinition.defineMethod<5>("width", &rbVideoMode::getWidth); 38 | ourDefinition.defineMethod<6>("width=", &rbVideoMode::setWidth); 39 | ourDefinition.defineMethod<7>("height", &rbVideoMode::getHeight); 40 | ourDefinition.defineMethod<8>("height=", &rbVideoMode::setHeight); 41 | ourDefinition.defineMethod<9>("bits_per_pixel", &rbVideoMode::getBitsPerPixel); 42 | ourDefinition.defineMethod<10>("bits_per_pixel=", &rbVideoMode::setBitsPerPixel); 43 | ourDefinition.defineMethod<11>("marshal_dump", &rbVideoMode::marshalDump); 44 | ourDefinition.defineMethod<12>("inspect", &rbVideoMode::inspect); 45 | ourDefinition.defineMethod<13>("<=>", &rbVideoMode::compare); 46 | 47 | ourDefinition.aliasMethod("inspect", "to_s"); 48 | ourDefinition.aliasMethod("bits_per_pixel", "bpp"); 49 | ourDefinition.aliasMethod("bits_per_pixel=", "bpp="); 50 | } 51 | 52 | rbVideoMode::rbVideoMode() 53 | : rb::Object() 54 | , myObject() 55 | { 56 | } 57 | 58 | rbVideoMode::~rbVideoMode() 59 | { 60 | } 61 | 62 | rbVideoMode* rbVideoMode::getDesktopMode() 63 | { 64 | rb::Value desktopMode = ourDefinition.newObject(); 65 | rbVideoMode* object = desktopMode.to(); 66 | object->myObject = sf::VideoMode::getDesktopMode(); 67 | return object; 68 | } 69 | 70 | std::vector rbVideoMode::getFullscreenModes() 71 | { 72 | const std::vector& fullscreenModes = sf::VideoMode::getFullscreenModes(); 73 | std::vector convertedModes; 74 | for(int index = 0, size = fullscreenModes.size(); index < size; index++) 75 | { 76 | rb::Value value = ourDefinition.newObject(); 77 | rbVideoMode* object = value.to(); 78 | object->myObject = fullscreenModes[index]; 79 | convertedModes.push_back(value); 80 | } 81 | return convertedModes; 82 | } 83 | 84 | rb::Value rbVideoMode::initialize(rb::Value self, const std::vector& args) 85 | { 86 | rbVideoMode* object = self.to(); 87 | switch( args.size() ) 88 | { 89 | case 0: 90 | break; 91 | case 2: 92 | object->myObject = sf::VideoMode(args[0].to(), args[1].to()); 93 | break; 94 | case 3: 95 | object->myObject = sf::VideoMode(args[0].to(), args[1].to(), 96 | args[2].to()); 97 | break; 98 | default: 99 | rb::expectedNumArgs( args.size(), "0, 2 or 3" ); 100 | break; 101 | } 102 | 103 | return self; 104 | } 105 | 106 | rbVideoMode* rbVideoMode::initializeCopy(const rbVideoMode* value) 107 | { 108 | myObject = value->myObject; 109 | return this; 110 | } 111 | 112 | bool rbVideoMode::isValid() const 113 | { 114 | return myObject.isValid(); 115 | } 116 | 117 | void rbVideoMode::setWidth(unsigned int value) 118 | { 119 | myObject.width = value; 120 | } 121 | 122 | unsigned int rbVideoMode::getWidth() const 123 | { 124 | return myObject.width; 125 | } 126 | 127 | void rbVideoMode::setHeight(unsigned int value) 128 | { 129 | myObject.height = value; 130 | } 131 | 132 | unsigned int rbVideoMode::getHeight() const 133 | { 134 | return myObject.height; 135 | } 136 | 137 | void rbVideoMode::setBitsPerPixel(unsigned int value) 138 | { 139 | myObject.bitsPerPixel = value; 140 | } 141 | 142 | unsigned int rbVideoMode::getBitsPerPixel() const 143 | { 144 | return myObject.bitsPerPixel; 145 | } 146 | 147 | 148 | rb::Value rbVideoMode::marshalDump() const 149 | { 150 | rb::raise(rb::TypeError, "can't dump %s", ourDefinition.getName().c_str() ); 151 | return rb::Nil; 152 | } 153 | 154 | std::string rbVideoMode::inspect() const 155 | { 156 | return ourDefinition.getName() + "(" 157 | + macro::toString(myObject.width) + ", " 158 | + macro::toString(myObject.height) + ", " 159 | + macro::toString(myObject.bitsPerPixel) + ")"; 160 | } 161 | 162 | int rbVideoMode::compare(const rbVideoMode* other) const 163 | { 164 | if(myObject == other->myObject) return 0; 165 | if(myObject > other->myObject) return 1; 166 | return -1; 167 | } 168 | 169 | namespace rb 170 | { 171 | 172 | template<> 173 | rbVideoMode* Value::to() const 174 | { 175 | errorHandling(T_DATA); 176 | rbVideoMode* object = nullptr; 177 | if(myValue != Qnil) 178 | Data_Get_Struct(myValue, rbVideoMode, object); 179 | return object; 180 | } 181 | 182 | template<> 183 | const rbVideoMode* Value::to() const 184 | { 185 | errorHandling(T_DATA); 186 | const rbVideoMode* object = nullptr; 187 | if(myValue != Qnil) 188 | Data_Get_Struct(myValue, rbVideoMode, object); 189 | return object; 190 | } 191 | 192 | } -------------------------------------------------------------------------------- /ext/rbsfml/rbvideomode.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBVIDEOMODE_HPP_ 23 | #define RBSFML_RBVIDEOMODE_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbVideoMode; 30 | 31 | typedef rb::Class rbVideoModeClass; 32 | 33 | class rbVideoMode : public rb::Object 34 | { 35 | public: 36 | static void defineClass(const rb::Value& sfml); 37 | 38 | rbVideoMode(); 39 | ~rbVideoMode(); 40 | 41 | static rbVideoMode* getDesktopMode(); 42 | static std::vector getFullscreenModes(); 43 | 44 | static rb::Value initialize(rb::Value self, const std::vector& args); 45 | rbVideoMode* initializeCopy(const rbVideoMode* value); 46 | 47 | bool isValid() const; 48 | 49 | void setWidth(unsigned int value); 50 | unsigned int getWidth() const; 51 | 52 | void setHeight(unsigned int value); 53 | unsigned int getHeight() const; 54 | 55 | void setBitsPerPixel(unsigned int value); 56 | unsigned int getBitsPerPixel() const; 57 | 58 | rb::Value marshalDump() const; 59 | std::string inspect() const; 60 | 61 | int compare(const rbVideoMode* other) const; 62 | 63 | private: 64 | friend class rbWindow; 65 | 66 | static rbVideoModeClass ourDefinition; 67 | 68 | sf::VideoMode myObject; 69 | }; 70 | 71 | namespace rb 72 | { 73 | template<> 74 | rbVideoMode* Value::to() const; 75 | template<> 76 | const rbVideoMode* Value::to() const; 77 | } 78 | 79 | #endif // RBSFML_RBVIDEOMODE_HPP_ 80 | -------------------------------------------------------------------------------- /ext/rbsfml/rbview.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBVIEW_HPP_ 23 | #define RBSFML_RBVIEW_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "object.hpp" 28 | 29 | class rbView; 30 | class rbTransform; 31 | 32 | typedef rb::Class rbViewClass; 33 | 34 | class rbView : public rb::Object 35 | { 36 | public: 37 | static void defineClass(const rb::Value& sfml); 38 | static rbViewClass& getDefinition(); 39 | 40 | rbView(); 41 | ~rbView(); 42 | 43 | static rb::Value initialize(rb::Value self, const std::vector& args); 44 | rbView* initializeCopy(const rbView* value); 45 | 46 | rb::Value marshalDump() const; 47 | void marshalLoad(const std::vector& data); 48 | 49 | std::string inspect() const; 50 | 51 | void setCenter(sf::Vector2f center); 52 | const sf::Vector2f& getCenter() const; 53 | 54 | void setSize(sf::Vector2f size); 55 | const sf::Vector2f& getSize() const; 56 | 57 | void setRotation(float rotation); 58 | float getRotation() const; 59 | 60 | void reset(sf::FloatRect rect); 61 | const sf::FloatRect& getViewport() const; 62 | 63 | void move(sf::Vector2f offset); 64 | void rotate(float angle); 65 | void zoom(float factor); 66 | 67 | rbTransform* getTransform() const; 68 | rbTransform* getInverseTransform() const; 69 | 70 | private: 71 | friend class rb::Value; 72 | friend class rbRenderTarget; 73 | 74 | static rbViewClass ourDefinition; 75 | 76 | sf::View myObject; 77 | }; 78 | 79 | namespace rb 80 | { 81 | template<> 82 | rbView* Value::to() const; 83 | template<> 84 | const rbView* Value::to() const; 85 | template<> 86 | sf::View& Value::to() const; 87 | template<> 88 | const sf::View& Value::to() const; 89 | } 90 | 91 | #endif // RBSFML_RBVIEW_HPP_ 92 | -------------------------------------------------------------------------------- /ext/rbsfml/rbwindow.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_RBWINDOW_HPP_ 23 | #define RBSFML_RBWINDOW_HPP_ 24 | 25 | #include 26 | #include "class.hpp" 27 | #include "rbrenderbasetype.hpp" 28 | 29 | 30 | class rbWindow; 31 | class rbContextSettings; 32 | class rbEvent; 33 | 34 | typedef rb::Class rbWindowClass; 35 | 36 | class rbWindow : public virtual rbRenderBaseType 37 | { 38 | public: 39 | static void defineClass(const rb::Value& sfml); 40 | static rbWindowClass& getDefinition(); 41 | 42 | rbWindow(); 43 | ~rbWindow(); 44 | 45 | static rb::Value initialize(rb::Value self, const std::vector& arguments); 46 | static rb::Value create(rb::Value self, const std::vector& arguments); 47 | 48 | void close(); 49 | bool isOpen() const; 50 | 51 | rbContextSettings* getSettings() const; 52 | 53 | void setPosition(sf::Vector2i position); 54 | sf::Vector2i getPosition() const; 55 | 56 | void setSize(sf::Vector2u size); 57 | sf::Vector2u getSize() const; 58 | 59 | void setTitle(const std::string& title); 60 | 61 | void setIcon(unsigned int width, unsigned int height, const std::vector& pixels); 62 | 63 | void setVisible(bool enabled); 64 | void setVerticalSyncEnabled(bool enabled); 65 | void setMouseCursorVisible(bool enabled); 66 | void setKeyRepeatEnabled(bool enabled); 67 | void setFramerateLimit(unsigned int limit); 68 | void setJoystickThreshold(float treshold); 69 | static rb::Value setActive(rb::Value self, const std::vector& arguments); 70 | void requestFocus(); 71 | bool hasFocus() const; 72 | void display(); 73 | sf::WindowHandle getSystemHandle() const; 74 | 75 | rbEvent* pollEvent(); 76 | rbEvent* waitEvent(); 77 | 78 | rb::Value eachEvent(); 79 | 80 | private: 81 | static rbWindowClass ourDefinition; 82 | }; 83 | 84 | namespace rb 85 | { 86 | template<> 87 | rbWindow* Value::to() const; 88 | template<> 89 | const rbWindow* Value::to() const; 90 | } 91 | 92 | #endif // RBSFML_RBWINDOW_HPP_ 93 | -------------------------------------------------------------------------------- /ext/rbsfml/value.hpp: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef RBSFML_VALUE_HEADER_ 23 | #define RBSFML_VALUE_HEADER_ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace rb 30 | { 31 | template 32 | class Module; 33 | class Object; 34 | 35 | enum class ValueType 36 | { 37 | None, Object, Class, Module, 38 | Float, String, Regexp, Array, 39 | Hash, Struct, Bignum, File, 40 | Data, Match, Complex, Rational, 41 | Nil, Bool, Symbol, Fixnum, 42 | Unknown 43 | }; 44 | 45 | class Value 46 | { 47 | public: 48 | template 49 | static Value create(Type value); 50 | 51 | Value(); 52 | explicit Value(VALUE value); 53 | explicit Value(const std::string& value); 54 | explicit Value(unsigned char value); 55 | explicit Value(int value); 56 | explicit Value(float value); 57 | explicit Value(double value); 58 | explicit Value(long long int value); 59 | explicit Value(unsigned int value); 60 | explicit Value(bool value); 61 | explicit Value(rb::Object* object); 62 | explicit Value(const rb::Object* object); 63 | explicit Value(const std::vector& collection); 64 | 65 | template 66 | explicit Value(const Module& module); 67 | 68 | ~Value(); 69 | 70 | template 71 | Type to() const; 72 | 73 | ValueType getType() const; 74 | std::string getClassName() const; 75 | 76 | bool isKindOf(const Value& klass) const; 77 | 78 | bool isNil() const; 79 | bool isFrozen() const; 80 | 81 | bool equal(const Value& other) const; 82 | bool operator==(const Value& other) const; 83 | bool operator!=(const Value& other) const; 84 | 85 | int getArrayLength() const; 86 | 87 | template 88 | ReturnType getHashEntry() const; 89 | 90 | void freeze(); 91 | 92 | template 93 | ReturnType call(Args... args); 94 | 95 | template 96 | void setVar(ValueType value); 97 | template 98 | ValueType getVar() const; 99 | 100 | private: 101 | void errorHandling(int rubyType) const; 102 | void errorHandling(int type1, int type2) const; 103 | 104 | VALUE myValue; 105 | mutable std::string myCachedStr; 106 | mutable std::vector myCachedArray; 107 | }; 108 | 109 | extern Value Nil; 110 | extern Value True; 111 | extern Value False; 112 | 113 | template<> 114 | VALUE Value::to() const; 115 | 116 | template<> 117 | const Value& Value::to() const; 118 | template<> 119 | Value Value::to() const; 120 | 121 | template<> 122 | std::string Value::to() const; 123 | template<> 124 | const std::string& Value::to() const; 125 | 126 | template<> 127 | std::vector Value::to() const; 128 | template<> 129 | const std::vector& Value::to() const; 130 | 131 | template<> 132 | unsigned char Value::to() const; 133 | template<> 134 | int Value::to() const; 135 | template<> 136 | float Value::to() const; 137 | template<> 138 | double Value::to() const; 139 | template<> 140 | long long int Value::to() const; 141 | template<> 142 | unsigned int Value::to() const; 143 | template<> 144 | bool Value::to() const; 145 | } 146 | 147 | #include "value.inc" 148 | 149 | #endif // RBSFML_VALUE_HEADER_ -------------------------------------------------------------------------------- /ext/rbsfml/value.inc: -------------------------------------------------------------------------------- 1 | /* rbSFML 2 | * Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 3 | * This software is provided 'as-is', without any express or implied warranty. 4 | * In no event will the authors be held liable for any damages arising from 5 | * the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 11 | * 1. The origin of this software must not be misrepresented; you must not 12 | * claim that you wrote the original software. If you use this software in 13 | * a product, an acknowledgment in the product documentation would be 14 | * appreciated but is not required. 15 | * 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | namespace rb 23 | { 24 | 25 | template 26 | Value Value::create(Type value) 27 | { 28 | return Value(value); 29 | } 30 | 31 | template 32 | Value::Value(const Module& module) 33 | : myValue(module.myDefinition) 34 | , myCachedStr() 35 | , myCachedArray() 36 | { 37 | } 38 | 39 | template 40 | ReturnType Value::getHashEntry() const 41 | { 42 | static VALUE symbol = ID2SYM(rb_intern(Name)); 43 | rb::Value returnValue(rb_hash_aref(myValue, symbol)); 44 | return returnValue.to(); 45 | } 46 | 47 | template 48 | ReturnType Value::call(Args... args) 49 | { 50 | static ID sym = rb_intern(Name); 51 | VALUE returnValue = rb_funcall(myValue, sym, sizeof...(args), (Value::create(args).to())...); 52 | return Value::create(returnValue).to(); 53 | } 54 | 55 | template 56 | void Value::setVar(ValueType value) 57 | { 58 | static ID sym = rb_intern(Name); 59 | rb_ivar_set(myValue, sym, Value::create(value).to()); 60 | } 61 | 62 | template 63 | ValueType Value::getVar() const 64 | { 65 | static ID sym = rb_intern(Name); 66 | VALUE value = rb_ivar_get(myValue, sym); 67 | return Value::create(value).to(); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | rbSFML 2 | ---- 3 | 4 | rbSFML - Copyright (c) 2015 Henrik Valter Vogelius Hansson - groogy@groogy.se 5 | 6 | This software is provided 'as-is', without any express or 7 | implied warranty. In no event will the authors be held 8 | liable for any damages arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute 12 | it freely, subject to the following restrictions: 13 | 14 | 1. The origin of this software must not be misrepresented; 15 | you must not claim that you wrote the original software. 16 | If you use this software in a product, an acknowledgment 17 | in the product documentation would be appreciated but 18 | is not required. 19 | 20 | 2. Altered source versions must be plainly marked as such, 21 | and must not be misrepresented as being the original software. 22 | 23 | 3. This notice may not be removed or altered from any 24 | source distribution. -------------------------------------------------------------------------------- /rbsfml.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "rbSFML" 3 | s.version = "0.1.0" 4 | s.summary = "SFML for Ruby" 5 | s.description = "Bindings for the C++ multimedia library SFML." 6 | s.authors = ["Henrik Valter Vogelius Hansson"] 7 | s.email = "groogy@groogy.se" 8 | 9 | s.files = ["lib/sfml/rbsfml.so"} 10 | 11 | s.add_development_dependency "rake-compiler" 12 | 13 | s.homepage = "htpp://github.com/Groogy/rbSFML" 14 | end -------------------------------------------------------------------------------- /spec/blend_mode_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::BlendMode do 4 | 5 | describe "in creation" do 6 | context "given three arguments" do 7 | before(:each) do 8 | @mode = SFML::BlendMode.new(SFML::BlendMode::Zero, SFML::BlendMode::One, SFML::BlendMode::Subtract) 9 | end 10 | 11 | it "should set the properties accordingly" do 12 | expect(@mode.color_src_factor).to eql(SFML::BlendMode::Zero) 13 | expect(@mode.color_dst_factor).to eql(SFML::BlendMode::One) 14 | expect(@mode.color_equation).to eql(SFML::BlendMode::Subtract) 15 | end 16 | 17 | it "should set the alpha properties to the same" do 18 | expect(@mode.alpha_src_factor).to eql(@mode.color_src_factor) 19 | expect(@mode.alpha_dst_factor).to eql(@mode.color_dst_factor) 20 | expect(@mode.alpha_equation).to eql(@mode.color_equation) 21 | end 22 | end 23 | 24 | context "given six arguments" do 25 | before(:each) do 26 | @mode = SFML::BlendMode.new( 27 | SFML::BlendMode::Zero, SFML::BlendMode::One, SFML::BlendMode::Subtract, 28 | SFML::BlendMode::SrcColor, SFML::BlendMode::DstAlpha, SFML::BlendMode::Add 29 | ) 30 | end 31 | 32 | it "should set the properties accordingly" do 33 | expect(@mode.color_src_factor).to eql(SFML::BlendMode::Zero) 34 | expect(@mode.color_dst_factor).to eql(SFML::BlendMode::One) 35 | expect(@mode.color_equation).to eql(SFML::BlendMode::Subtract) 36 | expect(@mode.alpha_src_factor).to eql(SFML::BlendMode::SrcColor) 37 | expect(@mode.alpha_dst_factor).to eql(SFML::BlendMode::DstAlpha) 38 | expect(@mode.alpha_equation).to eql(SFML::BlendMode::Add) 39 | end 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /spec/clock_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Clock do 4 | describe "will give elapsed time" do 5 | context "after two seconds has passed" do 6 | clock = SFML::Clock.new 7 | SFML.sleep(SFML.milliseconds(20)) 8 | 9 | it "the returned time will be longer" do 10 | expect(clock.elapsed_time.as_milliseconds).to be > 20 11 | end 12 | end 13 | end 14 | 15 | describe "will reset its time" do 16 | context "after restart has been called" do 17 | clock = SFML::Clock.new 18 | time = SFML::Time.new 19 | before(:each) do 20 | SFML.sleep(SFML.milliseconds(20)) 21 | time = clock.restart 22 | end 23 | 24 | it "returning the elapsed time up to that point" do 25 | expect(time.as_milliseconds).to be > 18 # SFML doesn't guarantee that elapsed time will be passed 20 milliseconds 26 | end 27 | 28 | it "next call to elapsed_time give a lower elapsed time" do 29 | expect(clock.elapsed_time).to be < time 30 | end 31 | end 32 | end 33 | end -------------------------------------------------------------------------------- /spec/color_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Color do 4 | describe "in creation" do 5 | context "given no arguments" do 6 | obj = SFML::Color.new 7 | it "color properties should be zero" do 8 | expect(obj.r).to be(0) 9 | expect(obj.g).to be(0) 10 | expect(obj.b).to be(0) 11 | end 12 | 13 | it "should be equal to black color" do 14 | expect(obj == SFML::Color::Black).to be_truthy 15 | end 16 | 17 | it "should be equal an array of zeros" do 18 | expect(obj == [0, 0, 0]).to be_truthy 19 | end 20 | end 21 | 22 | context "given out of bounds arguments" do 23 | obj = SFML::Color.new(300, -100, 200) 24 | it "should clamp the values" do 25 | expect(obj.r).to be(255) 26 | expect(obj.g).to be(0) 27 | expect(obj.b).to be(200) 28 | end 29 | end 30 | end 31 | 32 | describe "in math" do 33 | context "between two color objects" do 34 | before(:each) do 35 | @color1 = SFML::Color.new(100, 200, 50) 36 | @color2 = SFML::Color.new(200, 25, 25) 37 | end 38 | 39 | it "addition will produce expected result" do 40 | expect(@color1 + @color2).to eq([255, 225, 75]) 41 | end 42 | 43 | it "subtraction will produce expected result" do 44 | expect(@color1 - @color2).to eq([0, 175, 25, 0]) 45 | end 46 | 47 | it "multiplication will produce expected result" do 48 | expect(@color1 * @color2).to eq([78, 19, 4]) 49 | end 50 | end 51 | end 52 | end -------------------------------------------------------------------------------- /spec/context_settings_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::ContextSettings do 4 | describe "in creation" do 5 | context "with no arguments" do 6 | mode = SFML::ContextSettings.new 7 | 8 | it "should give a context with default values" do 9 | expect(mode.depth_bits).to eql(0) 10 | expect(mode.stencil_bits).to eql(0) 11 | expect(mode.antialiasing_level).to eql(0) 12 | expect(mode.major_version).to eql(1) 13 | expect(mode.minor_version).to eql(1) 14 | expect(mode.attribute_flags).to eql(SFML::ContextSettings::Default) 15 | end 16 | end 17 | end 18 | end -------------------------------------------------------------------------------- /spec/context_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Context do 4 | describe "in creation" do 5 | context "with simple arguments" do 6 | it "should give a context that can be set active" do 7 | context = SFML::Context.new(SFML::ContextSettings.new, 800, 600) 8 | expect(context.set_active(true)).to be_truthy 9 | end 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /spec/renderwindow_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::RenderWindow do 4 | describe "in creation" do 5 | context "with no arguments" do 6 | before(:each) do 7 | @window = SFML::RenderWindow.new 8 | end 9 | 10 | it "should not open the window" do 11 | expect(@window.open?).to be_falsy 12 | end 13 | 14 | it "should open window if calling create" do 15 | @window.create(SFML::VideoMode.new(800, 600), "Hello World!") 16 | expect(@window.open?).to be_truthy 17 | end 18 | end 19 | 20 | context "with arguments" do 21 | before(:all) do 22 | @window = SFML::Window.new(SFML::VideoMode.new(800, 600), "Hello World!") 23 | end 24 | 25 | it "should open the window" do 26 | expect(@window.open?).to be_truthy 27 | end 28 | end 29 | end 30 | 31 | describe "in usage" do 32 | before(:each) do 33 | @window = SFML::RenderWindow.new(SFML::VideoMode.new(800, 600), "Hello World!") 34 | end 35 | 36 | context "when closing the window" do 37 | it "should be closed" do 38 | @window.close 39 | expect(@window.open?).to be_falsy 40 | end 41 | end 42 | 43 | context "when retrieving the settings" do 44 | it "should return a frozen object" do 45 | settings = @window.settings 46 | expect(settings.frozen?).to be_truthy 47 | end 48 | end 49 | 50 | context "when setting the position" do 51 | pos = SFML::Vector2.new(150, 88) 52 | before(:each) do 53 | @window.position = pos 54 | end 55 | 56 | it "should have that new position" do 57 | expect(@window.position).to eql(pos) 58 | end 59 | end 60 | 61 | context "when setting the size" do 62 | size = SFML::Vector2.new(300, 300) 63 | before(:each) do 64 | @window.size = size 65 | end 66 | 67 | it "should have that new size" do 68 | expect(@window.size).to eql(size) 69 | end 70 | end 71 | end 72 | end -------------------------------------------------------------------------------- /spec/time_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Time do 4 | describe "compare methods" do 5 | context "given an equal time" do 6 | time1 = SFML.seconds(2.0) 7 | time2 = SFML.seconds(2.0) 8 | 9 | it "returns true on equal" do 10 | expect(time1 == time2).to be_truthy 11 | end 12 | 13 | it "returns false on less than" do 14 | expect(time1 < time2).to be_falsy 15 | end 16 | 17 | it "returns false on greater than" do 18 | expect(time1 > time2).to be_falsy 19 | end 20 | end 21 | context "given a smaller time" do 22 | time1 = SFML.seconds(4.0) 23 | time2 = SFML.seconds(2.0) 24 | 25 | it "returns false on equal" do 26 | expect(time1 == time2).to be_falsy 27 | end 28 | 29 | it "returns false on less than" do 30 | expect(time1 < time2).to be_falsy 31 | end 32 | 33 | it "returns true on greater than" do 34 | expect(time1 > time2).to be_truthy 35 | end 36 | end 37 | context "given an bigger time" do 38 | time1 = SFML.seconds(2.0) 39 | time2 = SFML.seconds(4.0) 40 | 41 | it "returns false on equal" do 42 | expect(time1 == time2).to be_falsy 43 | end 44 | 45 | it "returns true on less than" do 46 | expect(time1 < time2).to be_truthy 47 | end 48 | 49 | it "returns false on greater than" do 50 | expect(time1 > time2).to be_falsy 51 | end 52 | end 53 | end 54 | 55 | describe "dup" do 56 | context "given an initialized time" do 57 | original = SFML.seconds(4.0) 58 | copy = original.dup 59 | 60 | it "creates an equal object" do 61 | expect(copy == original).to be_truthy 62 | end 63 | 64 | it "creates a new object" do 65 | expect(copy.equal?(original)).to be_falsy 66 | end 67 | end 68 | end 69 | end -------------------------------------------------------------------------------- /spec/vector2_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Vector2 do 4 | describe "in creation" do 5 | context "given no arguments" do 6 | obj = SFML::Vector2.new 7 | it "vector attributes should be zero" do 8 | expect(obj.x).to be(0) 9 | expect(obj.y).to be(0) 10 | end 11 | 12 | it "should be equal to the zero vector" do 13 | expect(obj == SFML::Vector2::Zero).to be_truthy 14 | end 15 | 16 | it "should be equal an array of zeros" do 17 | expect(obj == [0, 0]).to be_truthy 18 | end 19 | end 20 | 21 | context "given fixnum arguments" do 22 | obj = SFML::Vector2.new(3, 8) 23 | it "vector attributes should be equal to given values" do 24 | expect(obj.x).to eql(3) 25 | expect(obj.y).to eql(8) 26 | end 27 | 28 | it "vector attributes should be of fixnum type" do 29 | expect(obj.x).to be_kind_of(Fixnum) 30 | expect(obj.y).to be_kind_of(Fixnum) 31 | end 32 | end 33 | 34 | context "given float arguments" do 35 | obj = SFML::Vector2.new(3.0, 8.0) 36 | it "vector attributes should be equal to given values" do 37 | expect(obj.x).to eql(3.0) 38 | expect(obj.y).to eql(8.0) 39 | end 40 | 41 | it "vector attributes should be of float type" do 42 | expect(obj.x).to be_kind_of(Float) 43 | expect(obj.y).to be_kind_of(Float) 44 | end 45 | end 46 | end 47 | 48 | describe "in math" do 49 | context "given same type vectors" do 50 | vec1 = SFML::Vector2.new(3, 9) 51 | vec2 = SFML::Vector2.new(7, 4) 52 | it "addition will produce expected result" do 53 | expect(vec1 + vec2).to be(SFML::Vector2.new(10, 13)) 54 | end 55 | 56 | it "subtraction will produce expected result" do 57 | expect(vec1 - vec2).to be(SFML::Vector2.new(-4, 5)) 58 | end 59 | 60 | it "multiplication will produce expected result" do 61 | expect(vec1 * vec2).to be(SFML::Vector2.new(21, 36)) 62 | end 63 | 64 | it "division will produce expected result" do 65 | expect(vec1 / vec2).to be(SFML::Vector2.new(0, 2)) 66 | end 67 | end 68 | 69 | context "given different type vectors" do 70 | vec1 = SFML::Vector2.new(10.0, 12.0) 71 | vec2 = SFML::Vector2.new(2, 5) 72 | it "addition will produce expected result" do 73 | expect(vec1 + vec2).to be(SFML::Vector2.new(12.0, 17.0)) 74 | end 75 | 76 | it "subtraction will produce expected result" do 77 | expect(vec1 - vec2).to be(SFML::Vector2.new(8.0, 7.0)) 78 | end 79 | 80 | it "multiplication will produce expected result" do 81 | expect(vec1 * vec2).to be(SFML::Vector2.new(20.0, 60.0)) 82 | end 83 | 84 | it "division will produce expected result" do 85 | expect(vec1 / vec2).to be(SFML::Vector2.new(5.0, 2.4)) 86 | end 87 | end 88 | end 89 | end -------------------------------------------------------------------------------- /spec/vector3_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Vector3 do 4 | describe "in creation" do 5 | context "given no arguments" do 6 | obj = SFML::Vector3.new 7 | it "vector attributes should be zero" do 8 | expect(obj.x).to be(0) 9 | expect(obj.y).to be(0) 10 | expect(obj.z).to be(0) 11 | end 12 | 13 | it "should be equal to the zero vector" do 14 | expect(obj == SFML::Vector3::Zero).to be_truthy 15 | end 16 | 17 | it "should be equal an array of zeros" do 18 | expect(obj == [0, 0, 0]).to be_truthy 19 | end 20 | end 21 | 22 | context "given fixnum arguments" do 23 | obj = SFML::Vector3.new(3, 8, 9) 24 | it "vector attributes should be equal to given values" do 25 | expect(obj.x).to eql(3) 26 | expect(obj.y).to eql(8) 27 | expect(obj.z).to eql(9) 28 | end 29 | 30 | it "vector attributes should be of fixnum type" do 31 | expect(obj.x).to be_kind_of(Fixnum) 32 | expect(obj.y).to be_kind_of(Fixnum) 33 | expect(obj.z).to be_kind_of(Fixnum) 34 | end 35 | end 36 | 37 | context "given float arguments" do 38 | obj = SFML::Vector3.new(3.0, 8.0, 9.0) 39 | it "vector attributes should be equal to given values" do 40 | expect(obj.x).to eql(3.0) 41 | expect(obj.y).to eql(8.0) 42 | expect(obj.z).to eql(9.0) 43 | end 44 | 45 | it "vector attributes should be of float type" do 46 | expect(obj.x).to be_kind_of(Float) 47 | expect(obj.y).to be_kind_of(Float) 48 | expect(obj.z).to be_kind_of(Float) 49 | end 50 | end 51 | end 52 | 53 | describe "in math" do 54 | context "given same type vectors" do 55 | vec1 = SFML::Vector3.new(3, 9, 2) 56 | vec2 = SFML::Vector3.new(7, 4, 5) 57 | it "addition will produce expected result" do 58 | expect(vec1 + vec2).to be(SFML::Vector3.new(10, 13, 7)) 59 | end 60 | 61 | it "subtraction will produce expected result" do 62 | expect(vec1 - vec2).to be(SFML::Vector3.new(-4, 5, -3)) 63 | end 64 | 65 | it "multiplication will produce expected result" do 66 | expect(vec1 * vec2).to be(SFML::Vector3.new(21, 36, 10)) 67 | end 68 | 69 | it "division will produce expected result" do 70 | expect(vec1 / vec2).to be(SFML::Vector3.new(0, 2, 0)) 71 | end 72 | end 73 | 74 | context "given different type vectors" do 75 | vec1 = SFML::Vector3.new(10.0, 12.0, 6.0) 76 | vec2 = SFML::Vector3.new(2, 5, 4) 77 | it "addition will produce expected result" do 78 | expect(vec1 + vec2).to be(SFML::Vector3.new(12.0, 17.0, 10.0)) 79 | end 80 | 81 | it "subtraction will produce expected result" do 82 | expect(vec1 - vec2).to be(SFML::Vector3.new(8.0, 7.0, 2.0)) 83 | end 84 | 85 | it "multiplication will produce expected result" do 86 | expect(vec1 * vec2).to be(SFML::Vector3.new(20.0, 60.0, 24.0)) 87 | end 88 | 89 | it "division will produce expected result" do 90 | expect(vec1 / vec2).to be(SFML::Vector3.new(5.0, 2.4, 1.5)) 91 | end 92 | end 93 | end 94 | end -------------------------------------------------------------------------------- /spec/video_mode_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::VideoMode do 4 | describe "in creation" do 5 | context "with no arguments" do 6 | mode = SFML::VideoMode.new 7 | 8 | it "should give an invalid video mode" do 9 | expect(mode.valid?).to be_falsy 10 | end 11 | end 12 | 13 | context "with two arguments" do 14 | mode = SFML::VideoMode.new(800, 600) 15 | it "should give a valid video mode" do 16 | expect(mode.valid?).to be_truthy 17 | end 18 | 19 | it "should return correct width" do 20 | expect(mode.width).to eql(800) 21 | end 22 | 23 | it "should return correct height" do 24 | expect(mode.height).to eql(600) 25 | end 26 | 27 | it "should return default bits per pixel" do 28 | expect(mode.bpp).to eql(32) 29 | end 30 | end 31 | 32 | context "with invalid bits per pixel" do 33 | mode = SFML::VideoMode.new(800, 600, 88) 34 | it "should give an invalid video mode" do 35 | expect(mode.valid?).to be_falsy 36 | end 37 | end 38 | end 39 | 40 | describe "in basic instance usage" do 41 | before(:each) do 42 | @mode = SFML::VideoMode.new 43 | end 44 | 45 | it "should allow you to modify the width" do 46 | @mode.width = 1024 47 | expect(@mode.width).to eql(1024) 48 | end 49 | 50 | it "should allow you to modify the height" do 51 | @mode.height = 900 52 | expect(@mode.height).to eql(900) 53 | end 54 | end 55 | 56 | describe "in fetching desktop resolution" do 57 | mode = SFML::VideoMode.desktop_mode 58 | 59 | it "should give a valid video mode" do 60 | expect(mode.valid?).to be_truthy 61 | end 62 | end 63 | 64 | describe "in fetching fullscreen resolutions" do 65 | modes = SFML::VideoMode.fullscreen_modes 66 | 67 | it "should give array with more than one mode" do 68 | expect(modes.size).to be > 1 69 | end 70 | 71 | it "should give only valid video modes" do 72 | modes.each do |mode| 73 | expect(mode.valid?).to be_truthy 74 | end 75 | end 76 | end 77 | end -------------------------------------------------------------------------------- /spec/window_spec.rb: -------------------------------------------------------------------------------- 1 | require './lib/sfml/rbsfml.so' 2 | 3 | describe SFML::Window do 4 | describe "in creation" do 5 | context "with no arguments" do 6 | before(:each) do 7 | @window = SFML::Window.new 8 | end 9 | 10 | it "should not open the window" do 11 | expect(@window.open?).to be_falsy 12 | end 13 | 14 | it "should open window if calling create" do 15 | @window.create(SFML::VideoMode.new(800, 600), "Hello World!") 16 | expect(@window.open?).to be_truthy 17 | end 18 | end 19 | 20 | context "with arguments" do 21 | before(:all) do 22 | @window = SFML::Window.new(SFML::VideoMode.new(800, 600), "Hello World!") 23 | end 24 | 25 | it "should open the window" do 26 | expect(@window.open?).to be_truthy 27 | end 28 | end 29 | end 30 | 31 | describe "in usage" do 32 | before(:each) do 33 | @window = SFML::Window.new(SFML::VideoMode.new(800, 600), "Hello World!") 34 | end 35 | 36 | context "when closing the window" do 37 | it "should be closed" do 38 | @window.close 39 | expect(@window.open?).to be_falsy 40 | end 41 | end 42 | 43 | context "when retrieving the settings" do 44 | it "should return a frozen object" do 45 | settings = @window.settings 46 | expect(settings.frozen?).to be_truthy 47 | end 48 | end 49 | 50 | context "when setting the position" do 51 | pos = SFML::Vector2.new(150, 88) 52 | before(:each) do 53 | @window.position = pos 54 | end 55 | 56 | it "should have that new position" do 57 | expect(@window.position).to eql(pos) 58 | end 59 | end 60 | 61 | context "when setting the size" do 62 | size = SFML::Vector2.new(300, 300) 63 | before(:each) do 64 | @window.size = size 65 | end 66 | 67 | it "should have that new size" do 68 | expect(@window.size).to eql(size) 69 | end 70 | end 71 | end 72 | end --------------------------------------------------------------------------------