2009-01-29 00:18:34 +08:00
|
|
|
/*
|
2010-03-14 06:44:26 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
module dsfml.graphics.shape;
|
|
|
|
|
2010-07-24 08:30:30 +08:00
|
|
|
import dsfml.system.vector;
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
import dsfml.graphics.blendmode;
|
|
|
|
import dsfml.graphics.color;
|
|
|
|
import dsfml.graphics.drawableimpl;
|
|
|
|
|
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Shape defines a drawable convex shape ; it also defines
|
|
|
|
* helper functions to draw simple shapes like
|
|
|
|
* lines, rectangles, circles, etc.
|
|
|
|
*/
|
2010-01-12 03:28:34 +08:00
|
|
|
class Shape : DrawableImpl!("sfShape")
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
2010-01-08 06:00:45 +08:00
|
|
|
private:
|
2010-03-16 07:35:53 +08:00
|
|
|
this (SFMLClass ptr)
|
2010-01-08 06:00:45 +08:00
|
|
|
{
|
|
|
|
super(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2010-01-07 04:37:29 +08:00
|
|
|
this()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* 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)
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void addPoint(float x, float y, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
|
|
|
{
|
|
|
|
sfShape_AddPoint(m_ptr, x, y, col, outlineCol);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* 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)
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
|
|
|
{
|
|
|
|
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
|
|
|
|
}
|
2010-03-14 06:44:26 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
{
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Enable or disable filling the shape.
|
|
|
|
* Fill is enabled by default.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* enable = True to enable, false to disable
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void enableFill(bool enable)
|
|
|
|
{
|
|
|
|
sfShape_EnableFill(m_ptr, enable);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Enable or disable drawing a shape outline.
|
|
|
|
* Outline is enabled by default
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* enable = True to enable, false to disable
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void enableOutline(bool enable)
|
|
|
|
{
|
|
|
|
sfShape_EnableOutline(m_ptr, enable);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Change the width of a shape outline
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* width = New width
|
|
|
|
*/
|
|
|
|
void outlineWidth(float width)
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
|
|
|
sfShape_SetOutlineWidth(m_ptr, width);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Get the width of the shape outline
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Current outline width
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
float outlineWidth()
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
|
|
|
return sfShape_GetOutlineWidth(m_ptr);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Get the number of points composing a shape
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Total number of points
|
|
|
|
*/
|
|
|
|
uint pointsCount()
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
2010-02-18 03:21:18 +08:00
|
|
|
return sfShape_GetPointsCount(m_ptr);
|
2010-01-07 04:37:29 +08:00
|
|
|
}
|
2010-03-14 06:44:26 +08:00
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Get a point of the shape
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* index = Index of the point
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* position of the point
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
Vector2f getPointPosition(uint index)
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
sfShape_GetPointPosition(m_ptr, index, &x, &y);
|
|
|
|
return Vector2f(x, y);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Set the position of a shape point
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* index = Index of the point
|
|
|
|
* position = New position of the point
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void setPointPosition(uint index, Vector2f position)
|
|
|
|
{
|
|
|
|
sfShape_SetPointPosition(m_ptr, index, position.x, position.y);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Get the color of a shape's point
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* index = Index of the point
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Color of the point
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
Color getPointColor(uint index)
|
|
|
|
{
|
|
|
|
return sfShape_GetPointColor(m_ptr, index);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Set the color of a shape's point
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* index = Index of the point
|
|
|
|
* color = new color of the point
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void setPointColor(uint index, Color color)
|
|
|
|
{
|
|
|
|
sfShape_SetPointColor(m_ptr, index, color);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Get the outline color of a shape's point
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* index = Index of the point
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Color of the outline
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
Color getPointOutlineColor(uint index)
|
|
|
|
{
|
|
|
|
return sfShape_GetPointOutlineColor(m_ptr, index);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Set the outline color of a shape's point
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* index = Index of the point
|
|
|
|
* color = new color of the point
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
void setPointOutlineColor(uint index, Color color)
|
|
|
|
{
|
|
|
|
sfShape_SetPointOutlineColor(m_ptr, index, color);
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* 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
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
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));
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* Create a shape made of a single rectangle
|
|
|
|
*
|
|
|
|
* Params:
|
2010-04-21 04:50:15 +08:00
|
|
|
* left, top = Top-left corner of the rectangle
|
|
|
|
* width, height = Size of the rectangle
|
2010-03-14 06:44:26 +08:00
|
|
|
* 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
|
|
|
|
*/
|
2010-04-21 04:50:15 +08:00
|
|
|
static Shape rectangle(float left, float top, float width, float height, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
2010-04-21 04:50:15 +08:00
|
|
|
return new Shape(sfShape_CreateRectangle(left, top, width, height, col, outline, outlineCol));
|
2010-01-07 04:37:29 +08:00
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
/**
|
2010-03-14 06:44:26 +08:00
|
|
|
* 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
|
|
|
|
*/
|
2010-01-07 04:37:29 +08:00
|
|
|
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));
|
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
private:
|
2010-01-07 04:37:29 +08:00
|
|
|
|
2010-03-14 06:44:26 +08:00
|
|
|
static extern(C)
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
2010-03-16 07:35:53 +08:00
|
|
|
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;
|
2010-01-07 04:37:29 +08:00
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-03-14 06:44:26 +08:00
|
|
|
mixin(loadFromSharedLib2("csfml-graphics", "sfShape",
|
|
|
|
"CreateLine", "CreateRectangle", "CreateCircle", "AddPoint", "EnableFill", "EnableOutline", "SetOutlineWidth", "GetOutlineWidth",
|
|
|
|
"GetPointsCount", "GetPointPosition", "SetPointPosition", "GetPointColor", "SetPointColor", "GetPointOutlineColor",
|
|
|
|
"SetPointOutlineColor"));
|
|
|
|
}
|