next step to D-ify the property functions

this time all Drawables

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1458 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-03-13 22:44:26 +00:00
parent ca7c1d1690
commit 6b444d338e
6 changed files with 578 additions and 677 deletions

View File

@ -39,10 +39,10 @@ import dsfml.graphics.idrawable,
/* /*
* Package base class of all drawable. * Package base class of all drawable.
* Provide implementation of IDrawable and functions aliases. * Provide implementation of IDrawable and functions aliases.
*/ */
package class DrawableImpl(alias symbol) : DSFMLObject, IDrawable package class DrawableImpl(alias derivedClassName) : DSFMLObject, IDrawable
{ {
protected: protected:
this() this()
@ -55,105 +55,12 @@ protected:
super(ptr, true); super(ptr, true);
} }
override void dispose()
{
sfDrawable_Destroy(m_ptr);
}
public: public:
void setX(float x)
{
sfDrawable_SetX(m_ptr, x);
}
void setY(float y)
{
sfDrawable_SetY(m_ptr, y);
}
void setPosition(float x, float y)
{
sfDrawable_SetPosition(m_ptr, x, y);
}
void setPosition(Vector2f vec)
{
sfDrawable_SetPosition(m_ptr, vec.x, vec.y);
}
void setScaleX(float scale)
{
if (scale > 0)
sfDrawable_SetScaleX(m_ptr, scale);
}
void setScaleY(float scale)
{
if (scale > 0)
sfDrawable_SetScaleY(m_ptr, scale);
}
void setScale(float scaleX, float scaleY)
{
if (scaleX > 0 && scaleY > 0)
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
}
void setScale(Vector2f scale)
{
if (scale.x > 0 && scale.y > 0)
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
}
void setOrigin(float originX, float originY)
{
sfDrawable_SetOrigin(m_ptr, originX, originY);
}
void setOrigin(Vector2f origin)
{
sfDrawable_SetOrigin(m_ptr, origin.x, origin.y);
}
void setRotation(float angle)
{
sfDrawable_SetRotation(m_ptr, angle);
}
void setColor(Color c)
{
sfDrawable_SetColor(m_ptr, c);
}
void setBlendMode(BlendMode mode)
{
sfDrawable_SetBlendMode(m_ptr, mode);
}
Vector2f getPosition()
{
return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr));
}
Vector2f getScale()
{
return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr));
}
Vector2f getOrigin()
{
return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr));
}
float getRotation()
{
return sfDrawable_GetRotation(m_ptr);
}
Color getColor()
{
return sfDrawable_GetColor(m_ptr);
}
BlendMode getBlendMode()
{
return cast(BlendMode)(sfDrawable_GetBlendMode(m_ptr));
}
void rotate(float angle) void rotate(float angle)
{ {
@ -170,18 +77,6 @@ public:
sfDrawable_Move(m_ptr, offset.x, offset.y); sfDrawable_Move(m_ptr, offset.x, offset.y);
} }
void scale(float scaleX, float scaleY)
{
if (scaleX > 0 && scaleY > 0)
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
}
void scale(Vector2f scale)
{
if (scale.x > 0 && scale.y > 0)
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
}
Vector2f tranformToLocal(Vector2f point) Vector2f tranformToLocal(Vector2f point)
{ {
Vector2f ret; Vector2f ret;
@ -206,11 +101,113 @@ public:
sfRenderWindow_DrawThisWithShader((cast(DSFMLObject)window).getNativePointer, m_ptr, shader.getNativePointer); sfRenderWindow_DrawThisWithShader((cast(DSFMLObject)window).getNativePointer, m_ptr, shader.getNativePointer);
} }
override void dispose() void setPosition(float x, float y)
{ {
sfDrawable_Destroy(m_ptr); sfDrawable_SetPosition(m_ptr, x, y);
} }
void setScale(float scaleX, float scaleY)
{
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
}
void setOrigin(float originX, float originY)
{
sfDrawable_SetOrigin(m_ptr, originX, originY);
}
@property
{
void x(float x)
{
sfDrawable_SetX(m_ptr, x);
}
void y(float y)
{
sfDrawable_SetY(m_ptr, y);
}
void position(Vector2f vec)
{
sfDrawable_SetPosition(m_ptr, vec.x, vec.y);
}
void scaleX(float scale)
{
if (scale > 0)
sfDrawable_SetScaleX(m_ptr, scale);
}
void scaleY(float scale)
{
if (scale > 0)
sfDrawable_SetScaleY(m_ptr, scale);
}
void scale(Vector2f scale)
{
if (scale.x > 0 && scale.y > 0)
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
}
void origin(Vector2f origin)
{
sfDrawable_SetOrigin(m_ptr, origin.x, origin.y);
}
void rotation(float angle)
{
sfDrawable_SetRotation(m_ptr, angle);
}
void color(Color c)
{
sfDrawable_SetColor(m_ptr, c);
}
void blendMode(BlendMode mode)
{
sfDrawable_SetBlendMode(m_ptr, mode);
}
Vector2f position()
{
return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr));
}
Vector2f scale()
{
return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr));
}
Vector2f origin()
{
return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr));
}
float rotation()
{
return sfDrawable_GetRotation(m_ptr);
}
Color color()
{
return sfDrawable_GetColor(m_ptr);
}
BlendMode blendMode()
{
return cast(BlendMode)(sfDrawable_GetBlendMode(m_ptr));
}
void scale(Vector2f scale)
{
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
}
}
private: private:
extern (C) extern (C)
@ -287,36 +284,36 @@ private:
else else
DllLoader dll = DllLoader.load("csfml-graphics"); DllLoader dll = DllLoader.load("csfml-graphics");
sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create"); sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(derivedClassName ~ "_Create");
sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy"); sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(derivedClassName ~ "_Destroy");
sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX"); sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(derivedClassName ~ "_SetX");
sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY"); sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(derivedClassName ~ "_SetY");
sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition"); sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(derivedClassName ~ "_SetPosition");
sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX"); sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(derivedClassName ~ "_SetScaleX");
sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY"); sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(derivedClassName ~ "_SetScaleY");
sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale"); sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(derivedClassName ~ "_SetScale");
sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation"); sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(derivedClassName ~ "_SetRotation");
sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin"); sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(derivedClassName ~ "_SetOrigin");
sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor"); sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(derivedClassName ~ "_SetColor");
sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode"); sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(derivedClassName ~ "_SetBlendMode");
sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX"); sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(derivedClassName ~ "_GetX");
sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY"); sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(derivedClassName ~ "_GetY");
sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX"); sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(derivedClassName ~ "_GetScaleX");
sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(symbol ~ "_GetScaleX"); sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(derivedClassName ~ "_GetScaleX");
sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation"); sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(derivedClassName ~ "_GetRotation");
sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX"); sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(derivedClassName ~ "_GetOriginX");
sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY"); sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(derivedClassName ~ "_GetOriginY");
sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor"); sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(derivedClassName ~ "_GetColor");
sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode"); sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(derivedClassName ~ "_GetBlendMode");
sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move"); sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(derivedClassName ~ "_Move");
sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale"); sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(derivedClassName ~ "_Scale");
sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate"); sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(derivedClassName ~ "_Rotate");
sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal"); sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(derivedClassName ~ "_TransformToLocal");
sfDrawable_TransformToGlobal= cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal"); sfDrawable_TransformToGlobal= cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(derivedClassName ~ "_TransformToGlobal");
sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$]); sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ derivedClassName[2..$]);
sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$] ~ "WithShader"); sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ derivedClassName[2..$] ~ "WithShader");
sfRenderImage_DrawThis = cast(pf_sfRenderImage_DrawThis)dll.getSymbol("sfRenderImage_Draw" ~ symbol[2..$]); sfRenderImage_DrawThis = cast(pf_sfRenderImage_DrawThis)dll.getSymbol("sfRenderImage_Draw" ~ derivedClassName[2..$]);
sfRenderImage_DrawThisWithShader = cast(pf_sfRenderImage_DrawThisWithShader)dll.getSymbol("sfRenderImage_Draw" ~ symbol[2..$] ~ "WithShader"); sfRenderImage_DrawThisWithShader = cast(pf_sfRenderImage_DrawThisWithShader)dll.getSymbol("sfRenderImage_Draw" ~ derivedClassName[2..$] ~ "WithShader");
} }
} }

View File

@ -43,23 +43,6 @@ import dsfml.graphics.color,
*/ */
interface IDrawable interface IDrawable
{ {
/**
* Set the left position of the object
*
* Params:
* x = New left coordinate
*/
void setX(float x);
/**
* Set the top position of the object
*
* Params:
* y = New top coordinate
*/
void setY(float y);
/** /**
* Set the position of the object * Set the position of the object
* *
@ -69,46 +52,15 @@ interface IDrawable
*/ */
void setPosition(float x, float y); void setPosition(float x, float y);
/**
* Set the position of the object
*
* Params:
* vec = new position
*/
void setPosition(Vector2f vec);
/**
* Set the horizontal scale of the object
*
* Params:
* scale = New horizontal scale (Strictly positive)
*/
void setScaleX(float scale);
/**
* Set the vertical scale of the object
*
* Params:
* scale = New vertical scale (Strictly positive)
*/
void setScaleY(float scale);
/** /**
* Set the scale of the object * Set the scale of the object
* *
* Params: * Params:
* scaleX = New horizontal scale * scaleX = New horizontal scale > 0
* scaleY = New vertical scale * scaleY = New vertical scale > 0
*/ */
void setScale(float scaleX, float scaleY); void setScale(float scalex, float scaley);
// in {assert(scalex > 0 && scalex > 0);} // TODO: add in again when interface contracts work
/**
* Set the scale of the object
*
* Params:
* scale = new scale
*/
void setScale(Vector2f scale);
/** /**
* Set the origin of the object, in coordinates relative to the * Set the origin of the object, in coordinates relative to the
@ -121,6 +73,57 @@ interface IDrawable
*/ */
void setOrigin(float originX, float originY); void setOrigin(float originX, float originY);
@property
{
/**
* Set the left position of the object
*
* Params:
* x = New left coordinate
*/
void x(float x);
/**
* Set the top position of the object
*
* Params:
* y = New top coordinate
*/
void y(float y);
/**
* Set the position of the object
*
* Params:
* vec = new position
*/
void position(Vector2f vec);
/**
* Set the horizontal scale of the object
*
* Params:
* scale = New horizontal scale (Strictly positive)
*/
void scaleX(float scale);
/**
* Set the vertical scale of the object
*
* Params:
* scale = New vertical scale (Strictly positive)
*/
void scaleY(float scale);
/**
* Set the scale of the object
*
* Params:
* scale = new scale
*/
void scale(Vector2f scale);
// in {assert(scale.x > 0 && scale.y > 0);} // TODO
/** /**
* Set the origin of the object, in coordinates relative to the * Set the origin of the object, in coordinates relative to the
* top-left of the object (take a 2D vector). * top-left of the object (take a 2D vector).
@ -129,7 +132,7 @@ interface IDrawable
* Params: * Params:
* origin : New origin * origin : New origin
*/ */
void setOrigin(Vector2f origin); void origin(Vector2f origin);
/** /**
@ -138,7 +141,7 @@ interface IDrawable
* Params: * Params:
* angle = Angle of rotation, in degree * angle = Angle of rotation, in degree
*/ */
void setRotation(float angle); void rotation(float angle);
/** /**
* Set the color * Set the color
@ -146,7 +149,7 @@ interface IDrawable
* Params: * Params:
* c = New color * c = New color
*/ */
void setColor(Color c); void color(Color c);
/** /**
* Set the blending mode for the object. * Set the blending mode for the object.
@ -155,7 +158,7 @@ interface IDrawable
* Params: * Params:
* mode = New blending mode * mode = New blending mode
*/ */
void setBlendMode(BlendMode mode); void blendMode(BlendMode mode);
/** /**
* Get the position of the object * Get the position of the object
@ -164,7 +167,7 @@ interface IDrawable
* Current position * Current position
* *
*/ */
Vector2f getPosition(); Vector2f position();
/** /**
* Get the current scale of the object * Get the current scale of the object
@ -172,7 +175,7 @@ interface IDrawable
* Returns: * Returns:
* Current scale * Current scale
*/ */
Vector2f getScale(); Vector2f scale();
/** /**
* Get the origin of the object * Get the origin of the object
@ -181,7 +184,7 @@ interface IDrawable
* Current position of the origin * Current position of the origin
* *
*/ */
Vector2f getOrigin(); Vector2f origin();
/** /**
* Get the rotation angle of the object * Get the rotation angle of the object
@ -189,7 +192,7 @@ interface IDrawable
* Returns: * Returns:
* Angle of rotation, in degree * Angle of rotation, in degree
*/ */
float getRotation(); float rotation();
/** /**
* Get the color of the string * Get the color of the string
@ -197,7 +200,7 @@ interface IDrawable
* Returns: * Returns:
* Current color * Current color
*/ */
Color getColor(); Color color();
/** /**
* Get the current blending mode * Get the current blending mode
@ -205,7 +208,8 @@ interface IDrawable
* Returns: * Returns:
* Current blending mode * Current blending mode
*/ */
BlendMode getBlendMode(); BlendMode blendMode();
}
/** /**
* Rotate the object * Rotate the object
@ -235,23 +239,6 @@ interface IDrawable
*/ */
void move(Vector2f offset); void move(Vector2f offset);
/**
* Set the scale of the object
*
* Params:
* scaleX = New horizontal scale (Strictly positive)
* scaleY = New vertical scale (Strictly positive)
*/
void scale(float scaleX, float scaleY);
/**
* Scale the object (take a 2D vector)
*
* Params:
* factor = Scaling factors (both values must be strictly positive)
*/
void scale(Vector2f factor);
/** /**
* Transform a point from global coordinates into local coordinates * Transform a point from global coordinates into local coordinates
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point) * (ie it applies the inverse of object's origin, translation, rotation and scale to the point)

View File

@ -1,28 +1,28 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.shape; module dsfml.graphics.shape;
@ -33,10 +33,10 @@ import dsfml.graphics.color;
import dsfml.graphics.drawableimpl; import dsfml.graphics.drawableimpl;
/** /**
* Shape defines a drawable convex shape ; it also defines * Shape defines a drawable convex shape ; it also defines
* helper functions to draw simple shapes like * helper functions to draw simple shapes like
* lines, rectangles, circles, etc. * lines, rectangles, circles, etc.
*/ */
class Shape : DrawableImpl!("sfShape") class Shape : DrawableImpl!("sfShape")
{ {
private: private:
@ -78,6 +78,8 @@ public:
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol); sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
} }
@property
{
/** /**
* Enable or disable filling the shape. * Enable or disable filling the shape.
* Fill is enabled by default. * Fill is enabled by default.
@ -108,7 +110,7 @@ public:
* Params: * Params:
* width = New width * width = New width
*/ */
void setOutlineWidth(float width) void outlineWidth(float width)
{ {
sfShape_SetOutlineWidth(m_ptr, width); sfShape_SetOutlineWidth(m_ptr, width);
} }
@ -120,7 +122,7 @@ public:
* Current outline width * Current outline width
* *
*/ */
float getOutlineWidth() float outlineWidth()
{ {
return sfShape_GetOutlineWidth(m_ptr); return sfShape_GetOutlineWidth(m_ptr);
} }
@ -131,10 +133,11 @@ public:
* Returns: * Returns:
* Total number of points * Total number of points
*/ */
uint getPointsCount() uint pointsCount()
{ {
return sfShape_GetPointsCount(m_ptr); return sfShape_GetPointsCount(m_ptr);
} }
}
/** /**
* Get a point of the shape * Get a point of the shape
@ -279,62 +282,27 @@ public:
private: private:
extern (C) static extern(C)
{ {
typedef void* function(float, float, float, float, float, Color, float, Color) pf_sfShape_CreateLine; void* function(float, float, float, float, float, Color, float, Color) sfShape_CreateLine;
typedef void* function(float, float, float, float, Color, float, Color) pf_sfShape_CreateRectangle; void* function(float, float, float, float, Color, float, Color) sfShape_CreateRectangle;
typedef void* function(float, float, float, Color, float, Color) pf_sfShape_CreateCircle; void* function(float, float, float, Color, float, Color) sfShape_CreateCircle;
typedef void function(void* Shape, float, float, Color, Color) pf_sfShape_AddPoint; void function(void*, float, float, Color, Color) sfShape_AddPoint;
typedef void function(void* Shape, int) pf_sfShape_EnableFill; void function(void*, int) sfShape_EnableFill;
typedef void function(void* Shape, int) pf_sfShape_EnableOutline; void function(void*, int) sfShape_EnableOutline;
typedef void function (void* Shape, float Width) pf_sfShape_SetOutlineWidth; void function(void*, float Width) sfShape_SetOutlineWidth;
typedef float function (void* Shape) pf_sfShape_GetOutlineWidth; float function(void*) sfShape_GetOutlineWidth;
typedef uint function (void* Shape) pf_sfShape_GetPointsCount; uint function(void*) sfShape_GetPointsCount;
typedef void function (void* Shape, uint Index, float* X, float* Y) pf_sfShape_GetPointPosition; void function(void*, uint Index, float* X, float* Y) sfShape_GetPointPosition;
typedef void function (void* Shape, uint Index, float X, float Y) pf_sfShape_SetPointPosition; void function(void*, uint Index, float X, float Y) sfShape_SetPointPosition;
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointColor; Color function(void*, uint index) sfShape_GetPointColor;
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointColor; void function(void*, uint index, Color color) sfShape_SetPointColor;
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointOutlineColor; Color function(void*, uint index) sfShape_GetPointOutlineColor;
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointOutlineColor; void function(void*, uint index, Color color) sfShape_SetPointOutlineColor;
static pf_sfShape_CreateLine sfShape_CreateLine;
static pf_sfShape_CreateRectangle sfShape_CreateRectangle;
static pf_sfShape_CreateCircle sfShape_CreateCircle;
static pf_sfShape_AddPoint sfShape_AddPoint;
static pf_sfShape_EnableFill sfShape_EnableFill;
static pf_sfShape_EnableOutline sfShape_EnableOutline;
static pf_sfShape_SetOutlineWidth sfShape_SetOutlineWidth;
static pf_sfShape_GetOutlineWidth sfShape_GetOutlineWidth;
static pf_sfShape_GetPointsCount sfShape_GetPointsCount;
static pf_sfShape_GetPointPosition sfShape_GetPointPosition;
static pf_sfShape_SetPointPosition sfShape_SetPointPosition;
static pf_sfShape_GetPointColor sfShape_GetPointColor;
static pf_sfShape_SetPointColor sfShape_SetPointColor;
static pf_sfShape_GetPointOutlineColor sfShape_GetPointOutlineColor;
static pf_sfShape_SetPointOutlineColor sfShape_SetPointOutlineColor;
} }
static this() mixin(loadFromSharedLib2("csfml-graphics", "sfShape",
{ "CreateLine", "CreateRectangle", "CreateCircle", "AddPoint", "EnableFill", "EnableOutline", "SetOutlineWidth", "GetOutlineWidth",
debug "GetPointsCount", "GetPointPosition", "SetPointPosition", "GetPointColor", "SetPointColor", "GetPointOutlineColor",
DllLoader dll = DllLoader.load("csfml-graphics-d"); "SetPointOutlineColor"));
else
DllLoader dll = DllLoader.load("csfml-graphics");
sfShape_CreateLine = cast(pf_sfShape_CreateLine)dll.getSymbol("sfShape_CreateLine");
sfShape_CreateRectangle = cast(pf_sfShape_CreateRectangle)dll.getSymbol("sfShape_CreateRectangle");
sfShape_CreateCircle = cast(pf_sfShape_CreateCircle)dll.getSymbol("sfShape_CreateCircle");
sfShape_AddPoint = cast(pf_sfShape_AddPoint)dll.getSymbol("sfShape_AddPoint");
sfShape_EnableFill = cast(pf_sfShape_EnableFill)dll.getSymbol("sfShape_EnableFill");
sfShape_EnableOutline = cast(pf_sfShape_EnableOutline)dll.getSymbol("sfShape_EnableOutline");
sfShape_SetOutlineWidth = cast(pf_sfShape_SetOutlineWidth)dll.getSymbol("sfShape_SetOutlineWidth");
sfShape_GetOutlineWidth = cast(pf_sfShape_GetOutlineWidth)dll.getSymbol("sfShape_GetOutlineWidth");
sfShape_GetPointsCount = cast(pf_sfShape_GetPointsCount)dll.getSymbol("sfShape_GetPointsCount");
sfShape_GetPointPosition = cast(pf_sfShape_GetPointPosition)dll.getSymbol("sfShape_GetPointPosition");
sfShape_SetPointPosition = cast(pf_sfShape_SetPointPosition)dll.getSymbol("sfShape_SetPointPosition");
sfShape_GetPointColor = cast (pf_sfShape_GetPointColor)dll.getSymbol("sfShape_GetPointColor");
sfShape_SetPointColor = cast (pf_sfShape_SetPointColor)dll.getSymbol("sfShape_SetPointColor");
sfShape_GetPointOutlineColor = cast(pf_sfShape_GetPointOutlineColor)dll.getSymbol("sfShape_GetPointOutlineColor");
sfShape_SetPointOutlineColor = cast(pf_sfShape_SetPointOutlineColor)dll.getSymbol("sfShape_SetPointOutlineColor");
}
} }

View File

@ -63,22 +63,22 @@ public:
* img = Image of the sprite * img = Image of the sprite
* left = Left coordinate of the sprite (0 by default) * left = Left coordinate of the sprite (0 by default)
* top = Top coordinate of the sprite (0 by default) * top = Top coordinate of the sprite (0 by default)
* scaleX = Horizontal scale (1 by default) * scalex = Horizontal scale (1 by default)
* scaleY= Vertical scale (1 by default) * scaley = Vertical scale (1 by default)
* rotation = Orientation, in degrees (0 by default) * rot = Orientation, in degrees (0 by default)
* col = Color of the sprite (white by default) * col = Color of the sprite (white by default)
*/ */
this(Image img, float left = 0.f, float top = 0.f, float scaleX = 1.f, float scaleY = 1.f, float rotation = 0.f, Color col = Color.WHITE) this(Image img, float left = 0.f, float top = 0.f, float scalex = 1.f, float scaley = 1.f, float rot = 0.f, Color col = Color.WHITE)
{ {
super(); super();
m_image = img; m_image = img;
sfSprite_SetImage(m_ptr, img.getNativePointer, true); sfSprite_SetImage(m_ptr, img.getNativePointer, true);
setX(left); x = left;
setY(top); y = top;
setScaleX(scaleX); scaleX = scalex;
setScaleY(scaleY); scaleY = scaley;
setRotation(rotation); rotation = rot;
setColor(col); color = col;
} }
/** /**
@ -95,18 +95,6 @@ public:
m_image = img; m_image = img;
} }
/**
* Set the sub-rectangle of a sprite inside the source image.
*
* Params:
* rect = New sub-rectangle
*/
void setSubRect(IntRect rect)
{
sfSprite_SetSubRect(m_ptr, rect);
m_subRect = rect;
}
/** /**
* Resize the sprite (by changing its scale factors). * Resize the sprite (by changing its scale factors).
* The default size is defined by the subrect * The default size is defined by the subrect
@ -157,43 +145,6 @@ public:
sfSprite_FlipY(m_ptr, flipped); sfSprite_FlipY(m_ptr, flipped);
} }
/**
* Get the source image of the sprite
*
* Returns:
* Pointer to the image (can be NULL)
*/
Image getImage()
{
return m_image;
}
/**
* Get the sub-rectangle of the sprite inside the source image
*
* Returns:
* Sub-rectangle
*/
IntRect getSubRect()
{
if (m_subRect == IntRect())
m_subRect = sfSprite_GetSubRect(m_ptr);
//m_subRect = IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
return m_subRect;
}
/**
* Get the sprite size
*
* Returns:
* Size of the sprite
*/
Vector2f getSize()
{
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
}
/** /**
* Get the color of a given pixel in the sprite * Get the color of a given pixel in the sprite
* *
@ -209,49 +160,74 @@ public:
return sfSprite_GetPixel(m_ptr, x, y); return sfSprite_GetPixel(m_ptr, x, y);
} }
private: @property
{
extern (C) /**
* Set the sub-rectangle of a sprite inside the source image.
*
* Params:
* rect = New sub-rectangle
*/
void subRect(IntRect rect)
{ {
typedef void function(void*, void*, bool) pf_sfSprite_SetImage; sfSprite_SetSubRect(m_ptr, rect);
typedef void function(void*, IntRect) pf_sfSprite_SetSubRect; m_subRect = rect;
typedef void function(void*, float, float) pf_sfSprite_Resize;
typedef void function(void*, int) pf_sfSprite_FlipX;
typedef void function(void*, int) pf_sfSprite_FlipY;
typedef void* function(void*) pf_sfSprite_GetImage;
typedef IntRect function(void*) pf_sfSprite_GetSubRect;
typedef float function(void*) pf_sfSprite_GetWidth;
typedef float function(void*) pf_sfSprite_GetHeight;
typedef Color function(void*, uint, uint) pf_sfSprite_GetPixel;
static pf_sfSprite_SetImage sfSprite_SetImage;
static pf_sfSprite_SetSubRect sfSprite_SetSubRect;
static pf_sfSprite_Resize sfSprite_Resize;
static pf_sfSprite_FlipX sfSprite_FlipX;
static pf_sfSprite_FlipY sfSprite_FlipY;
static pf_sfSprite_GetImage sfSprite_GetImage;
static pf_sfSprite_GetSubRect sfSprite_GetSubRect;
static pf_sfSprite_GetWidth sfSprite_GetWidth;
static pf_sfSprite_GetHeight sfSprite_GetHeight;
static pf_sfSprite_GetPixel sfSprite_GetPixel;
} }
static this() /**
* Get the source image of the sprite
*
* Returns:
* Pointer to the image (can be NULL)
*/
Image image()
{ {
debug return m_image;
DllLoader dll = DllLoader.load("csfml-graphics-d"); }
else
DllLoader dll = DllLoader.load("csfml-graphics");
sfSprite_SetImage = cast(pf_sfSprite_SetImage)dll.getSymbol("sfSprite_SetImage"); /**
sfSprite_SetSubRect = cast(pf_sfSprite_SetSubRect)dll.getSymbol("sfSprite_SetSubRect"); * Get the sub-rectangle of the sprite inside the source image
sfSprite_Resize = cast(pf_sfSprite_Resize)dll.getSymbol("sfSprite_Resize"); *
sfSprite_FlipX = cast(pf_sfSprite_FlipX)dll.getSymbol("sfSprite_FlipX"); * Returns:
sfSprite_FlipY = cast(pf_sfSprite_FlipY)dll.getSymbol("sfSprite_FlipY"); * Sub-rectangle
sfSprite_GetImage = cast(pf_sfSprite_GetImage)dll.getSymbol("sfSprite_GetImage"); */
sfSprite_GetSubRect = cast(pf_sfSprite_GetSubRect)dll.getSymbol("sfSprite_GetSubRect"); IntRect subRect()
sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth"); {
sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight"); if (m_subRect == IntRect())
sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("sfSprite_GetPixel"); m_subRect = sfSprite_GetSubRect(m_ptr);
//m_subRect = IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
return m_subRect;
}
/**
* Get the sprite size
*
* Returns:
* Size of the sprite
*/
Vector2f size()
{
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
} }
} }
private:
static extern(C)
{
void function(void*, void*, bool) sfSprite_SetImage;
void function(void*, IntRect) sfSprite_SetSubRect;
void function(void*, float, float) sfSprite_Resize;
void function(void*, int) sfSprite_FlipX;
void function(void*, int) sfSprite_FlipY;
void* function(void*) sfSprite_GetImage;
IntRect function(void*) sfSprite_GetSubRect;
float function(void*) sfSprite_GetWidth;
float function(void*) sfSprite_GetHeight;
Color function(void*, uint, uint) sfSprite_GetPixel;
}
mixin(loadFromSharedLib2("csfml-graphics", "sfSprite",
"SetImage", "SetSubRect", "Resize", "FlipX", "FlipY", "GetImage", "GetSubRect", "GetWidth", "GetHeight", "GetPixel"));
}

View File

@ -76,17 +76,17 @@ public:
* Prefixs string litterals with c * Prefixs string litterals with c
* *
* Params: * Params:
* text = Text assigned to the string * s = Text assigned to the string
* font = Font used to draw the string (use default font) * f = Font used to draw the string (use default font)
* size = Characters size, in pixels (32 by default) * size = Characters size, in pixels (32 by default)
*/ */
this(string text, Font font = Font.getDefaultFont(), uint size = 30) this(string s, Font f = Font.getDefaultFont(), uint size = 30)
{ {
super(); super();
m_font = font;
setFont(font); font = f;
setString(text); text = s;
setCharacterSize(size); characterSize = size;
} }
/** /**
@ -95,26 +95,28 @@ public:
* Prefixs string litterals with d * Prefixs string litterals with d
* *
* Params: * Params:
* text = Text assigned to the string * s = Text assigned to the string
* font = Font used to draw the string (use default font) * f = Font used to draw the string (use default font)
* size = Characters size, in pixels (32 by default) * size = Characters size, in pixels (32 by default)
*/ */
this(dstring text, Font font = Font.getDefaultFont(), uint size = 30) this(dstring s, Font f = Font.getDefaultFont(), uint size = 30)
{ {
super(); super();
m_font = font;
setFont(font); font = f;
setString(text); text = s;
setCharacterSize(size); characterSize = size;
} }
@property
{
/** /**
* Set the text (from a multibyte string) * Set the text (from a multibyte string)
* *
* Params: * Params:
* text = New text * text = New text
*/ */
void setString(string text) void text(string text)
{ {
sfText_SetString(m_ptr, toStringz(text)); sfText_SetString(m_ptr, toStringz(text));
} }
@ -125,21 +127,32 @@ public:
* Params: * Params:
* text = New text * text = New text
*/ */
void setString(dstring text) void text(dstring text)
{ {
sfText_SetUnicodeString(m_ptr, toStringz(text)); sfText_SetUnicodeString(m_ptr, toStringz(text));
} }
/**
* Get the text (returns a multibyte string)
*
* Returns:
* Text
*/
string text()
{
return fromStringz(sfText_GetString(m_ptr));
}
/** /**
* Set the font of the string * Set the font of the string
* *
* Params: * Params:
* font = Font filename * f = Font
*/ */
void setFont(Font font) void font(Font f)
{ {
m_font = font; m_font = f;
sfText_SetFont(m_ptr, font.getNativePointer); sfText_SetFont(m_ptr, f.getNativePointer);
} }
/** /**
@ -148,7 +161,7 @@ public:
* Params: * Params:
* size = New size, in pixels * size = New size, in pixels
*/ */
void setCharacterSize(uint size) void characterSize(uint size)
{ {
sfText_SetCharacterSize(m_ptr, size); sfText_SetCharacterSize(m_ptr, size);
} }
@ -161,9 +174,9 @@ public:
* TextStyle = New text style, (combination of Style enum values) * TextStyle = New text style, (combination of Style enum values)
* *
*/ */
void setStyle(TextStyle style) void style(TextStyle tstyle)
{ {
sfText_SetStyle(m_ptr, style); sfText_SetStyle(m_ptr, tstyle);
} }
/** /**
@ -172,29 +185,18 @@ public:
* Returns: * Returns:
* Text * Text
*/ */
dstring getUnicodeText() dstring unicodeText()
{ {
return fromStringz(sfText_GetUnicodeString(m_ptr)); return fromStringz(sfText_GetUnicodeString(m_ptr));
} }
/**
* Get the text (returns a multibyte string)
*
* Returns:
* Text
*/
string getText()
{
return fromStringz(sfText_GetString(m_ptr));
}
/** /**
* Get the font used by the string * Get the font used by the string
* *
* Returns: * Returns:
* Font name * Font name
*/ */
Font getFont() Font font()
{ {
return m_font; return m_font;
} }
@ -205,7 +207,7 @@ public:
* Returns: * Returns:
* Size of the characters * Size of the characters
*/ */
uint getCharacterSize() uint characterSize()
{ {
return sfText_GetCharacterSize(m_ptr); return sfText_GetCharacterSize(m_ptr);
} }
@ -216,11 +218,23 @@ public:
* Returns: * Returns:
* Font style * Font style
*/ */
TextStyle getStyle() TextStyle style()
{ {
return sfText_GetStyle(m_ptr); return sfText_GetStyle(m_ptr);
} }
/**
* Get the string rectangle on screen
*
* Returns:
* Rectangle contaning the string in screen coordinates
*/
FloatRect rect()
{
return sfText_GetRect(m_ptr);
}
}
/** /**
* Return the visual position of the Index-th character of the string, * Return the visual position of the Index-th character of the string,
* in coordinates relative to the string * in coordinates relative to the string
@ -239,66 +253,25 @@ public:
return ret; return ret;
} }
/**
* Get the string rectangle on screen
*
* Returns:
* Rectangle contaning the string in screen coordinates
*/
FloatRect getRect()
{
return sfText_GetRect(m_ptr);
}
private: private:
extern (C) static extern(C)
{ {
typedef void function(void*, cchar*) pf_sfText_SetString; void function(void*, cchar*) sfText_SetString;
typedef void function(void*, cdchar*) pf_sfText_SetUnicodeString; void function(void*, cdchar*) sfText_SetUnicodeString;
typedef void function(void*, void*) pf_sfText_SetFont; void function(void*, void*) sfText_SetFont;
typedef void function(void*, uint) pf_sfText_SetCharacterSize; void function(void*, uint) sfText_SetCharacterSize;
typedef void function(void*, TextStyle) pf_sfText_SetStyle; void function(void*, TextStyle) sfText_SetStyle;
typedef idchar* function(void*) pf_sfText_GetUnicodeString; idchar* function(void*) sfText_GetUnicodeString;
typedef ichar* function(void*) pf_sfText_GetString; ichar* function(void*) sfText_GetString;
typedef void* function(void*) pf_sfText_GetFont; void* function(void*) sfText_GetFont;
typedef uint function(void*) pf_sfText_GetCharacterSize; uint function(void*) sfText_GetCharacterSize;
typedef TextStyle function (void*) pf_sfText_GetStyle; TextStyle function (void*) sfText_GetStyle;
typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos; void function(void*, size_t, float*, float*) sfText_GetCharacterPos;
typedef FloatRect function(void*) pf_sfText_GetRect; FloatRect function(void*) sfText_GetRect;
static pf_sfText_SetString sfText_SetString;
static pf_sfText_SetUnicodeString sfText_SetUnicodeString;
static pf_sfText_SetFont sfText_SetFont;
static pf_sfText_SetCharacterSize sfText_SetCharacterSize;
static pf_sfText_SetStyle sfText_SetStyle;
static pf_sfText_GetUnicodeString sfText_GetUnicodeString;
static pf_sfText_GetString sfText_GetString;
static pf_sfText_GetFont sfText_GetFont;
static pf_sfText_GetCharacterSize sfText_GetCharacterSize;
static pf_sfText_GetStyle sfText_GetStyle;
static pf_sfText_GetCharacterPos sfText_GetCharacterPos;
static pf_sfText_GetRect sfText_GetRect;
} }
static this() mixin(loadFromSharedLib2("csfml-graphics", "sfText",
{ "SetString", "SetUnicodeString", "SetFont", "SetCharacterSize", "SetStyle", "GetUnicodeString", "GetString", "GetFont",
debug "GetCharacterSize", "GetStyle", "GetCharacterPos", "GetRect"));
DllLoader dll = DllLoader.load("csfml-graphics-d");
else
DllLoader dll = DllLoader.load("csfml-graphics");
sfText_SetString = cast(pf_sfText_SetString)dll.getSymbol("sfText_SetString");
sfText_SetUnicodeString = cast(pf_sfText_SetUnicodeString)dll.getSymbol("sfText_SetUnicodeString");
sfText_SetFont = cast(pf_sfText_SetFont)dll.getSymbol("sfText_SetFont");
sfText_SetCharacterSize = cast(pf_sfText_SetCharacterSize)dll.getSymbol("sfText_SetCharacterSize");
sfText_SetStyle = cast(pf_sfText_SetStyle)dll.getSymbol("sfText_SetStyle");
sfText_GetUnicodeString = cast(pf_sfText_GetUnicodeString)dll.getSymbol("sfText_GetUnicodeString");
sfText_GetString = cast(pf_sfText_GetString)dll.getSymbol("sfText_GetString");
sfText_GetFont = cast(pf_sfText_GetFont)dll.getSymbol("sfText_GetFont");
sfText_GetCharacterSize = cast(pf_sfText_GetCharacterSize)dll.getSymbol("sfText_GetCharacterSize");
sfText_GetStyle = cast(pf_sfText_GetStyle)dll.getSymbol("sfText_GetStyle");
sfText_GetCharacterPos = cast(pf_sfText_GetCharacterPos)dll.getSymbol("sfText_GetCharacterPos");
sfText_GetRect = cast(pf_sfText_GetRect)dll.getSymbol("sfText_GetRect");
}
} }

View File

@ -358,10 +358,10 @@ public:
} }
/** /**
* Get time elapsed since last frame * Get the time the last frame took
* *
* Returns: * Returns:
* Time elapsed, in seconds * time in seconds
*/ */
float getFrameTime() float getFrameTime()
{ {