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

@ -42,7 +42,7 @@ import dsfml.graphics.idrawable,
* Package base class of all drawable.
* Provide implementation of IDrawable and functions aliases.
*/
package class DrawableImpl(alias symbol) : DSFMLObject, IDrawable
package class DrawableImpl(alias derivedClassName) : DSFMLObject, IDrawable
{
protected:
this()
@ -55,105 +55,12 @@ protected:
super(ptr, true);
}
override void dispose()
{
sfDrawable_Destroy(m_ptr);
}
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)
{
@ -170,18 +77,6 @@ public:
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 ret;
@ -206,9 +101,111 @@ public:
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:
@ -287,36 +284,36 @@ private:
else
DllLoader dll = DllLoader.load("csfml-graphics");
sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create");
sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy");
sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX");
sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY");
sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition");
sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX");
sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY");
sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale");
sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation");
sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin");
sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor");
sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode");
sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX");
sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY");
sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX");
sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(symbol ~ "_GetScaleX");
sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation");
sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX");
sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY");
sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor");
sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode");
sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move");
sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale");
sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate");
sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal");
sfDrawable_TransformToGlobal= cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal");
sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(derivedClassName ~ "_Create");
sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(derivedClassName ~ "_Destroy");
sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(derivedClassName ~ "_SetX");
sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(derivedClassName ~ "_SetY");
sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(derivedClassName ~ "_SetPosition");
sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(derivedClassName ~ "_SetScaleX");
sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(derivedClassName ~ "_SetScaleY");
sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(derivedClassName ~ "_SetScale");
sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(derivedClassName ~ "_SetRotation");
sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(derivedClassName ~ "_SetOrigin");
sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(derivedClassName ~ "_SetColor");
sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(derivedClassName ~ "_SetBlendMode");
sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(derivedClassName ~ "_GetX");
sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(derivedClassName ~ "_GetY");
sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(derivedClassName ~ "_GetScaleX");
sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(derivedClassName ~ "_GetScaleX");
sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(derivedClassName ~ "_GetRotation");
sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(derivedClassName ~ "_GetOriginX");
sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(derivedClassName ~ "_GetOriginY");
sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(derivedClassName ~ "_GetColor");
sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(derivedClassName ~ "_GetBlendMode");
sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(derivedClassName ~ "_Move");
sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(derivedClassName ~ "_Scale");
sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(derivedClassName ~ "_Rotate");
sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(derivedClassName ~ "_TransformToLocal");
sfDrawable_TransformToGlobal= cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(derivedClassName ~ "_TransformToGlobal");
sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$]);
sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$] ~ "WithShader");
sfRenderImage_DrawThis = cast(pf_sfRenderImage_DrawThis)dll.getSymbol("sfRenderImage_Draw" ~ symbol[2..$]);
sfRenderImage_DrawThisWithShader = cast(pf_sfRenderImage_DrawThisWithShader)dll.getSymbol("sfRenderImage_Draw" ~ symbol[2..$] ~ "WithShader");
sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ derivedClassName[2..$]);
sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ derivedClassName[2..$] ~ "WithShader");
sfRenderImage_DrawThis = cast(pf_sfRenderImage_DrawThis)dll.getSymbol("sfRenderImage_Draw" ~ derivedClassName[2..$]);
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
{
/**
* 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
*
@ -69,46 +52,15 @@ interface IDrawable
*/
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
*
* Params:
* scaleX = New horizontal scale
* scaleY = New vertical scale
* scaleX = New horizontal scale > 0
* scaleY = New vertical scale > 0
*/
void setScale(float scaleX, float scaleY);
/**
* Set the scale of the object
*
* Params:
* scale = new scale
*/
void setScale(Vector2f scale);
void setScale(float scalex, float scaley);
// in {assert(scalex > 0 && scalex > 0);} // TODO: add in again when interface contracts work
/**
* Set the origin of the object, in coordinates relative to the
@ -121,6 +73,57 @@ interface IDrawable
*/
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
* top-left of the object (take a 2D vector).
@ -129,7 +132,7 @@ interface IDrawable
* Params:
* origin : New origin
*/
void setOrigin(Vector2f origin);
void origin(Vector2f origin);
/**
@ -138,7 +141,7 @@ interface IDrawable
* Params:
* angle = Angle of rotation, in degree
*/
void setRotation(float angle);
void rotation(float angle);
/**
* Set the color
@ -146,7 +149,7 @@ interface IDrawable
* Params:
* c = New color
*/
void setColor(Color c);
void color(Color c);
/**
* Set the blending mode for the object.
@ -155,7 +158,7 @@ interface IDrawable
* Params:
* mode = New blending mode
*/
void setBlendMode(BlendMode mode);
void blendMode(BlendMode mode);
/**
* Get the position of the object
@ -164,7 +167,7 @@ interface IDrawable
* Current position
*
*/
Vector2f getPosition();
Vector2f position();
/**
* Get the current scale of the object
@ -172,7 +175,7 @@ interface IDrawable
* Returns:
* Current scale
*/
Vector2f getScale();
Vector2f scale();
/**
* Get the origin of the object
@ -181,7 +184,7 @@ interface IDrawable
* Current position of the origin
*
*/
Vector2f getOrigin();
Vector2f origin();
/**
* Get the rotation angle of the object
@ -189,7 +192,7 @@ interface IDrawable
* Returns:
* Angle of rotation, in degree
*/
float getRotation();
float rotation();
/**
* Get the color of the string
@ -197,7 +200,7 @@ interface IDrawable
* Returns:
* Current color
*/
Color getColor();
Color color();
/**
* Get the current blending mode
@ -205,7 +208,8 @@ interface IDrawable
* Returns:
* Current blending mode
*/
BlendMode getBlendMode();
BlendMode blendMode();
}
/**
* Rotate the object
@ -235,23 +239,6 @@ interface IDrawable
*/
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
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)

View File

@ -78,6 +78,8 @@ public:
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
}
@property
{
/**
* Enable or disable filling the shape.
* Fill is enabled by default.
@ -108,7 +110,7 @@ public:
* Params:
* width = New width
*/
void setOutlineWidth(float width)
void outlineWidth(float width)
{
sfShape_SetOutlineWidth(m_ptr, width);
}
@ -120,7 +122,7 @@ public:
* Current outline width
*
*/
float getOutlineWidth()
float outlineWidth()
{
return sfShape_GetOutlineWidth(m_ptr);
}
@ -131,10 +133,11 @@ public:
* Returns:
* Total number of points
*/
uint getPointsCount()
uint pointsCount()
{
return sfShape_GetPointsCount(m_ptr);
}
}
/**
* Get a point of the shape
@ -279,62 +282,27 @@ public:
private:
extern (C)
static extern(C)
{
typedef void* function(float, float, float, float, float, Color, float, Color) pf_sfShape_CreateLine;
typedef void* function(float, float, float, float, Color, float, Color) pf_sfShape_CreateRectangle;
typedef void* function(float, float, float, Color, float, Color) pf_sfShape_CreateCircle;
typedef void function(void* Shape, float, float, Color, Color) pf_sfShape_AddPoint;
typedef void function(void* Shape, int) pf_sfShape_EnableFill;
typedef void function(void* Shape, int) pf_sfShape_EnableOutline;
typedef void function (void* Shape, float Width) pf_sfShape_SetOutlineWidth;
typedef float function (void* Shape) pf_sfShape_GetOutlineWidth;
typedef uint function (void* Shape) pf_sfShape_GetPointsCount;
typedef void function (void* Shape, uint Index, float* X, float* Y) pf_sfShape_GetPointPosition;
typedef void function (void* Shape, uint Index, float X, float Y) pf_sfShape_SetPointPosition;
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointColor;
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointColor;
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointOutlineColor;
typedef void function (void* Shape, uint index, Color color) pf_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;
void* function(float, float, float, float, float, Color, float, Color) sfShape_CreateLine;
void* function(float, float, float, float, Color, float, Color) sfShape_CreateRectangle;
void* function(float, float, float, Color, float, Color) sfShape_CreateCircle;
void function(void*, float, float, Color, Color) sfShape_AddPoint;
void function(void*, int) sfShape_EnableFill;
void function(void*, int) sfShape_EnableOutline;
void function(void*, float Width) sfShape_SetOutlineWidth;
float function(void*) sfShape_GetOutlineWidth;
uint function(void*) sfShape_GetPointsCount;
void function(void*, uint Index, float* X, float* Y) sfShape_GetPointPosition;
void function(void*, uint Index, float X, float Y) sfShape_SetPointPosition;
Color function(void*, uint index) sfShape_GetPointColor;
void function(void*, uint index, Color color) sfShape_SetPointColor;
Color function(void*, uint index) sfShape_GetPointOutlineColor;
void function(void*, uint index, Color color) sfShape_SetPointOutlineColor;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-graphics-d");
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");
}
mixin(loadFromSharedLib2("csfml-graphics", "sfShape",
"CreateLine", "CreateRectangle", "CreateCircle", "AddPoint", "EnableFill", "EnableOutline", "SetOutlineWidth", "GetOutlineWidth",
"GetPointsCount", "GetPointPosition", "SetPointPosition", "GetPointColor", "SetPointColor", "GetPointOutlineColor",
"SetPointOutlineColor"));
}

View File

@ -63,22 +63,22 @@ public:
* img = Image of the sprite
* left = Left coordinate of the sprite (0 by default)
* top = Top coordinate of the sprite (0 by default)
* scaleX = Horizontal scale (1 by default)
* scaleY= Vertical scale (1 by default)
* rotation = Orientation, in degrees (0 by default)
* scalex = Horizontal scale (1 by default)
* scaley = Vertical scale (1 by default)
* rot = Orientation, in degrees (0 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();
m_image = img;
sfSprite_SetImage(m_ptr, img.getNativePointer, true);
setX(left);
setY(top);
setScaleX(scaleX);
setScaleY(scaleY);
setRotation(rotation);
setColor(col);
x = left;
y = top;
scaleX = scalex;
scaleY = scaley;
rotation = rot;
color = col;
}
/**
@ -95,18 +95,6 @@ public:
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).
* The default size is defined by the subrect
@ -157,43 +145,6 @@ public:
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
*
@ -209,49 +160,74 @@ public:
return sfSprite_GetPixel(m_ptr, x, y);
}
@property
{
/**
* Set the sub-rectangle of a sprite inside the source image.
*
* Params:
* rect = New sub-rectangle
*/
void subRect(IntRect rect)
{
sfSprite_SetSubRect(m_ptr, rect);
m_subRect = rect;
}
/**
* Get the source image of the sprite
*
* Returns:
* Pointer to the image (can be NULL)
*/
Image image()
{
return m_image;
}
/**
* Get the sub-rectangle of the sprite inside the source image
*
* Returns:
* Sub-rectangle
*/
IntRect subRect()
{
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 size()
{
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
}
}
private:
extern (C)
static extern(C)
{
typedef void function(void*, void*, bool) pf_sfSprite_SetImage;
typedef void function(void*, IntRect) pf_sfSprite_SetSubRect;
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;
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;
}
static this()
{
debug
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");
sfSprite_Resize = cast(pf_sfSprite_Resize)dll.getSymbol("sfSprite_Resize");
sfSprite_FlipX = cast(pf_sfSprite_FlipX)dll.getSymbol("sfSprite_FlipX");
sfSprite_FlipY = cast(pf_sfSprite_FlipY)dll.getSymbol("sfSprite_FlipY");
sfSprite_GetImage = cast(pf_sfSprite_GetImage)dll.getSymbol("sfSprite_GetImage");
sfSprite_GetSubRect = cast(pf_sfSprite_GetSubRect)dll.getSymbol("sfSprite_GetSubRect");
sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth");
sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight");
sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("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
*
* Params:
* text = Text assigned to the string
* font = Font used to draw the string (use default font)
* s = Text assigned to the string
* f = Font used to draw the string (use default font)
* 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();
m_font = font;
setFont(font);
setString(text);
setCharacterSize(size);
font = f;
text = s;
characterSize = size;
}
/**
@ -95,26 +95,28 @@ public:
* Prefixs string litterals with d
*
* Params:
* text = Text assigned to the string
* font = Font used to draw the string (use default font)
* s = Text assigned to the string
* f = Font used to draw the string (use default font)
* 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();
m_font = font;
setFont(font);
setString(text);
setCharacterSize(size);
font = f;
text = s;
characterSize = size;
}
@property
{
/**
* Set the text (from a multibyte string)
*
* Params:
* text = New text
*/
void setString(string text)
void text(string text)
{
sfText_SetString(m_ptr, toStringz(text));
}
@ -125,21 +127,32 @@ public:
* Params:
* text = New text
*/
void setString(dstring text)
void text(dstring 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
*
* Params:
* font = Font filename
* f = Font
*/
void setFont(Font font)
void font(Font f)
{
m_font = font;
sfText_SetFont(m_ptr, font.getNativePointer);
m_font = f;
sfText_SetFont(m_ptr, f.getNativePointer);
}
/**
@ -148,7 +161,7 @@ public:
* Params:
* size = New size, in pixels
*/
void setCharacterSize(uint size)
void characterSize(uint size)
{
sfText_SetCharacterSize(m_ptr, size);
}
@ -161,9 +174,9 @@ public:
* 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:
* Text
*/
dstring getUnicodeText()
dstring unicodeText()
{
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
*
* Returns:
* Font name
*/
Font getFont()
Font font()
{
return m_font;
}
@ -205,7 +207,7 @@ public:
* Returns:
* Size of the characters
*/
uint getCharacterSize()
uint characterSize()
{
return sfText_GetCharacterSize(m_ptr);
}
@ -216,11 +218,23 @@ public:
* Returns:
* Font style
*/
TextStyle getStyle()
TextStyle style()
{
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,
* in coordinates relative to the string
@ -239,66 +253,25 @@ public:
return ret;
}
/**
* Get the string rectangle on screen
*
* Returns:
* Rectangle contaning the string in screen coordinates
*/
FloatRect getRect()
{
return sfText_GetRect(m_ptr);
}
private:
extern (C)
static extern(C)
{
typedef void function(void*, cchar*) pf_sfText_SetString;
typedef void function(void*, cdchar*) pf_sfText_SetUnicodeString;
typedef void function(void*, void*) pf_sfText_SetFont;
typedef void function(void*, uint) pf_sfText_SetCharacterSize;
typedef void function(void*, TextStyle) pf_sfText_SetStyle;
typedef idchar* function(void*) pf_sfText_GetUnicodeString;
typedef ichar* function(void*) pf_sfText_GetString;
typedef void* function(void*) pf_sfText_GetFont;
typedef uint function(void*) pf_sfText_GetCharacterSize;
typedef TextStyle function (void*) pf_sfText_GetStyle;
typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos;
typedef FloatRect function(void*) pf_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;
void function(void*, cchar*) sfText_SetString;
void function(void*, cdchar*) sfText_SetUnicodeString;
void function(void*, void*) sfText_SetFont;
void function(void*, uint) sfText_SetCharacterSize;
void function(void*, TextStyle) sfText_SetStyle;
idchar* function(void*) sfText_GetUnicodeString;
ichar* function(void*) sfText_GetString;
void* function(void*) sfText_GetFont;
uint function(void*) sfText_GetCharacterSize;
TextStyle function (void*) sfText_GetStyle;
void function(void*, size_t, float*, float*) sfText_GetCharacterPos;
FloatRect function(void*) sfText_GetRect;
}
static this()
{
debug
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");
}
mixin(loadFromSharedLib2("csfml-graphics", "sfText",
"SetString", "SetUnicodeString", "SetFont", "SetCharacterSize", "SetStyle", "GetUnicodeString", "GetString", "GetFont",
"GetCharacterSize", "GetStyle", "GetCharacterPos", "GetRect"));
}

View File

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