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
This commit is contained in:
groogy 2010-12-04 19:26:05 +00:00
parent 44e811ec64
commit aa39447c26
5 changed files with 64 additions and 11 deletions

View File

@ -34,16 +34,6 @@ static VALUE Music_Free( sf::Music *anObject )
delete 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: /* call-seq:
* music.openFromFile() -> true or false * 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: /* call-seq:
* music.getDuration() -> float * music.getDuration() -> float
* *
@ -130,7 +134,7 @@ void Init_Music( void )
rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 ); rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 );
// Instance methods // 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, "openFromFile", Music_OpenFromFile, 1 );
rb_define_method( globalMusicClass, "getDuration", Music_GetDuration, 0 ); rb_define_method( globalMusicClass, "getDuration", Music_GetDuration, 0 );

View File

@ -193,6 +193,19 @@ static VALUE SoundBuffer_GetDuration( VALUE self )
return rb_float_new( object->GetDuration() ); 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 ) static VALUE SoundBuffer_InitializeCopy( VALUE self, VALUE aSource )
{ {
sf::SoundBuffer *object = NULL; sf::SoundBuffer *object = NULL;
@ -273,6 +286,7 @@ void Init_SoundBuffer( void )
rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 ); rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 );
// Instance methods // Instance methods
rb_define_method( globalSoundBufferClass, "initialize", SoundBuffer_Initialize, -1 );
rb_define_method( globalSoundBufferClass, "initialize_copy", SoundBuffer_InitializeCopy, 1 ); rb_define_method( globalSoundBufferClass, "initialize_copy", SoundBuffer_InitializeCopy, 1 );
rb_define_method( globalSoundBufferClass, "loadFromFile", SoundBuffer_LoadFromFile, 1 ); rb_define_method( globalSoundBufferClass, "loadFromFile", SoundBuffer_LoadFromFile, 1 );
rb_define_method( globalSoundBufferClass, "loadFromSamples", SoundBuffer_LoadFromSamples, 4 ); rb_define_method( globalSoundBufferClass, "loadFromSamples", SoundBuffer_LoadFromSamples, 4 );

View File

@ -130,6 +130,15 @@ static VALUE Font_GetImage( VALUE self, VALUE aCharacterSize )
return rbImage; 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 ) static VALUE Font_InitializeCopy( VALUE self, VALUE aSource )
{ {
sf::Font *object = NULL; sf::Font *object = NULL;
@ -228,6 +237,7 @@ void Init_Font( void )
rb_define_singleton_method( globalFontClass, "getDefaultFont", Font_GetDefaultFont, 0 ); rb_define_singleton_method( globalFontClass, "getDefaultFont", Font_GetDefaultFont, 0 );
// Instance methods // Instance methods
rb_define_method( globalFontClass, "initialize", Font_Initialize, -1 );
rb_define_method( globalFontClass, "initialize_copy", Font_InitializeCopy, 1 ); rb_define_method( globalFontClass, "initialize_copy", Font_InitializeCopy, 1 );
rb_define_method( globalFontClass, "loadFromFile", Font_LoadFromFile, 1 ); rb_define_method( globalFontClass, "loadFromFile", Font_LoadFromFile, 1 );
rb_define_method( globalFontClass, "getGlyph", Font_GetGlyph, 3 ); rb_define_method( globalFontClass, "getGlyph", Font_GetGlyph, 3 );

View File

@ -517,6 +517,19 @@ static VALUE Image_GetTexCoords( VALUE self, VALUE aRectangle )
rb_float_new( result.Width ), rb_float_new( result.Height ) ); 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 ) static VALUE Image_InitializeCopy( VALUE self, VALUE aSource )
{ {
sf::Image *object = NULL; sf::Image *object = NULL;
@ -605,6 +618,7 @@ void Init_Image( void )
rb_define_singleton_method( globalImageClass, "getMaximumSize", Image_GetMaximumSize, 0 ); rb_define_singleton_method( globalImageClass, "getMaximumSize", Image_GetMaximumSize, 0 );
// Instance methods // Instance methods
rb_define_method( globalImageClass, "initialize", Image_Initialize, 1 );
rb_define_method( globalImageClass, "initialize_copy", Image_InitializeCopy, 1 ); rb_define_method( globalImageClass, "initialize_copy", Image_InitializeCopy, 1 );
rb_define_method( globalImageClass, "loadFromFile", Image_LoadFromFile, 1 ); rb_define_method( globalImageClass, "loadFromFile", Image_LoadFromFile, 1 );
rb_define_method( globalImageClass, "loadFromPixels", Image_LoadFromPixels, 3 ); rb_define_method( globalImageClass, "loadFromPixels", Image_LoadFromPixels, 3 );

View File

@ -215,6 +215,16 @@ static VALUE Shader_Unbind( VALUE self )
return Qnil; 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 ) static VALUE Shader_InitializeCopy( VALUE self, VALUE aSource )
{ {
sf::Shader *object = NULL; sf::Shader *object = NULL;
@ -325,6 +335,7 @@ void Init_Shader( void )
rb_define_const( globalShaderClass, "CurrentTexture", CreateCurrentTextureWrapper() ); rb_define_const( globalShaderClass, "CurrentTexture", CreateCurrentTextureWrapper() );
// Instance methods // Instance methods
rb_define_method( globalShaderClass, "initialize", Shader_Initialize, -1 );
rb_define_method( globalShaderClass, "initialize_copy", Shader_InitializeCopy, 1 ); rb_define_method( globalShaderClass, "initialize_copy", Shader_InitializeCopy, 1 );
rb_define_method( globalShaderClass, "loadFromFile", Shader_LoadFromFile, 1 ); rb_define_method( globalShaderClass, "loadFromFile", Shader_LoadFromFile, 1 );
rb_define_method( globalShaderClass, "loadFromMemory", Shader_LoadFromMemory, 1 ); rb_define_method( globalShaderClass, "loadFromMemory", Shader_LoadFromMemory, 1 );