Finished SFML::Event and run tests to see that it works.

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1618 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
groogy 2010-11-06 15:38:26 +00:00
parent 3a7168b497
commit 0124c37fb5
2 changed files with 18 additions and 4 deletions

View File

@ -173,11 +173,22 @@ EVENT_TYPE_ACCESSORS( Size, Height, INT2NUM, NUM2UINT );
EVENT_TYPE_ACCESSORS( Text, Unicode, INT2NUM, NUM2UINT );
static VALUE Event_Initialize( VALUE self )
static VALUE Event_Initialize( VALUE self, VALUE aType )
{
sf::Event * object = NULL;
Data_Get_Struct( self, sf::Event, object );
int typeNum = FIX2INT( aType );
if(typeNum >= 0 && typeNum < sf::Event::Count)
{
rb_iv_set( self, "@type", aType );
object->Type = static_cast< sf::Event::EventType >( typeNum );
}
else
{
rb_raise( rb_eTypeError, "expected Fixnum in range of 0...SFML::Event::Count" );
}
bool noSpecialType = false;
VALUE eventType;
const char * name = NULL;
@ -235,11 +246,11 @@ static VALUE Event_Initialize( VALUE self )
*
* The constructor creates a new event.
*/
static VALUE Event_New( VALUE aKlass )
static VALUE Event_New( int argc, VALUE * args, VALUE aKlass )
{
sf::Event *object = new sf::Event();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Event_Free, object );
rb_obj_call_init( rbData, 0, 0 );
rb_obj_call_init( rbData, argc, args );
return rbData;
}
@ -274,9 +285,10 @@ void Init_Event( void )
rb_define_const( globalEventClass, "Count", INT2NUM( static_cast< int >( sf::Event::Count ) ) );
// Class methods
rb_define_singleton_method( globalEventClass, "new", FUNCPTR( Event_New ), 0 );
rb_define_singleton_method( globalEventClass, "new", FUNCPTR( Event_New ), -1 );
// Instance methods
rb_define_method( globalEventClass, "initialize", FUNCPTR( Event_Initialize ), 1 );
rb_define_attr( globalEventClass, "joyButton", 1, 0 );
rb_define_attr( globalEventClass, "joyMove", 1, 0 );
rb_define_attr( globalEventClass, "key", 1, 0 );

View File

@ -23,6 +23,7 @@
#include "main.hpp"
#include "Context.hpp"
#include "ContextSettings.hpp"
#include "Event.hpp"
VALUE globalSFMLNamespace;
@ -37,4 +38,5 @@ void Init_window( void )
rb_define_const(globalSFMLNamespace, "WindowLoaded", Qtrue);
Init_Context();
Init_ContextSettings();
Init_Event();
}