Also had forgotten two breaks in a switch-statement in View.cpp

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1727 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
groogy 2010-11-29 15:44:02 +00:00
parent 4de4d0832c
commit fef70e1280
4 changed files with 149 additions and 3 deletions

View File

@ -31,12 +31,18 @@ extern VALUE globalRenderTargetModule;
extern VALUE globalImageClass; extern VALUE globalImageClass;
extern VALUE globalDrawableModule; extern VALUE globalDrawableModule;
extern VALUE globalShaderClass; extern VALUE globalShaderClass;
extern VALUE globalViewClass;
static void RenderImage_Free( sf::RenderImage *anObject ) static void RenderImage_Free( sf::RenderImage *anObject )
{ {
delete anObject; delete anObject;
} }
static void View_Free( sf::View *anObject )
{
delete anObject;
}
/* call-seq: /* call-seq:
* render_image.create( width, height, depthBuffer = false ) -> true or false * render_image.create( width, height, depthBuffer = false ) -> true or false
* *
@ -240,6 +246,60 @@ static VALUE RenderImage_SetSmooth( VALUE self, VALUE aSmoothFlag )
return Qnil; return Qnil;
} }
/* call-seq:
* render_target.setView( view )
*
* Change the current active view.
*
* The new view will affect everything that is drawn, until another view is activated. The render target keeps its own
* copy of the view object, so it is not necessary to keep the original one alive as long as it is in use. To restore
* the original view of the target, you can pass the result of getDefaultView() to this function.
*/
static VALUE RenderImage_SetView( VALUE self, VALUE aView )
{
VALIDATE_CLASS( aView, globalViewClass, "view" );
sf::View *view = NULL;
sf::RenderImage *object = NULL;
Data_Get_Struct( self, sf::RenderImage, object );
Data_Get_Struct( aView, sf::View, view );
object->SetView( *view );
return Qnil;
}
/* call-seq:
* render_target.getView() -> view
*
* Retrieve the view currently in use in the render target.
*/
static VALUE RenderImage_GetView( VALUE self )
{
sf::RenderImage *object = NULL;
Data_Get_Struct( self, sf::RenderImage, object );
const sf::View &original = object->GetView();
sf::View * view = new sf::View( original );
VALUE rbData = Data_Wrap_Struct( globalViewClass, 0, View_Free, view );
rb_obj_call_init( rbData, 0, 0 );
return rbData;
}
/* call-seq:
* render_target.getDefaultView() -> VIEW
*
* Get the default view of the render target.
*
* The default view has the initial size of the render target, and never changes after the target has been created.
*/
static VALUE RenderImage_GetDefaultView( VALUE self )
{
sf::RenderImage *object = NULL;
Data_Get_Struct( self, sf::RenderImage, object );
const sf::View &original = object->GetDefaultView();
sf::View * view = new sf::View( original );
VALUE rbData = Data_Wrap_Struct( globalViewClass, 0, View_Free, view );
rb_obj_call_init( rbData, 0, 0 );
return rbData;
}
/* call-seq: /* call-seq:
* RenderImage.new() -> render_image * RenderImage.new() -> render_image
* *
@ -347,6 +407,9 @@ void Init_RenderImage( void )
rb_define_method( globalRenderImageClass, "isSmooth", RenderImage_IsSmooth, 0 ); rb_define_method( globalRenderImageClass, "isSmooth", RenderImage_IsSmooth, 0 );
rb_define_method( globalRenderImageClass, "setActive", RenderImage_SetActive, -1 ); rb_define_method( globalRenderImageClass, "setActive", RenderImage_SetActive, -1 );
rb_define_method( globalRenderImageClass, "setSmooth", RenderImage_SetSmooth, 1 ); rb_define_method( globalRenderImageClass, "setSmooth", RenderImage_SetSmooth, 1 );
rb_define_method( globalRenderImageClass, "getView", RenderImage_GetView, 0 );
rb_define_method( globalRenderImageClass, "setView", RenderImage_SetView, 1 );
rb_define_method( globalRenderImageClass, "getDefaultView", RenderImage_GetDefaultView, 0 );
// Class Aliases // Class Aliases
rb_define_alias( CLASS_OF( globalRenderImageClass ), "is_available", "isAvailable" ); rb_define_alias( CLASS_OF( globalRenderImageClass ), "is_available", "isAvailable" );
@ -363,4 +426,10 @@ void Init_RenderImage( void )
rb_define_alias( globalRenderImageClass, "active=", "setActive" ); rb_define_alias( globalRenderImageClass, "active=", "setActive" );
rb_define_alias( globalRenderImageClass, "smooth=", "setSmooth" ); rb_define_alias( globalRenderImageClass, "smooth=", "setSmooth" );
rb_define_alias( globalRenderImageClass, "view=", "setView" );
rb_define_alias( globalRenderImageClass, "view", "getView" );
rb_define_alias( globalRenderImageClass, "defaultView", "getDefaultView" );
rb_define_alias( globalRenderImageClass, "default_view", "getDefaultView" );
} }

View File

@ -38,6 +38,11 @@ extern VALUE globalDrawableModule;
extern VALUE globalShaderClass; extern VALUE globalShaderClass;
extern VALUE globalViewClass; extern VALUE globalViewClass;
static VALUE View_Free( sf::View *anObject )
{
delete anObject;
}
/* call-seq: /* call-seq:
* render_target.clear( color = SFML::Color::Black ) * render_target.clear( color = SFML::Color::Black )
* *
@ -178,10 +183,10 @@ static VALUE RenderTarget_GetView( VALUE self )
{ {
sf::RenderTarget *object = NULL; sf::RenderTarget *object = NULL;
Data_Get_Struct( self, sf::RenderTarget, object ); Data_Get_Struct( self, sf::RenderTarget, object );
const sf::View &view = object->GetView(); const sf::View &original = object->GetView();
VALUE rbData = Data_Wrap_Struct( globalViewClass, 0, 0, const_cast< sf::View * >( &view ) ); sf::View * view = new sf::View( original );
VALUE rbData = Data_Wrap_Struct( globalViewClass, 0, View_Free, view );
rb_obj_call_init( rbData, 0, 0 ); rb_obj_call_init( rbData, 0, 0 );
rb_iv_set( rbData, "@__owner_ref", self );
return rbData; return rbData;
} }

View File

@ -31,12 +31,18 @@ extern VALUE globalRenderTargetModule;
extern VALUE globalWindowClass; extern VALUE globalWindowClass;
extern VALUE globalDrawableModule; extern VALUE globalDrawableModule;
extern VALUE globalShaderClass; extern VALUE globalShaderClass;
extern VALUE globalViewClass;
static void RenderWindow_Free( sf::RenderWindow *anObject ) static void RenderWindow_Free( sf::RenderWindow *anObject )
{ {
delete anObject; delete anObject;
} }
static void View_Free( sf::View *anObject )
{
delete anObject;
}
/* call-seq: /* call-seq:
* render_window.draw( drawable ) * render_window.draw( drawable )
* render_window.draw( drawable, shader ) * render_window.draw( drawable, shader )
@ -78,6 +84,60 @@ static VALUE RenderWindow_Draw( int argc, VALUE *args, VALUE self )
return Qnil; return Qnil;
} }
/* call-seq:
* render_target.setView( view )
*
* Change the current active view.
*
* The new view will affect everything that is drawn, until another view is activated. The render target keeps its own
* copy of the view object, so it is not necessary to keep the original one alive as long as it is in use. To restore
* the original view of the target, you can pass the result of getDefaultView() to this function.
*/
static VALUE RenderWindow_SetView( VALUE self, VALUE aView )
{
VALIDATE_CLASS( aView, globalViewClass, "view" );
sf::View *view = NULL;
sf::RenderWindow *object = NULL;
Data_Get_Struct( self, sf::RenderWindow, object );
Data_Get_Struct( aView, sf::View, view );
object->SetView( *view );
return Qnil;
}
/* call-seq:
* render_target.getView() -> view
*
* Retrieve the view currently in use in the render target.
*/
static VALUE RenderWindow_GetView( VALUE self )
{
sf::RenderWindow *object = NULL;
Data_Get_Struct( self, sf::RenderWindow, object );
const sf::View &original = object->GetView();
sf::View * view = new sf::View( original );
VALUE rbData = Data_Wrap_Struct( globalViewClass, 0, View_Free, view );
rb_obj_call_init( rbData, 0, 0 );
return rbData;
}
/* call-seq:
* render_target.getDefaultView() -> VIEW
*
* Get the default view of the render target.
*
* The default view has the initial size of the render target, and never changes after the target has been created.
*/
static VALUE RenderWindow_GetDefaultView( VALUE self )
{
sf::RenderWindow *object = NULL;
Data_Get_Struct( self, sf::RenderWindow, object );
const sf::View &original = object->GetDefaultView();
sf::View * view = new sf::View( original );
VALUE rbData = Data_Wrap_Struct( globalViewClass, 0, View_Free, view );
rb_obj_call_init( rbData, 0, 0 );
return rbData;
}
/* call-seq: /* call-seq:
* Window.new() -> render_window * Window.new() -> render_window
* Window.new( mode, title, style = SFML::Style::Default, settings = SFML::ContextSettings.new ) -> render_window * Window.new( mode, title, style = SFML::Style::Default, settings = SFML::ContextSettings.new ) -> render_window
@ -197,4 +257,14 @@ void Init_RenderWindow( void )
// Instance methods // Instance methods
rb_define_method( globalRenderWindowClass, "draw", RenderWindow_Draw, -1 ); rb_define_method( globalRenderWindowClass, "draw", RenderWindow_Draw, -1 );
rb_define_method( globalRenderWindowClass, "getView", RenderWindow_GetView, 0 );
rb_define_method( globalRenderWindowClass, "setView", RenderWindow_SetView, 1 );
rb_define_method( globalRenderWindowClass, "getDefaultView", RenderWindow_GetDefaultView, 0 );
// Alias
rb_define_alias( globalRenderWindowClass, "view=", "setView" );
rb_define_alias( globalRenderWindowClass, "view", "getView" );
rb_define_alias( globalRenderWindowClass, "defaultView", "getDefaultView" );
rb_define_alias( globalRenderWindowClass, "default_view", "getDefaultView" );
} }

View File

@ -278,11 +278,13 @@ static VALUE View_SetSize( int argc, VALUE * args, VALUE self )
VALUE temp = Vector2_ForceType( args[0] ); VALUE temp = Vector2_ForceType( args[0] );
x = NUM2DBL( Vector2_GetX( temp ) ); x = NUM2DBL( Vector2_GetX( temp ) );
y = NUM2DBL( Vector2_GetY( temp ) ); y = NUM2DBL( Vector2_GetY( temp ) );
break;
} }
case 2: case 2:
{ {
x = NUM2DBL( args[0] ); x = NUM2DBL( args[0] );
y = NUM2DBL( args[1] ); y = NUM2DBL( args[1] );
break;
} }
default: default:
rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc );