diff --git a/DSFML/import/dsfml/graphics/common.d b/DSFML/import/dsfml/graphics/common.d index 692cf925f..44f06f1b2 100644 --- a/DSFML/import/dsfml/graphics/common.d +++ b/DSFML/import/dsfml/graphics/common.d @@ -52,6 +52,7 @@ package extern (C) void* function(void*) sfRenderWindow_GetInput; // bool function(void*) sfRenderWindow_IsOpened; +/* void function(void*, void*) sfRenderWindow_DrawSprite; void function(void*, void*) sfRenderWindow_DrawShape; void function(void*, void*) sfRenderWindow_DrawText; @@ -59,13 +60,18 @@ package extern (C) void function(void*, void*, void*) sfRenderWindow_DrawSpriteWithShader; void function(void*, void*, void*) sfRenderWindow_DrawShapeWithShader; void function(void*, void*, void*) sfRenderWindow_DrawTextWithShader; - +*/ + void* function(void*) sfRenderWindow_Capture; void function(void*, Color) sfRenderWindow_Clear; void function(void*, void*) sfRenderWindow_SetView; void* function(void*) sfRenderWindow_GetView; void* function (void*) sfRenderWindow_GetDefaultView; void function(void*, uint, uint, float*, float*, void*) sfRenderWindow_ConvertCoords; + + // DSFML2 + + void function(void*) sfRenderWindow_Flush; // sfShader void* function(cchar*) sfShader_CreateFromFile; @@ -82,22 +88,24 @@ package extern (C) // sfView void* function() sfView_Create; - void* function(sfFloatRect) sfView_CreateFromRect; + void* function(FloatRect) sfView_CreateFromRect; void function(void*) sfView_Destroy; void function(void*, float, float) sfView_SetCenter; void function(void*, float, float) sfView_SetSize; - void function(void*, sfFloatRect) sfView_SetViewport; + void function(void*, FloatRect) sfView_SetViewport; float function(void*) sfView_GetCenterX; float function(void*) sfView_GetCenterY; float function(void*) sfView_GetWidth; float function(void*) sfView_GetHeight; - sfFloatRect function(void*) sfView_GetViewport; + FloatRect function(void*) sfView_GetViewport; void function(void*, float, float) sfView_Move; void function(void*, float) sfView_Zoom; + // DSFML2 void function(void*, float) sfView_SetRotation; float function(void*) sfView_GetRotation; void function(void*, float) sfView_Rotate; + void function(void*, FloatRect) sfView_Reset; } static this() @@ -120,6 +128,7 @@ else mixin(loadFromSharedLib("sfRenderWindow_Destroy")); mixin(loadFromSharedLib("sfRenderWindow_GetInput")); +/* mixin(loadFromSharedLib("sfRenderWindow_DrawSprite")); mixin(loadFromSharedLib("sfRenderWindow_DrawShape")); mixin(loadFromSharedLib("sfRenderWindow_DrawText")); @@ -127,12 +136,16 @@ else mixin(loadFromSharedLib("sfRenderWindow_DrawSpriteWithShader")); mixin(loadFromSharedLib("sfRenderWindow_DrawShapeWithShader")); mixin(loadFromSharedLib("sfRenderWindow_DrawTextWithShader")); - +*/ + mixin(loadFromSharedLib("sfRenderWindow_Clear")); mixin(loadFromSharedLib("sfRenderWindow_SetView")); mixin(loadFromSharedLib("sfRenderWindow_GetView")); mixin(loadFromSharedLib("sfRenderWindow_GetDefaultView")); mixin(loadFromSharedLib("sfRenderWindow_ConvertCoords")); + + // DSFML2 + mixin(loadFromSharedLib("sfRenderWindow_Flush")); // sfShader mixin(loadFromSharedLib("sfShader_CreateFromFile")); @@ -162,7 +175,9 @@ else 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")); } \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/drawableimpl.d b/DSFML/import/dsfml/graphics/drawableimpl.d index 1d3789a5f..6dcbcadc9 100644 --- a/DSFML/import/dsfml/graphics/drawableimpl.d +++ b/DSFML/import/dsfml/graphics/drawableimpl.d @@ -29,11 +29,12 @@ module dsfml.graphics.drawableimpl; public import dsfml.system.common; import dsfml.system.vector2; -import dsfml.graphics.idrawable; -import dsfml.graphics.color; -import dsfml.graphics.blendmode; -import dsfml.graphics.renderwindow; -import dsfml.graphics.shader; +import dsfml.graphics.idrawable, + dsfml.graphics.color, + dsfml.graphics.blendmode, + dsfml.graphics.renderwindow, + dsfml.graphics.renderimage, + dsfml.graphics.shader; package { @@ -202,7 +203,7 @@ public: void render(RenderWindow window) { - sfRenderWindow_DrawThis(window.getNativePointer, m_ptr); + sfRenderWindow_DrawThis(window.getNativePointer(), m_ptr); } void renderWithShader(RenderWindow window, Shader shader) @@ -210,6 +211,16 @@ public: sfRenderWindow_DrawThisWithShader(window.getNativePointer, m_ptr, shader.getNativePointer); } + void render(RenderImage image) + { + sfRenderImage_DrawThis(image.getNativePointer(), m_ptr); + } + + void renderWithShader(RenderImage image, Shader shader) + { + sfRenderImage_DrawThisWithShader(image.getNativePointer, m_ptr, shader.getNativePointer); + } + override void dispose() { sfDrawable_Destroy(m_ptr); @@ -248,6 +259,8 @@ private: typedef void function(void*, void*) pf_sfRenderWindow_DrawThis; typedef void function(void*, void*, void*) pf_sfRenderWindow_DrawThisWithShader; + typedef void function(void*, void*) pf_sfRenderImage_DrawThis; + typedef void function(void*, void*, void*) pf_sfRenderImage_DrawThisWithShader; static pf_sfDrawable_Create sfDrawable_Create; static pf_sfDrawable_Destroy sfDrawable_Destroy; @@ -278,6 +291,8 @@ private: static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis; static pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader; + static pf_sfRenderImage_DrawThis sfRenderImage_DrawThis; + static pf_sfRenderImage_DrawThisWithShader sfRenderImage_DrawThisWithShader; } static this() @@ -300,34 +315,36 @@ private: string symbol = "sfShape"; } - sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create"); - sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy"); - sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX"); - sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY"); - sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition"); - sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX"); - sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY"); - sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale"); - sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation"); - sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin"); - sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor"); - sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode"); - sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX"); - sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY"); - sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX"); - sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(symbol ~ "_GetScaleX"); - sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation"); - sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX"); - sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY"); - sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor"); - sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode"); - sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move"); - sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale"); - sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate"); - sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal"); - sfDrawable_TransformToGlobal = cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal"); + sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create"); + sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy"); + sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX"); + sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY"); + sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition"); + sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX"); + sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY"); + sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale"); + sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation"); + sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin"); + sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor"); + sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode"); + sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX"); + sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY"); + sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX"); + sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(symbol ~ "_GetScaleX"); + sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation"); + sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX"); + sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY"); + sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor"); + sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode"); + sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move"); + sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale"); + sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate"); + sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal"); + sfDrawable_TransformToGlobal= cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal"); sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$]); sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$] ~ "WithShader"); + sfRenderImage_DrawThis = cast(pf_sfRenderImage_DrawThis)dll.getSymbol("sfRenderImage_Draw" ~ symbol[2..$]); + sfRenderImage_DrawThisWithShader = cast(pf_sfRenderImage_DrawThisWithShader)dll.getSymbol("sfRenderImage_Draw" ~ symbol[2..$] ~ "WithShader"); } } diff --git a/DSFML/import/dsfml/graphics/font.d b/DSFML/import/dsfml/graphics/font.d index 615bded93..39e443231 100644 --- a/DSFML/import/dsfml/graphics/font.d +++ b/DSFML/import/dsfml/graphics/font.d @@ -38,8 +38,8 @@ import dsfml.graphics.common, struct Glyph { int Advance; /// Offset to move horizontically to the next character - sfIntRect Rectangle; /// Bounding rectangle of the glyph, in relative coordinates - sfFloatRect TexCoords; /// Texture coordinates of the glyph inside the bitmap font + IntRect Rectangle; /// Bounding rectangle of the glyph, in relative coordinates + FloatRect TexCoords; /// Texture coordinates of the glyph inside the bitmap font } /** diff --git a/DSFML/import/dsfml/graphics/idrawable.d b/DSFML/import/dsfml/graphics/idrawable.d index 581cb73df..6c75b7616 100644 --- a/DSFML/import/dsfml/graphics/idrawable.d +++ b/DSFML/import/dsfml/graphics/idrawable.d @@ -31,6 +31,7 @@ import dsfml.system.vector2; import dsfml.graphics.color, dsfml.graphics.blendmode, dsfml.graphics.renderwindow, + dsfml.graphics.renderimage, dsfml.graphics.shader; @@ -290,4 +291,21 @@ interface IDrawable * shader = Shader to use */ void renderWithShader(RenderWindow window, Shader shader); + + /** + * Render the specific geometry of the object + * + * Params: + * image = Target into which render the object + */ + void render(RenderImage image); + + /** + * Render the specific geometry of the object with a shader + * + * Params: + * image = Render target + * shader = Shader to use + */ + void renderWithShader(RenderImage image, Shader shader); } \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/image.d b/DSFML/import/dsfml/graphics/image.d index e293f9d89..3f9446ae8 100644 --- a/DSFML/import/dsfml/graphics/image.d +++ b/DSFML/import/dsfml/graphics/image.d @@ -42,6 +42,14 @@ import dsfml.system.common, */ class Image : DSFMLObject { +package: + this(void* ptr) + { + super(ptr, true); + } + +public: + /** * Default constructor */ @@ -176,7 +184,7 @@ class Image : DSFMLObject // */ // void copyScreen(RenderWindow window, IntRect sourceRect = new IntRect()) // { -// return cast(bool)sfImage_CopyScreen(m_ptr, window.getNativePointer, sourceRect.toCIntRect()); +// return cast(bool)sfImage_CopyScreen(m_ptr, window.getNativePointer, sourceRect); // } /** @@ -190,9 +198,9 @@ class Image : DSFMLObject * destY = Y coordinate of the destination position * sourceRect = Sub-rectangle of the source image to copy */ - void copy(Image source, uint destX, uint destY, IntRect sourceRect = new IntRect()) + void copy(Image source, uint destX, uint destY, IntRect sourceRect = IntRect()) { - sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect.toCIntRect()); + sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect); } /** @@ -290,52 +298,30 @@ class Image : DSFMLObject return cast(bool)sfImage_IsSmooth(m_ptr); } -package: - this(void* ptr) - { - super(ptr); - } - private: extern (C) { - typedef void* function() pf_sfImage_Create; - typedef void* function(uint, uint, Color) pf_sfImage_CreateFromColor; - typedef void* function(uint, uint, ubyte*) pf_sfImage_CreateFromPixels; - typedef void* function(cchar*) pf_sfImage_CreateFromFile; - typedef void* function(ubyte* ,size_t) pf_sfImage_CreateFromMemory; - typedef void function(void*) pf_sfImage_Destroy; - typedef int function(void*, cchar*) pf_sfImage_SaveToFile; - typedef void function(void*, Color, ubyte) pf_sfImage_CreateMaskFromColor; - typedef int function(void*, void*, sfIntRect) pf_sfImage_CopyScreen; - typedef void function(void*, void*, uint, uint, sfIntRect) pf_sfImage_Copy; - typedef void function(void*, uint, uint, Color) pf_sfImage_SetPixel; - typedef Color function(void*, uint, uint) pf_sfImage_GetPixel; - typedef ubyte* function(void*) pf_sfImage_GetPixelsPtr; - typedef void function(void*) pf_sfImage_Bind; - typedef void function(void*, int) pf_sfImage_SetSmooth; - typedef uint function(void*) pf_sfImage_GetWidth; - typedef uint function(void*) pf_sfImage_GetHeight; - typedef int function(void*) pf_sfImage_IsSmooth; - - static pf_sfImage_Create sfImage_Create; - static pf_sfImage_CreateFromColor sfImage_CreateFromColor; - static pf_sfImage_CreateFromPixels sfImage_CreateFromPixels; - static pf_sfImage_CreateFromFile sfImage_CreateFromFile; - static pf_sfImage_CreateFromMemory sfImage_CreateFromMemory; - static pf_sfImage_Destroy sfImage_Destroy; - static pf_sfImage_SaveToFile sfImage_SaveToFile; - static pf_sfImage_CreateMaskFromColor sfImage_CreateMaskFromColor; - static pf_sfImage_CopyScreen sfImage_CopyScreen; - static pf_sfImage_Copy sfImage_Copy; - static pf_sfImage_SetPixel sfImage_SetPixel; - static pf_sfImage_GetPixel sfImage_GetPixel; - static pf_sfImage_GetPixelsPtr sfImage_GetPixelsPtr; - static pf_sfImage_Bind sfImage_Bind; - static pf_sfImage_SetSmooth sfImage_SetSmooth; - static pf_sfImage_GetWidth sfImage_GetWidth; - static pf_sfImage_GetHeight sfImage_GetHeight; - static pf_sfImage_IsSmooth sfImage_IsSmooth; + static + { + void* function() sfImage_Create; + void* function(uint, uint, Color) sfImage_CreateFromColor; + void* function(uint, uint, ubyte*) sfImage_CreateFromPixels; + void* function(cchar*) sfImage_CreateFromFile; + void* function(ubyte* ,size_t) sfImage_CreateFromMemory; + void function(void*) sfImage_Destroy; + int function(void*, cchar*) sfImage_SaveToFile; + void function(void*, Color, ubyte) sfImage_CreateMaskFromColor; + int function(void*, void*, IntRect) sfImage_CopyScreen; + void function(void*, void*, uint, uint, IntRect) sfImage_Copy; + void function(void*, uint, uint, Color) sfImage_SetPixel; + Color function(void*, uint, uint) sfImage_GetPixel; + ubyte* function(void*) sfImage_GetPixelsPtr; + void function(void*) sfImage_Bind; + void function(void*, int) sfImage_SetSmooth; + uint function(void*) sfImage_GetWidth; + uint function(void*) sfImage_GetHeight; + int function(void*) sfImage_IsSmooth; + } } static this() @@ -345,23 +331,23 @@ private: else DllLoader dll = DllLoader.load("csfml-graphics"); - sfImage_Create = cast(pf_sfImage_Create)dll.getSymbol("sfImage_Create"); - sfImage_CreateFromColor = cast(pf_sfImage_CreateFromColor)dll.getSymbol("sfImage_CreateFromColor"); - sfImage_CreateFromPixels = cast(pf_sfImage_CreateFromPixels)dll.getSymbol("sfImage_CreateFromPixels"); - sfImage_CreateFromFile = cast(pf_sfImage_CreateFromFile)dll.getSymbol("sfImage_CreateFromFile"); - sfImage_CreateFromMemory = cast(pf_sfImage_CreateFromMemory)dll.getSymbol("sfImage_CreateFromMemory"); - sfImage_Destroy = cast(pf_sfImage_Destroy)dll.getSymbol("sfImage_Destroy"); - sfImage_SaveToFile = cast(pf_sfImage_SaveToFile)dll.getSymbol("sfImage_SaveToFile"); - sfImage_CreateMaskFromColor = cast(pf_sfImage_CreateMaskFromColor)dll.getSymbol("sfImage_CreateMaskFromColor"); - sfImage_CopyScreen = cast(pf_sfImage_CopyScreen)dll.getSymbol("sfImage_CopyScreen"); - sfImage_Copy = cast(pf_sfImage_Copy)dll.getSymbol("sfImage_Copy"); - sfImage_SetPixel = cast(pf_sfImage_SetPixel)dll.getSymbol("sfImage_SetPixel"); - sfImage_GetPixel = cast(pf_sfImage_GetPixel)dll.getSymbol("sfImage_GetPixel"); - sfImage_GetPixelsPtr = cast(pf_sfImage_GetPixelsPtr)dll.getSymbol("sfImage_GetPixelsPtr"); - sfImage_Bind = cast(pf_sfImage_Bind)dll.getSymbol("sfImage_Bind"); - sfImage_SetSmooth = cast(pf_sfImage_SetSmooth)dll.getSymbol("sfImage_SetSmooth"); - sfImage_GetWidth = cast(pf_sfImage_GetWidth)dll.getSymbol("sfImage_GetWidth"); - sfImage_GetHeight = cast(pf_sfImage_GetHeight)dll.getSymbol("sfImage_GetHeight"); - sfImage_IsSmooth = cast(pf_sfImage_IsSmooth)dll.getSymbol("sfImage_IsSmooth"); + mixin(loadFromSharedLib("sfImage_Create")); + mixin(loadFromSharedLib("sfImage_CreateFromColor")); + mixin(loadFromSharedLib("sfImage_CreateFromPixels")); + mixin(loadFromSharedLib("sfImage_CreateFromFile")); + mixin(loadFromSharedLib("sfImage_CreateFromMemory")); + mixin(loadFromSharedLib("sfImage_Destroy")); + mixin(loadFromSharedLib("sfImage_SaveToFile")); + mixin(loadFromSharedLib("sfImage_CreateMaskFromColor")); + mixin(loadFromSharedLib("sfImage_CopyScreen")); + mixin(loadFromSharedLib("sfImage_Copy")); + mixin(loadFromSharedLib("sfImage_SetPixel")); + mixin(loadFromSharedLib("sfImage_GetPixel")); + mixin(loadFromSharedLib("sfImage_GetPixelsPtr")); + mixin(loadFromSharedLib("sfImage_Bind")); + mixin(loadFromSharedLib("sfImage_SetSmooth")); + mixin(loadFromSharedLib("sfImage_GetWidth")); + mixin(loadFromSharedLib("sfImage_GetHeight")); + mixin(loadFromSharedLib("sfImage_IsSmooth")); } -} +} \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/rect.d b/DSFML/import/dsfml/graphics/rect.d index cb06e0cbb..0c72279f8 100644 --- a/DSFML/import/dsfml/graphics/rect.d +++ b/DSFML/import/dsfml/graphics/rect.d @@ -26,22 +26,6 @@ module dsfml.graphics.rect; -struct sfFloatRect -{ - float Left; - float Top; - float Right; - float Bottom; -} - -struct sfIntRect -{ - int Left; - int Top; - int Right; - int Bottom; -} - version (Tango) { import tango.core.Traits; @@ -64,20 +48,20 @@ else is (T == double) || is (T == real); } -} +} + /** * Rect is an utility class for manipulating rectangles. * Template parameter defines the type of coordinates (integer float, ...) */ - -class Rect (T) +struct Rect(T) { private: - T m_Left; // Left coordinate of the rectangle - T m_Top; // Top coordinate of the rectangle - T m_Right; // Right coordinate of the rectangle - T m_Bottom; // Bottom coordinate of the rectangle + T left; // Left coordinate of the rectangle + T top; // Top coordinate of the rectangle + T right; // Right coordinate of the rectangle + T bottom; // Bottom coordinate of the rectangle public: static if (!isIntegerType!(T) && !isRealType!(T)) @@ -95,17 +79,7 @@ public: return i > j ? i : j; } - /** - * Default constructor - */ - this() - { - m_Left = 0; - m_Top = 0; - m_Right = 0; - m_Bottom = 0; - } - +/+ /** * Construct the rectangle from its coordinates * @@ -117,11 +91,12 @@ public: */ this(T leftCoord, T topCoord, T rightCoord, T bottomCoord) { - m_Left = leftCoord; - m_Top = topCoord; - m_Right = rightCoord; - m_Bottom = bottomCoord; + left = leftCoord; + top = topCoord; + right = rightCoord; + bottom = bottomCoord; } ++/ /** * Get the width of the rectangle @@ -131,7 +106,7 @@ public: */ T getWidth() { - return m_Right - m_Left; + return right - left; } /** @@ -142,7 +117,7 @@ public: */ T getHeight() { - return m_Bottom - m_Top; + return bottom - top; } /** @@ -154,10 +129,10 @@ public: */ void offset(T offsetX, T offsetY) { - m_Left += offsetX; - m_Right += offsetX; - m_Top += offsetY; - m_Bottom += offsetY; + left += offsetX; + right += offsetX; + top += offsetY; + bottom += offsetY; } /** @@ -172,7 +147,7 @@ public: */ bool contains(T x, T y) { - return (x >= m_Left) && (x <= m_Right) && (y >= m_Top) && (y <= m_Bottom); + return (x >= left) && (x <= right) && (y >= top) && (y <= bottom); } /** @@ -185,103 +160,30 @@ public: * Returns: * True if rectangles overlap */ - bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = null) + bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = Rect!(T)()) { // Compute overlapping rect - Rect!(T) overlapping = new Rect!(T)( - max(m_Left, rectangle.getLeft), - max(m_Top, rectangle.getTop), - min(m_Right, rectangle.getRight), - min(m_Bottom, rectangle.getBottom) - ); + 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.getLeft() < overlapping.getRight() ) && (overlapping.getTop() < overlapping.getBottom())) + if ((overlapping.left < overlapping.right) && (overlapping.top < overlapping.bottom)) { overlappingRect = overlapping; return true; } else { - overlappingRect = new Rect!(T)(); + overlappingRect = Rect!(T)(); return false; } } - /** - * Set left Coordinate - */ - void setLeft(T left) - { - m_Left = left; - } - - /** - * Set top Coordinate - */ - void setTop(T top) - { - m_Top = top; - } - - /** - * Set right Coordinate - */ - void setRight(T right) - { - m_Right = right; - } - - /** - * Set bottom Coordinate - */ - void setBottom(T bottom) - { - m_Bottom = bottom; - } - - /** - * Get left Coordinate - */ - T getLeft() - { - return m_Left; - } - - /** - * Get top Coordinate - */ - T getTop() - { - return m_Top; - } - - /** - * Get right Coordinate - */ - T getRight() - { - return m_Right; - } - - /** - * Get bottom Coordinate - */ - T getBottom() - { - return m_Bottom; - } - -package: - sfFloatRect toCFloatRect() - { - return sfFloatRect(m_Left, m_Top, m_Right, m_Bottom); - } - - sfIntRect toCIntRect() - { - return sfIntRect(cast(int)m_Left, cast(int)m_Top, cast(int)m_Right, cast(int)m_Bottom); - } + //bool opEquals } ///Alias diff --git a/DSFML/import/dsfml/graphics/renderimage.d b/DSFML/import/dsfml/graphics/renderimage.d new file mode 100644 index 000000000..72008f051 --- /dev/null +++ b/DSFML/import/dsfml/graphics/renderimage.d @@ -0,0 +1,336 @@ +/* +* 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.vector2; + +import dsfml.graphics.common, + dsfml.graphics.idrawable, + dsfml.graphics.image, + dsfml.graphics.color, + dsfml.graphics.rect, + dsfml.graphics.shader, + dsfml.graphics.view; + + +/** + * Target for 2D rendering into an image that can be reused in a sprite + */ +class RenderImage : DSFMLObject +{ +private: + Image _image = null; + View _view = null; + View _defaultView = null; + +package: + this(void* ptr) + { + super(ptr, true); + } + +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)); + } + + override void dispose() + { + sfRenderImage_Destroy(m_ptr); + } + + /** + * Return the width of the rendering region of a renderimage + * + * Returns: + * Width in pixels + */ + uint getWidth() + { + return sfRenderImage_GetWidth(m_ptr); + } + + /** + * Return the height of the rendering region of a renderimage + * + * Returns: + * Height in pixels + */ + uint getHeight() + { + 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 setActive(bool active) + { + return sfRenderImage_SetActive(m_ptr, active); + } + + /** + * Make sure that what has been drawn so far is rendered + * + * Use this function if you use OpenGL rendering commands, and you want to make sure that things will appear on top + * of all the SFML objects that have been drawn so far. This is needed because SFML doesn't use immediate rendering, + * it first accumulates drawables into a queue and trigger the actual rendering afterwards. + * + * You don't need to call this function if you're not dealing with OpenGL directly. + */ + void flush() + { + sfRenderImage_Flush(m_ptr); + } + + /** + * 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 drawWithShader(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); + } + + /** + * Change the current active view of a renderimage + * + * Params: + * view = Pointer to the new view + */ + void setView(View view) + { + if (_view !is null) + { + _view.setHandled(false); + } + + sfRenderImage_SetView(m_ptr, view.getNativePointer); + + _view = view; + _view.setHandled(true); + } + + /** + * Get the current active view rectangle + * + * Returns: + * current view rectangle, in global coordinates + */ + View getView() + { + if (_view is null) + { + void* cView = sfRenderImage_GetView(m_ptr); + _view = new View(cView, true); + } + return _view; + } + + /** + * Get the default view + * + * Returns: + * default view + */ + View getDefaultView() + { + if (_defaultView is null) + { + void* cView = sfRenderImage_GetDefaultView(m_ptr); + _defaultView = new View(cView, true); + } + return _defaultView; + } + + + IntRect getViewport() // TODO: is there a need to accept other Views than the currently assigned one? + { + return sfRenderImage_GetViewport(m_ptr, _view.getNativePointer); + } + + /** + * 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.getNativePointer); + return vec; + } + + /** + * Get the target image + * + * Returns: + * target image + */ + Image getImage() + { + if (_image is null) + { + void* 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: + extern (C) + { + static + { + void* function(uint, uint, bool) sfRenderImage_Create; + void function(void*) sfRenderImage_Destroy; + uint function(void*) sfRenderImage_GetWidth; + uint function(void*) sfRenderImage_GetHeight; + bool function(void*, bool) sfRenderImage_SetActive; + void function(void*) sfRenderImage_Flush; + void function(void*) sfRenderImage_Display; + + void function(void*, void*) sfRenderImage_DrawSprite; + void function(void*, void*) sfRenderImage_DrawShape; + void function(void*, void*) sfRenderImage_DrawText; + + void function(void*, void*, void*) sfRenderImage_DrawSpriteWithShader; + void function(void*, void*, void*) sfRenderImage_DrawShapeWithShader; + void function(void*, void*, void*) sfRenderImage_DrawTextWithShader; + + void function(void*, Color) sfRenderImage_Clear; + void function(void*, void*) sfRenderImage_SetView; + void* function(void*) sfRenderImage_GetView; + void* function(void*) sfRenderImage_GetDefaultView; + IntRect function(void*, void*) sfRenderImage_GetViewport; + void function(void*, uint, uint, float*, float*, void*) sfRenderImage_ConvertCoords; + void* function(void*) sfRenderImage_GetImage; + bool function() sfRenderImage_IsAvailable; + } + } + + static this() + { + debug + DllLoader dll = DllLoader.load("csfml-graphics-d"); + else + DllLoader dll = DllLoader.load("csfml-graphics"); + + mixin(loadFromSharedLib("sfRenderImage_Create")); + mixin(loadFromSharedLib("sfRenderImage_Destroy")); + mixin(loadFromSharedLib("sfRenderImage_GetWidth")); + mixin(loadFromSharedLib("sfRenderImage_GetHeight")); + mixin(loadFromSharedLib("sfRenderImage_SetActive")); + mixin(loadFromSharedLib("sfRenderImage_Flush")); + mixin(loadFromSharedLib("sfRenderImage_Display")); +/* + mixin(loadFromSharedLib("sfRenderImage_DrawSprite")); + mixin(loadFromSharedLib("sfRenderImage_DrawShape")); + mixin(loadFromSharedLib("sfRenderImage_DrawText")); + + mixin(loadFromSharedLib("sfRenderImage_DrawSpriteWithShader")); + mixin(loadFromSharedLib("sfRenderImage_DrawShapeWithShader")); + mixin(loadFromSharedLib("sfRenderImage_DrawTextWithShader")); +*/ + + mixin(loadFromSharedLib("sfRenderImage_Clear")); + mixin(loadFromSharedLib("sfRenderImage_SetView")); + mixin(loadFromSharedLib("sfRenderImage_GetView")); + mixin(loadFromSharedLib("sfRenderImage_GetDefaultView")); + mixin(loadFromSharedLib("sfRenderImage_GetViewport")); + mixin(loadFromSharedLib("sfRenderImage_ConvertCoords")); + mixin(loadFromSharedLib("sfRenderImage_GetImage")); + mixin(loadFromSharedLib("sfRenderImage_IsAvailable")); + } +} \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/renderwindow.d b/DSFML/import/dsfml/graphics/renderwindow.d index ee6e7951e..0d0d47657 100644 --- a/DSFML/import/dsfml/graphics/renderwindow.d +++ b/DSFML/import/dsfml/graphics/renderwindow.d @@ -234,4 +234,17 @@ public: sfRenderWindow_ConvertCoords(m_ptr, windowX, windowY, &vec.x, &vec.y, targetView is null ? null : targetView.getNativePointer); return vec; } + + /** + * Make sure that what has been drawn so far is rendered + * Use this function if you use OpenGL rendering commands, and you want to make sure that things will appear on top + * of all the SFML objects that have been drawn so far. This is needed because SFML doesn't use immediate rendering, + * it first accumulates drawables into a queue and trigger the actual rendering afterwards. + * + * You don't need to call this function if you're not dealing with OpenGL directly. + */ + void flush() + { + sfRenderWindow_Flush(m_ptr); + } } \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/sprite.d b/DSFML/import/dsfml/graphics/sprite.d index b9f94a863..b59aebe1c 100644 --- a/DSFML/import/dsfml/graphics/sprite.d +++ b/DSFML/import/dsfml/graphics/sprite.d @@ -42,11 +42,18 @@ import dsfml.system.vector2; */ 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(); } /** @@ -63,6 +70,7 @@ class Sprite : Drawableimpl!(sfSprite) */ this(Image img, float left = 0.f, float top = 0.f, float scaleX = 1.f, float scaleY = 1.f, float rotation = 0.f, Color col = Color.WHITE) { + super(); m_image = img; sfSprite_SetImage(m_ptr, img.getNativePointer); setX(left); @@ -94,7 +102,7 @@ class Sprite : Drawableimpl!(sfSprite) */ void setSubRect(IntRect rect) { - sfIntRect r = rect.toCIntRect(); + IntRect r = rect; sfSprite_SetSubRect(m_ptr, &r); m_subRect = rect; } @@ -168,8 +176,8 @@ class Sprite : Drawableimpl!(sfSprite) */ IntRect getSubRect() { - if (m_subRect is null) - m_subRect = new IntRect(0, 0, m_image.getWidth(), m_image.getHeight()); + if (m_subRect == IntRect()) + m_subRect = IntRect(0, 0, m_image.getWidth(), m_image.getHeight()); return m_subRect; } @@ -201,13 +209,11 @@ 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 extern (C) { typedef void function(void*, void*) pf_sfSprite_SetImage; - typedef void function(void*, sfIntRect*) pf_sfSprite_SetSubRect; + typedef void function(void*, IntRect*) pf_sfSprite_SetSubRect; typedef void function(void*, float, float) pf_sfSprite_Resize; typedef void function(void*, int) pf_sfSprite_FlipX; typedef void function(void*, int) pf_sfSprite_FlipY; @@ -246,7 +252,5 @@ private: sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth"); sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight"); sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("sfSprite_GetPixel"); - } - -} - + } +} \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/text.d b/DSFML/import/dsfml/graphics/text.d index 3aa5720c6..2718e8912 100644 --- a/DSFML/import/dsfml/graphics/text.d +++ b/DSFML/import/dsfml/graphics/text.d @@ -37,6 +37,17 @@ import dsfml.system.stringutil; import dsfml.system.vector2; +/** + * 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 * @@ -56,6 +67,10 @@ import dsfml.system.vector2; */ class Text : Drawableimpl!(sfText) { +private: + Font m_font; + +public: /** * Construct the string from a text * @@ -99,11 +114,10 @@ class Text : Drawableimpl!(sfText) * * Params: * text = New text - * */ void setString(string text) { - sfText_SetString(m_ptr,toStringz(text)); + sfText_SetString(m_ptr, toStringz(text)); } /** @@ -234,13 +248,10 @@ class Text : Drawableimpl!(sfText) */ FloatRect getRect() { - sfFloatRect sfRect = sfText_GetRect(m_ptr); - - return new Rect!(float)(sfRect.Left, sfRect.Top, sfRect.Right, sfRect.Bottom); + return sfText_GetRect(m_ptr); } private: - Font m_font; extern (C) { @@ -255,7 +266,7 @@ private: typedef uint function(void*) pf_sfText_GetCharacterSize; typedef TextStyle function (void*) pf_sfText_GetStyle; typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos; - typedef sfFloatRect function(void*) pf_sfText_GetRect; + typedef FloatRect function(void*) pf_sfText_GetRect; static pf_sfText_SetString sfText_SetString; static pf_sfText_SetUnicodeString sfText_SetUnicodeString; diff --git a/DSFML/import/dsfml/graphics/textstyle.d b/DSFML/import/dsfml/graphics/textstyle.d deleted file mode 100644 index 82d668e47..000000000 --- a/DSFML/import/dsfml/graphics/textstyle.d +++ /dev/null @@ -1,38 +0,0 @@ -/* -* 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.textstyle; - -/** -* Enumerate the string drawing styles -*/ -enum TextStyle -{ - REGULAR = 0, /// Regular characters, no style - BOLD = 1 << 0, /// Characters are bold - ITALIC = 1 << 1, /// Characters are in italic - UNDERLINED = 1 << 2 /// Characters are underlined -} diff --git a/DSFML/import/dsfml/graphics/view.d b/DSFML/import/dsfml/graphics/view.d index ba339d6e5..aa855c512 100644 --- a/DSFML/import/dsfml/graphics/view.d +++ b/DSFML/import/dsfml/graphics/view.d @@ -39,14 +39,15 @@ import dsfml.system.common, class View : DSFMLObject { private: - FloatRect m_viewport; + 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) + * Default view (1000 x 1000) */ this() { @@ -58,11 +59,11 @@ public: * * Params: * center = center of the view - * size = size of the view (width, height) + * size = size of the view (width, height) */ this(Vector2f center, Vector2f size) { - super(sfView_CreateFromRect(sfFloatRect(center.x - size.x / 2, center.y - size.y / 2, center.x + size.x / 2, center.y + size.y / 2) )); + super(sfView_CreateFromRect(FloatRect(center.x - size.x / 2, center.y - size.y / 2, center.x + size.x / 2, center.y + size.y / 2) )); } /** @@ -73,7 +74,7 @@ public: */ this(FloatRect rect) { - super(sfView_CreateFromRect(rect.toCFloatRect())); + super(sfView_CreateFromRect(rect)); } override void dispose() @@ -139,8 +140,8 @@ public: */ void setViewport(FloatRect viewport) { - sfView_SetViewport(m_ptr, viewport.toCFloatRect()); - m_viewport = viewport; + sfView_SetViewport(m_ptr, viewport); + _viewport = viewport; } /** @@ -195,10 +196,9 @@ public: if (m_isModified) { m_isModified = false; - sfFloatRect cViewport = sfView_GetViewport(m_ptr); - m_viewport = new FloatRect(cViewport.Left, cViewport.Top, cViewport.Right, cViewport.Bottom); + _viewport = sfView_GetViewport(m_ptr); } - return m_viewport; + return _viewport; } /** @@ -272,6 +272,11 @@ public: return sfView_GetRotation(m_ptr); } + void reset(FloatRect rect) + { + sfView_Reset(m_ptr, rect); + _rect = rect; + } package: this(void* ptr, bool preventDelete) diff --git a/DSFML/import/dsfml/system/common.d b/DSFML/import/dsfml/system/common.d index 46c3a2c1a..337f208fb 100644 --- a/DSFML/import/dsfml/system/common.d +++ b/DSFML/import/dsfml/system/common.d @@ -62,6 +62,7 @@ public: this(void* ptr, bool preventDelete = false) { m_ptr = ptr; + m_preventDelete = preventDelete; } ~this() diff --git a/DSFML/import/dsfml/window/event.d b/DSFML/import/dsfml/window/event.d index b7eec3a26..357838574 100644 --- a/DSFML/import/dsfml/window/event.d +++ b/DSFML/import/dsfml/window/event.d @@ -181,22 +181,22 @@ align(1) struct Event { enum EventType { - CLOSED, - RESIZED, - LOSTFOCUS, - GAINEDFOCUS, - TEXTENTERED, - KEYPRESSED, - KEYRELEASED, - MOUSEWHEELMOVED, - MOUSEBUTTONPRESSED, - MOUSEBUTTONRELEASED, + CLOSED, + RESIZED, + LOSTFOCUS, + GAINEDFOCUS, + TEXTENTERED, + KEYPRESSED, + KEYRELEASED, + MOUSEWHEELMOVED, + MOUSEBUTTONPRESSED, + MOUSEBUTTONRELEASED, MOUSEMOVED, MOUSEENTERED, - MOUSELEFT, - JOYBUTTONPRESSED, - JOYBUTTONRELEASED, - JOYMOVED + MOUSELEFT, + JOYBUTTONPRESSED, + JOYBUTTONRELEASED, + JOYMOVED } /** diff --git a/DSFML/import/dsfml/window/window.d b/DSFML/import/dsfml/window/window.d index c85df5c21..ba3a10a5b 100644 --- a/DSFML/import/dsfml/window/window.d +++ b/DSFML/import/dsfml/window/window.d @@ -67,6 +67,15 @@ struct ContextSettings */ class Window : DSFMLObject { +protected: + this(void* ptr) + { + super(ptr); + } + + Input m_input; + +public: /** * Construct a new window * @@ -197,9 +206,9 @@ class Window : DSFMLObject * Returns: * True if an event was returned, false if events stack was empty */ - bool getEvent(ref Event eventReceived) + bool getEvent(out Event eventReceived) { - return cast(bool)sfWindow_GetEvent(m_ptr, &eventReceived); + return cast(bool) sfWindow_GetEvent(m_ptr, &eventReceived); } /** @@ -369,65 +378,59 @@ class Window : DSFMLObject sfWindow_SetJoystickThreshold(m_ptr, threshold); } -protected: - this(void* ptr) + /** + * Wait for an event and return it + * + * This function is blocking: if there's no pending event then it will wait until an event is received. + * After this function returns (and no error occured), the \a event object is always valid and filled properly. + * This function is typically used when you have a thread that is dedicated to events handling: you want to make this thread + * sleep as long as no new event is received. + * + * Params: + * e Event to be returned + * + * Returns: + * false if any error occured + */ + bool waitEvent(out Event e) { - super(ptr); + return sfWindow_WaitEvent(m_ptr, &e); } - - Input m_input; -private: +private: + // External ==================================================================== extern (C) { - typedef void* function(VideoMode, cchar*, uint, ContextSettings) pf_sfWindow_Create; - typedef void* function(WindowHandle, ContextSettings) pf_sfWindow_CreateFromHandle; - typedef void function(void*) pf_sfWindow_Destroy; - typedef void function(void*) pf_sfWindow_Close; - typedef int function(void*) pf_sfWindow_IsOpened; - typedef uint function(void*) pf_sfWindow_GetWidth; - typedef uint function(void*) pf_sfWindow_GetHeight; - typedef ContextSettings function(void* Window) pf_sfWindow_GetSettings; - typedef int function(void*, Event*) pf_sfWindow_GetEvent; - typedef void function(void*, int) pf_sfWindow_UseVerticalSync; - typedef void function(void*, int) pf_sfWindow_ShowMouseCursor; - typedef void function(void*, uint, uint) pf_sfWindow_SetCursorPosition; - typedef void function(void*, int, int) pf_sfWindow_SetPosition; - typedef void function(void*, uint, uint) pf_sfWindow_SetSize; - typedef void function(void*, int) pf_sfWindow_Show; - typedef void function(void*, int) pf_sfWindow_EnableKeyRepeat; - typedef void function(void*, size_t, size_t, ubyte*) pf_sfWindow_SetIcon; - typedef int function(void*, int) pf_sfWindow_SetActive; - typedef void function(void*) pf_sfWindow_Display; - typedef void* function(void*) pf_sfWindow_GetInput; - typedef void function(void*, uint) pf_sfWindow_SetFramerateLimit; - typedef float function(void*) pf_sfWindow_GetFrameTime; - typedef void function(void*, float) pf_sfWindow_SetJoystickThreshold; - - static pf_sfWindow_Create sfWindow_Create; - static pf_sfWindow_CreateFromHandle sfWindow_CreateFromHandle; - static pf_sfWindow_Destroy sfWindow_Destroy; - static pf_sfWindow_Close sfWindow_Close; - static pf_sfWindow_IsOpened sfWindow_IsOpened; - static pf_sfWindow_GetWidth sfWindow_GetWidth; - static pf_sfWindow_GetHeight sfWindow_GetHeight; - static pf_sfWindow_GetSettings sfWindow_GetSettings; - static pf_sfWindow_GetEvent sfWindow_GetEvent; - static pf_sfWindow_UseVerticalSync sfWindow_UseVerticalSync; - static pf_sfWindow_ShowMouseCursor sfWindow_ShowMouseCursor; - static pf_sfWindow_SetCursorPosition sfWindow_SetCursorPosition; - static pf_sfWindow_SetPosition sfWindow_SetPosition; - static pf_sfWindow_SetSize sfWindow_SetSize; - static pf_sfWindow_Show sfWindow_Show; - static pf_sfWindow_EnableKeyRepeat sfWindow_EnableKeyRepeat; - static pf_sfWindow_SetIcon sfWindow_SetIcon; - static pf_sfWindow_SetActive sfWindow_SetActive; - static pf_sfWindow_Display sfWindow_Display; - static pf_sfWindow_GetInput sfWindow_GetInput; - static pf_sfWindow_SetFramerateLimit sfWindow_SetFramerateLimit; - static pf_sfWindow_GetFrameTime sfWindow_GetFrameTime; - static pf_sfWindow_SetJoystickThreshold sfWindow_SetJoystickThreshold; + static + { + void* function(VideoMode, cchar*, uint, ContextSettings) sfWindow_Create; + void* function(WindowHandle, ContextSettings) sfWindow_CreateFromHandle; + void function(void*) sfWindow_Destroy; + void function(void*) sfWindow_Close; + int function(void*) sfWindow_IsOpened; + uint function(void*) sfWindow_GetWidth; + uint function(void*) sfWindow_GetHeight; + ContextSettings function(void* Window) sfWindow_GetSettings; + int function(void*, Event*) sfWindow_GetEvent; + void function(void*, int) sfWindow_UseVerticalSync; + void function(void*, int) sfWindow_ShowMouseCursor; + void function(void*, uint, uint) sfWindow_SetCursorPosition; + void function(void*, int, int) sfWindow_SetPosition; + void function(void*, uint, uint) sfWindow_SetSize; + void function(void*, int) sfWindow_Show; + void function(void*, int) sfWindow_EnableKeyRepeat; + void function(void*, size_t, size_t, ubyte*) sfWindow_SetIcon; + int function(void*, int) sfWindow_SetActive; + void function(void*) sfWindow_Display; + void* function(void*) sfWindow_GetInput; + void function(void*, uint) sfWindow_SetFramerateLimit; + float function(void*) sfWindow_GetFrameTime; + void function(void*, float) sfWindow_SetJoystickThreshold; + + // DSFML2 + bool function(void*, void*) sfWindow_WaitEvent; + } } static this() @@ -437,28 +440,29 @@ private: else DllLoader dll = DllLoader.load("csfml-window"); - sfWindow_Create = cast(pf_sfWindow_Create)dll.getSymbol("sfWindow_Create"); - sfWindow_CreateFromHandle = cast(pf_sfWindow_CreateFromHandle)dll.getSymbol("sfWindow_CreateFromHandle"); - sfWindow_Destroy = cast(pf_sfWindow_Destroy)dll.getSymbol("sfWindow_Destroy"); - sfWindow_Close = cast(pf_sfWindow_Close)dll.getSymbol("sfWindow_Close"); - sfWindow_IsOpened = cast(pf_sfWindow_IsOpened)dll.getSymbol("sfWindow_IsOpened"); - sfWindow_GetWidth = cast(pf_sfWindow_GetWidth)dll.getSymbol("sfWindow_GetWidth"); - sfWindow_GetHeight = cast(pf_sfWindow_GetHeight)dll.getSymbol("sfWindow_GetHeight"); - sfWindow_GetSettings = cast(pf_sfWindow_GetSettings)dll.getSymbol("sfWindow_GetSettings"); - sfWindow_GetEvent = cast(pf_sfWindow_GetEvent)dll.getSymbol("sfWindow_GetEvent"); - sfWindow_UseVerticalSync = cast(pf_sfWindow_UseVerticalSync)dll.getSymbol("sfWindow_UseVerticalSync"); - sfWindow_ShowMouseCursor = cast(pf_sfWindow_ShowMouseCursor)dll.getSymbol("sfWindow_ShowMouseCursor"); - sfWindow_SetCursorPosition = cast(pf_sfWindow_SetCursorPosition)dll.getSymbol("sfWindow_SetCursorPosition"); - sfWindow_SetPosition = cast(pf_sfWindow_SetPosition)dll.getSymbol("sfWindow_SetPosition"); - sfWindow_SetSize = cast(pf_sfWindow_SetSize)dll.getSymbol("sfWindow_SetSize"); - sfWindow_Show = cast(pf_sfWindow_Show)dll.getSymbol("sfWindow_Show"); - sfWindow_EnableKeyRepeat = cast(pf_sfWindow_EnableKeyRepeat)dll.getSymbol("sfWindow_EnableKeyRepeat"); - sfWindow_SetIcon = cast(pf_sfWindow_SetIcon)dll.getSymbol("sfWindow_SetIcon"); - sfWindow_SetActive = cast(pf_sfWindow_SetActive)dll.getSymbol("sfWindow_SetActive"); - sfWindow_Display = cast(pf_sfWindow_Display)dll.getSymbol("sfWindow_Display"); - sfWindow_GetInput = cast(pf_sfWindow_GetInput)dll.getSymbol("sfWindow_GetInput"); - sfWindow_SetFramerateLimit = cast(pf_sfWindow_SetFramerateLimit)dll.getSymbol("sfWindow_SetFramerateLimit"); - sfWindow_GetFrameTime = cast(pf_sfWindow_GetFrameTime)dll.getSymbol("sfWindow_GetFrameTime"); - sfWindow_SetJoystickThreshold = cast(pf_sfWindow_SetJoystickThreshold)dll.getSymbol("sfWindow_SetJoystickThreshold"); + mixin(loadFromSharedLib("sfWindow_Create")); + mixin(loadFromSharedLib("sfWindow_CreateFromHandle")); + mixin(loadFromSharedLib("sfWindow_Destroy")); + mixin(loadFromSharedLib("sfWindow_Close")); + mixin(loadFromSharedLib("sfWindow_IsOpened")); + mixin(loadFromSharedLib("sfWindow_GetWidth")); + mixin(loadFromSharedLib("sfWindow_GetHeight")); + mixin(loadFromSharedLib("sfWindow_GetSettings")); + mixin(loadFromSharedLib("sfWindow_GetEvent")); + mixin(loadFromSharedLib("sfWindow_UseVerticalSync")); + mixin(loadFromSharedLib("sfWindow_ShowMouseCursor")); + mixin(loadFromSharedLib("sfWindow_SetCursorPosition")); + mixin(loadFromSharedLib("sfWindow_SetPosition")); + mixin(loadFromSharedLib("sfWindow_SetSize")); + mixin(loadFromSharedLib("sfWindow_Show")); + mixin(loadFromSharedLib("sfWindow_EnableKeyRepeat")); + mixin(loadFromSharedLib("sfWindow_SetIcon")); + mixin(loadFromSharedLib("sfWindow_SetActive")); + mixin(loadFromSharedLib("sfWindow_Display")); + mixin(loadFromSharedLib("sfWindow_GetInput")); + mixin(loadFromSharedLib("sfWindow_SetFramerateLimit")); + mixin(loadFromSharedLib("sfWindow_GetFrameTime")); + mixin(loadFromSharedLib("sfWindow_SetJoystickThreshold")); + mixin(loadFromSharedLib("sfWindow_WaitEvent")); } -} +} \ No newline at end of file