diff --git a/bindings/ruby/sfml-window/window/Context.cpp b/bindings/ruby/sfml-window/window/Context.cpp index d2f2a95a2..d61a7ea3b 100644 --- a/bindings/ruby/sfml-window/window/Context.cpp +++ b/bindings/ruby/sfml-window/window/Context.cpp @@ -24,20 +24,6 @@ #include "main.hpp" #include -/* If you need to make OpenGL / graphics calls without having an active window - * (like in a thread), you can use an instance of this class to get a valid context. - * - * Having a valid context is necessary for *every* OpenGL call, and for most of - * the classes from the Graphics package. - * - * Note that a context is only active in its current thread, if you create a new - * thread it will have no valid context by default. - * - * To use a sf::Context instance, just construct it and let it live as long as - * you need a valid context. No explicit activation is needed, all it has to do - * is to exist. Its destructor will take care of deactivating and freeing all - * the attached resources. - */ VALUE globalContextClass; /* Free a heap allocated object @@ -105,14 +91,31 @@ static VALUE Context_New( VALUE aKlass ) void Init_Context( void ) { - globalContextClass = rb_define_class_under( GetNamespace(), "Context", rb_cObject ); + +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* If you need to make OpenGL / graphics calls without having an active window + * (like in a thread), you can use an instance of this class to get a valid context. + * + * Having a valid context is necessary for *every* OpenGL call, and for most of + * the classes from the Graphics package. + * + * Note that a context is only active in its current thread, if you create a new + * thread it will have no valid context by default. + * + * To use a sf::Context instance, just construct it and let it live as long as + * you need a valid context. No explicit activation is needed, all it has to do + * is to exist. Its destructor will take care of deactivating and freeing all + * the attached resources. + */ + globalContextClass = rb_define_class_under( sfml, "Context", rb_cObject ); // Class methods - rb_define_singleton_method( globalContextClass, "new", FUNCPTR( Context_New ), 0 ); - rb_define_singleton_method( globalContextClass, "setReferenceActive", FUNCPTR( Context_SetReferenceActive ), 0 ); + rb_define_singleton_method( globalContextClass, "new", Context_New, 0 ); + rb_define_singleton_method( globalContextClass, "setReferenceActive", Context_SetReferenceActive, 0 ); // Instance methods - rb_define_method( globalContextClass, "setActive", FUNCPTR( Context_SetActive ), 1 ); + rb_define_method( globalContextClass, "setActive", Context_SetActive, 1 ); // Aliases rb_define_alias( globalContextClass, "active=", "setActive" ); diff --git a/bindings/ruby/sfml-window/window/ContextSettings.cpp b/bindings/ruby/sfml-window/window/ContextSettings.cpp index 3503d1633..ddc790f18 100644 --- a/bindings/ruby/sfml-window/window/ContextSettings.cpp +++ b/bindings/ruby/sfml-window/window/ContextSettings.cpp @@ -25,31 +25,7 @@ #include #include -/* ContextSettings allows to define several advanced settings of the OpenGL - * context attached to a window. - * - * All these settings have no impact on the regular SFML rendering - * (graphics module) -- except the anti-aliasing level, so you may need to use - * this structure only if you're using SFML as a windowing system for custom - * OpenGL rendering. - * - * The DepthBits and StencilBits members define the number of bits per pixel - * requested for the (respectively) depth and stencil buffers. - * - * AntialiasingLevel represents the requested number of multisampling levels - * for anti-aliasing. - * - * MajorVersion and MinorVersion define the version of the OpenGL context that - * you want. Only versions greater or equal to 3.0 are relevant; versions - * lesser than 3.0 are all handled the same way (i.e. you can use any version - * < 3.0 if you don't want an OpenGL 3 context). - * - * Please note that these values are only a hint. No failure will be reported - * if one or more of these values are not supported by the system; instead, - * SFML will try to find the closest valid match. You can then retrieve the - * settings that the window actually used to create its context, with - * Window::GetSettings(). - */ + VALUE globalContextSettingsClass; /* Free a heap allocated object @@ -242,26 +218,53 @@ static VALUE ContextSettings_New( VALUE aKlass, VALUE someArgs ) void Init_ContextSettings( void ) { - globalContextSettingsClass = rb_define_class_under( GetNamespace(), "ContextSettings", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* ContextSettings allows to define several advanced settings of the OpenGL + * context attached to a window. + * + * All these settings have no impact on the regular SFML rendering + * (graphics module) -- except the anti-aliasing level, so you may need to use + * this structure only if you're using SFML as a windowing system for custom + * OpenGL rendering. + * + * The DepthBits and StencilBits members define the number of bits per pixel + * requested for the (respectively) depth and stencil buffers. + * + * AntialiasingLevel represents the requested number of multisampling levels + * for anti-aliasing. + * + * MajorVersion and MinorVersion define the version of the OpenGL context that + * you want. Only versions greater or equal to 3.0 are relevant; versions + * lesser than 3.0 are all handled the same way (i.e. you can use any version + * < 3.0 if you don't want an OpenGL 3 context). + * + * Please note that these values are only a hint. No failure will be reported + * if one or more of these values are not supported by the system; instead, + * SFML will try to find the closest valid match. You can then retrieve the + * settings that the window actually used to create its context, with + * Window::GetSettings(). + */ + globalContextSettingsClass = rb_define_class_under( sfml, "ContextSettings", rb_cObject ); // Class methods - rb_define_singleton_method( globalContextSettingsClass, "new", FUNCPTR( ContextSettings_New ), -2 ); + rb_define_singleton_method( globalContextSettingsClass, "new", ContextSettings_New, -2 ); // Instance methods - rb_define_method( globalContextSettingsClass, "depthBits", FUNCPTR( ContextSettings_GetDepth ), 0 ); - rb_define_method( globalContextSettingsClass, "depthBits=", FUNCPTR( ContextSettings_SetDepth ), 1 ); + rb_define_method( globalContextSettingsClass, "depthBits", ContextSettings_GetDepth, 0 ); + rb_define_method( globalContextSettingsClass, "depthBits=", ContextSettings_SetDepth, 1 ); - rb_define_method( globalContextSettingsClass, "stencilBits", FUNCPTR( ContextSettings_GetStencil ), 0 ); - rb_define_method( globalContextSettingsClass, "stencilBits=", FUNCPTR( ContextSettings_SetStencil ), 1 ); + rb_define_method( globalContextSettingsClass, "stencilBits", ContextSettings_GetStencil, 0 ); + rb_define_method( globalContextSettingsClass, "stencilBits=", ContextSettings_SetStencil, 1 ); - rb_define_method( globalContextSettingsClass, "antialiasingLevel", FUNCPTR( ContextSettings_GetAntialiasing ), 0 ); - rb_define_method( globalContextSettingsClass, "antialiasingLevel=", FUNCPTR( ContextSettings_SetAntialiasing ), 1 ); + rb_define_method( globalContextSettingsClass, "antialiasingLevel", ContextSettings_GetAntialiasing, 0 ); + rb_define_method( globalContextSettingsClass, "antialiasingLevel=", ContextSettings_SetAntialiasing, 1 ); - rb_define_method( globalContextSettingsClass, "majorVersion", FUNCPTR( ContextSettings_GetMajorVersion ), 0 ); - rb_define_method( globalContextSettingsClass, "majorVersion=", FUNCPTR( ContextSettings_SetMajorVersion ), 1 ); + rb_define_method( globalContextSettingsClass, "majorVersion", ContextSettings_GetMajorVersion, 0 ); + rb_define_method( globalContextSettingsClass, "majorVersion=", ContextSettings_SetMajorVersion, 1 ); - rb_define_method( globalContextSettingsClass, "minorVersion", FUNCPTR( ContextSettings_GetMinorVersion ), 0 ); - rb_define_method( globalContextSettingsClass, "minorVersion=", FUNCPTR( ContextSettings_SetMinorVersion ), 1 ); + rb_define_method( globalContextSettingsClass, "minorVersion", ContextSettings_GetMinorVersion, 0 ); + rb_define_method( globalContextSettingsClass, "minorVersion=", ContextSettings_SetMinorVersion, 1 ); // Aliases rb_define_alias( globalContextSettingsClass, "depth", "depthBits" ); diff --git a/bindings/ruby/sfml-window/window/Event.cpp b/bindings/ruby/sfml-window/window/Event.cpp index e0eba0d51..8896fbdc3 100644 --- a/bindings/ruby/sfml-window/window/Event.cpp +++ b/bindings/ruby/sfml-window/window/Event.cpp @@ -24,40 +24,6 @@ #include "main.hpp" #include -/* SFML::Event holds all the informations about a system event that just happened. - * - * Events are retrieved using the SFML::Window#GetEvent function. - * - * A SFML::Event instance contains the type of the event (mouse moved, key pressed, window closed, ...) - * as well as the details about this particular event. Please note that the event parameters are - * defined in a union, which means that only the member matching the type of the event will be properly - * filled; all other members will have undefined values and must not be read if the type of the event - * doesn't match. For example, if you received a KeyPressed event, then you must read the event.Key - * member, all other members such as event.MouseMove or event.Text will have undefined values. - * - * The ruby version differs from C++ in that the parameters are still stored in a union but that - * the values can be directly accessed from the event object. If you try to access any data which - * would be considered undefined then SFML::SomeKindOfException will be thrown. - * - * Usage example: - * - * while event = window.getEvent() - * - * # Request for closing the window - * if event.type == SFML::Event::Closed - * window.close - * - * # The escape key was pressed - * if ( event.type == sf::Event::KeyPressed ) && ( event.code == SFML::Key::Escape ) - * window.close - * - * # The window was resized - * if event.type == SFML::Event::Resized - * DoSomethingWithTheNewSize(event.size); - * - * # etc ... - * end - */ VALUE globalEventClass; /* Joystick buttons events parameters (JoyButtonPressed, JoyButtonReleased). */ @@ -94,23 +60,14 @@ static void Event_Free( sf::Event *anObject ) #define MOUSE2NUM( x ) INT2NUM( static_cast< int > ( x ) ) #define NUM2MOUSE( x ) static_cast< sf::Mouse::Button >( NUM2INT( x ) ) -#define EVENT_TYPE_ACCESSORS( a, b, conv1, conv2 ) \ -static VALUE a##Event_Get##b ( VALUE self ) \ +#define EVENT_TYPE_ACCESSORS( a, b, conv1 ) \ { \ sf::Event:: a##Event * object = NULL; \ Data_Get_Struct( self, sf::Event:: a##Event, object ); \ return conv1 ( object-> b ); \ -} \ - \ -static VALUE a##Event_Set##b ( VALUE self, VALUE aVal ) \ -{ \ - sf::Event:: a##Event * object = NULL; \ - Data_Get_Struct( self, sf::Event:: a##Event, object ); \ - return conv1 ( object-> b = conv2 ( aVal ) ); \ } #define EVENT_TYPE_BOOL_ACCESSORS( a, b ) \ -static VALUE a##Event_Get##b ( VALUE self ) \ { \ sf::Event:: a##Event * object = NULL; \ Data_Get_Struct( self, sf::Event:: a##Event, object ); \ @@ -118,47 +75,77 @@ static VALUE a##Event_Get##b ( VALUE self ) \ return Qtrue; \ else \ return Qfalse; \ -} \ - \ -static VALUE a##Event_Set##b ( VALUE self, VALUE aVal ) \ -{ \ - sf::Event:: a##Event * object = NULL; \ - Data_Get_Struct( self, sf::Event:: a##Event, object ); \ - if( aVal == Qtrue ) \ - object-> b = true; \ - else \ - object-> b = false; \ - return aVal; \ } -EVENT_TYPE_ACCESSORS( JoyButton, JoystickId, INT2NUM, NUM2UINT ); -EVENT_TYPE_ACCESSORS( JoyButton, Button, INT2NUM, NUM2UINT ); +/* Index of the joystick (0 or 1). */ +static VALUE JoyButtonEvent_GetJoystickId( VALUE self ) +EVENT_TYPE_ACCESSORS( JoyButton, JoystickId, INT2NUM ) +/* Index of the button that has been pressed. */ +static VALUE JoyButtonEvent_GetButton( VALUE self ) +EVENT_TYPE_ACCESSORS( JoyButton, Button, INT2NUM ) -EVENT_TYPE_ACCESSORS( JoyMove, JoystickId, INT2NUM, NUM2UINT ); -EVENT_TYPE_ACCESSORS( JoyMove, Axis, AXIS2NUM, NUM2AXIS ); -EVENT_TYPE_ACCESSORS( JoyMove, Position, rb_float_new, NUM2DBL ); +/* Index of the joystick (0 or 1). */ +static VALUE JoyMoveEvent_GetJoystickId( VALUE self ) +EVENT_TYPE_ACCESSORS( JoyMove, JoystickId, INT2NUM ) +/* Axis on which the joystick moved. */ +static VALUE JoyMoveEvent_GetAxis( VALUE self ) +EVENT_TYPE_ACCESSORS( JoyMove, Axis, AXIS2NUM ) +/* New position on the axis (in range [-100, 100]). */ +static VALUE JoyMoveEvent_GetPosition( VALUE self ) +EVENT_TYPE_ACCESSORS( JoyMove, Position, rb_float_new ) -EVENT_TYPE_ACCESSORS( Key, Code, KEY2NUM, NUM2KEY ); -EVENT_TYPE_BOOL_ACCESSORS( Key, Alt ); -EVENT_TYPE_BOOL_ACCESSORS( Key, Control ); -EVENT_TYPE_BOOL_ACCESSORS( Key, Shift ); +/* Code of the key that has been pressed. */ +static VALUE KeyEvent_GetCode( VALUE self ) +EVENT_TYPE_ACCESSORS( Key, Code, KEY2NUM ) +/* Is the Alt key pressed? */ +static VALUE KeyEvent_GetAlt( VALUE self ) +EVENT_TYPE_BOOL_ACCESSORS( Key, Alt ) +/* Is the Control key pressed? */ +static VALUE KeyEvent_GetControl( VALUE self ) +EVENT_TYPE_BOOL_ACCESSORS( Key, Control ) +/* Is the Shift key pressed? */ +static VALUE KeyEvent_GetShift( VALUE self ) +EVENT_TYPE_BOOL_ACCESSORS( Key, Shift ) -EVENT_TYPE_ACCESSORS( MouseButton, Button, MOUSE2NUM, NUM2MOUSE ); -EVENT_TYPE_ACCESSORS( MouseButton, X, INT2NUM, NUM2INT ); -EVENT_TYPE_ACCESSORS( MouseButton, Y, INT2NUM, NUM2INT ); +/* Code of the button that has been pressed. */ +static VALUE MouseButtonEvent_GetButton( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseButton, Button, MOUSE2NUM ) +/* X position of the mouse pointer, relative to the left of the owner window */ +static VALUE MouseButtonEvent_GetX( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseButton, X, INT2NUM ) +/* Y position of the mouse pointer, relative to the top of the owner window */ +static VALUE MouseButtonEvent_GetY( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseButton, Y, INT2NUM ) -EVENT_TYPE_ACCESSORS( MouseMove, X, INT2NUM, NUM2INT ); -EVENT_TYPE_ACCESSORS( MouseMove, Y, INT2NUM, NUM2INT ); +/* X position of the mouse pointer, relative to the left of the owner window */ +static VALUE MouseMoveEvent_GetX( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseMove, X, INT2NUM ) +/* Y position of the mouse pointer, relative to the top of the owner window */ +static VALUE MouseMoveEvent_GetY( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseMove, Y, INT2NUM ) -EVENT_TYPE_ACCESSORS( MouseWheel, Delta, INT2NUM, NUM2INT ); -EVENT_TYPE_ACCESSORS( MouseWheel, X, INT2NUM, NUM2INT ); -EVENT_TYPE_ACCESSORS( MouseWheel, Y, INT2NUM, NUM2INT ); +/* Number of ticks the wheel has moved (positive is up, negative is down). */ +static VALUE MouseWheelEvent_GetDelta( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseWheel, Delta, INT2NUM ) +/* X position of the mouse pointer, relative to the left of the owner window */ +static VALUE MouseWheelEvent_GetX( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseWheel, X, INT2NUM ) +/* Y position of the mouse pointer, relative to the top of the owner window */ +static VALUE MouseWheelEvent_GetY( VALUE self ) +EVENT_TYPE_ACCESSORS( MouseWheel, Y, INT2NUM ) -EVENT_TYPE_ACCESSORS( Size, Width, INT2NUM, NUM2UINT ); -EVENT_TYPE_ACCESSORS( Size, Height, INT2NUM, NUM2UINT ); +/* New width, in pixels. */ +static VALUE SizeEvent_GetWidth( VALUE self ) +EVENT_TYPE_ACCESSORS( Size, Width, INT2NUM ) +/* New height, in pixels. */ +static VALUE SizeEvent_GetHeight( VALUE self ) +EVENT_TYPE_ACCESSORS( Size, Height, INT2NUM ) -EVENT_TYPE_ACCESSORS( Text, Unicode, INT2NUM, NUM2UINT ); +/* UTF-32 unicode value of the character. */ +static VALUE TextEvent_GetUnicode( VALUE self ) +EVENT_TYPE_ACCESSORS( Text, Unicode, INT2NUM ) +/* */ static VALUE Event_Initialize( VALUE self, VALUE aType ) { sf::Event * object = NULL; @@ -243,9 +230,46 @@ static VALUE Event_New( int argc, VALUE * args, VALUE aKlass ) return rbData; } + void Init_Event( void ) { - globalEventClass = rb_define_class_under( GetNamespace(), "Event", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* SFML::Event holds all the informations about a system event that just happened. + * + * Events are retrieved using the SFML::Window#GetEvent function. + * + * A SFML::Event instance contains the type of the event (mouse moved, key pressed, window closed, ...) + * as well as the details about this particular event. Please note that the event parameters are + * defined in a union, which means that only the member matching the type of the event will be properly + * filled; all other members will have undefined values and must not be read if the type of the event + * doesn't match. For example, if you received a KeyPressed event, then you must read the event.Key + * member, all other members such as event.MouseMove or event.Text will have undefined values. + * + * The ruby version differs from C++ in that the parameters are still stored in a union but that + * the values can be directly accessed from the event object. If you try to access any data which + * would be considered undefined then SFML::SomeKindOfException will be thrown. + * + * Usage example: + * + * while event = window.getEvent() + * + * # Request for closing the window + * if event.type == SFML::Event::Closed + * window.close + * + * # The escape key was pressed + * if ( event.type == sf::Event::KeyPressed ) && ( event.code == SFML::Key::Escape ) + * window.close + * + * # The window was resized + * if event.type == SFML::Event::Resized + * DoSomethingWithTheNewSize(event.size); + * + * # etc ... + * end + */ + globalEventClass = rb_define_class_under( sfml, "Event", rb_cObject ); globalJoyButtonEventClass = rb_define_class_under( globalEventClass, "JoyButton", rb_cObject ); globalJoyMoveEventClass = rb_define_class_under( globalEventClass, "JoyMove", rb_cObject ); globalKeyEventClass = rb_define_class_under( globalEventClass, "Key", rb_cObject ); @@ -255,29 +279,29 @@ void Init_Event( void ) globalSizeEventClass = rb_define_class_under( globalEventClass, "Size", rb_cObject ); globalTextEventClass = rb_define_class_under( globalEventClass, "Text", rb_cObject ); - rb_define_const( globalEventClass, "Closed", INT2NUM( static_cast< int >( sf::Event::Closed ) ) ); - rb_define_const( globalEventClass, "Resized", INT2NUM( static_cast< int >( sf::Event::Resized ) ) ); - rb_define_const( globalEventClass, "LostFocus", INT2NUM( static_cast< int >( sf::Event::LostFocus ) ) ); - rb_define_const( globalEventClass, "GainedFocus", INT2NUM( static_cast< int >( sf::Event::GainedFocus ) ) ); - rb_define_const( globalEventClass, "TextEntered", INT2NUM( static_cast< int >( sf::Event::TextEntered ) ) ); - rb_define_const( globalEventClass, "KeyPressed", INT2NUM( static_cast< int >( sf::Event::KeyPressed ) ) ); - rb_define_const( globalEventClass, "KeyReleased", INT2NUM( static_cast< int >( sf::Event::KeyReleased ) ) ); - rb_define_const( globalEventClass, "MouseWheelMoved", INT2NUM( static_cast< int >( sf::Event::MouseWheelMoved ) ) ); - rb_define_const( globalEventClass, "MouseButtonPressed", INT2NUM( static_cast< int >( sf::Event::MouseButtonPressed ) ) ); - rb_define_const( globalEventClass, "MouseButtonReleased", INT2NUM( static_cast< int >( sf::Event::MouseButtonReleased ) ) ); - rb_define_const( globalEventClass, "MouseMoved", INT2NUM( static_cast< int >( sf::Event::MouseMoved ) ) ); - rb_define_const( globalEventClass, "MouseEntered", INT2NUM( static_cast< int >( sf::Event::MouseEntered ) ) ); - rb_define_const( globalEventClass, "MouseLeft", INT2NUM( static_cast< int >( sf::Event::MouseLeft ) ) ); - rb_define_const( globalEventClass, "JoyButtonPressed", INT2NUM( static_cast< int >( sf::Event::JoyButtonPressed ) ) ); - rb_define_const( globalEventClass, "JoyButtonReleased", INT2NUM( static_cast< int >( sf::Event::JoyButtonReleased ) ) ); - rb_define_const( globalEventClass, "JoyMoved", INT2NUM( static_cast< int >( sf::Event::JoyMoved ) ) ); - rb_define_const( globalEventClass, "Count", INT2NUM( static_cast< int >( sf::Event::Count ) ) ); + rb_define_const( globalEventClass, "Closed", INT2NUM( sf::Event::Closed ) ); + rb_define_const( globalEventClass, "Resized", INT2NUM( sf::Event::Resized ) ); + rb_define_const( globalEventClass, "LostFocus", INT2NUM( sf::Event::LostFocus ) ); + rb_define_const( globalEventClass, "GainedFocus", INT2NUM( sf::Event::GainedFocus ) ); + rb_define_const( globalEventClass, "TextEntered", INT2NUM( sf::Event::TextEntered ) ); + rb_define_const( globalEventClass, "KeyPressed", INT2NUM( sf::Event::KeyPressed ) ); + rb_define_const( globalEventClass, "KeyReleased", INT2NUM( sf::Event::KeyReleased ) ); + rb_define_const( globalEventClass, "MouseWheelMoved", INT2NUM( sf::Event::MouseWheelMoved ) ); + rb_define_const( globalEventClass, "MouseButtonPressed", INT2NUM( sf::Event::MouseButtonPressed ) ); + rb_define_const( globalEventClass, "MouseButtonReleased", INT2NUM( sf::Event::MouseButtonReleased ) ); + rb_define_const( globalEventClass, "MouseMoved", INT2NUM( sf::Event::MouseMoved ) ); + rb_define_const( globalEventClass, "MouseEntered", INT2NUM( sf::Event::MouseEntered ) ); + rb_define_const( globalEventClass, "MouseLeft", INT2NUM( sf::Event::MouseLeft ) ); + rb_define_const( globalEventClass, "JoyButtonPressed", INT2NUM( sf::Event::JoyButtonPressed ) ); + rb_define_const( globalEventClass, "JoyButtonReleased", INT2NUM( sf::Event::JoyButtonReleased ) ); + rb_define_const( globalEventClass, "JoyMoved", INT2NUM( sf::Event::JoyMoved ) ); + rb_define_const( globalEventClass, "Count", INT2NUM( sf::Event::Count ) ); // Class methods - rb_define_singleton_method( globalEventClass, "new", FUNCPTR( Event_New ), -1 ); + rb_define_singleton_method( globalEventClass, "new", Event_New, -1 ); // Instance methods - rb_define_method( globalEventClass, "initialize", FUNCPTR( Event_Initialize ), 1 ); + rb_define_method( globalEventClass, "initialize", Event_Initialize, 1 ); rb_define_attr( globalEventClass, "type", 1, 0 ); rb_define_attr( globalEventClass, "joyButton", 1, 0 ); rb_define_attr( globalEventClass, "joyMove", 1, 0 ); @@ -289,70 +313,50 @@ void Init_Event( void ) rb_define_attr( globalEventClass, "text", 1, 0 ); // JoyButton methods - rb_define_method( globalJoyButtonEventClass, "joystickId", FUNCPTR( JoyButtonEvent_GetJoystickId ), 0 ); - rb_define_method( globalJoyButtonEventClass, "joystickId=", FUNCPTR( JoyButtonEvent_SetJoystickId ), 1 ); + rb_define_method( globalJoyButtonEventClass, "joystickId", JoyButtonEvent_GetJoystickId, 0 ); - rb_define_method( globalJoyButtonEventClass, "button", FUNCPTR( JoyButtonEvent_GetButton ), 0 ); - rb_define_method( globalJoyButtonEventClass, "button=", FUNCPTR( JoyButtonEvent_SetButton ), 1 ); + rb_define_method( globalJoyButtonEventClass, "button", JoyButtonEvent_GetButton, 0 ); // JoyMove methods - rb_define_method( globalJoyMoveEventClass, "joystickId", FUNCPTR( JoyMoveEvent_GetJoystickId ), 0 ); - rb_define_method( globalJoyMoveEventClass, "joystickId=", FUNCPTR( JoyMoveEvent_SetJoystickId ), 1 ); + rb_define_method( globalJoyMoveEventClass, "joystickId", JoyMoveEvent_GetJoystickId, 0 ); - rb_define_method( globalJoyMoveEventClass, "axis", FUNCPTR( JoyMoveEvent_GetAxis ), 0 ); - rb_define_method( globalJoyMoveEventClass, "axis=", FUNCPTR( JoyMoveEvent_SetAxis ), 1 ); + rb_define_method( globalJoyMoveEventClass, "axis", JoyMoveEvent_GetAxis, 0 ); - rb_define_method( globalJoyMoveEventClass, "position", FUNCPTR( JoyMoveEvent_GetPosition ), 0 ); - rb_define_method( globalJoyMoveEventClass, "position=", FUNCPTR( JoyMoveEvent_SetPosition ), 1 ); + rb_define_method( globalJoyMoveEventClass, "position", JoyMoveEvent_GetPosition, 0 ); // Key methods - rb_define_method( globalKeyEventClass, "code", FUNCPTR( KeyEvent_GetCode ), 0 ); - rb_define_method( globalKeyEventClass, "code=", FUNCPTR( KeyEvent_SetCode ), 1 ); + rb_define_method( globalKeyEventClass, "code", KeyEvent_GetCode, 0 ); - rb_define_method( globalKeyEventClass, "alt", FUNCPTR( KeyEvent_GetAlt ), 0 ); - rb_define_method( globalKeyEventClass, "alt=", FUNCPTR( KeyEvent_SetAlt ), 1 ); + rb_define_method( globalKeyEventClass, "alt", KeyEvent_GetAlt, 0 ); - rb_define_method( globalKeyEventClass, "control", FUNCPTR( KeyEvent_GetControl ), 0 ); - rb_define_method( globalKeyEventClass, "control=", FUNCPTR( KeyEvent_SetControl ), 1 ); + rb_define_method( globalKeyEventClass, "control", KeyEvent_GetControl, 0 ); - rb_define_method( globalKeyEventClass, "shift", FUNCPTR( KeyEvent_GetShift ), 0 ); - rb_define_method( globalKeyEventClass, "shift=", FUNCPTR( KeyEvent_SetShift ), 1 ); + rb_define_method( globalKeyEventClass, "shift", KeyEvent_GetShift, 0 ); // MouseButton methods - rb_define_method( globalMouseButtonEventClass, "button", FUNCPTR( MouseButtonEvent_GetButton ), 0 ); - rb_define_method( globalMouseButtonEventClass, "button=", FUNCPTR( MouseButtonEvent_SetButton ), 1 ); + rb_define_method( globalMouseButtonEventClass, "button", MouseButtonEvent_GetButton, 0 ); - rb_define_method( globalMouseButtonEventClass, "x", FUNCPTR( MouseButtonEvent_GetX ), 0 ); - rb_define_method( globalMouseButtonEventClass, "x=", FUNCPTR( MouseButtonEvent_SetX ), 1 ); + rb_define_method( globalMouseButtonEventClass, "x", MouseButtonEvent_GetX, 0 ); - rb_define_method( globalMouseButtonEventClass, "y", FUNCPTR( MouseButtonEvent_GetY ), 0 ); - rb_define_method( globalMouseButtonEventClass, "y=", FUNCPTR( MouseButtonEvent_SetY ), 1 ); + rb_define_method( globalMouseButtonEventClass, "y", MouseButtonEvent_GetY, 0 ); // MouseMove methods - rb_define_method( globalMouseMoveEventClass, "x", FUNCPTR( MouseMoveEvent_GetX ), 0 ); - rb_define_method( globalMouseMoveEventClass, "x=", FUNCPTR( MouseMoveEvent_SetX ), 1 ); + rb_define_method( globalMouseMoveEventClass, "x", MouseMoveEvent_GetX, 0 ); - rb_define_method( globalMouseMoveEventClass, "y", FUNCPTR( MouseMoveEvent_GetY ), 0 ); - rb_define_method( globalMouseMoveEventClass, "y=", FUNCPTR( MouseMoveEvent_SetY ), 1 ); + rb_define_method( globalMouseMoveEventClass, "y", MouseMoveEvent_GetY, 0 ); // MouseWheel methods - rb_define_method( globalMouseWheelEventClass, "delta", FUNCPTR( MouseWheelEvent_GetDelta ), 0 ); - rb_define_method( globalMouseWheelEventClass, "delta=", FUNCPTR( MouseWheelEvent_SetDelta ), 1 ); + rb_define_method( globalMouseWheelEventClass, "delta", MouseWheelEvent_GetDelta, 0 ); - rb_define_method( globalMouseWheelEventClass, "x", FUNCPTR( MouseWheelEvent_GetX ), 0 ); - rb_define_method( globalMouseWheelEventClass, "x=", FUNCPTR( MouseWheelEvent_SetX ), 1 ); + rb_define_method( globalMouseWheelEventClass, "x", MouseWheelEvent_GetX, 0 ); - rb_define_method( globalMouseWheelEventClass, "y", FUNCPTR( MouseWheelEvent_GetY ), 0 ); - rb_define_method( globalMouseWheelEventClass, "y=", FUNCPTR( MouseWheelEvent_SetY ), 1 ); + rb_define_method( globalMouseWheelEventClass, "y", MouseWheelEvent_GetY, 0 ); // Size methods - rb_define_method( globalSizeEventClass, "width", FUNCPTR( SizeEvent_GetWidth ), 0 ); - rb_define_method( globalSizeEventClass, "width=", FUNCPTR( SizeEvent_SetWidth ), 1 ); + rb_define_method( globalSizeEventClass, "width", SizeEvent_GetWidth, 0 ); - rb_define_method( globalSizeEventClass, "height", FUNCPTR( SizeEvent_GetWidth ), 0 ); - rb_define_method( globalSizeEventClass, "height=", FUNCPTR( SizeEvent_SetWidth ), 1 ); + rb_define_method( globalSizeEventClass, "height", SizeEvent_GetWidth, 0 ); // Text methods - rb_define_method( globalTextEventClass, "unicode", FUNCPTR( TextEvent_GetUnicode ), 0 ); - rb_define_method( globalTextEventClass, "unicode=", FUNCPTR( TextEvent_SetUnicode ), 1 ); + rb_define_method( globalTextEventClass, "unicode", TextEvent_GetUnicode, 0 ); } diff --git a/bindings/ruby/sfml-window/window/Input.cpp b/bindings/ruby/sfml-window/window/Input.cpp index 7409979ca..d21b519fa 100644 --- a/bindings/ruby/sfml-window/window/Input.cpp +++ b/bindings/ruby/sfml-window/window/Input.cpp @@ -24,36 +24,6 @@ #include "main.hpp" #include -/* SFML::Input provides a way to access the state of keys, mouse buttons, - * mouse position, joystick buttons and jostick axis. - * - * SFML::Input provides the same informations as the event system, but these - * informations can be accessed at any time, which is more convenient in many - * situations. - * - * For example, to move an entity you can decide to catch the - * SFML::Event::KeyPressed event on arrow keys. But if you do so, you will only - * receive one event when the key gets pressed (or repeated events if you - * activated this feature), thus the entity will not move smoothly. The best - * solution here is to use SFML::Input#isKeyDown so that you can update your - * entity's position at every iteration of your game loop, not only when you - * catch a KeyPressed event. - * - * Note that instances of SFML::Input cannot be created directly, they must be - * retrieved from a window (SFML::Window) with the SFML::Window#input method. - * - * Usage example: - * - * # Retrieve the input object attached to our window - * input = window.input - * - * # Move an entity according to the current keys state - * offset = 5.0 * window.frameTime # 5 pixels/sec - * entity.move( -offset, 0 ) if input.keyDown?( SFML::Key::Left ) - * entity.move( offset, 0 ) if input.keyDown?( SFML::Key::Right ) - * entity.move( 0, -offset ) if input.keyDown?( SFML::Key::Up ) - * entity.move( 0, offset ) if input.keyDown?( SFML::Key::Down ) - */ VALUE globalInputClass; /* Free a heap allocated object @@ -179,18 +149,46 @@ static VALUE Input_New( int argc, VALUE * args, VALUE aKlass ) void Init_Input( void ) { - globalInputClass = rb_define_class_under( GetNamespace(), "Input", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* The SFML::Input class provides a way to access the state of keys, mouse buttons, mouse position, joystick + * buttons and jostick axis. + * + * SFML::Input provides the same informations as the event system, but these informations can be accessed at any time, + * which is more convenient in many situations. + * + * For example, to move an entity you can decide to catch the SFML::Event::KeyPressed event on arrow keys. But if you + * do so, you will only receive one event when the key gets pressed (or repeated events if you activated this feature), + * thus the entity will not move smoothly. The best solution here is to use SFML::Input#isKeyDown so that you can + * update your entity's position at every iteration of your game loop, not only when you catch a KeyPressed event. + * + * Note that instances of SFML::Input cannot be created directly, they must be retrieved from a window (SFML::Window) + * with the SFML::Window#input method. + * + * Usage example: + * + * # Retrieve the input object attached to our window + * input = window.input + * + * # Move an entity according to the current keys state + * offset = 5.0 * window.frameTime # 5 pixels/sec + * entity.move( -offset, 0 ) if input.keyDown?( SFML::Key::Left ) + * entity.move( offset, 0 ) if input.keyDown?( SFML::Key::Right ) + * entity.move( 0, -offset ) if input.keyDown?( SFML::Key::Up ) + * entity.move( 0, offset ) if input.keyDown?( SFML::Key::Down ) + */ + globalInputClass = rb_define_class_under( sfml, "Input", rb_cObject ); // Class methods - rb_define_singleton_method( globalInputClass, "new", FUNCPTR( Input_New ), -1 ); + rb_define_singleton_method( globalInputClass, "new", Input_New, -1 ); // Instance methods - rb_define_method( globalInputClass, "isKeyDown", FUNCPTR( Input_IsKeyDown ), 1 ); - rb_define_method( globalInputClass, "isMouseButtonDown", FUNCPTR( Input_IsMouseButtonDown ), 1 ); - rb_define_method( globalInputClass, "isJoystickButtonDown", FUNCPTR( Input_IsJoystickButtonDown ), 2 ); - rb_define_method( globalInputClass, "getMouseX", FUNCPTR( Input_GetMouseX ), 0 ); - rb_define_method( globalInputClass, "getMouseY", FUNCPTR( Input_GetMouseY ), 0 ); - rb_define_method( globalInputClass, "getJoystickAxis", FUNCPTR( Input_GetJoystickAxis ), 2 ); + rb_define_method( globalInputClass, "isKeyDown", Input_IsKeyDown, 1 ); + rb_define_method( globalInputClass, "isMouseButtonDown", Input_IsMouseButtonDown, 1 ); + rb_define_method( globalInputClass, "isJoystickButtonDown", Input_IsJoystickButtonDown, 2 ); + rb_define_method( globalInputClass, "getMouseX", Input_GetMouseX, 0 ); + rb_define_method( globalInputClass, "getMouseY", Input_GetMouseY, 0 ); + rb_define_method( globalInputClass, "getJoystickAxis", Input_GetJoystickAxis, 2 ); // Aliases rb_define_alias( globalInputClass, "key_down?", "isKeyDown"); diff --git a/bindings/ruby/sfml-window/window/VideoMode.cpp b/bindings/ruby/sfml-window/window/VideoMode.cpp index 6a4be0c19..9fcd05f88 100644 --- a/bindings/ruby/sfml-window/window/VideoMode.cpp +++ b/bindings/ruby/sfml-window/window/VideoMode.cpp @@ -25,36 +25,6 @@ #include #include -/* A video mode is defined by a width and a height (in pixels) and a depth (in bits per pixel). - * - * Video modes are used to setup windows (SFML::Window) at creation time. - * - * The main usage of video modes is for fullscreen mode: indeed you must use one of the valid - * video modes allowed by the OS (which are defined by what the monitor and the graphics card support), - * otherwise your window creation will just fail. - * - * SFML::VideoMode provides a static function for retrieving the list of all the video modes supported by - * the system: getFullscreenModes(). - * - * A custom video mode can also be checked directly for fullscreen compatibility with its isValid() function. - * - * Additionnally, SFML::VideoMode provides a static function to get the mode currently used by the desktop: - * getDesktopMode(). This allows to build windows with the same size or pixel depth as the current resolution. - * - * Usage example: - * - * # Display the list of all the video modes available for fullscreen - * modes = SFML::VideoMode.getFullscreenModes() - * i = 0 - * modes.each do | mode | - * puts "Mode #" + i + ": " + mode.width + "x" + mode.height + " - " + mode.bitsPerPixel + " bpp" - * - * end - * - * # Create a window with the same pixel depth as the desktop - * desktop = SFML::VideoMode.getDesktopMode() - * window.create( SFML::VideoMode.new( 1024, 768, desktop.BitsPerPixel ), "SFML window" ) - */ VALUE globalVideoModeClass; /* Internal function @@ -236,22 +206,54 @@ static VALUE VideoMode_New( int argc, VALUE *args, VALUE aKlass ) void Init_VideoMode( void ) { - globalVideoModeClass = rb_define_class_under( GetNamespace(), "VideoMode", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* A video mode is defined by a width and a height (in pixels) and a depth (in bits per pixel). + * + * Video modes are used to setup windows (SFML::Window) at creation time. + * + * The main usage of video modes is for fullscreen mode: indeed you must use one of the valid + * video modes allowed by the OS (which are defined by what the monitor and the graphics card support), + * otherwise your window creation will just fail. + * + * SFML::VideoMode provides a static function for retrieving the list of all the video modes supported by + * the system: getFullscreenModes(). + * + * A custom video mode can also be checked directly for fullscreen compatibility with its isValid() function. + * + * Additionnally, SFML::VideoMode provides a static function to get the mode currently used by the desktop: + * getDesktopMode(). This allows to build windows with the same size or pixel depth as the current resolution. + * + * Usage example: + * + * # Display the list of all the video modes available for fullscreen + * modes = SFML::VideoMode.getFullscreenModes() + * i = 0 + * modes.each do | mode | + * puts "Mode #" + i + ": " + mode.width + "x" + mode.height + " - " + mode.bitsPerPixel + " bpp" + * + * end + * + * # Create a window with the same pixel depth as the desktop + * desktop = SFML::VideoMode.getDesktopMode() + * window.create( SFML::VideoMode.new( 1024, 768, desktop.BitsPerPixel ), "SFML window" ) + */ + globalVideoModeClass = rb_define_class_under( sfml, "VideoMode", rb_cObject ); // Class methods - rb_define_singleton_method( globalVideoModeClass, "new", FUNCPTR( VideoMode_New ), -1 ); - rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", FUNCPTR( VideoMode_GetDesktopMode ), 0 ); - rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", FUNCPTR( VideoMode_GetFullscreenModes ), 0 ); + rb_define_singleton_method( globalVideoModeClass, "new", VideoMode_New, -1 ); + rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", VideoMode_GetDesktopMode, 0 ); + rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", VideoMode_GetFullscreenModes, 0 ); // Instance methods - rb_define_method( globalVideoModeClass, "width", FUNCPTR( VideoMode_GetWidth ), 0 ); - rb_define_method( globalVideoModeClass, "width=", FUNCPTR( VideoMode_SetWidth ), 1 ); + rb_define_method( globalVideoModeClass, "width", VideoMode_GetWidth, 0 ); + rb_define_method( globalVideoModeClass, "width=", VideoMode_SetWidth, 1 ); - rb_define_method( globalVideoModeClass, "height", FUNCPTR( VideoMode_GetWidth ), 0 ); - rb_define_method( globalVideoModeClass, "height=", FUNCPTR( VideoMode_SetWidth ), 1 ); + rb_define_method( globalVideoModeClass, "height", VideoMode_GetWidth, 0 ); + rb_define_method( globalVideoModeClass, "height=", VideoMode_SetWidth, 1 ); - rb_define_method( globalVideoModeClass, "bitsPerPixel", FUNCPTR( VideoMode_GetBitsPerPixel ), 0 ); - rb_define_method( globalVideoModeClass, "bitsPerPixel=", FUNCPTR( VideoMode_SetBitsPerPixel ), 1 ); + rb_define_method( globalVideoModeClass, "bitsPerPixel", VideoMode_GetBitsPerPixel, 0 ); + rb_define_method( globalVideoModeClass, "bitsPerPixel=", VideoMode_SetBitsPerPixel, 1 ); // Class aliases rb_define_alias( CLASS_OF( globalVideoModeClass ), "desktopMode", "getDesktopMode" ); diff --git a/bindings/ruby/sfml-window/window/Window.cpp b/bindings/ruby/sfml-window/window/Window.cpp index 2fbe26781..043a7049f 100644 --- a/bindings/ruby/sfml-window/window/Window.cpp +++ b/bindings/ruby/sfml-window/window/Window.cpp @@ -26,50 +26,6 @@ #include "Vector2.hpp" #include "main.hpp" -/* SFML::Window is the main class of the Window module. - * - * It defines an OS window that is able to receive an OpenGL rendering. - * - * A SFML::Window can create its own new window, but using an already created window trough a handle is not supported - * in the ruby bindings yet. - * - * The SFML::Window class provides a simple interface for manipulating the window: move, resize, show/hide, control mouse - * cursor, etc. It also provides event handling through its getEvent() function, and real-time state handling with its - * attached SFML::Input object (see getInput()). - * - * Note that OpenGL experts can pass their own parameters (antialiasing level, bits for the depth and stencil buffers, - * etc.) to the OpenGL context attached to the window, with the SFML::ContextSettings structure which is passed as an - * optional argument when creating the window. - * - * Usage example: - * - * # Declare and create a new window - * window = SFML::Window.new( SFML::VideoMode.new( 800, 600 ), "SFML window" ) - * - * # Limit the framerate to 60 frames per second (this step is optional) - * window.setFramerateLimit( 60 ); - * - * # The main loop - ends as soon as the window is closed - * while window.open? - * - * # Event processing - * while event = window.getEvent - * - * # Request for closing the window - * if event.type == SFML::Event::Closed - * window.close() - * end - * end - * - * # Activate the window for OpenGL rendering - * window.setActive() - * - * # OpenGL drawing commands go here... - * - * # End the current frame and display its contents on screen - * window.display() - * end - */ VALUE globalWindowClass; extern VALUE globalVideoModeClass; extern VALUE globalContextSettingsClass; @@ -109,7 +65,7 @@ static VALUE Window_Close( VALUE self ) } /* call-seq: - * window.Create( mode, title, style = SFML::Style::Default, settings = SFML::ContextSettings.new ) + * window.create( mode, title, style = SFML::Style::Default, settings = SFML::ContextSettings.new ) * * Create (or recreate) the window. * @@ -703,38 +659,84 @@ static VALUE Window_New( int argc, VALUE *args, VALUE aKlass ) void Init_Window( void ) { - globalWindowClass = rb_define_class_under( GetNamespace(), "Window", rb_cObject ); +/* SFML namespace which contains the classes of this module. */ + VALUE sfml = rb_define_module( "SFML" ); +/* SFML::Window is the main class of the Window module. + * + * It defines an OS window that is able to receive an OpenGL rendering. + * + * A SFML::Window can create its own new window, but using an already created window trough a handle is not supported + * in the ruby bindings yet. + * + * The SFML::Window class provides a simple interface for manipulating the window: move, resize, show/hide, control mouse + * cursor, etc. It also provides event handling through its getEvent() function, and real-time state handling with its + * attached SFML::Input object (see getInput()). + * + * Note that OpenGL experts can pass their own parameters (antialiasing level, bits for the depth and stencil buffers, + * etc.) to the OpenGL context attached to the window, with the SFML::ContextSettings structure which is passed as an + * optional argument when creating the window. + * + * Usage example: + * + * # Declare and create a new window + * window = SFML::Window.new( SFML::VideoMode.new( 800, 600 ), "SFML window" ) + * + * # Limit the framerate to 60 frames per second (this step is optional) + * window.setFramerateLimit( 60 ); + * + * # The main loop - ends as soon as the window is closed + * while window.open? + * + * # Event processing + * while event = window.getEvent + * + * # Request for closing the window + * if event.type == SFML::Event::Closed + * window.close() + * end + * end + * + * # Activate the window for OpenGL rendering + * window.setActive() + * + * # OpenGL drawing commands go here... + * + * # End the current frame and display its contents on screen + * window.display() + * end + */ + globalWindowClass = rb_define_class_under( sfml, "Window", rb_cObject ); // Class methods - rb_define_singleton_method( globalWindowClass, "new", FUNCPTR( Window_New ), -1 ); + rb_define_singleton_method( globalWindowClass, "new", Window_New , -1 ); // Instance methods - rb_define_method( globalWindowClass, "close", FUNCPTR( Window_Close ), 0 ); - rb_define_method( globalWindowClass, "create", FUNCPTR( Window_Create ), -1 ); - rb_define_method( globalWindowClass, "display", FUNCPTR( Window_Display ), 0 ); - rb_define_method( globalWindowClass, "enableKeyRepeat", FUNCPTR( Window_EnableKeyRepeat ), 1 ); - rb_define_method( globalWindowClass, "getEvent", FUNCPTR( Window_GetEvent ), 0 ); - rb_define_method( globalWindowClass, "getFrameTime", FUNCPTR( Window_GetFrameTime ), 0 ); - rb_define_method( globalWindowClass, "getHeight", FUNCPTR( Window_GetHeight ), 0 ); - rb_define_method( globalWindowClass, "getInput", FUNCPTR( Window_GetInput ), 0 ); - rb_define_method( globalWindowClass, "getSettings", FUNCPTR( Window_GetSettings ), 0 ); - rb_define_method( globalWindowClass, "getWidth", FUNCPTR( Window_GetWidth ), 0 ); - rb_define_method( globalWindowClass, "isOpened", FUNCPTR( Window_IsOpened ), 0 ); - rb_define_method( globalWindowClass, "setActive", FUNCPTR( Window_SetActive ), 1 ); - rb_define_method( globalWindowClass, "setCursorPosition", FUNCPTR( Window_SetCursorPosition ), 2 ); - rb_define_method( globalWindowClass, "cursorPosition=", FUNCPTR( Window_SetCursorPosition2 ), 1 ); - rb_define_method( globalWindowClass, "setFramerateLimit", FUNCPTR( Window_SetFramerateLimit ), 1 ); - rb_define_method( globalWindowClass, "setIcon", FUNCPTR( Window_SetIcon ), 3 ); - rb_define_method( globalWindowClass, "setJoystickThreshold", FUNCPTR( Window_SetJoystickThreshold ), 1 ); - rb_define_method( globalWindowClass, "setPosition", FUNCPTR( Window_SetPosition ), 2 ); - rb_define_method( globalWindowClass, "position=", FUNCPTR( Window_SetPosition2 ), 1 ); - rb_define_method( globalWindowClass, "setSize", FUNCPTR( Window_SetSize ), 2 ); - rb_define_method( globalWindowClass, "size=", FUNCPTR( Window_SetSize2 ), 1 ); - rb_define_method( globalWindowClass, "setTitle", FUNCPTR( Window_SetTitle ), 1 ); - rb_define_method( globalWindowClass, "show", FUNCPTR( Window_Show ), 1 ); - rb_define_method( globalWindowClass, "showMouseCursor", FUNCPTR( Window_ShowMouseCursor ), 1 ); - rb_define_method( globalWindowClass, "useVerticalSync", FUNCPTR( Window_UseVerticalSync ), 1 ); - rb_define_method( globalWindowClass, "waitEvent", FUNCPTR( Window_WaitEvent ), 0 ); + rb_define_method( globalWindowClass, "close", Window_Close, 0 ); + rb_define_method( globalWindowClass, "create", Window_Create, -1 ); + rb_define_method( globalWindowClass, "display", Window_Display, 0 ); + rb_define_method( globalWindowClass, "enableKeyRepeat", Window_EnableKeyRepeat, 1 ); + rb_define_method( globalWindowClass, "getEvent", Window_GetEvent, 0 ); + rb_define_method( globalWindowClass, "getFrameTime", Window_GetFrameTime , 0 ); + rb_define_method( globalWindowClass, "getHeight", Window_GetHeight, 0 ); + rb_define_method( globalWindowClass, "getInput", Window_GetInput, 0 ); + rb_define_method( globalWindowClass, "getSettings", Window_GetSettings, 0 ); + rb_define_method( globalWindowClass, "getWidth", Window_GetWidth, 0 ); + rb_define_method( globalWindowClass, "isOpened", Window_IsOpened, 0 ); + rb_define_method( globalWindowClass, "setActive", Window_SetActive, 1 ); + rb_define_method( globalWindowClass, "setCursorPosition", Window_SetCursorPosition, 2 ); + rb_define_method( globalWindowClass, "cursorPosition=", Window_SetCursorPosition2, 1 ); + rb_define_method( globalWindowClass, "setFramerateLimit", Window_SetFramerateLimit, 1 ); + rb_define_method( globalWindowClass, "setIcon", Window_SetIcon, 3 ); + rb_define_method( globalWindowClass, "setJoystickThreshold", Window_SetJoystickThreshold, 1 ); + rb_define_method( globalWindowClass, "setPosition", Window_SetPosition, 2 ); + rb_define_method( globalWindowClass, "position=", Window_SetPosition2, 1 ); + rb_define_method( globalWindowClass, "setSize", Window_SetSize, 2 ); + rb_define_method( globalWindowClass, "size=", Window_SetSize2, 1 ); + rb_define_method( globalWindowClass, "setTitle", Window_SetTitle, 1 ); + rb_define_method( globalWindowClass, "show", Window_Show, 1 ); + rb_define_method( globalWindowClass, "showMouseCursor", Window_ShowMouseCursor, 1 ); + rb_define_method( globalWindowClass, "useVerticalSync", Window_UseVerticalSync, 1 ); + rb_define_method( globalWindowClass, "waitEvent", Window_WaitEvent, 0 ); // Aliases rb_define_alias( globalWindowClass, "keyRepeat=", "enableKeyRepeat" ); diff --git a/bindings/ruby/sfml-window/window/main.cpp b/bindings/ruby/sfml-window/window/main.cpp index eba1f63c2..e2de8961b 100644 --- a/bindings/ruby/sfml-window/window/main.cpp +++ b/bindings/ruby/sfml-window/window/main.cpp @@ -32,6 +32,7 @@ #include +/* SFML Namespace which contains all classes in this module. */ VALUE globalSFMLNamespace; VALUE globalKeyNamespace; VALUE globalMouseNamespace; @@ -46,17 +47,6 @@ VALUE GetNamespace( void ) return globalSFMLNamespace; } -static const char * keyNamesLetters[] = -{ - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", - "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" -}; - -static const char * keyNamesNum[] = -{ - "Num0", "Num1", "Num2", "Num3", "Num4", "Num5", "Num6", "Num7", "Num8", "Num9" -}; - static const char * keyNamesMisc[] = { "Escape", "LControl", "LShift", "LAlt", "LSystem", "RControl", "RShift", "RAlt", "RSystem", @@ -69,29 +59,49 @@ static const char * keyNamesMisc[] = "Count" }; -static const char * mouseNames[] = -{ - "Left", "Right", "Middle", "XButton1", "XButton2", "ButtonCount" -}; - -static const char * axisNames[] = -{ - "AxisX", "AxisY", "AxisZ", "AxisR", "AxisU", "AxisV", "AxisPOV", - "AxisCount" -}; - +/* Definition of key codes for keyboard events. + * + * All SFML::Key constants exists, I just haven't written them all so Rdoc can interpret them yet. + */ void CreateKeyEnum( void ) { globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" ); - for( int index = static_cast< int >( sf::Key::A ); index <= sf::Key::Z; index++ ) - { - rb_define_const( globalKeyNamespace, keyNamesLetters[ index - sf::Key::A ], INT2FIX( index ) ); - } + rb_define_const( globalKeyNamespace, "A", INT2FIX( sf::Key::A ) ); + rb_define_const( globalKeyNamespace, "B", INT2FIX( sf::Key::B ) ); + rb_define_const( globalKeyNamespace, "C", INT2FIX( sf::Key::C ) ); + rb_define_const( globalKeyNamespace, "D", INT2FIX( sf::Key::D ) ); + rb_define_const( globalKeyNamespace, "E", INT2FIX( sf::Key::E ) ); + rb_define_const( globalKeyNamespace, "F", INT2FIX( sf::Key::F ) ); + rb_define_const( globalKeyNamespace, "G", INT2FIX( sf::Key::G ) ); + rb_define_const( globalKeyNamespace, "H", INT2FIX( sf::Key::H ) ); + rb_define_const( globalKeyNamespace, "I", INT2FIX( sf::Key::I ) ); + rb_define_const( globalKeyNamespace, "J", INT2FIX( sf::Key::J ) ); + rb_define_const( globalKeyNamespace, "K", INT2FIX( sf::Key::K ) ); + rb_define_const( globalKeyNamespace, "L", INT2FIX( sf::Key::L ) ); + rb_define_const( globalKeyNamespace, "M", INT2FIX( sf::Key::M ) ); + rb_define_const( globalKeyNamespace, "N", INT2FIX( sf::Key::N ) ); + rb_define_const( globalKeyNamespace, "O", INT2FIX( sf::Key::O ) ); + rb_define_const( globalKeyNamespace, "P", INT2FIX( sf::Key::P ) ); + rb_define_const( globalKeyNamespace, "Q", INT2FIX( sf::Key::Q ) ); + rb_define_const( globalKeyNamespace, "R", INT2FIX( sf::Key::R ) ); + rb_define_const( globalKeyNamespace, "S", INT2FIX( sf::Key::S ) ); + rb_define_const( globalKeyNamespace, "T", INT2FIX( sf::Key::T ) ); + rb_define_const( globalKeyNamespace, "U", INT2FIX( sf::Key::U ) ); + rb_define_const( globalKeyNamespace, "V", INT2FIX( sf::Key::V ) ); + rb_define_const( globalKeyNamespace, "X", INT2FIX( sf::Key::X ) ); + rb_define_const( globalKeyNamespace, "Y", INT2FIX( sf::Key::Y ) ); + rb_define_const( globalKeyNamespace, "Z", INT2FIX( sf::Key::Z ) ); - for( int index = static_cast< int >( sf::Key::Num0 ); index <= sf::Key::Num9; index++ ) - { - rb_define_const( globalKeyNamespace, keyNamesNum[ index - sf::Key::Num0 ], INT2FIX( index ) ); - } + rb_define_const( globalKeyNamespace, "Num0", INT2FIX( sf::Key::Num0 ) ); + rb_define_const( globalKeyNamespace, "Num1", INT2FIX( sf::Key::Num1 ) ); + rb_define_const( globalKeyNamespace, "Num2", INT2FIX( sf::Key::Num2 ) ); + rb_define_const( globalKeyNamespace, "Num3", INT2FIX( sf::Key::Num3 ) ); + rb_define_const( globalKeyNamespace, "Num4", INT2FIX( sf::Key::Num4 ) ); + rb_define_const( globalKeyNamespace, "Num5", INT2FIX( sf::Key::Num5 ) ); + rb_define_const( globalKeyNamespace, "Num6", INT2FIX( sf::Key::Num6 ) ); + rb_define_const( globalKeyNamespace, "Num7", INT2FIX( sf::Key::Num7 ) ); + rb_define_const( globalKeyNamespace, "Num8", INT2FIX( sf::Key::Num8 ) ); + rb_define_const( globalKeyNamespace, "Num9", INT2FIX( sf::Key::Num9 ) ); for( int index = static_cast< int >( sf::Key::Escape ); index <= sf::Key::Count; index++ ) { @@ -99,33 +109,42 @@ void CreateKeyEnum( void ) } } +/* Definition of button codes for mouse events. */ void CreateMouseEnum( void ) { globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" ); - for( int index = static_cast< int >( sf::Mouse::Left ); index <= sf::Mouse::ButtonCount; index++ ) - { - rb_define_const( globalMouseNamespace, mouseNames[ index - sf::Mouse::Left ], INT2FIX( index ) ); - } + rb_define_const( globalMouseNamespace, "Left", INT2FIX( sf::Mouse::Left ) ); + rb_define_const( globalMouseNamespace, "Right", INT2FIX( sf::Mouse::Right ) ); + rb_define_const( globalMouseNamespace, "Middle", INT2FIX( sf::Mouse::Middle ) ); + rb_define_const( globalMouseNamespace, "XButton1", INT2FIX( sf::Mouse::XButton1 ) ); + rb_define_const( globalMouseNamespace, "XButton2", INT2FIX( sf::Mouse::XButton2 ) ); + rb_define_const( globalMouseNamespace, "ButtonCount", INT2FIX( sf::Mouse::ButtonCount ) ); } +/* Definition of joystick axis for joystick events. */ void CreateJoyEnum( void ) { globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" ); - for( int index = static_cast< int >( sf::Joy::AxisX ); index <= sf::Joy::AxisCount; index++ ) - { - rb_define_const( globalJoyNamespace, axisNames[ index - sf::Joy::AxisX ], INT2FIX( index ) ); - } + rb_define_const( globalJoyNamespace, "AxisX", INT2FIX( sf::Joy::AxisX ) ); + rb_define_const( globalJoyNamespace, "AxisY", INT2FIX( sf::Joy::AxisY ) ); + rb_define_const( globalJoyNamespace, "AxisZ", INT2FIX( sf::Joy::AxisZ ) ); + rb_define_const( globalJoyNamespace, "AxisR", INT2FIX( sf::Joy::AxisR ) ); + rb_define_const( globalJoyNamespace, "AxisU", INT2FIX( sf::Joy::AxisU ) ); + rb_define_const( globalJoyNamespace, "AxisV", INT2FIX( sf::Joy::AxisV ) ); + rb_define_const( globalJoyNamespace, "AxisPOV", INT2FIX( sf::Joy::AxisPOV ) ); + rb_define_const( globalJoyNamespace, "AxisCount", INT2FIX( sf::Joy::AxisCount ) ); } +/* Enumeration of the window styles. */ void CreateStyleEnum( void ) { globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" ); - rb_define_const( globalStyleNamespace, "None", sf::Style::None ); - rb_define_const( globalStyleNamespace, "Titlebar", sf::Style::Titlebar ); - rb_define_const( globalStyleNamespace, "Resize", sf::Style::Resize ); - rb_define_const( globalStyleNamespace, "Close", sf::Style::Close ); - rb_define_const( globalStyleNamespace, "Fullscreen", sf::Style::Fullscreen ); - rb_define_const( globalStyleNamespace, "Default", sf::Style::Default ); + rb_define_const( globalStyleNamespace, "None", INT2FIX( sf::Style::None ) ); + rb_define_const( globalStyleNamespace, "Titlebar", INT2FIX( sf::Style::Titlebar ) ); + rb_define_const( globalStyleNamespace, "Resize", INT2FIX( sf::Style::Resize ) ); + rb_define_const( globalStyleNamespace, "Close", INT2FIX( sf::Style::Close ) ); + rb_define_const( globalStyleNamespace, "Fullscreen", INT2FIX( sf::Style::Fullscreen ) ); + rb_define_const( globalStyleNamespace, "Default", INT2FIX( sf::Style::Default ) ); } bool CheckDependencies( void ) @@ -156,6 +175,7 @@ void RetrieveVector2Class( void ) void Init_window( void ) { + /* SFML namespace which contains the classes of this module. */ globalSFMLNamespace = rb_define_module( "SFML" ); if( CheckDependencies() == false ) { diff --git a/bindings/ruby/sfml-window/window/main.hpp b/bindings/ruby/sfml-window/window/main.hpp index db953c87d..5094cf8ce 100644 --- a/bindings/ruby/sfml-window/window/main.hpp +++ b/bindings/ruby/sfml-window/window/main.hpp @@ -34,6 +34,7 @@ extern "C" void Init_window( void ); typedef VALUE ( *RubyFunctionPtr )( ... ); -#define FUNCPTR( x ) ( reinterpret_cast< RubyFunctionPtr >( x ) ) +#define rb_define_singleton_method( klass, name, func, argc, ... ) rb_define_singleton_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) +#define rb_define_method( klass, name, func, argc, ... ) rb_define_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) #endif // SFML_RUBYEXT_MAIN_HEADER_