From 0124c37fb5dc84fa98a318376a5219efe71f418c Mon Sep 17 00:00:00 2001 From: groogy Date: Sat, 6 Nov 2010 15:38:26 +0000 Subject: [PATCH] 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 --- ruby/sfml-window/window/Event.cpp | 20 ++++++++++++++++---- ruby/sfml-window/window/main.cpp | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ruby/sfml-window/window/Event.cpp b/ruby/sfml-window/window/Event.cpp index 149098a9..6a351cbb 100644 --- a/ruby/sfml-window/window/Event.cpp +++ b/ruby/sfml-window/window/Event.cpp @@ -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 ); diff --git a/ruby/sfml-window/window/main.cpp b/ruby/sfml-window/window/main.cpp index 9dc18937..106a38a1 100644 --- a/ruby/sfml-window/window/main.cpp +++ b/ruby/sfml-window/window/main.cpp @@ -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(); }