diff --git a/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp b/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp index 6ee9bac87..58b208171 100644 --- a/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp +++ b/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp @@ -29,6 +29,8 @@ VALUE globalRenderImageClass; /* External classes */ extern VALUE globalRenderTargetModule; extern VALUE globalImageClass; +extern VALUE globalDrawableModule; +extern VALUE globalShaderClass; static void RenderImage_Free( sf::RenderImage *anObject ) { @@ -264,6 +266,7 @@ void Init_RenderImage( void ) rb_define_singleton_method( globalRenderImageClass, "isAvailable", RenderImage_IsAvailable, 0 ); // Instance methods + rb_define_method( globalRenderImageClass, "draw", RenderImage_Create, -1 ); rb_define_method( globalRenderImageClass, "create", RenderImage_Create, -1 ); rb_define_method( globalRenderImageClass, "display", RenderImage_Display, 0 ); rb_define_method( globalRenderImageClass, "getImage", RenderImage_GetImage, 0 ); diff --git a/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp b/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp index 37f77764e..922c19412 100644 --- a/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp +++ b/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp @@ -25,6 +25,7 @@ #include "main.hpp" #include #include +#include VALUE globalRenderTargetModule; VALUE globalRenderTargetInstanceClass; @@ -65,6 +66,7 @@ static VALUE RenderTarget_Draw( int argc, VALUE *args, VALUE self ) { sf::RenderTarget *object = NULL; Data_Get_Struct( self, sf::RenderTarget, object ); + std::cout << object << std::endl; switch( argc ) { case 2: diff --git a/bindings/ruby/sfml-window/window/Window.cpp b/bindings/ruby/sfml-window/window/Window.cpp index fdc434b4a..7a6809217 100644 --- a/bindings/ruby/sfml-window/window/Window.cpp +++ b/bindings/ruby/sfml-window/window/Window.cpp @@ -592,6 +592,15 @@ static VALUE Window_WaitEvent( VALUE self ) } } +static VALUE Window_Initialize( int argc, VALUE *args, VALUE self ) +{ + if( args > 0 ) + { + rb_funcall( self, rb_intern( "create" ), argc, args ); + } + return self; +} + /* call-seq: * Window.new() -> window * Window.new( mode, title, style = SFML::Style::Default, settings = SFML::ContextSettings.new ) -> window @@ -610,46 +619,9 @@ static VALUE Window_WaitEvent( VALUE self ) */ static VALUE Window_New( int argc, VALUE *args, VALUE aKlass ) { - sf::Window *object = NULL; - sf::VideoMode *mode = NULL; - sf::ContextSettings *settings = NULL; - VALUE arg0 = Qnil; - switch( argc ) - { - case 0: - object = new sf::Window(); - break; - case 2: - arg0 = VideoMode_ForceType( args[0] ); - VALIDATE_CLASS( arg0, globalVideoModeClass, "first" ); - VALIDATE_CLASS( args[1], rb_cString, "second" ); - Data_Get_Struct( arg0, sf::VideoMode, mode ); - object = new sf::Window( *mode , rb_string_value_cstr( &args[1] ) ); - break; - case 3: - arg0 = VideoMode_ForceType( args[0] ); - VALIDATE_CLASS( arg0, globalVideoModeClass, "first" ); - VALIDATE_CLASS( args[1], rb_cString, "second" ); - VALIDATE_CLASS( args[2], rb_cFixnum, "third" ); - Data_Get_Struct( arg0, sf::VideoMode, mode ); - object = new sf::Window( *mode, rb_string_value_cstr( &args[1] ), FIX2UINT( args[2] ) ); - break; - case 4: - arg0 = VideoMode_ForceType( args[0] ); - VALIDATE_CLASS( arg0, globalVideoModeClass, "first" ); - VALIDATE_CLASS( args[1], rb_cString, "second" ); - VALIDATE_CLASS( args[2], rb_cFixnum, "third" ); - VALIDATE_CLASS( args[3], globalContextSettingsClass, "fourth" ); - Data_Get_Struct( arg0, sf::VideoMode, mode ); - Data_Get_Struct( args[3], sf::ContextSettings, settings ); - object = new sf::Window( *mode, rb_string_value_cstr( &args[1] ), FIX2UINT( args[2] ), *settings ); - break; - default: - rb_raise( rb_eArgError, "Expected 2..4 arguments but was given %d", argc ); - break; - } + sf::Window *object = new sf::Window(); VALUE rbData = Data_Wrap_Struct( aKlass, 0, Window_Free, object ); - rb_obj_call_init( rbData, 0, 0 ); + rb_obj_call_init( rbData, argc, args ); return rbData; } @@ -707,6 +679,7 @@ void Init_Window( void ) rb_define_singleton_method( globalWindowClass, "new", Window_New , -1 ); // Instance methods + rb_define_method( globalWindowClass, "initialize", Window_Initialize, -1 ); rb_define_method( globalWindowClass, "close", Window_Close, 0 ); rb_define_method( globalWindowClass, "create", Window_Create, -1 ); rb_define_method( globalWindowClass, "display", Window_Display, 0 ); diff --git a/bindings/ruby/testing/render-window-demo.rb b/bindings/ruby/testing/render-window-demo.rb index 146ca337c..e75fdf578 100644 --- a/bindings/ruby/testing/render-window-demo.rb +++ b/bindings/ruby/testing/render-window-demo.rb @@ -2,7 +2,8 @@ require 'sfml/system' require 'sfml/window' require 'sfml/graphics' -app = SFML::RenderWindow.new( [800, 600], "My Ruby SFML" ) +app = SFML::RenderWindow.new +app.create( [800, 600], "My Ruby SFML" ) app.framerate = 100 app.position = [300, 300] input = app.input @@ -16,9 +17,8 @@ while app.open? end end - app.clear shape.position = [input.mouseX, input.mouseY] - app.draw shape + app.draw shape app.display end