Some refactoring, moved C++ allocation into the *_Alloc function instead of directly in new, removed new in most of classes too. Cloning should work on all copyable classes now.

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1802 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
groogy 2011-02-27 14:07:10 +00:00
parent 0a2abc6933
commit 7d7c4c999f
26 changed files with 235 additions and 301 deletions

View File

@ -86,12 +86,10 @@ static VALUE Music_GetDuration( VALUE self )
return rb_float_new( object->GetDuration() ); return rb_float_new( object->GetDuration() );
} }
static VALUE Music_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Music_Alloc( VALUE aKlass )
{ {
sf::Music *object = new sf::Music(); sf::Music *object = new sf::Music();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Music_Free, object ); return Data_Wrap_Struct( aKlass, 0, Music_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Music( void ) void Init_Music( void )
@ -134,7 +132,8 @@ void Init_Music( void )
globalMusicClass = rb_define_class_under( sfml, "Music", globalSoundStreamClass ); globalMusicClass = rb_define_class_under( sfml, "Music", globalSoundStreamClass );
// Class methods // Class methods
rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 ); //rb_define_singleton_method( globalMusicClass, "new", Music_New, -1 );
rb_define_alloc_func( globalMusicClass, Music_Alloc );
// Instance methods // Instance methods
rb_define_method( globalMusicClass, "initialize", Music_Initialize, -1 ); rb_define_method( globalMusicClass, "initialize", Music_Initialize, -1 );

View File

@ -91,6 +91,16 @@ static VALUE Sound_Initialize( int argc, VALUE *args, VALUE self )
return self; return self;
} }
static VALUE Sound_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Sound *selfObject = NULL;
Data_Get_Struct( self, sf::Sound, selfObject );
sf::Sound *sourceObject = NULL;
Data_Get_Struct( aSource, sf::Sound, sourceObject );
*selfObject = *sourceObject;
return self;
}
/* call-seq: /* call-seq:
* sound.play() * sound.play()
* *
@ -269,12 +279,10 @@ static VALUE Sound_ResetBuffer( VALUE self )
return Qnil; return Qnil;
} }
static VALUE Sound_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Sound_Alloc( VALUE aKlass )
{ {
sf::Sound *object = new sf::Sound(); sf::Sound *object = new sf::Sound();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Sound_Free, object ); return Data_Wrap_Struct( aKlass, 0, Sound_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Sound( void ) void Init_Sound( void )
@ -312,10 +320,12 @@ void Init_Sound( void )
globalSoundClass = rb_define_class_under( sfml, "Sound", globalSoundSourceClass ); globalSoundClass = rb_define_class_under( sfml, "Sound", globalSoundSourceClass );
// Class methods // Class methods
rb_define_singleton_method( globalSoundClass, "new", Sound_New, -1 ); //rb_define_singleton_method( globalSoundClass, "new", Sound_New, -1 );
rb_define_alloc_func( globalSoundClass, Sound_Alloc );
// Instance methods // Instance methods
rb_define_method( globalSoundClass, "initialize", Sound_Initialize, 0 ); rb_define_method( globalSoundClass, "initialize", Sound_Initialize, 0 );
rb_define_method( globalSoundClass, "initialize_copy", Sound_InitializeCopy, 1 );
rb_define_method( globalSoundClass, "play", Sound_Play, 0 ); rb_define_method( globalSoundClass, "play", Sound_Play, 0 );
rb_define_method( globalSoundClass, "pause", Sound_Pause, 0 ); rb_define_method( globalSoundClass, "pause", Sound_Pause, 0 );
rb_define_method( globalSoundClass, "stop", Sound_Stop, 0 ); rb_define_method( globalSoundClass, "stop", Sound_Stop, 0 );

View File

@ -231,12 +231,10 @@ static VALUE SoundBuffer_InitializeCopy( VALUE self, VALUE aSource )
* *
* Creates an sound buffer instance for us. * Creates an sound buffer instance for us.
*/ */
static VALUE SoundBuffer_New( int argc, VALUE *args, VALUE aKlass ) static VALUE SoundBuffer_Alloc( VALUE aKlass )
{ {
sf::SoundBuffer *object = new sf::SoundBuffer(); sf::SoundBuffer *object = new sf::SoundBuffer();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundBuffer_Free, object ); return Data_Wrap_Struct( aKlass, 0, SoundBuffer_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_SoundBuffer( void ) void Init_SoundBuffer( void )
@ -294,7 +292,8 @@ void Init_SoundBuffer( void )
globalSoundBufferClass = rb_define_class_under( sfml, "SoundBuffer", rb_cObject ); globalSoundBufferClass = rb_define_class_under( sfml, "SoundBuffer", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 ); //rb_define_singleton_method( globalSoundBufferClass, "new", SoundBuffer_New, -1 );
rb_define_alloc_func( globalSoundBufferClass, SoundBuffer_Alloc );
// Instance methods // Instance methods
rb_define_method( globalSoundBufferClass, "initialize", SoundBuffer_Initialize, -1 ); rb_define_method( globalSoundBufferClass, "initialize", SoundBuffer_Initialize, -1 );

View File

@ -126,12 +126,10 @@ static VALUE SoundBufferRecorder_GetBuffer( VALUE self )
* *
* Creates a sound buffer recorder instance for us. * Creates a sound buffer recorder instance for us.
*/ */
static VALUE SoundBufferRecorder_New( int argc, VALUE *args, VALUE aKlass ) static VALUE SoundBufferRecorder_Alloc( VALUE aKlass )
{ {
rbSoundBufferRecorder *object = new rbSoundBufferRecorder(); rbSoundBufferRecorder *object = new rbSoundBufferRecorder();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundBufferRecorder_Free, object ); return Data_Wrap_Struct( aKlass, 0, SoundBufferRecorder_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_SoundBufferRecorder( void ) void Init_SoundBufferRecorder( void )
@ -201,7 +199,8 @@ void Init_SoundBufferRecorder( void )
globalSoundBufferRecorderClass = rb_define_class_under( sfml, "SoundBufferRecorder", globalSoundRecorderClass ); globalSoundBufferRecorderClass = rb_define_class_under( sfml, "SoundBufferRecorder", globalSoundRecorderClass );
// Class methods // Class methods
rb_define_singleton_method( globalSoundBufferRecorderClass, "new", SoundBufferRecorder_New, -1 ); //rb_define_singleton_method( globalSoundBufferRecorderClass, "new", SoundBufferRecorder_New, -1 );
rb_define_alloc_func( globalSoundBufferRecorderClass, SoundBufferRecorder_Alloc );
// Instance methods // Instance methods
rb_define_method( globalSoundRecorderClass, "getBuffer", SoundBufferRecorder_GetBuffer, 0 ); rb_define_method( globalSoundRecorderClass, "getBuffer", SoundBufferRecorder_GetBuffer, 0 );

View File

@ -161,12 +161,10 @@ static VALUE SoundRecorder_GetSampleRate( VALUE self )
* *
* Creates a sound recorder instance for us. * Creates a sound recorder instance for us.
*/ */
static VALUE SoundRecorder_New( int argc, VALUE *args, VALUE aKlass ) static VALUE SoundRecorder_Alloc( VALUE aKlass )
{ {
rbSoundRecorder *object = new rbSoundRecorder(); rbSoundRecorder *object = new rbSoundRecorder();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundRecorder_Free, object ); return Data_Wrap_Struct( aKlass, 0, SoundRecorder_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
/* call-seq: /* call-seq:
@ -250,7 +248,8 @@ void Init_SoundRecorder( void )
rb_include_module( globalSoundRecorderClass, globalNonCopyableModule ); rb_include_module( globalSoundRecorderClass, globalNonCopyableModule );
// Class methods // Class methods
rb_define_singleton_method( globalSoundRecorderClass, "new", SoundRecorder_New, -1 ); //rb_define_singleton_method( globalSoundRecorderClass, "new", SoundRecorder_New, -1 );
rb_define_alloc_func( globalSoundRecorderClass, SoundRecorder_Alloc );
rb_define_singleton_method( globalSoundRecorderClass, "isAvailable", SoundRecorder_IsAvailable, 0 ); rb_define_singleton_method( globalSoundRecorderClass, "isAvailable", SoundRecorder_IsAvailable, 0 );
// Instance methods // Instance methods

View File

@ -237,13 +237,9 @@ static VALUE SoundSource_SetVolume( VALUE self, VALUE aValue )
return Qnil; return Qnil;
} }
static VALUE SoundSource_InitializeCopy( VALUE self, VALUE aSource ) static VALUE SoundSource_Initialize( VALUE self )
{ {
sf::SoundSource *object = NULL; rb_raise( rb_eNotImpError, "Trying to construct instance of abstract class" );
Data_Get_Struct( self, sf::SoundSource, object );
sf::SoundSource *source = NULL;
Data_Get_Struct( aSource, sf::SoundSource, source );
*object = *source;
} }
static void DefineStatusEnum( void ) static void DefineStatusEnum( void )
@ -269,7 +265,6 @@ void Init_SoundSource( void )
DefineStatusEnum(); DefineStatusEnum();
// Instance methods // Instance methods
rb_define_method( globalSoundSourceClass, "initialize_copy", SoundSource_InitializeCopy, 1 );
rb_define_method( globalSoundSourceClass, "getAttenuation", SoundSource_GetAttenuation, 0 ); rb_define_method( globalSoundSourceClass, "getAttenuation", SoundSource_GetAttenuation, 0 );
rb_define_method( globalSoundSourceClass, "getMinDistance", SoundSource_GetMinDistance, 0 ); rb_define_method( globalSoundSourceClass, "getMinDistance", SoundSource_GetMinDistance, 0 );
rb_define_method( globalSoundSourceClass, "getPitch", SoundSource_GetPitch, 0 ); rb_define_method( globalSoundSourceClass, "getPitch", SoundSource_GetPitch, 0 );

View File

@ -287,12 +287,11 @@ static VALUE SoundStream_Initialize( VALUE self, VALUE channelsCount, VALUE samp
return self; return self;
} }
static VALUE SoundStream_New( int argc, VALUE *args, VALUE aKlass ) static VALUE SoundStream_Alloc( VALUE aKlass )
{ {
rbSoundStream *object = new rbSoundStream(); rbSoundStream *object = new rbSoundStream();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundStream_Free, object ); VALUE rbData = Data_Wrap_Struct( aKlass, 0, SoundStream_Free, object );
object->Init( rbData ); object->Init( rbData );
rb_obj_call_init( rbData, argc, args );
return rbData; return rbData;
} }
@ -361,7 +360,8 @@ void Init_SoundStream( void )
rb_include_module( globalSoundStreamClass, globalNonCopyableModule ); rb_include_module( globalSoundStreamClass, globalNonCopyableModule );
// Class methods // Class methods
rb_define_singleton_method( globalSoundStreamClass, "new", SoundStream_New, -1 ); //rb_define_singleton_method( globalSoundStreamClass, "new", SoundStream_New, -1 );
rb_define_alloc_func( globalSoundStreamClass, SoundStream_Alloc );
// Instance methods // Instance methods
rb_define_method( globalSoundStreamClass, "initialize", SoundStream_Initialize, 2 ); rb_define_method( globalSoundStreamClass, "initialize", SoundStream_Initialize, 2 );

View File

@ -529,18 +529,28 @@ static VALUE Drawable_Initialize( int argc, VALUE *args, VALUE self )
return rb_call_super( argc, args ); return rb_call_super( argc, args );
} }
static VALUE Drawable_New( int argc, VALUE *args, VALUE aKlass )
static VALUE Drawable_InitializeCopy( VALUE self, VALUE aSource )
{
sf::Drawable *selfDrawable = NULL;
Data_Get_Struct( self, sf::Drawable, selfDrawable );
sf::Drawable *sourceDrawable = NULL;
Data_Get_Struct( aSource, sf::Drawable, sourceDrawable );
*selfDrawable = *sourceDrawable;
return self;
}
static VALUE Drawable_Allocate( VALUE aKlass )
{ {
rbDrawable *object = new rbDrawable(); rbDrawable *object = new rbDrawable();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Drawable_Free, object ); VALUE rbData = Data_Wrap_Struct( aKlass, 0, Drawable_Free, object );
object->Init( rbData ); object->Init( rbData );
rb_obj_call_init( rbData, argc, args );
return rbData; return rbData;
} }
static VALUE Drawable_Included( VALUE aModule, VALUE aBase ) static VALUE Drawable_Included( VALUE aModule, VALUE aBase )
{ {
rb_define_singleton_method( aBase, "new", Drawable_New, -1 ); rb_define_singleton_method( aBase, "allocate", Drawable_Allocate, 0 );
return Qnil; return Qnil;
} }
@ -615,6 +625,7 @@ void Init_Drawable( void )
// Instance methods // Instance methods
rb_define_method( globalDrawableModule, "initialize", Drawable_Initialize, -1 ); rb_define_method( globalDrawableModule, "initialize", Drawable_Initialize, -1 );
rb_define_method( globalDrawableModule, "initialize_copy", Drawable_Initialize, 1 );
rb_define_method( globalDrawableModule, "setPosition", Drawable_SetPosition, -1 ); rb_define_method( globalDrawableModule, "setPosition", Drawable_SetPosition, -1 );
rb_define_method( globalDrawableModule, "setX", Drawable_SetX, 1 ); rb_define_method( globalDrawableModule, "setX", Drawable_SetX, 1 );
rb_define_method( globalDrawableModule, "setY", Drawable_SetY, 1 ); rb_define_method( globalDrawableModule, "setY", Drawable_SetY, 1 );

View File

@ -156,17 +156,10 @@ static VALUE Font_InitializeCopy( VALUE self, VALUE aSource )
*object = *source; *object = *source;
} }
/* call-seq: static VALUE Font_Alloc( VALUE aKlass )
* Font.new() -> font
*
* Creates an empty font
*/
static VALUE Font_New( int argc, VALUE *args, VALUE aKlass )
{ {
sf::Font *object = new sf::Font(); sf::Font *object = new sf::Font();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Font_Free, object ); return Data_Wrap_Struct( aKlass, 0, Font_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
/* call-seq: /* call-seq:
@ -241,7 +234,8 @@ void Init_Font( void )
globalFontClass = rb_define_class_under( sfml, "Font", rb_cObject ); globalFontClass = rb_define_class_under( sfml, "Font", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalFontClass, "new", Font_New, -1 ); //rb_define_singleton_method( globalFontClass, "new", Font_New, -1 );
rb_define_alloc_func( globalFontClass, Font_Alloc );
rb_define_singleton_method( globalFontClass, "getDefaultFont", Font_GetDefaultFont, 0 ); rb_define_singleton_method( globalFontClass, "getDefaultFont", Font_GetDefaultFont, 0 );
// Instance methods // Instance methods

View File

@ -43,15 +43,6 @@ static VALUE Glyph_Initialize( VALUE self )
return 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 ) void Init_Glyph( void )
{ {
/* SFML namespace which contains the classes of this module. */ /* SFML namespace which contains the classes of this module. */
@ -70,7 +61,6 @@ void Init_Glyph( void )
// Instance methods // Instance methods
rb_define_method( globalGlyphClass, "initialize", Glyph_Initialize, 0 ); rb_define_method( globalGlyphClass, "initialize", Glyph_Initialize, 0 );
rb_define_method( globalGlyphClass, "initialize_copy", Glyph_InitializeCopy, 1 );
// Attribute accessors // Attribute accessors
rb_define_attr( globalGlyphClass, "advance", 1, 1 ); rb_define_attr( globalGlyphClass, "advance", 1, 1 );

View File

@ -524,8 +524,8 @@ static VALUE Image_GetTexCoords( VALUE self, VALUE aRectangle )
* *
* Will create a new image instance. * Will create a new image instance.
* *
* If a filename argument is specified then image#loadFromFile will be called on the created instance. If width, height * If a filename argument is specified then Image#loadFromFile will be called on the created instance. If width, height
* and pixels are specified then image#loadFromPixels will be called on the created instance. * and pixels are specified then Image#loadFromPixels will be called on the created instance.
*/ */
static VALUE Image_Initialize( int argc, VALUE *args, VALUE self ) static VALUE Image_Initialize( int argc, VALUE *args, VALUE self )
{ {
@ -549,17 +549,10 @@ static VALUE Image_InitializeCopy( VALUE self, VALUE aSource )
*object = *source; *object = *source;
} }
/* call-seq: static VALUE Image_Alloc( VALUE aKlass )
* Image.new() -> image
*
* Creates an image instance for us.
*/
static VALUE Image_New( int argc, VALUE *args, VALUE aKlass )
{ {
sf::Image *object = new sf::Image(); sf::Image *object = new sf::Image();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Image_Free, object ); return Data_Wrap_Struct( aKlass, 0, Image_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
/* call-seq: /* call-seq:
@ -624,7 +617,8 @@ void Init_Image( void )
globalImageClass = rb_define_class_under( sfml, "Image", rb_cObject ); globalImageClass = rb_define_class_under( sfml, "Image", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalImageClass, "new", Image_New, -1 ); //rb_define_singleton_method( globalImageClass, "new", Image_New, -1 );
rb_define_alloc_func( globalImageClass, Image_Alloc );
rb_define_singleton_method( globalImageClass, "getMaximumSize", Image_GetMaximumSize, 0 ); rb_define_singleton_method( globalImageClass, "getMaximumSize", Image_GetMaximumSize, 0 );
// Instance methods // Instance methods

View File

@ -300,17 +300,10 @@ static VALUE RenderImage_Initialize( int argc, VALUE *args, VALUE self )
return self; return self;
} }
/* call-seq: static VALUE RenderImage_Alloc( VALUE aKlass )
* RenderImage.new() -> render_image
*
* Constructs an empty, invalid render-image. You must call create() to have a valid render-image.
*/
static VALUE RenderImage_New( int argc, VALUE *args, VALUE aKlass )
{ {
sf::RenderImage *object = new sf::RenderImage(); sf::RenderImage *object = new sf::RenderImage();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, RenderImage_Free, object ); return Data_Wrap_Struct( aKlass, 0, RenderImage_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
/* call-seq: /* call-seq:
@ -396,7 +389,8 @@ void Init_RenderImage( void )
rb_include_module( globalRenderImageClass, globalRenderTargetModule ); rb_include_module( globalRenderImageClass, globalRenderTargetModule );
// Class methods // Class methods
rb_define_singleton_method( globalRenderImageClass, "new", RenderImage_New, 0 ); //rb_define_singleton_method( globalRenderImageClass, "new", RenderImage_New, 0 );
rb_define_alloc_func( globalRenderImageClass, RenderImage_Alloc );
rb_define_singleton_method( globalRenderImageClass, "isAvailable", RenderImage_IsAvailable, 0 ); rb_define_singleton_method( globalRenderImageClass, "isAvailable", RenderImage_IsAvailable, 0 );
// Instance methods // Instance methods

View File

@ -121,28 +121,10 @@ static VALUE RenderWindow_GetHeight( VALUE self )
return INT2FIX( object->GetHeight() ); return INT2FIX( object->GetHeight() );
} }
/* call-seq: static VALUE RenderWindow_Alloc( VALUE aKlass )
* Window.new() -> render_window
* Window.new( mode, title, style = SFML::Style::Default, settings = SFML::ContextSettings.new ) -> render_window
*
* Construct a new window.
*
* The first form of new doesn't actually create the visual window, use the other form of new or call
* SFML::Window#create to do so.
*
* The second form of new creates the window with the size and pixel depth defined in mode. An optional style can be passed
* to customize the look and behaviour of the window (borders, title bar, resizable, closable, ...). If style contains
* Style::Fullscreen, then mode must be a valid video mode.
*
* The fourth parameter is an optional structure specifying advanced OpenGL context settings such as antialiasing,
* depth-buffer bits, etc. You shouldn't care about these parameters for a regular usage of the graphics module.
*/
static VALUE RenderWindow_New( int argc, VALUE *args, VALUE aKlass )
{ {
sf::RenderWindow *object = new sf::RenderWindow(); sf::RenderWindow *object = new sf::RenderWindow();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, RenderWindow_Free, object ); return Data_Wrap_Struct( aKlass, 0, RenderWindow_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_RenderWindow( void ) void Init_RenderWindow( void )
@ -236,7 +218,8 @@ void Init_RenderWindow( void )
rb_include_module( globalRenderWindowClass, globalRenderTargetModule ); rb_include_module( globalRenderWindowClass, globalRenderTargetModule );
// Class methods // Class methods
rb_define_singleton_method( globalRenderWindowClass, "new", RenderWindow_New, -1 ); //rb_define_singleton_method( globalRenderWindowClass, "new", RenderWindow_New, -1 );
rb_define_alloc_func( globalRenderWindowClass, RenderWindow_Alloc );
// Instance methods // Instance methods
rb_define_method( globalRenderWindowClass, "draw", RenderWindow_Draw, -1 ); rb_define_method( globalRenderWindowClass, "draw", RenderWindow_Draw, -1 );

View File

@ -246,12 +246,10 @@ static VALUE Shader_InitializeCopy( VALUE self, VALUE aSource )
* *
* Create a new shader. * Create a new shader.
*/ */
static VALUE Shader_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Shader_Alloc( VALUE aKlass )
{ {
sf::Shader *object = new sf::Shader(); sf::Shader *object = new sf::Shader();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Shader_Free, object ); return Data_Wrap_Struct( aKlass, 0, Shader_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
/* call-seq: /* call-seq:
@ -335,7 +333,8 @@ void Init_Shader( void )
globalShaderClass = rb_define_class_under( sfml, "Shader", rb_cObject ); globalShaderClass = rb_define_class_under( sfml, "Shader", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalShaderClass, "new", Shader_New, -1 ); //rb_define_singleton_method( globalShaderClass, "new", Shader_New, -1 );
rb_define_alloc_func( globalShaderClass, Shader_Alloc );
rb_define_singleton_method( globalShaderClass, "isAvailable", Shader_IsAvailable, 0 ); rb_define_singleton_method( globalShaderClass, "isAvailable", Shader_IsAvailable, 0 );
// Class Constants // Class Constants

View File

@ -344,12 +344,10 @@ static VALUE Shape_InitializeCopy( VALUE self, VALUE aSource )
* *
* Create an empty shape. * Create an empty shape.
*/ */
static VALUE Shape_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Shape_Alloc( VALUE aKlass )
{ {
sf::Shape *object = new sf::Shape(); sf::Shape *object = new sf::Shape();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Shape_Free, object ); return Data_Wrap_Struct( aKlass, 0, Shape_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
/* call-seq: /* call-seq:
@ -646,7 +644,8 @@ void Init_Shape( void )
rb_include_module( globalShapeClass, globalDrawableModule ); rb_include_module( globalShapeClass, globalDrawableModule );
// Class methods // Class methods
rb_define_singleton_method( globalShapeClass, "new", Shape_New, -1 ); //rb_define_singleton_method( globalShapeClass, "new", Shape_New, -1 );
rb_define_alloc_func( globalShapeClass, Shape_Alloc );
rb_define_singleton_method( globalShapeClass, "line", Shape_Line, -1 ); rb_define_singleton_method( globalShapeClass, "line", Shape_Line, -1 );
rb_define_singleton_method( globalShapeClass, "rectangle", Shape_Rectangle, -1 ); rb_define_singleton_method( globalShapeClass, "rectangle", Shape_Rectangle, -1 );
rb_define_singleton_method( globalShapeClass, "circle", Shape_Circle, -1 ); rb_define_singleton_method( globalShapeClass, "circle", Shape_Circle, -1 );

View File

@ -308,12 +308,10 @@ static VALUE Sprite_GetPixel( VALUE self, VALUE aX, VALUE aY )
INT2FIX( color.b ), INT2FIX( color.a ) ); INT2FIX( color.b ), INT2FIX( color.a ) );
} }
static VALUE Sprite_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Sprite_Alloc( VALUE aKlass )
{ {
sf::Sprite *object = new sf::Sprite(); sf::Sprite *object = new sf::Sprite();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Sprite_Free, object ); return Data_Wrap_Struct( aKlass, 0, Sprite_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Sprite( void ) void Init_Sprite( void )
@ -363,7 +361,8 @@ void Init_Sprite( void )
rb_include_module( globalSpriteClass, globalDrawableModule ); rb_include_module( globalSpriteClass, globalDrawableModule );
// Class methods // Class methods
rb_define_singleton_method( globalSpriteClass, "new", Sprite_New, -1 ); //rb_define_singleton_method( globalSpriteClass, "new", Sprite_New, -1 );
rb_define_alloc_func( globalSpriteClass, Sprite_Alloc );
// Instance methods // Instance methods
rb_define_method( globalSpriteClass, "initialize", Sprite_Initialize, -1 ); rb_define_method( globalSpriteClass, "initialize", Sprite_Initialize, -1 );

View File

@ -229,12 +229,10 @@ static VALUE Text_GetRect( VALUE self )
rb_float_new( rect.Width ), rb_float_new( rect.Height ) ); rb_float_new( rect.Width ), rb_float_new( rect.Height ) );
} }
static VALUE Text_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Text_Alloc( VALUE aKlass )
{ {
sf::Text *object = new sf::Text(); sf::Text *object = new sf::Text();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Text_Free, object ); return Data_Wrap_Struct( aKlass, 0, Text_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
static void CreateStyleEnum() static void CreateStyleEnum()
@ -293,7 +291,8 @@ void Init_Text( void )
CreateStyleEnum(); CreateStyleEnum();
// Class methods // Class methods
rb_define_singleton_method( globalTextClass, "new", Text_New, -1 ); //rb_define_singleton_method( globalTextClass, "new", Text_New, -1 );
rb_define_alloc_func( globalTextClass, Text_Alloc );
// Instance methods // Instance methods
rb_define_method( globalTextClass, "initialize", Text_Initialize, -1 ); rb_define_method( globalTextClass, "initialize", Text_Initialize, -1 );

View File

@ -349,12 +349,10 @@ static VALUE View_Zoom( VALUE self, VALUE aFactor )
return Qnil; return Qnil;
} }
static VALUE View_New( int argc, VALUE *args, VALUE aKlass ) static VALUE View_Alloc( VALUE aKlass )
{ {
sf::View *object = new sf::View(); sf::View *object = new sf::View();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, View_Free, object ); return Data_Wrap_Struct( aKlass, 0, View_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_View( void ) void Init_View( void )
@ -408,7 +406,8 @@ void Init_View( void )
globalViewClass = rb_define_class_under( sfml, "View", rb_cObject ); globalViewClass = rb_define_class_under( sfml, "View", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalViewClass, "new", View_New, -1 ); //rb_define_singleton_method( globalViewClass, "new", View_New, -1 );
rb_define_alloc_func( globalViewClass, View_Alloc );
// Instance methods // Instance methods
rb_define_method( globalViewClass, "initialize", View_Initialize, -1 ); rb_define_method( globalViewClass, "initialize", View_Initialize, -1 );

View File

@ -75,12 +75,10 @@ static VALUE Clock_InitializeCopy( VALUE self, VALUE aSource )
* *
* The clock starts automatically after being constructed. * The clock starts automatically after being constructed.
*/ */
static VALUE Clock_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Clock_Allocate( VALUE aKlass )
{ {
sf::Clock *object = new sf::Clock(); sf::Clock *object = new sf::Clock();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Clock_Free, object ); return Data_Wrap_Struct( aKlass, 0, Clock_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Clock( void ) void Init_Clock( void )
@ -94,16 +92,17 @@ void Init_Clock( void )
* Its resolution depends on the underlying OS, but you can generally expect a 1 ms resolution. * Its resolution depends on the underlying OS, but you can generally expect a 1 ms resolution.
*/ */
globalClockClass = rb_define_class_under( sfml, "Clock", rb_cObject ); globalClockClass = rb_define_class_under( sfml, "Clock", rb_cObject );
rb_define_alloc_func( globalClockClass, Clock_Allocate );
// Class methods // Class methods
rb_define_singleton_method( globalClockClass, "new", Clock_New, -1 ); //rb_define_singleton_method( globalClockClass, "new", Clock_New, -1 );
// Instance methods // Instance methods
rb_define_method( globalClockClass, "initialize_copy", Clock_InitializeCopy, 1 ); rb_define_method( globalClockClass, "initialize_copy", Clock_InitializeCopy, 1 );
rb_define_method( globalClockClass, "getElapsedTime", Clock_GetElapsedTime, 0 ); rb_define_method( globalClockClass, "elapsed_time", Clock_GetElapsedTime, 0 );
rb_define_method( globalClockClass, "reset", Clock_Reset, 0 ); rb_define_method( globalClockClass, "reset", Clock_Reset, 0 );
// Aliases // Aliases
rb_define_alias( globalClockClass, "elapsedTime", "getElapsedTime" ); rb_define_alias( globalClockClass, "elapsedTime", "elapsed_time" );
rb_define_alias( globalClockClass, "elapsed_time", "getElapsedTime" ); rb_define_alias( globalClockClass, "getElapsedTime", "elapsed_time" );
} }

View File

@ -79,17 +79,10 @@ static VALUE Context_SetReferenceActive( VALUE aKlass )
} }
} }
/* call-seq: static VALUE Context_Alloc( VALUE aKlass )
* Context.new() -> context
*
* The constructor creates and activates the context
*/
static VALUE Context_New( VALUE aKlass )
{ {
sf::Context *object = new sf::Context(); sf::Context *object = new sf::Context();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Context_Free, object ); return Data_Wrap_Struct( aKlass, 0, Context_Free, object );
rb_obj_call_init( rbData, 0, 0 );
return rbData;
} }
void Init_Context( void ) void Init_Context( void )
@ -115,7 +108,8 @@ void Init_Context( void )
rb_include_module( globalContextClass, globalNonCopyableModule ); rb_include_module( globalContextClass, globalNonCopyableModule );
// Class methods // Class methods
rb_define_singleton_method( globalContextClass, "new", Context_New, 0 ); //rb_define_singleton_method( globalContextClass, "new", Context_New, 0 );
rb_define_alloc_func( globalContextClass, Context_Alloc );
rb_define_singleton_method( globalContextClass, "setReferenceActive", Context_SetReferenceActive, 0 ); rb_define_singleton_method( globalContextClass, "setReferenceActive", Context_SetReferenceActive, 0 );
// Instance methods // Instance methods

View File

@ -25,7 +25,6 @@
#include <SFML/Window/ContextSettings.hpp> #include <SFML/Window/ContextSettings.hpp>
#include <iostream> #include <iostream>
VALUE globalContextSettingsClass; VALUE globalContextSettingsClass;
/* Free a heap allocated object /* Free a heap allocated object
@ -171,43 +170,36 @@ static VALUE ContextSettings_InitializeCopy( VALUE self, VALUE aSource )
* *
* The constructor creates the settings * The constructor creates the settings
*/ */
static VALUE ContextSettings_New( int argc, VALUE *args, VALUE aKlass ) static VALUE ContextSettings_Alloc( VALUE aKlass )
{
sf::ContextSettings *object = new sf::ContextSettings();
return Data_Wrap_Struct( aKlass, 0, ContextSettings_Free, object );;
}
static VALUE ContextSettings_Initialize( int argc, VALUE *args, VALUE self )
{ {
sf::ContextSettings *object = NULL; sf::ContextSettings *object = NULL;
if( argc == 0 ) Data_Get_Struct( self, sf::ContextSettings, object );
switch( argc )
{ {
object = new sf::ContextSettings(); case 0:
break;
case 5:
object->MinorVersion = NUM2UINT( args[4] );
case 4:
object->MajorVersion = NUM2UINT( args[3] );
case 3:
object->AntialiasingLevel = NUM2UINT( args[2] );
case 2:
object->StencilBits = NUM2UINT( args[1] );
case 1:
object->DepthBits = NUM2UINT( args[0] );
break;
default:
rb_raise( rb_eArgError, "Expected 0..5 arguments but was given %d", argc );
return Qnil;
} }
else if( argc == 1 ) return self;
{
object = new sf::ContextSettings( NUM2UINT( args[0] ) );
}
else if( argc == 2 )
{
object = new sf::ContextSettings( NUM2UINT( args[0] ), NUM2UINT( args[1] ) );
}
else if( argc == 3 )
{
object = new sf::ContextSettings( NUM2UINT( args[0] ), NUM2UINT( args[1] ), NUM2UINT( args[2] ) );
}
else if( argc == 4 )
{
object = new sf::ContextSettings( NUM2UINT( args[0] ), NUM2UINT( args[1] ), NUM2UINT( args[2] ), NUM2UINT( args[3] ) );
}
else if( argc == 5 )
{
object = new sf::ContextSettings( NUM2UINT( args[0] ), NUM2UINT( args[1] ), NUM2UINT( args[2] ), NUM2UINT( args[3] ), NUM2UINT( args[4] ) );
}
else
{
rb_raise( rb_eArgError, "Expected 0..5 arguments but was given %d", argc );
return Qnil;
}
VALUE rbData = Data_Wrap_Struct( aKlass, 0, ContextSettings_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_ContextSettings( void ) void Init_ContextSettings( void )
@ -242,9 +234,11 @@ void Init_ContextSettings( void )
globalContextSettingsClass = rb_define_class_under( sfml, "ContextSettings", rb_cObject ); globalContextSettingsClass = rb_define_class_under( sfml, "ContextSettings", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalContextSettingsClass, "new", ContextSettings_New, -1 ); //rb_define_singleton_method( globalContextSettingsClass, "new", ContextSettings_New, -1 );
rb_define_alloc_func( globalContextSettingsClass, ContextSettings_Alloc );
// Instance methods // Instance methods
rb_define_method( globalContextSettingsClass, "initialize", ContextSettings_Initialize, -1 );
rb_define_method( globalContextSettingsClass, "initialize_copy", ContextSettings_InitializeCopy, 1 ); rb_define_method( globalContextSettingsClass, "initialize_copy", ContextSettings_InitializeCopy, 1 );
rb_define_method( globalContextSettingsClass, "depthBits", ContextSettings_GetDepth, 0 ); rb_define_method( globalContextSettingsClass, "depthBits", ContextSettings_GetDepth, 0 );

View File

@ -145,7 +145,14 @@ EVENT_TYPE_ACCESSORS( Size, Height, INT2NUM )
static VALUE TextEvent_GetUnicode( VALUE self ) static VALUE TextEvent_GetUnicode( VALUE self )
EVENT_TYPE_ACCESSORS( Text, Unicode, INT2NUM ) EVENT_TYPE_ACCESSORS( Text, Unicode, INT2NUM )
/* */ /* call-seq:
* Event.new(type) -> event
*
* You should never call this function directly. You should only aquire event's trough
* SFML::Window#getEvent or SFML::Window#waitEvent, if you need to pass data to a method
* that takes an event instance then make a proxy instance to simulate an event.
* NOTE: Using this method works but it will act constant as you can't access any values.
*/
static VALUE Event_Initialize( VALUE self, VALUE aType ) static VALUE Event_Initialize( VALUE self, VALUE aType )
{ {
sf::Event * object = NULL; sf::Event * object = NULL;
@ -212,6 +219,7 @@ static VALUE Event_Initialize( VALUE self, VALUE aType )
rb_iv_set( eventType, "@internal__parent_ref", self ); rb_iv_set( eventType, "@internal__parent_ref", self );
rb_iv_set( self, name, eventType ); rb_iv_set( self, name, eventType );
} }
return self;
} }
static VALUE Event_InitializeCopy( VALUE self, VALUE aSource ) static VALUE Event_InitializeCopy( VALUE self, VALUE aSource )
@ -224,20 +232,10 @@ static VALUE Event_InitializeCopy( VALUE self, VALUE aSource )
return Event_Initialize( self, INT2FIX( object->Type ) ); return Event_Initialize( self, INT2FIX( object->Type ) );
} }
/* call-seq: static VALUE Event_Alloc( VALUE aKlass )
* Event.new(type) -> event
*
* You should never call this function directly. You should only aquire event's trough
* SFML::Window#getEvent or SFML::Window#waitEvent, if you need to pass data to a method
* that takes an event instance then make a proxy instance to simulate an event.
* NOTE: Using this method works but it will act constant as you can't access any values.
*/
static VALUE Event_New( int argc, VALUE * args, VALUE aKlass )
{ {
sf::Event *object = new sf::Event(); sf::Event *object = new sf::Event();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Event_Free, object ); return Data_Wrap_Struct( aKlass, 0, Event_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Event( void ) void Init_Event( void )
@ -279,14 +277,14 @@ void Init_Event( void )
* end * end
*/ */
globalEventClass = rb_define_class_under( sfml, "Event", rb_cObject ); globalEventClass = rb_define_class_under( sfml, "Event", rb_cObject );
globalJoyButtonEventClass = rb_define_class_under( globalEventClass, "JoyButton", rb_cObject ); globalJoyButtonEventClass = rb_define_class_under( globalEventClass, "JoyButton", rb_cObject );
globalJoyMoveEventClass = rb_define_class_under( globalEventClass, "JoyMove", rb_cObject ); globalJoyMoveEventClass = rb_define_class_under( globalEventClass, "JoyMove", rb_cObject );
globalKeyEventClass = rb_define_class_under( globalEventClass, "Key", rb_cObject ); globalKeyEventClass = rb_define_class_under( globalEventClass, "Key", rb_cObject );
globalMouseButtonEventClass = rb_define_class_under( globalEventClass, "MouseButton", rb_cObject ); globalMouseButtonEventClass = rb_define_class_under( globalEventClass, "MouseButton", rb_cObject );
globalMouseMoveEventClass = rb_define_class_under( globalEventClass, "MouseMove", rb_cObject ); globalMouseMoveEventClass = rb_define_class_under( globalEventClass, "MouseMove", rb_cObject );
globalMouseWheelEventClass = rb_define_class_under( globalEventClass, "MouseWheel", rb_cObject ); globalMouseWheelEventClass = rb_define_class_under( globalEventClass, "MouseWheel", rb_cObject );
globalSizeEventClass = rb_define_class_under( globalEventClass, "Size", rb_cObject ); globalSizeEventClass = rb_define_class_under( globalEventClass, "Size", rb_cObject );
globalTextEventClass = rb_define_class_under( globalEventClass, "Text", rb_cObject ); globalTextEventClass = rb_define_class_under( globalEventClass, "Text", rb_cObject );
rb_define_const( globalEventClass, "Closed", INT2NUM( sf::Event::Closed ) ); rb_define_const( globalEventClass, "Closed", INT2NUM( sf::Event::Closed ) );
rb_define_const( globalEventClass, "Resized", INT2NUM( sf::Event::Resized ) ); rb_define_const( globalEventClass, "Resized", INT2NUM( sf::Event::Resized ) );
@ -307,7 +305,8 @@ void Init_Event( void )
rb_define_const( globalEventClass, "Count", INT2NUM( sf::Event::Count ) ); rb_define_const( globalEventClass, "Count", INT2NUM( sf::Event::Count ) );
// Class methods // Class methods
rb_define_singleton_method( globalEventClass, "new", Event_New, -1 ); //rb_define_singleton_method( globalEventClass, "new", Event_New, -1 );
rb_define_alloc_func( globalEventClass, Event_Alloc );
// Instance methods // Instance methods
rb_define_method( globalEventClass, "initialize", Event_Initialize, 1 ); rb_define_method( globalEventClass, "initialize", Event_Initialize, 1 );
@ -325,47 +324,35 @@ void Init_Event( void )
// JoyButton methods // JoyButton methods
rb_define_method( globalJoyButtonEventClass, "joystickId", JoyButtonEvent_GetJoystickId, 0 ); rb_define_method( globalJoyButtonEventClass, "joystickId", JoyButtonEvent_GetJoystickId, 0 );
rb_define_method( globalJoyButtonEventClass, "button", JoyButtonEvent_GetButton, 0 ); rb_define_method( globalJoyButtonEventClass, "button", JoyButtonEvent_GetButton, 0 );
// JoyMove methods // JoyMove methods
rb_define_method( globalJoyMoveEventClass, "joystickId", JoyMoveEvent_GetJoystickId, 0 ); rb_define_method( globalJoyMoveEventClass, "joystickId", JoyMoveEvent_GetJoystickId, 0 );
rb_define_method( globalJoyMoveEventClass, "axis", JoyMoveEvent_GetAxis, 0 ); rb_define_method( globalJoyMoveEventClass, "axis", JoyMoveEvent_GetAxis, 0 );
rb_define_method( globalJoyMoveEventClass, "position", JoyMoveEvent_GetPosition, 0 ); rb_define_method( globalJoyMoveEventClass, "position", JoyMoveEvent_GetPosition, 0 );
// Key methods // Key methods
rb_define_method( globalKeyEventClass, "code", KeyEvent_GetCode, 0 ); rb_define_method( globalKeyEventClass, "code", KeyEvent_GetCode, 0 );
rb_define_method( globalKeyEventClass, "alt", KeyEvent_GetAlt, 0 ); rb_define_method( globalKeyEventClass, "alt", KeyEvent_GetAlt, 0 );
rb_define_method( globalKeyEventClass, "control", KeyEvent_GetControl, 0 ); rb_define_method( globalKeyEventClass, "control", KeyEvent_GetControl, 0 );
rb_define_method( globalKeyEventClass, "shift", KeyEvent_GetShift, 0 ); rb_define_method( globalKeyEventClass, "shift", KeyEvent_GetShift, 0 );
// MouseButton methods // MouseButton methods
rb_define_method( globalMouseButtonEventClass, "button", MouseButtonEvent_GetButton, 0 ); rb_define_method( globalMouseButtonEventClass, "button", MouseButtonEvent_GetButton, 0 );
rb_define_method( globalMouseButtonEventClass, "x", MouseButtonEvent_GetX, 0 ); rb_define_method( globalMouseButtonEventClass, "x", MouseButtonEvent_GetX, 0 );
rb_define_method( globalMouseButtonEventClass, "y", MouseButtonEvent_GetY, 0 ); rb_define_method( globalMouseButtonEventClass, "y", MouseButtonEvent_GetY, 0 );
// MouseMove methods // MouseMove methods
rb_define_method( globalMouseMoveEventClass, "x", MouseMoveEvent_GetX, 0 ); rb_define_method( globalMouseMoveEventClass, "x", MouseMoveEvent_GetX, 0 );
rb_define_method( globalMouseMoveEventClass, "y", MouseMoveEvent_GetY, 0 ); rb_define_method( globalMouseMoveEventClass, "y", MouseMoveEvent_GetY, 0 );
// MouseWheel methods // MouseWheel methods
rb_define_method( globalMouseWheelEventClass, "delta", MouseWheelEvent_GetDelta, 0 ); rb_define_method( globalMouseWheelEventClass, "delta", MouseWheelEvent_GetDelta, 0 );
rb_define_method( globalMouseWheelEventClass, "x", MouseWheelEvent_GetX, 0 ); rb_define_method( globalMouseWheelEventClass, "x", MouseWheelEvent_GetX, 0 );
rb_define_method( globalMouseWheelEventClass, "y", MouseWheelEvent_GetY, 0 ); rb_define_method( globalMouseWheelEventClass, "y", MouseWheelEvent_GetY, 0 );
// Size methods // Size methods
rb_define_method( globalSizeEventClass, "width", SizeEvent_GetWidth, 0 ); rb_define_method( globalSizeEventClass, "width", SizeEvent_GetWidth, 0 );
rb_define_method( globalSizeEventClass, "height", SizeEvent_GetWidth, 0 ); rb_define_method( globalSizeEventClass, "height", SizeEvent_GetWidth, 0 );
// Text methods // Text methods

View File

@ -136,18 +136,10 @@ static VALUE Input_GetJoystickAxis( VALUE self, VALUE aJoystick, VALUE anAxis )
return rb_float_new( object->GetJoystickAxis( rawJoystick, rawAxis ) ); return rb_float_new( object->GetJoystickAxis( rawJoystick, rawAxis ) );
} }
/* call-seq: static VALUE Input_Alloc( VALUE aKlass )
* Input.new() -> input
*
* This will create a new input object. though it will not receive any updates of events.
* You should aquire an input object from the SFML::Window#input method.
*/
static VALUE Input_New( int argc, VALUE * args, VALUE aKlass )
{ {
sf::Input *object = new sf::Input(); sf::Input *object = new sf::Input();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Input_Free, object ); return Data_Wrap_Struct( aKlass, 0, Input_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Input( void ) void Init_Input( void )
@ -184,7 +176,8 @@ void Init_Input( void )
rb_include_module( globalInputClass, globalNonCopyableModule ); rb_include_module( globalInputClass, globalNonCopyableModule );
// Class methods // Class methods
rb_define_singleton_method( globalInputClass, "new", Input_New, -1 ); //rb_define_singleton_method( globalInputClass, "new", Input_New, -1 );
rb_define_alloc_func( globalInputClass, Input_Alloc );
// Instance methods // Instance methods
rb_define_method( globalInputClass, "isKeyDown", Input_IsKeyDown, 1 ); rb_define_method( globalInputClass, "isKeyDown", Input_IsKeyDown, 1 );

View File

@ -198,33 +198,37 @@ static VALUE VideoMode_GetFullscreenModes( VALUE aKlass )
return array; return array;
} }
static VALUE VideoMode_Alloc( VALUE aKlass )
{
sf::VideoMode *object = new sf::VideoMode();
return Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object );
}
/* call-seq: /* call-seq:
* VideoMode.new() -> mode * VideoMode.new() -> mode
* VideoMode.new( width, height, bpp = 32 ) -> mode * VideoMode.new( width, height, bpp = 32 ) -> mode
* *
* Create a new mode. * Create a new mode.
*/ */
static VALUE VideoMode_New( int argc, VALUE *args, VALUE aKlass ) static VALUE VideoMode_Initialize( int argc, VALUE *args, VALUE self )
{ {
sf::VideoMode *object = NULL; sf::VideoMode *object = NULL;
Data_Get_Struct( self, sf::VideoMode, object );
switch( argc ) switch( argc )
{ {
case 0: case 0:
object = new sf::VideoMode();
break;
case 2:
object = new sf::VideoMode( FIX2UINT( args[0] ), FIX2UINT( args[1] ) );
break; break;
case 3: case 3:
object = new sf::VideoMode( FIX2UINT( args[0] ), FIX2UINT( args[1] ),FIX2UINT( args[2] ) ); object->BitsPerPixel = NUM2UINT( args[2] );
case 2:
object->Height = NUM2UINT( args[1] );
object->Width = NUM2UINT( args[0] );
break; break;
default: default:
rb_raise( rb_eArgError, "Expected 0, 2 or 3 arguments but was given %d", argc ); rb_raise( rb_eArgError, "Expected 0..3 arguments but was given %d", argc );
break; return Qnil;
} }
VALUE rbData = Data_Wrap_Struct( aKlass, 0, VideoMode_Free, object ); return self;
rb_obj_call_init( rbData, 0, 0 );
return rbData;
} }
void Init_VideoMode( void ) void Init_VideoMode( void )
@ -264,11 +268,13 @@ void Init_VideoMode( void )
globalVideoModeClass = rb_define_class_under( sfml, "VideoMode", rb_cObject ); globalVideoModeClass = rb_define_class_under( sfml, "VideoMode", rb_cObject );
// Class methods // Class methods
rb_define_singleton_method( globalVideoModeClass, "new", VideoMode_New, -1 ); //rb_define_singleton_method( globalVideoModeClass, "new", VideoMode_New, -1 );
rb_define_alloc_func( globalVideoModeClass, VideoMode_Alloc );
rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", VideoMode_GetDesktopMode, 0 ); rb_define_singleton_method( globalVideoModeClass, "getDesktopMode", VideoMode_GetDesktopMode, 0 );
rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", VideoMode_GetFullscreenModes, 0 ); rb_define_singleton_method( globalVideoModeClass, "getFullscreenModes", VideoMode_GetFullscreenModes, 0 );
// Instance methods // Instance methods
rb_define_method( globalVideoModeClass, "initialize", VideoMode_Initialize, -1 );
rb_define_method( globalVideoModeClass, "initialize_copy", VideoMode_InitializeCopy, 1 ); rb_define_method( globalVideoModeClass, "initialize_copy", VideoMode_InitializeCopy, 1 );
rb_define_method( globalVideoModeClass, "width", VideoMode_GetWidth, 0 ); rb_define_method( globalVideoModeClass, "width", VideoMode_GetWidth, 0 );

View File

@ -620,12 +620,10 @@ static VALUE Window_Initialize( int argc, VALUE *args, VALUE self )
return self; return self;
} }
static VALUE Window_New( int argc, VALUE *args, VALUE aKlass ) static VALUE Window_Alloc( VALUE aKlass )
{ {
sf::Window *object = new sf::Window(); sf::Window *object = new sf::Window();
VALUE rbData = Data_Wrap_Struct( aKlass, 0, Window_Free, object ); return Data_Wrap_Struct( aKlass, 0, Window_Free, object );
rb_obj_call_init( rbData, argc, args );
return rbData;
} }
void Init_Window( void ) void Init_Window( void )
@ -680,7 +678,8 @@ void Init_Window( void )
rb_include_module( globalWindowClass, globalNonCopyableModule ); rb_include_module( globalWindowClass, globalNonCopyableModule );
// Class methods // Class methods
rb_define_singleton_method( globalWindowClass, "new", Window_New , -1 ); //rb_define_singleton_method( globalWindowClass, "new", Window_New , -1 );
rb_define_alloc_func( globalWindowClass, Window_Alloc );
// Instance methods // Instance methods
rb_define_method( globalWindowClass, "initialize", Window_Initialize, -1 ); rb_define_method( globalWindowClass, "initialize", Window_Initialize, -1 );

View File

@ -25,7 +25,7 @@
#include "ruby.h" #include "ruby.h"
#define SFML_STATIC #define SFML_DYNAMIC
extern VALUE globalSFMLNamespace; extern VALUE globalSFMLNamespace;