mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
Modified the entire module so that rdoc can interpret the source to generate documentation for me. This will also be done for sfml-system.
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1657 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
f8bfec9321
commit
13e9b006e7
@ -24,20 +24,6 @@
|
|||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include <SFML/Window/Context.hpp>
|
#include <SFML/Window/Context.hpp>
|
||||||
|
|
||||||
/* 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;
|
VALUE globalContextClass;
|
||||||
|
|
||||||
/* Free a heap allocated object
|
/* Free a heap allocated object
|
||||||
@ -105,14 +91,31 @@ static VALUE Context_New( VALUE aKlass )
|
|||||||
|
|
||||||
void Init_Context( void )
|
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
|
// Class methods
|
||||||
rb_define_singleton_method( globalContextClass, "new", FUNCPTR( Context_New ), 0 );
|
rb_define_singleton_method( globalContextClass, "new", Context_New, 0 );
|
||||||
rb_define_singleton_method( globalContextClass, "setReferenceActive", FUNCPTR( Context_SetReferenceActive ), 0 );
|
rb_define_singleton_method( globalContextClass, "setReferenceActive", Context_SetReferenceActive, 0 );
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
rb_define_method( globalContextClass, "setActive", FUNCPTR( Context_SetActive ), 1 );
|
rb_define_method( globalContextClass, "setActive", Context_SetActive, 1 );
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
rb_define_alias( globalContextClass, "active=", "setActive" );
|
rb_define_alias( globalContextClass, "active=", "setActive" );
|
||||||
|
@ -25,31 +25,7 @@
|
|||||||
#include <SFML/Window/ContextSettings.hpp>
|
#include <SFML/Window/ContextSettings.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
/* 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;
|
VALUE globalContextSettingsClass;
|
||||||
|
|
||||||
/* Free a heap allocated object
|
/* Free a heap allocated object
|
||||||
@ -242,26 +218,53 @@ static VALUE ContextSettings_New( VALUE aKlass, VALUE someArgs )
|
|||||||
|
|
||||||
void Init_ContextSettings( void )
|
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
|
// Class methods
|
||||||
rb_define_singleton_method( globalContextSettingsClass, "new", FUNCPTR( ContextSettings_New ), -2 );
|
rb_define_singleton_method( globalContextSettingsClass, "new", ContextSettings_New, -2 );
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
rb_define_method( globalContextSettingsClass, "depthBits", FUNCPTR( ContextSettings_GetDepth ), 0 );
|
rb_define_method( globalContextSettingsClass, "depthBits", ContextSettings_GetDepth, 0 );
|
||||||
rb_define_method( globalContextSettingsClass, "depthBits=", FUNCPTR( ContextSettings_SetDepth ), 1 );
|
rb_define_method( globalContextSettingsClass, "depthBits=", ContextSettings_SetDepth, 1 );
|
||||||
|
|
||||||
rb_define_method( globalContextSettingsClass, "stencilBits", FUNCPTR( ContextSettings_GetStencil ), 0 );
|
rb_define_method( globalContextSettingsClass, "stencilBits", ContextSettings_GetStencil, 0 );
|
||||||
rb_define_method( globalContextSettingsClass, "stencilBits=", FUNCPTR( ContextSettings_SetStencil ), 1 );
|
rb_define_method( globalContextSettingsClass, "stencilBits=", ContextSettings_SetStencil, 1 );
|
||||||
|
|
||||||
rb_define_method( globalContextSettingsClass, "antialiasingLevel", FUNCPTR( ContextSettings_GetAntialiasing ), 0 );
|
rb_define_method( globalContextSettingsClass, "antialiasingLevel", ContextSettings_GetAntialiasing, 0 );
|
||||||
rb_define_method( globalContextSettingsClass, "antialiasingLevel=", FUNCPTR( ContextSettings_SetAntialiasing ), 1 );
|
rb_define_method( globalContextSettingsClass, "antialiasingLevel=", ContextSettings_SetAntialiasing, 1 );
|
||||||
|
|
||||||
rb_define_method( globalContextSettingsClass, "majorVersion", FUNCPTR( ContextSettings_GetMajorVersion ), 0 );
|
rb_define_method( globalContextSettingsClass, "majorVersion", ContextSettings_GetMajorVersion, 0 );
|
||||||
rb_define_method( globalContextSettingsClass, "majorVersion=", FUNCPTR( ContextSettings_SetMajorVersion ), 1 );
|
rb_define_method( globalContextSettingsClass, "majorVersion=", ContextSettings_SetMajorVersion, 1 );
|
||||||
|
|
||||||
rb_define_method( globalContextSettingsClass, "minorVersion", FUNCPTR( ContextSettings_GetMinorVersion ), 0 );
|
rb_define_method( globalContextSettingsClass, "minorVersion", ContextSettings_GetMinorVersion, 0 );
|
||||||
rb_define_method( globalContextSettingsClass, "minorVersion=", FUNCPTR( ContextSettings_SetMinorVersion ), 1 );
|
rb_define_method( globalContextSettingsClass, "minorVersion=", ContextSettings_SetMinorVersion, 1 );
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
rb_define_alias( globalContextSettingsClass, "depth", "depthBits" );
|
rb_define_alias( globalContextSettingsClass, "depth", "depthBits" );
|
||||||
|
@ -24,40 +24,6 @@
|
|||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Event.hpp>
|
||||||
|
|
||||||
/* 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;
|
VALUE globalEventClass;
|
||||||
|
|
||||||
/* Joystick buttons events parameters (JoyButtonPressed, JoyButtonReleased). */
|
/* 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 MOUSE2NUM( x ) INT2NUM( static_cast< int > ( x ) )
|
||||||
#define NUM2MOUSE( x ) static_cast< sf::Mouse::Button >( NUM2INT( x ) )
|
#define NUM2MOUSE( x ) static_cast< sf::Mouse::Button >( NUM2INT( x ) )
|
||||||
|
|
||||||
#define EVENT_TYPE_ACCESSORS( a, b, conv1, conv2 ) \
|
#define EVENT_TYPE_ACCESSORS( a, b, conv1 ) \
|
||||||
static VALUE a##Event_Get##b ( VALUE self ) \
|
|
||||||
{ \
|
{ \
|
||||||
sf::Event:: a##Event * object = NULL; \
|
sf::Event:: a##Event * object = NULL; \
|
||||||
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
||||||
return conv1 ( object-> b ); \
|
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 ) \
|
#define EVENT_TYPE_BOOL_ACCESSORS( a, b ) \
|
||||||
static VALUE a##Event_Get##b ( VALUE self ) \
|
|
||||||
{ \
|
{ \
|
||||||
sf::Event:: a##Event * object = NULL; \
|
sf::Event:: a##Event * object = NULL; \
|
||||||
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
Data_Get_Struct( self, sf::Event:: a##Event, object ); \
|
||||||
@ -118,47 +75,77 @@ static VALUE a##Event_Get##b ( VALUE self ) \
|
|||||||
return Qtrue; \
|
return Qtrue; \
|
||||||
else \
|
else \
|
||||||
return Qfalse; \
|
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 );
|
/* Index of the joystick (0 or 1). */
|
||||||
EVENT_TYPE_ACCESSORS( JoyButton, Button, INT2NUM, NUM2UINT );
|
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 );
|
/* Index of the joystick (0 or 1). */
|
||||||
EVENT_TYPE_ACCESSORS( JoyMove, Axis, AXIS2NUM, NUM2AXIS );
|
static VALUE JoyMoveEvent_GetJoystickId( VALUE self )
|
||||||
EVENT_TYPE_ACCESSORS( JoyMove, Position, rb_float_new, NUM2DBL );
|
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 );
|
/* Code of the key that has been pressed. */
|
||||||
EVENT_TYPE_BOOL_ACCESSORS( Key, Alt );
|
static VALUE KeyEvent_GetCode( VALUE self )
|
||||||
EVENT_TYPE_BOOL_ACCESSORS( Key, Control );
|
EVENT_TYPE_ACCESSORS( Key, Code, KEY2NUM )
|
||||||
EVENT_TYPE_BOOL_ACCESSORS( Key, Shift );
|
/* 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 );
|
/* Code of the button that has been pressed. */
|
||||||
EVENT_TYPE_ACCESSORS( MouseButton, X, INT2NUM, NUM2INT );
|
static VALUE MouseButtonEvent_GetButton( VALUE self )
|
||||||
EVENT_TYPE_ACCESSORS( MouseButton, Y, INT2NUM, NUM2INT );
|
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 );
|
/* X position of the mouse pointer, relative to the left of the owner window */
|
||||||
EVENT_TYPE_ACCESSORS( MouseMove, Y, INT2NUM, NUM2INT );
|
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 );
|
/* Number of ticks the wheel has moved (positive is up, negative is down). */
|
||||||
EVENT_TYPE_ACCESSORS( MouseWheel, X, INT2NUM, NUM2INT );
|
static VALUE MouseWheelEvent_GetDelta( VALUE self )
|
||||||
EVENT_TYPE_ACCESSORS( MouseWheel, Y, INT2NUM, NUM2INT );
|
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 );
|
/* New width, in pixels. */
|
||||||
EVENT_TYPE_ACCESSORS( Size, Height, INT2NUM, NUM2UINT );
|
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 )
|
static VALUE Event_Initialize( VALUE self, VALUE aType )
|
||||||
{
|
{
|
||||||
sf::Event * object = NULL;
|
sf::Event * object = NULL;
|
||||||
@ -243,9 +230,46 @@ static VALUE Event_New( int argc, VALUE * args, VALUE aKlass )
|
|||||||
return rbData;
|
return rbData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Init_Event( void )
|
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 );
|
globalJoyButtonEventClass = rb_define_class_under( globalEventClass, "JoyButton", rb_cObject );
|
||||||
globalJoyMoveEventClass = rb_define_class_under( globalEventClass, "JoyMove", rb_cObject );
|
globalJoyMoveEventClass = rb_define_class_under( globalEventClass, "JoyMove", rb_cObject );
|
||||||
globalKeyEventClass = rb_define_class_under( globalEventClass, "Key", 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 );
|
globalSizeEventClass = rb_define_class_under( globalEventClass, "Size", rb_cObject );
|
||||||
globalTextEventClass = rb_define_class_under( globalEventClass, "Text", 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, "Closed", INT2NUM( sf::Event::Closed ) );
|
||||||
rb_define_const( globalEventClass, "Resized", INT2NUM( static_cast< int >( sf::Event::Resized ) ) );
|
rb_define_const( globalEventClass, "Resized", INT2NUM( sf::Event::Resized ) );
|
||||||
rb_define_const( globalEventClass, "LostFocus", INT2NUM( static_cast< int >( sf::Event::LostFocus ) ) );
|
rb_define_const( globalEventClass, "LostFocus", INT2NUM( sf::Event::LostFocus ) );
|
||||||
rb_define_const( globalEventClass, "GainedFocus", INT2NUM( static_cast< int >( sf::Event::GainedFocus ) ) );
|
rb_define_const( globalEventClass, "GainedFocus", INT2NUM( sf::Event::GainedFocus ) );
|
||||||
rb_define_const( globalEventClass, "TextEntered", INT2NUM( static_cast< int >( sf::Event::TextEntered ) ) );
|
rb_define_const( globalEventClass, "TextEntered", INT2NUM( sf::Event::TextEntered ) );
|
||||||
rb_define_const( globalEventClass, "KeyPressed", INT2NUM( static_cast< int >( sf::Event::KeyPressed ) ) );
|
rb_define_const( globalEventClass, "KeyPressed", INT2NUM( sf::Event::KeyPressed ) );
|
||||||
rb_define_const( globalEventClass, "KeyReleased", INT2NUM( static_cast< int >( sf::Event::KeyReleased ) ) );
|
rb_define_const( globalEventClass, "KeyReleased", INT2NUM( sf::Event::KeyReleased ) );
|
||||||
rb_define_const( globalEventClass, "MouseWheelMoved", INT2NUM( static_cast< int >( sf::Event::MouseWheelMoved ) ) );
|
rb_define_const( globalEventClass, "MouseWheelMoved", INT2NUM( sf::Event::MouseWheelMoved ) );
|
||||||
rb_define_const( globalEventClass, "MouseButtonPressed", INT2NUM( static_cast< int >( sf::Event::MouseButtonPressed ) ) );
|
rb_define_const( globalEventClass, "MouseButtonPressed", INT2NUM( sf::Event::MouseButtonPressed ) );
|
||||||
rb_define_const( globalEventClass, "MouseButtonReleased", INT2NUM( static_cast< int >( sf::Event::MouseButtonReleased ) ) );
|
rb_define_const( globalEventClass, "MouseButtonReleased", INT2NUM( sf::Event::MouseButtonReleased ) );
|
||||||
rb_define_const( globalEventClass, "MouseMoved", INT2NUM( static_cast< int >( sf::Event::MouseMoved ) ) );
|
rb_define_const( globalEventClass, "MouseMoved", INT2NUM( sf::Event::MouseMoved ) );
|
||||||
rb_define_const( globalEventClass, "MouseEntered", INT2NUM( static_cast< int >( sf::Event::MouseEntered ) ) );
|
rb_define_const( globalEventClass, "MouseEntered", INT2NUM( sf::Event::MouseEntered ) );
|
||||||
rb_define_const( globalEventClass, "MouseLeft", INT2NUM( static_cast< int >( sf::Event::MouseLeft ) ) );
|
rb_define_const( globalEventClass, "MouseLeft", INT2NUM( sf::Event::MouseLeft ) );
|
||||||
rb_define_const( globalEventClass, "JoyButtonPressed", INT2NUM( static_cast< int >( sf::Event::JoyButtonPressed ) ) );
|
rb_define_const( globalEventClass, "JoyButtonPressed", INT2NUM( sf::Event::JoyButtonPressed ) );
|
||||||
rb_define_const( globalEventClass, "JoyButtonReleased", INT2NUM( static_cast< int >( sf::Event::JoyButtonReleased ) ) );
|
rb_define_const( globalEventClass, "JoyButtonReleased", INT2NUM( sf::Event::JoyButtonReleased ) );
|
||||||
rb_define_const( globalEventClass, "JoyMoved", INT2NUM( static_cast< int >( sf::Event::JoyMoved ) ) );
|
rb_define_const( globalEventClass, "JoyMoved", INT2NUM( sf::Event::JoyMoved ) );
|
||||||
rb_define_const( globalEventClass, "Count", INT2NUM( static_cast< int >( sf::Event::Count ) ) );
|
rb_define_const( globalEventClass, "Count", INT2NUM( sf::Event::Count ) );
|
||||||
|
|
||||||
// Class methods
|
// Class methods
|
||||||
rb_define_singleton_method( globalEventClass, "new", FUNCPTR( Event_New ), -1 );
|
rb_define_singleton_method( globalEventClass, "new", Event_New, -1 );
|
||||||
|
|
||||||
// Instance methods
|
// 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, "type", 1, 0 );
|
||||||
rb_define_attr( globalEventClass, "joyButton", 1, 0 );
|
rb_define_attr( globalEventClass, "joyButton", 1, 0 );
|
||||||
rb_define_attr( globalEventClass, "joyMove", 1, 0 );
|
rb_define_attr( globalEventClass, "joyMove", 1, 0 );
|
||||||
@ -289,70 +313,50 @@ void Init_Event( void )
|
|||||||
rb_define_attr( globalEventClass, "text", 1, 0 );
|
rb_define_attr( globalEventClass, "text", 1, 0 );
|
||||||
|
|
||||||
// JoyButton methods
|
// JoyButton methods
|
||||||
rb_define_method( globalJoyButtonEventClass, "joystickId", FUNCPTR( JoyButtonEvent_GetJoystickId ), 0 );
|
rb_define_method( globalJoyButtonEventClass, "joystickId", JoyButtonEvent_GetJoystickId, 0 );
|
||||||
rb_define_method( globalJoyButtonEventClass, "joystickId=", FUNCPTR( JoyButtonEvent_SetJoystickId ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalJoyButtonEventClass, "button", FUNCPTR( JoyButtonEvent_GetButton ), 0 );
|
rb_define_method( globalJoyButtonEventClass, "button", JoyButtonEvent_GetButton, 0 );
|
||||||
rb_define_method( globalJoyButtonEventClass, "button=", FUNCPTR( JoyButtonEvent_SetButton ), 1 );
|
|
||||||
|
|
||||||
// JoyMove methods
|
// JoyMove methods
|
||||||
rb_define_method( globalJoyMoveEventClass, "joystickId", FUNCPTR( JoyMoveEvent_GetJoystickId ), 0 );
|
rb_define_method( globalJoyMoveEventClass, "joystickId", JoyMoveEvent_GetJoystickId, 0 );
|
||||||
rb_define_method( globalJoyMoveEventClass, "joystickId=", FUNCPTR( JoyMoveEvent_SetJoystickId ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalJoyMoveEventClass, "axis", FUNCPTR( JoyMoveEvent_GetAxis ), 0 );
|
rb_define_method( globalJoyMoveEventClass, "axis", JoyMoveEvent_GetAxis, 0 );
|
||||||
rb_define_method( globalJoyMoveEventClass, "axis=", FUNCPTR( JoyMoveEvent_SetAxis ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalJoyMoveEventClass, "position", FUNCPTR( JoyMoveEvent_GetPosition ), 0 );
|
rb_define_method( globalJoyMoveEventClass, "position", JoyMoveEvent_GetPosition, 0 );
|
||||||
rb_define_method( globalJoyMoveEventClass, "position=", FUNCPTR( JoyMoveEvent_SetPosition ), 1 );
|
|
||||||
|
|
||||||
// Key methods
|
// Key methods
|
||||||
rb_define_method( globalKeyEventClass, "code", FUNCPTR( KeyEvent_GetCode ), 0 );
|
rb_define_method( globalKeyEventClass, "code", KeyEvent_GetCode, 0 );
|
||||||
rb_define_method( globalKeyEventClass, "code=", FUNCPTR( KeyEvent_SetCode ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalKeyEventClass, "alt", FUNCPTR( KeyEvent_GetAlt ), 0 );
|
rb_define_method( globalKeyEventClass, "alt", KeyEvent_GetAlt, 0 );
|
||||||
rb_define_method( globalKeyEventClass, "alt=", FUNCPTR( KeyEvent_SetAlt ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalKeyEventClass, "control", FUNCPTR( KeyEvent_GetControl ), 0 );
|
rb_define_method( globalKeyEventClass, "control", KeyEvent_GetControl, 0 );
|
||||||
rb_define_method( globalKeyEventClass, "control=", FUNCPTR( KeyEvent_SetControl ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalKeyEventClass, "shift", FUNCPTR( KeyEvent_GetShift ), 0 );
|
rb_define_method( globalKeyEventClass, "shift", KeyEvent_GetShift, 0 );
|
||||||
rb_define_method( globalKeyEventClass, "shift=", FUNCPTR( KeyEvent_SetShift ), 1 );
|
|
||||||
|
|
||||||
// MouseButton methods
|
// MouseButton methods
|
||||||
rb_define_method( globalMouseButtonEventClass, "button", FUNCPTR( MouseButtonEvent_GetButton ), 0 );
|
rb_define_method( globalMouseButtonEventClass, "button", MouseButtonEvent_GetButton, 0 );
|
||||||
rb_define_method( globalMouseButtonEventClass, "button=", FUNCPTR( MouseButtonEvent_SetButton ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalMouseButtonEventClass, "x", FUNCPTR( MouseButtonEvent_GetX ), 0 );
|
rb_define_method( globalMouseButtonEventClass, "x", MouseButtonEvent_GetX, 0 );
|
||||||
rb_define_method( globalMouseButtonEventClass, "x=", FUNCPTR( MouseButtonEvent_SetX ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalMouseButtonEventClass, "y", FUNCPTR( MouseButtonEvent_GetY ), 0 );
|
rb_define_method( globalMouseButtonEventClass, "y", MouseButtonEvent_GetY, 0 );
|
||||||
rb_define_method( globalMouseButtonEventClass, "y=", FUNCPTR( MouseButtonEvent_SetY ), 1 );
|
|
||||||
|
|
||||||
// MouseMove methods
|
// MouseMove methods
|
||||||
rb_define_method( globalMouseMoveEventClass, "x", FUNCPTR( MouseMoveEvent_GetX ), 0 );
|
rb_define_method( globalMouseMoveEventClass, "x", MouseMoveEvent_GetX, 0 );
|
||||||
rb_define_method( globalMouseMoveEventClass, "x=", FUNCPTR( MouseMoveEvent_SetX ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalMouseMoveEventClass, "y", FUNCPTR( MouseMoveEvent_GetY ), 0 );
|
rb_define_method( globalMouseMoveEventClass, "y", MouseMoveEvent_GetY, 0 );
|
||||||
rb_define_method( globalMouseMoveEventClass, "y=", FUNCPTR( MouseMoveEvent_SetY ), 1 );
|
|
||||||
|
|
||||||
// MouseWheel methods
|
// MouseWheel methods
|
||||||
rb_define_method( globalMouseWheelEventClass, "delta", FUNCPTR( MouseWheelEvent_GetDelta ), 0 );
|
rb_define_method( globalMouseWheelEventClass, "delta", MouseWheelEvent_GetDelta, 0 );
|
||||||
rb_define_method( globalMouseWheelEventClass, "delta=", FUNCPTR( MouseWheelEvent_SetDelta ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalMouseWheelEventClass, "x", FUNCPTR( MouseWheelEvent_GetX ), 0 );
|
rb_define_method( globalMouseWheelEventClass, "x", MouseWheelEvent_GetX, 0 );
|
||||||
rb_define_method( globalMouseWheelEventClass, "x=", FUNCPTR( MouseWheelEvent_SetX ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalMouseWheelEventClass, "y", FUNCPTR( MouseWheelEvent_GetY ), 0 );
|
rb_define_method( globalMouseWheelEventClass, "y", MouseWheelEvent_GetY, 0 );
|
||||||
rb_define_method( globalMouseWheelEventClass, "y=", FUNCPTR( MouseWheelEvent_SetY ), 1 );
|
|
||||||
|
|
||||||
// Size methods
|
// Size methods
|
||||||
rb_define_method( globalSizeEventClass, "width", FUNCPTR( SizeEvent_GetWidth ), 0 );
|
rb_define_method( globalSizeEventClass, "width", SizeEvent_GetWidth, 0 );
|
||||||
rb_define_method( globalSizeEventClass, "width=", FUNCPTR( SizeEvent_SetWidth ), 1 );
|
|
||||||
|
|
||||||
rb_define_method( globalSizeEventClass, "height", FUNCPTR( SizeEvent_GetWidth ), 0 );
|
rb_define_method( globalSizeEventClass, "height", SizeEvent_GetWidth, 0 );
|
||||||
rb_define_method( globalSizeEventClass, "height=", FUNCPTR( SizeEvent_SetWidth ), 1 );
|
|
||||||
|
|
||||||
// Text methods
|
// Text methods
|
||||||
rb_define_method( globalTextEventClass, "unicode", FUNCPTR( TextEvent_GetUnicode ), 0 );
|
rb_define_method( globalTextEventClass, "unicode", TextEvent_GetUnicode, 0 );
|
||||||
rb_define_method( globalTextEventClass, "unicode=", FUNCPTR( TextEvent_SetUnicode ), 1 );
|
|
||||||
}
|
}
|
||||||
|
@ -24,36 +24,6 @@
|
|||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
#include <SFML/Window/Input.hpp>
|
#include <SFML/Window/Input.hpp>
|
||||||
|
|
||||||
/* 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;
|
VALUE globalInputClass;
|
||||||
|
|
||||||
/* Free a heap allocated object
|
/* Free a heap allocated object
|
||||||
@ -179,18 +149,46 @@ static VALUE Input_New( int argc, VALUE * args, VALUE aKlass )
|
|||||||
|
|
||||||
void Init_Input( void )
|
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
|
// Class methods
|
||||||
rb_define_singleton_method( globalInputClass, "new", FUNCPTR( Input_New ), -1 );
|
rb_define_singleton_method( globalInputClass, "new", Input_New, -1 );
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
rb_define_method( globalInputClass, "isKeyDown", FUNCPTR( Input_IsKeyDown ), 1 );
|
rb_define_method( globalInputClass, "isKeyDown", Input_IsKeyDown, 1 );
|
||||||
rb_define_method( globalInputClass, "isMouseButtonDown", FUNCPTR( Input_IsMouseButtonDown ), 1 );
|
rb_define_method( globalInputClass, "isMouseButtonDown", Input_IsMouseButtonDown, 1 );
|
||||||
rb_define_method( globalInputClass, "isJoystickButtonDown", FUNCPTR( Input_IsJoystickButtonDown ), 2 );
|
rb_define_method( globalInputClass, "isJoystickButtonDown", Input_IsJoystickButtonDown, 2 );
|
||||||
rb_define_method( globalInputClass, "getMouseX", FUNCPTR( Input_GetMouseX ), 0 );
|
rb_define_method( globalInputClass, "getMouseX", Input_GetMouseX, 0 );
|
||||||
rb_define_method( globalInputClass, "getMouseY", FUNCPTR( Input_GetMouseY ), 0 );
|
rb_define_method( globalInputClass, "getMouseY", Input_GetMouseY, 0 );
|
||||||
rb_define_method( globalInputClass, "getJoystickAxis", FUNCPTR( Input_GetJoystickAxis ), 2 );
|
rb_define_method( globalInputClass, "getJoystickAxis", Input_GetJoystickAxis, 2 );
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
rb_define_alias( globalInputClass, "key_down?", "isKeyDown");
|
rb_define_alias( globalInputClass, "key_down?", "isKeyDown");
|
||||||
|
@ -25,36 +25,6 @@
|
|||||||
#include <SFML/Window/VideoMode.hpp>
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
/* 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;
|
VALUE globalVideoModeClass;
|
||||||
|
|
||||||
/* Internal function
|
/* Internal function
|
||||||
@ -236,22 +206,54 @@ static VALUE VideoMode_New( int argc, VALUE *args, VALUE aKlass )
|
|||||||
|
|
||||||
void Init_VideoMode( void )
|
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
|
// Class methods
|
||||||
rb_define_singleton_method( globalVideoModeClass, "new", FUNCPTR( VideoMode_New ), -1 );
|
rb_define_singleton_method( globalVideoModeClass, "new", VideoMode_New, -1 );
|
||||||
rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", FUNCPTR( VideoMode_GetDesktopMode ), 0 );
|
rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", VideoMode_GetDesktopMode, 0 );
|
||||||
rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", FUNCPTR( VideoMode_GetFullscreenModes ), 0 );
|
rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", VideoMode_GetFullscreenModes, 0 );
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
rb_define_method( globalVideoModeClass, "width", FUNCPTR( VideoMode_GetWidth ), 0 );
|
rb_define_method( globalVideoModeClass, "width", VideoMode_GetWidth, 0 );
|
||||||
rb_define_method( globalVideoModeClass, "width=", FUNCPTR( VideoMode_SetWidth ), 1 );
|
rb_define_method( globalVideoModeClass, "width=", VideoMode_SetWidth, 1 );
|
||||||
|
|
||||||
rb_define_method( globalVideoModeClass, "height", FUNCPTR( VideoMode_GetWidth ), 0 );
|
rb_define_method( globalVideoModeClass, "height", VideoMode_GetWidth, 0 );
|
||||||
rb_define_method( globalVideoModeClass, "height=", FUNCPTR( VideoMode_SetWidth ), 1 );
|
rb_define_method( globalVideoModeClass, "height=", VideoMode_SetWidth, 1 );
|
||||||
|
|
||||||
rb_define_method( globalVideoModeClass, "bitsPerPixel", FUNCPTR( VideoMode_GetBitsPerPixel ), 0 );
|
rb_define_method( globalVideoModeClass, "bitsPerPixel", VideoMode_GetBitsPerPixel, 0 );
|
||||||
rb_define_method( globalVideoModeClass, "bitsPerPixel=", FUNCPTR( VideoMode_SetBitsPerPixel ), 1 );
|
rb_define_method( globalVideoModeClass, "bitsPerPixel=", VideoMode_SetBitsPerPixel, 1 );
|
||||||
|
|
||||||
// Class aliases
|
// Class aliases
|
||||||
rb_define_alias( CLASS_OF( globalVideoModeClass ), "desktopMode", "getDesktopMode" );
|
rb_define_alias( CLASS_OF( globalVideoModeClass ), "desktopMode", "getDesktopMode" );
|
||||||
|
@ -26,50 +26,6 @@
|
|||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
#include "main.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;
|
VALUE globalWindowClass;
|
||||||
extern VALUE globalVideoModeClass;
|
extern VALUE globalVideoModeClass;
|
||||||
extern VALUE globalContextSettingsClass;
|
extern VALUE globalContextSettingsClass;
|
||||||
@ -109,7 +65,7 @@ static VALUE Window_Close( VALUE self )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* call-seq:
|
/* 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.
|
* Create (or recreate) the window.
|
||||||
*
|
*
|
||||||
@ -703,38 +659,84 @@ static VALUE Window_New( int argc, VALUE *args, VALUE aKlass )
|
|||||||
|
|
||||||
void Init_Window( void )
|
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
|
// Class methods
|
||||||
rb_define_singleton_method( globalWindowClass, "new", FUNCPTR( Window_New ), -1 );
|
rb_define_singleton_method( globalWindowClass, "new", Window_New , -1 );
|
||||||
|
|
||||||
// Instance methods
|
// Instance methods
|
||||||
rb_define_method( globalWindowClass, "close", FUNCPTR( Window_Close ), 0 );
|
rb_define_method( globalWindowClass, "close", Window_Close, 0 );
|
||||||
rb_define_method( globalWindowClass, "create", FUNCPTR( Window_Create ), -1 );
|
rb_define_method( globalWindowClass, "create", Window_Create, -1 );
|
||||||
rb_define_method( globalWindowClass, "display", FUNCPTR( Window_Display ), 0 );
|
rb_define_method( globalWindowClass, "display", Window_Display, 0 );
|
||||||
rb_define_method( globalWindowClass, "enableKeyRepeat", FUNCPTR( Window_EnableKeyRepeat ), 1 );
|
rb_define_method( globalWindowClass, "enableKeyRepeat", Window_EnableKeyRepeat, 1 );
|
||||||
rb_define_method( globalWindowClass, "getEvent", FUNCPTR( Window_GetEvent ), 0 );
|
rb_define_method( globalWindowClass, "getEvent", Window_GetEvent, 0 );
|
||||||
rb_define_method( globalWindowClass, "getFrameTime", FUNCPTR( Window_GetFrameTime ), 0 );
|
rb_define_method( globalWindowClass, "getFrameTime", Window_GetFrameTime , 0 );
|
||||||
rb_define_method( globalWindowClass, "getHeight", FUNCPTR( Window_GetHeight ), 0 );
|
rb_define_method( globalWindowClass, "getHeight", Window_GetHeight, 0 );
|
||||||
rb_define_method( globalWindowClass, "getInput", FUNCPTR( Window_GetInput ), 0 );
|
rb_define_method( globalWindowClass, "getInput", Window_GetInput, 0 );
|
||||||
rb_define_method( globalWindowClass, "getSettings", FUNCPTR( Window_GetSettings ), 0 );
|
rb_define_method( globalWindowClass, "getSettings", Window_GetSettings, 0 );
|
||||||
rb_define_method( globalWindowClass, "getWidth", FUNCPTR( Window_GetWidth ), 0 );
|
rb_define_method( globalWindowClass, "getWidth", Window_GetWidth, 0 );
|
||||||
rb_define_method( globalWindowClass, "isOpened", FUNCPTR( Window_IsOpened ), 0 );
|
rb_define_method( globalWindowClass, "isOpened", Window_IsOpened, 0 );
|
||||||
rb_define_method( globalWindowClass, "setActive", FUNCPTR( Window_SetActive ), 1 );
|
rb_define_method( globalWindowClass, "setActive", Window_SetActive, 1 );
|
||||||
rb_define_method( globalWindowClass, "setCursorPosition", FUNCPTR( Window_SetCursorPosition ), 2 );
|
rb_define_method( globalWindowClass, "setCursorPosition", Window_SetCursorPosition, 2 );
|
||||||
rb_define_method( globalWindowClass, "cursorPosition=", FUNCPTR( Window_SetCursorPosition2 ), 1 );
|
rb_define_method( globalWindowClass, "cursorPosition=", Window_SetCursorPosition2, 1 );
|
||||||
rb_define_method( globalWindowClass, "setFramerateLimit", FUNCPTR( Window_SetFramerateLimit ), 1 );
|
rb_define_method( globalWindowClass, "setFramerateLimit", Window_SetFramerateLimit, 1 );
|
||||||
rb_define_method( globalWindowClass, "setIcon", FUNCPTR( Window_SetIcon ), 3 );
|
rb_define_method( globalWindowClass, "setIcon", Window_SetIcon, 3 );
|
||||||
rb_define_method( globalWindowClass, "setJoystickThreshold", FUNCPTR( Window_SetJoystickThreshold ), 1 );
|
rb_define_method( globalWindowClass, "setJoystickThreshold", Window_SetJoystickThreshold, 1 );
|
||||||
rb_define_method( globalWindowClass, "setPosition", FUNCPTR( Window_SetPosition ), 2 );
|
rb_define_method( globalWindowClass, "setPosition", Window_SetPosition, 2 );
|
||||||
rb_define_method( globalWindowClass, "position=", FUNCPTR( Window_SetPosition2 ), 1 );
|
rb_define_method( globalWindowClass, "position=", Window_SetPosition2, 1 );
|
||||||
rb_define_method( globalWindowClass, "setSize", FUNCPTR( Window_SetSize ), 2 );
|
rb_define_method( globalWindowClass, "setSize", Window_SetSize, 2 );
|
||||||
rb_define_method( globalWindowClass, "size=", FUNCPTR( Window_SetSize2 ), 1 );
|
rb_define_method( globalWindowClass, "size=", Window_SetSize2, 1 );
|
||||||
rb_define_method( globalWindowClass, "setTitle", FUNCPTR( Window_SetTitle ), 1 );
|
rb_define_method( globalWindowClass, "setTitle", Window_SetTitle, 1 );
|
||||||
rb_define_method( globalWindowClass, "show", FUNCPTR( Window_Show ), 1 );
|
rb_define_method( globalWindowClass, "show", Window_Show, 1 );
|
||||||
rb_define_method( globalWindowClass, "showMouseCursor", FUNCPTR( Window_ShowMouseCursor ), 1 );
|
rb_define_method( globalWindowClass, "showMouseCursor", Window_ShowMouseCursor, 1 );
|
||||||
rb_define_method( globalWindowClass, "useVerticalSync", FUNCPTR( Window_UseVerticalSync ), 1 );
|
rb_define_method( globalWindowClass, "useVerticalSync", Window_UseVerticalSync, 1 );
|
||||||
rb_define_method( globalWindowClass, "waitEvent", FUNCPTR( Window_WaitEvent ), 0 );
|
rb_define_method( globalWindowClass, "waitEvent", Window_WaitEvent, 0 );
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
rb_define_alias( globalWindowClass, "keyRepeat=", "enableKeyRepeat" );
|
rb_define_alias( globalWindowClass, "keyRepeat=", "enableKeyRepeat" );
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/* SFML Namespace which contains all classes in this module. */
|
||||||
VALUE globalSFMLNamespace;
|
VALUE globalSFMLNamespace;
|
||||||
VALUE globalKeyNamespace;
|
VALUE globalKeyNamespace;
|
||||||
VALUE globalMouseNamespace;
|
VALUE globalMouseNamespace;
|
||||||
@ -46,17 +47,6 @@ VALUE GetNamespace( void )
|
|||||||
return globalSFMLNamespace;
|
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[] =
|
static const char * keyNamesMisc[] =
|
||||||
{
|
{
|
||||||
"Escape", "LControl", "LShift", "LAlt", "LSystem", "RControl", "RShift", "RAlt", "RSystem",
|
"Escape", "LControl", "LShift", "LAlt", "LSystem", "RControl", "RShift", "RAlt", "RSystem",
|
||||||
@ -69,29 +59,49 @@ static const char * keyNamesMisc[] =
|
|||||||
"Count"
|
"Count"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * mouseNames[] =
|
/* Definition of key codes for keyboard events.
|
||||||
{
|
*
|
||||||
"Left", "Right", "Middle", "XButton1", "XButton2", "ButtonCount"
|
* All SFML::Key constants exists, I just haven't written them all so Rdoc can interpret them yet.
|
||||||
};
|
*/
|
||||||
|
|
||||||
static const char * axisNames[] =
|
|
||||||
{
|
|
||||||
"AxisX", "AxisY", "AxisZ", "AxisR", "AxisU", "AxisV", "AxisPOV",
|
|
||||||
"AxisCount"
|
|
||||||
};
|
|
||||||
|
|
||||||
void CreateKeyEnum( void )
|
void CreateKeyEnum( void )
|
||||||
{
|
{
|
||||||
globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" );
|
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, "A", INT2FIX( sf::Key::A ) );
|
||||||
{
|
rb_define_const( globalKeyNamespace, "B", INT2FIX( sf::Key::B ) );
|
||||||
rb_define_const( globalKeyNamespace, keyNamesLetters[ index - sf::Key::A ], INT2FIX( index ) );
|
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, "Num0", INT2FIX( sf::Key::Num0 ) );
|
||||||
{
|
rb_define_const( globalKeyNamespace, "Num1", INT2FIX( sf::Key::Num1 ) );
|
||||||
rb_define_const( globalKeyNamespace, keyNamesNum[ index - sf::Key::Num0 ], INT2FIX( index ) );
|
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++ )
|
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 )
|
void CreateMouseEnum( void )
|
||||||
{
|
{
|
||||||
globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" );
|
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, "Left", INT2FIX( sf::Mouse::Left ) );
|
||||||
{
|
rb_define_const( globalMouseNamespace, "Right", INT2FIX( sf::Mouse::Right ) );
|
||||||
rb_define_const( globalMouseNamespace, mouseNames[ index - sf::Mouse::Left ], INT2FIX( index ) );
|
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 )
|
void CreateJoyEnum( void )
|
||||||
{
|
{
|
||||||
globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" );
|
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, "AxisX", INT2FIX( sf::Joy::AxisX ) );
|
||||||
{
|
rb_define_const( globalJoyNamespace, "AxisY", INT2FIX( sf::Joy::AxisY ) );
|
||||||
rb_define_const( globalJoyNamespace, axisNames[ index - sf::Joy::AxisX ], INT2FIX( index ) );
|
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 )
|
void CreateStyleEnum( void )
|
||||||
{
|
{
|
||||||
globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" );
|
globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" );
|
||||||
rb_define_const( globalStyleNamespace, "None", sf::Style::None );
|
rb_define_const( globalStyleNamespace, "None", INT2FIX( sf::Style::None ) );
|
||||||
rb_define_const( globalStyleNamespace, "Titlebar", sf::Style::Titlebar );
|
rb_define_const( globalStyleNamespace, "Titlebar", INT2FIX( sf::Style::Titlebar ) );
|
||||||
rb_define_const( globalStyleNamespace, "Resize", sf::Style::Resize );
|
rb_define_const( globalStyleNamespace, "Resize", INT2FIX( sf::Style::Resize ) );
|
||||||
rb_define_const( globalStyleNamespace, "Close", sf::Style::Close );
|
rb_define_const( globalStyleNamespace, "Close", INT2FIX( sf::Style::Close ) );
|
||||||
rb_define_const( globalStyleNamespace, "Fullscreen", sf::Style::Fullscreen );
|
rb_define_const( globalStyleNamespace, "Fullscreen", INT2FIX( sf::Style::Fullscreen ) );
|
||||||
rb_define_const( globalStyleNamespace, "Default", sf::Style::Default );
|
rb_define_const( globalStyleNamespace, "Default", INT2FIX( sf::Style::Default ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckDependencies( void )
|
bool CheckDependencies( void )
|
||||||
@ -156,6 +175,7 @@ void RetrieveVector2Class( void )
|
|||||||
|
|
||||||
void Init_window( void )
|
void Init_window( void )
|
||||||
{
|
{
|
||||||
|
/* SFML namespace which contains the classes of this module. */
|
||||||
globalSFMLNamespace = rb_define_module( "SFML" );
|
globalSFMLNamespace = rb_define_module( "SFML" );
|
||||||
if( CheckDependencies() == false )
|
if( CheckDependencies() == false )
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@ extern "C" void Init_window( void );
|
|||||||
|
|
||||||
typedef VALUE ( *RubyFunctionPtr )( ... );
|
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_
|
#endif // SFML_RUBYEXT_MAIN_HEADER_
|
||||||
|
Loading…
Reference in New Issue
Block a user