Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
41
DSFML/import/dsfml/graphics/all.d
Normal file
41
DSFML/import/dsfml/graphics/all.d
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.all;
|
||||
|
||||
public import
|
||||
dsfml.graphics.blendmode,
|
||||
dsfml.graphics.color,
|
||||
dsfml.graphics.font,
|
||||
dsfml.graphics.idrawable,
|
||||
dsfml.graphics.image,
|
||||
dsfml.graphics.postfx,
|
||||
dsfml.graphics.rect,
|
||||
dsfml.graphics.renderwindow,
|
||||
dsfml.graphics.shape,
|
||||
dsfml.graphics.sprite,
|
||||
dsfml.graphics.string,
|
||||
dsfml.graphics.textstyle,
|
||||
dsfml.graphics.view;
|
37
DSFML/import/dsfml/graphics/blendmode.d
Normal file
37
DSFML/import/dsfml/graphics/blendmode.d
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.blendmode;
|
||||
|
||||
/**
|
||||
* Enumerate the blending modes for drawable objects.
|
||||
*/
|
||||
enum BlendMode
|
||||
{
|
||||
ALPHA, /// Pixel = Src * a + Dest * (1 - a)
|
||||
ADD, /// Pixel = Src + Dest
|
||||
MULTIPLY, /// Pixel = Src * Dest
|
||||
NONE /// No blending
|
||||
}
|
130
DSFML/import/dsfml/graphics/color.d
Normal file
130
DSFML/import/dsfml/graphics/color.d
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.color;
|
||||
|
||||
|
||||
/**
|
||||
* Color is an utility structure for manipulating colors
|
||||
*/
|
||||
struct Color
|
||||
{
|
||||
/**
|
||||
* Construct the color from its 4 RGBA components
|
||||
*
|
||||
* Params:
|
||||
* r = Red component (0 .. 255)
|
||||
* g = Green component (0 .. 255)
|
||||
* b = Blue component (0 .. 255)
|
||||
* a = Alpha component (0 .. 255) (255 by default)
|
||||
*/
|
||||
static Color opCall(ubyte r, ubyte g, ubyte b, ubyte a = 255)
|
||||
{
|
||||
Color c;
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
c.a = a;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator == and != overload to compare two colors
|
||||
*/
|
||||
int opEquals(Color color2)
|
||||
{
|
||||
return
|
||||
(r == color2.r)
|
||||
&& (g == color2.g)
|
||||
&& (b == color2.b)
|
||||
&& (a == color2.a);
|
||||
}
|
||||
/**
|
||||
* Operator + overload to add two colors
|
||||
*/
|
||||
Color opAdd(Color color2)
|
||||
{
|
||||
ubyte r = this.r + color2.r > 255 ? 255 : this.r + color2.r;
|
||||
ubyte g = this.g + color2.g > 255 ? 255 : this.g + color2.g;
|
||||
ubyte b = this.b + color2.b > 255 ? 255 : this.b + color2.b;
|
||||
ubyte a = this.a + color2.a > 255 ? 255 : this.a + color2.a;
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator += overload
|
||||
*/
|
||||
Color opAddAssign(Color color2)
|
||||
{
|
||||
this.r = this.r + color2.r > 255 ? 255 : this.r + color2.r;
|
||||
this.g = this.g + color2.g > 255 ? 255 : this.g + color2.g;
|
||||
this.b = this.b + color2.b > 255 ? 255 : this.b + color2.b;
|
||||
this.a = this.a + color2.a > 255 ? 255 : this.a + color2.a;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator * overload to modulate colors
|
||||
*/
|
||||
Color opMul(Color color2)
|
||||
{
|
||||
ubyte r = this.r * color2.r / 255;
|
||||
ubyte g = this.g * color2.g / 255;
|
||||
ubyte b = this.b * color2.b / 255;
|
||||
ubyte a = this.a * color2.a / 255;
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator *= overload
|
||||
*/
|
||||
Color opMulAssign(Color color2)
|
||||
{
|
||||
this.r = this.r * color2.r / 255;
|
||||
this.g = this.g * color2.g / 255;
|
||||
this.b = this.b * color2.b / 255;
|
||||
this.a = this.a * color2.a / 255;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ubyte r; /// Red component
|
||||
ubyte g; /// Green component
|
||||
ubyte b; /// Blue component
|
||||
ubyte a = 255; /// Alpha (transparency) component
|
||||
|
||||
static const Color BLACK = {0, 0, 0}; /// Black predefined color
|
||||
static const Color WHITE = {255, 255, 255}; /// White predefined color
|
||||
static const Color RED = {255, 0, 0}; /// Red predefined color
|
||||
static const Color GREEN = {0, 255, 0}; /// Green predefined color
|
||||
static const Color BLUE = {0, 0, 255}; /// Blue predefined color
|
||||
static const Color YELLOW = {255, 0, 255}; /// Yellow predefined color
|
||||
static const Color MAGENTA = {255, 0, 255}; /// Magenta predefined color
|
||||
static const Color CYAN = {0, 255, 255}; /// Cyan predefined color
|
||||
}
|
320
DSFML/import/dsfml/graphics/drawableimpl.d
Normal file
320
DSFML/import/dsfml/graphics/drawableimpl.d
Normal file
|
@ -0,0 +1,320 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.drawableimpl;
|
||||
|
||||
public import dsfml.system.common;
|
||||
import dsfml.system.vector2;
|
||||
|
||||
import dsfml.graphics.idrawable;
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.blendmode;
|
||||
import dsfml.graphics.renderwindow;
|
||||
|
||||
|
||||
package
|
||||
{
|
||||
struct sfSprite{};
|
||||
struct sfShape{};
|
||||
struct sfString{};
|
||||
}
|
||||
|
||||
/*
|
||||
* Package base class of all drawable.
|
||||
* Provide implementation of IDrawable and functions aliases.
|
||||
*/
|
||||
package class Drawableimpl(T) : DSFMLObject, IDrawable
|
||||
{
|
||||
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 setCenter(float centerX, float centerY)
|
||||
{
|
||||
sfDrawable_SetCenter(m_ptr, centerX, centerY);
|
||||
}
|
||||
|
||||
void setCenter(Vector2f center)
|
||||
{
|
||||
sfDrawable_SetCenter(m_ptr, center.x, center.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 getCenter()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetCenterX(m_ptr), sfDrawable_GetCenterY(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)
|
||||
{
|
||||
sfDrawable_Rotate(m_ptr, angle);
|
||||
}
|
||||
|
||||
void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offsetX, offsetY);
|
||||
}
|
||||
|
||||
void move(Vector2f offset)
|
||||
{
|
||||
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;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Vector2f tranformToGlobal(Vector2f point)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void render(RenderWindow window)
|
||||
{
|
||||
sfRenderWindow_DrawThis(window.getNativePointer, m_ptr);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfDrawable_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
this()
|
||||
{
|
||||
super(sfDrawable_Create());
|
||||
}
|
||||
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfDrawable_Create;
|
||||
typedef void function(void*) pf_sfDrawable_Destroy;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetX;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetY;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetPosition;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetScaleX;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetScaleY;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetScale;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetRotation;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetCenter;
|
||||
typedef void function(void*, Color) pf_sfDrawable_SetColor;
|
||||
typedef void function(void*, BlendMode) pf_sfDrawable_SetBlendMode;
|
||||
typedef float function(void*) pf_sfDrawable_GetX;
|
||||
typedef float function(void*) pf_sfDrawable_GetY;
|
||||
typedef float function(void*) pf_sfDrawable_GetScaleX;
|
||||
typedef float function(void*) pf_sfDrawable_GetScaleY;
|
||||
typedef float function(void*) pf_sfDrawable_GetRotation;
|
||||
typedef float function(void*) pf_sfDrawable_GetCenterX;
|
||||
typedef float function(void*) pf_sfDrawable_GetCenterY;
|
||||
typedef Color function(void*) pf_sfDrawable_GetColor;
|
||||
typedef BlendMode function(void*) pf_sfDrawable_GetBlendMode;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_Move;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_Scale;
|
||||
typedef void function(void*, float) pf_sfDrawable_Rotate;
|
||||
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToLocal;
|
||||
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToGlobal;
|
||||
|
||||
typedef void function(void*, void*) pf_sfRenderWindow_DrawThis;
|
||||
|
||||
static pf_sfDrawable_Create sfDrawable_Create;
|
||||
static pf_sfDrawable_Destroy sfDrawable_Destroy;
|
||||
static pf_sfDrawable_SetX sfDrawable_SetX;
|
||||
static pf_sfDrawable_SetY sfDrawable_SetY;
|
||||
static pf_sfDrawable_SetPosition sfDrawable_SetPosition;
|
||||
static pf_sfDrawable_SetScaleX sfDrawable_SetScaleX;
|
||||
static pf_sfDrawable_SetScaleY sfDrawable_SetScaleY;
|
||||
static pf_sfDrawable_SetScale sfDrawable_SetScale;
|
||||
static pf_sfDrawable_SetRotation sfDrawable_SetRotation;
|
||||
static pf_sfDrawable_SetCenter sfDrawable_SetCenter;
|
||||
static pf_sfDrawable_SetColor sfDrawable_SetColor;
|
||||
static pf_sfDrawable_SetBlendMode sfDrawable_SetBlendMode;
|
||||
static pf_sfDrawable_GetX sfDrawable_GetX;
|
||||
static pf_sfDrawable_GetY sfDrawable_GetY;
|
||||
static pf_sfDrawable_GetScaleX sfDrawable_GetScaleX;
|
||||
static pf_sfDrawable_GetScaleY sfDrawable_GetScaleY;
|
||||
static pf_sfDrawable_GetRotation sfDrawable_GetRotation;
|
||||
static pf_sfDrawable_GetCenterX sfDrawable_GetCenterX;
|
||||
static pf_sfDrawable_GetCenterY sfDrawable_GetCenterY;
|
||||
static pf_sfDrawable_GetColor sfDrawable_GetColor;
|
||||
static pf_sfDrawable_GetBlendMode sfDrawable_GetBlendMode;
|
||||
static pf_sfDrawable_Move sfDrawable_Move;
|
||||
static pf_sfDrawable_Scale sfDrawable_Scale;
|
||||
static pf_sfDrawable_Rotate sfDrawable_Rotate;
|
||||
static pf_sfDrawable_TransformToLocal sfDrawable_TransformToLocal;
|
||||
static pf_sfDrawable_TransformToGlobal sfDrawable_TransformToGlobal;
|
||||
|
||||
static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
static if (is (T : sfSprite))
|
||||
{
|
||||
char[] symbol = "sfSprite";
|
||||
}
|
||||
else static if (is (T : sfString))
|
||||
{
|
||||
char[] symbol = "sfString";
|
||||
}
|
||||
else static if (is (T : sfShape))
|
||||
{
|
||||
char[] symbol = "sfShape";
|
||||
}
|
||||
|
||||
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_SetCenter = cast(pf_sfDrawable_SetCenter)dll.getSymbol(symbol ~ "_SetCenter");
|
||||
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_GetCenterX = cast(pf_sfDrawable_GetCenterX)dll.getSymbol(symbol ~ "_GetCenterX");
|
||||
sfDrawable_GetCenterY = cast(pf_sfDrawable_GetCenterY)dll.getSymbol(symbol ~ "_GetCenterY");
|
||||
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");
|
||||
|
||||
sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$]);
|
||||
}
|
||||
}
|
123
DSFML/import/dsfml/graphics/font.d
Normal file
123
DSFML/import/dsfml/graphics/font.d
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.font;
|
||||
|
||||
import dsfml.system.common;
|
||||
import dsfml.system.exception;
|
||||
import dsfml.system.stringutil;
|
||||
|
||||
/**
|
||||
* Font is the low-level class for loading and
|
||||
* manipulating character fonts.
|
||||
*/
|
||||
class Font : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Get SFML default built-in font (Arial)
|
||||
*/
|
||||
static Font getDefaultFont()
|
||||
{
|
||||
if (s_default is null)
|
||||
s_default = new Font(sfFont_GetDefaultFont());
|
||||
return s_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* construct the Font from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = font file to load
|
||||
* charSize = size of characters (30 by default)
|
||||
* charset = characters set to generate (empty by default - takes the ASCII range [31, 255])
|
||||
*/
|
||||
this(char[] filename, uint charSize = 30, dchar[] charset = null)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfFont_CreateFromFile(toStringz(filename), charSize, toStringz(charset)));
|
||||
}
|
||||
|
||||
/**
|
||||
* construct the Font from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = data to load
|
||||
* charSize = size of characters (30 by default)
|
||||
* charset = characters set to generate (empty by default - takes the ASCII range [31, 255])
|
||||
*/
|
||||
this(byte[] data, uint charSize = 30, dchar[] charset = null)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new Exception("LoadingException : Memory stream is invalid.");
|
||||
|
||||
super(sfFont_CreateFromMemory(data.ptr, data.length, charSize, toStringz(charset)));
|
||||
}
|
||||
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfFont_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
package:
|
||||
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
|
||||
private:
|
||||
static Font s_default;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfFont_Create;
|
||||
typedef void* function(char*, uint, dchar*) pf_sfFont_CreateFromFile;
|
||||
typedef void* function(byte*, size_t, uint, dchar*) pf_sfFont_CreateFromMemory;
|
||||
typedef void function(void*) pf_sfFont_Destroy;
|
||||
typedef void* function() pf_sfFont_GetDefaultFont;
|
||||
|
||||
static pf_sfFont_Create sfFont_Create;
|
||||
static pf_sfFont_CreateFromFile sfFont_CreateFromFile;
|
||||
static pf_sfFont_CreateFromMemory sfFont_CreateFromMemory;
|
||||
static pf_sfFont_Destroy sfFont_Destroy;
|
||||
static pf_sfFont_GetDefaultFont sfFont_GetDefaultFont;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfFont_Create = cast(pf_sfFont_Create) dll.getSymbol("sfFont_Create");
|
||||
sfFont_CreateFromFile = cast(pf_sfFont_CreateFromFile) dll.getSymbol("sfFont_CreateFromFile");
|
||||
sfFont_CreateFromMemory = cast(pf_sfFont_CreateFromMemory) dll.getSymbol("sfFont_CreateFromMemory");
|
||||
sfFont_Destroy = cast(pf_sfFont_Destroy) dll.getSymbol("sfFont_Destroy");
|
||||
sfFont_GetDefaultFont = cast(pf_sfFont_GetDefaultFont) dll.getSymbol("sfFont_GetDefaultFont");
|
||||
}
|
||||
}
|
284
DSFML/import/dsfml/graphics/idrawable.d
Normal file
284
DSFML/import/dsfml/graphics/idrawable.d
Normal file
|
@ -0,0 +1,284 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.idrawable;
|
||||
|
||||
import dsfml.system.vector2;
|
||||
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.blendmode;
|
||||
import dsfml.graphics.renderwindow;
|
||||
|
||||
|
||||
/**
|
||||
* Interface for drawable object
|
||||
*
|
||||
* Shape, String and Sprite implement 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
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
* 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
|
||||
*/
|
||||
void setScale(float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = new scale
|
||||
*/
|
||||
void setScale(Vector2f scale);
|
||||
|
||||
/**
|
||||
* Set the center of the object, in coordinates relative to the
|
||||
* top-left of the object (take 2 values).
|
||||
* The default center is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* centerX : X coordinate of the center
|
||||
* centerY : Y coordinate of the center
|
||||
*/
|
||||
void setCenter(float centerX, float centerY);
|
||||
|
||||
/**
|
||||
* Set the center of the object, in coordinates relative to the
|
||||
* top-left of the object (take a 2D vector).
|
||||
* The default center is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* center : New center
|
||||
*/
|
||||
void setCenter(Vector2f center);
|
||||
|
||||
|
||||
/**
|
||||
* Set the rotation of the object
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation, in degree
|
||||
*/
|
||||
void setRotation(float angle);
|
||||
|
||||
/**
|
||||
* Set the color
|
||||
*
|
||||
* Params:
|
||||
* c = New color
|
||||
*/
|
||||
void setColor(Color c);
|
||||
|
||||
/**
|
||||
* Set the blending mode for the object.
|
||||
* The default blend mode is Blend.Alpha
|
||||
*
|
||||
* Params:
|
||||
* mode = New blending mode
|
||||
*/
|
||||
void setBlendMode(BlendMode mode);
|
||||
|
||||
/**
|
||||
* Get the position of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position
|
||||
*
|
||||
*/
|
||||
Vector2f getPosition();
|
||||
|
||||
/**
|
||||
* Get the current scale of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current scale
|
||||
*/
|
||||
Vector2f getScale();
|
||||
|
||||
/**
|
||||
* Get the center of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position of the center
|
||||
*
|
||||
*/
|
||||
Vector2f getCenter();
|
||||
|
||||
/**
|
||||
* Get the rotation angle of the object
|
||||
*
|
||||
* Returns:
|
||||
* Angle of rotation, in degree
|
||||
*/
|
||||
float getRotation();
|
||||
|
||||
/**
|
||||
* Get the color of the string
|
||||
*
|
||||
* Returns:
|
||||
* Current color
|
||||
*/
|
||||
Color getColor();
|
||||
|
||||
/**
|
||||
* Get the current blending mode
|
||||
*
|
||||
* Returns:
|
||||
* Current blending mode
|
||||
*/
|
||||
BlendMode getBlendMode();
|
||||
|
||||
/**
|
||||
* Rotate the object
|
||||
* Angle is added to the current orientation of the objet
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation in degree
|
||||
*/
|
||||
void rotate(float angle);
|
||||
|
||||
/**
|
||||
* Move the object
|
||||
* New offset is added to object current position
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset on the X axis
|
||||
* offsetY = Offset on the Y axis
|
||||
*/
|
||||
void move(float offsetX, float offsetY);
|
||||
|
||||
/**
|
||||
* Move the object
|
||||
* New offset is added to object current position
|
||||
*
|
||||
* Params:
|
||||
* offset = Amount of units to move the object of
|
||||
*/
|
||||
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 center, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f tranformToLocal(Vector2f point);
|
||||
|
||||
/**
|
||||
* Transform a point from local coordinates into global coordinates
|
||||
* (ie it applies the inverse of object's center, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f tranformToGlobal(Vector2f point);
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object
|
||||
*
|
||||
* Params:
|
||||
* window = Target into which render the object
|
||||
*/
|
||||
void render(RenderWindow window);
|
||||
}
|
||||
|
||||
|
366
DSFML/import/dsfml/graphics/image.d
Normal file
366
DSFML/import/dsfml/graphics/image.d
Normal file
|
@ -0,0 +1,366 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* TODO : FIX circular dependency with render window
|
||||
*/
|
||||
module dsfml.graphics.image;
|
||||
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.common;
|
||||
import dsfml.system.exception;
|
||||
import dsfml.system.stringutil;
|
||||
|
||||
|
||||
/**
|
||||
* Image is the low-level class for loading and
|
||||
* manipulating images
|
||||
*/
|
||||
class Image : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfImage_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty image
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* col = Image color (black by default)
|
||||
*/
|
||||
this(uint width, uint height, Color col = Color.BLACK)
|
||||
{
|
||||
super(sfImage_CreateFromColor(width, height, col));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the image from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the image file to load
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException if filename is empty or null.
|
||||
*/
|
||||
this(char[] filename)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfImage_CreateFromFile(toStringz(filename)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the image from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = array of data in memory
|
||||
* Throws:
|
||||
* LoadingException if data is empty or null.
|
||||
*/
|
||||
this(byte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new LoadingException("LoadingException : Memory stream is invalid.");
|
||||
|
||||
super(sfImage_CreateFromMemory(data.ptr, data.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the image directly from an array of pixels
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* data = array of pixels in memory (assumed format is RGBA)
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException if data length doesn't match Width * Height * 4
|
||||
*/
|
||||
this(uint width, uint height, ubyte[] data)
|
||||
{
|
||||
if (width * height * 4 != data.length)
|
||||
throw new LoadingException("LoadingException : Pixels array length doesn't match the specified size.");
|
||||
|
||||
super(sfImage_CreateFromPixels(width, height, data.ptr));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfImage_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the content of the image to a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the file to save (overwritten if already exist)
|
||||
*
|
||||
* Returns:
|
||||
* True if saving was successful
|
||||
*/
|
||||
bool saveToFile(char[] filename)
|
||||
{
|
||||
return cast(bool)sfImage_SaveToFile(m_ptr, toStringz(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty image
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* col = Image color (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* True if creation was successful
|
||||
*/
|
||||
bool create(uint width, uint height, Color col = Color.BLACK)
|
||||
{
|
||||
m_ptr = sfImage_CreateFromColor(width, height, col);
|
||||
return (m_ptr !is null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create transparency mask from a specified colorkey
|
||||
*
|
||||
* Params:
|
||||
* colorKey = Color to become transparent
|
||||
* alpha = Alpha value to use for transparent pixels (0 by default)
|
||||
*/
|
||||
void createMaskFromColor(Color colorKey, ubyte alpha = 0)
|
||||
{
|
||||
sfImage_CreateMaskFromColor(m_ptr, colorKey, alpha);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Create the image from the current contents of the
|
||||
// * given window
|
||||
// *
|
||||
// * Params:
|
||||
// * window = Window to capture
|
||||
// * sourceRect = Sub-rectangle of the screen to copy (empty by default - entire image)
|
||||
// *
|
||||
// * Returns:
|
||||
// * True if copy was successful
|
||||
// */
|
||||
// void copyScreen(RenderWindow window, IntRect sourceRect = new IntRect())
|
||||
// {
|
||||
// return cast(bool)sfImage_CopyScreen(m_ptr, window.getNativePointer, sourceRect.toCIntRect());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Copy pixels from another image onto this one.
|
||||
* This function does a slow pixel copy and should only
|
||||
* be used at initialization time
|
||||
*
|
||||
* Params:
|
||||
* source = Source image to copy
|
||||
* destX = X coordinate of the destination position
|
||||
* destY = Y coordinate of the destination position
|
||||
* sourceRect = Sub-rectangle of the source image to copy
|
||||
*/
|
||||
void copy(Image source, uint destX, uint destY, IntRect sourceRect = new IntRect())
|
||||
{
|
||||
sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect.toCIntRect());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color of a pixel
|
||||
* Don't forget to call Update when you end modifying pixels
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of pixel in the image
|
||||
* y = Y coordinate of pixel in the image
|
||||
* col = New color for pixel (X, Y)
|
||||
*/
|
||||
void setPixel(uint x, uint y, Color col)
|
||||
{
|
||||
sfImage_SetPixel(m_ptr, x, y, col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pixel from the image
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of pixel in the image
|
||||
* y = Y coordinate of pixel in the image
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel (x, y)
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
{
|
||||
return sfImage_GetPixel(m_ptr, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of pixels (8 bits integers RGBA)
|
||||
* Array size is GetWidth() x GetHeight() x 4
|
||||
* This array becomes invalid if you reload or resize the image
|
||||
*
|
||||
* Returns:
|
||||
* array of pixels
|
||||
*/
|
||||
ubyte[] getPixelsArray()
|
||||
{
|
||||
return sfImage_GetPixelsPtr(m_ptr)[0..getWidth() * getHeight() * 4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the image for rendering
|
||||
*/
|
||||
void bind()
|
||||
{
|
||||
sfImage_Bind(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable image smooth filter.
|
||||
* This parameter is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* smooth = True to enable smoothing filter, false to disable it
|
||||
*/
|
||||
void setSmooth(bool smooth)
|
||||
{
|
||||
sfImage_SetSmooth(m_ptr, smooth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the width of the image
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint getWidth()
|
||||
{
|
||||
return sfImage_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of the image
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint getHeight()
|
||||
{
|
||||
return sfImage_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the smooth filtering is enabled or not
|
||||
*
|
||||
* Returns:
|
||||
* True if image smoothing is enabled
|
||||
*/
|
||||
bool isSmooth()
|
||||
{
|
||||
return cast(bool)sfImage_IsSmooth(m_ptr);
|
||||
}
|
||||
|
||||
package:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfImage_Create;
|
||||
typedef void* function(uint, uint, Color) pf_sfImage_CreateFromColor;
|
||||
typedef void* function(uint, uint, ubyte*) pf_sfImage_CreateFromPixels;
|
||||
typedef void* function(char*) pf_sfImage_CreateFromFile;
|
||||
typedef void* function(byte* ,size_t) pf_sfImage_CreateFromMemory;
|
||||
typedef void function(void*) pf_sfImage_Destroy;
|
||||
typedef int function(void*, char*) pf_sfImage_SaveToFile;
|
||||
typedef void function(void*, Color, ubyte) pf_sfImage_CreateMaskFromColor;
|
||||
typedef int function(void*, void*, sfIntRect) pf_sfImage_CopyScreen;
|
||||
typedef void function(void*, void*, uint, uint, sfIntRect) pf_sfImage_Copy;
|
||||
typedef void function(void*, uint, uint, Color) pf_sfImage_SetPixel;
|
||||
typedef Color function(void*, uint, uint) pf_sfImage_GetPixel;
|
||||
typedef ubyte* function(void*) pf_sfImage_GetPixelsPtr;
|
||||
typedef void function(void*) pf_sfImage_Bind;
|
||||
typedef void function(void*, int) pf_sfImage_SetSmooth;
|
||||
typedef uint function(void*) pf_sfImage_GetWidth;
|
||||
typedef uint function(void*) pf_sfImage_GetHeight;
|
||||
typedef int function(void*) pf_sfImage_IsSmooth;
|
||||
|
||||
static pf_sfImage_Create sfImage_Create;
|
||||
static pf_sfImage_CreateFromColor sfImage_CreateFromColor;
|
||||
static pf_sfImage_CreateFromPixels sfImage_CreateFromPixels;
|
||||
static pf_sfImage_CreateFromFile sfImage_CreateFromFile;
|
||||
static pf_sfImage_CreateFromMemory sfImage_CreateFromMemory;
|
||||
static pf_sfImage_Destroy sfImage_Destroy;
|
||||
static pf_sfImage_SaveToFile sfImage_SaveToFile;
|
||||
static pf_sfImage_CreateMaskFromColor sfImage_CreateMaskFromColor;
|
||||
static pf_sfImage_CopyScreen sfImage_CopyScreen;
|
||||
static pf_sfImage_Copy sfImage_Copy;
|
||||
static pf_sfImage_SetPixel sfImage_SetPixel;
|
||||
static pf_sfImage_GetPixel sfImage_GetPixel;
|
||||
static pf_sfImage_GetPixelsPtr sfImage_GetPixelsPtr;
|
||||
static pf_sfImage_Bind sfImage_Bind;
|
||||
static pf_sfImage_SetSmooth sfImage_SetSmooth;
|
||||
static pf_sfImage_GetWidth sfImage_GetWidth;
|
||||
static pf_sfImage_GetHeight sfImage_GetHeight;
|
||||
static pf_sfImage_IsSmooth sfImage_IsSmooth;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfImage_Create = cast(pf_sfImage_Create)dll.getSymbol("sfImage_Create");
|
||||
sfImage_CreateFromColor = cast(pf_sfImage_CreateFromColor)dll.getSymbol("sfImage_CreateFromColor");
|
||||
sfImage_CreateFromPixels = cast(pf_sfImage_CreateFromPixels)dll.getSymbol("sfImage_CreateFromPixels");
|
||||
sfImage_CreateFromFile = cast(pf_sfImage_CreateFromFile)dll.getSymbol("sfImage_CreateFromFile");
|
||||
sfImage_CreateFromMemory = cast(pf_sfImage_CreateFromMemory)dll.getSymbol("sfImage_CreateFromMemory");
|
||||
sfImage_Destroy = cast(pf_sfImage_Destroy)dll.getSymbol("sfImage_Destroy");
|
||||
sfImage_SaveToFile = cast(pf_sfImage_SaveToFile)dll.getSymbol("sfImage_SaveToFile");
|
||||
sfImage_CreateMaskFromColor = cast(pf_sfImage_CreateMaskFromColor)dll.getSymbol("sfImage_CreateMaskFromColor");
|
||||
sfImage_CopyScreen = cast(pf_sfImage_CopyScreen)dll.getSymbol("sfImage_CopyScreen");
|
||||
sfImage_Copy = cast(pf_sfImage_Copy)dll.getSymbol("sfImage_Copy");
|
||||
sfImage_SetPixel = cast(pf_sfImage_SetPixel)dll.getSymbol("sfImage_SetPixel");
|
||||
sfImage_GetPixel = cast(pf_sfImage_GetPixel)dll.getSymbol("sfImage_GetPixel");
|
||||
sfImage_GetPixelsPtr = cast(pf_sfImage_GetPixelsPtr)dll.getSymbol("sfImage_GetPixelsPtr");
|
||||
sfImage_Bind = cast(pf_sfImage_Bind)dll.getSymbol("sfImage_Bind");
|
||||
sfImage_SetSmooth = cast(pf_sfImage_SetSmooth)dll.getSymbol("sfImage_SetSmooth");
|
||||
sfImage_GetWidth = cast(pf_sfImage_GetWidth)dll.getSymbol("sfImage_GetWidth");
|
||||
sfImage_GetHeight = cast(pf_sfImage_GetHeight)dll.getSymbol("sfImage_GetHeight");
|
||||
sfImage_IsSmooth = cast(pf_sfImage_IsSmooth)dll.getSymbol("sfImage_IsSmooth");
|
||||
}
|
||||
}
|
175
DSFML/import/dsfml/graphics/postfx.d
Normal file
175
DSFML/import/dsfml/graphics/postfx.d
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.postfx;
|
||||
|
||||
import dsfml.graphics.image;
|
||||
|
||||
import dsfml.system.common;
|
||||
import dsfml.system.exception;
|
||||
import dsfml.system.stringutil;
|
||||
|
||||
|
||||
/**
|
||||
* Define loading methods for effect
|
||||
*/
|
||||
enum LoadingType
|
||||
{
|
||||
FROMFILE, /// string represents a file path
|
||||
FROMSTRING /// string represents effect code
|
||||
}
|
||||
|
||||
/**
|
||||
* PostFX is used to apply a post effect to a window
|
||||
*
|
||||
* See_Also:
|
||||
* $(LINK2 http://www.sfml-dev.org/tutorials/graphics-postfx.php, SFML post FX tutorial) from more informations about Post effects and GLSL fragment shaders syntax.
|
||||
*/
|
||||
class PostFX : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* construct the effect
|
||||
*
|
||||
* Params:
|
||||
* effect = Path of a file or string containing the effect.
|
||||
* type = type of the effect (default is FROMFILE)
|
||||
*/
|
||||
this(char[] effect, LoadingType type = LoadingType.FROMFILE)
|
||||
{
|
||||
if (effect is null || effect.length == 0)
|
||||
throw new LoadingException("LoadingException : Effect is invalid.");
|
||||
|
||||
if (type == LoadingType.FROMFILE)
|
||||
super(sfPostFX_CreateFromFile(toStringz(effect)));
|
||||
else
|
||||
super(sfPostFX_CreateFromMemory(toStringz(effect)));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfPostFX_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change parameters of the effect
|
||||
*
|
||||
* Params:
|
||||
* name = Parameter name in the effect
|
||||
*/
|
||||
void setParameter(char[] name, float x)
|
||||
{
|
||||
sfPostFX_SetParameter1(m_ptr, toStringz(name), x);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(char[] name, float x, float y)
|
||||
{
|
||||
sfPostFX_SetParameter2(m_ptr, toStringz(name), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(char[] name, float x, float y, float z)
|
||||
{
|
||||
sfPostFX_SetParameter3(m_ptr, toStringz(name), x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(char[] name, float x, float y, float z, float w)
|
||||
{
|
||||
sfPostFX_SetParameter4(m_ptr, toStringz(name), x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a texture parameter
|
||||
*
|
||||
* Params:
|
||||
* name = Texture name in the effect
|
||||
* texture = Image to set (pass NULL to use content of current framebuffer)
|
||||
*/
|
||||
void setTexture(char[] name, Image texture)
|
||||
{
|
||||
m_texture = texture;
|
||||
sfPostFX_SetTexture(m_ptr, toStringz(name), texture is null ? null : texture.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether or not the system supports post-effects
|
||||
*
|
||||
* Returns:
|
||||
* True if the system can use post-effects
|
||||
*/
|
||||
static bool canUsePostFX()
|
||||
{
|
||||
return cast(bool)sfPostFX_CanUsePostFX();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Image m_texture;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function(char*) pf_sfPostFX_CreateFromFile;
|
||||
typedef void* function(char*) pf_sfPostFX_CreateFromMemory;
|
||||
typedef void function(void*) pf_sfPostFX_Destroy;
|
||||
typedef void function(void*, char*, float) pf_sfPostFX_SetParameter1;
|
||||
typedef void function(void*, char*, float, float) pf_sfPostFX_SetParameter2;
|
||||
typedef void function(void*, char*, float, float, float) pf_sfPostFX_SetParameter3;
|
||||
typedef void function(void*, char*, float, float, float, float) pf_sfPostFX_SetParameter4;
|
||||
typedef void function(void*, char*, void*) pf_sfPostFX_SetTexture;
|
||||
typedef int function() pf_sfPostFX_CanUsePostFX;
|
||||
|
||||
static pf_sfPostFX_CreateFromFile sfPostFX_CreateFromFile;
|
||||
static pf_sfPostFX_CreateFromMemory sfPostFX_CreateFromMemory;
|
||||
static pf_sfPostFX_Destroy sfPostFX_Destroy;
|
||||
static pf_sfPostFX_SetParameter1 sfPostFX_SetParameter1;
|
||||
static pf_sfPostFX_SetParameter2 sfPostFX_SetParameter2;
|
||||
static pf_sfPostFX_SetParameter3 sfPostFX_SetParameter3;
|
||||
static pf_sfPostFX_SetParameter4 sfPostFX_SetParameter4;
|
||||
static pf_sfPostFX_SetTexture sfPostFX_SetTexture;
|
||||
static pf_sfPostFX_CanUsePostFX sfPostFX_CanUsePostFX;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfPostFX_CreateFromFile = cast(pf_sfPostFX_CreateFromFile)dll.getSymbol("sfPostFX_CreateFromFile");
|
||||
sfPostFX_CreateFromMemory = cast(pf_sfPostFX_CreateFromMemory)dll.getSymbol("sfPostFX_CreateFromMemory");
|
||||
sfPostFX_Destroy = cast(pf_sfPostFX_Destroy)dll.getSymbol("sfPostFX_Destroy");
|
||||
sfPostFX_SetParameter1 = cast(pf_sfPostFX_SetParameter1)dll.getSymbol("sfPostFX_SetParameter1");
|
||||
sfPostFX_SetParameter2 = cast(pf_sfPostFX_SetParameter2)dll.getSymbol("sfPostFX_SetParameter2");
|
||||
sfPostFX_SetParameter3 = cast(pf_sfPostFX_SetParameter3)dll.getSymbol("sfPostFX_SetParameter3");
|
||||
sfPostFX_SetParameter4 = cast(pf_sfPostFX_SetParameter4)dll.getSymbol("sfPostFX_SetParameter4");
|
||||
sfPostFX_SetTexture = cast(pf_sfPostFX_SetTexture)dll.getSymbol("sfPostFX_SetTexture");
|
||||
sfPostFX_CanUsePostFX = cast(pf_sfPostFX_CanUsePostFX)dll.getSymbol("sfPostFX_CanUsePostFX");
|
||||
}
|
||||
}
|
291
DSFML/import/dsfml/graphics/rect.d
Normal file
291
DSFML/import/dsfml/graphics/rect.d
Normal file
|
@ -0,0 +1,291 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.rect;
|
||||
|
||||
struct sfFloatRect
|
||||
{
|
||||
float Left;
|
||||
float Top;
|
||||
float Right;
|
||||
float Bottom;
|
||||
}
|
||||
|
||||
struct sfIntRect
|
||||
{
|
||||
int Left;
|
||||
int Top;
|
||||
int Right;
|
||||
int Bottom;
|
||||
}
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
import tango.core.Traits;
|
||||
}
|
||||
else
|
||||
{
|
||||
template isIntegerType(T)
|
||||
{
|
||||
const bool isIntegerType =
|
||||
is (T == byte) ||
|
||||
is (T == short) ||
|
||||
is (T == int) ||
|
||||
is (T == long);
|
||||
}
|
||||
|
||||
template isRealType(T)
|
||||
{
|
||||
const bool isRealType =
|
||||
is (T == float) ||
|
||||
is (T == double) ||
|
||||
is (T == real);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Rect is an utility class for manipulating rectangles.
|
||||
* Template parameter defines the type of coordinates (integer float, ...)
|
||||
*/
|
||||
|
||||
class Rect (T)
|
||||
{
|
||||
static if (!isIntegerType!(T) && !isRealType!(T))
|
||||
{
|
||||
static assert (0, "This type is not supported by Rectangle");
|
||||
}
|
||||
|
||||
T min(T)(T i, T j)
|
||||
{
|
||||
return i < j ? i : j;
|
||||
}
|
||||
|
||||
T max(T)(T i, T j)
|
||||
{
|
||||
return i > j ? i : j;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
m_Left = 0;
|
||||
m_Top = 0;
|
||||
m_Right = 0;
|
||||
m_Bottom = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the rectangle from its coordinates
|
||||
*
|
||||
* Params:
|
||||
* leftCoord = Left coordinate of the rectangle
|
||||
* topCoord = Top coordinate of the rectangle
|
||||
* rightCoord = Right coordinate of the rectangle
|
||||
* bottomCoord = Bottom coordinate of the rectangle
|
||||
*/
|
||||
this(T leftCoord, T topCoord, T rightCoord, T bottomCoord)
|
||||
{
|
||||
m_Left = leftCoord;
|
||||
m_Top = topCoord;
|
||||
m_Right = rightCoord;
|
||||
m_Bottom = bottomCoord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the rectangle
|
||||
*
|
||||
* Returns:
|
||||
* Width of rectangle
|
||||
*/
|
||||
T getWidth()
|
||||
{
|
||||
return m_Right - m_Left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the rectangle
|
||||
*
|
||||
* Returns:
|
||||
* Height of rectangle
|
||||
*/
|
||||
T getHeight()
|
||||
{
|
||||
return m_Bottom - m_Top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the whole rectangle by the given offset
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Horizontal offset
|
||||
* offsetY = Vertical offset
|
||||
*/
|
||||
void offset(T offsetX, T offsetY)
|
||||
{
|
||||
m_Left += offsetX;
|
||||
m_Right += offsetX;
|
||||
m_Top += offsetY;
|
||||
m_Bottom += offsetY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is inside the rectangle's area
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of the point to test
|
||||
* y = Y coordinate of the point to test
|
||||
*
|
||||
* Returns:
|
||||
* True if the point is inside
|
||||
*/
|
||||
bool contains(T x, T y)
|
||||
{
|
||||
return (x >= m_Left) && (x <= m_Right) && (y >= m_Top) && (y <= m_Bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check intersection between two rectangles
|
||||
*
|
||||
* Params:
|
||||
* rectangle = Rectangle to test
|
||||
* overlappingRect = Rectangle to be filled with overlapping rect (NULL by default)
|
||||
*
|
||||
* Returns:
|
||||
* True if rectangles overlap
|
||||
*/
|
||||
bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = null)
|
||||
{
|
||||
// Compute overlapping rect
|
||||
Rect!(T) overlapping = new Rect!(T)(
|
||||
max(m_Left, rectangle.getLeft),
|
||||
max(m_Top, rectangle.getTop),
|
||||
min(m_Right, rectangle.getRight),
|
||||
min(m_Bottom, rectangle.getBottom)
|
||||
);
|
||||
|
||||
// If overlapping rect is valid, then there is intersection
|
||||
if ((overlapping.getLeft() < overlapping.getRight() ) && (overlapping.getTop() < overlapping.getBottom()))
|
||||
{
|
||||
overlappingRect = overlapping;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlappingRect = new Rect!(T)();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left Coordinate
|
||||
*/
|
||||
void setLeft(T left)
|
||||
{
|
||||
m_Left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top Coordinate
|
||||
*/
|
||||
void setTop(T top)
|
||||
{
|
||||
m_Top = top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right Coordinate
|
||||
*/
|
||||
void setRight(T right)
|
||||
{
|
||||
m_Right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bottom Coordinate
|
||||
*/
|
||||
void setBottom(T bottom)
|
||||
{
|
||||
m_Bottom = bottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left Coordinate
|
||||
*/
|
||||
T getLeft()
|
||||
{
|
||||
return m_Left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top Coordinate
|
||||
*/
|
||||
T getTop()
|
||||
{
|
||||
return m_Top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get right Coordinate
|
||||
*/
|
||||
T getRight()
|
||||
{
|
||||
return m_Right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bottom Coordinate
|
||||
*/
|
||||
T getBottom()
|
||||
{
|
||||
return m_Bottom;
|
||||
}
|
||||
|
||||
package:
|
||||
sfFloatRect toCFloatRect()
|
||||
{
|
||||
return sfFloatRect(m_Left, m_Top, m_Right, m_Bottom);
|
||||
}
|
||||
|
||||
sfIntRect toCIntRect()
|
||||
{
|
||||
return sfIntRect(cast(int)m_Left, cast(int)m_Top, cast(int)m_Right, cast(int)m_Bottom);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T m_Left; // Left coordinate of the rectangle
|
||||
T m_Top; // Top coordinate of the rectangle
|
||||
T m_Right; // Right coordinate of the rectangle
|
||||
T m_Bottom; // Bottom coordinate of the rectangle
|
||||
}
|
||||
|
||||
///Alias
|
||||
alias Rect!(int) IntRect;
|
||||
///ditto
|
||||
alias Rect!(float) FloatRect;
|
||||
|
||||
|
||||
|
306
DSFML/import/dsfml/graphics/renderwindow.d
Normal file
306
DSFML/import/dsfml/graphics/renderwindow.d
Normal file
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.renderwindow;
|
||||
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.idrawable;
|
||||
import dsfml.graphics.image;
|
||||
import dsfml.graphics.rect;
|
||||
import dsfml.graphics.postfx;
|
||||
import dsfml.graphics.view;
|
||||
|
||||
import dsfml.window.event;
|
||||
import dsfml.window.input;
|
||||
import dsfml.window.videomode;
|
||||
import dsfml.window.window;
|
||||
import dsfml.window.windowhandle;
|
||||
import dsfml.window.windowsettings;
|
||||
import dsfml.window.windowstyle;
|
||||
|
||||
import dsfml.system.common;
|
||||
import dsfml.system.stringutil;
|
||||
import dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* Simple wrapper for Window that allows easy 2D rendering.
|
||||
*/
|
||||
class RenderWindow : Window
|
||||
{
|
||||
/**
|
||||
* Construct the window
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Window settings (default is default WindowSettings values)
|
||||
*/
|
||||
this(VideoMode mode, in char[] title, ulong windowStyle = Style.RESIZE | Style.CLOSE, WindowSettings settings = WindowSettings())
|
||||
{
|
||||
super(sfRenderWindow_Create(mode, toStringz(title), windowStyle, settings));
|
||||
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the window from an existing control
|
||||
*
|
||||
* Params:
|
||||
* handle = Platform-specific handle of the control
|
||||
* settings = Window settings (default is default WindowSettings values)
|
||||
*/
|
||||
this(WindowHandle handle, WindowSettings settings = WindowSettings())
|
||||
{
|
||||
super(sfRenderWindow_CreateFromHandle(handle, settings));
|
||||
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfRenderWindow_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create (or recreate) the window
|
||||
*
|
||||
* Input created with getInput will become invalid.
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Window settings (default is default WindowSettings values)
|
||||
*
|
||||
*/
|
||||
void create(VideoMode mode, char[] title, ulong windowStyle = Style.RESIZE | Style.CLOSE, WindowSettings settings = WindowSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
|
||||
m_ptr = sfRenderWindow_Create(mode, toStringz(title), windowStyle, settings);
|
||||
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create (or recreate) the window from an existing control
|
||||
*
|
||||
* Input created with getInput become invalid.
|
||||
*
|
||||
* Params:
|
||||
* handle = Platform-specific handle of the control
|
||||
* settings = Window settings (default is default WindowSettings values)
|
||||
*
|
||||
*/
|
||||
void create(WindowHandle handle, WindowSettings settings = WindowSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
|
||||
m_ptr = sfRenderWindow_CreateFromHandle(handle, settings);
|
||||
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a PostFX on the window
|
||||
*
|
||||
* Params:
|
||||
* postFX = PostFX to draw
|
||||
*/
|
||||
void draw(PostFX postFX)
|
||||
{
|
||||
sfRenderWindow_DrawPostFX(m_ptr, postFX.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a Sprite or a String
|
||||
*
|
||||
* Params:
|
||||
* obj = IDrawable object to draw
|
||||
*/
|
||||
void draw(IDrawable obj)
|
||||
{
|
||||
obj.render(this);
|
||||
}
|
||||
/**
|
||||
* Save the content of the window to an image
|
||||
*
|
||||
* Returns:
|
||||
* Image instance containing the contents of the screen
|
||||
*/
|
||||
Image capture()
|
||||
{
|
||||
return new Image(sfRenderWindow_Capture(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the screen with the given color.
|
||||
*
|
||||
* Params:
|
||||
* col = Fill color
|
||||
*/
|
||||
void clear(Color col = Color.BLACK)
|
||||
{
|
||||
sfRenderWindow_Clear(m_ptr, col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current active view.
|
||||
* The current view is defined with the initial size of the window
|
||||
*
|
||||
* Params:
|
||||
* newView = Pointer to the new view (pass getDefaultView to set the default view)
|
||||
*/
|
||||
void setView(View newView)
|
||||
{
|
||||
if (m_view !is null)
|
||||
{
|
||||
m_view.setHandled(false);
|
||||
}
|
||||
|
||||
sfRenderWindow_SetView(m_ptr, newView.getNativePointer);
|
||||
|
||||
m_view = newView;
|
||||
m_view.setHandled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current view rectangle
|
||||
*
|
||||
* Returns:
|
||||
* current view rectangle, in global coordinates
|
||||
*/
|
||||
View getView()
|
||||
{
|
||||
if (m_view is null)
|
||||
{
|
||||
void* cView = sfRenderWindow_GetView(m_ptr);
|
||||
m_view = new View(cView, true);
|
||||
}
|
||||
return m_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default view
|
||||
*
|
||||
* Returns:
|
||||
* default view
|
||||
*/
|
||||
View getDefaultView()
|
||||
{
|
||||
if (m_defaultView is null)
|
||||
{
|
||||
void* cView = sfRenderWindow_GetDefaultView(m_ptr);
|
||||
m_defaultView = new View(cView, true);
|
||||
}
|
||||
return m_defaultView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point in window coordinates into view coordinates
|
||||
*
|
||||
* Params:
|
||||
* windowX = X coordinate of the point to convert, relative to the window
|
||||
* windowY = Y coordinate of the point to convert, relative to the window
|
||||
* targetView = Target view to convert the point to (pass NULL to use the current view)
|
||||
*
|
||||
* Returns:
|
||||
* Converted point
|
||||
*/
|
||||
Vector2f convertCoords(uint windowX, uint windowY, View targetView = null)
|
||||
{
|
||||
Vector2f vec;
|
||||
sfRenderWindow_ConvertCoords(m_ptr, windowX, windowY, &vec.x, &vec.y, targetView is null ? null : targetView.getNativePointer);
|
||||
return vec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell SFML to preserve external OpenGL states, at the expense of
|
||||
* more CPU charge. Use this function if you don't want SFML
|
||||
* to mess up your own OpenGL states (if any).
|
||||
* Don't enable state preservation if not needed, as it will allow
|
||||
* SFML to do internal optimizations and improve performances.
|
||||
* This parameter is false by default
|
||||
*
|
||||
* Params:
|
||||
* preserve = True to preserve OpenGL states, false to let SFML optimize
|
||||
*
|
||||
*/
|
||||
void preserveOpenGLStates(bool preserve)
|
||||
{
|
||||
sfRenderWindow_PreserveOpenGLStates(m_ptr, preserve);
|
||||
}
|
||||
|
||||
private:
|
||||
View m_view = null;
|
||||
View m_defaultView = null;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function(VideoMode, char*, uint, WindowSettings) pf_sfRenderWindow_Create;
|
||||
typedef void* function(WindowHandle, WindowSettings) pf_sfRenderWindow_CreateFromHandle;
|
||||
typedef void function(void*) pf_sfRenderWindow_Destroy;
|
||||
typedef void* function(void*) pf_sfRenderWindow_GetInput;
|
||||
typedef void function(void*, void*) pf_sfRenderWindow_DrawPostFX;
|
||||
typedef void* function(void*) pf_sfRenderWindow_Capture;
|
||||
typedef void function(void*, Color) pf_sfRenderWindow_Clear;
|
||||
typedef void function(void*, void*) pf_sfRenderWindow_SetView;
|
||||
typedef void* function(void*) pf_sfRenderWindow_GetView;
|
||||
typedef void* function (void*) pf_sfRenderWindow_GetDefaultView;
|
||||
typedef void function(void*, uint, uint, float*, float*, void*) pf_sfRenderWindow_ConvertCoords;
|
||||
typedef void function(void*, int) pf_sfRenderWindow_PreserveOpenGLStates;
|
||||
|
||||
static pf_sfRenderWindow_Create sfRenderWindow_Create;
|
||||
static pf_sfRenderWindow_CreateFromHandle sfRenderWindow_CreateFromHandle;
|
||||
static pf_sfRenderWindow_Destroy sfRenderWindow_Destroy;
|
||||
static pf_sfRenderWindow_GetInput sfRenderWindow_GetInput;
|
||||
static pf_sfRenderWindow_DrawPostFX sfRenderWindow_DrawPostFX;
|
||||
static pf_sfRenderWindow_Capture sfRenderWindow_Capture;
|
||||
static pf_sfRenderWindow_Clear sfRenderWindow_Clear;
|
||||
static pf_sfRenderWindow_SetView sfRenderWindow_SetView;
|
||||
static pf_sfRenderWindow_GetView sfRenderWindow_GetView;
|
||||
static pf_sfRenderWindow_GetDefaultView sfRenderWindow_GetDefaultView;
|
||||
static pf_sfRenderWindow_ConvertCoords sfRenderWindow_ConvertCoords;
|
||||
static pf_sfRenderWindow_PreserveOpenGLStates sfRenderWindow_PreserveOpenGLStates;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfRenderWindow_Create = cast(pf_sfRenderWindow_Create)dll.getSymbol("sfRenderWindow_Create");
|
||||
sfRenderWindow_CreateFromHandle = cast(pf_sfRenderWindow_CreateFromHandle)dll.getSymbol("sfRenderWindow_CreateFromHandle");
|
||||
sfRenderWindow_Destroy = cast(pf_sfRenderWindow_Destroy)dll.getSymbol("sfRenderWindow_Destroy");
|
||||
sfRenderWindow_GetInput = cast(pf_sfRenderWindow_GetInput)dll.getSymbol("sfRenderWindow_GetInput");
|
||||
sfRenderWindow_DrawPostFX = cast(pf_sfRenderWindow_DrawPostFX)dll.getSymbol("sfRenderWindow_DrawPostFX");
|
||||
sfRenderWindow_Capture = cast(pf_sfRenderWindow_Capture)dll.getSymbol("sfRenderWindow_Capture");
|
||||
sfRenderWindow_Clear = cast(pf_sfRenderWindow_Clear)dll.getSymbol("sfRenderWindow_Clear");
|
||||
sfRenderWindow_SetView = cast(pf_sfRenderWindow_SetView)dll.getSymbol("sfRenderWindow_SetView");
|
||||
sfRenderWindow_GetView = cast(pf_sfRenderWindow_GetView)dll.getSymbol("sfRenderWindow_GetView");
|
||||
sfRenderWindow_GetDefaultView = cast(pf_sfRenderWindow_GetDefaultView)dll.getSymbol("sfRenderWindow_GetDefaultView");
|
||||
sfRenderWindow_ConvertCoords = cast(pf_sfRenderWindow_ConvertCoords)dll.getSymbol("sfRenderWindow_ConvertCoords");
|
||||
sfRenderWindow_PreserveOpenGLStates = cast(pf_sfRenderWindow_PreserveOpenGLStates)dll.getSymbol("sfRenderWindow_PreserveOpenGLStates");
|
||||
}
|
||||
}
|
||||
|
333
DSFML/import/dsfml/graphics/shape.d
Normal file
333
DSFML/import/dsfml/graphics/shape.d
Normal file
|
@ -0,0 +1,333 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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;
|
||||
|
||||
import dsfml.system.vector2;
|
||||
|
||||
import dsfml.graphics.blendmode;
|
||||
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.
|
||||
*/
|
||||
class Shape : Drawableimpl!(sfShape)
|
||||
{
|
||||
this()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void enableOutline(bool enable)
|
||||
{
|
||||
sfShape_EnableOutline(m_ptr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the width of a shape outline
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
*/
|
||||
void setOutlineWidth(float width)
|
||||
{
|
||||
sfShape_SetOutlineWidth(m_ptr, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the shape outline
|
||||
*
|
||||
* Returns:
|
||||
* Current outline width
|
||||
*
|
||||
*/
|
||||
float getOutlineWidth()
|
||||
{
|
||||
return sfShape_GetOutlineWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of points composing a shape
|
||||
*
|
||||
* Returns:
|
||||
* Total number of points
|
||||
*/
|
||||
uint getNbPoints()
|
||||
{
|
||||
return sfShape_GetNbPoints(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point of the shape
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* position of the point
|
||||
*/
|
||||
Vector2f getPointPosition(uint index)
|
||||
{
|
||||
float x, y;
|
||||
sfShape_GetPointPosition(m_ptr, index, &x, &y);
|
||||
return Vector2f(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
void setPointOutlineColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointOutlineColor(m_ptr, index, color);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
|
||||
return new Shape(sfShape_CreateLine(p1X, p1Y, p2X, p2Y, thickness, col, outline, outlineCol));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
private:
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
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_GetNbPoints;
|
||||
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_GetNbPoints sfShape_GetNbPoints;
|
||||
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()
|
||||
{
|
||||
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_GetNbPoints = cast(pf_sfShape_GetNbPoints)dll.getSymbol("sfShape_GetNbPoints");
|
||||
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");
|
||||
}
|
||||
}
|
248
DSFML/import/dsfml/graphics/sprite.d
Normal file
248
DSFML/import/dsfml/graphics/sprite.d
Normal file
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.sprite;
|
||||
|
||||
import dsfml.graphics.blendmode;
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.drawableimpl;
|
||||
import dsfml.graphics.image;
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* Sprite defines a sprite : texture, transformations,
|
||||
* color, and draw on screen
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
*/
|
||||
class Sprite : Drawableimpl!(sfSprite)
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the sprite from a source image
|
||||
*
|
||||
* Params:
|
||||
* 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)
|
||||
* 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)
|
||||
{
|
||||
m_image = img;
|
||||
sfSprite_SetImage(m_ptr, img.getNativePointer);
|
||||
setX(left);
|
||||
setY(top);
|
||||
setScaleX(scaleX);
|
||||
setScaleY(scaleY);
|
||||
setRotation(rotation);
|
||||
setColor(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image of the sprite
|
||||
*
|
||||
* Params:
|
||||
* img = New image
|
||||
*/
|
||||
void setImage(Image img)
|
||||
{
|
||||
assert(img !is null, "Trying to set a null image.");
|
||||
sfSprite_SetImage(m_ptr, img.getNativePointer);
|
||||
m_image = img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sub-rectangle of a sprite inside the source image.
|
||||
*
|
||||
* Params:
|
||||
* rect = New sub-rectangle
|
||||
*/
|
||||
void setSubRect(IntRect rect)
|
||||
{
|
||||
sfIntRect r = rect.toCIntRect();
|
||||
sfSprite_SetSubRect(m_ptr, &r);
|
||||
m_subRect = rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the sprite (by changing its scale factors).
|
||||
* The default size is defined by the subrect
|
||||
*
|
||||
* Params:
|
||||
* width = New width (must be strictly positive)
|
||||
* height = New height (must be strictly positive)
|
||||
*/
|
||||
void resize(float width, float height)
|
||||
{
|
||||
if (width > 0 && height > 0)
|
||||
sfSprite_Resize(m_ptr, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the sprite (by changing its scale factors).
|
||||
* The default size is defined by the subrect
|
||||
*
|
||||
* Params:
|
||||
* size = New size (both coordinates must be strictly positive)
|
||||
*/
|
||||
void resize(Vector2f size)
|
||||
{
|
||||
if (size.x > 0 && size.y > 0)
|
||||
sfSprite_Resize(m_ptr, size.x, size.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flip the sprite horizontally
|
||||
*
|
||||
* Params:
|
||||
* flipped = True to flip the sprite
|
||||
*/
|
||||
void flipX(bool flipped)
|
||||
{
|
||||
sfSprite_FlipX(m_ptr, flipped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip the sprite vertically
|
||||
*
|
||||
* Params:
|
||||
* flipped = True to flip the sprite
|
||||
*/
|
||||
void flipY(bool 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 is null)
|
||||
m_subRect = new 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
|
||||
*
|
||||
* 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:
|
||||
Image m_image; //< Image used to draw the sprite
|
||||
IntRect m_subRect; //< Sub-rectangle of source image to assign to the sprite
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*, void*) pf_sfSprite_SetImage;
|
||||
typedef void function(void*, sfIntRect*) 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 void* 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()
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
290
DSFML/import/dsfml/graphics/string.d
Normal file
290
DSFML/import/dsfml/graphics/string.d
Normal file
|
@ -0,0 +1,290 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.string;
|
||||
|
||||
import dsfml.graphics.blendmode;
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.font;
|
||||
import dsfml.graphics.textstyle;
|
||||
import dsfml.graphics.drawableimpl;
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.stringutil;
|
||||
import dsfml.system.vector2;
|
||||
|
||||
|
||||
/**
|
||||
* String defines a graphical 2D text, that can be drawn on screen
|
||||
*
|
||||
* All string litterals used must be prefixed with c for utf-8
|
||||
* and d for utf-32 string.
|
||||
*
|
||||
* Examples :
|
||||
* ---------------------------------------------------------------
|
||||
* String s = new String("Hello"c);
|
||||
* //this(char[], Font, float)
|
||||
* s = new String("Hello"d);
|
||||
* //this(dchar[], Font, float)
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
*/
|
||||
class String : Drawableimpl!(sfString)
|
||||
{
|
||||
/**
|
||||
* Construct the string from a text
|
||||
*
|
||||
* Prefixs string litterals with c
|
||||
*
|
||||
* Params:
|
||||
* text = Text assigned to the string
|
||||
* font = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(char[] text, Font font = Font.getDefaultFont(), float size = 30.f)
|
||||
{
|
||||
super();
|
||||
m_font = font;
|
||||
setFont(font);
|
||||
setText(text);
|
||||
setSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the string from a unicode text
|
||||
*
|
||||
* Prefixs string litterals with d
|
||||
*
|
||||
* Params:
|
||||
* text = Text assigned to the string
|
||||
* font = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(dchar[] text, Font font = Font.getDefaultFont(), float size = 30.f)
|
||||
{
|
||||
super();
|
||||
m_font = font;
|
||||
setFont(font);
|
||||
setText(text);
|
||||
setSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text (from a multibyte string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*
|
||||
*/
|
||||
void setText(char[] text)
|
||||
{
|
||||
sfString_SetText(m_ptr,toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text (from a unicode string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void setText(dchar[] text)
|
||||
{
|
||||
sfString_SetUnicodeText(m_ptr, toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font of the string
|
||||
*
|
||||
* Params:
|
||||
* font = Font filename
|
||||
*/
|
||||
void setFont(Font font)
|
||||
{
|
||||
m_font = font;
|
||||
sfString_SetFont(m_ptr, font.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the string
|
||||
*
|
||||
* Params:
|
||||
* size = New size, in pixels
|
||||
*/
|
||||
void setSize(float size)
|
||||
{
|
||||
sfString_SetSize(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)
|
||||
{
|
||||
sfString_SetStyle(m_ptr, style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a unicode string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
dchar[] getUnicodeText()
|
||||
{
|
||||
return fromStringz(sfString_GetUnicodeText(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a multibyte string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
char[] getText()
|
||||
{
|
||||
return fromStringz(sfString_GetText(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the font used by the string
|
||||
*
|
||||
* Returns:
|
||||
* Font name
|
||||
*/
|
||||
Font getFont()
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the characters
|
||||
*
|
||||
* Returns:
|
||||
* Size of the characters
|
||||
*/
|
||||
float getSize()
|
||||
{
|
||||
return sfString_GetSize(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current font style
|
||||
*
|
||||
* Returns:
|
||||
* Font style
|
||||
*/
|
||||
TextStyle getStyle()
|
||||
{
|
||||
return sfString_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)
|
||||
*/
|
||||
Vector2f getCharacterPos(size_t index)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfString_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()
|
||||
{
|
||||
sfFloatRect sfRect = sfString_GetRect(m_ptr);
|
||||
|
||||
return new Rect!(float)(sfRect.Left, sfRect.Top, sfRect.Right, sfRect.Bottom);
|
||||
}
|
||||
|
||||
private:
|
||||
Font m_font;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*, char*) pf_sfString_SetText;
|
||||
typedef void function(void*, dchar*) pf_sfString_SetUnicodeText;
|
||||
typedef void function(void*, void*) pf_sfString_SetFont;
|
||||
typedef void function(void*, float) pf_sfString_SetSize;
|
||||
typedef void function(void*, TextStyle) pf_sfString_SetStyle;
|
||||
typedef dchar* function(void*) pf_sfString_GetUnicodeText;
|
||||
typedef char* function(void*) pf_sfString_GetText;
|
||||
typedef void* function(void*) pf_sfString_GetFont;
|
||||
typedef float function(void*) pf_sfString_GetSize;
|
||||
typedef TextStyle function (void*) pf_sfString_GetStyle;
|
||||
typedef void function(void*, size_t, float*, float*) pf_sfString_GetCharacterPos;
|
||||
typedef sfFloatRect function(void*) pf_sfString_GetRect;
|
||||
|
||||
static pf_sfString_SetText sfString_SetText;
|
||||
static pf_sfString_SetUnicodeText sfString_SetUnicodeText;
|
||||
static pf_sfString_SetFont sfString_SetFont;
|
||||
static pf_sfString_SetSize sfString_SetSize;
|
||||
static pf_sfString_SetStyle sfString_SetStyle;
|
||||
static pf_sfString_GetUnicodeText sfString_GetUnicodeText;
|
||||
static pf_sfString_GetText sfString_GetText;
|
||||
static pf_sfString_GetFont sfString_GetFont;
|
||||
static pf_sfString_GetSize sfString_GetSize;
|
||||
static pf_sfString_GetStyle sfString_GetStyle;
|
||||
static pf_sfString_GetCharacterPos sfString_GetCharacterPos;
|
||||
static pf_sfString_GetRect sfString_GetRect;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfString_SetText = cast(pf_sfString_SetText)dll.getSymbol("sfString_SetText");
|
||||
sfString_SetUnicodeText = cast(pf_sfString_SetUnicodeText)dll.getSymbol("sfString_SetUnicodeText");
|
||||
sfString_SetFont = cast(pf_sfString_SetFont)dll.getSymbol("sfString_SetFont");
|
||||
sfString_SetSize = cast(pf_sfString_SetSize)dll.getSymbol("sfString_SetSize");
|
||||
sfString_SetStyle = cast(pf_sfString_SetStyle)dll.getSymbol("sfString_SetStyle");
|
||||
sfString_GetUnicodeText = cast(pf_sfString_GetUnicodeText)dll.getSymbol("sfString_GetUnicodeText");
|
||||
sfString_GetText = cast(pf_sfString_GetText)dll.getSymbol("sfString_GetText");
|
||||
sfString_GetFont = cast(pf_sfString_GetFont)dll.getSymbol("sfString_GetFont");
|
||||
sfString_GetSize = cast(pf_sfString_GetSize)dll.getSymbol("sfString_GetSize");
|
||||
sfString_GetStyle = cast(pf_sfString_GetStyle)dll.getSymbol("sfString_GetStyle");
|
||||
sfString_GetCharacterPos = cast(pf_sfString_GetCharacterPos)dll.getSymbol("sfString_GetCharacterPos");
|
||||
sfString_GetRect = cast(pf_sfString_GetRect)dll.getSymbol("sfString_GetRect");
|
||||
}
|
||||
}
|
37
DSFML/import/dsfml/graphics/textstyle.d
Normal file
37
DSFML/import/dsfml/graphics/textstyle.d
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.textstyle;
|
||||
|
||||
/**
|
||||
* Enumerate the string drawing styles
|
||||
*/
|
||||
enum TextStyle
|
||||
{
|
||||
REGULAR = 0, /// Regular characters, no style
|
||||
BOLD = 1 << 0, /// Characters are bold
|
||||
ITALIC = 1 << 1, /// Characters are in italic
|
||||
UNDERLINED = 1 << 2 /// Characters are underlined
|
||||
}
|
274
DSFML/import/dsfml/graphics/view.d
Normal file
274
DSFML/import/dsfml/graphics/view.d
Normal file
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* DSFML - SFML Library binding in D language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
*
|
||||
* 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.view;
|
||||
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.common;
|
||||
import dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* This class defines a view (position, size and zoom) ;
|
||||
* you can consider it as a camera
|
||||
*/
|
||||
class View : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Default view (1000 x 1000)
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfView_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* center = center of the view
|
||||
* halfsize = Half-size of the view (from center to corner)
|
||||
*/
|
||||
this(Vector2f center, Vector2f halfsize)
|
||||
{
|
||||
super(sfView_CreateFromRect(sfFloatRect(center.x - halfsize.x, center.y - halfsize.y, center.x + halfsize.x, center.y + halfsize.y) ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* rect = Rectangle defining the position and size of the view
|
||||
*/
|
||||
this(FloatRect rect)
|
||||
{
|
||||
super(sfView_CreateFromRect(rect.toCFloatRect()));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfView_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the center of the view
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinates of the new center
|
||||
* y = Y coordinates of the new center
|
||||
*/
|
||||
void setCenter(float x, float y)
|
||||
{
|
||||
sfView_SetCenter(m_ptr, x, y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the center of the view
|
||||
*
|
||||
* Params:
|
||||
* center = New center
|
||||
*/
|
||||
void setCenter(Vector2f center)
|
||||
{
|
||||
sfView_SetCenter(m_ptr, center.x, center.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the half-size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* halfWidth = New half-width
|
||||
* halfHeight = New half-height
|
||||
*/
|
||||
void setHalfSize(float halfWidth, float HalfHeight)
|
||||
{
|
||||
sfView_SetHalfSize(m_ptr, halfWidth, HalfHeight);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the half-size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* helfSize = New halfsize
|
||||
*/
|
||||
void setHalfSize(Vector2f halfSize)
|
||||
{
|
||||
sfView_SetHalfSize(m_ptr, halfSize.x, halfSize.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the view from a rectangle
|
||||
*
|
||||
* Params:
|
||||
* viewRect : Rectangle defining the position and size of the view
|
||||
*/
|
||||
void setFromRect(FloatRect viewRect)
|
||||
{
|
||||
sfView_SetFromRect(m_ptr, viewRect.toCFloatRect());
|
||||
m_rect = viewRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the center of the view
|
||||
*
|
||||
* Returns:
|
||||
* Center of the view
|
||||
*/
|
||||
Vector2f GetCenter()
|
||||
{
|
||||
return Vector2f(sfView_GetCenterX(m_ptr), sfView_GetCenterY(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the halfsize of the view
|
||||
*
|
||||
* Returns:
|
||||
* Halfsize of the view
|
||||
*/
|
||||
Vector2f GetHalfSize()
|
||||
{
|
||||
return Vector2f(sfView_GetHalfSizeX(m_ptr), sfView_GetHalfSizeY(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounding retangle of the view
|
||||
*/
|
||||
FloatRect getRect()
|
||||
{
|
||||
if (m_isModified)
|
||||
{
|
||||
m_isModified = false;
|
||||
sfFloatRect cRect = sfView_GetRect(m_ptr);
|
||||
m_rect = new FloatRect(cRect.Left, cRect.Top, cRect.Right, cRect.Bottom);
|
||||
}
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset to move the view, on X axis
|
||||
* offsetY = Offset to move the view, on Y axis
|
||||
*/
|
||||
void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfView_Move(m_ptr, offsetX, offsetY);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offset = offsetto move the view
|
||||
*/
|
||||
void move(Vector2f offset)
|
||||
{
|
||||
sfView_Move(m_ptr, offset.x, offset.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the view rectangle to simulate a zoom / unzoom effect
|
||||
*
|
||||
* Params:
|
||||
* factor = Zoom factor to apply, relative to the current zoom
|
||||
*/
|
||||
void zoom(float factor)
|
||||
{
|
||||
sfView_Zoom(m_ptr, factor);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
package:
|
||||
|
||||
this(void* ptr, bool preventDelete)
|
||||
{
|
||||
super(ptr, preventDelete);
|
||||
}
|
||||
|
||||
private:
|
||||
FloatRect m_rect;
|
||||
bool m_isModified = true;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfView_Create;
|
||||
typedef void* function(sfFloatRect) pf_sfView_CreateFromRect;
|
||||
typedef void function(void*) pf_sfView_Destroy;
|
||||
typedef void function(void*, float, float) pf_sfView_SetCenter;
|
||||
typedef void function(void*, float, float) pf_sfView_SetHalfSize;
|
||||
typedef void function(void*, sfFloatRect ViewRect) pf_sfView_SetFromRect;
|
||||
typedef float function(void*) pf_sfView_GetCenterX;
|
||||
typedef float function(void*) pf_sfView_GetCenterY;
|
||||
typedef float function(void*) pf_sfView_GetHalfSizeX;
|
||||
typedef float function(void*) pf_sfView_GetHalfSizeY;
|
||||
typedef sfFloatRect function(void*) pf_sfView_GetRect;
|
||||
typedef void function(void*, float, float) pf_sfView_Move;
|
||||
typedef void function(void*, float) pf_sfView_Zoom;
|
||||
|
||||
static pf_sfView_Create sfView_Create;
|
||||
static pf_sfView_CreateFromRect sfView_CreateFromRect;
|
||||
static pf_sfView_Destroy sfView_Destroy;
|
||||
static pf_sfView_SetCenter sfView_SetCenter;
|
||||
static pf_sfView_SetHalfSize sfView_SetHalfSize;
|
||||
static pf_sfView_SetFromRect sfView_SetFromRect;
|
||||
static pf_sfView_GetCenterX sfView_GetCenterX;
|
||||
static pf_sfView_GetCenterY sfView_GetCenterY;
|
||||
static pf_sfView_GetHalfSizeX sfView_GetHalfSizeX;
|
||||
static pf_sfView_GetHalfSizeY sfView_GetHalfSizeY;
|
||||
static pf_sfView_GetRect sfView_GetRect;
|
||||
static pf_sfView_Move sfView_Move;
|
||||
static pf_sfView_Zoom sfView_Zoom;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfView_Create = cast(pf_sfView_Create) dll.getSymbol("sfView_Create");
|
||||
sfView_CreateFromRect = cast(pf_sfView_CreateFromRect) dll.getSymbol("sfView_CreateFromRect");
|
||||
sfView_Destroy = cast(pf_sfView_Destroy) dll.getSymbol("sfView_Destroy");
|
||||
sfView_SetCenter = cast(pf_sfView_SetCenter) dll.getSymbol("sfView_SetCenter");
|
||||
sfView_SetHalfSize = cast(pf_sfView_SetHalfSize) dll.getSymbol("sfView_SetHalfSize");
|
||||
sfView_SetFromRect = cast(pf_sfView_SetFromRect) dll.getSymbol("sfView_SetFromRect");
|
||||
sfView_GetCenterX = cast(pf_sfView_GetCenterX) dll.getSymbol("sfView_GetCenterX");
|
||||
sfView_GetCenterY = cast(pf_sfView_GetCenterY) dll.getSymbol("sfView_GetCenterY");
|
||||
sfView_GetHalfSizeX = cast(pf_sfView_GetHalfSizeX) dll.getSymbol("sfView_GetHalfSizeX");
|
||||
sfView_GetHalfSizeY = cast(pf_sfView_GetHalfSizeY) dll.getSymbol("sfView_GetHalfSizeY");
|
||||
sfView_GetRect = cast(pf_sfView_GetRect) dll.getSymbol("sfView_GetRect");
|
||||
sfView_Move = cast(pf_sfView_Move) dll.getSymbol("sfView_Move");
|
||||
sfView_Zoom = cast(pf_sfView_Zoom) dll.getSymbol("sfView_Zoom");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue