From aa39447c263e55498300a1af616a36036b1afdc9 Mon Sep 17 00:00:00 2001 From: groogy Date: Sat, 4 Dec 2010 19:26:05 +0000 Subject: [PATCH] Changed resource classes initialize method to call often used methods if arguments are provided. Check for details: http://tasks.groogy.se/index.php?do=details&task_id=1&project=2 git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1745 4e206d99-4929-0410-ac5d-dfc041789085 --- bindings/ruby/sfml-audio/audio/Music.cpp | 26 +++++++++++-------- .../ruby/sfml-audio/audio/SoundBuffer.cpp | 14 ++++++++++ bindings/ruby/sfml-graphics/graphics/Font.cpp | 10 +++++++ .../ruby/sfml-graphics/graphics/Image.cpp | 14 ++++++++++ .../ruby/sfml-graphics/graphics/Shader.cpp | 11 ++++++++ 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/bindings/ruby/sfml-audio/audio/Music.cpp b/bindings/ruby/sfml-audio/audio/Music.cpp index dbcce6b35..19a74009d 100644 --- a/bindings/ruby/sfml-audio/audio/Music.cpp +++ b/bindings/ruby/sfml-audio/audio/Music.cpp @@ -34,16 +34,6 @@ static VALUE Music_Free( sf::Music *anObject ) delete anObject; } -/* call-seq: - * Music.new() -> music - * - * Creates a new music instance. - */ -static VALUE Music_Initialize( int argc, VALUE *args, VALUE self ) -{ - return self; -} - /* call-seq: * music.openFromFile() -> true or false * @@ -67,6 +57,20 @@ static VALUE Music_OpenFromFile( VALUE self, VALUE aFilename ) } } +/* call-seq: + * Music.new() -> music + * + * Creates a new music instance. + */ +static VALUE Music_Initialize( int argc, VALUE *args, VALUE self ) +{ + if( argc > 0 ) + { + rb_funcall2( self, rb_intern( "openFromFile" ), argc, args ); + } + return self; +} + /* call-seq: * music.getDuration() -> float * @@ -130,7 +134,7 @@ void Init_Music( void ) rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 ); // Instance methods - rb_define_method( globalMusicClass, "initialize", Music_Initialize, 0 ); + rb_define_method( globalMusicClass, "initialize", Music_Initialize, -1 ); rb_define_method( globalMusicClass, "openFromFile", Music_OpenFromFile, 1 ); rb_define_method( globalMusicClass, "getDuration", Music_GetDuration, 0 ); diff --git a/bindings/ruby/sfml-audio/audio/SoundBuffer.cpp b/bindings/ruby/sfml-audio/audio/SoundBuffer.cpp index b41982b10..34ac3ca22 100644 --- a/bindings/ruby/sfml-audio/audio/SoundBuffer.cpp +++ b/bindings/ruby/sfml-audio/audio/SoundBuffer.cpp @@ -193,6 +193,19 @@ static VALUE SoundBuffer_GetDuration( VALUE self ) return rb_float_new( object->GetDuration() ); } +static VALUE SoundBuffer_Initialize( int argc, VALUE *args, VALUE self ) +{ + if( argc > 1 ) + { + rb_funcall2( self, rb_intern( "loadFromSampels" ), argc, args ); + } + else if( argc > 0 ) + { + rb_funcall2( self, rb_intern( "loadFromFile" ), argc, args ); + } + return self; +} + static VALUE SoundBuffer_InitializeCopy( VALUE self, VALUE aSource ) { sf::SoundBuffer *object = NULL; @@ -273,6 +286,7 @@ void Init_SoundBuffer( void ) rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 ); // Instance methods + rb_define_method( globalSoundBufferClass, "initialize", SoundBuffer_Initialize, -1 ); rb_define_method( globalSoundBufferClass, "initialize_copy", SoundBuffer_InitializeCopy, 1 ); rb_define_method( globalSoundBufferClass, "loadFromFile", SoundBuffer_LoadFromFile, 1 ); rb_define_method( globalSoundBufferClass, "loadFromSamples", SoundBuffer_LoadFromSamples, 4 ); diff --git a/bindings/ruby/sfml-graphics/graphics/Font.cpp b/bindings/ruby/sfml-graphics/graphics/Font.cpp index 73f4b8e7e..7f6547052 100644 --- a/bindings/ruby/sfml-graphics/graphics/Font.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Font.cpp @@ -130,6 +130,15 @@ static VALUE Font_GetImage( VALUE self, VALUE aCharacterSize ) return rbImage; } +static VALUE Font_Initialize( int argc, VALUE *args, VALUE self ) +{ + if( argc > 0 ) + { + rb_funcall2( self, rb_intern( "loadFromFile" ), argc, args ); + } + return self; +} + static VALUE Font_InitializeCopy( VALUE self, VALUE aSource ) { sf::Font *object = NULL; @@ -228,6 +237,7 @@ void Init_Font( void ) rb_define_singleton_method( globalFontClass, "getDefaultFont", Font_GetDefaultFont, 0 ); // Instance methods + rb_define_method( globalFontClass, "initialize", Font_Initialize, -1 ); rb_define_method( globalFontClass, "initialize_copy", Font_InitializeCopy, 1 ); rb_define_method( globalFontClass, "loadFromFile", Font_LoadFromFile, 1 ); rb_define_method( globalFontClass, "getGlyph", Font_GetGlyph, 3 ); diff --git a/bindings/ruby/sfml-graphics/graphics/Image.cpp b/bindings/ruby/sfml-graphics/graphics/Image.cpp index e5d5e66d0..f007f8090 100644 --- a/bindings/ruby/sfml-graphics/graphics/Image.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Image.cpp @@ -517,6 +517,19 @@ static VALUE Image_GetTexCoords( VALUE self, VALUE aRectangle ) rb_float_new( result.Width ), rb_float_new( result.Height ) ); } +static VALUE Image_Initialize( int argc, VALUE *args, VALUE self ) +{ + if( argc > 1 ) + { + rb_funcall2( self, rb_intern( "loadFromPixels" ), argc, args ); + } + else if( argc > 0 ) + { + rb_funcall2( self, rb_intern( "loadFromFile" ), argc, args ); + } + return self; +} + static VALUE Image_InitializeCopy( VALUE self, VALUE aSource ) { sf::Image *object = NULL; @@ -605,6 +618,7 @@ void Init_Image( void ) rb_define_singleton_method( globalImageClass, "getMaximumSize", Image_GetMaximumSize, 0 ); // Instance methods + rb_define_method( globalImageClass, "initialize", Image_Initialize, 1 ); rb_define_method( globalImageClass, "initialize_copy", Image_InitializeCopy, 1 ); rb_define_method( globalImageClass, "loadFromFile", Image_LoadFromFile, 1 ); rb_define_method( globalImageClass, "loadFromPixels", Image_LoadFromPixels, 3 ); diff --git a/bindings/ruby/sfml-graphics/graphics/Shader.cpp b/bindings/ruby/sfml-graphics/graphics/Shader.cpp index 4da50bc19..eb588d0f8 100644 --- a/bindings/ruby/sfml-graphics/graphics/Shader.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Shader.cpp @@ -215,6 +215,16 @@ static VALUE Shader_Unbind( VALUE self ) return Qnil; } + +static VALUE Shader_Initialize( int argc, VALUE *args, VALUE self ) +{ + if( argc > 0 ) + { + rb_funcall2( self, rb_intern( "loadFromFile" ), argc, args ); + } + return self; +} + static VALUE Shader_InitializeCopy( VALUE self, VALUE aSource ) { sf::Shader *object = NULL; @@ -325,6 +335,7 @@ void Init_Shader( void ) rb_define_const( globalShaderClass, "CurrentTexture", CreateCurrentTextureWrapper() ); // Instance methods + rb_define_method( globalShaderClass, "initialize", Shader_Initialize, -1 ); rb_define_method( globalShaderClass, "initialize_copy", Shader_InitializeCopy, 1 ); rb_define_method( globalShaderClass, "loadFromFile", Shader_LoadFromFile, 1 ); rb_define_method( globalShaderClass, "loadFromMemory", Shader_LoadFromMemory, 1 );