From dcdf39bf74b746f2c4a10d49e73815a773448253 Mon Sep 17 00:00:00 2001 From: trass3r Date: Tue, 16 Mar 2010 02:04:52 +0000 Subject: [PATCH] * D-ified property functions and used SFMLClass in: - Window - RenderTargets - Image - Drawable * fixed Image.copy -> copyImage git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1461 4e206d99-4929-0410-ac5d-dfc041789085 --- DSFML/import/dsfml/graphics/drawableimpl.d | 143 ++-- DSFML/import/dsfml/graphics/image.d | 183 +++--- DSFML/import/dsfml/graphics/irendertarget.d | 105 +-- DSFML/import/dsfml/graphics/renderimage.d | 299 ++++----- DSFML/import/dsfml/graphics/renderwindow.d | 317 ++++----- DSFML/import/dsfml/window/window.d | 694 ++++++++++---------- 6 files changed, 844 insertions(+), 897 deletions(-) diff --git a/DSFML/import/dsfml/graphics/drawableimpl.d b/DSFML/import/dsfml/graphics/drawableimpl.d index 2360d44be..3d8b2fd10 100644 --- a/DSFML/import/dsfml/graphics/drawableimpl.d +++ b/DSFML/import/dsfml/graphics/drawableimpl.d @@ -42,7 +42,7 @@ import dsfml.graphics.idrawable, * Package base class of all drawable. * Provide implementation of IDrawable and functions aliases. */ -package class DrawableImpl(alias derivedClassName) : DSFMLObject, IDrawable +package class DrawableImpl(string derivedClassName) : DSFMLObject, IDrawable { protected: this() @@ -50,7 +50,7 @@ protected: super(sfDrawable_Create()); } - this(void* ptr) + this(SFMLClass ptr) { super(ptr, true); } @@ -210,107 +210,58 @@ public: private: - extern (C) + static extern(C) { - typedef void* function() pf_sfDrawable_Create; - typedef void function(void*) pf_sfDrawable_Destroy; - typedef void function(void*, float) pf_sfDrawable_SetX; - typedef void function(void*, float) pf_sfDrawable_SetY; - typedef void function(void*, float, float) pf_sfDrawable_SetPosition; - typedef void function(void*, float) pf_sfDrawable_SetScaleX; - typedef void function(void*, float) pf_sfDrawable_SetScaleY; - typedef void function(void*, float, float) pf_sfDrawable_SetScale; - typedef void function(void*, float) pf_sfDrawable_SetRotation; - typedef void function(void*, float, float) pf_sfDrawable_SetOrigin; - typedef void function(void*, Color) pf_sfDrawable_SetColor; - typedef void function(void*, BlendMode) pf_sfDrawable_SetBlendMode; - typedef float function(void*) pf_sfDrawable_GetX; - typedef float function(void*) pf_sfDrawable_GetY; - typedef float function(void*) pf_sfDrawable_GetScaleX; - typedef float function(void*) pf_sfDrawable_GetScaleY; - typedef float function(void*) pf_sfDrawable_GetRotation; - typedef float function(void*) pf_sfDrawable_GetOriginX; - typedef float function(void*) pf_sfDrawable_GetOriginY; - typedef Color function(void*) pf_sfDrawable_GetColor; - typedef BlendMode function(void*) pf_sfDrawable_GetBlendMode; - typedef void function(void*, float, float) pf_sfDrawable_Move; - typedef void function(void*, float, float) pf_sfDrawable_Scale; - typedef void function(void*, float) pf_sfDrawable_Rotate; - typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToLocal; - typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToGlobal; + 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(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; + 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; - static pf_sfDrawable_Create sfDrawable_Create; - static pf_sfDrawable_Destroy sfDrawable_Destroy; - static pf_sfDrawable_SetX sfDrawable_SetX; - static pf_sfDrawable_SetY sfDrawable_SetY; - static pf_sfDrawable_SetPosition sfDrawable_SetPosition; - static pf_sfDrawable_SetScaleX sfDrawable_SetScaleX; - static pf_sfDrawable_SetScaleY sfDrawable_SetScaleY; - static pf_sfDrawable_SetScale sfDrawable_SetScale; - static pf_sfDrawable_SetRotation sfDrawable_SetRotation; - static pf_sfDrawable_SetOrigin sfDrawable_SetOrigin; - static pf_sfDrawable_SetColor sfDrawable_SetColor; - static pf_sfDrawable_SetBlendMode sfDrawable_SetBlendMode; - static pf_sfDrawable_GetX sfDrawable_GetX; - static pf_sfDrawable_GetY sfDrawable_GetY; - static pf_sfDrawable_GetScaleX sfDrawable_GetScaleX; - static pf_sfDrawable_GetScaleY sfDrawable_GetScaleY; - static pf_sfDrawable_GetRotation sfDrawable_GetRotation; - static pf_sfDrawable_GetOriginX sfDrawable_GetOriginX; - static pf_sfDrawable_GetOriginY sfDrawable_GetOriginY; - static pf_sfDrawable_GetColor sfDrawable_GetColor; - static pf_sfDrawable_GetBlendMode sfDrawable_GetBlendMode; - static pf_sfDrawable_Move sfDrawable_Move; - static pf_sfDrawable_Scale sfDrawable_Scale; - static pf_sfDrawable_Rotate sfDrawable_Rotate; - static pf_sfDrawable_TransformToLocal sfDrawable_TransformToLocal; - static pf_sfDrawable_TransformToGlobal sfDrawable_TransformToGlobal; - - static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis; - static pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader; - static pf_sfRenderImage_DrawThis sfRenderImage_DrawThis; - static pf_sfRenderImage_DrawThisWithShader 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"); - - sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(derivedClassName ~ "_Create"); - sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(derivedClassName ~ "_Destroy"); - sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(derivedClassName ~ "_SetX"); - sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(derivedClassName ~ "_SetY"); - sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(derivedClassName ~ "_SetPosition"); - sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(derivedClassName ~ "_SetScaleX"); - sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(derivedClassName ~ "_SetScaleY"); - sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(derivedClassName ~ "_SetScale"); - sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(derivedClassName ~ "_SetRotation"); - sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(derivedClassName ~ "_SetOrigin"); - sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(derivedClassName ~ "_SetColor"); - sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(derivedClassName ~ "_SetBlendMode"); - sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(derivedClassName ~ "_GetX"); - sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(derivedClassName ~ "_GetY"); - sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(derivedClassName ~ "_GetScaleX"); - sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(derivedClassName ~ "_GetScaleX"); - sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(derivedClassName ~ "_GetRotation"); - sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(derivedClassName ~ "_GetOriginX"); - sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(derivedClassName ~ "_GetOriginY"); - sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(derivedClassName ~ "_GetColor"); - sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(derivedClassName ~ "_GetBlendMode"); - sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(derivedClassName ~ "_Move"); - sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(derivedClassName ~ "_Scale"); - sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(derivedClassName ~ "_Rotate"); - sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(derivedClassName ~ "_TransformToLocal"); - sfDrawable_TransformToGlobal= cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(derivedClassName ~ "_TransformToGlobal"); - + 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..$]); diff --git a/DSFML/import/dsfml/graphics/image.d b/DSFML/import/dsfml/graphics/image.d index 2f902e7e4..42988acd0 100644 --- a/DSFML/import/dsfml/graphics/image.d +++ b/DSFML/import/dsfml/graphics/image.d @@ -29,6 +29,7 @@ module dsfml.graphics.image; import dsfml.graphics.color, dsfml.graphics.rect; +// dsfml.graphics.renderwindow; import dsfml.system.common, dsfml.system.exception, @@ -42,7 +43,7 @@ import dsfml.system.common, class Image : DSFMLObject { package: - this(void* ptr) + this(SFMLClass ptr) { super(ptr, true); } @@ -169,23 +170,25 @@ public: { sfImage_CreateMaskFromColor(m_ptr, colorKey, alpha); } - -// /** -// * Create the image from the current contents of the -// * given window -// * -// * Params: -// * window = Window to capture -// * sourceRect = Sub-rectangle of the screen to copy (empty by default - entire image) -// * -// * Returns: -// * True if copy was successful -// */ -// void copyScreen(RenderWindow window, IntRect sourceRect = IntRect()) -// { -// return cast(bool)sfImage_CopyScreen(m_ptr, window.nativePointer, sourceRect); -// } - + +/+ + /** + * 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 @@ -197,9 +200,9 @@ public: * 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 = IntRect()) + void copyImage(Image source, uint destX, uint destY, IntRect sourceRect = IntRect()) { - sfImage_Copy(m_ptr, source.nativePointer, destX, destY, sourceRect); + sfImage_CopyImage(m_ptr, source.nativePointer, destX, destY, sourceRect); } /** @@ -241,7 +244,7 @@ public: */ ubyte[] getPixelsArray() { - return sfImage_GetPixelsPtr(m_ptr)[0..getWidth() * getHeight() * 4]; + return sfImage_GetPixelsPtr(m_ptr)[0..width() * height() * 4]; } /** @@ -252,51 +255,6 @@ public: sfImage_Bind(m_ptr); } - /** - * Enable or disable image smooth filter. - * This parameter is enabled by default - * - * Params: - * smooth = True to enable smoothing filter, false to disable it - */ - void setSmooth(bool smooth) - { - sfImage_SetSmooth(m_ptr, smooth); - } - - /** - * Return the width of the image - * - * Returns: - * Width in pixels - */ - uint getWidth() - { - return sfImage_GetWidth(m_ptr); - } - - /** - * Return the height of the image - * - * Returns: - * Height in pixels - */ - uint getHeight() - { - return sfImage_GetHeight(m_ptr); - } - - /** - * Tells whether the smooth filtering is enabled or not - * - * Returns: - * True if image smoothing is enabled - */ - bool isSmooth() - { - return cast(bool)sfImage_IsSmooth(m_ptr); - } - /** * Update a sub-rectangle of the image from an array of pixels * @@ -313,33 +271,82 @@ public: { 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) { - 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; - void function(void*, ubyte*, IntRect) sfImage_UpdatePixels; + 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", "CopyScreen", "Copy", "SetPixel", "GetPixel", "GetPixelsPtr", "Bind", "SetSmooth", "GetWidth", - "GetHeight", "IsSmooth", "UpdatePixels")); + "Create", "CreateFromColor", "CreateFromPixels", "CreateFromFile", "CreateFromMemory", "Destroy", "SaveToFile", + "CreateMaskFromColor", "Copy", "CopyScreen", "CopyImage", "SetPixel", "GetPixel", "GetPixelsPtr", "Bind", "SetSmooth", "GetWidth", + "GetHeight", "IsSmooth", "UpdatePixels")); } \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/irendertarget.d b/DSFML/import/dsfml/graphics/irendertarget.d index 8a901502e..9a9e92c5f 100644 --- a/DSFML/import/dsfml/graphics/irendertarget.d +++ b/DSFML/import/dsfml/graphics/irendertarget.d @@ -59,58 +59,6 @@ interface IRenderTarget */ void draw(IDrawable object, Shader shader); - /** - * Get the width of the rendering region of the target - * - * \return Width in pixels - * - */ - uint getWidth(); - - /** - * Get the height of the rendering region of the target - * - * \return Height in pixels - * - */ - uint getHeight(); - - /** - * Change the current active view. - * - * \param view : New view to use (pass GetDefaultView() to set the default view) - * - */ - void setView(View view); - - /** - * Get the current view - * - * \return Current view active in the window - * - */ - View getView(); - - /** - * Get the default view of the window - * - * \return Default view - * - */ - View getDefaultView(); - - /** - * 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 getViewport(View view); - - - /** * Convert a point in target coordinates into view coordinates * @@ -134,4 +82,57 @@ interface IRenderTarget * */ 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); +} } \ No newline at end of file diff --git a/DSFML/import/dsfml/graphics/renderimage.d b/DSFML/import/dsfml/graphics/renderimage.d index 2754f1b43..a0d4db57e 100644 --- a/DSFML/import/dsfml/graphics/renderimage.d +++ b/DSFML/import/dsfml/graphics/renderimage.d @@ -51,11 +51,16 @@ private: View _defaultView = null; package: - this(void* ptr) + this(SFMLClass ptr) { super(ptr, true); } - + + override void dispose() + { + sfRenderImage_Destroy(m_ptr); + } + public: /** @@ -70,46 +75,6 @@ public: { 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); - } /** * Update the contents of the target image @@ -151,64 +116,7 @@ public: { 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.nativePointer); - - _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(View view = null) // TODO: is there a need to accept other Views than the currently assigned one? - { - return sfRenderImage_GetViewport(m_ptr, view is null ? _view.nativePointer : view.nativePointer); - } - /** * Convert a point in image coordinates into view coordinates * @@ -227,32 +135,7 @@ public: 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(); - } + /** * Save the current OpenGL render states and matrices @@ -270,36 +153,158 @@ public: 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) { - 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_Display; + 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(void*, void*) sfRenderImage_DrawSprite; - void function(void*, void*) sfRenderImage_DrawShape; - void function(void*, void*) sfRenderImage_DrawText; + void function(SFMLClass, void*) sfRenderImage_DrawSprite; + void function(SFMLClass, void*) sfRenderImage_DrawShape; + void function(SFMLClass, 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(SFMLClass, void*, void*) sfRenderImage_DrawSpriteWithShader; + void function(SFMLClass, void*, void*) sfRenderImage_DrawShapeWithShader; + void function(SFMLClass, 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; + 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(void*) sfRenderImage_SaveGLStates; - void function(void*) sfRenderImage_RestoreGLStates; + void function(SFMLClass) sfRenderImage_SaveGLStates; + void function(SFMLClass) sfRenderImage_RestoreGLStates; } mixin(loadFromSharedLib2("csfml-graphics", "sfRenderImage", "Create", "Destroy", "GetWidth", "GetHeight", diff --git a/DSFML/import/dsfml/graphics/renderwindow.d b/DSFML/import/dsfml/graphics/renderwindow.d index 7058b5d17..04fb9c835 100644 --- a/DSFML/import/dsfml/graphics/renderwindow.d +++ b/DSFML/import/dsfml/graphics/renderwindow.d @@ -30,7 +30,6 @@ import dsfml.graphics.color, dsfml.graphics.sprite, dsfml.graphics.shape, dsfml.graphics.text, - dsfml.graphics.image, dsfml.graphics.rect, dsfml.graphics.shader, dsfml.graphics.view, @@ -48,8 +47,8 @@ import dsfml.system.common, dsfml.system.vector2; /** -* Simple wrapper for Window that allows easy 2D rendering. -*/ + * Simple wrapper for Window that allows easy 2D rendering. + */ class RenderWindow : Window, IRenderTarget { private: @@ -59,27 +58,27 @@ private: 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, uint windowStyle = Style.Default, ContextSettings settings = ContextSettings()) + * 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) - */ + * 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)); @@ -92,18 +91,18 @@ public: } /** - * 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) - * - */ - void create(VideoMode mode, string title, uint windowStyle = Style.Default, ContextSettings settings = ContextSettings()) + * 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(); @@ -113,16 +112,16 @@ public: } /** - * 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) - * - */ - void create(WindowHandle handle, ContextSettings settings = ContextSettings()) + * 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(); @@ -132,102 +131,52 @@ public: } /** - * Draw a sprite, shape or text on the window with a shader - * - * Params: - * drawable = IDrawable to draw - * shader = Shader to use - */ + * 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 - */ + * 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 - */ + * Clear the screen with the given color. + * + * Params: + * col = Fill color + */ void clear(Color col = Color.BLACK) { sfRenderWindow_Clear(m_ptr, col); } - /** - * Change the current active view. - * The current view is defined with the initial size of the window - * - * Params: - * newView = Pointer to the new view (pass getDefaultView to set the default view) - */ - void setView(View newView) - { - if (m_view !is null) - { - m_view.setHandled(false); - } - - sfRenderWindow_SetView(m_ptr, newView.nativePointer); - - m_view = newView; - m_view.setHandled(true); - } + /** - * Get the current view rectangle - * - * Returns: - * current view rectangle, in global coordinates - */ - View getView() - { - if (m_view is null) - { - void* cView = sfRenderWindow_GetView(m_ptr); - m_view = new View(cView, true); - } - return m_view; - } - - /** - * Get the default view - * - * Returns: - * default view - */ - View getDefaultView() - { - if (m_defaultView is null) - { - void* cView = sfRenderWindow_GetDefaultView(m_ptr); - m_defaultView = new View(cView, true); - } - return m_defaultView; - } - - /** - * Convert a point in window coordinates into view coordinates - * - * Params: - * windowX = X coordinate of the point to convert, relative to the window - * windowY = Y coordinate of the point to convert, relative to the window - * targetView = Target view to convert the point to (pass NULL to use the current view) - * - * Returns: - * Converted point - */ + * 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; @@ -251,67 +200,129 @@ public: 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); + } /** - * Return the width of the rendering region of a renderwindow - * - * Returns: - * Width in pixels - */ - uint getWidth() + * 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 - */ - uint getHeight() + * Return the height of the rendering region of a renderwindow + * + * Returns: + * Height in pixels + */ + override uint height() { return sfRenderWindow_GetHeight(m_ptr); } - IntRect getViewport(View view = null) // TODO: is there a need to accept other Views than the currently assigned one? + /** + * 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, view is null ? m_view.nativePointer : view.nativePointer); + return sfRenderWindow_GetViewport(m_ptr, v is null ? m_view.nativePointer : v.nativePointer); } +} private: static extern(C) { - void* function(VideoMode, cchar*, uint, ContextSettings*) sfRenderWindow_Create; - void* function(WindowHandle, ContextSettings*) sfRenderWindow_CreateFromHandle; - void function(void*) sfRenderWindow_Destroy; - void* function(void*) sfRenderWindow_GetInput; - bool function(void*) sfRenderWindow_IsOpened; - uint function(void*) sfRenderWindow_GetWidth; - uint function(void*) sfRenderWindow_GetHeight; + 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(void*, void*) sfRenderWindow_DrawSprite; - void function(void*, void*) sfRenderWindow_DrawShape; - void function(void*, void*) sfRenderWindow_DrawText; + void function(SFMLClass, SFMLClass) sfRenderWindow_DrawSprite; + void function(SFMLClass, SFMLClass) sfRenderWindow_DrawShape; + void function(SFMLClass, SFMLClass) sfRenderWindow_DrawText; - void function(void*, void*, void*) sfRenderWindow_DrawSpriteWithShader; - void function(void*, void*, void*) sfRenderWindow_DrawShapeWithShader; - void function(void*, void*, void*) sfRenderWindow_DrawTextWithShader; + void function(SFMLClass, SFMLClass, SFMLClass) sfRenderWindow_DrawSpriteWithShader; + void function(SFMLClass, SFMLClass, SFMLClass) sfRenderWindow_DrawShapeWithShader; + void function(SFMLClass, SFMLClass, SFMLClass) 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; + 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(void*) sfRenderWindow_SaveGLStates; - void function(void*) sfRenderWindow_RestoreGLStates; - IntRect function(void*, void*) sfRenderWindow_GetViewport; + void function(SFMLClass) sfRenderWindow_SaveGLStates; + void function(SFMLClass) sfRenderWindow_RestoreGLStates; + IntRect function(SFMLClass, SFMLClass) sfRenderWindow_GetViewport; } mixin(loadFromSharedLib2("csfml-graphics", "sfRenderWindow", "Create", "CreateFromHandle", diff --git a/DSFML/import/dsfml/window/window.d b/DSFML/import/dsfml/window/window.d index 7a85e369e..2015ca021 100644 --- a/DSFML/import/dsfml/window/window.d +++ b/DSFML/import/dsfml/window/window.d @@ -1,28 +1,28 @@ /* -* DSFML - SFML Library wrapper for the D programming language. -* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) -* Copyright (C) 2010 Andreas Hollandt -* -* This software is provided 'as-is', without any express or -* implied warranty. In no event will the authors be held -* liable for any damages arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute -* it freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; -* you must not claim that you wrote the original software. -* If you use this software in a product, an acknowledgment -* in the product documentation would be appreciated but -* is not required. -* -* 2. Altered source versions must be plainly marked as such, -* and must not be misrepresented as being the original software. -* -* 3. This notice may not be removed or altered from any -* source distribution. -*/ + * DSFML - SFML Library wrapper for the D programming language. + * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) + * Copyright (C) 2010 Andreas Hollandt + * + * This software is provided 'as-is', without any express or + * implied warranty. In no event will the authors be held + * liable for any damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; + * you must not claim that you wrote the original software. + * If you use this software in a product, an acknowledgment + * in the product documentation would be appreciated but + * is not required. + * + * 2. Altered source versions must be plainly marked as such, + * and must not be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any + * source distribution. + */ module dsfml.window.window; @@ -36,9 +36,9 @@ import dsfml.system.stringutil; /** -* Window style -*/ -enum Style + * Window style + */ +enum Style : uint { None = 0, /// No border / title bar (this flag and all others are mutually exclusive) Titlebar = 1 << 0, /// Title bar + fixed border @@ -51,8 +51,8 @@ enum Style /** -* Structure defining the creation settings of windows -*/ + * Structure defining the creation settings of windows + */ struct ContextSettings { uint DepthBits = 24; /// Bits of the depth buffer @@ -64,322 +64,112 @@ struct ContextSettings /** -* Window is a rendering window ; it can create a new window -* or connect to an existing one -*/ + * Window is a rendering window ; it can create a new window + * or connect to an existing one + */ class Window : DSFMLObject { protected: - this(void* ptr) + this(SFMLClass ptr) { super(ptr); } Input m_input; -public: - /** - * Construct a new 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(sfWindow_Create(mode, toStringz(title), windowStyle, settings)); - } - - /** - * 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(sfWindow_CreateFromHandle(handle, settings)); - } - override void dispose() { m_input = null; sfWindow_Destroy(m_ptr); } +public: /** - * Create (or recreate) the window - * - * Input created with getInput becomes 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) - */ + * Construct a new 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(sfWindow_Create(mode, toStringz(title), windowStyle, &settings)); + } + + /** + * 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(sfWindow_CreateFromHandle(handle, &settings)); + } + + /** + * Create (or recreate) the window + * + * Input created with getInput becomes 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) + */ void create(VideoMode mode, string title, Style windowStyle = Style.Default, ContextSettings settings = ContextSettings()) { if (m_ptr !is null) dispose(); - m_ptr = sfWindow_Create(mode, toStringz(title), windowStyle, settings); + m_ptr = sfWindow_Create(mode, toStringz(title), windowStyle, &settings); } /** - * Create (or recreate) the window from an existing control - * - * Input created with getInput becomes invalid. - * - * Params: - * handle = Platform-specific handle of the control - * settings = Context settings (default is default ContextSettings values) - */ + * Create (or recreate) the window from an existing control + * + * Input created with getInput becomes invalid. + * + * Params: + * handle = Platform-specific handle of the control + * settings = Context settings (default is default ContextSettings values) + */ void create(WindowHandle handle, ContextSettings settings = ContextSettings()) { if (m_ptr !is null) dispose(); - m_ptr = sfWindow_CreateFromHandle(handle, settings); + m_ptr = sfWindow_CreateFromHandle(handle, &settings); } /** - * Close (destroy) the window. - * You can call create to recreate a valid window - */ + * Close (destroy) the window. + * You can call create to recreate a valid window + */ void close() { sfWindow_Close(m_ptr); } - /** - * Tell whether or not a window is opened - * - * Returns: - * True if window is currently open. - */ - bool isOpened() - { - return cast(bool) sfWindow_IsOpened(m_ptr); - } - /** - * Get the width of the rendering region of the window - * - * Returns: - * Width in pixels - */ - uint getWidth() - { - return sfWindow_GetWidth(m_ptr); - } /** - * Get the height of the rendering region of the window - * - * Returns: - * Height in pixels - */ - uint getHeight() - { - return sfWindow_GetHeight(m_ptr); - } - - /** - * Get the creation settings of a window - * - * Returns: - * Settings used to create the window - */ - ContextSettings getSettings() - { - return sfWindow_GetSettings(m_ptr); - } - - - /** - * Get the event on top of events stack, if any, and pop it - * - * Params: - * eventReceived = Event to fill, if any - * - * Returns: - * True if an event was returned, false if events stack was empty - */ + * Get the event on top of events stack, if any, and pop it + * + * Params: + * eventReceived = Event to fill, if any + * + * Returns: + * True if an event was returned, false if events stack was empty + */ bool getEvent(out Event eventReceived) { return cast(bool) sfWindow_GetEvent(m_ptr, &eventReceived); } - - /** - * Enable / disable vertical synchronization - * - * Params: - * enabled : True to enable v-sync, false to deactivate - */ - void useVerticalSync(bool enabled) - { - sfWindow_UseVerticalSync(m_ptr, enabled); - } - - /** - * Show or hide the mouse cursor - * - * Params: - * show : True to show, false to hide - */ - void showMouseCursor(bool show) - { - sfWindow_ShowMouseCursor(m_ptr, show); - } - - /** - * Change the position of the mouse cursor - * - * Params: - * left = Left coordinate of the cursor, relative to the window - * top = Top coordinate of the cursor, relative to the window - */ - void setCursorPosition(uint left, uint top) - { - sfWindow_SetCursorPosition(m_ptr, left, top); - } - - /** - * Change the position of the window on screen. - * Only works for top-level windows - * - * Params: - * left = Left position - * top = Top position - */ - void setPosition(int left, int top) - { - sfWindow_SetPosition(m_ptr, left, top); - } - /** - * change the size of the rendering region of the window - * - * Params: - * width : new width - * height : new height - */ - void setSize(uint width, uint height) - { - sfWindow_SetSize(m_ptr, width, height); - } - - /** - * Show or hide the window - * - * Params: - * state = True to show, false to hide - * - */ - void show(bool state) - { - sfWindow_Show(m_ptr, state); - } - - /** - * Enable or disable automatic key-repeat for keydown events. - * Automatic key-repeat is enabled by default. - * - * Params: - * enabled = true to enable, false to disable - */ - void enableKeyRepeat(bool enabled) - { - sfWindow_EnableKeyRepeat(m_ptr, enabled); - } - - /** - * Change the window's icon - * - * Params: - * width = Icon's width, in pixels - * height = Icon's height, in pixels - * data = array of pixels in memory, format must be RGBA 32 bits - * - */ - void setIcon(size_t width, size_t height, ubyte[] data) - { - sfWindow_SetIcon(m_ptr, width, height, data.ptr); - } - - /** - * Set the window 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 = true) - { - return cast(bool)sfWindow_SetActive(m_ptr, active); - } - - /** - * Display the window on screen - */ - void display() - { - sfWindow_Display(m_ptr); - } - - /** - * Get the input manager of the window - * - * Returns: - * An input manager - * See_Also : - * Input - */ - Input getInput() - { - if (m_input is null) - m_input = new Input(sfWindow_GetInput(m_ptr)); - return m_input; - } - - /** - * Limit the framerate to a maximum fixed frequency - * - * Params: - * limit : Framerate limit, in frames per seconds (use 0 to disable limit) - */ - void setFramerateLimit(uint limit) - { - sfWindow_SetFramerateLimit(m_ptr, limit); - } - - /** - * Get the time the last frame took - * - * Returns: - * time in seconds - */ - float getFrameTime() - { - return sfWindow_GetFrameTime(m_ptr); - } - - /** - * Change the joystick threshold, ie. the value below which - * no move event will be generated - * - * Params: - * threshold : New threshold, in range [0, 100] - */ - void setJoystickThreshold(float threshold) - { - sfWindow_SetJoystickThreshold(m_ptr, threshold); - } - /** * Wait for an event and return it * @@ -399,72 +189,254 @@ public: return sfWindow_WaitEvent(m_ptr, &e); } + /** + * Show or hide the window + * + * Params: + * state = True to show, false to hide + * + */ + void show(bool state) + { + sfWindow_Show(m_ptr, state); + } + + /** + * Display the window on screen + */ + void display() + { + sfWindow_Display(m_ptr); + } + +@property +{ + /** + * Tell whether or not a window is opened + * + * Returns: + * True if window is currently open. + */ + bool isOpened() + { + return cast(bool) sfWindow_IsOpened(m_ptr); + } + /** + * Get the width of the rendering region of the window + * + * Returns: + * Width in pixels + */ + uint width() + { + return sfWindow_GetWidth(m_ptr); + } + + /** + * Get the height of the rendering region of the window + * + * Returns: + * Height in pixels + */ + uint height() + { + return sfWindow_GetHeight(m_ptr); + } + + /** + * Get the creation settings of a window + * + * Returns: + * Settings used to create the window + */ + ContextSettings settings() + { + return sfWindow_GetSettings(m_ptr); + } + + /** + * Enable / disable vertical synchronization + * + * Params: + * enabled : True to enable v-sync, false to deactivate + */ + void useVerticalSync(bool enabled) + { + sfWindow_UseVerticalSync(m_ptr, enabled); + } + + /** + * Show or hide the mouse cursor + * + * Params: + * show : True to show, false to hide + */ + void showMouseCursor(bool show) + { + sfWindow_ShowMouseCursor(m_ptr, show); + } + + /** + * Enable or disable automatic key-repeat for keydown events. + * Automatic key-repeat is enabled by default. + * + * Params: + * enabled = true to enable, false to disable + */ + void enableKeyRepeat(bool enabled) + { + sfWindow_EnableKeyRepeat(m_ptr, enabled); + } + + /** + * Set the window 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 active) + { + return cast(bool)sfWindow_SetActive(m_ptr, active); + } + + /** + * Get the input manager of the window + * + * Returns: + * An input manager + * See_Also : + * Input + */ + Input input() + { + if (m_input is null) + m_input = new Input(sfWindow_GetInput(m_ptr)); + return m_input; + } + + /** + * Limit the framerate to a maximum fixed frequency + * + * Params: + * limit : Framerate limit, in frames per seconds (use 0 to disable limit) + */ + void framerateLimit(uint limit) + { + sfWindow_SetFramerateLimit(m_ptr, limit); + } + + /** + * Get the time the last frame took + * + * Returns: + * time in seconds + */ + float frameTime() + { + return sfWindow_GetFrameTime(m_ptr); + } + + /** + * Change the joystick threshold, ie. the value below which + * no move event will be generated + * + * Params: + * threshold : New threshold, in range [0, 100] + */ + void joystickThreshold(float threshold) + { + sfWindow_SetJoystickThreshold(m_ptr, threshold); + } +} + + /** + * Change the position of the mouse cursor + * + * Params: + * left = Left coordinate of the cursor, relative to the window + * top = Top coordinate of the cursor, relative to the window + */ + void setCursorPosition(uint left, uint top) + { + sfWindow_SetCursorPosition(m_ptr, left, top); + } + + /** + * Change the position of the window on screen. + * Only works for top-level windows + * + * Params: + * left = Left position + * top = Top position + */ + void setPosition(int left, int top) + { + sfWindow_SetPosition(m_ptr, left, top); + } + + /** + * change the size of the rendering region of the window + * + * Params: + * width : new width + * height : new height + */ + void setSize(uint width, uint height) + { + sfWindow_SetSize(m_ptr, width, height); + } + + /** + * Change the window's icon + * + * Params: + * width = Icon's width, in pixels + * height = Icon's height, in pixels + * data = array of pixels in memory, format must be RGBA 32 bits + * + */ + void setIcon(size_t width, size_t height, ubyte[] data) + { + sfWindow_SetIcon(m_ptr, width, height, data.ptr); + } + private: // External ==================================================================== - extern (C) + static extern(C) { - 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; + SFMLClass function(VideoMode, cchar*, Style, ContextSettings*)sfWindow_Create; + SFMLClass function(WindowHandle, ContextSettings*) sfWindow_CreateFromHandle; + void function(SFMLClass) sfWindow_Destroy; + void function(SFMLClass) sfWindow_Close; + int function(SFMLClass) sfWindow_IsOpened; + uint function(SFMLClass) sfWindow_GetWidth; + uint function(SFMLClass) sfWindow_GetHeight; + ContextSettings function(SFMLClass Window) sfWindow_GetSettings; + int function(SFMLClass, Event*) sfWindow_GetEvent; + void function(SFMLClass, int) sfWindow_UseVerticalSync; + void function(SFMLClass, int) sfWindow_ShowMouseCursor; + void function(SFMLClass, uint, uint) sfWindow_SetCursorPosition; + void function(SFMLClass, int, int) sfWindow_SetPosition; + void function(SFMLClass, uint, uint) sfWindow_SetSize; + void function(SFMLClass, int) sfWindow_Show; + void function(SFMLClass, int) sfWindow_EnableKeyRepeat; + void function(SFMLClass, size_t, size_t, ubyte*) sfWindow_SetIcon; + int function(SFMLClass, int) sfWindow_SetActive; + void function(SFMLClass) sfWindow_Display; + SFMLClass function(SFMLClass) sfWindow_GetInput; + void function(SFMLClass, uint) sfWindow_SetFramerateLimit; + float function(SFMLClass) sfWindow_GetFrameTime; + void function(SFMLClass, float) sfWindow_SetJoystickThreshold; // DSFML2 - bool function(void*, void*) sfWindow_WaitEvent; - } + bool function(SFMLClass, void*) sfWindow_WaitEvent; } - static this() - { - debug - DllLoader dll = DllLoader.load("csfml-window-d"); - else - DllLoader dll = DllLoader.load("csfml-window"); - - 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")); - } + mixin(loadFromSharedLib2("csfml-window", "sfWindow", + "Create", "CreateFromHandle", "Destroy", "Close", "IsOpened", "GetWidth", "GetHeight", "GetSettings", "GetEvent", "UseVerticalSync", + "ShowMouseCursor", "SetCursorPosition", "SetPosition", "SetSize", "Show", "EnableKeyRepeat", "SetIcon", "SetActive", "Display", + "GetInput", "SetFramerateLimit", "GetFrameTime", "SetJoystickThreshold", "WaitEvent")); } \ No newline at end of file