Added a #initialize_copy method to all classes which are wrapped around a C++ object in order to properly copy the values.

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1740 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
groogy 2010-12-03 19:47:41 +00:00
parent 0920da5d8e
commit bb7a6fac1f
14 changed files with 156 additions and 8 deletions

View File

@ -193,6 +193,15 @@ static VALUE SoundBuffer_GetDuration( VALUE self )
return rb_float_new( object->GetDuration() );
}
static VALUE SoundBuffer_InitializeCopy( VALUE self, VALUE aSource )
{
sf::SoundBuffer *object = NULL;
Data_Get_Struct( self, sf::SoundBuffer, object );
sf::SoundBuffer *source = NULL;
Data_Get_Struct( aSource, sf::SoundBuffer, source );
*object = *source;
}
/* call-seq:
* SoundBuffer.new() -> sound_buffer
*
@ -264,6 +273,7 @@ void Init_SoundBuffer( void )
rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 );
// Instance methods
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 );
rb_define_method( globalSoundBufferClass, "saveToFile", SoundBuffer_SaveToFile, 1 );

View File

@ -237,6 +237,15 @@ static VALUE SoundSource_SetVolume( VALUE self, VALUE aValue )
return Qnil;
}
static VALUE SoundSource_InitializeCopy( VALUE self, VALUE aSource )
{
sf::SoundSource *object = NULL;
Data_Get_Struct( self, sf::SoundSource, object );
sf::SoundSource *source = NULL;
Data_Get_Struct( aSource, sf::SoundSource, source );
*object = *source;
}
static void DefineStatusEnum( void )
{
rb_define_const( globalSoundSourceClass, "Stopped", INT2FIX( sf::SoundSource::Stopped ) );
@ -260,6 +269,7 @@ void Init_SoundSource( void )
DefineStatusEnum();
// Instance methods
rb_define_method( globalSoundSourceClass, "initialize_copy", SoundSource_InitializeCopy, 1 );
rb_define_method( globalSoundSourceClass, "getAttenuation", SoundSource_GetAttenuation, 0 );
rb_define_method( globalSoundSourceClass, "getMinDistance", SoundSource_GetMinDistance, 0 );
rb_define_method( globalSoundSourceClass, "getPitch", SoundSource_GetPitch, 0 );

View File

@ -130,6 +130,15 @@ static VALUE Font_GetImage( VALUE self, VALUE aCharacterSize )
return rbImage;
}
static VALUE Font_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Font *object = NULL;
Data_Get_Struct( self, sf::Font, object );
sf::Font *source = NULL;
Data_Get_Struct( aSource, sf::Font, source );
*object = *source;
}
/* call-seq:
* Font.new() -> font
*
@ -219,6 +228,7 @@ void Init_Font( void )
rb_define_singleton_method( globalFontClass, "getDefaultFont", Font_GetDefaultFont, 0 );
// Instance methods
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 );
rb_define_method( globalFontClass, "getKerning", Font_GetKerning, 3 );

View File

@ -42,6 +42,15 @@ static VALUE Glyph_Initialize( VALUE self )
return self;
}
static VALUE Glyph_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Glyph *object = NULL;
Data_Get_Struct( self, sf::Glyph, object );
sf::Glyph *source = NULL;
Data_Get_Struct( aSource, sf::Glyph, source );
*object = *source;
}
void Init_Glyph( void )
{
/* SFML namespace which contains the classes of this module. */
@ -58,6 +67,10 @@ void Init_Glyph( void )
*/
globalGlyphClass = rb_define_class_under( sfml, "Glyph", rb_cObject );
// Instance methods
rb_define_method( globalGlyphClass, "initialize", Glyph_Initialize, 0 );
rb_define_method( globalGlyphClass, "initialize_copy", Glyph_InitializeCopy, 1 );
// Attribute accessors
rb_define_attr( globalGlyphClass, "advance", 1, 1 );
rb_define_attr( globalGlyphClass, "bounds", 1, 1 );

View File

@ -517,16 +517,25 @@ static VALUE Image_GetTexCoords( VALUE self, VALUE aRectangle )
rb_float_new( result.Width ), rb_float_new( result.Height ) );
}
static VALUE Image_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Image *object = NULL;
Data_Get_Struct( self, sf::Image, object );
sf::Image *source = NULL;
Data_Get_Struct( aSource, sf::Image, source );
*object = *source;
}
/* call-seq:
* Image.new() -> image
*
* Creates an image instance for us.
*/
static VALUE Image_New( VALUE aKlass )
static VALUE Image_New( int argc, VALUE *args, VALUE aKlass )
{
sf::Image *object = new sf::Image();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Image_Free, object );
rb_obj_call_init( rbData, 0, 0 );
rb_obj_call_init( rbData, argc, args );
return rbData;
}
@ -592,10 +601,11 @@ void Init_Image( void )
globalImageClass = rb_define_class_under( sfml, "Image", rb_cObject );
// Class methods
rb_define_singleton_method( globalImageClass, "new", Image_New, 0 );
rb_define_singleton_method( globalImageClass, "new", Image_New, -1 );
rb_define_singleton_method( globalImageClass, "getMaximumSize", Image_GetMaximumSize, 0 );
// Instance methods
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 );
rb_define_method( globalImageClass, "saveToFile", Image_SaveToFile, 1 );

View File

@ -215,6 +215,15 @@ static VALUE Shader_Unbind( VALUE self )
return Qnil;
}
static VALUE Shader_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Shader *object = NULL;
Data_Get_Struct( self, sf::Shader, object );
sf::Shader *source = NULL;
Data_Get_Struct( aSource, sf::Shader, source );
*object = *source;
}
/* call-seq:
* Shader.new()
*
@ -316,6 +325,7 @@ void Init_Shader( void )
rb_define_const( globalShaderClass, "CurrentTexture", CreateCurrentTextureWrapper() );
// Instance methods
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 );
rb_define_method( globalShaderClass, "setParameter", Shader_SetParameter, -1 );

View File

@ -330,6 +330,15 @@ static VALUE Shape_GetOutlineWidth( VALUE self )
return rb_float_new( object->GetOutlineWidth() );
}
static VALUE Shape_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Shape *object = NULL;
Data_Get_Struct( self, sf::Shape, object );
sf::Shape *source = NULL;
Data_Get_Struct( aSource, sf::Shape, source );
*object = *source;
}
/* call-seq:
* Shape.new() -> shape
*
@ -643,6 +652,7 @@ void Init_Shape( void )
rb_define_singleton_method( globalShapeClass, "circle", Shape_Circle, -1 );
// Instance methods
rb_define_method( globalShapeClass, "initialize_copy", Shape_InitializeCopy, 1 );
rb_define_method( globalShapeClass, "addPoint", Shape_AddPoint, -1 );
rb_define_method( globalShapeClass, "getPointsCount", Shape_GetPointsCount, 0 );
rb_define_method( globalShapeClass, "enableFill", Shape_EnableFill, 1 );

View File

@ -88,6 +88,15 @@ static VALUE Sprite_Initialize( int argc, VALUE *args, VALUE self )
return self;
}
static VALUE Sprite_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Sprite *object = NULL;
Data_Get_Struct( self, sf::Sprite, object );
sf::Sprite *source = NULL;
Data_Get_Struct( aSource, sf::Sprite, source );
*object = *source;
}
/* call-seq:
* sprite.setImage( image, adjustToNewSize = false)
*
@ -355,6 +364,7 @@ void Init_Sprite( void )
// Instance methods
rb_define_method( globalSpriteClass, "initialize", Sprite_Initialize, -1 );
rb_define_method( globalSpriteClass, "initialize_copy", Sprite_InitializeCopy, 1 );
rb_define_method( globalSpriteClass, "setImage", Sprite_SetImage, -1 );
rb_define_method( globalSpriteClass, "setSubRect", Sprite_SetSubRect, 1 );
rb_define_method( globalSpriteClass, "resize", Sprite_Resize, -1 );

View File

@ -76,6 +76,15 @@ static VALUE Text_Initialize( int argc, VALUE *args, VALUE self )
return self;
}
static VALUE Text_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Text *object = NULL;
Data_Get_Struct( self, sf::Text, object );
sf::Text *source = NULL;
Data_Get_Struct( aSource, sf::Text, source );
*object = *source;
}
/* call-seq:
* text.setString( string )
*
@ -288,6 +297,7 @@ void Init_Text( void )
// Instance methods
rb_define_method( globalTextClass, "initialize", Text_Initialize, -1 );
rb_define_method( globalTextClass, "initialize_copy", Text_InitializeCopy, 1 );
rb_define_method( globalTextClass, "setString", Text_SetString, 1 );
rb_define_method( globalTextClass, "setFont", Text_SetFont, 1 );
rb_define_method( globalTextClass, "setCharacterSize", Text_SetCharacterSize, 1 );

View File

@ -86,6 +86,15 @@ static VALUE View_Initialize( int argc, VALUE *args, VALUE self )
return self;
}
static VALUE View_InitializeCopy( VALUE self, VALUE aSource )
{
sf::View *object = NULL;
Data_Get_Struct( self, sf::View, object );
sf::View *source = NULL;
Data_Get_Struct( aSource, sf::View, source );
*object = *source;
}
/* call-seq:
* view.getCenter() -> vector2
*
@ -403,6 +412,7 @@ void Init_View( void )
// Instance methods
rb_define_method( globalViewClass, "initialize", View_Initialize, -1 );
rb_define_method( globalViewClass, "initialize_copy", View_InitializeCopy, 1 );
rb_define_method( globalViewClass, "setCenter", View_SetCenter, -1 );
rb_define_method( globalViewClass, "setSize", View_SetSize, -1 );
rb_define_method( globalViewClass, "setRotation", View_SetRotation, 1 );

View File

@ -60,16 +60,26 @@ static VALUE Clock_Reset( VALUE self )
return Qnil;
}
static VALUE Clock_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Clock *object = NULL;
Data_Get_Struct( self, sf::Clock, object );
sf::Clock *source = NULL;
Data_Get_Struct( aSource, sf::Clock, source );
*object = *source ;
return self;
}
/* call-seq:
* Clock.new() -> clock
*
* The clock starts automatically after being constructed.
*/
static VALUE Clock_New( VALUE aKlass )
static VALUE Clock_New( int argc, VALUE *args VALUE aKlass )
{
sf::Clock *object = new sf::Clock();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Clock_Free, object );
rb_obj_call_init( rbData, 0, 0 );
rb_obj_call_init( rbData, argc, args );
return rbData;
}
@ -86,9 +96,10 @@ void Init_Clock( void )
globalClockClass = rb_define_class_under( sfml, "Clock", rb_cObject );
// Class methods
rb_define_singleton_method( globalClockClass, "new", Clock_New, 0 );
rb_define_singleton_method( globalClockClass, "new", Clock_New, -1 );
// Instance methods
rb_define_method( globalClockClass, "initialize_copy", Clock_InitializeCopy, 1 );
rb_define_method( globalClockClass, "getElapsedTime", Clock_GetElapsedTime, 0 );
rb_define_method( globalClockClass, "reset", Clock_Reset, 0 );

View File

@ -156,6 +156,16 @@ static VALUE ContextSettings_SetMinorVersion( VALUE self, VALUE aValue )
return INT2FIX( object->MinorVersion = NUM2UINT( aValue ) );
}
static VALUE ContextSettings_InitializeCopy( VALUE self, VALUE aSource )
{
sf::ContextSettings *object = NULL;
Data_Get_Struct( self, sf::ContextSettings, object );
sf::ContextSettings *source = NULL;
Data_Get_Struct( aSource, sf::ContextSettings, source );
*object = *source;
return self;
}
/* call-seq:
* ContextSettings.new( depth = 24, stencil = 8, antialiasing = 0, major = 2, minor = 0) -> settings
*
@ -212,7 +222,7 @@ static VALUE ContextSettings_New( VALUE aKlass, VALUE someArgs )
}
VALUE rbData = Data_Wrap_Struct( aKlass, 0, ContextSettings_Free, object );
rb_obj_call_init( rbData, 0, 0 );
rb_obj_call_init( rbData, argc, args );
return rbData;
}
@ -251,6 +261,8 @@ void Init_ContextSettings( void )
rb_define_singleton_method( globalContextSettingsClass, "new", ContextSettings_New, -2 );
// Instance methods
rb_define_method( globalContextSettingsClass, "initialize_copy", ContextSettings_InitializeCopy, 1 );
rb_define_method( globalContextSettingsClass, "depthBits", ContextSettings_GetDepth, 0 );
rb_define_method( globalContextSettingsClass, "depthBits=", ContextSettings_SetDepth, 1 );

View File

@ -214,6 +214,16 @@ static VALUE Event_Initialize( VALUE self, VALUE aType )
}
}
static VALUE Event_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Event *object = NULL;
Data_Get_Struct( self, sf::Event, object );
sf::Event *source = NULL;
Data_Get_Struct( aSource, sf::Event, source );
*object = *source;
return Event_Initialize( VALUE self, INT2FIX( object->Type ) );
}
/* call-seq:
* Event.new(type) -> event
*
@ -230,7 +240,6 @@ static VALUE Event_New( int argc, VALUE * args, VALUE aKlass )
return rbData;
}
void Init_Event( void )
{
/* SFML namespace which contains the classes of this module. */
@ -302,6 +311,8 @@ void Init_Event( void )
// Instance methods
rb_define_method( globalEventClass, "initialize", Event_Initialize, 1 );
rb_define_method( globalEventClass, "initialize_copy", Event_InitializeCopy, 1 );
rb_define_attr( globalEventClass, "type", 1, 0 );
rb_define_attr( globalEventClass, "joyButton", 1, 0 );
rb_define_attr( globalEventClass, "joyMove", 1, 0 );

View File

@ -152,6 +152,15 @@ static VALUE VideoMode_IsValid( VALUE self )
return ( object->IsValid() == true ? Qtrue : Qfalse );
}
static VALUE VideoMode_InitializeCopy( VALUE self, VALUE aSource )
{
sf::VideoMode *object = NULL;
Data_Get_Struct( self, sf::VideoMode, object );
sf::VideoMode *source = NULL;
Data_Get_Struct( aSource, sf::VideoMode, source );
*object = *source;
}
/* call-seq:
* VideoMode.getDesktopMode -> desktop_mode
*
@ -260,6 +269,8 @@ void Init_VideoMode( void )
rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", VideoMode_GetFullscreenModes, 0 );
// Instance methods
rb_define_method( globalVideoModeClass, "initialize_copy", VideoMode_InitializeCopy, 1 );
rb_define_method( globalVideoModeClass, "width", VideoMode_GetWidth, 0 );
rb_define_method( globalVideoModeClass, "width=", VideoMode_SetWidth, 1 );