diff --git a/bindings/ruby/sfml-graphics/graphics/Color.cpp b/bindings/ruby/sfml-graphics/graphics/Color.cpp index d931fa176..042dcf1f8 100644 --- a/bindings/ruby/sfml-graphics/graphics/Color.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Color.cpp @@ -115,7 +115,11 @@ static void Color_internal_CopyFrom( VALUE self, VALUE aSource ) Color_SetA( self, a ); } -/* */ +/* call-seq: + * color1 + color2 -> color + * + * This operator returns the component-wise sum of two colors. Components that exceed 255 are clamped to 255. + */ static VALUE Color_Add( VALUE self, VALUE aRightOperand ) { VALUE right = Color_ForceType( aRightOperand ); @@ -138,7 +142,12 @@ static VALUE Color_Add( VALUE self, VALUE aRightOperand ) return rb_funcall( globalColorClass, rb_intern( "new" ), 4, newR, newG, newB, newA ); } -/* */ +/* call-seq: + * color1 * color2 -> color + * + * This operator returns the component-wise multiplication (also called "modulation") of two colors. Components are + * then divided by 255 so that the result is still in the range [0, 255]. + */ static VALUE Color_Multiply( VALUE self, VALUE aRightOperand ) { VALUE right = Color_ForceType( aRightOperand ); @@ -161,7 +170,11 @@ static VALUE Color_Multiply( VALUE self, VALUE aRightOperand ) return rb_funcall( globalColorClass, rb_intern( "new" ), 4, newR, newG, newB, newA ); } -/* */ +/* call-seq: + * color1 == color2 -> true or false + * + * This operator compares two colors and check if they are equal. + */ static VALUE Color_Equal( VALUE self, VALUE anArgument ) { VALUE right = Color_ForceType( anArgument ); @@ -227,11 +240,37 @@ void Init_Color( void ) { /* SFML namespace which contains the classes of this module. */ VALUE sfml = rb_define_module( "SFML" ); -/* Utility class for manipulating time. +/* Utility class for manpulating RGBA colors. * - * sf::Clock is a lightweight class for measuring time. + * SFML::Color is a simple color class composed of 4 components: * - * Its resolution depends on the underlying OS, but you can generally expect a 1 ms resolution. + * - Red + * - Green + * - Blue + * - Alpha (opacity) + * + * Each component is a public member, an unsigned integer in the range [0, 255]. Thus, colors can be constructed and manipulated very easily: + * + * c1 = SFML::Color.new(255, 0, 0) # red + * c1.red = 0 # make it black + * c1.blue = 128 # make it dark blue + * + * The fourth component of colors, named "alpha", represents the opacity of the color. A color with an alpha value of + * 255 will be fully opaque, while an alpha value of 0 will make a color fully transparent, whatever the value of the + * other components. + * + * The most common colors are already defined as class constants: + * + * black = SFML::Color::Black + * white = SFML::Color::White + * red = SFML::Color::Red + * green = SFML::Color::Green + * blue = SFML::Color::Blue + * yellow = SFML::Color::Yellow + * magenta = SFML::Color::Magenta + * cyan = SFML::Color::Cyan + * + * Colors can also be added and modulated (multiplied) using the overloaded operators + and *. */ globalColorClass = rb_define_class_under( sfml, "Color", rb_cObject ); @@ -256,4 +295,13 @@ void Init_Color( void ) rb_define_const( globalColorClass, "Yellow", rb_funcall( globalColorClass, rb_intern( "new" ), 3, INT2FIX( 255 ), INT2FIX( 255 ), INT2FIX( 0 ) ) ); rb_define_const( globalColorClass, "Magneta", rb_funcall( globalColorClass, rb_intern( "new" ), 3, INT2FIX( 255 ), INT2FIX( 0 ), INT2FIX( 255 ) ) ); rb_define_const( globalColorClass, "Cyan", rb_funcall( globalColorClass, rb_intern( "new" ), 3, INT2FIX( 0 ), INT2FIX( 255 ), INT2FIX( 255 ) ) ); + + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Black" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "White" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Red" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Green" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Blue" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Yellow" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Magneta" ) ), rb_intern( "freeze" ), 0 ); + rb_funcall( rb_cvar( globalColorClass, rb_intern( "Cyan" ) ), rb_intern( "freeze" ), 0 ); } diff --git a/bindings/ruby/sfml-graphics/graphics/Drawable.cpp b/bindings/ruby/sfml-graphics/graphics/Drawable.cpp index 32c9105a9..eeb983239 100644 --- a/bindings/ruby/sfml-graphics/graphics/Drawable.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Drawable.cpp @@ -60,6 +60,15 @@ static void Drawable_Free( rbDrawable *object ) delete object; } +/* call-seq: + * drawable.setPosition( x, y ) + * drawable.setPosition( vector2 ) + * + * Set the position of the object. + * + * This function completely overwrites the previous position. See Move to apply an offset based on the previous + * position instead. The default position of a drawable object is (0, 0). + */ static VALUE Drawable_SetPosition( int argc, VALUE *args, VALUE self ) { rbDrawable *object = NULL; @@ -87,6 +96,11 @@ static VALUE Drawable_SetPosition( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * drawable.setX( x ) + * + * Set the X position of the object. + */ static VALUE Drawable_SetX( VALUE self, VALUE aX ) { rbDrawable *object = NULL; @@ -95,6 +109,11 @@ static VALUE Drawable_SetX( VALUE self, VALUE aX ) return Qnil; } +/* call-seq: + * drawable.setY( y ) + * + * Set the Y position of the object. + */ static VALUE Drawable_SetY( VALUE self, VALUE aY ) { rbDrawable *object = NULL; @@ -103,6 +122,16 @@ static VALUE Drawable_SetY( VALUE self, VALUE aY ) return Qnil; } +/* call-seq: + * drawable.setScale( x, y ) + * drawable.setScale( vector2 ) + * + * Set the scale factors of the object. + * + * scale.x and scale.y must be strictly positive, otherwise they are ignored. This function completely overwrites + * the previous scale. See Scale to add a factor based on the previous scale instead. The default scale of a drawable + * object is (1, 1). + */ static VALUE Drawable_SetScale( int argc, VALUE *args, VALUE self ) { rbDrawable *object = NULL; @@ -130,6 +159,13 @@ static VALUE Drawable_SetScale( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * drawable.setScaleX( factor ) + * + * Set the X scale factor of the object. + * + * factor must be strictly positive, otherwise it is ignored. + */ static VALUE Drawable_SetScaleX( VALUE self, VALUE aX ) { rbDrawable *object = NULL; @@ -138,6 +174,13 @@ static VALUE Drawable_SetScaleX( VALUE self, VALUE aX ) return Qnil; } +/* call-seq: + * drawable.setScaleY( factor ) + * + * Set the Y scale factor of the object. + * + * factor must be strictly positive, otherwise it is ignored. + */ static VALUE Drawable_SetScaleY( VALUE self, VALUE aY ) { rbDrawable *object = NULL; @@ -146,6 +189,16 @@ static VALUE Drawable_SetScaleY( VALUE self, VALUE aY ) return Qnil; } +/* call-seq: + * drawable.setOrigin( x, y ) + * drawable.setOrigin( vector2 ) + * + * Set the local origin of the object. + * + * The origin of an object defines the center point for all transformations (position, scale, rotation). The + * coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations + * (position, scale, rotation). The default origin of a drawable object is (0, 0). + */ static VALUE Drawable_SetOrigin( int argc, VALUE *args, VALUE self ) { rbDrawable *object = NULL; @@ -173,6 +226,14 @@ static VALUE Drawable_SetOrigin( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * drawable.setRotation( angle ) + * + * Set the orientation of the object. + * + * This function completely overwrites the previous rotation. See Rotate to add an angle based on the previous + * rotation instead. The default rotation of a drawable object is 0. + */ static VALUE Drawable_SetRotation( VALUE self, VALUE aRotation ) { rbDrawable *object = NULL; @@ -181,6 +242,14 @@ static VALUE Drawable_SetRotation( VALUE self, VALUE aRotation ) return Qnil; } +/* call-seq: + * drawable.setColor( color ) + * + * Set the global color of the object. + * + * This global color affects the entire object, and modulates (multiplies) its original pixels. + * The default color is white. + */ static VALUE Drawable_SetColor( VALUE self, VALUE aColor ) { VALUE color = Color_ForceType( aColor ); @@ -190,6 +259,15 @@ static VALUE Drawable_SetColor( VALUE self, VALUE aColor ) return Qnil; } +/* call-seq: + * drawable.setBlendMode( mode ) + * + * Set the blending mode of the object. + * + * This property defines how the pixels of an object are blended with the pixels of the render target to which it is + * drawn. To know more about the blending modes available, see the SFML::Blend module. The default blend mode is + * SFML::Blend::Alpha. + */ static VALUE Drawable_SetBlendMode( VALUE self, VALUE aMode ) { rbDrawable *object = NULL; @@ -198,6 +276,11 @@ static VALUE Drawable_SetBlendMode( VALUE self, VALUE aMode ) return Qnil; } +/* call-seq: + * drawable.getPosition() -> vector2 + * + * Get the position of the object. + */ static VALUE Drawable_GetPosition( VALUE self ) { rbDrawable *object = NULL; @@ -206,6 +289,11 @@ static VALUE Drawable_GetPosition( VALUE self ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( vector.x ), rb_float_new( vector.y ) ); } +/* call-seq: + * drawable.getScale() -> vector2 + * + * Get the current scale of the object. + */ static VALUE Drawable_GetScale( VALUE self ) { rbDrawable *object = NULL; @@ -214,6 +302,11 @@ static VALUE Drawable_GetScale( VALUE self ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( vector.x ), rb_float_new( vector.y ) ); } +/* call-seq: + * drawable.getOrigin() -> vector2 + * + * Get the local origin of the object. + */ static VALUE Drawable_GetOrigin( VALUE self ) { rbDrawable *object = NULL; @@ -222,6 +315,13 @@ static VALUE Drawable_GetOrigin( VALUE self ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( vector.x ), rb_float_new( vector.y ) ); } +/* call-seq: + * drawable.getRotation() -> float + * + * Get the orientation of the object. + * + * The rotation is always in the range [0, 360]. + */ static VALUE Drawable_GetRotation( VALUE self ) { rbDrawable *object = NULL; @@ -229,6 +329,11 @@ static VALUE Drawable_GetRotation( VALUE self ) return rb_float_new( object->GetRotation() ); } +/* call-seq: + * drawable.getColor() -> color + * + * Get the color of the object. + */ static VALUE Drawable_GetColor( VALUE self ) { rbDrawable *object = NULL; @@ -238,6 +343,11 @@ static VALUE Drawable_GetColor( VALUE self ) INT2FIX( color.b ), INT2FIX( color.a ) ); } +/* call-seq: + * drawable.getBlendMode() -> mode + * + * Get the blend mode of the object. + */ static VALUE Drawable_GetBlendMode( VALUE self ) { rbDrawable *object = NULL; @@ -245,6 +355,14 @@ static VALUE Drawable_GetBlendMode( VALUE self ) return INT2FIX( object->GetBlendMode() ); } +/* call-seq: + * drawable.move( x, y ) + * drawable.move( vector2 ) + * + * Move the object by a given offset. + * + * This function adds to the current position of the object, unlike setPosition which overwrites it. + */ static VALUE Drawable_Move( int argc, VALUE *args, VALUE self ) { rbDrawable *object = NULL; @@ -272,6 +390,14 @@ static VALUE Drawable_Move( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * drawable.scale( x, y ) + * drawable.scale( vector2 ) + * + * Scale the object. + * + * This function multiplies the current scale of the object, unlike setScale which overwrites it. + */ static VALUE Drawable_Scale( int argc, VALUE *args, VALUE self ) { rbDrawable *object = NULL; @@ -299,6 +425,13 @@ static VALUE Drawable_Scale( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * drawable.rotate( angle ) + * + * Rotate the object. + * + * This function ads to the current rotation of the object, unlike setRotation which overwrites it + */ static VALUE Drawable_Rotate( VALUE self, VALUE aRotation ) { rbDrawable *object = NULL; @@ -307,6 +440,15 @@ static VALUE Drawable_Rotate( VALUE self, VALUE aRotation ) return Qnil; } +/* call-seq: + * drawable.transformToLocal( vector2 ) -> vector2 + * + * Transform a point in object local coordinates. + * + * This function takes a point in global coordinates, and transforms it in coordinates local to the object. In other + * words, it applies the inverse of all the transformations applied to the object (origin, translation, rotation + * and scale). + */ static VALUE Drawable_TransformToLocal( VALUE self, VALUE aPoint ) { VALUE point = Vector2_ForceType( point ); @@ -318,6 +460,14 @@ static VALUE Drawable_TransformToLocal( VALUE self, VALUE aPoint ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( newPoint.x ), rb_float_new( newPoint.y ) ); } +/* call-seq: + * drawable.transformToGlobal( vector2 ) -> vector2 + * + * Transform a local point in global coordinates. + * + * This function takes a point in local coordinates, and transforms it in global coordinates. In other words, it + * applies the same transformations that are applied to the object (origin, translation, rotation and scale). + */ static VALUE Drawable_TransformToGlobal( VALUE self, VALUE aPoint ) { VALUE point = Vector2_ForceType( point ); diff --git a/bindings/ruby/sfml-graphics/graphics/Font.cpp b/bindings/ruby/sfml-graphics/graphics/Font.cpp index 7a5e78672..14b9bbf16 100644 --- a/bindings/ruby/sfml-graphics/graphics/Font.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Font.cpp @@ -130,6 +130,11 @@ static VALUE Font_GetImage( VALUE self, VALUE aCharacterSize ) return rbImage; } +/* call-seq: + * Font.new() -> font + * + * Creates an empty font + */ static VALUE Font_New( int argc, VALUE *args, VALUE aKlass ) { sf::Font *object = new sf::Font(); @@ -138,10 +143,19 @@ static VALUE Font_New( int argc, VALUE *args, VALUE aKlass ) return rbData; } +/* call-seq: + * Font.getDefaultFont() -> font + * + * Return the default built-in font. + * + * This font is provided for convenience, it is used by SFML::Text instances by default. It is provided so that users + * don't have to provide and load a font file in order to display text on screen. The font used is Arial. + */ static VALUE Font_GetDefaultFont( VALUE aKlass ) { const sf::Font& font = sf::Font::GetDefaultFont(); VALUE rbFont = Data_Wrap_Struct( globalFontClass, 0, 0, const_cast( &font ) ); + rb_obj_call_init( rbFont, 0, 0 ); return rbFont; } @@ -215,6 +229,7 @@ void Init_Font( void ) rb_define_alias( CLASS_OF( globalFontClass ), "get_default_font", "getDefaultFont" ); rb_define_alias( CLASS_OF( globalFontClass ), "defaultFont", "getDefaultFont" ); rb_define_alias( CLASS_OF( globalFontClass ), "default_font", "getDefaultFont" ); + rb_define_alias( CLASS_OF( globalFontClass ), "DefaultFont", "getDefaultFont" ); // Instance Aliases rb_define_alias( globalFontClass , "load_from_file", "loadFromFile" ); diff --git a/bindings/ruby/sfml-graphics/graphics/Rect.cpp b/bindings/ruby/sfml-graphics/graphics/Rect.cpp index e6c5ea71f..5bd07a2f2 100644 --- a/bindings/ruby/sfml-graphics/graphics/Rect.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Rect.cpp @@ -128,9 +128,10 @@ static void Rect_internal_ValidateTypes( VALUE aFirst, VALUE aSecond, VALUE aThi } /* call-seq: - * Rect.new( x, y ) -> true or false - * Rect.new( vector2 ) -> true or false + * rect.contains( x, y ) -> true or false + * rect.contains( vector2 ) -> true or false * + * Check if a point is inside the rectangle's area. */ static VALUE Rect_Contains( int argc, VALUE * args, VALUE self ) { @@ -172,7 +173,14 @@ static VALUE Rect_Contains( int argc, VALUE * args, VALUE self ) } } -static VALUE Rect_Intersect( VALUE self, VALUE aRect ) +/* call-seq: + * rect.intersects( rectangle ) -> intersection rectangel or nil + * + * Check the intersection between two rectangles. + * + * This method returns the overlapped rectangle if intersecting otherwise nil. + */ +static VALUE Rect_Intersects( VALUE self, VALUE aRect ) { VALUE selfLeft = rb_funcall( self, rb_intern( "left" ), 0 ); VALUE selfTop = rb_funcall( self, rb_intern( "top" ), 0 ); @@ -332,7 +340,7 @@ void Init_Rect( void ) // Instance methods rb_define_method( globalRectClass, "initialize", Rect_Initialize, -1 ); rb_define_method( globalRectClass, "contains", Rect_Contains, -1 ); - rb_define_method( globalRectClass, "intersects", Rect_Contains, 1 ); + rb_define_method( globalRectClass, "intersects", Rect_Intersects, 1 ); // Instance operators diff --git a/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp b/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp index 58b208171..05f6d5457 100644 --- a/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp +++ b/bindings/ruby/sfml-graphics/graphics/RenderImage.cpp @@ -37,6 +37,16 @@ static void RenderImage_Free( sf::RenderImage *anObject ) delete anObject; } +/* call-seq: + * render_image.create( width, height, depthBuffer = false ) -> true or false + * + * Create the render-image. + * + * Before calling this function, the render-image is in an invalid state, thus it is mandatory to call it before + * doing anything with the render-image. The last parameter, depthBuffer, is useful if you want to use the render-image + * for 3D OpenGL rendering that requires a depth-buffer. Otherwise it is unnecessary, and you should leave this + * parameter to false (which is its default value). + */ static VALUE RenderImage_Create( int argc, VALUE *args, VALUE self ) { unsigned int width = 0; @@ -77,6 +87,16 @@ static VALUE RenderImage_Create( int argc, VALUE *args, VALUE self ) } } +/* call-seq: + * render_image.draw( drawable ) + * render_image.draw( drawable, shader ) + * + * Draw an object into the target with a shader. + * + * This function draws anything that inherits from the sf::Drawable base class (SFML::Sprite, SFML::Shape, SFML::Text, + * or even your own derived classes). The shader alters the way that the pixels are processed right before being + * written to the render target. + */ static VALUE RenderImage_Draw( int argc, VALUE *args, VALUE self ) { sf::RenderImage *object = NULL; @@ -108,13 +128,31 @@ static VALUE RenderImage_Draw( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * render_image.display() + * + * Update the contents of the target image. + * + * This function updates the target image with what has been drawn so far. Like for windows, calling this function is + * mandatory at the end of rendering. Not calling it may leave the image in an undefined state. + */ static VALUE RenderImage_Display( VALUE self ) { sf::RenderImage *object = NULL; Data_Get_Struct( self, sf::RenderImage, object ); object->Display(); + return Qnil; } +/* call-seq: + * render_image.getImage() -> image + * + * Get a read-only reference to the target image. + * + * After drawing to the render-image and calling display, you can retrieve the updated image using this function, and + * draw it using a sprite (for example). The internal SFML::Image of a render-image is always the same instance, so that + * it is possible to call this function once and keep a reference to the image even after is it modified. + */ static VALUE RenderImage_GetImage( VALUE self ) { sf::RenderImage *object = NULL; @@ -125,6 +163,11 @@ static VALUE RenderImage_GetImage( VALUE self ) return rbData; } +/* call-seq: + * render_image.isSmooth() -> true or false + * + * Tell whether the smooth filtering is enabled or not. + */ static VALUE RenderImage_IsSmooth( VALUE self ) { sf::RenderImage *object = NULL; @@ -132,6 +175,15 @@ static VALUE RenderImage_IsSmooth( VALUE self ) return ( object->IsSmooth() == true ? Qtrue : Qfalse ); } +/* call-seq: + * render_image.setActive( active ) + * + * Activate of deactivate the render-image for rendering. + * + * This function makes the render-image's context current for future OpenGL rendering operations (so you shouldn't + * care about it if you're not doing direct OpenGL stuff). Only one context can be current on a thread, so if you want + * to draw OpenGL geometry to another render target (like a RenderWindow) don't forget to activate it again. + */ static VALUE RenderImage_SetActive( int argc, VALUE *args, VALUE self ) { sf::RenderImage *object = NULL; @@ -161,6 +213,13 @@ static VALUE RenderImage_SetActive( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * render_image.setSmooth( smooth ) + * + * Enable or disable image smoothing. + * + * This function is similar to SFML::Image#setSmooth. This parameter is enabled by default. + */ static VALUE RenderImage_SetSmooth( VALUE self, VALUE aSmoothFlag ) { sf::RenderImage *object = NULL; @@ -180,6 +239,11 @@ static VALUE RenderImage_SetSmooth( VALUE self, VALUE aSmoothFlag ) return Qnil; } +/* call-seq: + * 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(); @@ -188,6 +252,15 @@ static VALUE RenderImage_New( int argc, VALUE *args, VALUE aKlass ) return rbData; } +/* call-seq: + * RenderImage.isAvailable() -> true or false + * + * Check whether the system supports render images or not. + * + * It is very important to always call this function before trying to use the RenderImage class, as the feature may + * not be supported on all platforms (especially very old ones). If this function returns false, then you won't be + * able to use the class at all. + */ static VALUE RenderImage_IsAvailable( VALUE aKlass ) { return ( sf::RenderImage::IsAvailable() == true ? Qtrue : Qfalse ); diff --git a/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp b/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp index 922c19412..86d543bcc 100644 --- a/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp +++ b/bindings/ruby/sfml-graphics/graphics/RenderTarget.cpp @@ -37,6 +37,13 @@ extern VALUE globalDrawableModule; extern VALUE globalShaderClass; extern VALUE globalViewClass; +/* call-seq: + * render_target.clear( color = SFML::Color::Black ) + * + * Clear the entire target with a single color. + * + * This function is usually called once every frame, to clear the previous contents of the target. + */ static VALUE RenderTarget_Clear( int argc, VALUE *args, VALUE self ) { sf::Color color = sf::Color::Black; @@ -62,6 +69,16 @@ static VALUE RenderTarget_Clear( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * render_target.draw( drawable ) + * render_target.draw( drawable, shader ) + * + * Draw an object into the target with a shader. + * + * This function draws anything that inherits from the SFML::Drawable base class (SFML::Sprite, SFML::Shape, SFML::Text, + * or even your own derived classes). The shader alters the way that the pixels are processed right before being written + * to the render target. + */ static VALUE RenderTarget_Draw( int argc, VALUE *args, VALUE self ) { sf::RenderTarget *object = NULL; @@ -94,6 +111,11 @@ static VALUE RenderTarget_Draw( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * render_target.getWidth() -> fixnum + * + * Return the width of the rendering region of the target. + */ static VALUE RenderTarget_GetWidth( VALUE self ) { sf::RenderTarget *object = NULL; @@ -101,6 +123,11 @@ static VALUE RenderTarget_GetWidth( VALUE self ) return INT2FIX( object->GetWidth() ); } +/* call-seq: + * render_target.getHeight() -> fixnum + * + * Return the height of the rendering region of the target. + */ static VALUE RenderTarget_GetHeight( VALUE self ) { sf::RenderTarget *object = NULL; @@ -108,6 +135,15 @@ static VALUE RenderTarget_GetHeight( VALUE self ) return INT2FIX( object->GetHeight() ); } +/* 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 RenderTarget_SetView( VALUE self, VALUE aView ) { VALIDATE_CLASS( aView, globalViewClass, "view" ); @@ -119,6 +155,11 @@ static VALUE RenderTarget_SetView( VALUE self, VALUE aView ) return Qnil; } +/* call-seq: + * render_target.getView() -> view + * + * Retrieve the view currently in use in the render target. + */ static VALUE RenderTarget_GetView( VALUE self ) { sf::RenderTarget *object = NULL; @@ -129,6 +170,13 @@ static VALUE RenderTarget_GetView( VALUE self ) 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 RenderTarget_GetDefaultView( VALUE self ) { sf::RenderTarget *object = NULL; @@ -139,6 +187,14 @@ static VALUE RenderTarget_GetDefaultView( VALUE self ) return rbData; } +/* call-seq: + * render_target.getViewport( view ) -> rectangle + * + * Get the viewport of a view, applied to this render target. + * + * The viewport is defined in the view as a ratio, this function simply applies this ratio to the current dimensions + * of the render target to calculate the pixels rectangle that the viewport actually covers in the target. + */ static VALUE RenderTarget_GetViewport( VALUE self, VALUE aView ) { VALIDATE_CLASS( aView, globalViewClass, "view" ); @@ -152,6 +208,19 @@ static VALUE RenderTarget_GetViewport( VALUE self, VALUE aView ) INT2FIX( viewport.Width ), INT2FIX( viewport.Height ) ); } +/* call-seq: + * render_target.convertCoords( x, y ) -> vector2 + * render_target.convertCoords( x, y, view ) -> vector2 + * + * Convert a point from target coordinates to view coordinates. + * + * Initially, a unit of the 2D world matches a pixel of the render target. But if you define a custom view, this + * assertion is not true anymore, ie. a point located at (10, 50) in your render target (for example a window) may + * map to the point (150, 75) in your 2D world -- for example if the view is translated by (140, 25). + * + * For render windows, this function is typically used to find which point (or object) is located below the mouse cursor. + * + */ static VALUE RenderTarget_ConvertCoords( int argc, VALUE *args, VALUE self ) { sf::RenderTarget *object = NULL; @@ -177,6 +246,30 @@ static VALUE RenderTarget_ConvertCoords( int argc, VALUE *args, VALUE self ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( result.x ), rb_float_new( result.y ) ); } +/* call-seq: + * render_target.saveGLStates() + * + * Save the current OpenGL render states and matrices. + * + * This function can be used when you mix SFML drawing and direct OpenGL rendering. Combined with RestoreGLStates, + * it ensures that: + * + * - SFML's internal states are not messed up by your OpenGL code + * - your OpenGL states are not modified by a call to a SFML function + * + * More specifically, it must be used around code that calls Draw functions. Example: + * + * # OpenGL code here... + * window.saveGLStates() + * window.draw(...) + * window.draw(...) + * window.restoreGLStates() + * # OpenGL code here... + * + * Note that this function is quite expensive and should be used wisely. It is provided for convenience, and the + * best results will be achieved if you handle OpenGL states yourself (because you really know which states have + * really changed, and need to be saved / restored). + */ static VALUE RenderTarget_SaveGLStates( VALUE self ) { sf::RenderTarget *object = NULL; @@ -185,6 +278,13 @@ static VALUE RenderTarget_SaveGLStates( VALUE self ) return Qnil; } +/* call-seq: + * render_target.restoreGLStates() + * + * Restore the previously saved OpenGL render states and matrices. + * + * See the description of saveGLStates to get a detailed description of these functions. + */ static VALUE RenderTarget_RestoreGLStates( VALUE self ) { sf::RenderTarget *object = NULL; diff --git a/bindings/ruby/sfml-graphics/graphics/RenderWindow.cpp b/bindings/ruby/sfml-graphics/graphics/RenderWindow.cpp index 166ebe7e1..2169f4581 100644 --- a/bindings/ruby/sfml-graphics/graphics/RenderWindow.cpp +++ b/bindings/ruby/sfml-graphics/graphics/RenderWindow.cpp @@ -37,6 +37,16 @@ static void RenderWindow_Free( sf::RenderWindow *anObject ) delete anObject; } +/* call-seq: + * render_window.draw( drawable ) + * render_window.draw( drawable, shader ) + * + * Draw an object into the target with a shader. + * + * This function draws anything that inherits from the SFML::Drawable base class (SFML::Sprite, SFML::Shape, + * SFML::Text, or even your own derived classes). The shader alters the way that the pixels are processed right before + * being written to the render target. + */ static VALUE RenderWindow_Draw( int argc, VALUE *args, VALUE self ) { sf::RenderWindow *object = NULL; @@ -68,13 +78,22 @@ static VALUE RenderWindow_Draw( int argc, VALUE *args, VALUE self ) return Qnil; } -static VALUE RenderWindow_Display( VALUE self ) -{ - sf::RenderWindow *object = NULL; - Data_Get_Struct( self, sf::RenderWindow, object ); - object->Display(); -} - +/* call-seq: + * 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(); diff --git a/bindings/ruby/sfml-graphics/graphics/Renderer.cpp b/bindings/ruby/sfml-graphics/graphics/Renderer.cpp index 2d6e8e335..a76675dbb 100644 --- a/bindings/ruby/sfml-graphics/graphics/Renderer.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Renderer.cpp @@ -27,13 +27,17 @@ #include VALUE globalRendererClass; -VALUE globalPrimitiveTypesNamespace; /* External classes */ extern VALUE globalColorClass; extern VALUE globalImageClass; extern VALUE globalShaderClass; +/* call-seq: + * renderer.saveGLStates() + * + * Save the current OpenGL render states and matrices. + */ static VALUE Renderer_SaveGLStates( VALUE self ) { sf::Renderer *object = NULL; @@ -42,6 +46,11 @@ static VALUE Renderer_SaveGLStates( VALUE self ) return Qnil; } +/* call-seq: + * renderer.restoreGLStates() + * + * Restore the previously saved OpenGL render states and matrices. + */ static VALUE Renderer_RestoreGLStates( VALUE self ) { sf::Renderer *object = NULL; @@ -50,6 +59,11 @@ static VALUE Renderer_RestoreGLStates( VALUE self ) return Qnil; } +/* call-seq: + * renderer.clear() + * + * Clear the color buffer. + */ static VALUE Renderer_Clear( VALUE self, VALUE aColor ) { VALUE temp = Color_ForceType( aColor ); @@ -64,6 +78,11 @@ static VALUE Renderer_Clear( VALUE self, VALUE aColor ) return Qnil; } +/* call-seq: + * renderer.pushStates() + * + * Save the current render states. + */ static VALUE Renderer_PushStates( VALUE self ) { sf::Renderer *object = NULL; @@ -72,6 +91,11 @@ static VALUE Renderer_PushStates( VALUE self ) return Qnil; } +/* call-seq: + * renderer.popStates() + * + * Restore the previously saved render states. + */ static VALUE Renderer_PopStates( VALUE self ) { sf::Renderer *object = NULL; @@ -80,6 +104,14 @@ static VALUE Renderer_PopStates( VALUE self ) return Qnil; } +/* call-seq: + * renderer.setColor( color ) + * + * Set the current global color. + * + * This color will be modulated with each vertex's color. Note: any call to this function after a call to BeginBatch + * will be ignored, and delayed until BeginBatch is called again. + */ static VALUE Renderer_SetColor( VALUE self, VALUE aColor ) { VALUE temp = Color_ForceType( aColor ); @@ -94,6 +126,14 @@ static VALUE Renderer_SetColor( VALUE self, VALUE aColor ) return Qnil; } +/* call-seq: + * renderer.applyColor( color ) + * + * Modulate the current global color with a new one. + * + * This color will be modulated with each vertex's color. Note: any call to this function after a call to BeginBatch + * will be ignored, and delayed until BeginBatch is called again. + */ static VALUE Renderer_ApplyColor( VALUE self, VALUE aColor ) { VALUE temp = Color_ForceType( aColor ); @@ -108,6 +148,13 @@ static VALUE Renderer_ApplyColor( VALUE self, VALUE aColor ) return Qnil; } +/* call-seq: + * renderer.setViewport( rectangle ) + * + * Set the current viewport. + * + * Note: any call to this function after a call to BeginBatch will be ignored, and delayed until BeginBatch is called again. + */ static VALUE Renderer_SetViewport( VALUE self, VALUE aRect ) { VALUE temp = Rect_ForceType( aRect ); @@ -122,6 +169,13 @@ static VALUE Renderer_SetViewport( VALUE self, VALUE aRect ) return Qnil; } +/* call-seq: + * renderer.setBlendMode( mode ) + * + * Set the current alpha-blending mode. + * + * Note: any call to this function after a call to BeginBatch will be ignored, and delayed until BeginBatch is called again. + */ static VALUE Renderer_SetBlendMode( VALUE self, VALUE aMode ) { sf::Renderer *object = NULL; @@ -130,6 +184,13 @@ static VALUE Renderer_SetBlendMode( VALUE self, VALUE aMode ) return Qnil; } +/* call-seq: + * renderer.setTexture( texture ) + * + * Set the current texture. + * + * Note: any call to this function after a call to BeginBatch will be ignored, and delayed until BeginBatch is called again. + */ static VALUE Renderer_SetTexture( VALUE self, VALUE aTexture ) { VALIDATE_CLASS( aTexture, globalImageClass, "texture" ); @@ -141,6 +202,13 @@ static VALUE Renderer_SetTexture( VALUE self, VALUE aTexture ) return Qnil; } +/* call-seq: + * renderer.setShader( shader ) + * + * Set the current shader. + * + * Note: any call to this function after a call to BeginBatch will be ignored, and delayed until BeginBatch is called again. + */ static VALUE Renderer_SetShader( VALUE self, VALUE aShader ) { VALIDATE_CLASS( aShader, globalShaderClass, "shader" ); @@ -152,6 +220,23 @@ static VALUE Renderer_SetShader( VALUE self, VALUE aShader ) return Qnil; } +/* call-seq: + * renderer.begin( type ) + * + * Begin rendering a new geometry batch. + * + * You need to call SFML::Renderer#end to complete the batch and trigger the actual rendering of the geometry that you + * passed between begin() and end(). + * + * Usage: + * + * renderer.begin( SFML::Renderer::TriangleList ) + * renderer.addVertex(...) + * renderer.addVertex(...) + * renderer.addVertex(...) + * renderer.end() + * + */ static VALUE Renderer_Begin( VALUE self, VALUE aType ) { sf::Renderer *object = NULL; @@ -160,6 +245,11 @@ static VALUE Renderer_Begin( VALUE self, VALUE aType ) return Qnil; } +/* call-seq: + * renderer.end() + * + * End the current geometry batch and render it. + */ static VALUE Renderer_End( VALUE self ) { sf::Renderer *object = NULL; @@ -168,6 +258,14 @@ static VALUE Renderer_End( VALUE self ) return Qnil; } +/* call-seq: + * renderer.addVertex( x, y ) + * renderer.addVertex( x, y, u, v ) + * renderer.addVertex( x, y color ) + * renderer.addVertex( x, y, u, v, color ) + * + * This function adds a new vertex to the current batch. + */ static VALUE Renderer_AddVertex( int argc, VALUE *args, VALUE self ) { sf::Renderer *object = NULL; @@ -214,11 +312,10 @@ static VALUE Renderer_AddVertex( int argc, VALUE *args, VALUE self ) static void DefinePrimitiveTypesEnum( void ) { - globalPrimitiveTypesNamespace = rb_define_module_under( globalRendererClass, "PrimitiveTypes" ); - rb_define_const( globalPrimitiveTypesNamespace, "TriangleList", INT2FIX( sf::Renderer::TriangleList ) ); - rb_define_const( globalPrimitiveTypesNamespace, "TriangleStrip", INT2FIX( sf::Renderer::TriangleStrip ) ); - rb_define_const( globalPrimitiveTypesNamespace, "TriangleFan", INT2FIX( sf::Renderer::TriangleFan ) ); - rb_define_const( globalPrimitiveTypesNamespace, "QuadList", INT2FIX( sf::Renderer::QuadList ) ); + rb_define_const( globalRendererClass, "TriangleList", INT2FIX( sf::Renderer::TriangleList ) ); + rb_define_const( globalRendererClass, "TriangleStrip", INT2FIX( sf::Renderer::TriangleStrip ) ); + rb_define_const( globalRendererClass, "TriangleFan", INT2FIX( sf::Renderer::TriangleFan ) ); + rb_define_const( globalRendererClass, "QuadList", INT2FIX( sf::Renderer::QuadList ) ); } void Init_Renderer( void ) diff --git a/bindings/ruby/sfml-graphics/graphics/Shader.cpp b/bindings/ruby/sfml-graphics/graphics/Shader.cpp index 8bea44bd7..bcfe8a6b6 100644 --- a/bindings/ruby/sfml-graphics/graphics/Shader.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Shader.cpp @@ -38,6 +38,14 @@ static void Shader_Free( sf::Shader *anObject ) delete anObject; } +/* call-seq: + * shader.loadFromFile( filename ) -> true or false + * + * Load the shader from a file. + * + * The source must be a text file containing a valid fragment shader in GLSL language. GLSL is a C-like language + * dedicated to OpenGL shaders; you'll probably need to read a good documentation for it before writing your own shaders. + */ static VALUE Shader_LoadFromFile( VALUE self, VALUE aFileName ) { sf::Shader *object = NULL; @@ -52,6 +60,14 @@ static VALUE Shader_LoadFromFile( VALUE self, VALUE aFileName ) } } +/* call-seq: + * shader.loadFromMemory( filename ) -> true or false + * + * Load the shader from a source code in memory. + * + * The source code must be a valid fragment shader in GLSL language. GLSL is a C-like language dedicated to OpenGL + * shaders; you'll probably need to read a good documentation for it before writing your own shaders. + */ static VALUE Shader_LoadFromMemory( VALUE self, VALUE aShader ) { sf::Shader *object = NULL; @@ -66,6 +82,16 @@ static VALUE Shader_LoadFromMemory( VALUE self, VALUE aShader ) } } +/* call-seq: + * shader.setParameter( name, x ) + * shader.setParameter( name, x, y ) + * shader.setParameter( name, x, y, z ) + * shader.setParameter( name, x, y, z, w ) + * shader.setParameter( name, vector2 ) + * shader.setParameter( name, vector3 ) + * + * Change a vector parameter of the shader. + */ static VALUE Shader_SetParameter( int argc, VALUE *args, VALUE self ) { sf::Shader *object = NULL; @@ -125,6 +151,25 @@ static VALUE Shader_SetParameter( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * shader.setParameter( name, texture ) + * + * Change a texture parameter of the shader. + * + * name is the name of the texture to change in the shader. To tell the shader to use the current texture of the object + * being drawn, pass Shader::CurrentTexture. Example: + * + * # These are the variables in the pixel shader + * uniform sampler2D current; + * uniform sampler2D other; + * + * image = SFML::Image.new + * ... + * shader.setParameter( "current", SFML::Shader::CurrentTexture ) + * shader.setParameter( "other", image ) + * +* It is important to note that texture must remain alive as long as the shader uses it, no copy is made internally. + */ static VALUE Shader_SetTexture( VALUE self, VALUE aName, VALUE aTexture ) { VALIDATE_CLASS( aName, rb_cString, "name" ); @@ -138,6 +183,14 @@ static VALUE Shader_SetTexture( VALUE self, VALUE aName, VALUE aTexture ) return Qnil; } +/* call-seq: + * shader.bind() + * + * Bind the shader for rendering (activate it). + * + * This function is normally for internal use only, unless you want to use the shader with a custom OpenGL rendering + * instead of a SFML drawable. + */ static VALUE Shader_Bind( VALUE self ) { sf::Shader *object = NULL; @@ -146,6 +199,14 @@ static VALUE Shader_Bind( VALUE self ) return Qnil; } +/* call-seq: + * shader.unbind() + * + * Unbind the shader (deactivate it). + * + * This function is normally for internal use only, unless you want to use the shader with a custom OpenGL rendering + * instead of a SFML drawable. + */ static VALUE Shader_Unbind( VALUE self ) { sf::Shader *object = NULL; @@ -154,6 +215,11 @@ static VALUE Shader_Unbind( VALUE self ) return Qnil; } +/* call-seq: + * Shader.new() + * + * Create a new shader. + */ static VALUE Shader_New( int argc, VALUE *args, VALUE aKlass ) { sf::Shader *object = new sf::Shader(); @@ -162,6 +228,14 @@ static VALUE Shader_New( int argc, VALUE *args, VALUE aKlass ) return rbData; } +/* call-seq: + * Shader.isAvailable() + * + * Tell whether or not the system supports shaders. + * + * This function should always be called before using the shader features. If it returns false, then any attempt to + * use SFML::Shader will fail. + */ static VALUE Shader_IsAvailable( VALUE aKlass ) { return ( sf::Shader::IsAvailable() == true ? Qtrue : Qfalse ); diff --git a/bindings/ruby/sfml-graphics/graphics/Shape.cpp b/bindings/ruby/sfml-graphics/graphics/Shape.cpp index 8c58e6d60..f414a93a8 100644 --- a/bindings/ruby/sfml-graphics/graphics/Shape.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Shape.cpp @@ -38,6 +38,14 @@ static void Shape_Free( sf::Shape *anObject ) delete anObject; } +/* call-seq: + * shape.addPoint( x, y, color, outlineColor ) + * shape.addPoint( position, color, outlineColor ) + * + * Add a new point to the shape. + * + * The new point is inserted at the end of the shape. + */ static VALUE Shape_AddPoint( int argc, VALUE *args, VALUE self ) { VALUE temp = Qnil; @@ -102,6 +110,11 @@ static VALUE Shape_AddPoint( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * shape.getPointsCount() -> fixnum + * + * Get the number of points composing the shape. + */ static VALUE Shape_GetPointsCount( VALUE self ) { sf::Shape *object = NULL; @@ -109,6 +122,13 @@ static VALUE Shape_GetPointsCount( VALUE self ) return INT2FIX( object->GetPointsCount() ); } +/* call-seq: + * shape.enableFill( enable ) + * + * Enable or disable the shape's filling. + * + * This option is enabled by default. + */ static VALUE Shape_EnableFill( VALUE self, VALUE anEnableFlag ) { sf::Shape *object = NULL; @@ -128,6 +148,13 @@ static VALUE Shape_EnableFill( VALUE self, VALUE anEnableFlag ) return Qnil; } +/* call-seq: + * shape.enableOutline( enable ) + * + * Enable or disable the shape's outline. + * + * This option is enabled by default. + */ static VALUE Shape_EnableOutline( VALUE self, VALUE anEnableFlag ) { sf::Shape *object = NULL; @@ -147,6 +174,15 @@ static VALUE Shape_EnableOutline( VALUE self, VALUE anEnableFlag ) return Qnil; } +/* call-seq: + * shape.setPointPosition( index, position ) + * shape.setPointPosition( index, x, y ) + * + * Change the position of a point. + * + * Warning: this function doesn't check the validity of index, if it is out of bounds (ie. in the range + * [0, GetPointscount() - 1]) the behaviour is undefined. + */ static VALUE Shape_SetPointPosition( int argc, VALUE *args, VALUE self ) { VALUE temp = Qnil; @@ -173,6 +209,14 @@ static VALUE Shape_SetPointPosition( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * shape.setPointColor( index, color ) + * + * Change the color of a point. + * + * Warning: this function doesn't check the validity of index, if it is out of bounds (ie. in the range + * [0, GetPointscount() - 1]) the behaviour is undefined. + */ static VALUE Shape_SetPointColor( VALUE self, VALUE anIndex, VALUE aColor ) { sf::Shape *object = NULL; @@ -187,6 +231,14 @@ static VALUE Shape_SetPointColor( VALUE self, VALUE anIndex, VALUE aColor ) return Qnil; } +/* call-seq: + * shape.setPointOutlineColor( index, color ) + * + * Change the outline color of a point. + * + * Warning: this function doesn't check the validity of index, if it is out of bounds (ie. in the range + * [0, GetPointscount() - 1]) the behaviour is undefined. + */ static VALUE Shape_SetPointOutlineColor( VALUE self, VALUE anIndex, VALUE aColor ) { sf::Shape *object = NULL; @@ -201,6 +253,11 @@ static VALUE Shape_SetPointOutlineColor( VALUE self, VALUE anIndex, VALUE aColor return Qnil; } +/* call-seq: + * shape.setOutlineWidth( width ) + * + * Change the thickness of the shape outline. + */ static VALUE Shape_SetOutlineWidth( VALUE self, VALUE aWidth ) { sf::Shape *object = NULL; @@ -209,6 +266,14 @@ static VALUE Shape_SetOutlineWidth( VALUE self, VALUE aWidth ) return Qnil; } +/* call-seq: + * shape.getPointPosition( index ) -> vector2 + * + * Get the position of a point. + * + * Warning: this function doesn't check the validity of index, if it is out of bounds (ie. in the range + * [0, GetPointscount() - 1]) the behaviour is undefined. + */ static VALUE Shape_GetPointPosition( VALUE self, VALUE anIndex ) { sf::Shape *object = NULL; @@ -217,6 +282,14 @@ static VALUE Shape_GetPointPosition( VALUE self, VALUE anIndex ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( vector.x ), rb_float_new( vector.y ) ); } +/* call-seq: + * shape.getPointColor( index ) -> color + * + * Get the color of a point. + * + * Warning: this function doesn't check the validity of index, if it is out of bounds (ie. in the range + * [0, GetPointscount() - 1]) the behaviour is undefined. + */ static VALUE Shape_GetPointColor( VALUE self, VALUE anIndex ) { sf::Shape *object = NULL; @@ -227,6 +300,14 @@ static VALUE Shape_GetPointColor( VALUE self, VALUE anIndex ) INT2FIX( color.b ), INT2FIX( color.a ) ); } +/* call-seq: + * shape.getPointOutlineColor( index ) -> color + * + * Get the outline color of a point. + * + * Warning: this function doesn't check the validity of index, if it is out of bounds (ie. in the range + * [0, GetPointscount() - 1]) the behaviour is undefined. + */ static VALUE Shape_GetPointOutlineColor( VALUE self, VALUE anIndex ) { sf::Shape *object = NULL; @@ -237,6 +318,11 @@ static VALUE Shape_GetPointOutlineColor( VALUE self, VALUE anIndex ) INT2FIX( color.b ), INT2FIX( color.a ) ); } +/* call-seq: + * shape.getOutlineWidth() -> float + * + * Get the thickness of the shape outline. + */ static VALUE Shape_GetOutlineWidth( VALUE self ) { sf::Shape *object = NULL; @@ -244,6 +330,11 @@ static VALUE Shape_GetOutlineWidth( VALUE self ) return rb_float_new( object->GetOutlineWidth() ); } +/* call-seq: + * Shape.new() -> shape + * + * Create an empty shape. + */ static VALUE Shape_New( int argc, VALUE *args, VALUE aKlass ) { sf::Shape *object = new sf::Shape(); @@ -252,6 +343,12 @@ static VALUE Shape_New( int argc, VALUE *args, VALUE aKlass ) return rbData; } +/* call-seq: + * Shape.line( p1x, p1y, p2x, p2y, thickness, color, outline = 0.0, outlineColor = SFML::Color::Black) -> shape + * Shape.line( start, end, thickness, color, outline = 0.0, outlineColor = SFML::Color::Black) -> shape + * + * Create a new line. + */ static VALUE Shape_Line( int argc, VALUE *args, VALUE aKlass ) { VALUE temp = Qnil; @@ -323,6 +420,12 @@ static VALUE Shape_Line( int argc, VALUE *args, VALUE aKlass ) return rbData; } +/* call-seq: + * Shape.rectangle( left, top, width, height, color, outline = 0.0, outlineColor = SFML::Color::Black) -> shape + * Shape.rectangle( rectangle, color, outline = 0.0, outlineColor = SFML::Color::Black) -> shape + * + * Create a new rectangular shape. + */ static VALUE Shape_Rectangle( int argc, VALUE *args, VALUE aKlass ) { VALUE temp = Qnil; @@ -390,6 +493,12 @@ static VALUE Shape_Rectangle( int argc, VALUE *args, VALUE aKlass ) return rbData; } +/* call-seq: + * Shape.circle( x, y, radius, color, outline = 0.0, outlineColor = SFML::Color::Black) -> shape + * Shape.circle( center, radius, color, outline = 0.0, outlineColor = SFML::Color::Black) -> shape + * + * Create a new circular shape. + */ static VALUE Shape_Circle( int argc, VALUE *args, VALUE aKlass ) { VALUE temp = Qnil; diff --git a/bindings/ruby/sfml-graphics/graphics/Sprite.cpp b/bindings/ruby/sfml-graphics/graphics/Sprite.cpp index 986c0a0fa..9d9d05e9e 100644 --- a/bindings/ruby/sfml-graphics/graphics/Sprite.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Sprite.cpp @@ -40,6 +40,12 @@ static void Sprite_Free( sf::Sprite *anObject ) delete anObject; } +/* call-seq: + * Sprite.new() -> sprite + * Sprite.new( image, position = [0, 0], scale = [1, 1], rotation = 0.0, color = SFML::Color::White ) -> sprite + * + * Construct the sprite from a source image. + */ static VALUE Sprite_Initialize( int argc, VALUE *args, VALUE self ) { VALUE temp = Qnil; @@ -82,6 +88,17 @@ static VALUE Sprite_Initialize( int argc, VALUE *args, VALUE self ) return self; } +/* call-seq: + * sprite.setImage( image, adjustToNewSize = false) + * + * Change the source image of the sprite. + * + * The image argument refers to an image that must exist as long as the sprite uses it. Indeed, the sprite doesn't + * store its own copy of the image, but rather keeps a pointer to the one that you passed to this function. If the + * source image is destroyed and the sprite tries to use it, it may appear as a white rectangle. If adjustToNewSize is + * true, the SubRect property of the sprite is adjusted to the size of the new image. If it is false, the SubRect + * is unchanged. + */ static VALUE Sprite_SetImage( int argc, VALUE *args, VALUE self ) { sf::Image *image = NULL; @@ -89,6 +106,7 @@ static VALUE Sprite_SetImage( int argc, VALUE *args, VALUE self ) sf::Sprite *object = NULL; Data_Get_Struct( self, sf::Sprite, object ); + rb_iv_set( self, "@__image_ref", Qnil ); switch( argc ) { case 2: @@ -116,6 +134,14 @@ static VALUE Sprite_SetImage( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * sprite.setSubRect( rectangle ) + * + * Set the part of the image that the sprite will display. + * + * The sub-rectangle is useful when you don't want to display the whole image, but rather a part of it. By default, + * the sub-rectangle covers the entire image. + */ static VALUE Sprite_SetSubRect( VALUE self, VALUE aRectangle ) { VALUE temp = Rect_ForceType( aRectangle ); @@ -127,6 +153,15 @@ static VALUE Sprite_SetSubRect( VALUE self, VALUE aRectangle ) return Qnil; } +/* call-seq: + * sprite.resize( width, height ) + * sprite.resize( vector2 ) + * + * Change the size of the sprite. + * + * This function is just a shortcut that calls SetScale with the proper values, calculated from the size of the current + * subrect. If width or height is not strictly positive, this functions does nothing. + */ static VALUE Sprite_Resize( int argc, VALUE *args, VALUE self ) { VALUE arg0 = Qnil; @@ -152,6 +187,11 @@ static VALUE Sprite_Resize( int argc, VALUE *args, VALUE self ) return Qnil; } +/* call-seq: + * sprite.flipX( flipped ) + * + * Flip the sprite horizontally. + */ static VALUE Sprite_FlipX( VALUE self, VALUE aFlippedFlag ) { sf::Sprite *object = NULL; @@ -171,6 +211,11 @@ static VALUE Sprite_FlipX( VALUE self, VALUE aFlippedFlag ) return Qnil; } +/* call-seq: + * sprite.flipY( flipped ) + * + * Flip the sprite vertically. + */ static VALUE Sprite_FlipY( VALUE self, VALUE aFlippedFlag ) { sf::Sprite *object = NULL; @@ -190,11 +235,23 @@ static VALUE Sprite_FlipY( VALUE self, VALUE aFlippedFlag ) return Qnil; } +/* call-seq: + * sprite.getImage() -> image or nil + * + * Get the source image of the sprite. + * + * If the sprite has no source image, or if the image doesn't exist anymore, nil is returned. + */ static VALUE Sprite_GetImage( VALUE self ) { return rb_iv_get( self, "@__image_ref" ); } +/* call-seq: + * sprite.getSubRect() -> rectangle + * + * Get the region of the image displayed by the sprite. + */ static VALUE Sprite_GetSubRect( VALUE self ) { sf::Sprite *object = NULL; @@ -205,6 +262,13 @@ static VALUE Sprite_GetSubRect( VALUE self ) INT2FIX( rect.Width ), INT2FIX( rect.Height ) ); } +/* call-seq: + * sprite.getSize() -> vector2 + * + * Get the global size of the sprite. + * + * This function is a shortcut that multiplies the size of the subrect by the scale factors. + */ static VALUE Sprite_GetSize( VALUE self ) { sf::Sprite *object = NULL; @@ -213,6 +277,15 @@ static VALUE Sprite_GetSize( VALUE self ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( size.x ), rb_float_new( size.y ) ); } +/* call-seq: + * sprite.getPixel( x, y ) -> color + * + * Get the color of a given pixel in the sprite. + * + * This function returns the source image pixel, multiplied by the global color of the sprite. The input point must + * be in local coordinates. If you have a global point, you can use the TransformToLocal function to make it local. + * This function doesn't perform any check, you must ensure that the x and y coordinates are not out of bounds. + */ static VALUE Sprite_GetPixel( VALUE self, VALUE aX, VALUE aY ) { sf::Sprite *object = NULL; diff --git a/bindings/ruby/sfml-graphics/graphics/Text.cpp b/bindings/ruby/sfml-graphics/graphics/Text.cpp index 4d4a4d883..dc1a68641 100644 --- a/bindings/ruby/sfml-graphics/graphics/Text.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Text.cpp @@ -40,6 +40,12 @@ static void Text_Free( sf::Text *anObject ) delete anObject; } +/* call-seq: + * Text.new() -> text + * Text.new( string, font = SFML::Font::DefaultFont, characterSize = 30 ) -> text + * + * Create a text instance + */ static VALUE Text_Initialize( int argc, VALUE *args, VALUE self ) { VALUE temp = Qnil; @@ -68,6 +74,11 @@ static VALUE Text_Initialize( int argc, VALUE *args, VALUE self ) return self; } +/* call-seq: + * text.setString( string ) + * + * Set the text's string. + */ static VALUE Text_SetString( VALUE self, VALUE aString ) { sf::Text *object = NULL; @@ -76,6 +87,13 @@ static VALUE Text_SetString( VALUE self, VALUE aString ) return Qnil; } +/* call-seq: + * text.setFont( font ) + * + * Set the text's font. + * + * Texts have a valid font by default, which the built-in SFML::Font::DefaultFont. + */ static VALUE Text_SetFont( VALUE self, VALUE aFont ) { VALIDATE_CLASS( aFont, globalFontClass, "font" ); @@ -88,6 +106,13 @@ static VALUE Text_SetFont( VALUE self, VALUE aFont ) return Qnil; } +/* call-seq: + * text.setCharacterSize( size ) + * + * Set the character size. + * + * The default size is 30. + */ static VALUE Text_SetCharacterSize( VALUE self, VALUE aSize ) { sf::Text *object = NULL; @@ -96,6 +121,14 @@ static VALUE Text_SetCharacterSize( VALUE self, VALUE aSize ) return Qnil; } +/* call-seq: + * text.setStyle( style ) + * + * Set the text's style. + * + * You can pass a combination of one or more styles, for example sf::Text::Bold | sf::Text::Italic. The default style + * is sf::Text::Regular. + */ static VALUE Text_SetStyle( VALUE self, VALUE aStyle ) { sf::Text *object = NULL; @@ -104,6 +137,11 @@ static VALUE Text_SetStyle( VALUE self, VALUE aStyle ) return Qnil; } +/* call-seq: + * text.getString() -> string + * + * Get the text's string. + */ static VALUE Text_GetString( VALUE self ) { sf::Text *object = NULL; @@ -111,11 +149,21 @@ static VALUE Text_GetString( VALUE self ) return rb_str_new2( object->GetString().ToAnsiString().c_str() ); } +/* call-seq: + * text.getFont() -> font + * + * Get the text's font. + */ static VALUE Text_GetFont( VALUE self ) { return rb_iv_get( self, "@__font_ref" ); } +/* call-seq: + * text.getCharacterSize() -> fixnum + * + * Get the character size + */ static VALUE Text_GetCharacterSize( VALUE self ) { sf::Text *object = NULL; @@ -123,6 +171,11 @@ static VALUE Text_GetCharacterSize( VALUE self ) return INT2FIX( object->GetCharacterSize() ); } +/* call-seq: + * text.getStyle() -> fixnum + * + * Get the text's style. + */ static VALUE Text_GetStyle( VALUE self ) { sf::Text *object = NULL; @@ -130,6 +183,16 @@ static VALUE Text_GetStyle( VALUE self ) return INT2FIX( object->GetStyle() ); } +/* call-seq: + * text.getCharacterPos( index ) -> vector2 + * + * Return the position of the index-th character. + * + * This function computes the visual position of a character from its index in the string. The returned position is in + * local coordinates (translation, rotation, scale and origin are not applied). You can easily get the corresponding + * global position with the TransformToGlobal function. If index is out of range, the position of the end of the + * string is returned. + */ static VALUE Text_GetCharacterPos( VALUE self, VALUE anIndex ) { sf::Text *object = NULL; @@ -138,6 +201,13 @@ static VALUE Text_GetCharacterPos( VALUE self, VALUE anIndex ) return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( pos.x ), rb_float_new( pos.y ) ); } +/* call-seq: + * text.getRect() -> rectangle + * + * Get the bounding rectangle of the text. + * + * The returned rectangle is in global coordinates. + */ static VALUE Text_GetRect( VALUE self ) { sf::Text *object = NULL; @@ -168,44 +238,44 @@ void Init_Text( void ) { /* SFML namespace which contains the classes of this module. */ VALUE sfml = rb_define_module( "SFML" ); -/* Drawable representation of an image, with its own transformations, color, blend mode, etc. +/* Graphical text that can be drawn to a render target. * - * SFML::Sprite is a drawable class that allows to easily display an image (or a part of it) on a render target. + * SFML::Text is a drawable class that allows to easily display some text with custom style and color on a render target. * * It inherits all the functions from SFML::Drawable: position, rotation, scale, origin, global color and blend mode. - * It also adds sprite-specific properties such as the image to use, the part of it to display, and some convenience - * functions to flip or resize the sprite. + * It also adds text-specific properties such as the font to use, the character size, the font style (bold, italic, + * underlined), and the text to display of course. It also provides convenience functions to calculate the graphical + * size of the text, or to get the visual position of a given character. * - * SFML::Sprite works in combination with the SFML::Image class, which loads and provides the pixel data of a - * given image. + * SFML::Text works in combination with the sf::Font class, which loads and provides the glyphs (visual characters) of + * a given font. * - * The separation of SFML::Sprite and SFML::Image allows more flexibility and better performances: indeed a SFML::Image - * is a heavy resource, and any operation on it is slow (often too slow for real-time applications). On the other side, - * a SFML::Sprite is a lightweight object which can use the pixel data of a SFML::Image and draw it with its own - * transformation / color / blending attributes. + * The separation of SFML::Font and SFML::Text allows more flexibility and better performances: indeed a SFML::Font is a + * heavy resource, and any operation on it is slow (often too slow for real-time applications). On the other side, a + * SFML::Text is a lightweight object which can combine the glyphs data and metrics of a SFML::Font to display any + * text on a render target. + * + * It is important to note that the SFML::Text instance doesn't copy the font that it uses, it only keeps a + * reference to it. Thus, a SFML::Font must not be destructed while it is used by a SFML::Text (i.e. never write a + * function that uses a local SFML::Font instance for creating a text). * - * It is important to note that the SFML::Sprite instance doesn't copy the image that it uses, it only keeps a reference - * to it. Thus, a SFML::Image must not be destructed while it is used by a SFML::Sprite (i.e. never write a function that - * uses a local SFML::Image instance for creating a sprite). - * - * NOTE: This is the ruby bindings so the images will be managed by the ruby garbage collector and thus the image won't + * NOTE: This is the ruby bindings so the fonts will be managed by the ruby garbage collector and thus the font won't * be destructed until all sprites referencing it is destructed. But it's still a good practice to keep in mind. * * Usage example: * - * # Declare and load an image - * image = SFML::Image.new - * image.loadFromFile( "image.png" ) + * # Declare and load a font + * font = SFML::Font.new + * font.loadFromFile( "arial.ttf" ) * - * # Create a sprite - * sprite = SFML::Sprite.new - * sprite.image = image - * sprite.subRect = [10, 10, 50, 30] - * sprite.resize( 100, 60 ) + * # Create a text + * text SFML::Text.new( "hello" ) + * text.setFont( font ) + * text.SetCharacterSize( 30 ) + * text.setStyle( SFML::Text::Regular ) * * # Display it - * window.draw( sprite ) # window is a SFML::RenderWindow - * + * window.draw( text ) # window is a SFML::RenderWindow */ globalTextClass = rb_define_class_under( sfml, "Text", rb_cObject ); rb_include_module( globalTextClass, globalDrawableModule ); diff --git a/bindings/ruby/sfml-graphics/graphics/View.cpp b/bindings/ruby/sfml-graphics/graphics/View.cpp index 6698ca6f3..065acb5e3 100644 --- a/bindings/ruby/sfml-graphics/graphics/View.cpp +++ b/bindings/ruby/sfml-graphics/graphics/View.cpp @@ -36,175 +36,13 @@ static void View_Free( sf::View *anObject ) delete anObject; } -static VALUE View_GetCenter( VALUE self ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - const sf::Vector2f& center = object->GetCenter(); - return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( center.x ), rb_float_new( center.y ) ); -} - -static VALUE View_GetRotation( VALUE self ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - return rb_float_new( object->GetRotation() ); -} - -static VALUE View_GetSize( VALUE self ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - const sf::Vector2f& size = object->GetSize(); - return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( size.x ), rb_float_new( size.y ) ); -} - -static VALUE View_GetViewport( VALUE self ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - const sf::FloatRect& viewport = object->GetViewport(); - return rb_funcall( globalRectClass, rb_intern( "new" ), 4, - rb_float_new( viewport.Left ), rb_float_new( viewport.Top ), - rb_float_new( viewport.Width ), rb_float_new( viewport.Height ) ); -} - -static VALUE View_Move( int argc, VALUE * args, VALUE self ) -{ - float offsetX = 0; - float offsetY = 0; - - switch( argc ) - { - case 1: - { - VALUE temp = Vector2_ForceType( args[0] ); - offsetX = NUM2DBL( Vector2_GetX( temp ) ); - offsetY = NUM2DBL( Vector2_GetY( temp ) ); - } - case 2: - { - offsetX = NUM2DBL( args[0] ); - offsetY = NUM2DBL( args[1] ); - } - default: - rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); - } - - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - object->Move( offsetX, offsetY ); - return Qnil; -} - -static VALUE View_Reset( VALUE self, VALUE aRectangle ) -{ - VALUE temp = Rect_ForceType( aRectangle ); - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - sf::FloatRect rectangle; - rectangle.Left = NUM2DBL( Rect_GetLeft( temp ) ); - rectangle.Top = NUM2DBL( Rect_GetTop( temp ) ); - rectangle.Width = NUM2DBL( Rect_GetWidth( temp ) ); - rectangle.Height = NUM2DBL( Rect_GetHeight( temp ) ); - object->Reset( rectangle ); - return Qnil; -} - -static VALUE View_Rotate( VALUE self, VALUE anAngle ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - object->Rotate( NUM2DBL( anAngle ) ); - return Qnil; -} - -static VALUE View_SetCenter( int argc, VALUE * args, VALUE self ) -{ - float x = 0; - float y = 0; - - switch( argc ) - { - case 1: - { - VALUE temp = Vector2_ForceType( args[0] ); - x = NUM2DBL( Vector2_GetX( temp ) ); - y = NUM2DBL( Vector2_GetY( temp ) ); - } - case 2: - { - x = NUM2DBL( args[0] ); - y = NUM2DBL( args[1] ); - } - default: - rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); - } - - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - object->SetCenter( x, y ); - return Qnil; -} - -static VALUE View_SetRotation( VALUE self, VALUE anAngle ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - object->SetRotation( NUM2DBL( anAngle ) ); - return Qnil; -} - -static VALUE View_SetSize( int argc, VALUE * args, VALUE self ) -{ - float x = 0; - float y = 0; - - switch( argc ) - { - case 1: - { - VALUE temp = Vector2_ForceType( args[0] ); - x = NUM2DBL( Vector2_GetX( temp ) ); - y = NUM2DBL( Vector2_GetY( temp ) ); - } - case 2: - { - x = NUM2DBL( args[0] ); - y = NUM2DBL( args[1] ); - } - default: - rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); - } - - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - object->SetSize( x, y ); - return Qnil; -} - -static VALUE View_SetViewport( VALUE self, VALUE aRectangle ) -{ - VALUE temp = Rect_ForceType( aRectangle ); - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - sf::FloatRect viewport; - viewport.Left = NUM2DBL( Rect_GetLeft( temp ) ); - viewport.Top = NUM2DBL( Rect_GetTop( temp ) ); - viewport.Width = NUM2DBL( Rect_GetWidth( temp ) ); - viewport.Height = NUM2DBL( Rect_GetHeight( temp ) ); - object->SetViewport( viewport ); - return Qnil; -} - -static VALUE View_Zoom( VALUE self, VALUE aFactor ) -{ - sf::View *object = NULL; - Data_Get_Struct( self, sf::View, object ); - object->Zoom( NUM2DBL( aFactor ) ); - return Qnil; -} - +/* call-seq: + * View.new() -> view + * View.new( rectangle ) -> view + * View.new( center, size ) -> view + * + * Construct a view. + */ static VALUE View_Initialize( int argc, VALUE *args, VALUE self ) { VALUE temp = Qnil; @@ -248,6 +86,254 @@ static VALUE View_Initialize( int argc, VALUE *args, VALUE self ) return self; } +/* call-seq: + * view.getCenter() -> vector2 + * + * Get the center of the view. + */ +static VALUE View_GetCenter( VALUE self ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + const sf::Vector2f& center = object->GetCenter(); + return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( center.x ), rb_float_new( center.y ) ); +} + +/* call-seq: + * view.getRotation() -> float + * + * Get the current orientation of the view. + */ +static VALUE View_GetRotation( VALUE self ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + return rb_float_new( object->GetRotation() ); +} + +/* call-seq: + * view.getSize() -> vector2 + * + * Get the size of the view. + */ +static VALUE View_GetSize( VALUE self ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + const sf::Vector2f& size = object->GetSize(); + return rb_funcall( globalVector2Class, rb_intern( "new" ), 2, rb_float_new( size.x ), rb_float_new( size.y ) ); +} + +/* call-seq: + * view.getViewport() -> rectangle + * + * Get the target viewport rectangle of the view. + */ +static VALUE View_GetViewport( VALUE self ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + const sf::FloatRect& viewport = object->GetViewport(); + return rb_funcall( globalRectClass, rb_intern( "new" ), 4, + rb_float_new( viewport.Left ), rb_float_new( viewport.Top ), + rb_float_new( viewport.Width ), rb_float_new( viewport.Height ) ); +} + +/* call-seq: + * view.move( x, y ) + * view.move( offset ) + * + * Move the view relatively to its current position. + */ +static VALUE View_Move( int argc, VALUE * args, VALUE self ) +{ + float offsetX = 0; + float offsetY = 0; + + switch( argc ) + { + case 1: + { + VALUE temp = Vector2_ForceType( args[0] ); + offsetX = NUM2DBL( Vector2_GetX( temp ) ); + offsetY = NUM2DBL( Vector2_GetY( temp ) ); + } + case 2: + { + offsetX = NUM2DBL( args[0] ); + offsetY = NUM2DBL( args[1] ); + } + default: + rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); + } + + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + object->Move( offsetX, offsetY ); + return Qnil; +} + +/* call-seq: + * view.reset( rectangle ) + * + * Reset the view to the given rectangle. + * + * Note that this function resets the rotation angle to 0. + */ +static VALUE View_Reset( VALUE self, VALUE aRectangle ) +{ + VALUE temp = Rect_ForceType( aRectangle ); + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + sf::FloatRect rectangle; + rectangle.Left = NUM2DBL( Rect_GetLeft( temp ) ); + rectangle.Top = NUM2DBL( Rect_GetTop( temp ) ); + rectangle.Width = NUM2DBL( Rect_GetWidth( temp ) ); + rectangle.Height = NUM2DBL( Rect_GetHeight( temp ) ); + object->Reset( rectangle ); + return Qnil; +} + +/* call-seq: + * view.rotate( angle ) + * + * Rotate the view relatively to its current orientation. + */ +static VALUE View_Rotate( VALUE self, VALUE anAngle ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + object->Rotate( NUM2DBL( anAngle ) ); + return Qnil; +} + +/* call-seq: + * view.setCenter( center ) + * view.setCenter( x, y ) + * + * Set the center of the view. + */ +static VALUE View_SetCenter( int argc, VALUE * args, VALUE self ) +{ + float x = 0; + float y = 0; + + switch( argc ) + { + case 1: + { + VALUE temp = Vector2_ForceType( args[0] ); + x = NUM2DBL( Vector2_GetX( temp ) ); + y = NUM2DBL( Vector2_GetY( temp ) ); + } + case 2: + { + x = NUM2DBL( args[0] ); + y = NUM2DBL( args[1] ); + } + default: + rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); + } + + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + object->SetCenter( x, y ); + return Qnil; +} + +/* call-seq: + * view.setRotation( angle ) + * + * Set the orientation of the view. + * + * The default rotation of a view is 0 degree. + */ +static VALUE View_SetRotation( VALUE self, VALUE anAngle ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + object->SetRotation( NUM2DBL( anAngle ) ); + return Qnil; +} + +/* call-seq: + * view.setSize( size ) + * view.setSize( width, height ) + * + * Set the center of the view. + */ +static VALUE View_SetSize( int argc, VALUE * args, VALUE self ) +{ + float x = 0; + float y = 0; + + switch( argc ) + { + case 1: + { + VALUE temp = Vector2_ForceType( args[0] ); + x = NUM2DBL( Vector2_GetX( temp ) ); + y = NUM2DBL( Vector2_GetY( temp ) ); + } + case 2: + { + x = NUM2DBL( args[0] ); + y = NUM2DBL( args[1] ); + } + default: + rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc ); + } + + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + object->SetSize( x, y ); + return Qnil; +} + +/* call-seq: + * view.setViewport( rectangle ) + * + * Set the target viewport. + * + * The viewport is the rectangle into which the contents of the view are displayed, expressed as a factor + * (between 0 and 1) of the size of the RenderTarget to which the view is applied. For example, a view which takes the + * left side of the target would be defined with SFML::View.setViewport( [0.0, 0.0, 0.5, 1.0] ). By default, a view has + * a viewport which covers the entire target. + */ +static VALUE View_SetViewport( VALUE self, VALUE aRectangle ) +{ + VALUE temp = Rect_ForceType( aRectangle ); + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + sf::FloatRect viewport; + viewport.Left = NUM2DBL( Rect_GetLeft( temp ) ); + viewport.Top = NUM2DBL( Rect_GetTop( temp ) ); + viewport.Width = NUM2DBL( Rect_GetWidth( temp ) ); + viewport.Height = NUM2DBL( Rect_GetHeight( temp ) ); + object->SetViewport( viewport ); + return Qnil; +} + +/* call-seq: + * view.zoom( factor ) + * + * Resize the view rectangle relatively to its current size. + * + * Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks. factor is a multiplier: + * + * - 1 keeps the size unchanged + * - > 1 makes the view bigger (objects appear smaller) + * - < 1 makes the view smaller (objects appear bigger) + * + */ +static VALUE View_Zoom( VALUE self, VALUE aFactor ) +{ + sf::View *object = NULL; + Data_Get_Struct( self, sf::View, object ); + object->Zoom( NUM2DBL( aFactor ) ); + return Qnil; +} + static VALUE View_New( int argc, VALUE *args, VALUE aKlass ) { sf::View *object = new sf::View();