mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
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:
parent
ca7c1d1690
commit
6b444d338e
@ -39,10 +39,10 @@ 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 base class of all drawable.
|
||||
* Provide implementation of IDrawable and functions aliases.
|
||||
*/
|
||||
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,11 +101,113 @@ 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:
|
||||
|
||||
extern (C)
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
@ -68,48 +51,17 @@ interface IDrawable
|
||||
* y = New top coordinate
|
||||
*/
|
||||
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
|
||||
* top-left of the object (take 2 values).
|
||||
@ -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)
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.shape;
|
||||
|
||||
@ -33,10 +33,10 @@ import dsfml.graphics.color;
|
||||
import dsfml.graphics.drawableimpl;
|
||||
|
||||
/**
|
||||
* Shape defines a drawable convex shape ; it also defines
|
||||
* helper functions to draw simple shapes like
|
||||
* lines, rectangles, circles, etc.
|
||||
*/
|
||||
* Shape defines a drawable convex shape ; it also defines
|
||||
* helper functions to draw simple shapes like
|
||||
* lines, rectangles, circles, etc.
|
||||
*/
|
||||
class Shape : DrawableImpl!("sfShape")
|
||||
{
|
||||
private:
|
||||
@ -52,99 +52,102 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the point
|
||||
* y = Y position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the point
|
||||
* y = Y position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
void addPoint(float x, float y, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, x, y, col, outlineCol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* position = position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* position = position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
|
||||
}
|
||||
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Enable or disable filling the shape.
|
||||
* Fill is enabled by default.
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
* Enable or disable filling the shape.
|
||||
* Fill is enabled by default.
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
void enableFill(bool enable)
|
||||
{
|
||||
sfShape_EnableFill(m_ptr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable drawing a shape outline.
|
||||
* Outline is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
* Enable or disable drawing a shape outline.
|
||||
* Outline is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
void enableOutline(bool enable)
|
||||
{
|
||||
sfShape_EnableOutline(m_ptr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the width of a shape outline
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
*/
|
||||
void setOutlineWidth(float width)
|
||||
* Change the width of a shape outline
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
*/
|
||||
void outlineWidth(float width)
|
||||
{
|
||||
sfShape_SetOutlineWidth(m_ptr, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the shape outline
|
||||
*
|
||||
* Returns:
|
||||
* Current outline width
|
||||
*
|
||||
*/
|
||||
float getOutlineWidth()
|
||||
* Get the width of the shape outline
|
||||
*
|
||||
* Returns:
|
||||
* Current outline width
|
||||
*
|
||||
*/
|
||||
float outlineWidth()
|
||||
{
|
||||
return sfShape_GetOutlineWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of points composing a shape
|
||||
*
|
||||
* Returns:
|
||||
* Total number of points
|
||||
*/
|
||||
uint getPointsCount()
|
||||
* Get the number of points composing a shape
|
||||
*
|
||||
* Returns:
|
||||
* Total number of points
|
||||
*/
|
||||
uint pointsCount()
|
||||
{
|
||||
return sfShape_GetPointsCount(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point of the shape
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* position of the point
|
||||
*/
|
||||
* Get a point of the shape
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* position of the point
|
||||
*/
|
||||
Vector2f getPointPosition(uint index)
|
||||
{
|
||||
float x, y;
|
||||
@ -153,64 +156,64 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of a shape point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* position = New position of the point
|
||||
*/
|
||||
* Set the position of a shape point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* position = New position of the point
|
||||
*/
|
||||
void setPointPosition(uint index, Vector2f position)
|
||||
{
|
||||
sfShape_SetPointPosition(m_ptr, index, position.x, position.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the point
|
||||
*/
|
||||
* Get the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the point
|
||||
*/
|
||||
Color getPointColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointColor(m_ptr, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
* Set the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
void setPointColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointColor(m_ptr, index, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the outline
|
||||
*/
|
||||
* Get the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the outline
|
||||
*/
|
||||
Color getPointOutlineColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointOutlineColor(m_ptr, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
* Set the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
void setPointOutlineColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointOutlineColor(m_ptr, index, color);
|
||||
@ -219,19 +222,19 @@ public:
|
||||
|
||||
|
||||
/**
|
||||
* Create a shape made of a single line
|
||||
*
|
||||
* Params:
|
||||
* p1X, p1Y = Position of the first point
|
||||
* p2X, p2Y = Position second point
|
||||
* thickness = Line thickness
|
||||
* col = Color used to draw the line
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* New line shape
|
||||
*/
|
||||
* Create a shape made of a single line
|
||||
*
|
||||
* Params:
|
||||
* p1X, p1Y = Position of the first point
|
||||
* p2X, p2Y = Position second point
|
||||
* thickness = Line thickness
|
||||
* col = Color used to draw the line
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* New line shape
|
||||
*/
|
||||
static Shape line(float p1X, float p1Y, float p2X, float p2Y, float thickness, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
|
||||
@ -239,39 +242,39 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shape made of a single rectangle
|
||||
*
|
||||
* Params:
|
||||
* p1X = X position of the first point
|
||||
* p1Y = Y position of the first point
|
||||
* p2X = X position second point
|
||||
* p2Y = Y position second point
|
||||
* col = Color used to fill the rectangle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new rectangle shape
|
||||
*/
|
||||
* Create a shape made of a single rectangle
|
||||
*
|
||||
* Params:
|
||||
* p1X = X position of the first point
|
||||
* p1Y = Y position of the first point
|
||||
* p2X = X position second point
|
||||
* p2Y = Y position second point
|
||||
* col = Color used to fill the rectangle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new rectangle shape
|
||||
*/
|
||||
static Shape rectangle(float p1X, float p1Y, float p2X, float p2Y, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
return new Shape(sfShape_CreateRectangle(p1X, p1Y, p2X, p2Y, col, outline, outlineCol));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shape made of a single circle
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the center
|
||||
* y = Y position of the center
|
||||
* radius = Radius
|
||||
* col = Color used to fill the circle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new circle shape
|
||||
*/
|
||||
* Create a shape made of a single circle
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the center
|
||||
* y = Y position of the center
|
||||
* radius = Radius
|
||||
* col = Color used to fill the circle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new circle shape
|
||||
*/
|
||||
static Shape circle(float x, float y, float radius, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
return new Shape(sfShape_CreateCircle(x, y, radius, col, outline, outlineCol));
|
||||
@ -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"));
|
||||
}
|
@ -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
|
||||
@ -158,23 +146,52 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source image of the sprite
|
||||
*
|
||||
* Returns:
|
||||
* Pointer to the image (can be NULL)
|
||||
*/
|
||||
Image getImage()
|
||||
* Get the color of a given pixel in the sprite
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate
|
||||
* y = Y coordinate
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
{
|
||||
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 getSubRect()
|
||||
* 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);
|
||||
@ -184,74 +201,33 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sprite size
|
||||
*
|
||||
* Returns:
|
||||
* Size of the sprite
|
||||
*/
|
||||
Vector2f getSize()
|
||||
* Get the sprite size
|
||||
*
|
||||
* Returns:
|
||||
* Size of the sprite
|
||||
*/
|
||||
Vector2f size()
|
||||
{
|
||||
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of a given pixel in the sprite
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate
|
||||
* y = Y coordinate
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
{
|
||||
return sfSprite_GetPixel(m_ptr, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
@ -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,106 +95,108 @@ 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)
|
||||
* Set the text (from a multibyte string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void text(string text)
|
||||
{
|
||||
sfText_SetString(m_ptr, toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text (from a unicode string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void setString(dstring text)
|
||||
* Set the text (from a unicode string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void text(dstring text)
|
||||
{
|
||||
sfText_SetUnicodeString(m_ptr, toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font of the string
|
||||
*
|
||||
* Params:
|
||||
* font = Font filename
|
||||
*/
|
||||
void setFont(Font font)
|
||||
* Get the text (returns a multibyte string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
string text()
|
||||
{
|
||||
m_font = font;
|
||||
sfText_SetFont(m_ptr, font.getNativePointer);
|
||||
return fromStringz(sfText_GetString(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font of the string
|
||||
*
|
||||
* Params:
|
||||
* f = Font
|
||||
*/
|
||||
void font(Font f)
|
||||
{
|
||||
m_font = f;
|
||||
sfText_SetFont(m_ptr, f.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the string
|
||||
*
|
||||
* Params:
|
||||
* size = New size, in pixels
|
||||
*/
|
||||
void setCharacterSize(uint size)
|
||||
* Set the size of the string
|
||||
*
|
||||
* Params:
|
||||
* size = New size, in pixels
|
||||
*/
|
||||
void characterSize(uint size)
|
||||
{
|
||||
sfText_SetCharacterSize(m_ptr, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style of the text
|
||||
* The default style is Regular
|
||||
*
|
||||
* Params:
|
||||
* TextStyle = New text style, (combination of Style enum values)
|
||||
*
|
||||
*/
|
||||
void setStyle(TextStyle style)
|
||||
* Set the style of the text
|
||||
* The default style is Regular
|
||||
*
|
||||
* Params:
|
||||
* TextStyle = New text style, (combination of Style enum values)
|
||||
*
|
||||
*/
|
||||
void style(TextStyle tstyle)
|
||||
{
|
||||
sfText_SetStyle(m_ptr, style);
|
||||
sfText_SetStyle(m_ptr, tstyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a unicode string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
dstring getUnicodeText()
|
||||
* Get the text (returns a unicode string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
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()
|
||||
* Get the font used by the string
|
||||
*
|
||||
* Returns:
|
||||
* Font name
|
||||
*/
|
||||
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,89 +218,60 @@ public:
|
||||
* Returns:
|
||||
* Font style
|
||||
*/
|
||||
TextStyle getStyle()
|
||||
TextStyle style()
|
||||
{
|
||||
return sfText_GetStyle(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the visual position of the Index-th character of the string,
|
||||
* in coordinates relative to the string
|
||||
* (note : translation, center, rotation and scale are not applied)
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the character
|
||||
*
|
||||
* Returns:
|
||||
* Position of the Index-th character (end of string of Index is out of range)
|
||||
*/
|
||||
* 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
|
||||
* (note : translation, center, rotation and scale are not applied)
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the character
|
||||
*
|
||||
* Returns:
|
||||
* Position of the Index-th character (end of string of Index is out of range)
|
||||
*/
|
||||
Vector2f getCharacterPos(size_t index)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfText_GetCharacterPos(m_ptr, index, &ret.x, &ret.y);
|
||||
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"));
|
||||
}
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user