Moved all bindings to the "bindings" sub-directory
Renamed the CSFML directory to c Renamed the DSFML directory to d --> bindings must now be updated to match the new organization! git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
0cc5563cac
commit
0e2297af28
417 changed files with 0 additions and 0 deletions
41
bindings/d/import/dsfml/graphics/all.d
Normal file
41
bindings/d/import/dsfml/graphics/all.d
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.all;
|
||||
|
||||
public import
|
||||
dsfml.graphics.blendmode,
|
||||
dsfml.graphics.color,
|
||||
dsfml.graphics.font,
|
||||
dsfml.graphics.idrawable,
|
||||
dsfml.graphics.image,
|
||||
dsfml.graphics.shader,
|
||||
dsfml.graphics.rect,
|
||||
dsfml.graphics.renderwindow,
|
||||
dsfml.graphics.shape,
|
||||
dsfml.graphics.sprite,
|
||||
dsfml.graphics.text,
|
||||
dsfml.graphics.view;
|
38
bindings/d/import/dsfml/graphics/blendmode.d
Normal file
38
bindings/d/import/dsfml/graphics/blendmode.d
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.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
|
||||
}
|
123
bindings/d/import/dsfml/graphics/color.d
Normal file
123
bindings/d/import/dsfml/graphics/color.d
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.color;
|
||||
|
||||
import std.string;
|
||||
|
||||
alias RGBA Color; // standard Color is RGBA
|
||||
|
||||
/**
|
||||
* Color is an utility structure for manipulating colors
|
||||
*/
|
||||
struct RGBA
|
||||
{
|
||||
align(1):
|
||||
ubyte r; /// Red component
|
||||
ubyte g; /// Green component
|
||||
ubyte b; /// Blue component
|
||||
ubyte a = 255; /// Alpha (transparency) component, 255 = opaque
|
||||
|
||||
/**
|
||||
* Operator == and != overload to compare two colors
|
||||
*/
|
||||
const bool opEquals(ref const(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 : cast(ubyte) (this.r + color2.r);
|
||||
ubyte g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
|
||||
ubyte b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
|
||||
ubyte a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator += overload
|
||||
*/
|
||||
Color opAddAssign(Color color2)
|
||||
{
|
||||
this.r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
|
||||
this.g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
|
||||
this.b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
|
||||
this.a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator * overload to modulate colors
|
||||
*/
|
||||
Color opMul(Color color2)
|
||||
{
|
||||
ubyte r = cast(ubyte) (this.r * color2.r / 255);
|
||||
ubyte g = cast(ubyte) (this.g * color2.g / 255);
|
||||
ubyte b = cast(ubyte) (this.b * color2.b / 255);
|
||||
ubyte a = cast(ubyte) (this.a * color2.a / 255);
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator *= overload
|
||||
*/
|
||||
Color opMulAssign(Color color2)
|
||||
{
|
||||
this.r = cast(ubyte) (this.r * color2.r / 255);
|
||||
this.g = cast(ubyte) (this.g * color2.g / 255);
|
||||
this.b = cast(ubyte) (this.b * color2.b / 255);
|
||||
this.a = cast(ubyte) (this.a * color2.a / 255);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
string toString()
|
||||
{
|
||||
return std.string.format("(%d,%d,%d,%d)", r,g,b,a);
|
||||
}
|
||||
|
||||
static immutable
|
||||
{
|
||||
Color BLACK = Color(0, 0, 0); /// Black predefined color
|
||||
Color WHITE = Color(255, 255, 255); /// White predefined color
|
||||
Color RED = Color(255, 0, 0); /// Red predefined color
|
||||
Color GREEN = Color(0, 255, 0); /// Green predefined color
|
||||
Color BLUE = Color(0, 0, 255); /// Blue predefined color
|
||||
Color YELLOW = Color(255, 0, 255); /// Yellow predefined color
|
||||
Color MAGENTA = Color(255, 0, 255); /// Magenta predefined color
|
||||
Color CYAN = Color(0, 255, 255); /// Cyan predefined color
|
||||
}
|
||||
}
|
268
bindings/d/import/dsfml/graphics/drawableimpl.d
Normal file
268
bindings/d/import/dsfml/graphics/drawableimpl.d
Normal file
|
@ -0,0 +1,268 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.drawableimpl;
|
||||
|
||||
public import dsfml.system.common;
|
||||
import dsfml.system.vector;
|
||||
|
||||
import dsfml.graphics.irendertarget;
|
||||
import dsfml.graphics.idrawable,
|
||||
dsfml.graphics.color,
|
||||
dsfml.graphics.blendmode,
|
||||
dsfml.graphics.renderwindow,
|
||||
dsfml.graphics.renderimage,
|
||||
dsfml.graphics.shader;
|
||||
|
||||
|
||||
/*
|
||||
* Package base class of all drawable.
|
||||
* Provide implementation of IDrawable and functions aliases.
|
||||
*/
|
||||
package class DrawableImpl(string derivedClassName) : DSFMLObject, IDrawable
|
||||
{
|
||||
protected:
|
||||
this()
|
||||
{
|
||||
super(sfDrawable_Create());
|
||||
}
|
||||
|
||||
this(SFMLClass ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfDrawable_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
public:
|
||||
override void rotate(float angle)
|
||||
{
|
||||
sfDrawable_Rotate(m_ptr, angle);
|
||||
}
|
||||
|
||||
override void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offsetX, offsetY);
|
||||
}
|
||||
|
||||
override void move(Vector2f offset)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offset.x, offset.y);
|
||||
}
|
||||
|
||||
override Vector2f transformToLocal(Vector2f point) const
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
override Vector2f transformToGlobal(Vector2f point) const
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
override void render(IRenderTarget window)
|
||||
{
|
||||
sfRenderWindow_DrawThis((cast(DSFMLObject)window).nativePointer, m_ptr);
|
||||
}
|
||||
|
||||
override void renderWithShader(IRenderTarget window, Shader shader)
|
||||
{
|
||||
sfRenderWindow_DrawThisWithShader((cast(DSFMLObject)window).nativePointer, m_ptr, shader.nativePointer);
|
||||
}
|
||||
|
||||
override void setPosition(float x, float y)
|
||||
{
|
||||
sfDrawable_SetPosition(m_ptr, x, y);
|
||||
}
|
||||
|
||||
override void setScale(float scaleX, float scaleY)
|
||||
{
|
||||
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
|
||||
}
|
||||
|
||||
override void setOrigin(float originX, float originY)
|
||||
{
|
||||
sfDrawable_SetOrigin(m_ptr, originX, originY);
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
override void x(float x)
|
||||
{
|
||||
sfDrawable_SetX(m_ptr, x);
|
||||
}
|
||||
|
||||
override void y(float y)
|
||||
{
|
||||
sfDrawable_SetY(m_ptr, y);
|
||||
}
|
||||
|
||||
override void position(Vector2f vec)
|
||||
{
|
||||
sfDrawable_SetPosition(m_ptr, vec.x, vec.y);
|
||||
}
|
||||
|
||||
override void scaleX(float scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
sfDrawable_SetScaleX(m_ptr, scale);
|
||||
}
|
||||
|
||||
override void scaleY(float scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
sfDrawable_SetScaleY(m_ptr, scale);
|
||||
}
|
||||
|
||||
override void scale(Vector2f scale)
|
||||
{
|
||||
if (scale.x > 0 && scale.y > 0)
|
||||
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
|
||||
}
|
||||
|
||||
override void origin(Vector2f origin)
|
||||
{
|
||||
sfDrawable_SetOrigin(m_ptr, origin.x, origin.y);
|
||||
}
|
||||
|
||||
override void rotation(float angle)
|
||||
{
|
||||
sfDrawable_SetRotation(m_ptr, angle);
|
||||
}
|
||||
|
||||
override void color(Color c)
|
||||
{
|
||||
sfDrawable_SetColor(m_ptr, c);
|
||||
}
|
||||
|
||||
override void blendMode(BlendMode mode)
|
||||
{
|
||||
sfDrawable_SetBlendMode(m_ptr, mode);
|
||||
}
|
||||
|
||||
override Vector2f position() const
|
||||
{
|
||||
return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr));
|
||||
}
|
||||
|
||||
override Vector2f scale() const
|
||||
{
|
||||
return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr));
|
||||
}
|
||||
|
||||
override Vector2f origin() const
|
||||
{
|
||||
return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr));
|
||||
}
|
||||
|
||||
override float rotation() const
|
||||
{
|
||||
return sfDrawable_GetRotation(m_ptr);
|
||||
}
|
||||
|
||||
override Color color() const
|
||||
{
|
||||
return sfDrawable_GetColor(m_ptr);
|
||||
}
|
||||
|
||||
override BlendMode blendMode() const
|
||||
{
|
||||
return cast(BlendMode)(sfDrawable_GetBlendMode(m_ptr));
|
||||
}
|
||||
|
||||
override void scale(Vector2f scale)
|
||||
{
|
||||
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function() sfDrawable_Create;
|
||||
void function(SFMLClass) sfDrawable_Destroy;
|
||||
void function(SFMLClass, float) sfDrawable_SetX;
|
||||
void function(SFMLClass, float) sfDrawable_SetY;
|
||||
void function(SFMLClass, float, float) sfDrawable_SetPosition;
|
||||
void function(SFMLClass, float) sfDrawable_SetScaleX;
|
||||
void function(SFMLClass, float) sfDrawable_SetScaleY;
|
||||
void function(SFMLClass, float, float) sfDrawable_SetScale;
|
||||
void function(SFMLClass, float) sfDrawable_SetRotation;
|
||||
void function(SFMLClass, float, float) sfDrawable_SetOrigin;
|
||||
void function(SFMLClass, Color) sfDrawable_SetColor;
|
||||
void function(SFMLClass, BlendMode) sfDrawable_SetBlendMode;
|
||||
float function(SFMLClass) sfDrawable_GetX;
|
||||
float function(SFMLClass) sfDrawable_GetY;
|
||||
float function(SFMLClass) sfDrawable_GetScaleX;
|
||||
float function(SFMLClass) sfDrawable_GetScaleY;
|
||||
float function(SFMLClass) sfDrawable_GetRotation;
|
||||
float function(SFMLClass) sfDrawable_GetOriginX;
|
||||
float function(SFMLClass) sfDrawable_GetOriginY;
|
||||
Color function(SFMLClass) sfDrawable_GetColor;
|
||||
BlendMode function(SFMLClass) sfDrawable_GetBlendMode;
|
||||
void function(SFMLClass, float, float) sfDrawable_Move;
|
||||
void function(SFMLClass, float, float) sfDrawable_Scale;
|
||||
void function(SFMLClass, float) sfDrawable_Rotate;
|
||||
void function(SFMLClass, float, float, float*, float*) sfDrawable_TransformToLocal;
|
||||
void function(SFMLClass, float, float, float*, float*) sfDrawable_TransformToGlobal;
|
||||
|
||||
typedef void function(SFMLClass, SFMLClass) pf_sfRenderWindow_DrawThis;
|
||||
typedef void function(SFMLClass, SFMLClass, SFMLClass) pf_sfRenderWindow_DrawThisWithShader;
|
||||
typedef void function(SFMLClass, SFMLClass) pf_sfRenderImage_DrawThis;
|
||||
typedef void function(SFMLClass, SFMLClass, SFMLClass) pf_sfRenderImage_DrawThisWithShader;
|
||||
|
||||
pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis;
|
||||
pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader;
|
||||
pf_sfRenderImage_DrawThis sfRenderImage_DrawThis;
|
||||
pf_sfRenderImage_DrawThisWithShader sfRenderImage_DrawThisWithShader;
|
||||
}
|
||||
|
||||
mixin(loadDerivedFromSharedLib("csfml-graphics", "sfDrawable", derivedClassName,
|
||||
"Create", "Destroy", "SetX", "SetY", "SetPosition", "SetScaleX", "SetScaleY", "SetScale", "SetRotation", "SetOrigin", "SetColor", "SetBlendMode",
|
||||
"GetX", "GetY", "GetScaleX", "GetScaleY", "GetRotation", "GetOriginX", "GetOriginY", "GetColor", "GetBlendMode", "Move",
|
||||
"Scale", "Rotate", "TransformToLocal", "TransformToGlobal"));
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ derivedClassName[2..$]);
|
||||
sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ derivedClassName[2..$] ~ "WithShader");
|
||||
sfRenderImage_DrawThis = cast(pf_sfRenderImage_DrawThis)dll.getSymbol("sfRenderImage_Draw" ~ derivedClassName[2..$]);
|
||||
sfRenderImage_DrawThisWithShader = cast(pf_sfRenderImage_DrawThisWithShader)dll.getSymbol("sfRenderImage_Draw" ~ derivedClassName[2..$] ~ "WithShader");
|
||||
}
|
||||
}
|
193
bindings/d/import/dsfml/graphics/font.d
Normal file
193
bindings/d/import/dsfml/graphics/font.d
Normal file
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.font;
|
||||
|
||||
import dsfml.system.common,
|
||||
dsfml.system.exception,
|
||||
dsfml.system.stringutil;
|
||||
|
||||
import dsfml.graphics.rect,
|
||||
dsfml.graphics.image;
|
||||
|
||||
|
||||
/// Glyph describes a glyph (a visual character)
|
||||
struct Glyph
|
||||
{
|
||||
int Advance; /// Offset to move horizontically to the next character
|
||||
IntRect Bounds; /// Bounding rectangle of the glyph, in coordinates relative to the baseline
|
||||
IntRect SubRect; /// Texture coordinates of the glyph inside the font's image
|
||||
}
|
||||
|
||||
/**
|
||||
* Font is the low-level class for loading and
|
||||
* manipulating character fonts.
|
||||
*/
|
||||
class Font : DSFMLObject
|
||||
{
|
||||
private:
|
||||
static Font s_default;
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfFont_CreateFromFile(toStringz(filename)));
|
||||
}
|
||||
|
||||
/**
|
||||
* construct the Font from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = data to load
|
||||
*/
|
||||
this(ubyte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new Exception("LoadingException : Memory stream is invalid.");
|
||||
|
||||
super(sfFont_CreateFromMemory(data.ptr, data.length));
|
||||
}
|
||||
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfFont_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a glyph in a font
|
||||
*
|
||||
* Params:
|
||||
* codePoint = Unicode code point of the character to get
|
||||
* charSize = Reference character size
|
||||
* bold = Retrieve the bold version or the regular one?
|
||||
* Returns:
|
||||
* The glyph corresponding to codePoint and charSize
|
||||
*/
|
||||
Glyph getGlyph(uint codePoint, uint charSize, bool bold)
|
||||
{
|
||||
return sfFont_GetGlyph(m_ptr, codePoint, charSize, bold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the kerning offset of two glyphs
|
||||
*
|
||||
* Params:
|
||||
* first = Unicode code point of the first character
|
||||
* second = Unicode code point of the second character
|
||||
* charSize = Reference character size
|
||||
*
|
||||
* Returns:
|
||||
* Kerning value for first and second, in pixels
|
||||
*/
|
||||
int getKerning(uint first, uint second, uint charSize)
|
||||
{
|
||||
return sfFont_GetKerning(m_ptr, first, second, charSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vertical offset to apply between two consecutive lines of text.
|
||||
*
|
||||
* Params:
|
||||
* charSize = Reference character size
|
||||
*
|
||||
* Returns:
|
||||
* Line spacing, in pixels
|
||||
*/
|
||||
int getLineSpacing(uint charSize)
|
||||
{
|
||||
return sfFont_GetLineSpacing(m_ptr, charSize);
|
||||
}
|
||||
|
||||
Image getImage(uint charSize)
|
||||
{
|
||||
return new Image(sfFont_GetImage(m_ptr, charSize));
|
||||
}
|
||||
|
||||
package:
|
||||
|
||||
this(SFMLClass ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
|
||||
private:
|
||||
static extern(C)
|
||||
{
|
||||
// sfFont
|
||||
SFMLClass function() sfFont_Create;
|
||||
SFMLClass function(cchar*) sfFont_CreateFromFile;
|
||||
SFMLClass function(ubyte*, size_t) sfFont_CreateFromMemory;
|
||||
void function(SFMLClass) sfFont_Destroy;
|
||||
SFMLClass function() sfFont_GetDefaultFont;
|
||||
|
||||
// DSFML2
|
||||
Glyph function(SFMLClass, uint, uint, bool) sfFont_GetGlyph;
|
||||
int function(SFMLClass, uint, uint, uint) sfFont_GetKerning;
|
||||
int function(SFMLClass, uint) sfFont_GetLineSpacing;
|
||||
SFMLClass function(SFMLClass, uint) sfFont_GetImage;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
// sfFont
|
||||
mixin(loadFromSharedLib("sfFont_CreateFromFile"));
|
||||
mixin(loadFromSharedLib("sfFont_CreateFromMemory"));
|
||||
mixin(loadFromSharedLib("sfFont_Destroy"));
|
||||
mixin(loadFromSharedLib("sfFont_GetDefaultFont"));
|
||||
|
||||
// DSFML2
|
||||
mixin(loadFromSharedLib("sfFont_GetGlyph"));
|
||||
mixin(loadFromSharedLib("sfFont_GetKerning"));
|
||||
mixin(loadFromSharedLib("sfFont_GetLineSpacing"));
|
||||
mixin(loadFromSharedLib("sfFont_GetImage"));
|
||||
|
||||
}
|
||||
}
|
285
bindings/d/import/dsfml/graphics/idrawable.d
Normal file
285
bindings/d/import/dsfml/graphics/idrawable.d
Normal file
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.idrawable;
|
||||
|
||||
import dsfml.system.vector;
|
||||
|
||||
import dsfml.graphics.irendertarget;
|
||||
import dsfml.graphics.color,
|
||||
dsfml.graphics.blendmode,
|
||||
dsfml.graphics.renderwindow,
|
||||
dsfml.graphics.renderimage,
|
||||
dsfml.graphics.shader;
|
||||
|
||||
|
||||
/**
|
||||
* Interface for drawable object
|
||||
*
|
||||
* Shape, Text and Sprite implement IDrawable
|
||||
*/
|
||||
interface IDrawable
|
||||
{
|
||||
/**
|
||||
* Set the position of the object
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
* y = New top coordinate
|
||||
*/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scaleX = New horizontal scale > 0
|
||||
* scaleY = New vertical scale > 0
|
||||
*/
|
||||
void setScale(float scalex, float scaley);
|
||||
// in {assert(scalex > 0 && scalex > 0);} // TODO: add in again when interface contracts work
|
||||
|
||||
/**
|
||||
* Set the origin of the object, in coordinates relative to the
|
||||
* top-left of the object (take 2 values).
|
||||
* The default origin is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* originX : X coordinate of the origin
|
||||
* originY : Y coordinate of the origin
|
||||
*/
|
||||
void setOrigin(float originX, float originY);
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Set the left position of the object
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
*/
|
||||
void x(float x);
|
||||
|
||||
/**
|
||||
* Set the top position of the object
|
||||
*
|
||||
* Params:
|
||||
* y = New top coordinate
|
||||
*/
|
||||
void y(float y);
|
||||
|
||||
/**
|
||||
* Set the position of the object
|
||||
*
|
||||
* Params:
|
||||
* vec = new position
|
||||
*/
|
||||
void position(Vector2f vec);
|
||||
|
||||
/**
|
||||
* Set the horizontal scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = New horizontal scale (Strictly positive)
|
||||
*/
|
||||
void scaleX(float scale);
|
||||
|
||||
/**
|
||||
* Set the vertical scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = New vertical scale (Strictly positive)
|
||||
*/
|
||||
void scaleY(float scale);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = new scale
|
||||
*/
|
||||
void scale(Vector2f scale);
|
||||
// in {assert(scale.x > 0 && scale.y > 0);} // TODO
|
||||
|
||||
/**
|
||||
* Set the origin of the object, in coordinates relative to the
|
||||
* top-left of the object (take a 2D vector).
|
||||
* The default origin is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* origin : New origin
|
||||
*/
|
||||
void origin(Vector2f origin);
|
||||
|
||||
|
||||
/**
|
||||
* Set the rotation of the object
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation, in degree
|
||||
*/
|
||||
void rotation(float angle);
|
||||
|
||||
/**
|
||||
* Set the color
|
||||
*
|
||||
* Params:
|
||||
* c = New color
|
||||
*/
|
||||
void color(Color c);
|
||||
|
||||
/**
|
||||
* Set the blending mode for the object.
|
||||
* The default blend mode is Blend.Alpha
|
||||
*
|
||||
* Params:
|
||||
* mode = New blending mode
|
||||
*/
|
||||
void blendMode(BlendMode mode);
|
||||
|
||||
const
|
||||
{
|
||||
/**
|
||||
* Get the position of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position
|
||||
*
|
||||
*/
|
||||
Vector2f position();
|
||||
|
||||
/**
|
||||
* Get the current scale of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current scale
|
||||
*/
|
||||
Vector2f scale();
|
||||
|
||||
/**
|
||||
* Get the origin of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position of the origin
|
||||
*
|
||||
*/
|
||||
Vector2f origin();
|
||||
|
||||
/**
|
||||
* Get the rotation angle of the object
|
||||
*
|
||||
* Returns:
|
||||
* Angle of rotation, in degree
|
||||
*/
|
||||
float rotation();
|
||||
|
||||
/**
|
||||
* Get the color of the string
|
||||
*
|
||||
* Returns:
|
||||
* Current color
|
||||
*/
|
||||
Color color();
|
||||
|
||||
/**
|
||||
* Get the current blending mode
|
||||
*
|
||||
* Returns:
|
||||
* Current blending mode
|
||||
*/
|
||||
BlendMode blendMode();
|
||||
} // const
|
||||
} // @property
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Transform a point from global coordinates into local coordinates
|
||||
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f transformToLocal(Vector2f point) const;
|
||||
|
||||
/**
|
||||
* Transform a point from local coordinates into global coordinates
|
||||
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f transformToGlobal(Vector2f point) const;
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object
|
||||
*
|
||||
* Params:
|
||||
* window = Target into which render the object
|
||||
*/
|
||||
void render(IRenderTarget window);
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object with a shader
|
||||
*
|
||||
* Params:
|
||||
* window = Render target
|
||||
* shader = Shader to use
|
||||
*/
|
||||
void renderWithShader(IRenderTarget window, Shader shader);
|
||||
}
|
352
bindings/d/import/dsfml/graphics/image.d
Normal file
352
bindings/d/import/dsfml/graphics/image.d
Normal file
|
@ -0,0 +1,352 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
|
||||
module dsfml.graphics.image;
|
||||
|
||||
import dsfml.graphics.color,
|
||||
dsfml.graphics.rect;
|
||||
// dsfml.graphics.renderwindow;
|
||||
|
||||
import dsfml.system.common,
|
||||
dsfml.system.exception,
|
||||
dsfml.system.stringutil;
|
||||
|
||||
|
||||
/**
|
||||
* Image is the low-level class for loading and
|
||||
* manipulating images
|
||||
*/
|
||||
class Image : DSFMLObject
|
||||
{
|
||||
package:
|
||||
this(SFMLClass ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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(string 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(ubyte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new 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("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(string 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
|
||||
*/
|
||||
bool copyScreen(RenderWindow window, IntRect sourceRect = IntRect())
|
||||
{
|
||||
return cast(bool)sfImage_CopyScreen(m_ptr, window.nativePointer, sourceRect);
|
||||
}
|
||||
+/
|
||||
|
||||
/**
|
||||
* 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 copyImage(Image source, uint destX, uint destY, IntRect sourceRect = IntRect())
|
||||
{
|
||||
sfImage_CopyImage(m_ptr, source.nativePointer, destX, destY, sourceRect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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..width() * height() * 4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the image for rendering
|
||||
*/
|
||||
void bind()
|
||||
{
|
||||
sfImage_Bind(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a sub-rectangle of the image from an array of pixels
|
||||
*
|
||||
* Warning: for performances reasons, this function doesn't
|
||||
* perform any check; thus you're responsible of ensuring that
|
||||
* rectangle does not exceed the image size, and that
|
||||
* pixels contains enough elements.
|
||||
*
|
||||
* Params:
|
||||
* rectangle = sub rectangle of the image to update
|
||||
* pixels = array of pixels to write to the image
|
||||
*/
|
||||
void updatePixels(ubyte[] pixels, IntRect rectangle)
|
||||
{
|
||||
sfImage_UpdatePixels(m_ptr, pixels.ptr, rectangle);
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Enable or disable image smooth filter.
|
||||
* This parameter is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* s = True to enable smoothing filter, false to disable it
|
||||
*/
|
||||
void smooth(bool s)
|
||||
{
|
||||
sfImage_SetSmooth(m_ptr, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the width of the image
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint width()
|
||||
{
|
||||
return sfImage_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of the image
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint height()
|
||||
{
|
||||
return sfImage_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the smooth filtering is enabled or not
|
||||
*
|
||||
* Returns:
|
||||
* True if image smoothing is enabled
|
||||
*/
|
||||
bool smooth()
|
||||
{
|
||||
return cast(bool)sfImage_IsSmooth(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static extern (C)
|
||||
{
|
||||
SFMLClass function() sfImage_Create;
|
||||
SFMLClass function(uint, uint, Color) sfImage_CreateFromColor;
|
||||
SFMLClass function(uint, uint, ubyte*) sfImage_CreateFromPixels;
|
||||
SFMLClass function(cchar*) sfImage_CreateFromFile;
|
||||
SFMLClass function(ubyte* ,size_t) sfImage_CreateFromMemory;
|
||||
void function(SFMLClass) sfImage_Destroy;
|
||||
int function(SFMLClass, cchar*) sfImage_SaveToFile;
|
||||
void function(SFMLClass, Color, ubyte) sfImage_CreateMaskFromColor;
|
||||
SFMLClass function(SFMLClass) sfImage_Copy;
|
||||
int function(SFMLClass, SFMLClass, IntRect) sfImage_CopyScreen;
|
||||
void function(SFMLClass, SFMLClass, uint, uint, IntRect) sfImage_CopyImage;
|
||||
void function(SFMLClass, uint, uint, Color) sfImage_SetPixel;
|
||||
Color function(SFMLClass, uint, uint) sfImage_GetPixel;
|
||||
ubyte* function(SFMLClass) sfImage_GetPixelsPtr;
|
||||
void function(SFMLClass) sfImage_Bind;
|
||||
void function(SFMLClass, int) sfImage_SetSmooth;
|
||||
uint function(SFMLClass) sfImage_GetWidth;
|
||||
uint function(SFMLClass) sfImage_GetHeight;
|
||||
int function(SFMLClass) sfImage_IsSmooth;
|
||||
void function(SFMLClass, ubyte*, IntRect) sfImage_UpdatePixels;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-graphics", "sfImage",
|
||||
"Create", "CreateFromColor", "CreateFromPixels", "CreateFromFile", "CreateFromMemory", "Destroy", "SaveToFile",
|
||||
"CreateMaskFromColor", "Copy", "CopyScreen", "CopyImage", "SetPixel", "GetPixel", "GetPixelsPtr", "Bind", "SetSmooth", "GetWidth",
|
||||
"GetHeight", "IsSmooth", "UpdatePixels"));
|
||||
}
|
138
bindings/d/import/dsfml/graphics/irendertarget.d
Normal file
138
bindings/d/import/dsfml/graphics/irendertarget.d
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.irendertarget;
|
||||
|
||||
import dsfml.system.vector;
|
||||
import dsfml.graphics.idrawable;
|
||||
import dsfml.graphics.rect;
|
||||
import dsfml.graphics.shader;
|
||||
import dsfml.graphics.view;
|
||||
import dsfml.graphics.color;
|
||||
|
||||
interface IRenderTarget
|
||||
{
|
||||
/**
|
||||
* Clear the entire target with a single color
|
||||
*
|
||||
* \param color : Color to use to clear the render target
|
||||
*
|
||||
*/
|
||||
void clear(Color color = Color());
|
||||
|
||||
/**
|
||||
* Draw something into the target
|
||||
*
|
||||
* \param object : Object to draw
|
||||
*
|
||||
*/
|
||||
void draw(IDrawable object);
|
||||
|
||||
/**
|
||||
* Draw something into the target with a shader
|
||||
*
|
||||
* \param object : Object to draw
|
||||
* \param shader : Shader to apply
|
||||
*
|
||||
*/
|
||||
void draw(IDrawable object, Shader shader);
|
||||
|
||||
/**
|
||||
* Convert a point in target coordinates into view coordinates
|
||||
*
|
||||
* \param x : X coordinate of the point to convert, relative to the target
|
||||
* \param y : Y coordinate of the point to convert, relative to the target
|
||||
* \param view : Target view to convert the point to, null to use the currently associated view
|
||||
*
|
||||
* \return Converted point
|
||||
*
|
||||
*/
|
||||
Vector2f convertCoords(uint x, uint y, View view = null);
|
||||
|
||||
/**
|
||||
* Save the current OpenGL render states and matrices
|
||||
*
|
||||
*/
|
||||
void saveGLStates();
|
||||
|
||||
/**
|
||||
* Restore the previously saved OpenGL render states and matrices
|
||||
*
|
||||
*/
|
||||
void restoreGLStates();
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Get the width of the rendering region of the target
|
||||
*
|
||||
* \return Width in pixels
|
||||
*
|
||||
*/
|
||||
uint width();
|
||||
|
||||
/**
|
||||
* Get the height of the rendering region of the target
|
||||
*
|
||||
* \return Height in pixels
|
||||
*
|
||||
*/
|
||||
uint height();
|
||||
|
||||
/**
|
||||
* Change the current active view.
|
||||
*
|
||||
* \param view : New view to use (pass GetDefaultView() to set the default view)
|
||||
*
|
||||
*/
|
||||
void view(View view);
|
||||
|
||||
/**
|
||||
* Get the current view
|
||||
*
|
||||
* \return Current view active in the window
|
||||
*
|
||||
*/
|
||||
View view();
|
||||
|
||||
/**
|
||||
* Get the default view of the window
|
||||
*
|
||||
* \return Default view
|
||||
*
|
||||
*/
|
||||
View defaultView();
|
||||
|
||||
/**
|
||||
* Get the viewport of a view applied to this target
|
||||
*
|
||||
* \param view Target view
|
||||
*
|
||||
* \return Viewport rectangle, expressed in pixels in the current target
|
||||
*
|
||||
*/
|
||||
IntRect viewport(View view);
|
||||
}
|
||||
}
|
149
bindings/d/import/dsfml/graphics/rect.d
Normal file
149
bindings/d/import/dsfml/graphics/rect.d
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.rect;
|
||||
|
||||
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, ...)
|
||||
*/
|
||||
struct Rect(T)
|
||||
{
|
||||
T left; // Left coordinate of the rectangle
|
||||
T top; // Top coordinate of the rectangle
|
||||
T width; // width
|
||||
T height; // height
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the right coordinate of the rectangle
|
||||
*/
|
||||
T right()
|
||||
{
|
||||
return left + width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bottom coordinate of the rectangle
|
||||
*/
|
||||
T bottom()
|
||||
{
|
||||
return top + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 >= left) && (x < right) && (y >= top) && (y < 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 = Rect!(T)())
|
||||
{
|
||||
// Compute overlapping rect
|
||||
auto overlapping = Rect!(T)(
|
||||
max(left, rectangle.left),
|
||||
max(top, rectangle.top),
|
||||
min(right, rectangle.right),
|
||||
min(bottom, rectangle.bottom)
|
||||
);
|
||||
|
||||
// If overlapping rect is valid, then there is intersection
|
||||
if ((overlapping.left < overlapping.right) && (overlapping.top < overlapping.bottom))
|
||||
{
|
||||
overlappingRect = overlapping;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlappingRect = Rect!(T)();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//bool opEquals
|
||||
}
|
||||
|
||||
///Alias
|
||||
alias Rect!(int) IntRect;
|
||||
///ditto
|
||||
alias Rect!(float) FloatRect;
|
316
bindings/d/import/dsfml/graphics/renderimage.d
Normal file
316
bindings/d/import/dsfml/graphics/renderimage.d
Normal file
|
@ -0,0 +1,316 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
|
||||
module dsfml.graphics.renderimage;
|
||||
|
||||
import dsfml.system.common,
|
||||
dsfml.system.exception,
|
||||
dsfml.system.stringutil,
|
||||
dsfml.system.vector;
|
||||
|
||||
import dsfml.graphics.idrawable,
|
||||
dsfml.graphics.image,
|
||||
dsfml.graphics.color,
|
||||
dsfml.graphics.rect,
|
||||
dsfml.graphics.shader,
|
||||
dsfml.graphics.view,
|
||||
dsfml.graphics.irendertarget;
|
||||
|
||||
|
||||
/**
|
||||
* Target for 2D rendering into an image that can be reused in a sprite
|
||||
*/
|
||||
class RenderImage : DSFMLObject, IRenderTarget
|
||||
{
|
||||
private:
|
||||
Image _image = null;
|
||||
View _view = null;
|
||||
View _defaultView = null;
|
||||
|
||||
package:
|
||||
this(SFMLClass ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfRenderImage_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct a new renderimage
|
||||
*
|
||||
* Params:
|
||||
* width = Width of the renderimage
|
||||
* height = Height of the renderimage
|
||||
* depthBuffer = Do you want a depth-buffer attached? (useful only if you're doing 3D OpenGL on the renderimage)
|
||||
*/
|
||||
this(uint width, uint height, bool depthBuffer = false)
|
||||
{
|
||||
super(sfRenderImage_Create(width, height, depthBuffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the contents of the target image
|
||||
*/
|
||||
void display()
|
||||
{
|
||||
sfRenderImage_Display(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw something on a renderimage
|
||||
*
|
||||
* Params:
|
||||
* drawable = object to draw
|
||||
*/
|
||||
void draw(IDrawable drawable)
|
||||
{
|
||||
drawable.render(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Params:
|
||||
* drawable = Object to draw
|
||||
* shader = Shader to use
|
||||
*/
|
||||
void draw(IDrawable drawable, Shader shader)
|
||||
{
|
||||
drawable.renderWithShader(this, shader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the renderimage with the given color
|
||||
*
|
||||
* Params:
|
||||
* color = Fill color
|
||||
*/
|
||||
void clear(Color color)
|
||||
{
|
||||
sfRenderImage_Clear(m_ptr, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point in image coordinates into view coordinates
|
||||
*
|
||||
* Params:
|
||||
* imageX = X coordinate of the point to convert, relative to the image
|
||||
* imageY = Y coordinate of the point to convert, relative to the image
|
||||
* targetView = Target view to convert the point to (pass NULL to use the current view)
|
||||
*
|
||||
* Returns:
|
||||
* Converted point
|
||||
*/
|
||||
Vector2f convertCoords(uint imageX, uint imageY, View targetView = null)
|
||||
{
|
||||
Vector2f vec;
|
||||
sfRenderImage_ConvertCoords(m_ptr, imageX, imageY, &vec.x, &vec.y, targetView is null ? null : targetView.nativePointer);
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the current OpenGL render states and matrices
|
||||
*/
|
||||
void saveGLStates()
|
||||
{
|
||||
sfRenderImage_SaveGLStates(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the previously saved OpenGL render states and matrices
|
||||
*/
|
||||
void restoreGLStates()
|
||||
{
|
||||
sfRenderImage_RestoreGLStates(m_ptr);
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Return the width of the rendering region of a renderimage
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint width()
|
||||
{
|
||||
return sfRenderImage_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of the rendering region of a renderimage
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint height()
|
||||
{
|
||||
return sfRenderImage_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate or deactivate a renderimage as the current target for rendering
|
||||
*
|
||||
* Params:
|
||||
* active = true to activate, false to deactivate
|
||||
* Returns:
|
||||
* true if operation was successful, false otherwise
|
||||
*/
|
||||
bool active(bool activ)
|
||||
{
|
||||
return sfRenderImage_SetActive(m_ptr, activ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current active view of a renderimage
|
||||
*
|
||||
* Params:
|
||||
* view = Pointer to the new view
|
||||
*/
|
||||
void view(View v)
|
||||
{
|
||||
if (_view !is null)
|
||||
{
|
||||
_view.setHandled(false);
|
||||
}
|
||||
|
||||
sfRenderImage_SetView(m_ptr, v.nativePointer);
|
||||
|
||||
_view = v;
|
||||
_view.setHandled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active view rectangle
|
||||
*
|
||||
* Returns:
|
||||
* current view rectangle, in global coordinates
|
||||
*/
|
||||
View view()
|
||||
{
|
||||
if (_view is null)
|
||||
{
|
||||
SFMLClass cView = sfRenderImage_GetView(m_ptr);
|
||||
_view = new View(cView, true);
|
||||
}
|
||||
return _view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default view
|
||||
*
|
||||
* Returns:
|
||||
* default view
|
||||
*/
|
||||
View defaultView()
|
||||
{
|
||||
if (_defaultView is null)
|
||||
{
|
||||
SFMLClass cView = sfRenderImage_GetDefaultView(m_ptr);
|
||||
_defaultView = new View(cView, true);
|
||||
}
|
||||
return _defaultView;
|
||||
}
|
||||
|
||||
|
||||
IntRect viewport(View v = null) // TODO: is there a need to accept other Views than the currently assigned one?
|
||||
{
|
||||
return sfRenderImage_GetViewport(m_ptr, v is null ? _view.nativePointer : v.nativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target image
|
||||
*
|
||||
* Returns:
|
||||
* target image
|
||||
*/
|
||||
Image image()
|
||||
{
|
||||
if (_image is null)
|
||||
{
|
||||
SFMLClass cImage = sfRenderImage_GetImage(m_ptr);
|
||||
_image = new Image(cImage);
|
||||
}
|
||||
return _image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the system supports render images or not
|
||||
*
|
||||
* Returns:
|
||||
* true if the RenderImage class can be used
|
||||
*/
|
||||
bool isAvailable()
|
||||
{
|
||||
return sfRenderImage_IsAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function(uint, uint, bool) sfRenderImage_Create;
|
||||
void function(SFMLClass) sfRenderImage_Destroy;
|
||||
uint function(SFMLClass) sfRenderImage_GetWidth;
|
||||
uint function(SFMLClass) sfRenderImage_GetHeight;
|
||||
bool function(SFMLClass, bool) sfRenderImage_SetActive;
|
||||
void function(SFMLClass) sfRenderImage_Display;
|
||||
|
||||
void function(SFMLClass, void*) sfRenderImage_DrawSprite;
|
||||
void function(SFMLClass, void*) sfRenderImage_DrawShape;
|
||||
void function(SFMLClass, void*) sfRenderImage_DrawText;
|
||||
|
||||
void function(SFMLClass, void*, void*) sfRenderImage_DrawSpriteWithShader;
|
||||
void function(SFMLClass, void*, void*) sfRenderImage_DrawShapeWithShader;
|
||||
void function(SFMLClass, void*, void*) sfRenderImage_DrawTextWithShader;
|
||||
|
||||
void function(SFMLClass, Color) sfRenderImage_Clear;
|
||||
void function(SFMLClass, SFMLClass) sfRenderImage_SetView;
|
||||
SFMLClass function(SFMLClass) sfRenderImage_GetView;
|
||||
SFMLClass function(SFMLClass) sfRenderImage_GetDefaultView;
|
||||
IntRect function(SFMLClass, SFMLClass) sfRenderImage_GetViewport;
|
||||
void function(SFMLClass, uint, uint, float*, float*, SFMLClass) sfRenderImage_ConvertCoords;
|
||||
SFMLClass function(SFMLClass) sfRenderImage_GetImage;
|
||||
bool function() sfRenderImage_IsAvailable;
|
||||
|
||||
// DSFML2
|
||||
void function(SFMLClass) sfRenderImage_SaveGLStates;
|
||||
void function(SFMLClass) sfRenderImage_RestoreGLStates;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-graphics", "sfRenderImage", "Create", "Destroy", "GetWidth", "GetHeight",
|
||||
"SetActive", "Display", "Clear", "SetView", "GetView", "GetDefaultView", "GetViewport", "ConvertCoords",
|
||||
"GetImage", "IsAvailable",
|
||||
// DSFML2
|
||||
"SaveGLStates", "RestoreGLStates"));
|
||||
|
||||
}
|
339
bindings/d/import/dsfml/graphics/renderwindow.d
Normal file
339
bindings/d/import/dsfml/graphics/renderwindow.d
Normal file
|
@ -0,0 +1,339 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.renderwindow;
|
||||
|
||||
import dsfml.graphics.color,
|
||||
dsfml.graphics.sprite,
|
||||
dsfml.graphics.shape,
|
||||
dsfml.graphics.text,
|
||||
dsfml.graphics.rect,
|
||||
dsfml.graphics.shader,
|
||||
dsfml.graphics.view,
|
||||
dsfml.graphics.idrawable,
|
||||
dsfml.graphics.irendertarget;
|
||||
|
||||
import dsfml.window.event,
|
||||
dsfml.window.input,
|
||||
dsfml.window.videomode,
|
||||
dsfml.window.window,
|
||||
dsfml.window.windowhandle;
|
||||
|
||||
import dsfml.system.common,
|
||||
dsfml.system.stringutil,
|
||||
dsfml.system.vector;
|
||||
|
||||
/**
|
||||
* Simple wrapper for Window that allows easy 2D rendering.
|
||||
*/
|
||||
class RenderWindow : Window, IRenderTarget
|
||||
{
|
||||
private:
|
||||
View m_view = null;
|
||||
View m_defaultView = null;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct the window
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(VideoMode mode, string title, Style windowStyle = Style.Default, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
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 = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(WindowHandle handle, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
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 = Context settings (default is default ContextSettings values)
|
||||
*
|
||||
*/
|
||||
override void create(VideoMode mode, string title, Style windowStyle = Style.Default, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
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 = Context settings (default is default ContextSettings values)
|
||||
*
|
||||
*/
|
||||
override void create(WindowHandle handle, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
|
||||
m_ptr = sfRenderWindow_CreateFromHandle(handle, &settings);
|
||||
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a sprite, shape or text on the window with a shader
|
||||
*
|
||||
* Params:
|
||||
* drawable = IDrawable to draw
|
||||
* shader = Shader to use
|
||||
*/
|
||||
void draw(IDrawable drawable, Shader shader)
|
||||
{
|
||||
drawable.renderWithShader(this, shader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a sprite, shape or text
|
||||
*
|
||||
* Params:
|
||||
* drawable = IDrawable to draw
|
||||
*/
|
||||
void draw(IDrawable drawable)
|
||||
{
|
||||
drawable.render(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the screen with the given color.
|
||||
*
|
||||
* Params:
|
||||
* col = Fill color
|
||||
*/
|
||||
void clear(Color col = Color.BLACK)
|
||||
{
|
||||
sfRenderWindow_Clear(m_ptr, col);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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.nativePointer);
|
||||
return vec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the current OpenGL render states and matrices
|
||||
*/
|
||||
void saveGLStates()
|
||||
{
|
||||
sfRenderWindow_SaveGLStates(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the previously saved OpenGL render states and matrices
|
||||
*/
|
||||
void restoreGLStates()
|
||||
{
|
||||
sfRenderWindow_RestoreGLStates(m_ptr);
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* 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 view(View newView)
|
||||
{
|
||||
if (m_view !is null)
|
||||
{
|
||||
m_view.setHandled(false);
|
||||
}
|
||||
|
||||
sfRenderWindow_SetView(m_ptr, newView.nativePointer);
|
||||
|
||||
m_view = newView;
|
||||
m_view.setHandled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current view rectangle
|
||||
*
|
||||
* Returns:
|
||||
* current view rectangle, in global coordinates
|
||||
*/
|
||||
View view()
|
||||
{
|
||||
if (m_view is null)
|
||||
{
|
||||
SFMLClass cView = sfRenderWindow_GetView(m_ptr);
|
||||
m_view = new View(cView, true);
|
||||
}
|
||||
return m_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default view
|
||||
*
|
||||
* Returns:
|
||||
* default view
|
||||
*/
|
||||
View defaultView()
|
||||
{
|
||||
if (m_defaultView is null)
|
||||
{
|
||||
SFMLClass cView = sfRenderWindow_GetDefaultView(m_ptr);
|
||||
m_defaultView = new View(cView, true);
|
||||
}
|
||||
return m_defaultView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the width of the rendering region of a renderwindow
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
override uint width()
|
||||
{
|
||||
return sfRenderWindow_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of the rendering region of a renderwindow
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
override uint height()
|
||||
{
|
||||
return sfRenderWindow_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the viewport of a view applied to this target
|
||||
*
|
||||
* Params:
|
||||
* view = Target view
|
||||
* Returns:
|
||||
* Viewport rectangle, expressed in pixels in the current target
|
||||
*/
|
||||
IntRect viewport(View v = null) // TODO: is there a need to accept other Views than the currently assigned one?
|
||||
{
|
||||
return sfRenderWindow_GetViewport(m_ptr, v is null ? m_view.nativePointer : v.nativePointer);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function(VideoMode, cchar*, Style, ContextSettings*)sfRenderWindow_Create;
|
||||
SFMLClass function(WindowHandle, ContextSettings*) sfRenderWindow_CreateFromHandle;
|
||||
void function(SFMLClass) sfRenderWindow_Destroy;
|
||||
SFMLClass function(SFMLClass) sfRenderWindow_GetInput;
|
||||
bool function(SFMLClass) sfRenderWindow_IsOpened;
|
||||
uint function(SFMLClass) sfRenderWindow_GetWidth;
|
||||
uint function(SFMLClass) sfRenderWindow_GetHeight;
|
||||
|
||||
/*
|
||||
void function(SFMLClass, SFMLClass) sfRenderWindow_DrawSprite;
|
||||
void function(SFMLClass, SFMLClass) sfRenderWindow_DrawShape;
|
||||
void function(SFMLClass, SFMLClass) sfRenderWindow_DrawText;
|
||||
|
||||
void function(SFMLClass, SFMLClass, SFMLClass) sfRenderWindow_DrawSpriteWithShader;
|
||||
void function(SFMLClass, SFMLClass, SFMLClass) sfRenderWindow_DrawShapeWithShader;
|
||||
void function(SFMLClass, SFMLClass, SFMLClass) sfRenderWindow_DrawTextWithShader;
|
||||
*/
|
||||
|
||||
SFMLClass function(SFMLClass) sfRenderWindow_Capture;
|
||||
void function(SFMLClass, Color) sfRenderWindow_Clear;
|
||||
void function(SFMLClass, SFMLClass) sfRenderWindow_SetView;
|
||||
SFMLClass function(SFMLClass) sfRenderWindow_GetView;
|
||||
SFMLClass function(SFMLClass) sfRenderWindow_GetDefaultView;
|
||||
void function(SFMLClass, uint, uint, float*, float*, SFMLClass) sfRenderWindow_ConvertCoords;
|
||||
|
||||
// DSFML2
|
||||
void function(SFMLClass) sfRenderWindow_SaveGLStates;
|
||||
void function(SFMLClass) sfRenderWindow_RestoreGLStates;
|
||||
IntRect function(SFMLClass, SFMLClass) sfRenderWindow_GetViewport;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-graphics", "sfRenderWindow", "Create", "CreateFromHandle",
|
||||
"Destroy", "GetInput", "Clear", "SetView", "GetView", "GetDefaultView", "ConvertCoords",
|
||||
"GetWidth", "GetHeight",
|
||||
// DSFML2
|
||||
"SaveGLStates", "RestoreGLStates", "GetViewport"));
|
||||
|
||||
|
||||
static ~this()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
177
bindings/d/import/dsfml/graphics/shader.d
Normal file
177
bindings/d/import/dsfml/graphics/shader.d
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.shader;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Shader 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 Shader : DSFMLObject
|
||||
{
|
||||
private:
|
||||
Image m_texture;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* construct the effect
|
||||
*
|
||||
* Params:
|
||||
* effect = Path of a file or string containing the effect.
|
||||
* type = type of the effect (default is FROMFILE)
|
||||
*/
|
||||
this(string effect, LoadingType type = LoadingType.FROMFILE)
|
||||
{
|
||||
if (effect is null || effect.length == 0)
|
||||
throw new LoadingException("LoadingException : Effect is invalid.");
|
||||
|
||||
if (type == LoadingType.FROMFILE)
|
||||
super(sfShader_CreateFromFile(toStringz(effect)));
|
||||
else
|
||||
super(sfShader_CreateFromMemory(toStringz(effect)));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfShader_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change parameters of the effect
|
||||
*
|
||||
* Params:
|
||||
* name = Parameter name in the effect
|
||||
*/
|
||||
void setParameter(string name, float x)
|
||||
{
|
||||
sfShader_SetParameter1(m_ptr, toStringz(name), x);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y)
|
||||
{
|
||||
sfShader_SetParameter2(m_ptr, toStringz(name), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y, float z)
|
||||
{
|
||||
sfShader_SetParameter3(m_ptr, toStringz(name), x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y, float z, float w)
|
||||
{
|
||||
sfShader_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(string name, Image texture)
|
||||
{
|
||||
m_texture = texture;
|
||||
sfShader_SetTexture(m_ptr, toStringz(name), texture is null ? null : texture.nativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether or not the system supports shaders
|
||||
*
|
||||
* Returns:
|
||||
* True if the system can use shaders
|
||||
*/
|
||||
static bool isAvailable()
|
||||
{
|
||||
return cast(bool)sfShader_IsAvailable();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function(cchar*) sfShader_CreateFromFile;
|
||||
SFMLClass function(cchar*) sfShader_CreateFromMemory;
|
||||
void function(SFMLClass) sfShader_Destroy;
|
||||
void function(SFMLClass, cchar*, float) sfShader_SetParameter1;
|
||||
void function(SFMLClass, cchar*, float, float) sfShader_SetParameter2;
|
||||
void function(SFMLClass, cchar*, float, float, float) sfShader_SetParameter3;
|
||||
void function(SFMLClass, cchar*, float, float, float, float) sfShader_SetParameter4;
|
||||
void function(SFMLClass, cchar*, SFMLClass) sfShader_SetTexture;
|
||||
int function() sfShader_IsAvailable;
|
||||
void function(SFMLClass) sfShader_Bind;
|
||||
void function(SFMLClass) sfShader_Unbind;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
mixin(loadFromSharedLib("sfShader_CreateFromFile"));
|
||||
mixin(loadFromSharedLib("sfShader_CreateFromMemory"));
|
||||
mixin(loadFromSharedLib("sfShader_Destroy"));
|
||||
mixin(loadFromSharedLib("sfShader_SetParameter1"));
|
||||
mixin(loadFromSharedLib("sfShader_SetParameter2"));
|
||||
mixin(loadFromSharedLib("sfShader_SetParameter3"));
|
||||
mixin(loadFromSharedLib("sfShader_SetParameter4"));
|
||||
mixin(loadFromSharedLib("sfShader_SetTexture"));
|
||||
mixin(loadFromSharedLib("sfShader_IsAvailable"));
|
||||
mixin(loadFromSharedLib("sfShader_Bind"));
|
||||
mixin(loadFromSharedLib("sfShader_Unbind"));
|
||||
}
|
||||
}
|
306
bindings/d/import/dsfml/graphics/shape.d
Normal file
306
bindings/d/import/dsfml/graphics/shape.d
Normal file
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.shape;
|
||||
|
||||
import dsfml.system.vector;
|
||||
|
||||
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")
|
||||
{
|
||||
private:
|
||||
this (SFMLClass ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
public:
|
||||
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);
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* 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 outlineWidth(float width)
|
||||
{
|
||||
sfShape_SetOutlineWidth(m_ptr, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the shape outline
|
||||
*
|
||||
* Returns:
|
||||
* Current outline width
|
||||
*
|
||||
*/
|
||||
float outlineWidth()
|
||||
{
|
||||
return sfShape_GetOutlineWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of points composing a shape
|
||||
*
|
||||
* Returns:
|
||||
* Total number of points
|
||||
*/
|
||||
uint pointsCount()
|
||||
{
|
||||
return sfShape_GetPointsCount(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:
|
||||
* left, top = Top-left corner of the rectangle
|
||||
* width, height = Size of the rectangle
|
||||
* 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 left, float top, float width, float height, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
return new Shape(sfShape_CreateRectangle(left, top, width, height, 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:
|
||||
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function(float, float, float, float, float, Color, float, Color) sfShape_CreateLine;
|
||||
SFMLClass function(float, float, float, float, Color, float, Color) sfShape_CreateRectangle;
|
||||
SFMLClass function(float, float, float, Color, float, Color) sfShape_CreateCircle;
|
||||
void function(SFMLClass, float, float, Color, Color) sfShape_AddPoint;
|
||||
void function(SFMLClass, int) sfShape_EnableFill;
|
||||
void function(SFMLClass, int) sfShape_EnableOutline;
|
||||
void function(SFMLClass, float Width) sfShape_SetOutlineWidth;
|
||||
float function(SFMLClass) sfShape_GetOutlineWidth;
|
||||
uint function(SFMLClass) sfShape_GetPointsCount;
|
||||
void function(SFMLClass, uint Index, float* X, float* Y) sfShape_GetPointPosition;
|
||||
void function(SFMLClass, uint Index, float X, float Y) sfShape_SetPointPosition;
|
||||
Color function(SFMLClass, uint index) sfShape_GetPointColor;
|
||||
void function(SFMLClass, uint index, Color color) sfShape_SetPointColor;
|
||||
Color function(SFMLClass, uint index) sfShape_GetPointOutlineColor;
|
||||
void function(SFMLClass, uint index, Color color) sfShape_SetPointOutlineColor;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-graphics", "sfShape",
|
||||
"CreateLine", "CreateRectangle", "CreateCircle", "AddPoint", "EnableFill", "EnableOutline", "SetOutlineWidth", "GetOutlineWidth",
|
||||
"GetPointsCount", "GetPointPosition", "SetPointPosition", "GetPointColor", "SetPointColor", "GetPointOutlineColor",
|
||||
"SetPointOutlineColor"));
|
||||
}
|
238
bindings/d/import/dsfml/graphics/sprite.d
Normal file
238
bindings/d/import/dsfml/graphics/sprite.d
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.sprite;
|
||||
|
||||
import dsfml.graphics.blendmode;
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.drawableimpl;
|
||||
import dsfml.graphics.image;
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.vector;
|
||||
|
||||
/**
|
||||
* Sprite defines a sprite : texture, transformations,
|
||||
* color, and draw on screen
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
*/
|
||||
class Sprite : DrawableImpl!("sfSprite")
|
||||
{
|
||||
private:
|
||||
Image m_image; //< Image used to draw the sprite
|
||||
IntRect m_subRect; //< Sub-rectangle of source image to assign to the sprite
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* rot = Orientation, in degrees (0 by default)
|
||||
* col = Color of the sprite (white by default)
|
||||
*/
|
||||
this(Image img, float left = 0.f, float top = 0.f, float scalex = 1.f, float scaley = 1.f, float rot = 0.f, Color col = Color.WHITE)
|
||||
{
|
||||
super();
|
||||
m_image = img;
|
||||
sfSprite_SetImage(m_ptr, img.nativePointer, true);
|
||||
x = left;
|
||||
y = top;
|
||||
scaleX = scalex;
|
||||
scaleY = scaley;
|
||||
rotation = rot;
|
||||
color = col;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image of the sprite
|
||||
*
|
||||
* Params:
|
||||
* img = New image
|
||||
* adjustToNewSize = adjust sprite subrect to new image size
|
||||
*/
|
||||
void setImage(Image img, bool adjustToNewSize = false)
|
||||
{
|
||||
assert(img !is null, "Trying to set a null image.");
|
||||
sfSprite_SetImage(m_ptr, img.nativePointer, adjustToNewSize);
|
||||
m_image = img;
|
||||
}
|
||||
|
||||
@property void image(Image img)
|
||||
{
|
||||
setImage(img, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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) const
|
||||
{
|
||||
return sfSprite_GetPixel(m_ptr, x, y);
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Set the sub-rectangle of a sprite inside the source image.
|
||||
*
|
||||
* Params:
|
||||
* rect = New sub-rectangle
|
||||
*/
|
||||
void subRect(IntRect rect)
|
||||
{
|
||||
sfSprite_SetSubRect(m_ptr, rect);
|
||||
m_subRect = rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source image of the sprite
|
||||
*
|
||||
* Returns:
|
||||
* Pointer to the image (can be NULL)
|
||||
*/
|
||||
Image image()
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sub-rectangle of the sprite inside the source image
|
||||
*
|
||||
* Returns:
|
||||
* Sub-rectangle
|
||||
*/
|
||||
IntRect subRect()
|
||||
{
|
||||
if (m_subRect == IntRect())
|
||||
m_subRect = sfSprite_GetSubRect(m_ptr);
|
||||
//m_subRect = IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
|
||||
|
||||
return m_subRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sprite size
|
||||
*
|
||||
* Returns:
|
||||
* Size of the sprite
|
||||
*/
|
||||
Vector2f size() const
|
||||
{
|
||||
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static extern(C)
|
||||
{
|
||||
void function(SFMLClass, SFMLClass, bool) sfSprite_SetImage;
|
||||
void function(SFMLClass, IntRect) sfSprite_SetSubRect;
|
||||
void function(SFMLClass, float, float) sfSprite_Resize;
|
||||
void function(SFMLClass, int) sfSprite_FlipX;
|
||||
void function(SFMLClass, int) sfSprite_FlipY;
|
||||
SFMLClass function(SFMLClass) sfSprite_GetImage;
|
||||
IntRect function(SFMLClass) sfSprite_GetSubRect;
|
||||
float function(SFMLClass) sfSprite_GetWidth;
|
||||
float function(SFMLClass) sfSprite_GetHeight;
|
||||
Color function(SFMLClass, uint, uint) sfSprite_GetPixel;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-graphics", "sfSprite",
|
||||
"SetImage", "SetSubRect", "Resize", "FlipX", "FlipY", "GetImage", "GetSubRect", "GetWidth", "GetHeight", "GetPixel"));
|
||||
}
|
277
bindings/d/import/dsfml/graphics/text.d
Normal file
277
bindings/d/import/dsfml/graphics/text.d
Normal file
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.text;
|
||||
|
||||
import dsfml.graphics.blendmode;
|
||||
import dsfml.graphics.color;
|
||||
import dsfml.graphics.font;
|
||||
import dsfml.graphics.drawableimpl;
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.stringutil;
|
||||
import dsfml.system.vector;
|
||||
|
||||
|
||||
/**
|
||||
* Enumerate the text 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
|
||||
}
|
||||
|
||||
/**
|
||||
* Text 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 :
|
||||
* ---------------------------------------------------------------
|
||||
* Text s = new Text("Hello"c);
|
||||
* //this(string, Font, float)
|
||||
* s = new Text("Hello"d);
|
||||
* //this(dstring, Font, float)
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
*/
|
||||
class Text : DrawableImpl!("sfText")
|
||||
{
|
||||
private:
|
||||
Font m_font;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct the string from a text
|
||||
*
|
||||
* Prefixs string litterals with c
|
||||
*
|
||||
* Params:
|
||||
* s = Text assigned to the string
|
||||
* f = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(string s, Font f = Font.getDefaultFont(), uint size = 30)
|
||||
{
|
||||
super();
|
||||
|
||||
font = f;
|
||||
text = s;
|
||||
characterSize = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the string from a unicode text
|
||||
*
|
||||
* Prefixs string litterals with d
|
||||
*
|
||||
* Params:
|
||||
* s = Text assigned to the string
|
||||
* f = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(dstring s, Font f = Font.getDefaultFont(), uint size = 30)
|
||||
{
|
||||
super();
|
||||
|
||||
font = f;
|
||||
text = s;
|
||||
characterSize = size;
|
||||
}
|
||||
|
||||
@property
|
||||
{
|
||||
/**
|
||||
* Set the text (from a multibyte string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void text(string text)
|
||||
{
|
||||
sfText_SetString(m_ptr, toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text (from a unicode string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void text(dstring text)
|
||||
{
|
||||
sfText_SetUnicodeString(m_ptr, toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a multibyte string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
string text()
|
||||
{
|
||||
return fromStringz(sfText_GetString(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font of the string
|
||||
*
|
||||
* Params:
|
||||
* f = Font
|
||||
*/
|
||||
void font(Font f)
|
||||
{
|
||||
m_font = f;
|
||||
sfText_SetFont(m_ptr, f.nativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the string
|
||||
*
|
||||
* Params:
|
||||
* size = New size, in pixels
|
||||
*/
|
||||
void characterSize(uint size)
|
||||
{
|
||||
sfText_SetCharacterSize(m_ptr, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style of the text
|
||||
* The default style is Regular
|
||||
*
|
||||
* Params:
|
||||
* TextStyle = New text style, (combination of Style enum values)
|
||||
*
|
||||
*/
|
||||
void style(TextStyle tstyle)
|
||||
{
|
||||
sfText_SetStyle(m_ptr, tstyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a unicode string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
dstring unicodeText()
|
||||
{
|
||||
return fromStringz(sfText_GetUnicodeString(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the font used by the string
|
||||
*
|
||||
* Returns:
|
||||
* Font name
|
||||
*/
|
||||
Font font()
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the characters
|
||||
*
|
||||
* Returns:
|
||||
* Size of the characters
|
||||
*/
|
||||
uint characterSize()
|
||||
{
|
||||
return sfText_GetCharacterSize(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current font style
|
||||
*
|
||||
* Returns:
|
||||
* Font style
|
||||
*/
|
||||
TextStyle style()
|
||||
{
|
||||
return sfText_GetStyle(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string rectangle on screen
|
||||
*
|
||||
* Returns:
|
||||
* Rectangle contaning the string in screen coordinates
|
||||
*/
|
||||
FloatRect rect()
|
||||
{
|
||||
return sfText_GetRect(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the visual position of the Index-th character of the string,
|
||||
* in coordinates relative to the string
|
||||
* (note : translation, center, rotation and scale are not applied)
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the character
|
||||
*
|
||||
* Returns:
|
||||
* Position of the Index-th character (end of string of Index is out of range)
|
||||
*/
|
||||
Vector2f getCharacterPos(size_t index)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfText_GetCharacterPos(m_ptr, index, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static extern(C)
|
||||
{
|
||||
void function(SFMLClass, cchar*) sfText_SetString;
|
||||
void function(SFMLClass, cdchar*) sfText_SetUnicodeString;
|
||||
void function(SFMLClass, SFMLClass) sfText_SetFont;
|
||||
void function(SFMLClass, uint) sfText_SetCharacterSize;
|
||||
void function(SFMLClass, TextStyle) sfText_SetStyle;
|
||||
idchar* function(SFMLClass) sfText_GetUnicodeString;
|
||||
ichar* function(SFMLClass) sfText_GetString;
|
||||
SFMLClass function(SFMLClass) sfText_GetFont;
|
||||
uint function(SFMLClass) sfText_GetCharacterSize;
|
||||
TextStyle function (SFMLClass) sfText_GetStyle;
|
||||
void function(SFMLClass, size_t, float*, float*) sfText_GetCharacterPos;
|
||||
FloatRect function(SFMLClass) sfText_GetRect;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-graphics", "sfText",
|
||||
"SetString", "SetUnicodeString", "SetFont", "SetCharacterSize", "SetStyle", "GetUnicodeString", "GetString", "GetFont",
|
||||
"GetCharacterSize", "GetStyle", "GetCharacterPos", "GetRect"));
|
||||
}
|
347
bindings/d/import/dsfml/graphics/view.d
Normal file
347
bindings/d/import/dsfml/graphics/view.d
Normal file
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.view;
|
||||
|
||||
import dsfml.graphics.rect;
|
||||
|
||||
import dsfml.system.common,
|
||||
dsfml.system.vector;
|
||||
|
||||
/**
|
||||
* This class defines a view (position, size and zoom) ;
|
||||
* you can consider it as a camera
|
||||
*/
|
||||
class View : DSFMLObject
|
||||
{
|
||||
private:
|
||||
FloatRect _rect; // a view defines a source area of the scene to display, and a destination area into the rendertarget where to map the source area
|
||||
FloatRect _viewport; // the viewport is the destination area in the rendertarget
|
||||
bool m_isModified = true;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Default view (1000 x 1000)
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfView_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* center = center of the view
|
||||
* size = size of the view (width, height)
|
||||
*/
|
||||
this(Vector2f center, Vector2f size)
|
||||
{
|
||||
super(sfView_CreateFromRect(FloatRect(center.x - size.x / 2, center.y - size.y / 2, size.x, size.y) ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* rect = Rectangle defining the position and size of the view
|
||||
*/
|
||||
this(FloatRect rect)
|
||||
{
|
||||
super(sfView_CreateFromRect(rect));
|
||||
}
|
||||
|
||||
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 size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
* height = New height
|
||||
*/
|
||||
void setSize(float width, float height)
|
||||
{
|
||||
sfView_SetSize(m_ptr, width, height);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* size = New size
|
||||
*/
|
||||
void setSize(Vector2f size)
|
||||
{
|
||||
sfView_SetSize(m_ptr, size.x, size.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the view from a rectangle
|
||||
*
|
||||
* Params:
|
||||
* viewport : Rectangle defining the position and size of the view
|
||||
*/
|
||||
void setViewport(FloatRect viewport)
|
||||
{
|
||||
sfView_SetViewport(m_ptr, viewport);
|
||||
_viewport = viewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 size of the view
|
||||
*
|
||||
* Returns:
|
||||
* size of the view
|
||||
*/
|
||||
Vector2f getSize()
|
||||
{
|
||||
return Vector2f(sfView_GetWidth(m_ptr), sfView_GetHeight(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the view
|
||||
*
|
||||
* Returns:
|
||||
* width of the view
|
||||
*/
|
||||
float getWidth()
|
||||
{
|
||||
return sfView_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the view
|
||||
*
|
||||
* Returns:
|
||||
* height of the view
|
||||
*/
|
||||
float getHeight()
|
||||
{
|
||||
return sfView_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounding retangle of the view
|
||||
*/
|
||||
FloatRect getViewport()
|
||||
{
|
||||
if (m_isModified)
|
||||
{
|
||||
m_isModified = false;
|
||||
_viewport = sfView_GetViewport(m_ptr);
|
||||
}
|
||||
return _viewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset to move the view, on X axis
|
||||
* offsetY = Offset to move the view, on Y axis
|
||||
*/
|
||||
View move(float offsetX, float offsetY)
|
||||
{
|
||||
sfView_Move(m_ptr, offsetX, offsetY);
|
||||
m_isModified = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offset = offsetto move the view
|
||||
*/
|
||||
View move(Vector2f offset)
|
||||
{
|
||||
sfView_Move(m_ptr, offset.x, offset.y);
|
||||
m_isModified = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the view rectangle to simulate a zoom / unzoom effect
|
||||
*
|
||||
* Params:
|
||||
* factor = Zoom factor to apply, relative to the current zoom
|
||||
*/
|
||||
View zoom(float factor)
|
||||
{
|
||||
sfView_Zoom(m_ptr, factor);
|
||||
m_isModified = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the view relatively to its current orientation.
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle to rotate, in degree
|
||||
*/
|
||||
View rotate(float angle)
|
||||
{
|
||||
sfView_Rotate(m_ptr, angle);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the orientation of the view
|
||||
* The default rotation of a view is 0 degree
|
||||
*
|
||||
* Params:
|
||||
* angle = New angle, in degrees
|
||||
*/
|
||||
View setRotation(float angle)
|
||||
{
|
||||
sfView_SetRotation(m_ptr, angle);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current orientation of the view
|
||||
*
|
||||
* Returns:
|
||||
* Rotation angle of the view, in degrees
|
||||
*/
|
||||
float getRotation()
|
||||
{
|
||||
return sfView_GetRotation(m_ptr);
|
||||
}
|
||||
|
||||
void reset(FloatRect rect)
|
||||
{
|
||||
sfView_Reset(m_ptr, rect);
|
||||
_rect = rect;
|
||||
}
|
||||
package:
|
||||
|
||||
this(SFMLClass ptr, bool preventDelete)
|
||||
{
|
||||
super(ptr, preventDelete);
|
||||
}
|
||||
|
||||
private:
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function() sfView_Create;
|
||||
SFMLClass function(FloatRect) sfView_CreateFromRect;
|
||||
void function(SFMLClass) sfView_Destroy;
|
||||
void function(SFMLClass, float, float) sfView_SetCenter;
|
||||
void function(SFMLClass, float, float) sfView_SetSize;
|
||||
void function(SFMLClass, FloatRect) sfView_SetViewport;
|
||||
float function(SFMLClass) sfView_GetCenterX;
|
||||
float function(SFMLClass) sfView_GetCenterY;
|
||||
float function(SFMLClass) sfView_GetWidth;
|
||||
float function(SFMLClass) sfView_GetHeight;
|
||||
FloatRect function(SFMLClass) sfView_GetViewport;
|
||||
void function(SFMLClass, float, float) sfView_Move;
|
||||
void function(SFMLClass, float) sfView_Zoom;
|
||||
|
||||
// DSFML2
|
||||
void function(SFMLClass, float) sfView_SetRotation;
|
||||
float function(SFMLClass) sfView_GetRotation;
|
||||
void function(SFMLClass, float) sfView_Rotate;
|
||||
void function(SFMLClass, FloatRect) sfView_Reset;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
mixin(loadFromSharedLib("sfView_Create"));
|
||||
mixin(loadFromSharedLib("sfView_CreateFromRect"));
|
||||
mixin(loadFromSharedLib("sfView_Destroy"));
|
||||
mixin(loadFromSharedLib("sfView_SetCenter"));
|
||||
mixin(loadFromSharedLib("sfView_SetSize"));
|
||||
mixin(loadFromSharedLib("sfView_SetViewport"));
|
||||
mixin(loadFromSharedLib("sfView_GetCenterX"));
|
||||
mixin(loadFromSharedLib("sfView_GetCenterY"));
|
||||
mixin(loadFromSharedLib("sfView_GetWidth"));
|
||||
mixin(loadFromSharedLib("sfView_GetHeight"));
|
||||
mixin(loadFromSharedLib("sfView_GetViewport"));
|
||||
mixin(loadFromSharedLib("sfView_Move"));
|
||||
mixin(loadFromSharedLib("sfView_Zoom"));
|
||||
|
||||
// DSFML2
|
||||
mixin(loadFromSharedLib("sfView_SetRotation"));
|
||||
mixin(loadFromSharedLib("sfView_GetRotation"));
|
||||
mixin(loadFromSharedLib("sfView_Rotate"));
|
||||
mixin(loadFromSharedLib("sfView_Reset"));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue