replaced all crappy spaces with proper tabs

kept this in its own changeset so it doesn't interfere with real changes

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1334 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-01-06 20:37:29 +00:00
parent 8431753ba3
commit 2f2fc5d4fa
56 changed files with 8094 additions and 8094 deletions

View file

@ -1,37 +1,37 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.all; module dsfml.audio.all;
public import public import
dsfml.audio.listener, dsfml.audio.listener,
dsfml.audio.music, dsfml.audio.music,
dsfml.audio.sound, dsfml.audio.sound,
dsfml.audio.soundbuffer, dsfml.audio.soundbuffer,
dsfml.audio.soundbufferrecorder, dsfml.audio.soundbufferrecorder,
dsfml.audio.soundrecorder, dsfml.audio.soundrecorder,
dsfml.audio.soundstatus, dsfml.audio.soundstatus,
dsfml.audio.soundstream; dsfml.audio.soundstream;

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.listener; module dsfml.audio.listener;
@ -30,122 +30,122 @@ import dsfml.system.common;
import dsfml.system.vector3; import dsfml.system.vector3;
/** /**
* Listener is a global interface for defining the audio * Listener is a global interface for defining the audio
* listener properties ; the audio listener is the point in * listener properties ; the audio listener is the point in
* the scene from where all the sounds are heard. * the scene from where all the sounds are heard.
* *
* See_Also: * See_Also:
* SFML Tutorial for sound spatialization example. * SFML Tutorial for sound spatialization example.
*/ */
class Listener class Listener
{ {
/** /**
* Change the global volume of all the sounds. * Change the global volume of all the sounds.
* The default volume is 100 * The default volume is 100
* *
* Params: * Params:
* volume = New global volume, in the range [0, 100] * volume = New global volume, in the range [0, 100]
*/ */
static void setGlobalVolume(float volume) static void setGlobalVolume(float volume)
in in
{ {
assert (volume >= 0.f && volume <= 100.f); assert (volume >= 0.f && volume <= 100.f);
} }
body body
{ {
sfListener_SetGlobalVolume(volume); sfListener_SetGlobalVolume(volume);
} }
/** /**
* Get the current value of the global volume of all the sounds * Get the current value of the global volume of all the sounds
* *
* Returns: * Returns:
* Current global volume, in the range [0, 100] * Current global volume, in the range [0, 100]
*/ */
static float getGlobalVolume() static float getGlobalVolume()
{ {
return sfListener_GetGlobalVolume(); return sfListener_GetGlobalVolume();
} }
/** /**
* Change the position of the listener. * Change the position of the listener.
* The default position is (0, 0, 0) * The default position is (0, 0, 0)
* *
* Params: * Params:
* posX = X position of the listener in the world * posX = X position of the listener in the world
* posY = Y position of the listener in the world * posY = Y position of the listener in the world
* posZ = Z position of the listener in the world * posZ = Z position of the listener in the world
*/ */
static void setPosition(float posX, float posY, float posZ) static void setPosition(float posX, float posY, float posZ)
{ {
sfListener_SetPosition(posX, posY, posZ); sfListener_SetPosition(posX, posY, posZ);
} }
/** /**
* Change the position of the listener. * Change the position of the listener.
* The default position is (0, 0, 0) * The default position is (0, 0, 0)
* *
* Params: * Params:
* position = new position * position = new position
*/ */
static void setPosition(Vector3f position) static void setPosition(Vector3f position)
{ {
sfListener_SetPosition(position.x, position.y, position.z); sfListener_SetPosition(position.x, position.y, position.z);
} }
/** /**
* Get the current position of the listener * Get the current position of the listener
* *
* Returns: * Returns:
* Current position * Current position
*/ */
static Vector3f getPosition() static Vector3f getPosition()
{ {
Vector3f ret; Vector3f ret;
sfListener_GetPosition(&ret.x, &ret.y, &ret.z); sfListener_GetPosition(&ret.x, &ret.y, &ret.z);
return ret; return ret;
} }
/** /**
* Change the orientation of the listener (the point * Change the orientation of the listener (the point
* he must look at). * he must look at).
* The default target is (0, 0, -1) * The default target is (0, 0, -1)
* *
* Params: * Params:
* targetX = X position of the point the listener must look at * targetX = X position of the point the listener must look at
* targetY = X position of the point the listener must look at * targetY = X position of the point the listener must look at
* targetZ = X position of the point the listener must look at * targetZ = X position of the point the listener must look at
*/ */
static void setTarget(float targetX, float targetY, float targetZ) static void setTarget(float targetX, float targetY, float targetZ)
{ {
sfListener_SetTarget(targetX, targetY, targetZ); sfListener_SetTarget(targetX, targetY, targetZ);
} }
/** /**
* Change the orientation of the listener (the point * Change the orientation of the listener (the point
* he must look at). * he must look at).
* The default target is (0, 0, -1) * The default target is (0, 0, -1)
* *
* Params: * Params:
* target = Position of the point the listener must look at * target = Position of the point the listener must look at
*/ */
static void setTarget(Vector3f position) static void setTarget(Vector3f position)
{ {
sfListener_SetTarget(position.x, position.y, position.z); sfListener_SetTarget(position.x, position.y, position.z);
} }
/** /**
* Get the current orientation of the listener (the point * Get the current orientation of the listener (the point
* he's looking at) * he's looking at)
* *
* Returns: * Returns:
* Position of the point the listener is looking at * Position of the point the listener is looking at
*/ */
static Vector3f getTarget() static Vector3f getTarget()
{ {
Vector3f ret; Vector3f ret;
sfListener_GetTarget(&ret.x, &ret.y, &ret.z); sfListener_GetTarget(&ret.x, &ret.y, &ret.z);
return ret; return ret;
} }
@ -154,35 +154,35 @@ private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void function(float) pf_sfListener_SetGlobalVolume; typedef void function(float) pf_sfListener_SetGlobalVolume;
typedef float function() pf_sfListener_GetGlobalVolume; typedef float function() pf_sfListener_GetGlobalVolume;
typedef void function(float, float, float) pf_sfListener_SetPosition; typedef void function(float, float, float) pf_sfListener_SetPosition;
typedef void function(float*, float*, float*) pf_sfListener_GetPosition; typedef void function(float*, float*, float*) pf_sfListener_GetPosition;
typedef void function(float, float, float) pf_sfListener_SetTarget; typedef void function(float, float, float) pf_sfListener_SetTarget;
typedef void function(float*, float*, float*) pf_sfListener_GetTarget; typedef void function(float*, float*, float*) pf_sfListener_GetTarget;
static pf_sfListener_SetGlobalVolume sfListener_SetGlobalVolume; static pf_sfListener_SetGlobalVolume sfListener_SetGlobalVolume;
static pf_sfListener_GetGlobalVolume sfListener_GetGlobalVolume; static pf_sfListener_GetGlobalVolume sfListener_GetGlobalVolume;
static pf_sfListener_SetPosition sfListener_SetPosition; static pf_sfListener_SetPosition sfListener_SetPosition;
static pf_sfListener_GetPosition sfListener_GetPosition; static pf_sfListener_GetPosition sfListener_GetPosition;
static pf_sfListener_SetTarget sfListener_SetTarget; static pf_sfListener_SetTarget sfListener_SetTarget;
static pf_sfListener_GetTarget sfListener_GetTarget; static pf_sfListener_GetTarget sfListener_GetTarget;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-audio-d"); DllLoader dll = DllLoader.load("csfml-audio-d");
else else
DllLoader dll = DllLoader.load("csfml-audio"); DllLoader dll = DllLoader.load("csfml-audio");
sfListener_SetGlobalVolume = cast(pf_sfListener_SetGlobalVolume)dll.getSymbol("sfListener_SetGlobalVolume"); sfListener_SetGlobalVolume = cast(pf_sfListener_SetGlobalVolume)dll.getSymbol("sfListener_SetGlobalVolume");
sfListener_GetGlobalVolume = cast(pf_sfListener_GetGlobalVolume)dll.getSymbol("sfListener_GetGlobalVolume"); sfListener_GetGlobalVolume = cast(pf_sfListener_GetGlobalVolume)dll.getSymbol("sfListener_GetGlobalVolume");
sfListener_SetPosition = cast(pf_sfListener_SetPosition)dll.getSymbol("sfListener_SetPosition"); sfListener_SetPosition = cast(pf_sfListener_SetPosition)dll.getSymbol("sfListener_SetPosition");
sfListener_GetPosition = cast(pf_sfListener_GetPosition)dll.getSymbol("sfListener_GetPosition"); sfListener_GetPosition = cast(pf_sfListener_GetPosition)dll.getSymbol("sfListener_GetPosition");
sfListener_SetTarget = cast(pf_sfListener_SetTarget)dll.getSymbol("sfListener_SetTarget"); sfListener_SetTarget = cast(pf_sfListener_SetTarget)dll.getSymbol("sfListener_SetTarget");
sfListener_GetTarget = cast(pf_sfListener_GetTarget)dll.getSymbol("sfListener_GetTarget"); sfListener_GetTarget = cast(pf_sfListener_GetTarget)dll.getSymbol("sfListener_GetTarget");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.music; module dsfml.audio.music;
@ -39,278 +39,278 @@ import dsfml.system.vector3;
*/ */
class Music : DSFMLObject class Music : DSFMLObject
{ {
/** /**
* Open a music file (doesn't play it -- call Play for that) * Open a music file (doesn't play it -- call Play for that)
* *
* Params: * Params:
* filename = Path of the file to open * filename = Path of the file to open
* *
*/ */
this(string filename) this(string filename)
{ {
if (filename is null || filename.length == 0) if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid."); throw new LoadingException("LoadingException : Filename is invalid.");
super(sfMusic_CreateFromFile(toStringz(filename))); super(sfMusic_CreateFromFile(toStringz(filename)));
} }
/** /**
* Open a music file from memory (doesn't play it -- call Play() for that) * Open a music file from memory (doesn't play it -- call Play() for that)
* *
* Params: * Params:
* data = file data in memory * data = file data in memory
* *
*/ */
this(byte[] data) this(byte[] data)
{ {
if (data is null || data.length == 0) if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid."); throw new Exception("LoadingException : Memory stream is invalid.");
super(m_ptr = sfMusic_CreateFromMemory(data.ptr, data.length)); super(m_ptr = sfMusic_CreateFromMemory(data.ptr, data.length));
} }
override void dispose() override void dispose()
{ {
sfMusic_Destroy(m_ptr); sfMusic_Destroy(m_ptr);
} }
/** /**
* Start playing the audio stream * Start playing the audio stream
*/ */
void play() void play()
{ {
sfMusic_Play(m_ptr); sfMusic_Play(m_ptr);
} }
/** /**
* Stop playing the audio stream * Stop playing the audio stream
*/ */
void stop() void stop()
{ {
sfMusic_Stop(m_ptr); sfMusic_Stop(m_ptr);
} }
/** /**
* Pause the audio stream * Pause the audio stream
*/ */
void pause() void pause()
{ {
sfMusic_Pause(m_ptr); sfMusic_Pause(m_ptr);
} }
/** /**
* Return the number of channels (1 = mono, 2 = stereo) * Return the number of channels (1 = mono, 2 = stereo)
* *
* Returns: * Returns:
* Number of channels * Number of channels
*/ */
uint getChannelsCount() uint getChannelsCount()
{ {
return sfMusic_GetChannelsCount(m_ptr); return sfMusic_GetChannelsCount(m_ptr);
} }
/** /**
* Get the stream sample rate * Get the stream sample rate
* *
* Returns: * Returns:
* Stream frequency (number of samples per second) * Stream frequency (number of samples per second)
*/ */
uint getSampleRate() uint getSampleRate()
{ {
return sfMusic_GetSampleRate(m_ptr); return sfMusic_GetSampleRate(m_ptr);
} }
/** /**
* Get the music duration * Get the music duration
* *
* Returns: * Returns:
* Music duration, in seconds * Music duration, in seconds
*/ */
float getDuration() float getDuration()
{ {
return sfMusic_GetDuration(m_ptr); return sfMusic_GetDuration(m_ptr);
} }
/** /**
* Get the status of the stream (stopped, paused, playing) * Get the status of the stream (stopped, paused, playing)
* *
* Returns: * Returns:
* Current status of the sound * Current status of the sound
*/ */
SoundStatus getStatus() SoundStatus getStatus()
{ {
return sfMusic_GetStatus(m_ptr); return sfMusic_GetStatus(m_ptr);
} }
/** /**
* Tell whether or not the music is looping * Tell whether or not the music is looping
* *
* Returns: * Returns:
* True if the music is looping, false otherwise * True if the music is looping, false otherwise
*/ */
bool getLoop() bool getLoop()
{ {
return cast(bool)sfMusic_GetLoop(m_ptr); return cast(bool)sfMusic_GetLoop(m_ptr);
} }
/** /**
* Get the pitch * Get the pitch
* *
* Returns: * Returns:
* Pitch value * Pitch value
*/ */
float getPitch() float getPitch()
{ {
return sfMusic_GetPitch(m_ptr); return sfMusic_GetPitch(m_ptr);
} }
/** /**
* Get the volume * Get the volume
* *
* Returns: * Returns:
* Volume value (in range [1, 100]) * Volume value (in range [1, 100])
*/ */
float getVolume() float getVolume()
{ {
return sfMusic_GetVolume(m_ptr); return sfMusic_GetVolume(m_ptr);
} }
/** /**
* Get the sound position * Get the sound position
* *
* Returns: * Returns:
* Current position of the music. * Current position of the music.
*/ */
Vector3f getPosition() Vector3f getPosition()
{ {
Vector3f ret; Vector3f ret;
sfMusic_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z); sfMusic_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
return ret; return ret;
} }
/** /**
* Get the minimum distance * Get the minimum distance
* *
* Returns: * Returns:
* Minimum distance for the sound * Minimum distance for the sound
*/ */
float getMinDistance() float getMinDistance()
{ {
return sfMusic_GetMinDistance(m_ptr); return sfMusic_GetMinDistance(m_ptr);
} }
/** /**
* Get the attenuation factor * Get the attenuation factor
* *
* Returns: * Returns:
* Attenuation factor of the sound * Attenuation factor of the sound
* *
*/ */
float getAttenuation() float getAttenuation()
{ {
return sfMusic_GetAttenuation(m_ptr); return sfMusic_GetAttenuation(m_ptr);
} }
/** /**
* Set the music loop state. * Set the music loop state.
* This parameter is disabled by default * This parameter is disabled by default
* *
* Params: * Params:
* loop = True to play in loop, false to play once * loop = True to play in loop, false to play once
*/ */
void setLoop(bool loop) void setLoop(bool loop)
{ {
sfMusic_SetLoop(m_ptr, loop); sfMusic_SetLoop(m_ptr, loop);
} }
/** /**
* Set the sound pitch. * Set the sound pitch.
* The default pitch is 1 * The default pitch is 1
* *
* Params: * Params:
* pitch = New pitch * pitch = New pitch
* *
*/ */
void setPitch(float pitch) void setPitch(float pitch)
{ {
sfMusic_SetPitch(m_ptr, pitch); sfMusic_SetPitch(m_ptr, pitch);
} }
/** /**
* Set the sound volume. * Set the sound volume.
* The default volume is 100 * The default volume is 100
* *
* Params: * Params:
* volume = Volume (in range [0, 100]) * volume = Volume (in range [0, 100])
* *
*/ */
void setVolume(float volume) void setVolume(float volume)
in in
{ {
assert (volume >= 0.f && volume <= 100.f); assert (volume >= 0.f && volume <= 100.f);
} }
body body
{ {
sfMusic_SetVolume(m_ptr, volume); sfMusic_SetVolume(m_ptr, volume);
} }
/** /**
* Set the sound position. * Set the sound position.
* The default position is (0, 0, 0) * The default position is (0, 0, 0)
* *
* Params: * Params:
* x = X position of the sound in the world * x = X position of the sound in the world
* y = Y position of the sound in the world * y = Y position of the sound in the world
* z = Z position of the sound in the world * z = Z position of the sound in the world
* *
*/ */
void setPosition(float x, float y, float z) void setPosition(float x, float y, float z)
{ {
sfMusic_SetPosition(m_ptr, x, y, z); sfMusic_SetPosition(m_ptr, x, y, z);
} }
/** /**
* Set the sound position. * Set the sound position.
* The default position is (0, 0, 0) * The default position is (0, 0, 0)
* *
* Params: * Params:
* position = new position * position = new position
* *
*/ */
void setPosition(Vector3f position) void setPosition(Vector3f position)
{ {
sfMusic_SetPosition(m_ptr, position.x, position.y, position.z); sfMusic_SetPosition(m_ptr, position.x, position.y, position.z);
} }
/** /**
* Set the minimum distance - closer than thsi distance * Set the minimum distance - closer than thsi distance
* the listener will hear the sound at its maximum volume. * the listener will hear the sound at its maximum volume.
* The default distance is 1.0 * The default distance is 1.0
* *
* Params: * Params:
* minDistance = new minimum distance for the sound * minDistance = new minimum distance for the sound
*/ */
void setMinDistance(float minDistance) void setMinDistance(float minDistance)
{ {
sfMusic_SetMinDistance(m_ptr, minDistance); sfMusic_SetMinDistance(m_ptr, minDistance);
} }
/** /**
* Set the attenuation factor - the higher the attenuation, the * Set the attenuation factor - the higher the attenuation, the
* more the sound will be attenuated with distance from listener. * more the sound will be attenuated with distance from listener.
* The default attenuation factor 1.0 * The default attenuation factor 1.0
* *
* Params: * Params:
* attenuation = new attenuation factor for the sound * attenuation = new attenuation factor for the sound
*/ */
void setAttenuation(float attenuation) void setAttenuation(float attenuation)
{ {
sfMusic_SetAttenuation(m_ptr, attenuation); sfMusic_SetAttenuation(m_ptr, attenuation);
} }
/** /**
* Make the music's position relative to the listener's position, or absolute. * Make the music's position relative to the listener's position, or absolute.

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.sound; module dsfml.audio.sound;
@ -34,39 +34,39 @@ import dsfml.system.exception;
import dsfml.system.vector3; import dsfml.system.vector3;
/** /**
* Sound defines the properties of the sound such as position, * Sound defines the properties of the sound such as position,
* volume, pitch, etc. * volume, pitch, etc.
*/ */
class Sound : DSFMLObject class Sound : DSFMLObject
{ {
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
super(sfSound_Create()); super(sfSound_Create());
} }
/** /**
* Construct the sound from its parameters * Construct the sound from its parameters
* *
* Params: * Params:
* buffer = Sound buffer to play * buffer = Sound buffer to play
* loop = Loop flag (false by default) * loop = Loop flag (false by default)
* pitch = Value of the pitch (1 by default) * pitch = Value of the pitch (1 by default)
* volume = Volume (100 by default) * volume = Volume (100 by default)
* x = X position (0 by default) * x = X position (0 by default)
* y = Y position (0 by default) * y = Y position (0 by default)
* z = Z position (0 by default) * z = Z position (0 by default)
* *
* Throws: * Throws:
* NullParameterException if buffer is null * NullParameterException if buffer is null
*/ */
this(SoundBuffer buffer, bool loop = false, float pitch = 1.f, float volume = 100.f, float x = 0.f, float y = 0.f, float z = 0.f) this(SoundBuffer buffer, bool loop = false, float pitch = 1.f, float volume = 100.f, float x = 0.f, float y = 0.f, float z = 0.f)
{ {
if (buffer is null) if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null."); throw new NullParameterException("NullParameterException : SoundBuffer is null.");
super(sfSound_Create()); super(sfSound_Create());
sfSound_SetBuffer(m_ptr, buffer.getNativePointer()); sfSound_SetBuffer(m_ptr, buffer.getNativePointer());
sfSound_SetLoop(m_ptr, loop); sfSound_SetLoop(m_ptr, loop);
@ -76,257 +76,257 @@ class Sound : DSFMLObject
} }
override void dispose() override void dispose()
{ {
sfSound_Destroy(m_ptr); sfSound_Destroy(m_ptr);
} }
/** /**
* Play the sound * Play the sound
*/ */
void play() void play()
{ {
sfSound_Play(m_ptr); sfSound_Play(m_ptr);
} }
/** /**
* Pause the sound * Pause the sound
*/ */
void pause() void pause()
{ {
sfSound_Pause(m_ptr); sfSound_Pause(m_ptr);
} }
/** /**
* Stop the sound * Stop the sound
*/ */
void stop() void stop()
{ {
sfSound_Stop(m_ptr); sfSound_Stop(m_ptr);
} }
/** /**
* Set the source buffer * Set the source buffer
* *
* Params: * Params:
* buffer = New sound buffer to bind to the sound * buffer = New sound buffer to bind to the sound
*/ */
void setBuffer(SoundBuffer buffer) void setBuffer(SoundBuffer buffer)
{ {
if (buffer is null) if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null."); throw new NullParameterException("NullParameterException : SoundBuffer is null.");
m_buffer = buffer; m_buffer = buffer;
sfSound_SetBuffer(m_ptr, buffer.getNativePointer); sfSound_SetBuffer(m_ptr, buffer.getNativePointer);
} }
/** /**
* Set the sound loop state. * Set the sound loop state.
* This parameter is disabled by default * This parameter is disabled by default
* *
* Params: * Params:
* loop = True to play in loop, false to play once * loop = True to play in loop, false to play once
*/ */
void setLoop(bool loop) void setLoop(bool loop)
{ {
sfSound_SetLoop(m_ptr, loop); sfSound_SetLoop(m_ptr, loop);
} }
/** /**
* Set the sound pitch. * Set the sound pitch.
* The default pitch is 1 * The default pitch is 1
* *
* Params: * Params:
* pitch = New pitch * pitch = New pitch
*/ */
void setPitch(float pitch) void setPitch(float pitch)
{ {
sfSound_SetPitch(m_ptr, pitch); sfSound_SetPitch(m_ptr, pitch);
} }
/** /**
* Set the sound volume. * Set the sound volume.
* The default volume is 100 * The default volume is 100
* *
* Params: * Params:
* volume = Volume (in range [0, 100]) * volume = Volume (in range [0, 100])
*/ */
void setVolume(float volume) void setVolume(float volume)
in in
{ {
assert(volume >= 0 && volume <= 100); assert(volume >= 0 && volume <= 100);
} }
body body
{ {
sfSound_SetVolume(m_ptr, volume); sfSound_SetVolume(m_ptr, volume);
} }
/** /**
* Set the sound position. * Set the sound position.
* The default position is (0, 0, 0) * The default position is (0, 0, 0)
* *
* Params: * Params:
* x = X position of the sound in the world * x = X position of the sound in the world
* y = Y position of the sound in the world * y = Y position of the sound in the world
* z = Z position of the sound in the world * z = Z position of the sound in the world
*/ */
void setPosition(float x, float y, float z) void setPosition(float x, float y, float z)
{ {
sfSound_SetPosition(m_ptr, x, y, z); sfSound_SetPosition(m_ptr, x, y, z);
} }
/** /**
* Set the sound position. * Set the sound position.
* The default position is (0, 0, 0) * The default position is (0, 0, 0)
* *
* Params : * Params :
* position = new position * position = new position
*/ */
void setPosition(Vector3f position) void setPosition(Vector3f position)
{ {
sfSound_SetPosition(m_ptr, position.x, position.y, position.z); sfSound_SetPosition(m_ptr, position.x, position.y, position.z);
} }
/** /**
* Set the minimum distance - closer than this distance * Set the minimum distance - closer than this distance
* the listener will hear the sound at its maximum volume. * the listener will hear the sound at its maximum volume.
* The default distance is 1.0 * The default distance is 1.0
* *
* Params: * Params:
* minDistance = new minimum distance for the sound * minDistance = new minimum distance for the sound
*/ */
void setMinDistance(float minDistance) void setMinDistance(float minDistance)
{ {
sfSound_SetMinDistance(m_ptr, minDistance); sfSound_SetMinDistance(m_ptr, minDistance);
} }
/** /**
* Set the attenuation factor - the higher the attenuation, the * Set the attenuation factor - the higher the attenuation, the
* more the sound will be attenuated with distance from listener. * more the sound will be attenuated with distance from listener.
* The default attenuation factor 1.0 * The default attenuation factor 1.0
* *
* Params: * Params:
* attenuation = new attenuation factor for the sound * attenuation = new attenuation factor for the sound
*/ */
void setAttenuation(float attenuation) void setAttenuation(float attenuation)
{ {
sfSound_SetAttenuation(m_ptr, attenuation); sfSound_SetAttenuation(m_ptr, attenuation);
} }
/** /**
* Set the current playing offset of a sound * Set the current playing offset of a sound
* *
* Params: * Params:
* offset = new playing position, expressed in seconds * offset = new playing position, expressed in seconds
*/ */
void setPlayingOffset(float offset) void setPlayingOffset(float offset)
{ {
sfSound_SetPlayingOffset(m_ptr, offset); sfSound_SetPlayingOffset(m_ptr, offset);
} }
/** /**
* Get the source buffer * Get the source buffer
* *
* Returns: * Returns:
* Sound buffer bound to the sound (can be NULL) * Sound buffer bound to the sound (can be NULL)
*/ */
SoundBuffer getBuffer() SoundBuffer getBuffer()
{ {
return m_buffer; return m_buffer;
} }
/** /**
* Tell whether or not the sound is looping * Tell whether or not the sound is looping
* *
* Returns: * Returns:
* True if the sound is looping, false otherwise * True if the sound is looping, false otherwise
*/ */
bool getLoop() bool getLoop()
{ {
return cast(bool)(sfSound_GetLoop(m_ptr)); return cast(bool)(sfSound_GetLoop(m_ptr));
} }
/** /**
* Get the pitch * Get the pitch
* *
* Returns: * Returns:
* Pitch value * Pitch value
*/ */
float getPitch() float getPitch()
{ {
return sfSound_GetPitch(m_ptr); return sfSound_GetPitch(m_ptr);
} }
/** /**
* Get the volume * Get the volume
* *
* Returns: * Returns:
* Volume value (in range [1, 100]) * Volume value (in range [1, 100])
*/ */
float getVolume() float getVolume()
{ {
return sfSound_GetVolume(m_ptr); return sfSound_GetVolume(m_ptr);
} }
/** /**
* Get the sound position * Get the sound position
* *
* Params: * Params:
* x = X position of the sound in the world * x = X position of the sound in the world
* y = Y position of the sound in the world * y = Y position of the sound in the world
* z = Z position of the sound in the world * z = Z position of the sound in the world
*/ */
Vector3f getPosition() Vector3f getPosition()
{ {
Vector3f ret; Vector3f ret;
sfSound_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z); sfSound_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
return ret; return ret;
} }
/** /**
* Get the minimum distance * Get the minimum distance
* *
* Returns: * Returns:
* Minimum distance for the sound * Minimum distance for the sound
*/ */
float getMinDistance() float getMinDistance()
{ {
return sfSound_GetMinDistance(m_ptr); return sfSound_GetMinDistance(m_ptr);
} }
/** /**
* Get the attenuation factor * Get the attenuation factor
* *
* Returns: * Returns:
* Attenuation factor of the sound * Attenuation factor of the sound
* *
*/ */
float getAttenuation() float getAttenuation()
{ {
return sfSound_GetAttenuation(m_ptr); return sfSound_GetAttenuation(m_ptr);
} }
/** /**
* Get the status of the sound (stopped, paused, playing) * Get the status of the sound (stopped, paused, playing)
* *
* Returns: * Returns:
* Current status of the sound * Current status of the sound
*/ */
SoundStatus getStatus() SoundStatus getStatus()
{ {
return sfSound_GetStatus(m_ptr); return sfSound_GetStatus(m_ptr);
} }
/** /**
* Get the current playing position of the sound * Get the current playing position of the sound
* *
* Returns: * Returns:
* Current playing position, expressed in seconds * Current playing position, expressed in seconds
*/ */
float getPlayingOffset() float getPlayingOffset()
{ {
return sfSound_GetPlayingOffset(m_ptr); return sfSound_GetPlayingOffset(m_ptr);
} }
@ -361,90 +361,90 @@ private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfSound_Create; typedef void* function() pf_sfSound_Create;
typedef void function(void*) pf_sfSound_Destroy; typedef void function(void*) pf_sfSound_Destroy;
typedef void function(void*) pf_sfSound_Play; typedef void function(void*) pf_sfSound_Play;
typedef void function(void*) pf_sfSound_Pause; typedef void function(void*) pf_sfSound_Pause;
typedef void function(void*) pf_sfSound_Stop; typedef void function(void*) pf_sfSound_Stop;
typedef void function(void*, void*) pf_sfSound_SetBuffer; typedef void function(void*, void*) pf_sfSound_SetBuffer;
typedef void* function(void*) pf_sfSound_GetBuffer; typedef void* function(void*) pf_sfSound_GetBuffer;
typedef void function(void*, int) pf_sfSound_SetLoop; typedef void function(void*, int) pf_sfSound_SetLoop;
typedef int function(void*) pf_sfSound_GetLoop; typedef int function(void*) pf_sfSound_GetLoop;
typedef SoundStatus function(void*) pf_sfSound_GetStatus; typedef SoundStatus function(void*) pf_sfSound_GetStatus;
typedef void function(void*, float) pf_sfSound_SetPitch; typedef void function(void*, float) pf_sfSound_SetPitch;
typedef void function(void*, float) pf_sfSound_SetVolume; typedef void function(void*, float) pf_sfSound_SetVolume;
typedef void function(void*, float, float, float) pf_sfSound_SetPosition; typedef void function(void*, float, float, float) pf_sfSound_SetPosition;
typedef float function(void*) pf_sfSound_GetPitch; typedef float function(void*) pf_sfSound_GetPitch;
typedef float function(void*) pf_sfSound_GetVolume; typedef float function(void*) pf_sfSound_GetVolume;
typedef void function(void*, float*, float*, float*) pf_sfSound_GetPosition; typedef void function(void*, float*, float*, float*) pf_sfSound_GetPosition;
typedef float function(void*) pf_sfSound_GetPlayingOffset; typedef float function(void*) pf_sfSound_GetPlayingOffset;
typedef float function(void*) pf_sfSound_GetMinDistance; typedef float function(void*) pf_sfSound_GetMinDistance;
typedef float function(void*) pf_sfSound_GetAttenuation; typedef float function(void*) pf_sfSound_GetAttenuation;
typedef void function(void*, float) pf_sfSound_SetMinDistance; typedef void function(void*, float) pf_sfSound_SetMinDistance;
typedef void function(void*, float) pf_sfSound_SetAttenuation; typedef void function(void*, float) pf_sfSound_SetAttenuation;
typedef void function(void*, float) pf_sfSound_SetPlayingOffset; typedef void function(void*, float) pf_sfSound_SetPlayingOffset;
static void function(void*, bool) sfSound_SetRelativeToListener; static void function(void*, bool) sfSound_SetRelativeToListener;
static bool function(void*) sfSound_IsRelativeToListener; static bool function(void*) sfSound_IsRelativeToListener;
static pf_sfSound_Create sfSound_Create; static pf_sfSound_Create sfSound_Create;
static pf_sfSound_Destroy sfSound_Destroy; static pf_sfSound_Destroy sfSound_Destroy;
static pf_sfSound_Play sfSound_Play; static pf_sfSound_Play sfSound_Play;
static pf_sfSound_Pause sfSound_Pause; static pf_sfSound_Pause sfSound_Pause;
static pf_sfSound_Stop sfSound_Stop; static pf_sfSound_Stop sfSound_Stop;
static pf_sfSound_SetBuffer sfSound_SetBuffer; static pf_sfSound_SetBuffer sfSound_SetBuffer;
static pf_sfSound_GetBuffer sfSound_GetBuffer; static pf_sfSound_GetBuffer sfSound_GetBuffer;
static pf_sfSound_SetLoop sfSound_SetLoop; static pf_sfSound_SetLoop sfSound_SetLoop;
static pf_sfSound_GetLoop sfSound_GetLoop; static pf_sfSound_GetLoop sfSound_GetLoop;
static pf_sfSound_GetStatus sfSound_GetStatus; static pf_sfSound_GetStatus sfSound_GetStatus;
static pf_sfSound_SetPitch sfSound_SetPitch; static pf_sfSound_SetPitch sfSound_SetPitch;
static pf_sfSound_SetVolume sfSound_SetVolume; static pf_sfSound_SetVolume sfSound_SetVolume;
static pf_sfSound_SetPosition sfSound_SetPosition; static pf_sfSound_SetPosition sfSound_SetPosition;
static pf_sfSound_GetPitch sfSound_GetPitch; static pf_sfSound_GetPitch sfSound_GetPitch;
static pf_sfSound_GetVolume sfSound_GetVolume; static pf_sfSound_GetVolume sfSound_GetVolume;
static pf_sfSound_GetPosition sfSound_GetPosition; static pf_sfSound_GetPosition sfSound_GetPosition;
static pf_sfSound_GetPlayingOffset sfSound_GetPlayingOffset; static pf_sfSound_GetPlayingOffset sfSound_GetPlayingOffset;
static pf_sfSound_GetMinDistance sfSound_GetMinDistance; static pf_sfSound_GetMinDistance sfSound_GetMinDistance;
static pf_sfSound_GetAttenuation sfSound_GetAttenuation; static pf_sfSound_GetAttenuation sfSound_GetAttenuation;
static pf_sfSound_SetMinDistance sfSound_SetMinDistance; static pf_sfSound_SetMinDistance sfSound_SetMinDistance;
static pf_sfSound_SetAttenuation sfSound_SetAttenuation; static pf_sfSound_SetAttenuation sfSound_SetAttenuation;
static pf_sfSound_SetPlayingOffset sfSound_SetPlayingOffset; static pf_sfSound_SetPlayingOffset sfSound_SetPlayingOffset;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-audio-d"); DllLoader dll = DllLoader.load("csfml-audio-d");
else else
DllLoader dll = DllLoader.load("csfml-audio"); DllLoader dll = DllLoader.load("csfml-audio");
sfSound_Create = cast(pf_sfSound_Create)dll.getSymbol("sfSound_Create"); sfSound_Create = cast(pf_sfSound_Create)dll.getSymbol("sfSound_Create");
sfSound_Destroy = cast(pf_sfSound_Destroy)dll.getSymbol("sfSound_Destroy"); sfSound_Destroy = cast(pf_sfSound_Destroy)dll.getSymbol("sfSound_Destroy");
sfSound_Play = cast(pf_sfSound_Play)dll.getSymbol("sfSound_Play"); sfSound_Play = cast(pf_sfSound_Play)dll.getSymbol("sfSound_Play");
sfSound_Pause = cast(pf_sfSound_Pause)dll.getSymbol("sfSound_Pause"); sfSound_Pause = cast(pf_sfSound_Pause)dll.getSymbol("sfSound_Pause");
sfSound_Stop = cast(pf_sfSound_Stop)dll.getSymbol("sfSound_Stop"); sfSound_Stop = cast(pf_sfSound_Stop)dll.getSymbol("sfSound_Stop");
sfSound_SetBuffer = cast(pf_sfSound_SetBuffer)dll.getSymbol("sfSound_SetBuffer"); sfSound_SetBuffer = cast(pf_sfSound_SetBuffer)dll.getSymbol("sfSound_SetBuffer");
sfSound_GetBuffer = cast(pf_sfSound_GetBuffer)dll.getSymbol("sfSound_GetBuffer"); sfSound_GetBuffer = cast(pf_sfSound_GetBuffer)dll.getSymbol("sfSound_GetBuffer");
sfSound_SetLoop = cast(pf_sfSound_SetLoop)dll.getSymbol("sfSound_SetLoop"); sfSound_SetLoop = cast(pf_sfSound_SetLoop)dll.getSymbol("sfSound_SetLoop");
sfSound_GetLoop = cast(pf_sfSound_GetLoop)dll.getSymbol("sfSound_GetLoop"); sfSound_GetLoop = cast(pf_sfSound_GetLoop)dll.getSymbol("sfSound_GetLoop");
sfSound_GetStatus = cast(pf_sfSound_GetStatus)dll.getSymbol("sfSound_GetStatus"); sfSound_GetStatus = cast(pf_sfSound_GetStatus)dll.getSymbol("sfSound_GetStatus");
sfSound_SetPitch = cast(pf_sfSound_SetPitch)dll.getSymbol("sfSound_SetPitch"); sfSound_SetPitch = cast(pf_sfSound_SetPitch)dll.getSymbol("sfSound_SetPitch");
sfSound_SetVolume = cast(pf_sfSound_SetVolume)dll.getSymbol("sfSound_SetVolume"); sfSound_SetVolume = cast(pf_sfSound_SetVolume)dll.getSymbol("sfSound_SetVolume");
sfSound_SetPosition = cast(pf_sfSound_SetPosition)dll.getSymbol("sfSound_SetPosition"); sfSound_SetPosition = cast(pf_sfSound_SetPosition)dll.getSymbol("sfSound_SetPosition");
sfSound_GetPitch = cast(pf_sfSound_GetPitch)dll.getSymbol("sfSound_GetPitch"); sfSound_GetPitch = cast(pf_sfSound_GetPitch)dll.getSymbol("sfSound_GetPitch");
sfSound_GetVolume = cast(pf_sfSound_GetVolume)dll.getSymbol("sfSound_GetVolume"); sfSound_GetVolume = cast(pf_sfSound_GetVolume)dll.getSymbol("sfSound_GetVolume");
sfSound_GetPosition = cast(pf_sfSound_GetPosition)dll.getSymbol("sfSound_GetPosition"); sfSound_GetPosition = cast(pf_sfSound_GetPosition)dll.getSymbol("sfSound_GetPosition");
sfSound_GetPlayingOffset = cast(pf_sfSound_GetPlayingOffset)dll.getSymbol("sfSound_GetPlayingOffset"); sfSound_GetPlayingOffset = cast(pf_sfSound_GetPlayingOffset)dll.getSymbol("sfSound_GetPlayingOffset");
sfSound_GetMinDistance = cast(pf_sfSound_GetMinDistance)dll.getSymbol("sfSound_GetMinDistance"); sfSound_GetMinDistance = cast(pf_sfSound_GetMinDistance)dll.getSymbol("sfSound_GetMinDistance");
sfSound_GetAttenuation = cast(pf_sfSound_GetAttenuation)dll.getSymbol("sfSound_GetAttenuation"); sfSound_GetAttenuation = cast(pf_sfSound_GetAttenuation)dll.getSymbol("sfSound_GetAttenuation");
sfSound_SetMinDistance = cast(pf_sfSound_SetMinDistance)dll.getSymbol("sfSound_SetMinDistance"); sfSound_SetMinDistance = cast(pf_sfSound_SetMinDistance)dll.getSymbol("sfSound_SetMinDistance");
sfSound_SetAttenuation = cast(pf_sfSound_SetAttenuation)dll.getSymbol("sfSound_SetAttenuation"); sfSound_SetAttenuation = cast(pf_sfSound_SetAttenuation)dll.getSymbol("sfSound_SetAttenuation");
sfSound_SetPlayingOffset = cast(pf_sfSound_SetPlayingOffset)dll.getSymbol("sfSound_SetPlayingOffset"); sfSound_SetPlayingOffset = cast(pf_sfSound_SetPlayingOffset)dll.getSymbol("sfSound_SetPlayingOffset");
mixin(loadFromSharedLib("sfSound_SetRelativeToListener")); mixin(loadFromSharedLib("sfSound_SetRelativeToListener"));
mixin(loadFromSharedLib("sfSound_IsRelativeToListener")); mixin(loadFromSharedLib("sfSound_IsRelativeToListener"));
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.soundbuffer; module dsfml.audio.soundbuffer;
@ -32,83 +32,83 @@ import dsfml.system.stringutil;
/** /**
* SoundBuffer is the low-level for loading and manipulating * SoundBuffer is the low-level for loading and manipulating
* sound buffers * sound buffers
*/ */
class SoundBuffer : DSFMLObject class SoundBuffer : DSFMLObject
{ {
/** /**
* Load the sound buffer from a file * Load the sound buffer from a file
* *
* Params: * Params:
* filename = Path of the sound file to load * filename = Path of the sound file to load
* *
* Throws: * Throws:
* LoadingException on failure * LoadingException on failure
*/ */
this(string filename) this(string filename)
{ {
if (filename is null || filename.length == 0) if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid."); throw new LoadingException("LoadingException : Filename is invalid.");
super(sfSoundBuffer_CreateFromFile(toStringz(filename))); super(sfSoundBuffer_CreateFromFile(toStringz(filename)));
} }
/** /**
* Load the sound buffer from a file in memory * Load the sound buffer from a file in memory
* *
* Params: * Params:
* data = Array of file data in memory * data = Array of file data in memory
* *
* Throws: * Throws:
* LoadingException on failure * LoadingException on failure
*/ */
this(byte[] data) this(byte[] data)
{ {
if (data is null || data.length == 0) if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid."); throw new Exception("LoadingException : Memory stream is invalid.");
super(sfSoundBuffer_CreateFromMemory(data.ptr, data.length)); super(sfSoundBuffer_CreateFromMemory(data.ptr, data.length));
} }
/** /**
* Load the sound buffer from an array of samples - assumed format for * Load the sound buffer from an array of samples - assumed format for
* samples is 16 bits signed integer * samples is 16 bits signed integer
* *
* Params: * Params:
* samples = Array of samples in memory * samples = Array of samples in memory
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...) * channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
* sampleRate = Frequency (number of samples to play per second) * sampleRate = Frequency (number of samples to play per second)
* *
* Throws: * Throws:
* LoadingException on failure * LoadingException on failure
*/ */
this(short[] samples, uint channelsCount, uint sampleRate) this(short[] samples, uint channelsCount, uint sampleRate)
{ {
if (samples is null || samples.length == 0) if (samples is null || samples.length == 0)
throw new Exception("LoadingException : Samples array is invalid."); throw new Exception("LoadingException : Samples array is invalid.");
super(sfSoundBuffer_CreateFromSamples(samples.ptr, samples.length, channelsCount, sampleRate)); super(sfSoundBuffer_CreateFromSamples(samples.ptr, samples.length, channelsCount, sampleRate));
} }
override void dispose() override void dispose()
{ {
sfSoundBuffer_Destroy(m_ptr); sfSoundBuffer_Destroy(m_ptr);
} }
/** /**
* Save the sound buffer to a file * Save the sound buffer to a file
* *
* Params: * Params:
* filename = Path of the sound file to write * filename = Path of the sound file to write
* *
* Returns: * Returns:
* True if saving has been successful * True if saving has been successful
*/ */
bool saveToFile(string filename) bool saveToFile(string filename)
{ {
if (filename !is null && filename.length > 0 ) if (filename !is null && filename.length > 0 )
{ {
return cast(bool)sfSoundBuffer_SaveToFile(m_ptr, toStringz(filename)); return cast(bool)sfSoundBuffer_SaveToFile(m_ptr, toStringz(filename));
@ -116,115 +116,115 @@ class SoundBuffer : DSFMLObject
return false; return false;
} }
/** /**
* Return the sound samples * Return the sound samples
* *
* Returns: * Returns:
* Array of sound samples, in 16 bits signed integer format * Array of sound samples, in 16 bits signed integer format
*/ */
short[] getSamples() short[] getSamples()
{ {
short* temp = null; short* temp = null;
temp = sfSoundBuffer_GetSamples(m_ptr); temp = sfSoundBuffer_GetSamples(m_ptr);
return temp is null ? null : temp[0..getSamplesCount]; return temp is null ? null : temp[0..getSamplesCount];
} }
/** /**
* Return the samples count * Return the samples count
* *
* Returns: * Returns:
* Number of samples * Number of samples
*/ */
size_t getSamplesCount() size_t getSamplesCount()
{ {
return sfSoundBuffer_GetSamplesCount(m_ptr); return sfSoundBuffer_GetSamplesCount(m_ptr);
} }
/** /**
* Get the sample rate * Get the sample rate
* *
* Returns: * Returns:
* Sound frequency (number of samples per second) * Sound frequency (number of samples per second)
*/ */
uint getSampleRate() uint getSampleRate()
{ {
return sfSoundBuffer_GetSampleRate(m_ptr); return sfSoundBuffer_GetSampleRate(m_ptr);
} }
/** /**
* Return the number of channels (1 = mono, 2 = stereo, ...) * Return the number of channels (1 = mono, 2 = stereo, ...)
* *
* Returns: * Returns:
* Number of channels * Number of channels
*/ */
uint getChannelsCount() uint getChannelsCount()
{ {
return sfSoundBuffer_GetChannelsCount(m_ptr); return sfSoundBuffer_GetChannelsCount(m_ptr);
} }
/** /**
* Get the sound duration * Get the sound duration
* *
* Returns: * Returns:
* Sound duration, in seconds * Sound duration, in seconds
*/ */
float getDuration() float getDuration()
{ {
return sfSoundBuffer_GetDuration(m_ptr); return sfSoundBuffer_GetDuration(m_ptr);
} }
package: package:
this(void* ptr) this(void* ptr)
{ {
super(ptr, true); super(ptr, true);
} }
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile; typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile;
typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory; typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory;
typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples; typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples;
typedef void function(void*) pf_sfSoundBuffer_Destroy; typedef void function(void*) pf_sfSoundBuffer_Destroy;
typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile; typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile;
typedef short* function(void*) pf_sfSoundBuffer_GetSamples; typedef short* function(void*) pf_sfSoundBuffer_GetSamples;
typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount; typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount;
typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate; typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate;
typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount; typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount;
typedef float function(void*) pf_sfSoundBuffer_GetDuration; typedef float function(void*) pf_sfSoundBuffer_GetDuration;
static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile; static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile;
static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory; static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory;
static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples; static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples;
static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy; static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy;
static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile; static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile;
static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples; static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples;
static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount; static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount;
static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate; static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate;
static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount; static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount;
static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration; static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-audio-d"); DllLoader dll = DllLoader.load("csfml-audio-d");
else else
DllLoader dll = DllLoader.load("csfml-audio"); DllLoader dll = DllLoader.load("csfml-audio");
sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile"); sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile");
sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory"); sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory");
sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples"); sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples");
sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy"); sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy");
sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile"); sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile");
sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples"); sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples");
sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount"); sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount");
sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate"); sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate");
sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount"); sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount");
sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration"); sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.soundbufferrecorder; module dsfml.audio.soundbufferrecorder;
@ -32,78 +32,78 @@ import dsfml.audio.soundbuffer;
import dsfml.audio.soundrecorder; import dsfml.audio.soundrecorder;
/** /**
* Specialized sfSoundRecorder which saves the captured * Specialized sfSoundRecorder which saves the captured
* audio data into a sound buffer * audio data into a sound buffer
*/ */
class SoundBufferRecorder : SoundRecorder class SoundBufferRecorder : SoundRecorder
{ {
/** /**
* Constructor * Constructor
*/ */
this() this()
{ {
super(sfSoundBufferRecorder_Create()); super(sfSoundBufferRecorder_Create());
} }
override void dispose() override void dispose()
{ {
sfSoundBufferRecorder_Destroy(m_ptr); sfSoundBufferRecorder_Destroy(m_ptr);
} }
/** /**
* Get the sound buffer containing the captured audio data * Get the sound buffer containing the captured audio data
* *
* Returns: * Returns:
* SoundBuffer containing the captured audio data * SoundBuffer containing the captured audio data
* *
*/ */
SoundBuffer getBuffer() SoundBuffer getBuffer()
{ {
return new SoundBuffer(sfSoundBufferRecorder_GetBuffer(m_ptr)); return new SoundBuffer(sfSoundBufferRecorder_GetBuffer(m_ptr));
} }
protected: protected:
override bool onStart() override bool onStart()
{ {
return true; return true;
} }
override bool onProcessSamples(short[] s) override bool onProcessSamples(short[] s)
{ {
return true; return true;
} }
override void onStop() override void onStop()
{ {
} }
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfSoundBufferRecorder_Create; typedef void* function() pf_sfSoundBufferRecorder_Create;
typedef void function(void*) pf_sfSoundBufferRecorder_Destroy; typedef void function(void*) pf_sfSoundBufferRecorder_Destroy;
typedef void* function(void*) pf_sfSoundBufferRecorder_GetBuffer; typedef void* function(void*) pf_sfSoundBufferRecorder_GetBuffer;
static pf_sfSoundBufferRecorder_Create sfSoundBufferRecorder_Create; static pf_sfSoundBufferRecorder_Create sfSoundBufferRecorder_Create;
static pf_sfSoundBufferRecorder_Destroy sfSoundBufferRecorder_Destroy; static pf_sfSoundBufferRecorder_Destroy sfSoundBufferRecorder_Destroy;
static pf_sfSoundBufferRecorder_GetBuffer sfSoundBufferRecorder_GetBuffer; static pf_sfSoundBufferRecorder_GetBuffer sfSoundBufferRecorder_GetBuffer;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-audio-d"); DllLoader dll = DllLoader.load("csfml-audio-d");
else else
DllLoader dll = DllLoader.load("csfml-audio"); DllLoader dll = DllLoader.load("csfml-audio");
sfSoundBufferRecorder_Create = cast(pf_sfSoundBufferRecorder_Create)dll.getSymbol("sfSoundBufferRecorder_Create"); sfSoundBufferRecorder_Create = cast(pf_sfSoundBufferRecorder_Create)dll.getSymbol("sfSoundBufferRecorder_Create");
sfSoundBufferRecorder_Destroy = cast(pf_sfSoundBufferRecorder_Destroy)dll.getSymbol("sfSoundBufferRecorder_Destroy"); sfSoundBufferRecorder_Destroy = cast(pf_sfSoundBufferRecorder_Destroy)dll.getSymbol("sfSoundBufferRecorder_Destroy");
sfSoundBufferRecorder_GetBuffer = cast(pf_sfSoundBufferRecorder_GetBuffer)dll.getSymbol("sfSoundBufferRecorder_GetBuffer"); sfSoundBufferRecorder_GetBuffer = cast(pf_sfSoundBufferRecorder_GetBuffer)dll.getSymbol("sfSoundBufferRecorder_GetBuffer");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.soundrecorder; module dsfml.audio.soundrecorder;
@ -38,300 +38,300 @@ import dsfml.system.lock;
import core.thread; import core.thread;
/** /**
* SoundRecorder is an interface for capturing sound data. * SoundRecorder is an interface for capturing sound data.
* *
* $(B onProcessSamples and onStop will be called by a different thread, take care of synchronization issues.) * $(B onProcessSamples and onStop will be called by a different thread, take care of synchronization issues.)
* *
* Examples: * Examples:
* ------- * -------
* class MySoundRecorder : SoundRecorder * class MySoundRecorder : SoundRecorder
* { * {
* this() * this()
* { * {
* *
* } * }
* *
* protected bool onStart() * protected bool onStart()
* { * {
* return true; * return true;
* } * }
* *
* protected void onStop() * protected void onStop()
* { * {
* *
* } * }
* *
* protected bool onProcessSamples(out short[]) * protected bool onProcessSamples(out short[])
* { * {
* // Process data here * // Process data here
* *
* return true; //return true to continue capture, else return false * return true; //return true to continue capture, else return false
* } * }
* } * }
* ------- * -------
*/ */
abstract class SoundRecorder : DSFMLObject abstract class SoundRecorder : DSFMLObject
{ {
override void dispose() override void dispose()
{ {
if (m_flag) if (m_flag)
stop(); stop();
m_instances.remove(m_id); m_instances.remove(m_id);
sfSoundRecorder_Destroy(m_ptr); sfSoundRecorder_Destroy(m_ptr);
} }
/** /**
* Start the capture. * Start the capture.
* *
* Only one capture can happen at the same time * Only one capture can happen at the same time
* *
* Params: * Params:
* sampleRate : Sound frequency (the more samples, the higher the quality) * sampleRate : Sound frequency (the more samples, the higher the quality)
* (44100 by default = CD quality) * (44100 by default = CD quality)
*/ */
void start(uint sampleRate = 44100) void start(uint sampleRate = 44100)
{ {
sfSoundRecorder_Start(m_ptr, sampleRate); sfSoundRecorder_Start(m_ptr, sampleRate);
m_t = new Thread(&threadPoll); m_t = new Thread(&threadPoll);
m_t.start(); m_t.start();
} }
/** /**
* Stop the capture * Stop the capture
*/ */
void stop() void stop()
{ {
sfSoundRecorder_Stop(m_ptr); sfSoundRecorder_Stop(m_ptr);
m_flag = false; m_flag = false;
m_t.join(); m_t.join();
m_t = null; m_t = null;
} }
/** /**
* Get the sample rate * Get the sample rate
* *
* Returns: * Returns:
* Frequency, in samples per second * Frequency, in samples per second
*/ */
uint getSampleRate() uint getSampleRate()
{ {
return sfSoundRecorder_GetSampleRate(m_ptr); return sfSoundRecorder_GetSampleRate(m_ptr);
} }
/** /**
* Tell if the system supports sound capture. * Tell if the system supports sound capture.
* If not, this class won't be usable * If not, this class won't be usable
* *
* Returns: * Returns:
* True if audio capture is supported * True if audio capture is supported
* *
*/ */
static bool canCapture() static bool canCapture()
{ {
return cast(bool)sfSoundRecorder_CanCapture(); return cast(bool)sfSoundRecorder_CanCapture();
} }
protected: protected:
/** /**
* Protected constructor * Protected constructor
*/ */
this() this()
{ {
m_id = ++seed; m_id = ++seed;
m_instances[m_id] = this; m_instances[m_id] = this;
super(sfSoundRecorder_Create(&internalOnStart, &internalCallback, &internalOnStop, &m_id)); super(sfSoundRecorder_Create(&internalOnStart, &internalCallback, &internalOnStop, &m_id));
init(true); init(true);
} }
this(void* ptr) this(void* ptr)
{ {
super(ptr); super(ptr);
init(false); init(false);
} }
/** /**
* Start recording audio data * Start recording audio data
* *
* Returns: * Returns:
* False to abort recording audio data, true to start * False to abort recording audio data, true to start
*/ */
abstract bool onStart(); abstract bool onStart();
/** /**
* Stop recording audio data * Stop recording audio data
*/ */
abstract void onStop(); abstract void onStop();
/** /**
* callback function * callback function
* *
* Parameters: * Parameters:
* samples = Array of samples * samples = Array of samples
* *
* Returns: * Returns:
* true to continue recording, false to stop. * true to continue recording, false to stop.
*/ */
abstract bool onProcessSamples(short[] samples); abstract bool onProcessSamples(short[] samples);
bool m_disposed; bool m_disposed;
private: private:
/* /*
* an init function to initialize id of the object. * an init function to initialize id of the object.
*/ */
void init(bool flag) void init(bool flag)
{ {
if (flag) if (flag)
{ {
m_list = new LinkedList!(Samples)(); m_list = new LinkedList!(Samples)();
m_flag = true; m_flag = true;
m_continue = true; m_continue = true;
m_mutex = new Mutex(); m_mutex = new Mutex();
} }
} }
void* m_userData; void* m_userData;
int m_id; int m_id;
static int seed = 0; static int seed = 0;
static SoundRecorder[int] m_instances; static SoundRecorder[int] m_instances;
/* /*
* Extern C callback function * Extern C callback function
* *
* This function must be static for C interop. To retrieve the current * This function must be static for C interop. To retrieve the current
* instance, we retrieve id of the sender in the user data, and search associated instance * instance, we retrieve id of the sender in the user data, and search associated instance
* in the associative array. * in the associative array.
* *
* We don't call delegate or derived class on that thread because GC is not aware of this thread * We don't call delegate or derived class on that thread because GC is not aware of this thread
* instead we enqueue data informations in a queue and poll this queue with a managed thread. * instead we enqueue data informations in a queue and poll this queue with a managed thread.
*/ */
extern(C) static int internalCallback(short* s, size_t size, void* user) extern(C) static int internalCallback(short* s, size_t size, void* user)
{ {
int id; int id;
// retrieve instance // retrieve instance
if ((id = *cast(int*)(user)) in m_instances) if ((id = *cast(int*)(user)) in m_instances)
{ {
SoundRecorder temp = m_instances[id]; SoundRecorder temp = m_instances[id];
scope Lock l = new Lock(temp.m_mutex); scope Lock l = new Lock(temp.m_mutex);
if (temp.m_continue) if (temp.m_continue)
// this new is allowed because Samples is an custom alloc class. // this new is allowed because Samples is an custom alloc class.
temp.m_list.enqueue(new Samples(s, size)); temp.m_list.enqueue(new Samples(s, size));
return temp.m_continue; return temp.m_continue;
} }
return false; return false;
} }
extern(C) static int internalOnStart(void* user) extern(C) static int internalOnStart(void* user)
{ {
int id; int id;
bool ret = false; bool ret = false;
if ((id = *cast(int*)(user)) in m_instances) if ((id = *cast(int*)(user)) in m_instances)
{ {
SoundRecorder temp = m_instances[id]; SoundRecorder temp = m_instances[id];
ret = temp.onStart(); ret = temp.onStart();
} }
return ret; return ret;
} }
extern(C) static void internalOnStop(void* user) extern(C) static void internalOnStop(void* user)
{ {
// Nothing to do // Nothing to do
} }
/* /*
* Managed thread loop * Managed thread loop
*/ */
void threadPoll() void threadPoll()
{ {
while (m_flag) while (m_flag)
{ {
sleep(0.05f); sleep(0.05f);
// if samples are available // if samples are available
if (!m_list.empty) if (!m_list.empty)
{ {
// Lock ressources // Lock ressources
scope Lock l = new Lock(m_mutex); scope Lock l = new Lock(m_mutex);
Samples s = m_list.dequeue; Samples s = m_list.dequeue;
m_continue = this.onProcessSamples(s.data[0..s.length].dup); m_continue = this.onProcessSamples(s.data[0..s.length].dup);
delete s; delete s;
if (!m_continue) if (!m_continue)
{ {
// delete all samples left // delete all samples left
foreach(Samples dummy; m_list) foreach(Samples dummy; m_list)
delete dummy; delete dummy;
break; break;
} }
} }
} }
onStop(); onStop();
} }
Mutex m_mutex; Mutex m_mutex;
bool m_flag; bool m_flag;
bool m_continue = true; bool m_continue = true;
LinkedList!(Samples) m_list; LinkedList!(Samples) m_list;
Thread m_t; Thread m_t;
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function(int function(void*), int function(short*, size_t, void*), void function(void*), void*) pf_sfSoundRecorder_Create; typedef void* function(int function(void*), int function(short*, size_t, void*), void function(void*), void*) pf_sfSoundRecorder_Create;
typedef void function(void*) pf_sfSoundRecorder_Destroy; typedef void function(void*) pf_sfSoundRecorder_Destroy;
typedef void function(void*, uint SampleRate) pf_sfSoundRecorder_Start; typedef void function(void*, uint SampleRate) pf_sfSoundRecorder_Start;
typedef void function(void*) pf_sfSoundRecorder_Stop; typedef void function(void*) pf_sfSoundRecorder_Stop;
typedef uint function(void*) pf_sfSoundRecorder_GetSampleRate; typedef uint function(void*) pf_sfSoundRecorder_GetSampleRate;
typedef int function() pf_sfSoundRecorder_CanCapture; typedef int function() pf_sfSoundRecorder_CanCapture;
static pf_sfSoundRecorder_Create sfSoundRecorder_Create; static pf_sfSoundRecorder_Create sfSoundRecorder_Create;
static pf_sfSoundRecorder_Destroy sfSoundRecorder_Destroy; static pf_sfSoundRecorder_Destroy sfSoundRecorder_Destroy;
static pf_sfSoundRecorder_Start sfSoundRecorder_Start; static pf_sfSoundRecorder_Start sfSoundRecorder_Start;
static pf_sfSoundRecorder_Stop sfSoundRecorder_Stop; static pf_sfSoundRecorder_Stop sfSoundRecorder_Stop;
static pf_sfSoundRecorder_GetSampleRate sfSoundRecorder_GetSampleRate; static pf_sfSoundRecorder_GetSampleRate sfSoundRecorder_GetSampleRate;
static pf_sfSoundRecorder_CanCapture sfSoundRecorder_CanCapture; static pf_sfSoundRecorder_CanCapture sfSoundRecorder_CanCapture;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-audio-d"); DllLoader dll = DllLoader.load("csfml-audio-d");
else else
DllLoader dll = DllLoader.load("csfml-audio"); DllLoader dll = DllLoader.load("csfml-audio");
sfSoundRecorder_Create = cast(pf_sfSoundRecorder_Create)dll.getSymbol("sfSoundRecorder_Create"); sfSoundRecorder_Create = cast(pf_sfSoundRecorder_Create)dll.getSymbol("sfSoundRecorder_Create");
sfSoundRecorder_Destroy = cast(pf_sfSoundRecorder_Destroy)dll.getSymbol("sfSoundRecorder_Destroy"); sfSoundRecorder_Destroy = cast(pf_sfSoundRecorder_Destroy)dll.getSymbol("sfSoundRecorder_Destroy");
sfSoundRecorder_Start = cast(pf_sfSoundRecorder_Start)dll.getSymbol("sfSoundRecorder_Start"); sfSoundRecorder_Start = cast(pf_sfSoundRecorder_Start)dll.getSymbol("sfSoundRecorder_Start");
sfSoundRecorder_Stop = cast(pf_sfSoundRecorder_Stop)dll.getSymbol("sfSoundRecorder_Stop"); sfSoundRecorder_Stop = cast(pf_sfSoundRecorder_Stop)dll.getSymbol("sfSoundRecorder_Stop");
sfSoundRecorder_GetSampleRate = cast(pf_sfSoundRecorder_GetSampleRate)dll.getSymbol("sfSoundRecorder_GetSampleRate"); sfSoundRecorder_GetSampleRate = cast(pf_sfSoundRecorder_GetSampleRate)dll.getSymbol("sfSoundRecorder_GetSampleRate");
sfSoundRecorder_CanCapture = cast(pf_sfSoundRecorder_CanCapture)dll.getSymbol("sfSoundRecorder_CanCapture"); sfSoundRecorder_CanCapture = cast(pf_sfSoundRecorder_CanCapture)dll.getSymbol("sfSoundRecorder_CanCapture");
} }
} }
// Use explicit alloc to allow instaciation by C thread // Use explicit alloc to allow instaciation by C thread
private class Samples private class Samples
{ {
mixin Alloc; mixin Alloc;
this(short* data, size_t length) this(short* data, size_t length)
{ {
this.data = data; this.data = data;
this.length = length; this.length = length;
} }
public short* data; public short* data;
public size_t length; public size_t length;
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.audio.soundstatus; module dsfml.audio.soundstatus;

File diff suppressed because it is too large Load diff

View file

@ -1,42 +1,42 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.all; module dsfml.graphics.all;
public import public import
dsfml.graphics.blendmode, dsfml.graphics.blendmode,
dsfml.graphics.color, dsfml.graphics.color,
dsfml.graphics.font, dsfml.graphics.font,
dsfml.graphics.idrawable, dsfml.graphics.idrawable,
dsfml.graphics.image, dsfml.graphics.image,
dsfml.graphics.shader, dsfml.graphics.shader,
dsfml.graphics.rect, dsfml.graphics.rect,
dsfml.graphics.renderwindow, dsfml.graphics.renderwindow,
dsfml.graphics.shape, dsfml.graphics.shape,
dsfml.graphics.sprite, dsfml.graphics.sprite,
dsfml.graphics.text, dsfml.graphics.text,
dsfml.graphics.textstyle, dsfml.graphics.textstyle,
dsfml.graphics.view; dsfml.graphics.view;

View file

@ -1,38 +1,38 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.blendmode; module dsfml.graphics.blendmode;
/** /**
* Enumerate the blending modes for drawable objects. * Enumerate the blending modes for drawable objects.
*/ */
enum BlendMode enum BlendMode
{ {
ALPHA, /// Pixel = Src * a + Dest * (1 - a) ALPHA, /// Pixel = Src * a + Dest * (1 - a)
ADD, /// Pixel = Src + Dest ADD, /// Pixel = Src + Dest
MULTIPLY, /// Pixel = Src * Dest MULTIPLY, /// Pixel = Src * Dest
NONE /// No blending NONE /// No blending
} }

View file

@ -1,132 +1,132 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.color; module dsfml.graphics.color;
/** /**
* Color is an utility structure for manipulating colors * Color is an utility structure for manipulating colors
*/ */
struct Color struct Color
{ {
ubyte r; /// Red component ubyte r; /// Red component
ubyte g; /// Green component ubyte g; /// Green component
ubyte b; /// Blue component ubyte b; /// Blue component
ubyte a = 255; /// Alpha (transparency) component ubyte a = 255; /// Alpha (transparency) component
/** /**
* Construct the color from its 4 RGBA components * Construct the color from its 4 RGBA components
* *
* Params: * Params:
* r = Red component (0 .. 255) * r = Red component (0 .. 255)
* g = Green component (0 .. 255) * g = Green component (0 .. 255)
* b = Blue component (0 .. 255) * b = Blue component (0 .. 255)
* a = Alpha component (0 .. 255) (255 by default) * a = Alpha component (0 .. 255) (255 by default)
*/ */
/* /*
static Color opCall(ubyte r, ubyte g, ubyte b, ubyte a = 255) static Color opCall(ubyte r, ubyte g, ubyte b, ubyte a = 255)
{ {
Color c; Color c;
c.r = r; c.r = r;
c.g = g; c.g = g;
c.b = b; c.b = b;
c.a = a; c.a = a;
return c; return c;
} }
*/ */
/** /**
* Operator == and != overload to compare two colors * Operator == and != overload to compare two colors
*/ */
const bool opEquals(ref const(Color) color2) const bool opEquals(ref const(Color) color2)
{ {
return return
(r == color2.r) (r == color2.r)
&& (g == color2.g) && (g == color2.g)
&& (b == color2.b) && (b == color2.b)
&& (a == color2.a); && (a == color2.a);
} }
/** /**
* Operator + overload to add two colors * Operator + overload to add two colors
*/ */
Color opAdd(Color color2) Color opAdd(Color color2)
{ {
ubyte r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r); ubyte r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
ubyte g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g); ubyte g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
ubyte b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b); ubyte b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
ubyte a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a); ubyte a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
return Color(r, g, b, a); return Color(r, g, b, a);
} }
/** /**
* Operator += overload * Operator += overload
*/ */
Color opAddAssign(Color color2) Color opAddAssign(Color color2)
{ {
this.r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r); this.r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
this.g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g); this.g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
this.b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b); this.b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
this.a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a); this.a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
return this; return this;
} }
/** /**
* Operator * overload to modulate colors * Operator * overload to modulate colors
*/ */
Color opMul(Color color2) Color opMul(Color color2)
{ {
ubyte r = cast(ubyte) (this.r * color2.r / 255); ubyte r = cast(ubyte) (this.r * color2.r / 255);
ubyte g = cast(ubyte) (this.g * color2.g / 255); ubyte g = cast(ubyte) (this.g * color2.g / 255);
ubyte b = cast(ubyte) (this.b * color2.b / 255); ubyte b = cast(ubyte) (this.b * color2.b / 255);
ubyte a = cast(ubyte) (this.a * color2.a / 255); ubyte a = cast(ubyte) (this.a * color2.a / 255);
return Color(r, g, b, a); return Color(r, g, b, a);
} }
/** /**
* Operator *= overload * Operator *= overload
*/ */
Color opMulAssign(Color color2) Color opMulAssign(Color color2)
{ {
this.r = cast(ubyte) (this.r * color2.r / 255); this.r = cast(ubyte) (this.r * color2.r / 255);
this.g = cast(ubyte) (this.g * color2.g / 255); this.g = cast(ubyte) (this.g * color2.g / 255);
this.b = cast(ubyte) (this.b * color2.b / 255); this.b = cast(ubyte) (this.b * color2.b / 255);
this.a = cast(ubyte) (this.a * color2.a / 255); this.a = cast(ubyte) (this.a * color2.a / 255);
return this; return this;
} }
static const Color BLACK = {0, 0, 0}; /// Black predefined color static const Color BLACK = {0, 0, 0}; /// Black predefined color
static const Color WHITE = {255, 255, 255}; /// White predefined color static const Color WHITE = {255, 255, 255}; /// White predefined color
static const Color RED = {255, 0, 0}; /// Red predefined color static const Color RED = {255, 0, 0}; /// Red predefined color
static const Color GREEN = {0, 255, 0}; /// Green predefined color static const Color GREEN = {0, 255, 0}; /// Green predefined color
static const Color BLUE = {0, 0, 255}; /// Blue predefined color static const Color BLUE = {0, 0, 255}; /// Blue predefined color
static const Color YELLOW = {255, 0, 255}; /// Yellow predefined color static const Color YELLOW = {255, 0, 255}; /// Yellow predefined color
static const Color MAGENTA = {255, 0, 255}; /// Magenta predefined color static const Color MAGENTA = {255, 0, 255}; /// Magenta predefined color
static const Color CYAN = {0, 255, 255}; /// Cyan predefined color static const Color CYAN = {0, 255, 255}; /// Cyan predefined color
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.common; module dsfml.graphics.common;

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.drawableimpl; module dsfml.graphics.drawableimpl;
@ -37,14 +37,14 @@ import dsfml.graphics.shader;
package package
{ {
struct sfSprite{}; struct sfSprite{};
struct sfShape{}; struct sfShape{};
struct sfText{}; struct sfText{};
} }
/* /*
* Package base class of all drawable. * Package base class of all drawable.
* Provide implementation of IDrawable and functions aliases. * Provide implementation of IDrawable and functions aliases.
*/ */
package class Drawableimpl(T) : DSFMLObject, IDrawable package class Drawableimpl(T) : DSFMLObject, IDrawable
{ {
@ -60,274 +60,274 @@ protected:
} }
public: public:
void setX(float x) void setX(float x)
{ {
sfDrawable_SetX(m_ptr, x); sfDrawable_SetX(m_ptr, x);
} }
void setY(float y) void setY(float y)
{ {
sfDrawable_SetY(m_ptr, y); sfDrawable_SetY(m_ptr, y);
} }
void setPosition(float x, float y) void setPosition(float x, float y)
{ {
sfDrawable_SetPosition(m_ptr, x, y); sfDrawable_SetPosition(m_ptr, x, y);
} }
void setPosition(Vector2f vec) void setPosition(Vector2f vec)
{ {
sfDrawable_SetPosition(m_ptr, vec.x, vec.y); sfDrawable_SetPosition(m_ptr, vec.x, vec.y);
} }
void setScaleX(float scale) void setScaleX(float scale)
{ {
if (scale > 0) if (scale > 0)
sfDrawable_SetScaleX(m_ptr, scale); sfDrawable_SetScaleX(m_ptr, scale);
} }
void setScaleY(float scale) void setScaleY(float scale)
{ {
if (scale > 0) if (scale > 0)
sfDrawable_SetScaleY(m_ptr, scale); sfDrawable_SetScaleY(m_ptr, scale);
} }
void setScale(float scaleX, float scaleY) void setScale(float scaleX, float scaleY)
{ {
if (scaleX > 0 && scaleY > 0) if (scaleX > 0 && scaleY > 0)
sfDrawable_SetScale(m_ptr, scaleX, scaleY); sfDrawable_SetScale(m_ptr, scaleX, scaleY);
} }
void setScale(Vector2f scale) void setScale(Vector2f scale)
{ {
if (scale.x > 0 && scale.y > 0) if (scale.x > 0 && scale.y > 0)
sfDrawable_SetScale(m_ptr, scale.x, scale.y); sfDrawable_SetScale(m_ptr, scale.x, scale.y);
} }
void setOrigin(float originX, float originY) void setOrigin(float originX, float originY)
{ {
sfDrawable_SetOrigin(m_ptr, originX, originY); sfDrawable_SetOrigin(m_ptr, originX, originY);
} }
void setOrigin(Vector2f origin) void setOrigin(Vector2f origin)
{ {
sfDrawable_SetOrigin(m_ptr, origin.x, origin.y); sfDrawable_SetOrigin(m_ptr, origin.x, origin.y);
} }
void setRotation(float angle) void setRotation(float angle)
{ {
sfDrawable_SetRotation(m_ptr, angle); sfDrawable_SetRotation(m_ptr, angle);
} }
void setColor(Color c) void setColor(Color c)
{ {
sfDrawable_SetColor(m_ptr, c); sfDrawable_SetColor(m_ptr, c);
} }
void setBlendMode(BlendMode mode) void setBlendMode(BlendMode mode)
{ {
sfDrawable_SetBlendMode(m_ptr, mode); sfDrawable_SetBlendMode(m_ptr, mode);
} }
Vector2f getPosition() Vector2f getPosition()
{ {
return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr)); return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr));
} }
Vector2f getScale() Vector2f getScale()
{ {
return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr)); return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr));
} }
Vector2f getOrigin() Vector2f getOrigin()
{ {
return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr)); return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr));
} }
float getRotation() float getRotation()
{ {
return sfDrawable_GetRotation(m_ptr); return sfDrawable_GetRotation(m_ptr);
} }
Color getColor() Color getColor()
{ {
return sfDrawable_GetColor(m_ptr); return sfDrawable_GetColor(m_ptr);
} }
BlendMode getBlendMode() BlendMode getBlendMode()
{ {
return cast(BlendMode)(sfDrawable_GetBlendMode(m_ptr)); return cast(BlendMode)(sfDrawable_GetBlendMode(m_ptr));
} }
void rotate(float angle) void rotate(float angle)
{ {
sfDrawable_Rotate(m_ptr, angle); sfDrawable_Rotate(m_ptr, angle);
} }
void move(float offsetX, float offsetY) void move(float offsetX, float offsetY)
{ {
sfDrawable_Move(m_ptr, offsetX, offsetY); sfDrawable_Move(m_ptr, offsetX, offsetY);
} }
void move(Vector2f offset) void move(Vector2f offset)
{ {
sfDrawable_Move(m_ptr, offset.x, offset.y); sfDrawable_Move(m_ptr, offset.x, offset.y);
} }
void scale(float scaleX, float scaleY) void scale(float scaleX, float scaleY)
{ {
if (scaleX > 0 && scaleY > 0) if (scaleX > 0 && scaleY > 0)
sfDrawable_SetScale(m_ptr, scaleX, scaleY); sfDrawable_SetScale(m_ptr, scaleX, scaleY);
} }
void scale(Vector2f scale) void scale(Vector2f scale)
{ {
if (scale.x > 0 && scale.y > 0) if (scale.x > 0 && scale.y > 0)
sfDrawable_SetScale(m_ptr, scale.x, scale.y); sfDrawable_SetScale(m_ptr, scale.x, scale.y);
} }
Vector2f tranformToLocal(Vector2f point) Vector2f tranformToLocal(Vector2f point)
{ {
Vector2f ret; Vector2f ret;
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y); sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
return ret; return ret;
} }
Vector2f tranformToGlobal(Vector2f point) Vector2f tranformToGlobal(Vector2f point)
{ {
Vector2f ret; Vector2f ret;
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y); sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
return ret; return ret;
} }
void render(RenderWindow window) void render(RenderWindow window)
{ {
sfRenderWindow_DrawThis(window.getNativePointer, m_ptr); sfRenderWindow_DrawThis(window.getNativePointer, m_ptr);
} }
void renderWithShader(RenderWindow window, Shader shader) void renderWithShader(RenderWindow window, Shader shader)
{ {
sfRenderWindow_DrawThisWithShader(window.getNativePointer, m_ptr, shader.getNativePointer); sfRenderWindow_DrawThisWithShader(window.getNativePointer, m_ptr, shader.getNativePointer);
} }
override void dispose() override void dispose()
{ {
sfDrawable_Destroy(m_ptr); sfDrawable_Destroy(m_ptr);
} }
private: private:
extern (C) extern (C)
{ {
typedef void* function() pf_sfDrawable_Create; typedef void* function() pf_sfDrawable_Create;
typedef void function(void*) pf_sfDrawable_Destroy; typedef void function(void*) pf_sfDrawable_Destroy;
typedef void function(void*, float) pf_sfDrawable_SetX; typedef void function(void*, float) pf_sfDrawable_SetX;
typedef void function(void*, float) pf_sfDrawable_SetY; typedef void function(void*, float) pf_sfDrawable_SetY;
typedef void function(void*, float, float) pf_sfDrawable_SetPosition; typedef void function(void*, float, float) pf_sfDrawable_SetPosition;
typedef void function(void*, float) pf_sfDrawable_SetScaleX; typedef void function(void*, float) pf_sfDrawable_SetScaleX;
typedef void function(void*, float) pf_sfDrawable_SetScaleY; typedef void function(void*, float) pf_sfDrawable_SetScaleY;
typedef void function(void*, float, float) pf_sfDrawable_SetScale; typedef void function(void*, float, float) pf_sfDrawable_SetScale;
typedef void function(void*, float) pf_sfDrawable_SetRotation; typedef void function(void*, float) pf_sfDrawable_SetRotation;
typedef void function(void*, float, float) pf_sfDrawable_SetOrigin; typedef void function(void*, float, float) pf_sfDrawable_SetOrigin;
typedef void function(void*, Color) pf_sfDrawable_SetColor; typedef void function(void*, Color) pf_sfDrawable_SetColor;
typedef void function(void*, BlendMode) pf_sfDrawable_SetBlendMode; typedef void function(void*, BlendMode) pf_sfDrawable_SetBlendMode;
typedef float function(void*) pf_sfDrawable_GetX; typedef float function(void*) pf_sfDrawable_GetX;
typedef float function(void*) pf_sfDrawable_GetY; typedef float function(void*) pf_sfDrawable_GetY;
typedef float function(void*) pf_sfDrawable_GetScaleX; typedef float function(void*) pf_sfDrawable_GetScaleX;
typedef float function(void*) pf_sfDrawable_GetScaleY; typedef float function(void*) pf_sfDrawable_GetScaleY;
typedef float function(void*) pf_sfDrawable_GetRotation; typedef float function(void*) pf_sfDrawable_GetRotation;
typedef float function(void*) pf_sfDrawable_GetOriginX; typedef float function(void*) pf_sfDrawable_GetOriginX;
typedef float function(void*) pf_sfDrawable_GetOriginY; typedef float function(void*) pf_sfDrawable_GetOriginY;
typedef Color function(void*) pf_sfDrawable_GetColor; typedef Color function(void*) pf_sfDrawable_GetColor;
typedef BlendMode function(void*) pf_sfDrawable_GetBlendMode; typedef BlendMode function(void*) pf_sfDrawable_GetBlendMode;
typedef void function(void*, float, float) pf_sfDrawable_Move; typedef void function(void*, float, float) pf_sfDrawable_Move;
typedef void function(void*, float, float) pf_sfDrawable_Scale; typedef void function(void*, float, float) pf_sfDrawable_Scale;
typedef void function(void*, float) pf_sfDrawable_Rotate; 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_TransformToLocal;
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToGlobal; typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToGlobal;
typedef void function(void*, void*) pf_sfRenderWindow_DrawThis; typedef void function(void*, void*) pf_sfRenderWindow_DrawThis;
typedef void function(void*, void*, void*) pf_sfRenderWindow_DrawThisWithShader; typedef void function(void*, void*, void*) pf_sfRenderWindow_DrawThisWithShader;
static pf_sfDrawable_Create sfDrawable_Create; static pf_sfDrawable_Create sfDrawable_Create;
static pf_sfDrawable_Destroy sfDrawable_Destroy; static pf_sfDrawable_Destroy sfDrawable_Destroy;
static pf_sfDrawable_SetX sfDrawable_SetX; static pf_sfDrawable_SetX sfDrawable_SetX;
static pf_sfDrawable_SetY sfDrawable_SetY; static pf_sfDrawable_SetY sfDrawable_SetY;
static pf_sfDrawable_SetPosition sfDrawable_SetPosition; static pf_sfDrawable_SetPosition sfDrawable_SetPosition;
static pf_sfDrawable_SetScaleX sfDrawable_SetScaleX; static pf_sfDrawable_SetScaleX sfDrawable_SetScaleX;
static pf_sfDrawable_SetScaleY sfDrawable_SetScaleY; static pf_sfDrawable_SetScaleY sfDrawable_SetScaleY;
static pf_sfDrawable_SetScale sfDrawable_SetScale; static pf_sfDrawable_SetScale sfDrawable_SetScale;
static pf_sfDrawable_SetRotation sfDrawable_SetRotation; static pf_sfDrawable_SetRotation sfDrawable_SetRotation;
static pf_sfDrawable_SetOrigin sfDrawable_SetOrigin; static pf_sfDrawable_SetOrigin sfDrawable_SetOrigin;
static pf_sfDrawable_SetColor sfDrawable_SetColor; static pf_sfDrawable_SetColor sfDrawable_SetColor;
static pf_sfDrawable_SetBlendMode sfDrawable_SetBlendMode; static pf_sfDrawable_SetBlendMode sfDrawable_SetBlendMode;
static pf_sfDrawable_GetX sfDrawable_GetX; static pf_sfDrawable_GetX sfDrawable_GetX;
static pf_sfDrawable_GetY sfDrawable_GetY; static pf_sfDrawable_GetY sfDrawable_GetY;
static pf_sfDrawable_GetScaleX sfDrawable_GetScaleX; static pf_sfDrawable_GetScaleX sfDrawable_GetScaleX;
static pf_sfDrawable_GetScaleY sfDrawable_GetScaleY; static pf_sfDrawable_GetScaleY sfDrawable_GetScaleY;
static pf_sfDrawable_GetRotation sfDrawable_GetRotation; static pf_sfDrawable_GetRotation sfDrawable_GetRotation;
static pf_sfDrawable_GetOriginX sfDrawable_GetOriginX; static pf_sfDrawable_GetOriginX sfDrawable_GetOriginX;
static pf_sfDrawable_GetOriginY sfDrawable_GetOriginY; static pf_sfDrawable_GetOriginY sfDrawable_GetOriginY;
static pf_sfDrawable_GetColor sfDrawable_GetColor; static pf_sfDrawable_GetColor sfDrawable_GetColor;
static pf_sfDrawable_GetBlendMode sfDrawable_GetBlendMode; static pf_sfDrawable_GetBlendMode sfDrawable_GetBlendMode;
static pf_sfDrawable_Move sfDrawable_Move; static pf_sfDrawable_Move sfDrawable_Move;
static pf_sfDrawable_Scale sfDrawable_Scale; static pf_sfDrawable_Scale sfDrawable_Scale;
static pf_sfDrawable_Rotate sfDrawable_Rotate; static pf_sfDrawable_Rotate sfDrawable_Rotate;
static pf_sfDrawable_TransformToLocal sfDrawable_TransformToLocal; static pf_sfDrawable_TransformToLocal sfDrawable_TransformToLocal;
static pf_sfDrawable_TransformToGlobal sfDrawable_TransformToGlobal; static pf_sfDrawable_TransformToGlobal sfDrawable_TransformToGlobal;
static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis; static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis;
static pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader; static pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-graphics-d"); DllLoader dll = DllLoader.load("csfml-graphics-d");
else else
DllLoader dll = DllLoader.load("csfml-graphics"); DllLoader dll = DllLoader.load("csfml-graphics");
static if (is (T : sfSprite)) static if (is (T : sfSprite))
{ {
string symbol = "sfSprite"; string symbol = "sfSprite";
} }
else static if (is (T : sfText)) else static if (is (T : sfText))
{ {
string symbol = "sfText"; string symbol = "sfText";
} }
else static if (is (T : sfShape)) else static if (is (T : sfShape))
{ {
string symbol = "sfShape"; string symbol = "sfShape";
} }
sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create"); sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create");
sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy"); sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy");
sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX"); sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX");
sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY"); sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY");
sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition"); sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition");
sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX"); sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX");
sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY"); sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY");
sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale"); sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale");
sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation"); sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation");
sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin"); sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin");
sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor"); sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor");
sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode"); sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode");
sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX"); sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX");
sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY"); sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY");
sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX"); sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX");
sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)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_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation");
sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX"); sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX");
sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY"); sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY");
sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor"); sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor");
sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode"); sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode");
sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move"); sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move");
sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale"); sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale");
sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate"); sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate");
sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal"); sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal");
sfDrawable_TransformToGlobal = cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal"); sfDrawable_TransformToGlobal = cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal");
sfRenderWindow_DrawThis = cast(pf_sfRenderWindow_DrawThis)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$]); 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"); sfRenderWindow_DrawThisWithShader = cast(pf_sfRenderWindow_DrawThisWithShader)dll.getSymbol("sfRenderWindow_Draw" ~ symbol[2..$] ~ "WithShader");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.font; module dsfml.graphics.font;
@ -43,8 +43,8 @@ struct Glyph
} }
/** /**
* Font is the low-level class for loading and * Font is the low-level class for loading and
* manipulating character fonts. * manipulating character fonts.
*/ */
class Font : DSFMLObject class Font : DSFMLObject
{ {
@ -53,54 +53,54 @@ private:
public: public:
/** /**
* Get SFML default built-in font (Arial) * Get SFML default built-in font (Arial)
*/ */
static Font getDefaultFont() static Font getDefaultFont()
{ {
if (s_default is null) if (s_default is null)
s_default = new Font(sfFont_GetDefaultFont()); s_default = new Font(sfFont_GetDefaultFont());
return s_default; return s_default;
} }
/** /**
* construct the Font from a file * construct the Font from a file
* *
* Params: * Params:
* filename = font file to load * filename = font file to load
*/ */
this(string filename) this(string filename)
{ {
if (filename is null || filename.length == 0) if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid."); throw new LoadingException("LoadingException : Filename is invalid.");
super(sfFont_CreateFromFile(toStringz(filename))); super(sfFont_CreateFromFile(toStringz(filename)));
} }
/** /**
* construct the Font from a file in memory * construct the Font from a file in memory
* *
* Params: * Params:
* data = data to load * data = data to load
*/ */
this(ubyte[] data) this(ubyte[] data)
{ {
if (data is null || data.length == 0) if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid."); throw new Exception("LoadingException : Memory stream is invalid.");
super(sfFont_CreateFromMemory(data.ptr, data.length)); super(sfFont_CreateFromMemory(data.ptr, data.length));
} }
override void dispose() override void dispose()
{ {
sfFont_Destroy(m_ptr); sfFont_Destroy(m_ptr);
} }
package: package:
this(void* ptr) this(void* ptr)
{ {
super(ptr, true); super(ptr, true);
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.idrawable; module dsfml.graphics.idrawable;
@ -35,259 +35,259 @@ import dsfml.graphics.color,
/** /**
* Interface for drawable object * Interface for drawable object
* *
* Shape, Text and Sprite implement IDrawable * Shape, Text and Sprite implement IDrawable
*/ */
interface IDrawable interface IDrawable
{ {
/** /**
* Set the left position of the object * Set the left position of the object
* *
* Params: * Params:
* x = New left coordinate * x = New left coordinate
*/ */
void setX(float x); void setX(float x);
/** /**
* Set the top position of the object * Set the top position of the object
* *
* Params: * Params:
* y = New top coordinate * y = New top coordinate
*/ */
void setY(float y); void setY(float y);
/** /**
* Set the position of the object * Set the position of the object
* *
* Params: * Params:
* x = New left coordinate * x = New left coordinate
* y = New top coordinate * y = New top coordinate
*/ */
void setPosition(float x, float y); void setPosition(float x, float y);
/** /**
* Set the position of the object * Set the position of the object
* *
* Params: * Params:
* vec = new position * vec = new position
*/ */
void setPosition(Vector2f vec); void setPosition(Vector2f vec);
/** /**
* Set the horizontal scale of the object * Set the horizontal scale of the object
* *
* Params: * Params:
* scale = New horizontal scale (Strictly positive) * scale = New horizontal scale (Strictly positive)
*/ */
void setScaleX(float scale); void setScaleX(float scale);
/** /**
* Set the vertical scale of the object * Set the vertical scale of the object
* *
* Params: * Params:
* scale = New vertical scale (Strictly positive) * scale = New vertical scale (Strictly positive)
*/ */
void setScaleY(float scale); void setScaleY(float scale);
/** /**
* Set the scale of the object * Set the scale of the object
* *
* Params: * Params:
* scaleX = New horizontal scale * scaleX = New horizontal scale
* scaleY = New vertical scale * scaleY = New vertical scale
*/ */
void setScale(float scaleX, float scaleY); void setScale(float scaleX, float scaleY);
/** /**
* Set the scale of the object * Set the scale of the object
* *
* Params: * Params:
* scale = new scale * scale = new scale
*/ */
void setScale(Vector2f scale); void setScale(Vector2f scale);
/** /**
* Set the origin of the object, in coordinates relative to the * Set the origin of the object, in coordinates relative to the
* top-left of the object (take 2 values). * top-left of the object (take 2 values).
* The default origin is (0, 0) * The default origin is (0, 0)
* *
* Params: * Params:
* originX : X coordinate of the origin * originX : X coordinate of the origin
* originY : Y coordinate of the origin * originY : Y coordinate of the origin
*/ */
void setOrigin(float originX, float originY); void setOrigin(float originX, float originY);
/** /**
* Set the origin of the object, in coordinates relative to the * Set the origin of the object, in coordinates relative to the
* top-left of the object (take a 2D vector). * top-left of the object (take a 2D vector).
* The default origin is (0, 0) * The default origin is (0, 0)
* *
* Params: * Params:
* origin : New origin * origin : New origin
*/ */
void setOrigin(Vector2f origin); void setOrigin(Vector2f origin);
/** /**
* Set the rotation of the object * Set the rotation of the object
* *
* Params: * Params:
* angle = Angle of rotation, in degree * angle = Angle of rotation, in degree
*/ */
void setRotation(float angle); void setRotation(float angle);
/** /**
* Set the color * Set the color
* *
* Params: * Params:
* c = New color * c = New color
*/ */
void setColor(Color c); void setColor(Color c);
/** /**
* Set the blending mode for the object. * Set the blending mode for the object.
* The default blend mode is Blend.Alpha * The default blend mode is Blend.Alpha
* *
* Params: * Params:
* mode = New blending mode * mode = New blending mode
*/ */
void setBlendMode(BlendMode mode); void setBlendMode(BlendMode mode);
/** /**
* Get the position of the object * Get the position of the object
* *
* Returns: * Returns:
* Current position * Current position
* *
*/ */
Vector2f getPosition(); Vector2f getPosition();
/** /**
* Get the current scale of the object * Get the current scale of the object
* *
* Returns: * Returns:
* Current scale * Current scale
*/ */
Vector2f getScale(); Vector2f getScale();
/** /**
* Get the origin of the object * Get the origin of the object
* *
* Returns: * Returns:
* Current position of the origin * Current position of the origin
* *
*/ */
Vector2f getOrigin(); Vector2f getOrigin();
/** /**
* Get the rotation angle of the object * Get the rotation angle of the object
* *
* Returns: * Returns:
* Angle of rotation, in degree * Angle of rotation, in degree
*/ */
float getRotation(); float getRotation();
/** /**
* Get the color of the string * Get the color of the string
* *
* Returns: * Returns:
* Current color * Current color
*/ */
Color getColor(); Color getColor();
/** /**
* Get the current blending mode * Get the current blending mode
* *
* Returns: * Returns:
* Current blending mode * Current blending mode
*/ */
BlendMode getBlendMode(); BlendMode getBlendMode();
/** /**
* Rotate the object * Rotate the object
* Angle is added to the current orientation of the objet * Angle is added to the current orientation of the objet
* *
* Params: * Params:
* angle = Angle of rotation in degree * angle = Angle of rotation in degree
*/ */
void rotate(float angle); void rotate(float angle);
/** /**
* Move the object * Move the object
* New offset is added to object current position * New offset is added to object current position
* *
* Params: * Params:
* offsetX = Offset on the X axis * offsetX = Offset on the X axis
* offsetY = Offset on the Y axis * offsetY = Offset on the Y axis
*/ */
void move(float offsetX, float offsetY); void move(float offsetX, float offsetY);
/** /**
* Move the object * Move the object
* New offset is added to object current position * New offset is added to object current position
* *
* Params: * Params:
* offset = Amount of units to move the object of * offset = Amount of units to move the object of
*/ */
void move(Vector2f offset); void move(Vector2f offset);
/** /**
* Set the scale of the object * Set the scale of the object
* *
* Params: * Params:
* scaleX = New horizontal scale (Strictly positive) * scaleX = New horizontal scale (Strictly positive)
* scaleY = New vertical scale (Strictly positive) * scaleY = New vertical scale (Strictly positive)
*/ */
void scale(float scaleX, float scaleY); void scale(float scaleX, float scaleY);
/** /**
* Scale the object (take a 2D vector) * Scale the object (take a 2D vector)
* *
* Params: * Params:
* factor = Scaling factors (both values must be strictly positive) * factor = Scaling factors (both values must be strictly positive)
*/ */
void scale(Vector2f factor); void scale(Vector2f factor);
/** /**
* Transform a point from global coordinates into local coordinates * Transform a point from global coordinates into local coordinates
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point) * (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
* *
* Params: * Params:
* point = Point to transform * point = Point to transform
* *
* Returns: * Returns:
* Transformed point * Transformed point
*/ */
Vector2f tranformToLocal(Vector2f point); Vector2f tranformToLocal(Vector2f point);
/** /**
* Transform a point from local coordinates into global coordinates * Transform a point from local coordinates into global coordinates
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point) * (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
* *
* Params: * Params:
* point = Point to transform * point = Point to transform
* *
* Returns: * Returns:
* Transformed point * Transformed point
*/ */
Vector2f tranformToGlobal(Vector2f point); Vector2f tranformToGlobal(Vector2f point);
/** /**
* Render the specific geometry of the object * Render the specific geometry of the object
* *
* Params: * Params:
* window = Target into which render the object * window = Target into which render the object
*/ */
void render(RenderWindow window); void render(RenderWindow window);
/** /**
* Render the specific geometry of the object with a shader * Render the specific geometry of the object with a shader
* *
* Params: * Params:
* window = Render target * window = Render target
* shader = Shader to use * shader = Shader to use
*/ */
void renderWithShader(RenderWindow window, Shader shader); void renderWithShader(RenderWindow window, Shader shader);
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
@ -37,331 +37,331 @@ import dsfml.system.common,
/** /**
* Image is the low-level class for loading and * Image is the low-level class for loading and
* manipulating images * manipulating images
*/ */
class Image : DSFMLObject class Image : DSFMLObject
{ {
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
super(sfImage_Create()); super(sfImage_Create());
} }
/** /**
* Construct an empty image * Construct an empty image
* *
* Params: * Params:
* width = Image width * width = Image width
* height = Image height * height = Image height
* col = Image color (black by default) * col = Image color (black by default)
*/ */
this(uint width, uint height, Color col = Color.BLACK) this(uint width, uint height, Color col = Color.BLACK)
{ {
super(sfImage_CreateFromColor(width, height, col)); super(sfImage_CreateFromColor(width, height, col));
} }
/** /**
* Construct the image from a file * Construct the image from a file
* *
* Params: * Params:
* filename = Path of the image file to load * filename = Path of the image file to load
* *
* Throws: * Throws:
* LoadingException if filename is empty or null. * LoadingException if filename is empty or null.
*/ */
this(string filename) this(string filename)
{ {
if (filename is null || filename.length == 0) if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid."); throw new LoadingException("LoadingException : Filename is invalid.");
super(sfImage_CreateFromFile(toStringz(filename))); super(sfImage_CreateFromFile(toStringz(filename)));
} }
/** /**
* Construct the image from a file in memory * Construct the image from a file in memory
* *
* Params: * Params:
* data = array of data in memory * data = array of data in memory
* Throws: * Throws:
* LoadingException if data is empty or null. * LoadingException if data is empty or null.
*/ */
this(ubyte[] data) this(ubyte[] data)
{ {
if (data is null || data.length == 0) if (data is null || data.length == 0)
throw new LoadingException("LoadingException : Memory stream is invalid."); throw new LoadingException("LoadingException : Memory stream is invalid.");
super(sfImage_CreateFromMemory(data.ptr, data.length)); super(sfImage_CreateFromMemory(data.ptr, data.length));
} }
/** /**
* Construct the image directly from an array of pixels * Construct the image directly from an array of pixels
* *
* Params: * Params:
* width = Image width * width = Image width
* height = Image height * height = Image height
* data = array of pixels in memory (assumed format is RGBA) * data = array of pixels in memory (assumed format is RGBA)
* *
* Throws: * Throws:
* LoadingException if data length doesn't match Width * Height * 4 * LoadingException if data length doesn't match Width * Height * 4
*/ */
this(uint width, uint height, ubyte[] data) this(uint width, uint height, ubyte[] data)
{ {
if (width * height * 4 != data.length) if (width * height * 4 != data.length)
throw new LoadingException("LoadingException : Pixels array length doesn't match the specified size."); throw new LoadingException("LoadingException : Pixels array length doesn't match the specified size.");
super(sfImage_CreateFromPixels(width, height, data.ptr)); super(sfImage_CreateFromPixels(width, height, data.ptr));
} }
override void dispose() override void dispose()
{ {
sfImage_Destroy(m_ptr); sfImage_Destroy(m_ptr);
} }
/** /**
* Save the content of the image to a file * Save the content of the image to a file
* *
* Params: * Params:
* filename = Path of the file to save (overwritten if already exist) * filename = Path of the file to save (overwritten if already exist)
* *
* Returns: * Returns:
* True if saving was successful * True if saving was successful
*/ */
bool saveToFile(string filename) bool saveToFile(string filename)
{ {
return cast(bool)sfImage_SaveToFile(m_ptr, toStringz(filename)); return cast(bool)sfImage_SaveToFile(m_ptr, toStringz(filename));
} }
/** /**
* Create an empty image * Create an empty image
* *
* Params: * Params:
* width = Image width * width = Image width
* height = Image height * height = Image height
* col = Image color (black by default) * col = Image color (black by default)
* *
* Returns: * Returns:
* True if creation was successful * True if creation was successful
*/ */
bool create(uint width, uint height, Color col = Color.BLACK) bool create(uint width, uint height, Color col = Color.BLACK)
{ {
m_ptr = sfImage_CreateFromColor(width, height, col); m_ptr = sfImage_CreateFromColor(width, height, col);
return (m_ptr !is null); return (m_ptr !is null);
} }
/** /**
* Create transparency mask from a specified colorkey * Create transparency mask from a specified colorkey
* *
* Params: * Params:
* colorKey = Color to become transparent * colorKey = Color to become transparent
* alpha = Alpha value to use for transparent pixels (0 by default) * alpha = Alpha value to use for transparent pixels (0 by default)
*/ */
void createMaskFromColor(Color colorKey, ubyte alpha = 0) void createMaskFromColor(Color colorKey, ubyte alpha = 0)
{ {
sfImage_CreateMaskFromColor(m_ptr, colorKey, alpha); sfImage_CreateMaskFromColor(m_ptr, colorKey, alpha);
} }
// /** // /**
// * Create the image from the current contents of the // * Create the image from the current contents of the
// * given window // * given window
// * // *
// * Params: // * Params:
// * window = Window to capture // * window = Window to capture
// * sourceRect = Sub-rectangle of the screen to copy (empty by default - entire image) // * sourceRect = Sub-rectangle of the screen to copy (empty by default - entire image)
// * // *
// * Returns: // * Returns:
// * True if copy was successful // * True if copy was successful
// */ // */
// void copyScreen(RenderWindow window, IntRect sourceRect = new IntRect()) // 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.toCIntRect());
// } // }
/** /**
* Copy pixels from another image onto this one. * Copy pixels from another image onto this one.
* This function does a slow pixel copy and should only * This function does a slow pixel copy and should only
* be used at initialization time * be used at initialization time
* *
* Params: * Params:
* source = Source image to copy * source = Source image to copy
* destX = X coordinate of the destination position * destX = X coordinate of the destination position
* destY = Y coordinate of the destination position * destY = Y coordinate of the destination position
* sourceRect = Sub-rectangle of the source image to copy * 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 = new IntRect())
{ {
sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect.toCIntRect()); sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect.toCIntRect());
} }
/** /**
* Change the color of a pixel * Change the color of a pixel
* Don't forget to call Update when you end modifying pixels * Don't forget to call Update when you end modifying pixels
* *
* Params: * Params:
* x = X coordinate of pixel in the image * x = X coordinate of pixel in the image
* y = Y coordinate of pixel in the image * y = Y coordinate of pixel in the image
* col = New color for pixel (X, Y) * col = New color for pixel (X, Y)
*/ */
void setPixel(uint x, uint y, Color col) void setPixel(uint x, uint y, Color col)
{ {
sfImage_SetPixel(m_ptr, x, y, col); sfImage_SetPixel(m_ptr, x, y, col);
} }
/** /**
* Get a pixel from the image * Get a pixel from the image
* *
* Params: * Params:
* x = X coordinate of pixel in the image * x = X coordinate of pixel in the image
* y = Y coordinate of pixel in the image * y = Y coordinate of pixel in the image
* *
* Returns: * Returns:
* Color of pixel (x, y) * Color of pixel (x, y)
*/ */
Color getPixel(uint x, uint y) Color getPixel(uint x, uint y)
{ {
return sfImage_GetPixel(m_ptr, x, y); return sfImage_GetPixel(m_ptr, x, y);
} }
/** /**
* Get an array of pixels (8 bits integers RGBA) * Get an array of pixels (8 bits integers RGBA)
* Array size is GetWidth() x GetHeight() x 4 * Array size is GetWidth() x GetHeight() x 4
* This array becomes invalid if you reload or resize the image * This array becomes invalid if you reload or resize the image
* *
* Returns: * Returns:
* array of pixels * array of pixels
*/ */
ubyte[] getPixelsArray() ubyte[] getPixelsArray()
{ {
return sfImage_GetPixelsPtr(m_ptr)[0..getWidth() * getHeight() * 4]; return sfImage_GetPixelsPtr(m_ptr)[0..getWidth() * getHeight() * 4];
} }
/** /**
* Bind the image for rendering * Bind the image for rendering
*/ */
void bind() void bind()
{ {
sfImage_Bind(m_ptr); sfImage_Bind(m_ptr);
} }
/** /**
* Enable or disable image smooth filter. * Enable or disable image smooth filter.
* This parameter is enabled by default * This parameter is enabled by default
* *
* Params: * Params:
* smooth = True to enable smoothing filter, false to disable it * smooth = True to enable smoothing filter, false to disable it
*/ */
void setSmooth(bool smooth) void setSmooth(bool smooth)
{ {
sfImage_SetSmooth(m_ptr, smooth); sfImage_SetSmooth(m_ptr, smooth);
} }
/** /**
* Return the width of the image * Return the width of the image
* *
* Returns: * Returns:
* Width in pixels * Width in pixels
*/ */
uint getWidth() uint getWidth()
{ {
return sfImage_GetWidth(m_ptr); return sfImage_GetWidth(m_ptr);
} }
/** /**
* Return the height of the image * Return the height of the image
* *
* Returns: * Returns:
* Height in pixels * Height in pixels
*/ */
uint getHeight() uint getHeight()
{ {
return sfImage_GetHeight(m_ptr); return sfImage_GetHeight(m_ptr);
} }
/** /**
* Tells whether the smooth filtering is enabled or not * Tells whether the smooth filtering is enabled or not
* *
* Returns: * Returns:
* True if image smoothing is enabled * True if image smoothing is enabled
*/ */
bool isSmooth() bool isSmooth()
{ {
return cast(bool)sfImage_IsSmooth(m_ptr); return cast(bool)sfImage_IsSmooth(m_ptr);
} }
package: package:
this(void* ptr) this(void* ptr)
{ {
super(ptr); super(ptr);
} }
private: private:
extern (C) extern (C)
{ {
typedef void* function() pf_sfImage_Create; typedef void* function() pf_sfImage_Create;
typedef void* function(uint, uint, Color) pf_sfImage_CreateFromColor; typedef void* function(uint, uint, Color) pf_sfImage_CreateFromColor;
typedef void* function(uint, uint, ubyte*) pf_sfImage_CreateFromPixels; typedef void* function(uint, uint, ubyte*) pf_sfImage_CreateFromPixels;
typedef void* function(cchar*) pf_sfImage_CreateFromFile; typedef void* function(cchar*) pf_sfImage_CreateFromFile;
typedef void* function(ubyte* ,size_t) pf_sfImage_CreateFromMemory; typedef void* function(ubyte* ,size_t) pf_sfImage_CreateFromMemory;
typedef void function(void*) pf_sfImage_Destroy; typedef void function(void*) pf_sfImage_Destroy;
typedef int function(void*, cchar*) pf_sfImage_SaveToFile; typedef int function(void*, cchar*) pf_sfImage_SaveToFile;
typedef void function(void*, Color, ubyte) pf_sfImage_CreateMaskFromColor; typedef void function(void*, Color, ubyte) pf_sfImage_CreateMaskFromColor;
typedef int function(void*, void*, sfIntRect) pf_sfImage_CopyScreen; typedef int function(void*, void*, sfIntRect) pf_sfImage_CopyScreen;
typedef void function(void*, void*, uint, uint, sfIntRect) pf_sfImage_Copy; typedef void function(void*, void*, uint, uint, sfIntRect) pf_sfImage_Copy;
typedef void function(void*, uint, uint, Color) pf_sfImage_SetPixel; typedef void function(void*, uint, uint, Color) pf_sfImage_SetPixel;
typedef Color function(void*, uint, uint) pf_sfImage_GetPixel; typedef Color function(void*, uint, uint) pf_sfImage_GetPixel;
typedef ubyte* function(void*) pf_sfImage_GetPixelsPtr; typedef ubyte* function(void*) pf_sfImage_GetPixelsPtr;
typedef void function(void*) pf_sfImage_Bind; typedef void function(void*) pf_sfImage_Bind;
typedef void function(void*, int) pf_sfImage_SetSmooth; typedef void function(void*, int) pf_sfImage_SetSmooth;
typedef uint function(void*) pf_sfImage_GetWidth; typedef uint function(void*) pf_sfImage_GetWidth;
typedef uint function(void*) pf_sfImage_GetHeight; typedef uint function(void*) pf_sfImage_GetHeight;
typedef int function(void*) pf_sfImage_IsSmooth; typedef int function(void*) pf_sfImage_IsSmooth;
static pf_sfImage_Create sfImage_Create; static pf_sfImage_Create sfImage_Create;
static pf_sfImage_CreateFromColor sfImage_CreateFromColor; static pf_sfImage_CreateFromColor sfImage_CreateFromColor;
static pf_sfImage_CreateFromPixels sfImage_CreateFromPixels; static pf_sfImage_CreateFromPixels sfImage_CreateFromPixels;
static pf_sfImage_CreateFromFile sfImage_CreateFromFile; static pf_sfImage_CreateFromFile sfImage_CreateFromFile;
static pf_sfImage_CreateFromMemory sfImage_CreateFromMemory; static pf_sfImage_CreateFromMemory sfImage_CreateFromMemory;
static pf_sfImage_Destroy sfImage_Destroy; static pf_sfImage_Destroy sfImage_Destroy;
static pf_sfImage_SaveToFile sfImage_SaveToFile; static pf_sfImage_SaveToFile sfImage_SaveToFile;
static pf_sfImage_CreateMaskFromColor sfImage_CreateMaskFromColor; static pf_sfImage_CreateMaskFromColor sfImage_CreateMaskFromColor;
static pf_sfImage_CopyScreen sfImage_CopyScreen; static pf_sfImage_CopyScreen sfImage_CopyScreen;
static pf_sfImage_Copy sfImage_Copy; static pf_sfImage_Copy sfImage_Copy;
static pf_sfImage_SetPixel sfImage_SetPixel; static pf_sfImage_SetPixel sfImage_SetPixel;
static pf_sfImage_GetPixel sfImage_GetPixel; static pf_sfImage_GetPixel sfImage_GetPixel;
static pf_sfImage_GetPixelsPtr sfImage_GetPixelsPtr; static pf_sfImage_GetPixelsPtr sfImage_GetPixelsPtr;
static pf_sfImage_Bind sfImage_Bind; static pf_sfImage_Bind sfImage_Bind;
static pf_sfImage_SetSmooth sfImage_SetSmooth; static pf_sfImage_SetSmooth sfImage_SetSmooth;
static pf_sfImage_GetWidth sfImage_GetWidth; static pf_sfImage_GetWidth sfImage_GetWidth;
static pf_sfImage_GetHeight sfImage_GetHeight; static pf_sfImage_GetHeight sfImage_GetHeight;
static pf_sfImage_IsSmooth sfImage_IsSmooth; static pf_sfImage_IsSmooth sfImage_IsSmooth;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-graphics-d"); DllLoader dll = DllLoader.load("csfml-graphics-d");
else else
DllLoader dll = DllLoader.load("csfml-graphics"); DllLoader dll = DllLoader.load("csfml-graphics");
sfImage_Create = cast(pf_sfImage_Create)dll.getSymbol("sfImage_Create"); sfImage_Create = cast(pf_sfImage_Create)dll.getSymbol("sfImage_Create");
sfImage_CreateFromColor = cast(pf_sfImage_CreateFromColor)dll.getSymbol("sfImage_CreateFromColor"); sfImage_CreateFromColor = cast(pf_sfImage_CreateFromColor)dll.getSymbol("sfImage_CreateFromColor");
sfImage_CreateFromPixels = cast(pf_sfImage_CreateFromPixels)dll.getSymbol("sfImage_CreateFromPixels"); sfImage_CreateFromPixels = cast(pf_sfImage_CreateFromPixels)dll.getSymbol("sfImage_CreateFromPixels");
sfImage_CreateFromFile = cast(pf_sfImage_CreateFromFile)dll.getSymbol("sfImage_CreateFromFile"); sfImage_CreateFromFile = cast(pf_sfImage_CreateFromFile)dll.getSymbol("sfImage_CreateFromFile");
sfImage_CreateFromMemory = cast(pf_sfImage_CreateFromMemory)dll.getSymbol("sfImage_CreateFromMemory"); sfImage_CreateFromMemory = cast(pf_sfImage_CreateFromMemory)dll.getSymbol("sfImage_CreateFromMemory");
sfImage_Destroy = cast(pf_sfImage_Destroy)dll.getSymbol("sfImage_Destroy"); sfImage_Destroy = cast(pf_sfImage_Destroy)dll.getSymbol("sfImage_Destroy");
sfImage_SaveToFile = cast(pf_sfImage_SaveToFile)dll.getSymbol("sfImage_SaveToFile"); sfImage_SaveToFile = cast(pf_sfImage_SaveToFile)dll.getSymbol("sfImage_SaveToFile");
sfImage_CreateMaskFromColor = cast(pf_sfImage_CreateMaskFromColor)dll.getSymbol("sfImage_CreateMaskFromColor"); sfImage_CreateMaskFromColor = cast(pf_sfImage_CreateMaskFromColor)dll.getSymbol("sfImage_CreateMaskFromColor");
sfImage_CopyScreen = cast(pf_sfImage_CopyScreen)dll.getSymbol("sfImage_CopyScreen"); sfImage_CopyScreen = cast(pf_sfImage_CopyScreen)dll.getSymbol("sfImage_CopyScreen");
sfImage_Copy = cast(pf_sfImage_Copy)dll.getSymbol("sfImage_Copy"); sfImage_Copy = cast(pf_sfImage_Copy)dll.getSymbol("sfImage_Copy");
sfImage_SetPixel = cast(pf_sfImage_SetPixel)dll.getSymbol("sfImage_SetPixel"); sfImage_SetPixel = cast(pf_sfImage_SetPixel)dll.getSymbol("sfImage_SetPixel");
sfImage_GetPixel = cast(pf_sfImage_GetPixel)dll.getSymbol("sfImage_GetPixel"); sfImage_GetPixel = cast(pf_sfImage_GetPixel)dll.getSymbol("sfImage_GetPixel");
sfImage_GetPixelsPtr = cast(pf_sfImage_GetPixelsPtr)dll.getSymbol("sfImage_GetPixelsPtr"); sfImage_GetPixelsPtr = cast(pf_sfImage_GetPixelsPtr)dll.getSymbol("sfImage_GetPixelsPtr");
sfImage_Bind = cast(pf_sfImage_Bind)dll.getSymbol("sfImage_Bind"); sfImage_Bind = cast(pf_sfImage_Bind)dll.getSymbol("sfImage_Bind");
sfImage_SetSmooth = cast(pf_sfImage_SetSmooth)dll.getSymbol("sfImage_SetSmooth"); sfImage_SetSmooth = cast(pf_sfImage_SetSmooth)dll.getSymbol("sfImage_SetSmooth");
sfImage_GetWidth = cast(pf_sfImage_GetWidth)dll.getSymbol("sfImage_GetWidth"); sfImage_GetWidth = cast(pf_sfImage_GetWidth)dll.getSymbol("sfImage_GetWidth");
sfImage_GetHeight = cast(pf_sfImage_GetHeight)dll.getSymbol("sfImage_GetHeight"); sfImage_GetHeight = cast(pf_sfImage_GetHeight)dll.getSymbol("sfImage_GetHeight");
sfImage_IsSmooth = cast(pf_sfImage_IsSmooth)dll.getSymbol("sfImage_IsSmooth"); sfImage_IsSmooth = cast(pf_sfImage_IsSmooth)dll.getSymbol("sfImage_IsSmooth");
} }
} }

View file

@ -1,287 +1,287 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.rect; module dsfml.graphics.rect;
struct sfFloatRect struct sfFloatRect
{ {
float Left; float Left;
float Top; float Top;
float Right; float Right;
float Bottom; float Bottom;
} }
struct sfIntRect struct sfIntRect
{ {
int Left; int Left;
int Top; int Top;
int Right; int Right;
int Bottom; int Bottom;
} }
version (Tango) version (Tango)
{ {
import tango.core.Traits; import tango.core.Traits;
} }
else else
{ {
template isIntegerType(T) template isIntegerType(T)
{ {
const bool isIntegerType = const bool isIntegerType =
is (T == byte) || is (T == byte) ||
is (T == short) || is (T == short) ||
is (T == int) || is (T == int) ||
is (T == long); is (T == long);
} }
template isRealType(T) template isRealType(T)
{ {
const bool isRealType = const bool isRealType =
is (T == float) || is (T == float) ||
is (T == double) || is (T == double) ||
is (T == real); is (T == real);
} }
} }
/** /**
* Rect is an utility class for manipulating rectangles. * Rect is an utility class for manipulating rectangles.
* Template parameter defines the type of coordinates (integer float, ...) * Template parameter defines the type of coordinates (integer float, ...)
*/ */
class Rect (T) class Rect (T)
{ {
private: private:
T m_Left; // Left coordinate of the rectangle T m_Left; // Left coordinate of the rectangle
T m_Top; // Top coordinate of the rectangle T m_Top; // Top coordinate of the rectangle
T m_Right; // Right coordinate of the rectangle T m_Right; // Right coordinate of the rectangle
T m_Bottom; // Bottom coordinate of the rectangle T m_Bottom; // Bottom coordinate of the rectangle
public: public:
static if (!isIntegerType!(T) && !isRealType!(T)) static if (!isIntegerType!(T) && !isRealType!(T))
{ {
static assert (0, "This type is not supported by Rectangle"); static assert (0, "This type is not supported by Rectangle");
} }
T min(T)(T i, T j) T min(T)(T i, T j)
{ {
return i < j ? i : j; return i < j ? i : j;
} }
T max(T)(T i, T j) T max(T)(T i, T j)
{ {
return i > j ? i : j; return i > j ? i : j;
} }
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
m_Left = 0; m_Left = 0;
m_Top = 0; m_Top = 0;
m_Right = 0; m_Right = 0;
m_Bottom = 0; m_Bottom = 0;
} }
/** /**
* Construct the rectangle from its coordinates * Construct the rectangle from its coordinates
* *
* Params: * Params:
* leftCoord = Left coordinate of the rectangle * leftCoord = Left coordinate of the rectangle
* topCoord = Top coordinate of the rectangle * topCoord = Top coordinate of the rectangle
* rightCoord = Right coordinate of the rectangle * rightCoord = Right coordinate of the rectangle
* bottomCoord = Bottom coordinate of the rectangle * bottomCoord = Bottom coordinate of the rectangle
*/ */
this(T leftCoord, T topCoord, T rightCoord, T bottomCoord) this(T leftCoord, T topCoord, T rightCoord, T bottomCoord)
{ {
m_Left = leftCoord; m_Left = leftCoord;
m_Top = topCoord; m_Top = topCoord;
m_Right = rightCoord; m_Right = rightCoord;
m_Bottom = bottomCoord; m_Bottom = bottomCoord;
} }
/** /**
* Get the width of the rectangle * Get the width of the rectangle
* *
* Returns: * Returns:
* Width of rectangle * Width of rectangle
*/ */
T getWidth() T getWidth()
{ {
return m_Right - m_Left; return m_Right - m_Left;
} }
/** /**
* Get the height of the rectangle * Get the height of the rectangle
* *
* Returns: * Returns:
* Height of rectangle * Height of rectangle
*/ */
T getHeight() T getHeight()
{ {
return m_Bottom - m_Top; return m_Bottom - m_Top;
} }
/** /**
* Move the whole rectangle by the given offset * Move the whole rectangle by the given offset
* *
* Params: * Params:
* offsetX = Horizontal offset * offsetX = Horizontal offset
* offsetY = Vertical offset * offsetY = Vertical offset
*/ */
void offset(T offsetX, T offsetY) void offset(T offsetX, T offsetY)
{ {
m_Left += offsetX; m_Left += offsetX;
m_Right += offsetX; m_Right += offsetX;
m_Top += offsetY; m_Top += offsetY;
m_Bottom += offsetY; m_Bottom += offsetY;
} }
/** /**
* Check if a point is inside the rectangle's area * Check if a point is inside the rectangle's area
* *
* Params: * Params:
* x = X coordinate of the point to test * x = X coordinate of the point to test
* y = Y coordinate of the point to test * y = Y coordinate of the point to test
* *
* Returns: * Returns:
* True if the point is inside * True if the point is inside
*/ */
bool contains(T x, T y) bool contains(T x, T y)
{ {
return (x >= m_Left) && (x <= m_Right) && (y >= m_Top) && (y <= m_Bottom); return (x >= m_Left) && (x <= m_Right) && (y >= m_Top) && (y <= m_Bottom);
} }
/** /**
* Check intersection between two rectangles * Check intersection between two rectangles
* *
* Params: * Params:
* rectangle = Rectangle to test * rectangle = Rectangle to test
* overlappingRect = Rectangle to be filled with overlapping rect (NULL by default) * overlappingRect = Rectangle to be filled with overlapping rect (NULL by default)
* *
* Returns: * Returns:
* True if rectangles overlap * True if rectangles overlap
*/ */
bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = null) bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = null)
{ {
// Compute overlapping rect // Compute overlapping rect
Rect!(T) overlapping = new Rect!(T)( Rect!(T) overlapping = new Rect!(T)(
max(m_Left, rectangle.getLeft), max(m_Left, rectangle.getLeft),
max(m_Top, rectangle.getTop), max(m_Top, rectangle.getTop),
min(m_Right, rectangle.getRight), min(m_Right, rectangle.getRight),
min(m_Bottom, rectangle.getBottom) min(m_Bottom, rectangle.getBottom)
); );
// If overlapping rect is valid, then there is intersection // If overlapping rect is valid, then there is intersection
if ((overlapping.getLeft() < overlapping.getRight() ) && (overlapping.getTop() < overlapping.getBottom())) if ((overlapping.getLeft() < overlapping.getRight() ) && (overlapping.getTop() < overlapping.getBottom()))
{ {
overlappingRect = overlapping; overlappingRect = overlapping;
return true; return true;
} }
else else
{ {
overlappingRect = new Rect!(T)(); overlappingRect = new Rect!(T)();
return false; return false;
} }
} }
/** /**
* Set left Coordinate * Set left Coordinate
*/ */
void setLeft(T left) void setLeft(T left)
{ {
m_Left = left; m_Left = left;
} }
/** /**
* Set top Coordinate * Set top Coordinate
*/ */
void setTop(T top) void setTop(T top)
{ {
m_Top = top; m_Top = top;
} }
/** /**
* Set right Coordinate * Set right Coordinate
*/ */
void setRight(T right) void setRight(T right)
{ {
m_Right = right; m_Right = right;
} }
/** /**
* Set bottom Coordinate * Set bottom Coordinate
*/ */
void setBottom(T bottom) void setBottom(T bottom)
{ {
m_Bottom = bottom; m_Bottom = bottom;
} }
/** /**
* Get left Coordinate * Get left Coordinate
*/ */
T getLeft() T getLeft()
{ {
return m_Left; return m_Left;
} }
/** /**
* Get top Coordinate * Get top Coordinate
*/ */
T getTop() T getTop()
{ {
return m_Top; return m_Top;
} }
/** /**
* Get right Coordinate * Get right Coordinate
*/ */
T getRight() T getRight()
{ {
return m_Right; return m_Right;
} }
/** /**
* Get bottom Coordinate * Get bottom Coordinate
*/ */
T getBottom() T getBottom()
{ {
return m_Bottom; return m_Bottom;
} }
package: package:
sfFloatRect toCFloatRect() sfFloatRect toCFloatRect()
{ {
return sfFloatRect(m_Left, m_Top, m_Right, m_Bottom); return sfFloatRect(m_Left, m_Top, m_Right, m_Bottom);
} }
sfIntRect toCIntRect() sfIntRect toCIntRect()
{ {
return sfIntRect(cast(int)m_Left, cast(int)m_Top, cast(int)m_Right, cast(int)m_Bottom); return sfIntRect(cast(int)m_Left, cast(int)m_Top, cast(int)m_Right, cast(int)m_Bottom);
} }
} }
///Alias ///Alias

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.renderwindow; module dsfml.graphics.renderwindow;
@ -48,190 +48,190 @@ import dsfml.system.common,
dsfml.system.vector2; dsfml.system.vector2;
/** /**
* Simple wrapper for Window that allows easy 2D rendering. * Simple wrapper for Window that allows easy 2D rendering.
*/ */
class RenderWindow : Window class RenderWindow : Window
{ {
private: private:
View m_view = null; View m_view = null;
View m_defaultView = null; View m_defaultView = null;
public: 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.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
{
super(sfRenderWindow_Create(mode, toStringz(title), windowStyle, &settings));
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
/**
* Construct the window from an existing control
*
* Params:
* handle = Platform-specific handle of the control
* settings = Context settings (default is default ContextSettings values)
*/
this(WindowHandle handle, ContextSettings settings = ContextSettings())
{
super(sfRenderWindow_CreateFromHandle(handle, &settings));
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
override void dispose()
{
sfRenderWindow_Destroy(m_ptr);
}
/**
* Create (or recreate) the window
*
* Input created with getInput will become invalid.
*
* Params:
* mode = Video mode to use
* title = Title of the window
* windowStyle = Window style (Resize | Close by default)
* settings = Context settings (default is default ContextSettings values)
*
*/
void create(VideoMode mode, string title, uint windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
{
if (m_ptr !is null)
dispose();
m_ptr = sfRenderWindow_Create(mode, toStringz(title), windowStyle, &settings);
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
/**
* Create (or recreate) the window from an existing control
*
* Input created with getInput become invalid.
*
* Params:
* handle = Platform-specific handle of the control
* settings = Context settings (default is default ContextSettings values)
*
*/
void create(WindowHandle handle, ContextSettings settings = ContextSettings())
{
if (m_ptr !is null)
dispose();
m_ptr = sfRenderWindow_CreateFromHandle(handle, &settings);
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
/** /**
* Draw a sprite, shape or text on the window with a shader * Construct the window
* *
* Params: * Params:
* drawable = IDrawable to draw * mode = Video mode to use
* shader = Shader 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.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
{
super(sfRenderWindow_Create(mode, toStringz(title), windowStyle, &settings));
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
/**
* Construct the window from an existing control
*
* Params:
* handle = Platform-specific handle of the control
* settings = Context settings (default is default ContextSettings values)
*/
this(WindowHandle handle, ContextSettings settings = ContextSettings())
{
super(sfRenderWindow_CreateFromHandle(handle, &settings));
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
override void dispose()
{
sfRenderWindow_Destroy(m_ptr);
}
/**
* Create (or recreate) the window
*
* Input created with getInput will become invalid.
*
* Params:
* mode = Video mode to use
* title = Title of the window
* windowStyle = Window style (Resize | Close by default)
* settings = Context settings (default is default ContextSettings values)
*
*/
void create(VideoMode mode, string title, uint windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
{
if (m_ptr !is null)
dispose();
m_ptr = sfRenderWindow_Create(mode, toStringz(title), windowStyle, &settings);
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
/**
* Create (or recreate) the window from an existing control
*
* Input created with getInput become invalid.
*
* Params:
* handle = Platform-specific handle of the control
* settings = Context settings (default is default ContextSettings values)
*
*/
void create(WindowHandle handle, ContextSettings settings = ContextSettings())
{
if (m_ptr !is null)
dispose();
m_ptr = sfRenderWindow_CreateFromHandle(handle, &settings);
m_input = new Input(sfRenderWindow_GetInput(m_ptr));
}
/**
* Draw a sprite, shape or text on the window with a shader
*
* Params:
* drawable = IDrawable to draw
* shader = Shader to use
*/ */
void draw(IDrawable drawable, Shader shader) void draw(IDrawable drawable, Shader shader)
{ {
drawable.renderWithShader(this, shader); drawable.renderWithShader(this, shader);
} }
/** /**
* Draw a sprite, shape or text * Draw a sprite, shape or text
* *
* Params: * Params:
* drawable = IDrawable to draw * drawable = IDrawable to draw
*/ */
void draw(IDrawable drawable) void draw(IDrawable drawable)
{ {
drawable.render(this); drawable.render(this);
} }
/** /**
* Clear the screen with the given color. * Clear the screen with the given color.
* *
* Params: * Params:
* col = Fill color * col = Fill color
*/ */
void clear(Color col = Color.BLACK) void clear(Color col = Color.BLACK)
{ {
sfRenderWindow_Clear(m_ptr, col); sfRenderWindow_Clear(m_ptr, col);
} }
/** /**
* Change the current active view. * Change the current active view.
* The current view is defined with the initial size of the window * The current view is defined with the initial size of the window
* *
* Params: * Params:
* newView = Pointer to the new view (pass getDefaultView to set the default view) * newView = Pointer to the new view (pass getDefaultView to set the default view)
*/ */
void setView(View newView) void setView(View newView)
{ {
if (m_view !is null) if (m_view !is null)
{ {
m_view.setHandled(false); m_view.setHandled(false);
} }
sfRenderWindow_SetView(m_ptr, newView.getNativePointer); sfRenderWindow_SetView(m_ptr, newView.getNativePointer);
m_view = newView; m_view = newView;
m_view.setHandled(true); m_view.setHandled(true);
} }
/** /**
* Get the current view rectangle * Get the current view rectangle
* *
* Returns: * Returns:
* current view rectangle, in global coordinates * current view rectangle, in global coordinates
*/ */
View getView() View getView()
{ {
if (m_view is null) if (m_view is null)
{ {
void* cView = sfRenderWindow_GetView(m_ptr); void* cView = sfRenderWindow_GetView(m_ptr);
m_view = new View(cView, true); m_view = new View(cView, true);
} }
return m_view; return m_view;
} }
/** /**
* Get the default view * Get the default view
* *
* Returns: * Returns:
* default view * default view
*/ */
View getDefaultView() View getDefaultView()
{ {
if (m_defaultView is null) if (m_defaultView is null)
{ {
void* cView = sfRenderWindow_GetDefaultView(m_ptr); void* cView = sfRenderWindow_GetDefaultView(m_ptr);
m_defaultView = new View(cView, true); m_defaultView = new View(cView, true);
} }
return m_defaultView; return m_defaultView;
} }
/** /**
* Convert a point in window coordinates into view coordinates * Convert a point in window coordinates into view coordinates
* *
* Params: * Params:
* windowX = X coordinate of the point to convert, relative to the window * windowX = X coordinate of the point to convert, relative to the window
* windowY = Y 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) * targetView = Target view to convert the point to (pass NULL to use the current view)
* *
* Returns: * Returns:
* Converted point * Converted point
*/ */
Vector2f convertCoords(uint windowX, uint windowY, View targetView = null) Vector2f convertCoords(uint windowX, uint windowY, View targetView = null)
{ {
Vector2f vec; Vector2f vec;
sfRenderWindow_ConvertCoords(m_ptr, windowX, windowY, &vec.x, &vec.y, targetView is null ? null : targetView.getNativePointer); sfRenderWindow_ConvertCoords(m_ptr, windowX, windowY, &vec.x, &vec.y, targetView is null ? null : targetView.getNativePointer);
return vec; return vec;
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.shader; module dsfml.graphics.shader;
@ -35,100 +35,100 @@ import dsfml.system.stringutil;
/** /**
* Define loading methods for effect * Define loading methods for effect
*/ */
enum LoadingType enum LoadingType
{ {
FROMFILE, /// string represents a file path FROMFILE, /// string represents a file path
FROMSTRING /// string represents effect code FROMSTRING /// string represents effect code
} }
/** /**
* Shader is used to apply a post effect to a window * Shader is used to apply a post effect to a window
* *
* See_Also: * See_Also:
* $(LINK2 http://www.sfml-dev.org/tutorials/graphics-postfx.php, SFML post FX tutorial) from more informations about Post effects and GLSL fragment shaders syntax. * $(LINK2 http://www.sfml-dev.org/tutorials/graphics-postfx.php, SFML post FX tutorial) from more informations about Post effects and GLSL fragment shaders syntax.
*/ */
class Shader : DSFMLObject class Shader : DSFMLObject
{ {
/** /**
* construct the effect * construct the effect
* *
* Params: * Params:
* effect = Path of a file or string containing the effect. * effect = Path of a file or string containing the effect.
* type = type of the effect (default is FROMFILE) * type = type of the effect (default is FROMFILE)
*/ */
this(string effect, LoadingType type = LoadingType.FROMFILE) this(string effect, LoadingType type = LoadingType.FROMFILE)
{ {
if (effect is null || effect.length == 0) if (effect is null || effect.length == 0)
throw new LoadingException("LoadingException : Effect is invalid."); throw new LoadingException("LoadingException : Effect is invalid.");
if (type == LoadingType.FROMFILE) if (type == LoadingType.FROMFILE)
super(sfShader_CreateFromFile(toStringz(effect))); super(sfShader_CreateFromFile(toStringz(effect)));
else else
super(sfShader_CreateFromMemory(toStringz(effect))); super(sfShader_CreateFromMemory(toStringz(effect)));
} }
override void dispose() override void dispose()
{ {
sfShader_Destroy(m_ptr); sfShader_Destroy(m_ptr);
} }
/** /**
* Change parameters of the effect * Change parameters of the effect
* *
* Params: * Params:
* name = Parameter name in the effect * name = Parameter name in the effect
*/ */
void setParameter(string name, float x) void setParameter(string name, float x)
{ {
sfShader_SetParameter1(m_ptr, toStringz(name), x); sfShader_SetParameter1(m_ptr, toStringz(name), x);
} }
/** /**
* ditto * ditto
*/ */
void setParameter(string name, float x, float y) void setParameter(string name, float x, float y)
{ {
sfShader_SetParameter2(m_ptr, toStringz(name), x, y); sfShader_SetParameter2(m_ptr, toStringz(name), x, y);
} }
/** /**
* ditto * ditto
*/ */
void setParameter(string name, float x, float y, float z) void setParameter(string name, float x, float y, float z)
{ {
sfShader_SetParameter3(m_ptr, toStringz(name), x, y, z); sfShader_SetParameter3(m_ptr, toStringz(name), x, y, z);
} }
/** /**
* ditto * ditto
*/ */
void setParameter(string name, float x, float y, float z, float w) void setParameter(string name, float x, float y, float z, float w)
{ {
sfShader_SetParameter4(m_ptr, toStringz(name), x, y, z, w); sfShader_SetParameter4(m_ptr, toStringz(name), x, y, z, w);
} }
/** /**
* Set a texture parameter * Set a texture parameter
* *
* Params: * Params:
* name = Texture name in the effect * name = Texture name in the effect
* texture = Image to set (pass NULL to use content of current framebuffer) * texture = Image to set (pass NULL to use content of current framebuffer)
*/ */
void setTexture(string name, Image texture) void setTexture(string name, Image texture)
{ {
m_texture = texture; m_texture = texture;
sfShader_SetTexture(m_ptr, toStringz(name), texture is null ? null : texture.getNativePointer); sfShader_SetTexture(m_ptr, toStringz(name), texture is null ? null : texture.getNativePointer);
} }
/** /**
* Tell whether or not the system supports shaders * Tell whether or not the system supports shaders
* *
* Returns: * Returns:
* True if the system can use shaders * True if the system can use shaders
*/ */
static bool isAvailable() static bool isAvailable()
{ {
return cast(bool)sfShader_IsAvailable(); return cast(bool)sfShader_IsAvailable();
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.shape; module dsfml.graphics.shape;
@ -33,305 +33,305 @@ import dsfml.graphics.color;
import dsfml.graphics.drawableimpl; import dsfml.graphics.drawableimpl;
/** /**
* Shape defines a drawable convex shape ; it also defines * Shape defines a drawable convex shape ; it also defines
* helper functions to draw simple shapes like * helper functions to draw simple shapes like
* lines, rectangles, circles, etc. * lines, rectangles, circles, etc.
*/ */
class Shape : Drawableimpl!(sfShape) class Shape : Drawableimpl!(sfShape)
{ {
this() this()
{ {
super(); super();
} }
/** /**
* Add a point to the shape * Add a point to the shape
* *
* Params: * Params:
* x = X position of the point * x = X position of the point
* y = Y position of the point * y = Y position of the point
* col = Color of the point (white by default) * col = Color of the point (white by default)
* outlineCol = Outline color of the point (black by default) * outlineCol = Outline color of the point (black by default)
*/ */
void addPoint(float x, float y, Color col = Color.WHITE, Color outlineCol = Color.BLACK) void addPoint(float x, float y, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
{ {
sfShape_AddPoint(m_ptr, x, y, col, outlineCol); sfShape_AddPoint(m_ptr, x, y, col, outlineCol);
} }
/** /**
* Add a point to the shape * Add a point to the shape
* *
* Params: * Params:
* position = position of the point * position = position of the point
* col = Color of the point (white by default) * col = Color of the point (white by default)
* outlineCol = Outline color of the point (black by default) * outlineCol = Outline color of the point (black by default)
*/ */
void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK) void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
{ {
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol); sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
} }
/** /**
* Enable or disable filling the shape. * Enable or disable filling the shape.
* Fill is enabled by default. * Fill is enabled by default.
* *
* Params: * Params:
* enable = True to enable, false to disable * enable = True to enable, false to disable
*/ */
void enableFill(bool enable) void enableFill(bool enable)
{ {
sfShape_EnableFill(m_ptr, enable); sfShape_EnableFill(m_ptr, enable);
} }
/** /**
* Enable or disable drawing a shape outline. * Enable or disable drawing a shape outline.
* Outline is enabled by default * Outline is enabled by default
* *
* Params: * Params:
* enable = True to enable, false to disable * enable = True to enable, false to disable
*/ */
void enableOutline(bool enable) void enableOutline(bool enable)
{ {
sfShape_EnableOutline(m_ptr, enable); sfShape_EnableOutline(m_ptr, enable);
} }
/** /**
* Change the width of a shape outline * Change the width of a shape outline
* *
* Params: * Params:
* width = New width * width = New width
*/ */
void setOutlineWidth(float width) void setOutlineWidth(float width)
{ {
sfShape_SetOutlineWidth(m_ptr, width); sfShape_SetOutlineWidth(m_ptr, width);
} }
/** /**
* Get the width of the shape outline * Get the width of the shape outline
* *
* Returns: * Returns:
* Current outline width * Current outline width
* *
*/ */
float getOutlineWidth() float getOutlineWidth()
{ {
return sfShape_GetOutlineWidth(m_ptr); return sfShape_GetOutlineWidth(m_ptr);
} }
/** /**
* Get the number of points composing a shape * Get the number of points composing a shape
* *
* Returns: * Returns:
* Total number of points * Total number of points
*/ */
uint getNbPoints() uint getNbPoints()
{ {
return sfShape_GetNbPoints(m_ptr); return sfShape_GetNbPoints(m_ptr);
} }
/** /**
* Get a point of the shape * Get a point of the shape
* *
* Params: * Params:
* index = Index of the point * index = Index of the point
* *
* Returns: * Returns:
* position of the point * position of the point
*/ */
Vector2f getPointPosition(uint index) Vector2f getPointPosition(uint index)
{ {
float x, y; float x, y;
sfShape_GetPointPosition(m_ptr, index, &x, &y); sfShape_GetPointPosition(m_ptr, index, &x, &y);
return Vector2f(x, y); return Vector2f(x, y);
} }
/** /**
* Set the position of a shape point * Set the position of a shape point
* *
* Params: * Params:
* index = Index of the point * index = Index of the point
* position = New position of the point * position = New position of the point
*/ */
void setPointPosition(uint index, Vector2f position) void setPointPosition(uint index, Vector2f position)
{ {
sfShape_SetPointPosition(m_ptr, index, position.x, position.y); sfShape_SetPointPosition(m_ptr, index, position.x, position.y);
} }
/** /**
* Get the color of a shape's point * Get the color of a shape's point
* *
* Params: * Params:
* index = Index of the point * index = Index of the point
* *
* Returns: * Returns:
* Color of the point * Color of the point
*/ */
Color getPointColor(uint index) Color getPointColor(uint index)
{ {
return sfShape_GetPointColor(m_ptr, index); return sfShape_GetPointColor(m_ptr, index);
} }
/** /**
* Set the color of a shape's point * Set the color of a shape's point
* *
* Params: * Params:
* index = Index of the point * index = Index of the point
* color = new color of the point * color = new color of the point
*/ */
void setPointColor(uint index, Color color) void setPointColor(uint index, Color color)
{ {
sfShape_SetPointColor(m_ptr, index, color); sfShape_SetPointColor(m_ptr, index, color);
} }
/** /**
* Get the outline color of a shape's point * Get the outline color of a shape's point
* *
* Params: * Params:
* index = Index of the point * index = Index of the point
* *
* Returns: * Returns:
* Color of the outline * Color of the outline
*/ */
Color getPointOutlineColor(uint index) Color getPointOutlineColor(uint index)
{ {
return sfShape_GetPointOutlineColor(m_ptr, index); return sfShape_GetPointOutlineColor(m_ptr, index);
} }
/** /**
* Set the outline color of a shape's point * Set the outline color of a shape's point
* *
* Params: * Params:
* index = Index of the point * index = Index of the point
* color = new color of the point * color = new color of the point
*/ */
void setPointOutlineColor(uint index, Color color) void setPointOutlineColor(uint index, Color color)
{ {
sfShape_SetPointOutlineColor(m_ptr, index, color); sfShape_SetPointOutlineColor(m_ptr, index, color);
} }
/** /**
* Create a shape made of a single line * Create a shape made of a single line
* *
* Params: * Params:
* p1X, p1Y = Position of the first point * p1X, p1Y = Position of the first point
* p2X, p2Y = Position second point * p2X, p2Y = Position second point
* thickness = Line thickness * thickness = Line thickness
* col = Color used to draw the line * col = Color used to draw the line
* outline = Outline width (0 by default) * outline = Outline width (0 by default)
* outlineCol = Color used to draw the outline (black by default) * outlineCol = Color used to draw the outline (black by default)
* *
* Returns: * Returns:
* New line shape * New line shape
*/ */
static Shape line(float p1X, float p1Y, float p2X, float p2Y, float thickness, Color col, float outline = 0.f, Color outlineCol = Color.BLACK) static Shape line(float p1X, float p1Y, float p2X, float p2Y, float thickness, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
{ {
return new Shape(sfShape_CreateLine(p1X, p1Y, p2X, p2Y, thickness, col, outline, outlineCol)); return new Shape(sfShape_CreateLine(p1X, p1Y, p2X, p2Y, thickness, col, outline, outlineCol));
} }
/** /**
* Create a shape made of a single rectangle * Create a shape made of a single rectangle
* *
* Params: * Params:
* p1X = X position of the first point * p1X = X position of the first point
* p1Y = Y position of the first point * p1Y = Y position of the first point
* p2X = X position second point * p2X = X position second point
* p2Y = Y position second point * p2Y = Y position second point
* col = Color used to fill the rectangle * col = Color used to fill the rectangle
* outline = Outline width (0 by default) * outline = Outline width (0 by default)
* outlineCol = Color used to draw the outline (black by default) * outlineCol = Color used to draw the outline (black by default)
* *
* Returns: * Returns:
* new rectangle shape * new rectangle shape
*/ */
static Shape rectangle(float p1X, float p1Y, float p2X, float p2Y, Color col, float outline = 0.f, Color outlineCol = Color.BLACK) static Shape rectangle(float p1X, float p1Y, float p2X, float p2Y, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
{ {
return new Shape(sfShape_CreateRectangle(p1X, p1Y, p2X, p2Y, col, outline, outlineCol)); return new Shape(sfShape_CreateRectangle(p1X, p1Y, p2X, p2Y, col, outline, outlineCol));
} }
/** /**
* Create a shape made of a single circle * Create a shape made of a single circle
* *
* Params: * Params:
* x = X position of the center * x = X position of the center
* y = Y position of the center * y = Y position of the center
* radius = Radius * radius = Radius
* col = Color used to fill the circle * col = Color used to fill the circle
* outline = Outline width (0 by default) * outline = Outline width (0 by default)
* outlineCol = Color used to draw the outline (black by default) * outlineCol = Color used to draw the outline (black by default)
* *
* Returns: * Returns:
* new circle shape * new circle shape
*/ */
static Shape circle(float x, float y, float radius, Color col, float outline = 0.f, Color outlineCol = Color.BLACK) static Shape circle(float x, float y, float radius, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
{ {
return new Shape(sfShape_CreateCircle(x, y, radius, col, outline, outlineCol)); return new Shape(sfShape_CreateCircle(x, y, radius, col, outline, outlineCol));
} }
private: private:
this (void* ptr) this (void* ptr)
{ {
super(ptr); super(ptr);
} }
extern (C) extern (C)
{ {
typedef void* function(float, float, float, float, float, Color, float, Color) pf_sfShape_CreateLine; typedef void* function(float, float, float, float, float, Color, float, Color) pf_sfShape_CreateLine;
typedef void* function(float, float, float, float, Color, float, Color) pf_sfShape_CreateRectangle; typedef void* function(float, float, float, float, Color, float, Color) pf_sfShape_CreateRectangle;
typedef void* function(float, float, float, Color, float, Color) pf_sfShape_CreateCircle; typedef void* function(float, float, float, Color, float, Color) pf_sfShape_CreateCircle;
typedef void function(void* Shape, float, float, Color, Color) pf_sfShape_AddPoint; typedef void function(void* Shape, float, float, Color, Color) pf_sfShape_AddPoint;
typedef void function(void* Shape, int) pf_sfShape_EnableFill; typedef void function(void* Shape, int) pf_sfShape_EnableFill;
typedef void function(void* Shape, int) pf_sfShape_EnableOutline; typedef void function(void* Shape, int) pf_sfShape_EnableOutline;
typedef void function (void* Shape, float Width) pf_sfShape_SetOutlineWidth; typedef void function (void* Shape, float Width) pf_sfShape_SetOutlineWidth;
typedef float function (void* Shape) pf_sfShape_GetOutlineWidth; typedef float function (void* Shape) pf_sfShape_GetOutlineWidth;
typedef uint function (void* Shape) pf_sfShape_GetNbPoints; typedef uint function (void* Shape) pf_sfShape_GetNbPoints;
typedef void function (void* Shape, uint Index, float* X, float* Y) pf_sfShape_GetPointPosition; typedef void function (void* Shape, uint Index, float* X, float* Y) pf_sfShape_GetPointPosition;
typedef void function (void* Shape, uint Index, float X, float Y) pf_sfShape_SetPointPosition; typedef void function (void* Shape, uint Index, float X, float Y) pf_sfShape_SetPointPosition;
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointColor; typedef Color function (void* Shape, uint index) pf_sfShape_GetPointColor;
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointColor; typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointColor;
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointOutlineColor; typedef Color function (void* Shape, uint index) pf_sfShape_GetPointOutlineColor;
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointOutlineColor; typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointOutlineColor;
static pf_sfShape_CreateLine sfShape_CreateLine; static pf_sfShape_CreateLine sfShape_CreateLine;
static pf_sfShape_CreateRectangle sfShape_CreateRectangle; static pf_sfShape_CreateRectangle sfShape_CreateRectangle;
static pf_sfShape_CreateCircle sfShape_CreateCircle; static pf_sfShape_CreateCircle sfShape_CreateCircle;
static pf_sfShape_AddPoint sfShape_AddPoint; static pf_sfShape_AddPoint sfShape_AddPoint;
static pf_sfShape_EnableFill sfShape_EnableFill; static pf_sfShape_EnableFill sfShape_EnableFill;
static pf_sfShape_EnableOutline sfShape_EnableOutline; static pf_sfShape_EnableOutline sfShape_EnableOutline;
static pf_sfShape_SetOutlineWidth sfShape_SetOutlineWidth; static pf_sfShape_SetOutlineWidth sfShape_SetOutlineWidth;
static pf_sfShape_GetOutlineWidth sfShape_GetOutlineWidth; static pf_sfShape_GetOutlineWidth sfShape_GetOutlineWidth;
static pf_sfShape_GetNbPoints sfShape_GetNbPoints; static pf_sfShape_GetNbPoints sfShape_GetNbPoints;
static pf_sfShape_GetPointPosition sfShape_GetPointPosition; static pf_sfShape_GetPointPosition sfShape_GetPointPosition;
static pf_sfShape_SetPointPosition sfShape_SetPointPosition; static pf_sfShape_SetPointPosition sfShape_SetPointPosition;
static pf_sfShape_GetPointColor sfShape_GetPointColor; static pf_sfShape_GetPointColor sfShape_GetPointColor;
static pf_sfShape_SetPointColor sfShape_SetPointColor; static pf_sfShape_SetPointColor sfShape_SetPointColor;
static pf_sfShape_GetPointOutlineColor sfShape_GetPointOutlineColor; static pf_sfShape_GetPointOutlineColor sfShape_GetPointOutlineColor;
static pf_sfShape_SetPointOutlineColor sfShape_SetPointOutlineColor; static pf_sfShape_SetPointOutlineColor sfShape_SetPointOutlineColor;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-graphics-d"); DllLoader dll = DllLoader.load("csfml-graphics-d");
else else
DllLoader dll = DllLoader.load("csfml-graphics"); DllLoader dll = DllLoader.load("csfml-graphics");
sfShape_CreateLine = cast(pf_sfShape_CreateLine)dll.getSymbol("sfShape_CreateLine"); sfShape_CreateLine = cast(pf_sfShape_CreateLine)dll.getSymbol("sfShape_CreateLine");
sfShape_CreateRectangle = cast(pf_sfShape_CreateRectangle)dll.getSymbol("sfShape_CreateRectangle"); sfShape_CreateRectangle = cast(pf_sfShape_CreateRectangle)dll.getSymbol("sfShape_CreateRectangle");
sfShape_CreateCircle = cast(pf_sfShape_CreateCircle)dll.getSymbol("sfShape_CreateCircle"); sfShape_CreateCircle = cast(pf_sfShape_CreateCircle)dll.getSymbol("sfShape_CreateCircle");
sfShape_AddPoint = cast(pf_sfShape_AddPoint)dll.getSymbol("sfShape_AddPoint"); sfShape_AddPoint = cast(pf_sfShape_AddPoint)dll.getSymbol("sfShape_AddPoint");
sfShape_EnableFill = cast(pf_sfShape_EnableFill)dll.getSymbol("sfShape_EnableFill"); sfShape_EnableFill = cast(pf_sfShape_EnableFill)dll.getSymbol("sfShape_EnableFill");
sfShape_EnableOutline = cast(pf_sfShape_EnableOutline)dll.getSymbol("sfShape_EnableOutline"); sfShape_EnableOutline = cast(pf_sfShape_EnableOutline)dll.getSymbol("sfShape_EnableOutline");
sfShape_SetOutlineWidth = cast(pf_sfShape_SetOutlineWidth)dll.getSymbol("sfShape_SetOutlineWidth"); sfShape_SetOutlineWidth = cast(pf_sfShape_SetOutlineWidth)dll.getSymbol("sfShape_SetOutlineWidth");
sfShape_GetOutlineWidth = cast(pf_sfShape_GetOutlineWidth)dll.getSymbol("sfShape_GetOutlineWidth"); sfShape_GetOutlineWidth = cast(pf_sfShape_GetOutlineWidth)dll.getSymbol("sfShape_GetOutlineWidth");
sfShape_GetNbPoints = cast(pf_sfShape_GetNbPoints)dll.getSymbol("sfShape_GetNbPoints"); sfShape_GetNbPoints = cast(pf_sfShape_GetNbPoints)dll.getSymbol("sfShape_GetNbPoints");
sfShape_GetPointPosition = cast(pf_sfShape_GetPointPosition)dll.getSymbol("sfShape_GetPointPosition"); sfShape_GetPointPosition = cast(pf_sfShape_GetPointPosition)dll.getSymbol("sfShape_GetPointPosition");
sfShape_SetPointPosition = cast(pf_sfShape_SetPointPosition)dll.getSymbol("sfShape_SetPointPosition"); sfShape_SetPointPosition = cast(pf_sfShape_SetPointPosition)dll.getSymbol("sfShape_SetPointPosition");
sfShape_GetPointColor = cast (pf_sfShape_GetPointColor)dll.getSymbol("sfShape_GetPointColor"); sfShape_GetPointColor = cast (pf_sfShape_GetPointColor)dll.getSymbol("sfShape_GetPointColor");
sfShape_SetPointColor = cast (pf_sfShape_SetPointColor)dll.getSymbol("sfShape_SetPointColor"); sfShape_SetPointColor = cast (pf_sfShape_SetPointColor)dll.getSymbol("sfShape_SetPointColor");
sfShape_GetPointOutlineColor = cast(pf_sfShape_GetPointOutlineColor)dll.getSymbol("sfShape_GetPointOutlineColor"); sfShape_GetPointOutlineColor = cast(pf_sfShape_GetPointOutlineColor)dll.getSymbol("sfShape_GetPointOutlineColor");
sfShape_SetPointOutlineColor = cast(pf_sfShape_SetPointOutlineColor)dll.getSymbol("sfShape_SetPointOutlineColor"); sfShape_SetPointOutlineColor = cast(pf_sfShape_SetPointOutlineColor)dll.getSymbol("sfShape_SetPointOutlineColor");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.sprite; module dsfml.graphics.sprite;
@ -35,218 +35,218 @@ import dsfml.graphics.rect;
import dsfml.system.vector2; import dsfml.system.vector2;
/** /**
* Sprite defines a sprite : texture, transformations, * Sprite defines a sprite : texture, transformations,
* color, and draw on screen * color, and draw on screen
* See_Also: * See_Also:
* IDrawable * IDrawable
*/ */
class Sprite : Drawableimpl!(sfSprite) class Sprite : Drawableimpl!(sfSprite)
{ {
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
} }
/** /**
* Construct the sprite from a source image * Construct the sprite from a source image
* *
* Params: * Params:
* img = Image of the sprite * img = Image of the sprite
* left = Left coordinate of the sprite (0 by default) * left = Left coordinate of the sprite (0 by default)
* top = Top coordinate of the sprite (0 by default) * top = Top coordinate of the sprite (0 by default)
* scaleX = Horizontal scale (1 by default) * scaleX = Horizontal scale (1 by default)
* scaleY= Vertical scale (1 by default) * scaleY= Vertical scale (1 by default)
* rotation = Orientation, in degrees (0 by default) * rotation = Orientation, in degrees (0 by default)
* col = Color of the sprite (white by default) * col = Color of the sprite (white by default)
*/ */
this(Image img, float left = 0.f, float top = 0.f, float scaleX = 1.f, float scaleY = 1.f, float rotation = 0.f, Color col = Color.WHITE) this(Image img, float left = 0.f, float top = 0.f, float scaleX = 1.f, float scaleY = 1.f, float rotation = 0.f, Color col = Color.WHITE)
{ {
m_image = img; m_image = img;
sfSprite_SetImage(m_ptr, img.getNativePointer); sfSprite_SetImage(m_ptr, img.getNativePointer);
setX(left); setX(left);
setY(top); setY(top);
setScaleX(scaleX); setScaleX(scaleX);
setScaleY(scaleY); setScaleY(scaleY);
setRotation(rotation); setRotation(rotation);
setColor(col); setColor(col);
} }
/** /**
* Change the image of the sprite * Change the image of the sprite
* *
* Params: * Params:
* img = New image * img = New image
*/ */
void setImage(Image img) void setImage(Image img)
{ {
assert(img !is null, "Trying to set a null image."); assert(img !is null, "Trying to set a null image.");
sfSprite_SetImage(m_ptr, img.getNativePointer); sfSprite_SetImage(m_ptr, img.getNativePointer);
m_image = img; m_image = img;
} }
/** /**
* Set the sub-rectangle of a sprite inside the source image. * Set the sub-rectangle of a sprite inside the source image.
* *
* Params: * Params:
* rect = New sub-rectangle * rect = New sub-rectangle
*/ */
void setSubRect(IntRect rect) void setSubRect(IntRect rect)
{ {
sfIntRect r = rect.toCIntRect(); sfIntRect r = rect.toCIntRect();
sfSprite_SetSubRect(m_ptr, &r); sfSprite_SetSubRect(m_ptr, &r);
m_subRect = rect; m_subRect = rect;
} }
/** /**
* Resize the sprite (by changing its scale factors). * Resize the sprite (by changing its scale factors).
* The default size is defined by the subrect * The default size is defined by the subrect
* *
* Params: * Params:
* width = New width (must be strictly positive) * width = New width (must be strictly positive)
* height = New height (must be strictly positive) * height = New height (must be strictly positive)
*/ */
void resize(float width, float height) void resize(float width, float height)
{ {
if (width > 0 && height > 0) if (width > 0 && height > 0)
sfSprite_Resize(m_ptr, width, height); sfSprite_Resize(m_ptr, width, height);
} }
/** /**
* Resize the sprite (by changing its scale factors). * Resize the sprite (by changing its scale factors).
* The default size is defined by the subrect * The default size is defined by the subrect
* *
* Params: * Params:
* size = New size (both coordinates must be strictly positive) * size = New size (both coordinates must be strictly positive)
*/ */
void resize(Vector2f size) void resize(Vector2f size)
{ {
if (size.x > 0 && size.y > 0) if (size.x > 0 && size.y > 0)
sfSprite_Resize(m_ptr, size.x, size.y); sfSprite_Resize(m_ptr, size.x, size.y);
} }
/** /**
* Flip the sprite horizontally * Flip the sprite horizontally
* *
* Params: * Params:
* flipped = True to flip the sprite * flipped = True to flip the sprite
*/ */
void flipX(bool flipped) void flipX(bool flipped)
{ {
sfSprite_FlipX(m_ptr, flipped); sfSprite_FlipX(m_ptr, flipped);
} }
/** /**
* Flip the sprite vertically * Flip the sprite vertically
* *
* Params: * Params:
* flipped = True to flip the sprite * flipped = True to flip the sprite
*/ */
void flipY(bool flipped) void flipY(bool flipped)
{ {
sfSprite_FlipY(m_ptr, flipped); sfSprite_FlipY(m_ptr, flipped);
} }
/** /**
* Get the source image of the sprite * Get the source image of the sprite
* *
* Returns: * Returns:
* Pointer to the image (can be NULL) * Pointer to the image (can be NULL)
*/ */
Image getImage() Image getImage()
{ {
return m_image; return m_image;
} }
/** /**
* Get the sub-rectangle of the sprite inside the source image * Get the sub-rectangle of the sprite inside the source image
* *
* Returns: * Returns:
* Sub-rectangle * Sub-rectangle
*/ */
IntRect getSubRect() IntRect getSubRect()
{ {
if (m_subRect is null) if (m_subRect is null)
m_subRect = new IntRect(0, 0, m_image.getWidth(), m_image.getHeight()); m_subRect = new IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
return m_subRect; return m_subRect;
} }
/** /**
* Get the sprite size * Get the sprite size
* *
* Returns: * Returns:
* Size of the sprite * Size of the sprite
*/ */
Vector2f getSize() Vector2f getSize()
{ {
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr)); return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
} }
/** /**
* Get the color of a given pixel in the sprite * Get the color of a given pixel in the sprite
* *
* Params: * Params:
* x = X coordinate * x = X coordinate
* y = Y coordinate * y = Y coordinate
* *
* Returns: * Returns:
* Color of pixel * Color of pixel
*/ */
Color getPixel(uint x, uint y) Color getPixel(uint x, uint y)
{ {
return sfSprite_GetPixel(m_ptr, x, y); return sfSprite_GetPixel(m_ptr, x, y);
} }
private: private:
Image m_image; //< Image used to draw the sprite Image m_image; //< Image used to draw the sprite
IntRect m_subRect; //< Sub-rectangle of source image to assign to the sprite IntRect m_subRect; //< Sub-rectangle of source image to assign to the sprite
extern (C) extern (C)
{ {
typedef void function(void*, void*) pf_sfSprite_SetImage; typedef void function(void*, void*) pf_sfSprite_SetImage;
typedef void function(void*, sfIntRect*) pf_sfSprite_SetSubRect; typedef void function(void*, sfIntRect*) pf_sfSprite_SetSubRect;
typedef void function(void*, float, float) pf_sfSprite_Resize; typedef void function(void*, float, float) pf_sfSprite_Resize;
typedef void function(void*, int) pf_sfSprite_FlipX; typedef void function(void*, int) pf_sfSprite_FlipX;
typedef void function(void*, int) pf_sfSprite_FlipY; typedef void function(void*, int) pf_sfSprite_FlipY;
typedef void* function(void*) pf_sfSprite_GetImage; typedef void* function(void*) pf_sfSprite_GetImage;
typedef void* function(void*) pf_sfSprite_GetSubRect; typedef void* function(void*) pf_sfSprite_GetSubRect;
typedef float function(void*) pf_sfSprite_GetWidth; typedef float function(void*) pf_sfSprite_GetWidth;
typedef float function(void*) pf_sfSprite_GetHeight; typedef float function(void*) pf_sfSprite_GetHeight;
typedef Color function(void*, uint, uint) pf_sfSprite_GetPixel; typedef Color function(void*, uint, uint) pf_sfSprite_GetPixel;
static pf_sfSprite_SetImage sfSprite_SetImage; static pf_sfSprite_SetImage sfSprite_SetImage;
static pf_sfSprite_SetSubRect sfSprite_SetSubRect; static pf_sfSprite_SetSubRect sfSprite_SetSubRect;
static pf_sfSprite_Resize sfSprite_Resize; static pf_sfSprite_Resize sfSprite_Resize;
static pf_sfSprite_FlipX sfSprite_FlipX; static pf_sfSprite_FlipX sfSprite_FlipX;
static pf_sfSprite_FlipY sfSprite_FlipY; static pf_sfSprite_FlipY sfSprite_FlipY;
static pf_sfSprite_GetImage sfSprite_GetImage; static pf_sfSprite_GetImage sfSprite_GetImage;
static pf_sfSprite_GetSubRect sfSprite_GetSubRect; static pf_sfSprite_GetSubRect sfSprite_GetSubRect;
static pf_sfSprite_GetWidth sfSprite_GetWidth; static pf_sfSprite_GetWidth sfSprite_GetWidth;
static pf_sfSprite_GetHeight sfSprite_GetHeight; static pf_sfSprite_GetHeight sfSprite_GetHeight;
static pf_sfSprite_GetPixel sfSprite_GetPixel; static pf_sfSprite_GetPixel sfSprite_GetPixel;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-graphics-d"); DllLoader dll = DllLoader.load("csfml-graphics-d");
else else
DllLoader dll = DllLoader.load("csfml-graphics"); DllLoader dll = DllLoader.load("csfml-graphics");
sfSprite_SetImage = cast(pf_sfSprite_SetImage)dll.getSymbol("sfSprite_SetImage"); sfSprite_SetImage = cast(pf_sfSprite_SetImage)dll.getSymbol("sfSprite_SetImage");
sfSprite_SetSubRect = cast(pf_sfSprite_SetSubRect)dll.getSymbol("sfSprite_SetSubRect"); sfSprite_SetSubRect = cast(pf_sfSprite_SetSubRect)dll.getSymbol("sfSprite_SetSubRect");
sfSprite_Resize = cast(pf_sfSprite_Resize)dll.getSymbol("sfSprite_Resize"); sfSprite_Resize = cast(pf_sfSprite_Resize)dll.getSymbol("sfSprite_Resize");
sfSprite_FlipX = cast(pf_sfSprite_FlipX)dll.getSymbol("sfSprite_FlipX"); sfSprite_FlipX = cast(pf_sfSprite_FlipX)dll.getSymbol("sfSprite_FlipX");
sfSprite_FlipY = cast(pf_sfSprite_FlipY)dll.getSymbol("sfSprite_FlipY"); sfSprite_FlipY = cast(pf_sfSprite_FlipY)dll.getSymbol("sfSprite_FlipY");
sfSprite_GetImage = cast(pf_sfSprite_GetImage)dll.getSymbol("sfSprite_GetImage"); sfSprite_GetImage = cast(pf_sfSprite_GetImage)dll.getSymbol("sfSprite_GetImage");
sfSprite_GetSubRect = cast(pf_sfSprite_GetSubRect)dll.getSymbol("sfSprite_GetSubRect"); sfSprite_GetSubRect = cast(pf_sfSprite_GetSubRect)dll.getSymbol("sfSprite_GetSubRect");
sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth"); sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth");
sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight"); sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight");
sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("sfSprite_GetPixel"); sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("sfSprite_GetPixel");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.text; module dsfml.graphics.text;
@ -38,35 +38,35 @@ import dsfml.system.vector2;
/** /**
* Text defines a graphical 2D text, that can be drawn on screen * Text defines a graphical 2D text, that can be drawn on screen
* *
* All string litterals used must be prefixed with c for utf-8 * All string litterals used must be prefixed with c for utf-8
* and d for utf-32 string. * and d for utf-32 string.
* *
* Examples : * Examples :
* --------------------------------------------------------------- * ---------------------------------------------------------------
* Text s = new Text("Hello"c); * Text s = new Text("Hello"c);
* //this(string, Font, float) * //this(string, Font, float)
* s = new Text("Hello"d); * s = new Text("Hello"d);
* //this(dstring, Font, float) * //this(dstring, Font, float)
* --------------------------------------------------------------- * ---------------------------------------------------------------
* *
* See_Also: * See_Also:
* IDrawable * IDrawable
*/ */
class Text : Drawableimpl!(sfText) class Text : Drawableimpl!(sfText)
{ {
/** /**
* Construct the string from a text * Construct the string from a text
* *
* Prefixs string litterals with c * Prefixs string litterals with c
* *
* Params: * Params:
* text = Text assigned to the string * text = Text assigned to the string
* font = Font used to draw the string (use default font) * font = Font used to draw the string (use default font)
* size = Characters size, in pixels (32 by default) * size = Characters size, in pixels (32 by default)
*/ */
this(string text, Font font = Font.getDefaultFont(), uint size = 30) this(string text, Font font = Font.getDefaultFont(), uint size = 30)
{ {
super(); super();
m_font = font; m_font = font;
@ -75,17 +75,17 @@ class Text : Drawableimpl!(sfText)
setCharacterSize(size); setCharacterSize(size);
} }
/** /**
* Construct the string from a unicode text * Construct the string from a unicode text
* *
* Prefixs string litterals with d * Prefixs string litterals with d
* *
* Params: * Params:
* text = Text assigned to the string * text = Text assigned to the string
* font = Font used to draw the string (use default font) * font = Font used to draw the string (use default font)
* size = Characters size, in pixels (32 by default) * size = Characters size, in pixels (32 by default)
*/ */
this(dstring text, Font font = Font.getDefaultFont(), uint size = 30) this(dstring text, Font font = Font.getDefaultFont(), uint size = 30)
{ {
super(); super();
m_font = font; m_font = font;
@ -94,145 +94,145 @@ class Text : Drawableimpl!(sfText)
setCharacterSize(size); setCharacterSize(size);
} }
/** /**
* Set the text (from a multibyte string) * Set the text (from a multibyte string)
* *
* Params: * Params:
* text = New text * text = New text
* *
*/ */
void setString(string text) void setString(string text)
{ {
sfText_SetString(m_ptr,toStringz(text)); sfText_SetString(m_ptr,toStringz(text));
} }
/** /**
* Set the text (from a unicode string) * Set the text (from a unicode string)
* *
* Params: * Params:
* text = New text * text = New text
*/ */
void setString(dstring text) void setString(dstring text)
{ {
sfText_SetUnicodeString(m_ptr, toStringz(text)); sfText_SetUnicodeString(m_ptr, toStringz(text));
} }
/** /**
* Set the font of the string * Set the font of the string
* *
* Params: * Params:
* font = Font filename * font = Font filename
*/ */
void setFont(Font font) void setFont(Font font)
{ {
m_font = font; m_font = font;
sfText_SetFont(m_ptr, font.getNativePointer); sfText_SetFont(m_ptr, font.getNativePointer);
} }
/** /**
* Set the size of the string * Set the size of the string
* *
* Params: * Params:
* size = New size, in pixels * size = New size, in pixels
*/ */
void setCharacterSize(uint size) void setCharacterSize(uint size)
{ {
sfText_SetCharacterSize(m_ptr, size); sfText_SetCharacterSize(m_ptr, size);
} }
/** /**
* Set the style of the text * Set the style of the text
* The default style is Regular * The default style is Regular
* *
* Params: * Params:
* TextStyle = New text style, (combination of Style enum values) * TextStyle = New text style, (combination of Style enum values)
* *
*/ */
void setStyle(TextStyle style) void setStyle(TextStyle style)
{ {
sfText_SetStyle(m_ptr, style); sfText_SetStyle(m_ptr, style);
} }
/** /**
* Get the text (returns a unicode string) * Get the text (returns a unicode string)
* *
* Returns: * Returns:
* Text * Text
*/ */
dstring getUnicodeText() dstring getUnicodeText()
{ {
return fromStringz(sfText_GetUnicodeString(m_ptr)); return fromStringz(sfText_GetUnicodeString(m_ptr));
} }
/** /**
* Get the text (returns a multibyte string) * Get the text (returns a multibyte string)
* *
* Returns: * Returns:
* Text * Text
*/ */
string getText() string getText()
{ {
return fromStringz(sfText_GetString(m_ptr)); return fromStringz(sfText_GetString(m_ptr));
} }
/** /**
* Get the font used by the string * Get the font used by the string
* *
* Returns: * Returns:
* Font name * Font name
*/ */
Font getFont() Font getFont()
{ {
return m_font; return m_font;
} }
/** /**
* Get the size of the characters * Get the size of the characters
* *
* Returns: * Returns:
* Size of the characters * Size of the characters
*/ */
uint getCharacterSize() uint getCharacterSize()
{ {
return sfText_GetCharacterSize(m_ptr); return sfText_GetCharacterSize(m_ptr);
} }
/** /**
* Get the current font style * Get the current font style
* *
* Returns: * Returns:
* Font style * Font style
*/ */
TextStyle getStyle() TextStyle getStyle()
{ {
return sfText_GetStyle(m_ptr); return sfText_GetStyle(m_ptr);
} }
/** /**
* Return the visual position of the Index-th character of the string, * Return the visual position of the Index-th character of the string,
* in coordinates relative to the string * in coordinates relative to the string
* (note : translation, center, rotation and scale are not applied) * (note : translation, center, rotation and scale are not applied)
* *
* Params: * Params:
* index = Index of the character * index = Index of the character
* *
* Returns: * Returns:
* Position of the Index-th character (end of string of Index is out of range) * Position of the Index-th character (end of string of Index is out of range)
*/ */
Vector2f getCharacterPos(size_t index) Vector2f getCharacterPos(size_t index)
{ {
Vector2f ret; Vector2f ret;
sfText_GetCharacterPos(m_ptr, index, &ret.x, &ret.y); sfText_GetCharacterPos(m_ptr, index, &ret.x, &ret.y);
return ret; return ret;
} }
/** /**
* Get the string rectangle on screen * Get the string rectangle on screen
* *
* Returns: * Returns:
* Rectangle contaning the string in screen coordinates * Rectangle contaning the string in screen coordinates
*/ */
FloatRect getRect() FloatRect getRect()
{ {
sfFloatRect sfRect = sfText_GetRect(m_ptr); sfFloatRect sfRect = sfText_GetRect(m_ptr);
@ -240,55 +240,55 @@ class Text : Drawableimpl!(sfText)
} }
private: private:
Font m_font; Font m_font;
extern (C) extern (C)
{ {
typedef void function(void*, cchar*) pf_sfText_SetString; typedef void function(void*, cchar*) pf_sfText_SetString;
typedef void function(void*, cdchar*) pf_sfText_SetUnicodeString; typedef void function(void*, cdchar*) pf_sfText_SetUnicodeString;
typedef void function(void*, void*) pf_sfText_SetFont; typedef void function(void*, void*) pf_sfText_SetFont;
typedef void function(void*, uint) pf_sfText_SetCharacterSize; typedef void function(void*, uint) pf_sfText_SetCharacterSize;
typedef void function(void*, TextStyle) pf_sfText_SetStyle; typedef void function(void*, TextStyle) pf_sfText_SetStyle;
typedef idchar* function(void*) pf_sfText_GetUnicodeString; typedef idchar* function(void*) pf_sfText_GetUnicodeString;
typedef ichar* function(void*) pf_sfText_GetString; typedef ichar* function(void*) pf_sfText_GetString;
typedef void* function(void*) pf_sfText_GetFont; typedef void* function(void*) pf_sfText_GetFont;
typedef uint function(void*) pf_sfText_GetCharacterSize; typedef uint function(void*) pf_sfText_GetCharacterSize;
typedef TextStyle function (void*) pf_sfText_GetStyle; typedef TextStyle function (void*) pf_sfText_GetStyle;
typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos; typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos;
typedef sfFloatRect function(void*) pf_sfText_GetRect; typedef sfFloatRect function(void*) pf_sfText_GetRect;
static pf_sfText_SetString sfText_SetString; static pf_sfText_SetString sfText_SetString;
static pf_sfText_SetUnicodeString sfText_SetUnicodeString; static pf_sfText_SetUnicodeString sfText_SetUnicodeString;
static pf_sfText_SetFont sfText_SetFont; static pf_sfText_SetFont sfText_SetFont;
static pf_sfText_SetCharacterSize sfText_SetCharacterSize; static pf_sfText_SetCharacterSize sfText_SetCharacterSize;
static pf_sfText_SetStyle sfText_SetStyle; static pf_sfText_SetStyle sfText_SetStyle;
static pf_sfText_GetUnicodeString sfText_GetUnicodeString; static pf_sfText_GetUnicodeString sfText_GetUnicodeString;
static pf_sfText_GetString sfText_GetString; static pf_sfText_GetString sfText_GetString;
static pf_sfText_GetFont sfText_GetFont; static pf_sfText_GetFont sfText_GetFont;
static pf_sfText_GetCharacterSize sfText_GetCharacterSize; static pf_sfText_GetCharacterSize sfText_GetCharacterSize;
static pf_sfText_GetStyle sfText_GetStyle; static pf_sfText_GetStyle sfText_GetStyle;
static pf_sfText_GetCharacterPos sfText_GetCharacterPos; static pf_sfText_GetCharacterPos sfText_GetCharacterPos;
static pf_sfText_GetRect sfText_GetRect; static pf_sfText_GetRect sfText_GetRect;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-graphics-d"); DllLoader dll = DllLoader.load("csfml-graphics-d");
else else
DllLoader dll = DllLoader.load("csfml-graphics"); DllLoader dll = DllLoader.load("csfml-graphics");
sfText_SetString = cast(pf_sfText_SetString)dll.getSymbol("sfText_SetString"); sfText_SetString = cast(pf_sfText_SetString)dll.getSymbol("sfText_SetString");
sfText_SetUnicodeString = cast(pf_sfText_SetUnicodeString)dll.getSymbol("sfText_SetUnicodeString"); sfText_SetUnicodeString = cast(pf_sfText_SetUnicodeString)dll.getSymbol("sfText_SetUnicodeString");
sfText_SetFont = cast(pf_sfText_SetFont)dll.getSymbol("sfText_SetFont"); sfText_SetFont = cast(pf_sfText_SetFont)dll.getSymbol("sfText_SetFont");
sfText_SetCharacterSize = cast(pf_sfText_SetCharacterSize)dll.getSymbol("sfText_SetCharacterSize"); sfText_SetCharacterSize = cast(pf_sfText_SetCharacterSize)dll.getSymbol("sfText_SetCharacterSize");
sfText_SetStyle = cast(pf_sfText_SetStyle)dll.getSymbol("sfText_SetStyle"); sfText_SetStyle = cast(pf_sfText_SetStyle)dll.getSymbol("sfText_SetStyle");
sfText_GetUnicodeString = cast(pf_sfText_GetUnicodeString)dll.getSymbol("sfText_GetUnicodeString"); sfText_GetUnicodeString = cast(pf_sfText_GetUnicodeString)dll.getSymbol("sfText_GetUnicodeString");
sfText_GetString = cast(pf_sfText_GetString)dll.getSymbol("sfText_GetString"); sfText_GetString = cast(pf_sfText_GetString)dll.getSymbol("sfText_GetString");
sfText_GetFont = cast(pf_sfText_GetFont)dll.getSymbol("sfText_GetFont"); sfText_GetFont = cast(pf_sfText_GetFont)dll.getSymbol("sfText_GetFont");
sfText_GetCharacterSize = cast(pf_sfText_GetCharacterSize)dll.getSymbol("sfText_GetCharacterSize"); sfText_GetCharacterSize = cast(pf_sfText_GetCharacterSize)dll.getSymbol("sfText_GetCharacterSize");
sfText_GetStyle = cast(pf_sfText_GetStyle)dll.getSymbol("sfText_GetStyle"); sfText_GetStyle = cast(pf_sfText_GetStyle)dll.getSymbol("sfText_GetStyle");
sfText_GetCharacterPos = cast(pf_sfText_GetCharacterPos)dll.getSymbol("sfText_GetCharacterPos"); sfText_GetCharacterPos = cast(pf_sfText_GetCharacterPos)dll.getSymbol("sfText_GetCharacterPos");
sfText_GetRect = cast(pf_sfText_GetRect)dll.getSymbol("sfText_GetRect"); sfText_GetRect = cast(pf_sfText_GetRect)dll.getSymbol("sfText_GetRect");
} }
} }

View file

@ -1,38 +1,38 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.textstyle; module dsfml.graphics.textstyle;
/** /**
* Enumerate the string drawing styles * Enumerate the string drawing styles
*/ */
enum TextStyle enum TextStyle
{ {
REGULAR = 0, /// Regular characters, no style REGULAR = 0, /// Regular characters, no style
BOLD = 1 << 0, /// Characters are bold BOLD = 1 << 0, /// Characters are bold
ITALIC = 1 << 1, /// Characters are in italic ITALIC = 1 << 1, /// Characters are in italic
UNDERLINED = 1 << 2 /// Characters are underlined UNDERLINED = 1 << 2 /// Characters are underlined
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.graphics.view; module dsfml.graphics.view;
@ -33,8 +33,8 @@ import dsfml.system.common,
dsfml.system.vector2; dsfml.system.vector2;
/** /**
* This class defines a view (position, size and zoom) ; * This class defines a view (position, size and zoom) ;
* you can consider it as a camera * you can consider it as a camera
*/ */
class View : DSFMLObject class View : DSFMLObject
{ {
@ -43,200 +43,200 @@ private:
bool m_isModified = true; bool m_isModified = true;
public: public:
/** /**
* Constructor * Constructor
* *
* Default view (1000 x 1000) * Default view (1000 x 1000)
*/ */
this() this()
{ {
super(sfView_Create()); super(sfView_Create());
} }
/** /**
* Constructor * Constructor
* *
* Params: * Params:
* center = center of the view * center = center of the view
* size = size of the view (width, height) * size = size of the view (width, height)
*/ */
this(Vector2f center, Vector2f size) 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(sfFloatRect(center.x - size.x / 2, center.y - size.y / 2, center.x + size.x / 2, center.y + size.y / 2) ));
} }
/** /**
* Constructor * Constructor
* *
* Params: * Params:
* rect = Rectangle defining the position and size of the view * rect = Rectangle defining the position and size of the view
*/ */
this(FloatRect rect) this(FloatRect rect)
{ {
super(sfView_CreateFromRect(rect.toCFloatRect())); super(sfView_CreateFromRect(rect.toCFloatRect()));
} }
override void dispose() override void dispose()
{ {
sfView_Destroy(m_ptr); sfView_Destroy(m_ptr);
} }
/** /**
* Change the center of the view * Change the center of the view
* *
* Params: * Params:
* x = X coordinates of the new center * x = X coordinates of the new center
* y = Y coordinates of the new center * y = Y coordinates of the new center
*/ */
void setCenter(float x, float y) void setCenter(float x, float y)
{ {
sfView_SetCenter(m_ptr, x, y); sfView_SetCenter(m_ptr, x, y);
m_isModified = true; m_isModified = true;
} }
/** /**
* Change the center of the view * Change the center of the view
* *
* Params: * Params:
* center = New center * center = New center
*/ */
void setCenter(Vector2f center) void setCenter(Vector2f center)
{ {
sfView_SetCenter(m_ptr, center.x, center.y); sfView_SetCenter(m_ptr, center.x, center.y);
m_isModified = true; m_isModified = true;
} }
/** /**
* Change the size of the view (take 2 values) * Change the size of the view (take 2 values)
* *
* Params: * Params:
* width = New width * width = New width
* height = New height * height = New height
*/ */
void setSize(float width, float height) void setSize(float width, float height)
{ {
sfView_SetSize(m_ptr, width, height); sfView_SetSize(m_ptr, width, height);
m_isModified = true; m_isModified = true;
} }
/** /**
* Change the size of the view (take 2 values) * Change the size of the view (take 2 values)
* *
* Params: * Params:
* size = New size * size = New size
*/ */
void setSize(Vector2f size) void setSize(Vector2f size)
{ {
sfView_SetSize(m_ptr, size.x, size.y); sfView_SetSize(m_ptr, size.x, size.y);
m_isModified = true; m_isModified = true;
} }
/** /**
* Rebuild the view from a rectangle * Rebuild the view from a rectangle
* *
* Params: * Params:
* viewport : Rectangle defining the position and size of the view * viewport : Rectangle defining the position and size of the view
*/ */
void setViewport(FloatRect viewport) void setViewport(FloatRect viewport)
{ {
sfView_SetViewport(m_ptr, viewport.toCFloatRect()); sfView_SetViewport(m_ptr, viewport.toCFloatRect());
m_viewport = viewport; m_viewport = viewport;
} }
/** /**
* Get the center of the view * Get the center of the view
* *
* Returns: * Returns:
* Center of the view * Center of the view
*/ */
Vector2f GetCenter() Vector2f GetCenter()
{ {
return Vector2f(sfView_GetCenterX(m_ptr), sfView_GetCenterY(m_ptr)); return Vector2f(sfView_GetCenterX(m_ptr), sfView_GetCenterY(m_ptr));
} }
/** /**
* Get the size of the view * Get the size of the view
* *
* Returns: * Returns:
* size of the view * size of the view
*/ */
Vector2f getSize() Vector2f getSize()
{ {
return Vector2f(sfView_GetWidth(m_ptr), sfView_GetHeight(m_ptr)); return Vector2f(sfView_GetWidth(m_ptr), sfView_GetHeight(m_ptr));
} }
/** /**
* Get the width of the view * Get the width of the view
* *
* Returns: * Returns:
* width of the view * width of the view
*/ */
float getWidth() float getWidth()
{ {
return sfView_GetWidth(m_ptr); return sfView_GetWidth(m_ptr);
} }
/** /**
* Get the height of the view * Get the height of the view
* *
* Returns: * Returns:
* height of the view * height of the view
*/ */
float getHeight() float getHeight()
{ {
return sfView_GetHeight(m_ptr); return sfView_GetHeight(m_ptr);
} }
/** /**
* Get the bounding retangle of the view * Get the bounding retangle of the view
*/ */
FloatRect getViewport() FloatRect getViewport()
{ {
if (m_isModified) if (m_isModified)
{ {
m_isModified = false; m_isModified = false;
sfFloatRect cViewport = sfView_GetViewport(m_ptr); sfFloatRect cViewport = sfView_GetViewport(m_ptr);
m_viewport = new FloatRect(cViewport.Left, cViewport.Top, cViewport.Right, cViewport.Bottom); m_viewport = new FloatRect(cViewport.Left, cViewport.Top, cViewport.Right, cViewport.Bottom);
} }
return m_viewport; return m_viewport;
} }
/** /**
* Move the view * Move the view
* *
* Params: * Params:
* offsetX = Offset to move the view, on X axis * offsetX = Offset to move the view, on X axis
* offsetY = Offset to move the view, on Y axis * offsetY = Offset to move the view, on Y axis
*/ */
void move(float offsetX, float offsetY) void move(float offsetX, float offsetY)
{ {
sfView_Move(m_ptr, offsetX, offsetY); sfView_Move(m_ptr, offsetX, offsetY);
m_isModified = true; m_isModified = true;
} }
/** /**
* Move the view * Move the view
* *
* Params: * Params:
* offset = offsetto move the view * offset = offsetto move the view
*/ */
void move(Vector2f offset) void move(Vector2f offset)
{ {
sfView_Move(m_ptr, offset.x, offset.y); sfView_Move(m_ptr, offset.x, offset.y);
m_isModified = true; m_isModified = true;
} }
/** /**
* Resize the view rectangle to simulate a zoom / unzoom effect * Resize the view rectangle to simulate a zoom / unzoom effect
* *
* Params: * Params:
* factor = Zoom factor to apply, relative to the current zoom * factor = Zoom factor to apply, relative to the current zoom
*/ */
void zoom(float factor) void zoom(float factor)
{ {
sfView_Zoom(m_ptr, factor); sfView_Zoom(m_ptr, factor);
m_isModified = true; m_isModified = true;
} }
/** /**
* Rotate the view relatively to its current orientation. * Rotate the view relatively to its current orientation.

View file

@ -1,37 +1,37 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.all; module dsfml.network.all;
public import public import
dsfml.network.ftp, dsfml.network.ftp,
dsfml.network.http, dsfml.network.http,
dsfml.network.ipaddress, dsfml.network.ipaddress,
dsfml.network.packet, dsfml.network.packet,
dsfml.network.selector, dsfml.network.selector,
dsfml.network.socketstatus, dsfml.network.socketstatus,
dsfml.network.sockettcp, dsfml.network.sockettcp,
dsfml.network.socketudp; dsfml.network.socketudp;

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.http; module dsfml.network.http;
@ -30,369 +30,369 @@ import dsfml.system.stringutil;
import dsfml.system.common; import dsfml.system.common;
/** /**
* HTTP methods enumeration * HTTP methods enumeration
*/ */
enum HttpMethod enum HttpMethod
{ {
GET, ///< Request in get mode, standard method to retrieve a page GET, ///< Request in get mode, standard method to retrieve a page
POST, ///< Request in post mode, usually to send data to a page POST, ///< Request in post mode, usually to send data to a page
HEAD ///< Request a page's header only HEAD ///< Request a page's header only
} }
/** /**
* HTTP response status code * HTTP response status code
*/ */
enum HttpStatus enum HttpStatus
{ {
// 2xx: success // 2xx: success
OK = 200, ///< Most common code returned when operation was successful OK = 200, ///< Most common code returned when operation was successful
CREATED = 201, ///< The resource has successfully been created CREATED = 201, ///< The resource has successfully been created
ACCEPTED = 202, ///< The request has been accepted, but will be processed later by the server ACCEPTED = 202, ///< The request has been accepted, but will be processed later by the server
NOCONTENT = 204, ///< Sent when the server didn't send any data in return NOCONTENT = 204, ///< Sent when the server didn't send any data in return
// 3xx: redirection // 3xx: redirection
MULTIPLECHOICES = 300, ///< The requested page can be accessed from several locations MULTIPLECHOICES = 300, ///< The requested page can be accessed from several locations
MOVEDPERMANENTLY = 301, ///< The requested page has permanently moved to a new location MOVEDPERMANENTLY = 301, ///< The requested page has permanently moved to a new location
MOVEDTEMPORARILY = 302, ///< The requested page has temporarily moved to a new location MOVEDTEMPORARILY = 302, ///< The requested page has temporarily moved to a new location
NOTMODIFIED = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed NOTMODIFIED = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
// 4xx: client error // 4xx: client error
BADREQUEST = 400, ///< The server couldn't understand the request (syntax error) BADREQUEST = 400, ///< The server couldn't understand the request (syntax error)
UNAUTHORIZED = 401, ///< The requested page needs an authentification to be accessed UNAUTHORIZED = 401, ///< The requested page needs an authentification to be accessed
FORBIDDEN = 403, ///< The requested page cannot be accessed at all, even with authentification FORBIDDEN = 403, ///< The requested page cannot be accessed at all, even with authentification
NOTFOUND = 404, ///< The requested page doesn't exist NOTFOUND = 404, ///< The requested page doesn't exist
// 5xx: server error // 5xx: server error
INTERNALSERVERERROR = 500, ///< The server encountered an unexpected error INTERNALSERVERERROR = 500, ///< The server encountered an unexpected error
NOTIMPLEMENTED = 501, ///< The server doesn't implement a requested feature NOTIMPLEMENTED = 501, ///< The server doesn't implement a requested feature
BADGATEWAY = 502, ///< The gateway server has received an error from the source server BADGATEWAY = 502, ///< The gateway server has received an error from the source server
SERVICENOTAVAILABLE = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...) SERVICENOTAVAILABLE = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
// 10xx: SFML custom codes // 10xx: SFML custom codes
INVALIDRESPONSE = 1000, ///< Response is not a valid HTTP one INVALIDRESPONSE = 1000, ///< Response is not a valid HTTP one
CONNECTIONFAILED = 1001 ///< Connection with server failed CONNECTIONFAILED = 1001 ///< Connection with server failed
} }
/** /**
* This class provides methods for manipulating the HTTP protocol (described in * This class provides methods for manipulating the HTTP protocol (described in
* RFC 1945). * RFC 1945).
* It can connect to a website, get files, send requests * It can connect to a website, get files, send requests
*/ */
class Http : DSFMLObject class Http : DSFMLObject
{ {
/** /**
* Wrapper for a http request, which is basically : * Wrapper for a http request, which is basically :
* - a header with a method, a target URI and a set of field/value pairs * - a header with a method, a target URI and a set of field/value pairs
* - an optional body (for POST requests) * - an optional body (for POST requests)
*/ */
static class Response : DSFMLObject static class Response : DSFMLObject
{ {
override void dispose() override void dispose()
{ {
sfHttpResponse_Destroy(m_ptr); sfHttpResponse_Destroy(m_ptr);
} }
/** /**
* Get the value of a field * Get the value of a field
* *
* Params: * Params:
* field = Name of the field to get (case-insensitive) * field = Name of the field to get (case-insensitive)
* Returns: * Returns:
* Value of the field, or enpty string if not found * Value of the field, or enpty string if not found
*/ */
string getField(string field) string getField(string field)
{ {
return fromStringz(sfHttpResponse_GetField(m_ptr, toStringz(field))); return fromStringz(sfHttpResponse_GetField(m_ptr, toStringz(field)));
} }
/** /**
* Get the header status code * Get the header status code
* *
* Returns: * Returns:
* header status code * header status code
*/ */
HttpStatus getStatus() HttpStatus getStatus()
{ {
return sfHttpResponse_GetStatus(m_ptr); return sfHttpResponse_GetStatus(m_ptr);
} }
/** /**
* Get the major HTTP version number of the response * Get the major HTTP version number of the response
* *
* Returns: * Returns:
* Major version number * Major version number
*/ */
uint getMajorHTTPVersion() uint getMajorHTTPVersion()
{ {
return sfHttpResponse_GetMajorVersion(m_ptr); return sfHttpResponse_GetMajorVersion(m_ptr);
} }
/** /**
* Get the minor HTTP version number of the response * Get the minor HTTP version number of the response
* *
* Returns: * Returns:
* Minor version number * Minor version number
*/ */
uint getMinorHTTPVersion() uint getMinorHTTPVersion()
{ {
return sfHttpResponse_GetMinorVersion(m_ptr); return sfHttpResponse_GetMinorVersion(m_ptr);
} }
/** /**
* Get the body of the response. The body can contain : * Get the body of the response. The body can contain :
* - the requested page (for GET requests) * - the requested page (for GET requests)
* - a response from the server (for POST requests) * - a response from the server (for POST requests)
* - nothing (for HEAD requests) * - nothing (for HEAD requests)
* - an error message (in case of an error) * - an error message (in case of an error)
* *
* Returns: * Returns:
* the response body * the response body
*/ */
string getBody() string getBody()
{ {
return fromStringz(sfHttpResponse_GetBody(m_ptr)); return fromStringz(sfHttpResponse_GetBody(m_ptr));
} }
private: private:
this(void* ptr) this(void* ptr)
{ {
super(ptr); super(ptr);
} }
// External ================================================================ // External ================================================================
extern (C) extern (C)
{ {
typedef void function(void*) pf_sfHttpResponse_Destroy; typedef void function(void*) pf_sfHttpResponse_Destroy;
typedef char* function(void*, char*) pf_sfHttpResponse_GetField; typedef char* function(void*, char*) pf_sfHttpResponse_GetField;
typedef HttpStatus function(void*) pf_sfHttpResponse_GetStatus; typedef HttpStatus function(void*) pf_sfHttpResponse_GetStatus;
typedef uint function(void*) pf_sfHttpResponse_GetMajorVersion; typedef uint function(void*) pf_sfHttpResponse_GetMajorVersion;
typedef uint function(void*) pf_sfHttpResponse_GetMinorVersion; typedef uint function(void*) pf_sfHttpResponse_GetMinorVersion;
typedef char* function(void*) pf_sfHttpResponse_GetBody; typedef char* function(void*) pf_sfHttpResponse_GetBody;
static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy; static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy;
static pf_sfHttpResponse_GetField sfHttpResponse_GetField; static pf_sfHttpResponse_GetField sfHttpResponse_GetField;
static pf_sfHttpResponse_GetStatus sfHttpResponse_GetStatus; static pf_sfHttpResponse_GetStatus sfHttpResponse_GetStatus;
static pf_sfHttpResponse_GetMajorVersion sfHttpResponse_GetMajorVersion; static pf_sfHttpResponse_GetMajorVersion sfHttpResponse_GetMajorVersion;
static pf_sfHttpResponse_GetMinorVersion sfHttpResponse_GetMinorVersion; static pf_sfHttpResponse_GetMinorVersion sfHttpResponse_GetMinorVersion;
static pf_sfHttpResponse_GetBody sfHttpResponse_GetBody; static pf_sfHttpResponse_GetBody sfHttpResponse_GetBody;
} }
static this() static this()
{ {
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfHttpResponse_Destroy = cast(pf_sfHttpResponse_Destroy)dll.getSymbol("sfHttpResponse_Destroy"); sfHttpResponse_Destroy = cast(pf_sfHttpResponse_Destroy)dll.getSymbol("sfHttpResponse_Destroy");
sfHttpResponse_GetField = cast(pf_sfHttpResponse_GetField)dll.getSymbol("sfHttpResponse_GetField"); sfHttpResponse_GetField = cast(pf_sfHttpResponse_GetField)dll.getSymbol("sfHttpResponse_GetField");
sfHttpResponse_GetStatus = cast(pf_sfHttpResponse_GetStatus)dll.getSymbol("sfHttpResponse_GetStatus"); sfHttpResponse_GetStatus = cast(pf_sfHttpResponse_GetStatus)dll.getSymbol("sfHttpResponse_GetStatus");
sfHttpResponse_GetMajorVersion = cast(pf_sfHttpResponse_GetMajorVersion)dll.getSymbol("sfHttpResponse_GetMajorVersion"); sfHttpResponse_GetMajorVersion = cast(pf_sfHttpResponse_GetMajorVersion)dll.getSymbol("sfHttpResponse_GetMajorVersion");
sfHttpResponse_GetMinorVersion = cast(pf_sfHttpResponse_GetMinorVersion)dll.getSymbol("sfHttpResponse_GetMinorVersion"); sfHttpResponse_GetMinorVersion = cast(pf_sfHttpResponse_GetMinorVersion)dll.getSymbol("sfHttpResponse_GetMinorVersion");
sfHttpResponse_GetBody = cast(pf_sfHttpResponse_GetBody)dll.getSymbol("sfHttpResponse_GetBody"); sfHttpResponse_GetBody = cast(pf_sfHttpResponse_GetBody)dll.getSymbol("sfHttpResponse_GetBody");
} }
} }
/** /**
* Wrapper for a HTTP response which is basically : * Wrapper for a HTTP response which is basically :
* - a header with a status code and a set of field/value pairs * - a header with a status code and a set of field/value pairs
* - a body (the content of the requested resource) * - a body (the content of the requested resource)
*/ */
static class Request : DSFMLObject static class Request : DSFMLObject
{ {
/** /**
* Constructor * Constructor
* *
* Params: * Params:
* requestMethod = Method to use for the request (Get by default) * requestMethod = Method to use for the request (Get by default)
* uri = Target URI ("/" by default -- index page) * uri = Target URI ("/" by default -- index page)
* requestBody = Content of the request's body (empty by default) * requestBody = Content of the request's body (empty by default)
*/ */
this(HttpMethod requestMethod = HttpMethod.GET, string uri = "/", string requestBody = "") this(HttpMethod requestMethod = HttpMethod.GET, string uri = "/", string requestBody = "")
{ {
super(sfHttpRequest_Create()); super(sfHttpRequest_Create());
sfHttpRequest_SetMethod(m_ptr, requestMethod); sfHttpRequest_SetMethod(m_ptr, requestMethod);
sfHttpRequest_SetURI(m_ptr, toStringz(uri)); sfHttpRequest_SetURI(m_ptr, toStringz(uri));
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody)); sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
} }
/** /**
* Set the value of a field. Field is created if it doesn't exists. * Set the value of a field. Field is created if it doesn't exists.
* *
* Params: * Params:
* field = name of the field to set (case-insensitive) * field = name of the field to set (case-insensitive)
* value = value of the field * value = value of the field
*/ */
void setField(string field, string value) void setField(string field, string value)
{ {
sfHttpRequest_SetField(m_ptr, toStringz(field), toStringz(value)); sfHttpRequest_SetField(m_ptr, toStringz(field), toStringz(value));
} }
/** /**
* Set the request method. * Set the request method.
* *
* Params: * Params:
* requestMethod = Method to use for the request. * requestMethod = Method to use for the request.
*/ */
void setMethod(HttpMethod requestMethod) void setMethod(HttpMethod requestMethod)
{ {
sfHttpRequest_SetMethod(m_ptr, requestMethod); sfHttpRequest_SetMethod(m_ptr, requestMethod);
} }
/** /**
* Set the target URI of the request. * Set the target URI of the request.
* *
* Params: * Params:
* uri = URI to request, local to the host. * uri = URI to request, local to the host.
* Returns: * Returns:
*/ */
void setURI(string uri) void setURI(string uri)
{ {
sfHttpRequest_SetURI(m_ptr, toStringz(uri)); sfHttpRequest_SetURI(m_ptr, toStringz(uri));
} }
/** /**
* Set the HTTP version of the request. * Set the HTTP version of the request.
* *
* Params: * Params:
* major = Major version number * major = Major version number
* minor = Minor version number * minor = Minor version number
*/ */
void setHttpVersion(uint major, uint minor) void setHttpVersion(uint major, uint minor)
{ {
sfHttpRequest_SetHttpVersion(m_ptr, major, minor); sfHttpRequest_SetHttpVersion(m_ptr, major, minor);
} }
/** /**
* Set the body of the request. This parameter is optionnal and make sense * Set the body of the request. This parameter is optionnal and make sense
* only for POST requests. * only for POST requests.
* *
* Params: * Params:
* requestBody = Content of the request body. * requestBody = Content of the request body.
*/ */
void setBody(string requestBody) void setBody(string requestBody)
{ {
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody)); sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
} }
private: private:
// External ================================================================ // External ================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfHttpRequest_Create; typedef void* function() pf_sfHttpRequest_Create;
typedef void function(void*) pf_sfHttpRequest_Destroy; typedef void function(void*) pf_sfHttpRequest_Destroy;
typedef void function(void*, char*, char*) pf_sfHttpRequest_SetField; typedef void function(void*, char*, char*) pf_sfHttpRequest_SetField;
typedef void function(void*, HttpMethod) pf_sfHttpRequest_SetMethod; typedef void function(void*, HttpMethod) pf_sfHttpRequest_SetMethod;
typedef void function(void*, char*) pf_sfHttpRequest_SetURI; typedef void function(void*, char*) pf_sfHttpRequest_SetURI;
typedef void function(void*, uint, uint) pf_sfHttpRequest_SetHttpVersion; typedef void function(void*, uint, uint) pf_sfHttpRequest_SetHttpVersion;
typedef void function(void*, char*) pf_sfHttpRequest_SetBody; typedef void function(void*, char*) pf_sfHttpRequest_SetBody;
static pf_sfHttpRequest_Create sfHttpRequest_Create; static pf_sfHttpRequest_Create sfHttpRequest_Create;
static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy; static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy;
static pf_sfHttpRequest_SetField sfHttpRequest_SetField; static pf_sfHttpRequest_SetField sfHttpRequest_SetField;
static pf_sfHttpRequest_SetMethod sfHttpRequest_SetMethod; static pf_sfHttpRequest_SetMethod sfHttpRequest_SetMethod;
static pf_sfHttpRequest_SetURI sfHttpRequest_SetURI; static pf_sfHttpRequest_SetURI sfHttpRequest_SetURI;
static pf_sfHttpRequest_SetHttpVersion sfHttpRequest_SetHttpVersion; static pf_sfHttpRequest_SetHttpVersion sfHttpRequest_SetHttpVersion;
static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody; static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody;
} }
static this() static this()
{ {
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfHttpRequest_Create = cast(pf_sfHttpRequest_Create)dll.getSymbol("sfHttpRequest_Create"); sfHttpRequest_Create = cast(pf_sfHttpRequest_Create)dll.getSymbol("sfHttpRequest_Create");
sfHttpRequest_Destroy = cast(pf_sfHttpRequest_Destroy)dll.getSymbol("sfHttpRequest_Destroy"); sfHttpRequest_Destroy = cast(pf_sfHttpRequest_Destroy)dll.getSymbol("sfHttpRequest_Destroy");
sfHttpRequest_SetField = cast(pf_sfHttpRequest_SetField)dll.getSymbol("sfHttpRequest_SetField"); sfHttpRequest_SetField = cast(pf_sfHttpRequest_SetField)dll.getSymbol("sfHttpRequest_SetField");
sfHttpRequest_SetMethod = cast(pf_sfHttpRequest_SetMethod)dll.getSymbol("sfHttpRequest_SetMethod"); sfHttpRequest_SetMethod = cast(pf_sfHttpRequest_SetMethod)dll.getSymbol("sfHttpRequest_SetMethod");
sfHttpRequest_SetURI = cast(pf_sfHttpRequest_SetURI)dll.getSymbol("sfHttpRequest_SetURI"); sfHttpRequest_SetURI = cast(pf_sfHttpRequest_SetURI)dll.getSymbol("sfHttpRequest_SetURI");
sfHttpRequest_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion"); sfHttpRequest_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion");
sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody"); sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody");
} }
} }
/** /**
* Constructor * Constructor
*/ */
this() this()
{ {
super(sfHttp_Create()); super(sfHttp_Create());
} }
/** /**
* Constructor * Constructor
* *
* Params: * Params:
* host = Web server to connect to * host = Web server to connect to
* port = port to use for connection (0 by default -- use the standard port of the protocol) * port = port to use for connection (0 by default -- use the standard port of the protocol)
*/ */
this(string host, ushort port = 0) this(string host, ushort port = 0)
{ {
super(sfHttp_Create()); super(sfHttp_Create());
sfHttp_SetHost(m_ptr, toStringz(host), port); sfHttp_SetHost(m_ptr, toStringz(host), port);
} }
override void dispose() override void dispose()
{ {
sfHttp_Destroy(m_ptr); sfHttp_Destroy(m_ptr);
} }
/** /**
* Set the target host. * Set the target host.
* *
* Params: * Params:
* host = Web server to connect to * host = Web server to connect to
* port = port to use for connection (0 by default -- use the standard port of the protocol) * port = port to use for connection (0 by default -- use the standard port of the protocol)
*/ */
void setHost(string host, ushort port = 0) void setHost(string host, ushort port = 0)
{ {
sfHttp_SetHost(m_ptr, toStringz(host), port); sfHttp_SetHost(m_ptr, toStringz(host), port);
} }
/** /**
* Send a HTTP request and return the server's response. * Send a HTTP request and return the server's response.
* You must be connected to a host before sending requests. * You must be connected to a host before sending requests.
* Any missing mandatory header field will be added with an appropriate value. * Any missing mandatory header field will be added with an appropriate value.
* *
* Warning : this function waits for the server's response and may * Warning : this function waits for the server's response and may
* not return instantly; use a thread if you don't want to block your * not return instantly; use a thread if you don't want to block your
* application. * application.
* *
* Params: * Params:
* req = Request to send * req = Request to send
* *
* Returns: * Returns:
* Server's response * Server's response
*/ */
Response sendRequest(Request req) Response sendRequest(Request req)
{ {
return new Response( sfHttp_SendRequest(m_ptr, req.getNativePointer) ); return new Response( sfHttp_SendRequest(m_ptr, req.getNativePointer) );
} }
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfHttp_Create; typedef void* function() pf_sfHttp_Create;
typedef void function(void*) pf_sfHttp_Destroy; typedef void function(void*) pf_sfHttp_Destroy;
typedef void function(void*, char*, ushort) pf_sfHttp_SetHost; typedef void function(void*, char*, ushort) pf_sfHttp_SetHost;
typedef void* function(void*, void*) pf_sfHttp_SendRequest; typedef void* function(void*, void*) pf_sfHttp_SendRequest;
static pf_sfHttp_Create sfHttp_Create; static pf_sfHttp_Create sfHttp_Create;
static pf_sfHttp_Destroy sfHttp_Destroy; static pf_sfHttp_Destroy sfHttp_Destroy;
static pf_sfHttp_SetHost sfHttp_SetHost; static pf_sfHttp_SetHost sfHttp_SetHost;
static pf_sfHttp_SendRequest sfHttp_SendRequest; static pf_sfHttp_SendRequest sfHttp_SendRequest;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-network-d"); DllLoader dll = DllLoader.load("csfml-network-d");
else else
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfHttp_Create = cast(pf_sfHttp_Create)dll.getSymbol("sfHttp_Create"); sfHttp_Create = cast(pf_sfHttp_Create)dll.getSymbol("sfHttp_Create");
sfHttp_Destroy = cast(pf_sfHttp_Destroy)dll.getSymbol("sfHttp_Destroy"); sfHttp_Destroy = cast(pf_sfHttp_Destroy)dll.getSymbol("sfHttp_Destroy");
sfHttp_SetHost = cast(pf_sfHttp_SetHost)dll.getSymbol("sfHttp_SetHost"); sfHttp_SetHost = cast(pf_sfHttp_SetHost)dll.getSymbol("sfHttp_SetHost");
sfHttp_SendRequest = cast(pf_sfHttp_SendRequest)dll.getSymbol("sfHttp_SendRequest"); sfHttp_SendRequest = cast(pf_sfHttp_SendRequest)dll.getSymbol("sfHttp_SendRequest");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.ipaddress; module dsfml.network.ipaddress;
@ -30,111 +30,111 @@ import dsfml.system.common;
import dsfml.system.stringutil; import dsfml.system.stringutil;
/** /**
* IPAddress provides easy manipulation of IP v4 addresses * IPAddress provides easy manipulation of IP v4 addresses
*/ */
struct IPAddress struct IPAddress
{ {
/** /**
* Construct the address from a string * Construct the address from a string
* *
* Params: * Params:
* address = IP address ("xxx.xxx.xxx.xxx") or network name * address = IP address ("xxx.xxx.xxx.xxx") or network name
* *
*/ */
static IPAddress opCall(string address) static IPAddress opCall(string address)
{ {
return sfIPAddress_FromString(toStringz(address)); return sfIPAddress_FromString(toStringz(address));
} }
/** /**
* Construct the address from 4 bytes * Construct the address from 4 bytes
* *
* Params: * Params:
* byte0 = First byte of the address * byte0 = First byte of the address
* byte1 = Second byte of the address * byte1 = Second byte of the address
* byte2 = Third byte of the address * byte2 = Third byte of the address
* byte3 = Fourth byte of the address * byte3 = Fourth byte of the address
* *
*/ */
static IPAddress opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3) static IPAddress opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3)
{ {
return sfIPAddress_FromBytes(byte0, byte1, byte2, byte3); return sfIPAddress_FromBytes(byte0, byte1, byte2, byte3);
} }
/** /**
* Construct the address from a 32 bits integer * Construct the address from a 32 bits integer
* *
* Params: * Params:
* address = 4 bytes of the address packed into a 32 bits integer * address = 4 bytes of the address packed into a 32 bits integer
* *
*/ */
static IPAddress opCall(uint address) static IPAddress opCall(uint address)
{ {
return sfIPAddress_FromInteger(address); return sfIPAddress_FromInteger(address);
} }
/** /**
* Tell if the address is a valid one * Tell if the address is a valid one
* *
* Returns: * Returns:
* True if address has a valid syntax * True if address has a valid syntax
* *
*/ */
bool isValid() bool isValid()
{ {
return cast(bool)sfIPAddress_IsValid(this); return cast(bool)sfIPAddress_IsValid(this);
} }
/** /**
* Get the computer's local IP address (from the LAN point of view) * Get the computer's local IP address (from the LAN point of view)
* *
* Returns: * Returns:
* Local IP address * Local IP address
* *
*/ */
static IPAddress getLocalAddress() static IPAddress getLocalAddress()
{ {
return sfIPAddress_GetLocalAddress(); return sfIPAddress_GetLocalAddress();
} }
/** /**
* Get the computer's public IP address (from the web point of view). * Get the computer's public IP address (from the web point of view).
* The only way to get a public address is to ask it to a * The only way to get a public address is to ask it to a
* distant website ; as a consequence, this function may be * distant website ; as a consequence, this function may be
* very slow -- use it as few as possible ! * very slow -- use it as few as possible !
* *
* Returns: * Returns:
* Public IP address * Public IP address
* *
*/ */
static IPAddress getPublicAddress() static IPAddress getPublicAddress()
{ {
return sfIPAddress_GetPublicAddress(); return sfIPAddress_GetPublicAddress();
} }
bool opEqual(IPAddress other) bool opEqual(IPAddress other)
{ {
return Address == other.Address; return Address == other.Address;
} }
/** /**
* Local host address (to connect to the same computer). * Local host address (to connect to the same computer).
*/ */
static IPAddress LOCALHOST() static IPAddress LOCALHOST()
{ {
return sfIPAddress_LocalHost(); return sfIPAddress_LocalHost();
} }
byte[16] Address; byte[16] Address;
} }
private: private:
extern (C) extern (C)
{ {
typedef IPAddress function(char*) pf_sfIPAddress_FromString; typedef IPAddress function(char*) pf_sfIPAddress_FromString;
typedef IPAddress function(ubyte, ubyte, ubyte, ubyte) pf_sfIPAddress_FromBytes; typedef IPAddress function(ubyte, ubyte, ubyte, ubyte) pf_sfIPAddress_FromBytes;
typedef IPAddress function(uint) pf_sfIPAddress_FromInteger; typedef IPAddress function(uint) pf_sfIPAddress_FromInteger;
typedef int function(IPAddress) pf_sfIPAddress_IsValid; typedef int function(IPAddress) pf_sfIPAddress_IsValid;
@ -157,12 +157,12 @@ static this()
DllLoader dll = DllLoader.load("csfml-network-d"); DllLoader dll = DllLoader.load("csfml-network-d");
else else
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfIPAddress_FromBytes = cast(pf_sfIPAddress_FromBytes)dll.getSymbol("sfIPAddress_FromBytes"); sfIPAddress_FromBytes = cast(pf_sfIPAddress_FromBytes)dll.getSymbol("sfIPAddress_FromBytes");
sfIPAddress_FromString = cast(pf_sfIPAddress_FromString)dll.getSymbol("sfIPAddress_FromString"); sfIPAddress_FromString = cast(pf_sfIPAddress_FromString)dll.getSymbol("sfIPAddress_FromString");
sfIPAddress_FromInteger = cast(pf_sfIPAddress_FromInteger)dll.getSymbol("sfIPAddress_FromInteger"); sfIPAddress_FromInteger = cast(pf_sfIPAddress_FromInteger)dll.getSymbol("sfIPAddress_FromInteger");
sfIPAddress_GetLocalAddress = cast(pf_sfIPAddress_GetLocalAddress)dll.getSymbol("sfIPAddress_GetLocalAddress"); sfIPAddress_GetLocalAddress = cast(pf_sfIPAddress_GetLocalAddress)dll.getSymbol("sfIPAddress_GetLocalAddress");
sfIPAddress_GetPublicAddress = cast(pf_sfIPAddress_GetPublicAddress)dll.getSymbol("sfIPAddress_GetPublicAddress"); sfIPAddress_GetPublicAddress = cast(pf_sfIPAddress_GetPublicAddress)dll.getSymbol("sfIPAddress_GetPublicAddress");
sfIPAddress_IsValid = cast(pf_sfIPAddress_IsValid)dll.getSymbol("sfIPAddress_IsValid"); sfIPAddress_IsValid = cast(pf_sfIPAddress_IsValid)dll.getSymbol("sfIPAddress_IsValid");
sfIPAddress_LocalHost = cast(pf_sfIPAddress_LocalHost)dll.getSymbol("sfIPAddress_LocalHost"); sfIPAddress_LocalHost = cast(pf_sfIPAddress_LocalHost)dll.getSymbol("sfIPAddress_LocalHost");
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.packet; module dsfml.network.packet;
@ -30,388 +30,388 @@ import dsfml.system.common;
import dsfml.system.stringutil; import dsfml.system.stringutil;
/** /**
* Packet wraps data to send / to receive through the network * Packet wraps data to send / to receive through the network
* *
* The order of insertion and extraction must be the same. * The order of insertion and extraction must be the same.
* *
* You can derive from Packet and override onSend and onReceive to do custom operations before send or after reception. * You can derive from Packet and override onSend and onReceive to do custom operations before send or after reception.
* *
* Litterals integer are promoted to int. * Litterals integer are promoted to int.
* Litterals floating point are promoted to float. * Litterals floating point are promoted to float.
* *
* Extraction or insertion can be specified with explicit template. * Extraction or insertion can be specified with explicit template.
* Examples: * Examples:
* ------------------------------------------------------------ * ------------------------------------------------------------
* Packet p = new Packet(); * Packet p = new Packet();
* *
* int i = 32, j = 42; * int i = 32, j = 42;
* string k = hello; * string k = hello;
* *
* p.set(i, k, j); //Set the data in the packet * p.set(i, k, j); //Set the data in the packet
* *
* int a, b; * int a, b;
* string c; * string c;
* p.get(a, c, b); //Get data from the packet * p.get(a, c, b); //Get data from the packet
* *
* //... * //...
* *
* Packet p = new Packet(); * Packet p = new Packet();
* p.set!(byte)(5); // Litteral are inserted with byte type * p.set!(byte)(5); // Litteral are inserted with byte type
* ------------------------------------------------------------ * ------------------------------------------------------------
* *
* See_Also: * See_Also:
* $(LINK2 http://www.digitalmars.com/d/1.0/lex.html, D litterals Specification) for more informations. * $(LINK2 http://www.digitalmars.com/d/1.0/lex.html, D litterals Specification) for more informations.
*/ */
class Packet : DSFMLObject class Packet : DSFMLObject
{ {
/** /**
* Default constructor * Default constructor
* *
*/ */
this() this()
{ {
super(sfPacket_Create()); super(sfPacket_Create());
} }
override void dispose() override void dispose()
{ {
sfPacket_Destroy(m_ptr); sfPacket_Destroy(m_ptr);
} }
/** /**
* Append data to the end of the packet. * Append data to the end of the packet.
* *
* Params: * Params:
* data = Array of data to append * data = Array of data to append
* *
*/ */
void append(byte[] data) void append(byte[] data)
{ {
if (data !is null) if (data !is null)
sfPacket_Append(m_ptr, data.ptr, data.length); sfPacket_Append(m_ptr, data.ptr, data.length);
} }
/** /**
* Clear the packet data * Clear the packet data
* *
*/ */
void clear() void clear()
{ {
sfPacket_Clear(m_ptr); sfPacket_Clear(m_ptr);
} }
/** /**
* Get an array to the data contained in the packet * Get an array to the data contained in the packet
* $(B the returned array may be invalid after you * $(B the returned array may be invalid after you
* append data to the packet) * append data to the packet)
* *
* Returns: * Returns:
* array of data * array of data
* *
* Remarks: * Remarks:
* return an array of $(B all) data in the packet. * return an array of $(B all) data in the packet.
* *
* ---------- * ----------
* Packet p = new Packet(); * Packet p = new Packet();
* *
* string str1 = "Hi"; * string str1 = "Hi";
* string str2 = "Hello"; * string str2 = "Hello";
* *
* p.set(str1, str2); * p.set(str1, str2);
* *
* // Retrieve str1 from packet * // Retrieve str1 from packet
* string str3; * string str3;
* p.get(str3); * p.get(str3);
* *
* // Returns an array containing str1 and str2. * // Returns an array containing str1 and str2.
* byte[] ptr = p.getData(); * byte[] ptr = p.getData();
* ---------- * ----------
*/ */
byte[] getData() byte[] getData()
{ {
if (canRead) if (canRead)
return sfPacket_GetData(m_ptr)[0..getDataSize]; return sfPacket_GetData(m_ptr)[0..getDataSize];
} }
/** /**
* Get the size of the data contained in the packet * Get the size of the data contained in the packet
* *
* Returns: * Returns:
* Data size, in bytes * Data size, in bytes
*/ */
uint getDataSize() uint getDataSize()
{ {
return sfPacket_GetDataSize(m_ptr); return sfPacket_GetDataSize(m_ptr);
} }
/** /**
* Tell if the reading position has reached the end of the packet * Tell if the reading position has reached the end of the packet
* *
* Returns: * Returns:
* true if all data have been read. * true if all data have been read.
*/ */
bool endOfPacket() bool endOfPacket()
{ {
return cast(bool)sfPacket_EndOfPacket(m_ptr); return cast(bool)sfPacket_EndOfPacket(m_ptr);
} }
/** /**
* Tell if the packet is valid for reading * Tell if the packet is valid for reading
* *
* Returns: * Returns:
* True if data can be extracted from the packet * True if data can be extracted from the packet
* *
*/ */
bool canRead() bool canRead()
{ {
return cast(bool)sfPacket_CanRead(m_ptr); return cast(bool)sfPacket_CanRead(m_ptr);
} }
/** /**
* Add new variables to the packet * Add new variables to the packet
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types * Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
*/ */
Packet set(T...)(T t) Packet set(T...)(T t)
{ {
foreach (v; t) foreach (v; t)
internalSet(t); internalSet(t);
return this; return this;
} }
/** /**
* Retrieve data from the packet * Retrieve data from the packet
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types * Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
*/ */
Packet get(T...)(ref T t) Packet get(T...)(ref T t)
{ {
foreach (v; t) foreach (v; t)
internalGet(t); internalGet(t);
return this; return this;
} }
/** /**
* Called before packet is send * Called before packet is send
* *
* Params: * Params:
* size = Variable to fill with the size of the data to send * size = Variable to fill with the size of the data to send
* Returns: * Returns:
* Array of byte to send * Array of byte to send
*/ */
byte[] onSend() byte[] onSend()
{ {
return getData(); return getData();
} }
/** /**
* Called after a packet has been received * Called after a packet has been received
* *
* Params: * Params:
* data = Array of byte received * data = Array of byte received
*/ */
void onReceive(byte[] data) void onReceive(byte[] data)
{ {
append(data); append(data);
} }
private: private:
void internalGet(ref bool data) void internalGet(ref bool data)
{ {
data = cast(bool)sfPacket_ReadInt32(m_ptr); data = cast(bool)sfPacket_ReadInt32(m_ptr);
} }
void internalGet(ref byte data) void internalGet(ref byte data)
{ {
data = sfPacket_ReadInt8(m_ptr); data = sfPacket_ReadInt8(m_ptr);
} }
void internalGet(ref ubyte data) void internalGet(ref ubyte data)
{ {
data = sfPacket_ReadUint8(m_ptr); data = sfPacket_ReadUint8(m_ptr);
} }
void internalGet(ref short data) void internalGet(ref short data)
{ {
data = sfPacket_ReadInt16(m_ptr); data = sfPacket_ReadInt16(m_ptr);
} }
void internalGet(ref ushort data) void internalGet(ref ushort data)
{ {
data = sfPacket_ReadUint16(m_ptr); data = sfPacket_ReadUint16(m_ptr);
} }
void internalGet(ref int data) void internalGet(ref int data)
{ {
data = sfPacket_ReadInt32(m_ptr); data = sfPacket_ReadInt32(m_ptr);
} }
void internalGet(ref uint data) void internalGet(ref uint data)
{ {
data = sfPacket_ReadUint32(m_ptr); data = sfPacket_ReadUint32(m_ptr);
} }
void internalGet(ref float data) void internalGet(ref float data)
{ {
data = sfPacket_ReadFloat(m_ptr); data = sfPacket_ReadFloat(m_ptr);
} }
void internalGet(ref double data) void internalGet(ref double data)
{ {
data = sfPacket_ReadDouble(m_ptr); data = sfPacket_ReadDouble(m_ptr);
} }
void internalGet(ref string data) void internalGet(ref string data)
{ {
scope string temp = new char[sfPacket_GetDataSize(m_ptr)]; scope string temp = new char[sfPacket_GetDataSize(m_ptr)];
sfPacket_ReadString(m_ptr, temp.ptr); sfPacket_ReadString(m_ptr, temp.ptr);
size_t l = fromStringz(temp.ptr).length; size_t l = fromStringz(temp.ptr).length;
data = new char[l]; data = new char[l];
data[] = temp[0 .. l]; data[] = temp[0 .. l];
} }
void internalGet(ref wstring data) void internalGet(ref wstring data)
{ {
scope wstring temp = new wchar[sfPacket_GetDataSize(m_ptr)]; scope wstring temp = new wchar[sfPacket_GetDataSize(m_ptr)];
sfPacket_ReadWideString(m_ptr, temp.ptr); sfPacket_ReadWideString(m_ptr, temp.ptr);
size_t l = fromStringz(temp.ptr).length; size_t l = fromStringz(temp.ptr).length;
data = new wchar[l]; data = new wchar[l];
data[] = temp[0 .. l]; data[] = temp[0 .. l];
} }
void internalSet(bool data) void internalSet(bool data)
{ {
sfPacket_WriteInt32(m_ptr, cast(int)data); sfPacket_WriteInt32(m_ptr, cast(int)data);
} }
void internalSet(byte data) void internalSet(byte data)
{ {
sfPacket_WriteInt8(m_ptr, data); sfPacket_WriteInt8(m_ptr, data);
} }
void internalSet(ubyte data) void internalSet(ubyte data)
{ {
sfPacket_WriteUint8(m_ptr, data); sfPacket_WriteUint8(m_ptr, data);
} }
void internalSet(short data) void internalSet(short data)
{ {
sfPacket_WriteInt16(m_ptr, data); sfPacket_WriteInt16(m_ptr, data);
} }
void internalSet(ushort data) void internalSet(ushort data)
{ {
sfPacket_WriteUint16(m_ptr, data); sfPacket_WriteUint16(m_ptr, data);
} }
void internalSet(int data) void internalSet(int data)
{ {
sfPacket_WriteInt32(m_ptr, data); sfPacket_WriteInt32(m_ptr, data);
} }
void internalSet(uint data) void internalSet(uint data)
{ {
sfPacket_WriteUint32(m_ptr, data); sfPacket_WriteUint32(m_ptr, data);
} }
void internalSet(float data) void internalSet(float data)
{ {
sfPacket_WriteFloat(m_ptr, data); sfPacket_WriteFloat(m_ptr, data);
} }
void internalSet(double data) void internalSet(double data)
{ {
sfPacket_WriteDouble(m_ptr, data); sfPacket_WriteDouble(m_ptr, data);
} }
void internalSet(string data) void internalSet(string data)
{ {
sfPacket_WriteString(m_ptr, toStringz(data)); sfPacket_WriteString(m_ptr, toStringz(data));
} }
void internalSet(wstring data) void internalSet(wstring data)
{ {
sfPacket_WriteWideString(m_ptr, toStringz(data)); sfPacket_WriteWideString(m_ptr, toStringz(data));
} }
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfPacket_Create; typedef void* function() pf_sfPacket_Create;
typedef void function(void*) pf_sfPacket_Destroy; typedef void function(void*) pf_sfPacket_Destroy;
typedef void function(void*, void*, size_t) pf_sfPacket_Append; typedef void function(void*, void*, size_t) pf_sfPacket_Append;
typedef void function(void*) pf_sfPacket_Clear; typedef void function(void*) pf_sfPacket_Clear;
typedef byte* function(void*) pf_sfPacket_GetData; typedef byte* function(void*) pf_sfPacket_GetData;
typedef uint function(void*) pf_sfPacket_GetDataSize; typedef uint function(void*) pf_sfPacket_GetDataSize;
typedef int function(void*) pf_sfPacket_EndOfPacket; typedef int function(void*) pf_sfPacket_EndOfPacket;
typedef int function(void*) pf_sfPacket_CanRead; typedef int function(void*) pf_sfPacket_CanRead;
typedef byte function(void*) pf_sfPacket_ReadInt8; typedef byte function(void*) pf_sfPacket_ReadInt8;
typedef ubyte function(void*) pf_sfPacket_ReadUint8; typedef ubyte function(void*) pf_sfPacket_ReadUint8;
typedef short function(void*) pf_sfPacket_ReadInt16; typedef short function(void*) pf_sfPacket_ReadInt16;
typedef ushort function(void*) pf_sfPacket_ReadUint16; typedef ushort function(void*) pf_sfPacket_ReadUint16;
typedef int function(void*) pf_sfPacket_ReadInt32; typedef int function(void*) pf_sfPacket_ReadInt32;
typedef uint function(void*) pf_sfPacket_ReadUint32; typedef uint function(void*) pf_sfPacket_ReadUint32;
typedef float function(void*) pf_sfPacket_ReadFloat; typedef float function(void*) pf_sfPacket_ReadFloat;
typedef double function(void*) pf_sfPacket_ReadDouble; typedef double function(void*) pf_sfPacket_ReadDouble;
typedef void function(void*, char*) pf_sfPacket_ReadString; typedef void function(void*, char*) pf_sfPacket_ReadString;
typedef void function(void*, wchar*) pf_sfPacket_ReadWideString; typedef void function(void*, wchar*) pf_sfPacket_ReadWideString;
typedef void function(void*, byte) pf_sfPacket_WriteInt8; typedef void function(void*, byte) pf_sfPacket_WriteInt8;
typedef void function(void*, ubyte) pf_sfPacket_WriteUint8; typedef void function(void*, ubyte) pf_sfPacket_WriteUint8;
typedef void function(void*, short) pf_sfPacket_WriteInt16; typedef void function(void*, short) pf_sfPacket_WriteInt16;
typedef void function(void*, ushort) pf_sfPacket_WriteUint16; typedef void function(void*, ushort) pf_sfPacket_WriteUint16;
typedef void function(void*, int) pf_sfPacket_WriteInt32; typedef void function(void*, int) pf_sfPacket_WriteInt32;
typedef void function(void*, uint) pf_sfPacket_WriteUint32; typedef void function(void*, uint) pf_sfPacket_WriteUint32;
typedef void function(void*, float) pf_sfPacket_WriteFloat; typedef void function(void*, float) pf_sfPacket_WriteFloat;
typedef void function(void*, double) pf_sfPacket_WriteDouble; typedef void function(void*, double) pf_sfPacket_WriteDouble;
typedef void function(void*, char*) pf_sfPacket_WriteString; typedef void function(void*, char*) pf_sfPacket_WriteString;
typedef void function(void*, wchar*) pf_sfPacket_WriteWideString; typedef void function(void*, wchar*) pf_sfPacket_WriteWideString;
static pf_sfPacket_Create sfPacket_Create; static pf_sfPacket_Create sfPacket_Create;
static pf_sfPacket_Destroy sfPacket_Destroy; static pf_sfPacket_Destroy sfPacket_Destroy;
static pf_sfPacket_Append sfPacket_Append; static pf_sfPacket_Append sfPacket_Append;
static pf_sfPacket_Clear sfPacket_Clear; static pf_sfPacket_Clear sfPacket_Clear;
static pf_sfPacket_GetData sfPacket_GetData; static pf_sfPacket_GetData sfPacket_GetData;
static pf_sfPacket_GetDataSize sfPacket_GetDataSize; static pf_sfPacket_GetDataSize sfPacket_GetDataSize;
static pf_sfPacket_EndOfPacket sfPacket_EndOfPacket; static pf_sfPacket_EndOfPacket sfPacket_EndOfPacket;
static pf_sfPacket_CanRead sfPacket_CanRead; static pf_sfPacket_CanRead sfPacket_CanRead;
static pf_sfPacket_ReadInt8 sfPacket_ReadInt8; static pf_sfPacket_ReadInt8 sfPacket_ReadInt8;
static pf_sfPacket_ReadUint8 sfPacket_ReadUint8; static pf_sfPacket_ReadUint8 sfPacket_ReadUint8;
static pf_sfPacket_ReadInt16 sfPacket_ReadInt16; static pf_sfPacket_ReadInt16 sfPacket_ReadInt16;
static pf_sfPacket_ReadUint16 sfPacket_ReadUint16; static pf_sfPacket_ReadUint16 sfPacket_ReadUint16;
static pf_sfPacket_ReadInt32 sfPacket_ReadInt32; static pf_sfPacket_ReadInt32 sfPacket_ReadInt32;
static pf_sfPacket_ReadUint32 sfPacket_ReadUint32; static pf_sfPacket_ReadUint32 sfPacket_ReadUint32;
static pf_sfPacket_ReadFloat sfPacket_ReadFloat; static pf_sfPacket_ReadFloat sfPacket_ReadFloat;
static pf_sfPacket_ReadDouble sfPacket_ReadDouble; static pf_sfPacket_ReadDouble sfPacket_ReadDouble;
static pf_sfPacket_ReadString sfPacket_ReadString; static pf_sfPacket_ReadString sfPacket_ReadString;
static pf_sfPacket_ReadWideString sfPacket_ReadWideString; static pf_sfPacket_ReadWideString sfPacket_ReadWideString;
static pf_sfPacket_WriteInt8 sfPacket_WriteInt8; static pf_sfPacket_WriteInt8 sfPacket_WriteInt8;
static pf_sfPacket_WriteUint8 sfPacket_WriteUint8; static pf_sfPacket_WriteUint8 sfPacket_WriteUint8;
static pf_sfPacket_WriteInt16 sfPacket_WriteInt16; static pf_sfPacket_WriteInt16 sfPacket_WriteInt16;
static pf_sfPacket_WriteUint16 sfPacket_WriteUint16; static pf_sfPacket_WriteUint16 sfPacket_WriteUint16;
static pf_sfPacket_WriteInt32 sfPacket_WriteInt32; static pf_sfPacket_WriteInt32 sfPacket_WriteInt32;
static pf_sfPacket_WriteUint32 sfPacket_WriteUint32; static pf_sfPacket_WriteUint32 sfPacket_WriteUint32;
static pf_sfPacket_WriteFloat sfPacket_WriteFloat; static pf_sfPacket_WriteFloat sfPacket_WriteFloat;
static pf_sfPacket_WriteDouble sfPacket_WriteDouble; static pf_sfPacket_WriteDouble sfPacket_WriteDouble;
static pf_sfPacket_WriteString sfPacket_WriteString; static pf_sfPacket_WriteString sfPacket_WriteString;
static pf_sfPacket_WriteWideString sfPacket_WriteWideString; static pf_sfPacket_WriteWideString sfPacket_WriteWideString;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-network-d"); DllLoader dll = DllLoader.load("csfml-network-d");
else else
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfPacket_Append = cast(pf_sfPacket_Append)dll.getSymbol("sfPacket_Append"); sfPacket_Append = cast(pf_sfPacket_Append)dll.getSymbol("sfPacket_Append");
sfPacket_CanRead = cast(pf_sfPacket_CanRead)dll.getSymbol("sfPacket_CanRead"); sfPacket_CanRead = cast(pf_sfPacket_CanRead)dll.getSymbol("sfPacket_CanRead");
sfPacket_Clear = cast(pf_sfPacket_Clear)dll.getSymbol("sfPacket_Clear"); sfPacket_Clear = cast(pf_sfPacket_Clear)dll.getSymbol("sfPacket_Clear");
sfPacket_Create = cast(pf_sfPacket_Create)dll.getSymbol("sfPacket_Create"); sfPacket_Create = cast(pf_sfPacket_Create)dll.getSymbol("sfPacket_Create");
sfPacket_Destroy = cast(pf_sfPacket_Destroy)dll.getSymbol("sfPacket_Destroy"); sfPacket_Destroy = cast(pf_sfPacket_Destroy)dll.getSymbol("sfPacket_Destroy");
sfPacket_EndOfPacket = cast(pf_sfPacket_EndOfPacket)dll.getSymbol("sfPacket_EndOfPacket"); sfPacket_EndOfPacket = cast(pf_sfPacket_EndOfPacket)dll.getSymbol("sfPacket_EndOfPacket");
sfPacket_GetData = cast(pf_sfPacket_GetData)dll.getSymbol("sfPacket_GetData"); sfPacket_GetData = cast(pf_sfPacket_GetData)dll.getSymbol("sfPacket_GetData");
sfPacket_GetDataSize = cast(pf_sfPacket_GetDataSize)dll.getSymbol("sfPacket_GetDataSize"); sfPacket_GetDataSize = cast(pf_sfPacket_GetDataSize)dll.getSymbol("sfPacket_GetDataSize");
sfPacket_ReadDouble = cast(pf_sfPacket_ReadDouble)dll.getSymbol("sfPacket_ReadDouble"); sfPacket_ReadDouble = cast(pf_sfPacket_ReadDouble)dll.getSymbol("sfPacket_ReadDouble");
sfPacket_ReadFloat = cast(pf_sfPacket_ReadFloat)dll.getSymbol("sfPacket_ReadFloat"); sfPacket_ReadFloat = cast(pf_sfPacket_ReadFloat)dll.getSymbol("sfPacket_ReadFloat");
sfPacket_ReadInt16 = cast(pf_sfPacket_ReadInt16)dll.getSymbol("sfPacket_ReadInt16"); sfPacket_ReadInt16 = cast(pf_sfPacket_ReadInt16)dll.getSymbol("sfPacket_ReadInt16");
sfPacket_ReadInt32 = cast(pf_sfPacket_ReadInt32)dll.getSymbol("sfPacket_ReadInt32"); sfPacket_ReadInt32 = cast(pf_sfPacket_ReadInt32)dll.getSymbol("sfPacket_ReadInt32");
sfPacket_ReadInt8 = cast(pf_sfPacket_ReadInt8)dll.getSymbol("sfPacket_ReadInt8"); sfPacket_ReadInt8 = cast(pf_sfPacket_ReadInt8)dll.getSymbol("sfPacket_ReadInt8");
sfPacket_ReadString = cast(pf_sfPacket_ReadString)dll.getSymbol("sfPacket_ReadString"); sfPacket_ReadString = cast(pf_sfPacket_ReadString)dll.getSymbol("sfPacket_ReadString");
sfPacket_ReadWideString = cast(pf_sfPacket_ReadWideString)dll.getSymbol("sfPacket_ReadWideString"); sfPacket_ReadWideString = cast(pf_sfPacket_ReadWideString)dll.getSymbol("sfPacket_ReadWideString");
sfPacket_ReadUint16 = cast(pf_sfPacket_ReadUint16)dll.getSymbol("sfPacket_ReadUint16"); sfPacket_ReadUint16 = cast(pf_sfPacket_ReadUint16)dll.getSymbol("sfPacket_ReadUint16");
sfPacket_ReadUint32 = cast(pf_sfPacket_ReadUint32)dll.getSymbol("sfPacket_ReadUint32"); sfPacket_ReadUint32 = cast(pf_sfPacket_ReadUint32)dll.getSymbol("sfPacket_ReadUint32");
sfPacket_ReadUint8 = cast(pf_sfPacket_ReadUint8)dll.getSymbol("sfPacket_ReadUint8"); sfPacket_ReadUint8 = cast(pf_sfPacket_ReadUint8)dll.getSymbol("sfPacket_ReadUint8");
sfPacket_WriteDouble = cast(pf_sfPacket_WriteDouble)dll.getSymbol("sfPacket_WriteDouble"); sfPacket_WriteDouble = cast(pf_sfPacket_WriteDouble)dll.getSymbol("sfPacket_WriteDouble");
sfPacket_WriteFloat = cast(pf_sfPacket_WriteFloat)dll.getSymbol("sfPacket_WriteFloat"); sfPacket_WriteFloat = cast(pf_sfPacket_WriteFloat)dll.getSymbol("sfPacket_WriteFloat");
sfPacket_WriteInt16 = cast(pf_sfPacket_WriteInt16)dll.getSymbol("sfPacket_WriteInt16"); sfPacket_WriteInt16 = cast(pf_sfPacket_WriteInt16)dll.getSymbol("sfPacket_WriteInt16");
sfPacket_WriteInt32 = cast(pf_sfPacket_WriteInt32)dll.getSymbol("sfPacket_WriteInt32"); sfPacket_WriteInt32 = cast(pf_sfPacket_WriteInt32)dll.getSymbol("sfPacket_WriteInt32");
sfPacket_WriteInt8 = cast(pf_sfPacket_WriteInt8)dll.getSymbol("sfPacket_WriteInt8"); sfPacket_WriteInt8 = cast(pf_sfPacket_WriteInt8)dll.getSymbol("sfPacket_WriteInt8");
sfPacket_WriteString = cast(pf_sfPacket_WriteString)dll.getSymbol("sfPacket_WriteString"); sfPacket_WriteString = cast(pf_sfPacket_WriteString)dll.getSymbol("sfPacket_WriteString");
sfPacket_WriteWideString = cast(pf_sfPacket_WriteWideString)dll.getSymbol("sfPacket_WriteWideString"); sfPacket_WriteWideString = cast(pf_sfPacket_WriteWideString)dll.getSymbol("sfPacket_WriteWideString");
sfPacket_WriteUint16 = cast(pf_sfPacket_WriteUint16)dll.getSymbol("sfPacket_WriteUint16"); sfPacket_WriteUint16 = cast(pf_sfPacket_WriteUint16)dll.getSymbol("sfPacket_WriteUint16");
sfPacket_WriteUint32 = cast(pf_sfPacket_WriteUint32)dll.getSymbol("sfPacket_WriteUint32"); sfPacket_WriteUint32 = cast(pf_sfPacket_WriteUint32)dll.getSymbol("sfPacket_WriteUint32");
sfPacket_WriteUint8 = cast(pf_sfPacket_WriteUint8)dll.getSymbol("sfPacket_WriteUint8"); sfPacket_WriteUint8 = cast(pf_sfPacket_WriteUint8)dll.getSymbol("sfPacket_WriteUint8");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.selector; module dsfml.network.selector;
@ -38,152 +38,152 @@ import dsfml.system.common;
*/ */
class Selector(T) : DSFMLObject class Selector(T) : DSFMLObject
{ {
//Ensure type is correct //Ensure type is correct
static if (!is(T : SocketTCP) && !is(T : SocketUDP)) static if (!is(T : SocketTCP) && !is(T : SocketUDP))
static assert("Only SocketTCP and SocketUDP are valid for Selector."); static assert("Only SocketTCP and SocketUDP are valid for Selector.");
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
super(sfSelector_Create()); super(sfSelector_Create());
} }
override void dispose() override void dispose()
{ {
sfSelector_Destroy(m_ptr); sfSelector_Destroy(m_ptr);
} }
/** /**
* Add a socket to watch * Add a socket to watch
* *
* Params: * Params:
* socket = A tcp or udp socket * socket = A tcp or udp socket
*/ */
void add(T socket) void add(T socket)
{ {
if (!(socket.getNativePointer in m_watchedSockets)) if (!(socket.getNativePointer in m_watchedSockets))
{ {
sfSelector_Add(m_ptr, socket.getNativePointer); sfSelector_Add(m_ptr, socket.getNativePointer);
m_watchedSockets[socket.getNativePointer] = socket; m_watchedSockets[socket.getNativePointer] = socket;
m_numSocketsWatched++; m_numSocketsWatched++;
} }
} }
/** /**
* Remove a previously added socket * Remove a previously added socket
* *
* Params: * Params:
* socket = A tcp or udp socket * socket = A tcp or udp socket
*/ */
void remove(T socket) void remove(T socket)
{ {
if (socket.getNativePointer in m_watchedSockets) if (socket.getNativePointer in m_watchedSockets)
{ {
sfSelector_Remove(m_ptr, socket.getNativePointer); sfSelector_Remove(m_ptr, socket.getNativePointer);
m_watchedSockets.remove(socket.getNativePointer); m_watchedSockets.remove(socket.getNativePointer);
m_numSocketsWatched--; m_numSocketsWatched--;
} }
} }
/** /**
* Clear all sockets being watched * Clear all sockets being watched
*/ */
void clear() void clear()
{ {
sfSelector_Clear(m_ptr); sfSelector_Clear(m_ptr);
foreach(key; m_watchedSockets.keys) foreach(key; m_watchedSockets.keys)
m_watchedSockets.remove(key); m_watchedSockets.remove(key);
m_numSocketsWatched = 0; m_numSocketsWatched = 0;
} }
/** /**
* Wait and collect sockets which are ready for reading. * Wait and collect sockets which are ready for reading.
* This functions will return either when at least one socket * This functions will return either when at least one socket
* is ready, or when the given time is out * is ready, or when the given time is out
* *
* Params: * Params:
* timeout = Maximum time to wait, in seconds (0 to disable timeout) * timeout = Maximum time to wait, in seconds (0 to disable timeout)
* *
* Returns: * Returns:
* Number of sockets ready * Number of sockets ready
*/ */
uint wait(float timeout = 0.f) uint wait(float timeout = 0.f)
{ {
return sfSelector_Wait(m_ptr, timeout); return sfSelector_Wait(m_ptr, timeout);
} }
/** /**
* After a call to Wait(), get the Index-th socket which is * After a call to Wait(), get the Index-th socket which is
* ready for reading. The total number of sockets ready * ready for reading. The total number of sockets ready
* is the integer returned by the previous call to Wait() * is the integer returned by the previous call to Wait()
* *
* Params: * Params:
* index = Index of the socket to get * index = Index of the socket to get
* *
* Returns: * Returns:
* The Index-th socket * The Index-th socket
*/ */
T GetSocketsReady(uint index) T GetSocketsReady(uint index)
{ {
return m_watchedSockets[sfSelector_GetSocketReady(m_ptr, index)]; return m_watchedSockets[sfSelector_GetSocketReady(m_ptr, index)];
} }
private: private:
size_t m_numSocketsWatched; size_t m_numSocketsWatched;
T[void*] m_watchedSockets; T[void*] m_watchedSockets;
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfSelector_Create; typedef void* function() pf_sfSelector_Create;
typedef void function(void*) pf_sfSelector_Destroy; typedef void function(void*) pf_sfSelector_Destroy;
typedef void function(void*, void*) pf_sfSelector_Add; typedef void function(void*, void*) pf_sfSelector_Add;
typedef void function(void*, void*) pf_sfSelector_Remove; typedef void function(void*, void*) pf_sfSelector_Remove;
typedef void function(void*) pf_sfSelector_Clear; typedef void function(void*) pf_sfSelector_Clear;
typedef uint function(void*, float) pf_sfSelector_Wait; typedef uint function(void*, float) pf_sfSelector_Wait;
typedef void* function(void*, uint) pf_sfSelector_GetSocketReady; typedef void* function(void*, uint) pf_sfSelector_GetSocketReady;
static pf_sfSelector_Create sfSelector_Create; static pf_sfSelector_Create sfSelector_Create;
static pf_sfSelector_Destroy sfSelector_Destroy; static pf_sfSelector_Destroy sfSelector_Destroy;
static pf_sfSelector_Add sfSelector_Add; static pf_sfSelector_Add sfSelector_Add;
static pf_sfSelector_Remove sfSelector_Remove; static pf_sfSelector_Remove sfSelector_Remove;
static pf_sfSelector_Clear sfSelector_Clear; static pf_sfSelector_Clear sfSelector_Clear;
static pf_sfSelector_Wait sfSelector_Wait; static pf_sfSelector_Wait sfSelector_Wait;
static pf_sfSelector_GetSocketReady sfSelector_GetSocketReady; static pf_sfSelector_GetSocketReady sfSelector_GetSocketReady;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-network-d"); DllLoader dll = DllLoader.load("csfml-network-d");
else else
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
static if (is (T : SocketTCP)) static if (is (T : SocketTCP))
{ {
string symbol = "sfSelectorTCP"; string symbol = "sfSelectorTCP";
} }
else static if (is (T : SocketUDP)) else static if (is (T : SocketUDP))
{ {
string symbol = "sfSelectorUDP"; string symbol = "sfSelectorUDP";
} }
sfSelector_Add = cast(pf_sfSelector_Add)dll.getSymbol(symbol ~ "_Add"); sfSelector_Add = cast(pf_sfSelector_Add)dll.getSymbol(symbol ~ "_Add");
sfSelector_Clear = cast(pf_sfSelector_Clear)dll.getSymbol(symbol ~ "_Clear"); sfSelector_Clear = cast(pf_sfSelector_Clear)dll.getSymbol(symbol ~ "_Clear");
sfSelector_Create = cast(pf_sfSelector_Create)dll.getSymbol(symbol ~ "_Create"); sfSelector_Create = cast(pf_sfSelector_Create)dll.getSymbol(symbol ~ "_Create");
sfSelector_Destroy = cast(pf_sfSelector_Destroy)dll.getSymbol(symbol ~ "_Destroy"); sfSelector_Destroy = cast(pf_sfSelector_Destroy)dll.getSymbol(symbol ~ "_Destroy");
sfSelector_GetSocketReady = cast(pf_sfSelector_GetSocketReady)dll.getSymbol(symbol ~ "_GetSocketReady"); sfSelector_GetSocketReady = cast(pf_sfSelector_GetSocketReady)dll.getSymbol(symbol ~ "_GetSocketReady");
sfSelector_Wait = cast(pf_sfSelector_Wait)dll.getSymbol(symbol ~ "_Wait"); sfSelector_Wait = cast(pf_sfSelector_Wait)dll.getSymbol(symbol ~ "_Wait");
sfSelector_Remove = cast(pf_sfSelector_Remove)dll.getSymbol(symbol ~ "_Remove"); sfSelector_Remove = cast(pf_sfSelector_Remove)dll.getSymbol(symbol ~ "_Remove");
} }
} }
/** /**
* alias of selector for TCP or UDP Socket. * alias of selector for TCP or UDP Socket.
*/ */
alias Selector!(SocketTCP) SelectorTCP; alias Selector!(SocketTCP) SelectorTCP;
/// ditto /// ditto

View file

@ -1,38 +1,38 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.socketstatus; module dsfml.network.socketstatus;
/** /**
* Enumeration of status returned by socket functions * Enumeration of status returned by socket functions
*/ */
enum SocketStatus enum SocketStatus
{ {
DONE, /// DONE, ///
NOTREADY, /// NOTREADY, ///
DISCONNECTED, /// DISCONNECTED, ///
UNEXPECTEDERROR /// UNEXPECTEDERROR ///
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.sockettcp; module dsfml.network.sockettcp;
@ -33,240 +33,240 @@ import dsfml.network.socketstatus;
import dsfml.system.common; import dsfml.system.common;
/** /**
* SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower) * SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower)
*/ */
class SocketTCP : DSFMLObject class SocketTCP : DSFMLObject
{ {
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
super(sfSocketTCP_Create()); super(sfSocketTCP_Create());
m_intermediatePacket = new Packet(); m_intermediatePacket = new Packet();
} }
override void dispose() override void dispose()
{ {
sfSocketTCP_Destroy(m_ptr); sfSocketTCP_Destroy(m_ptr);
} }
/** /**
* Connect to another computer on a specified port * Connect to another computer on a specified port
* *
* Params: * Params:
* port = Port to use for transfers (warning : ports < 1024 are reserved) * port = Port to use for transfers (warning : ports < 1024 are reserved)
* hostAddress = IP Address of the host to connect to * hostAddress = IP Address of the host to connect to
* timeout = Maximum time to wait in seconds (0 by default : no timeout) * timeout = Maximum time to wait in seconds (0 by default : no timeout)
* *
* Returns: * Returns:
* True if operation has been successful * True if operation has been successful
*/ */
bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f) bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f)
{ {
return cast(bool) !sfSocketTCP_Connect(m_ptr, port, hostAddress, timeout); return cast(bool) !sfSocketTCP_Connect(m_ptr, port, hostAddress, timeout);
} }
/** /**
* Listen to a specified port for incoming data or connections * Listen to a specified port for incoming data or connections
* *
* Params: * Params:
* port = Port to listen to * port = Port to listen to
* *
* Returns: * Returns:
* True if operation has been successful * True if operation has been successful
*/ */
bool listen(ushort port) bool listen(ushort port)
{ {
return cast(bool)sfSocketTCP_Listen(m_ptr, port); return cast(bool)sfSocketTCP_Listen(m_ptr, port);
} }
/** /**
* Wait for a connection (must be listening to a port). * Wait for a connection (must be listening to a port).
* This function is blocking. * This function is blocking.
* *
* Params: * Params:
* connected = Socket containing the connection with the connected client * connected = Socket containing the connection with the connected client
* *
* Returns: * Returns:
* Status code * Status code
*/ */
SocketStatus accept(SocketTCP connected) SocketStatus accept(SocketTCP connected)
{ {
void* temp = null; void* temp = null;
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, null); SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, null);
connected.m_ptr = temp; connected.m_ptr = temp;
return ret; return ret;
} }
/** /**
* Wait for a connection (must be listening to a port). * Wait for a connection (must be listening to a port).
* This function is blocking. * This function is blocking.
* *
* Params: * Params:
* connected = Socket containing the connection with the connected client * connected = Socket containing the connection with the connected client
* address = Pointer to an address to fill with client infos * address = Pointer to an address to fill with client infos
* *
* Returns: * Returns:
* Status code * Status code
*/ */
SocketStatus accept(SocketTCP connected, out IPAddress address) SocketStatus accept(SocketTCP connected, out IPAddress address)
{ {
void* temp = null; void* temp = null;
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, &address); SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, &address);
connected.m_ptr = temp; connected.m_ptr = temp;
return ret; return ret;
} }
/** /**
* Send an array of bytes to the host (must be connected first) * Send an array of bytes to the host (must be connected first)
* *
* Params: * Params:
* data = array of bytes to send * data = array of bytes to send
* *
* Returns: * Returns:
* Status code * Status code
*/ */
SocketStatus send(byte[] data) SocketStatus send(byte[] data)
{ {
if (data && data.length > 0) if (data && data.length > 0)
return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length); return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length);
} }
/** /**
* Receive an array of bytes from the host (must be connected first). * Receive an array of bytes from the host (must be connected first).
* This function will block until a connection was accepted * This function will block until a connection was accepted
* *
* Params: * Params:
* data = array to fill (make sure it is big enough) * data = array to fill (make sure it is big enough)
* sizeReceived = Number of bytes received * sizeReceived = Number of bytes received
* *
* Returns: * Returns:
* Status code * Status code
* *
* Remarks: * Remarks:
* Assert if data is null or length == 0 * Assert if data is null or length == 0
* *
*/ */
SocketStatus receive(byte[] data, out size_t sizeReceived) SocketStatus receive(byte[] data, out size_t sizeReceived)
{ {
if (data && data.length > 0) if (data && data.length > 0)
return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived); return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
} }
/** /**
* Send a packet of data to the host (must be connected first) * Send a packet of data to the host (must be connected first)
* *
* Params: * Params:
* packetToSend = Packet to send * packetToSend = Packet to send
* *
* Returns: * Returns:
* Status code * Status code
* *
*/ */
SocketStatus send(Packet packetToSend) SocketStatus send(Packet packetToSend)
{ {
byte[] dataArray = packetToSend.onSend(); byte[] dataArray = packetToSend.onSend();
m_intermediatePacket.append(dataArray); m_intermediatePacket.append(dataArray);
SocketStatus stat = cast(SocketStatus)sfSocketTCP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer); SocketStatus stat = cast(SocketStatus)sfSocketTCP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer);
m_intermediatePacket.clear(); m_intermediatePacket.clear();
return stat; return stat;
} }
/** /**
* Receive a packet from the host (must be connected first). * Receive a packet from the host (must be connected first).
* This function will block if the socket is blocking * This function will block if the socket is blocking
* *
* Params: * Params:
* packetToReceive = Packet to fill with received data * packetToReceive = Packet to fill with received data
* *
* Returns: * Returns:
* Status code * Status code
* *
*/ */
SocketStatus receive(Packet packetToReceive) SocketStatus receive(Packet packetToReceive)
{ {
SocketStatus stat = cast(SocketStatus)sfSocketTCP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer); SocketStatus stat = cast(SocketStatus)sfSocketTCP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer);
packetToReceive.onReceive(m_intermediatePacket.getData); packetToReceive.onReceive(m_intermediatePacket.getData);
m_intermediatePacket.clear(); m_intermediatePacket.clear();
return stat; return stat;
} }
/** /**
* Check if the socket is in a valid state ; this function * Check if the socket is in a valid state ; this function
* can be called any time to check if the socket is OK * can be called any time to check if the socket is OK
* *
* Returns: * Returns:
* True if the socket is valid * True if the socket is valid
* *
*/ */
bool isValid() bool isValid()
{ {
return cast(bool)sfSocketTCP_IsValid(m_ptr); return cast(bool)sfSocketTCP_IsValid(m_ptr);
} }
/// ///
bool opEquals(SocketTCP other) bool opEquals(SocketTCP other)
{ {
return (other.getNativePointer == this.getNativePointer); return (other.getNativePointer == this.getNativePointer);
} }
package: package:
this (void* ptr) this (void* ptr)
{ {
super(ptr); super(ptr);
m_intermediatePacket = new Packet(); m_intermediatePacket = new Packet();
} }
private: private:
Packet m_intermediatePacket; Packet m_intermediatePacket;
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfSocketTCP_Create; typedef void* function() pf_sfSocketTCP_Create;
typedef void function(void*) pf_sfSocketTCP_Destroy; typedef void function(void*) pf_sfSocketTCP_Destroy;
typedef int function(void*, ushort, IPAddress, float) pf_sfSocketTCP_Connect; typedef int function(void*, ushort, IPAddress, float) pf_sfSocketTCP_Connect;
typedef int function(void*, ushort) pf_sfSocketTCP_Listen; typedef int function(void*, ushort) pf_sfSocketTCP_Listen;
typedef SocketStatus function(void*, void**, IPAddress*) pf_sfSocketTCP_Accept; typedef SocketStatus function(void*, void**, IPAddress*) pf_sfSocketTCP_Accept;
typedef SocketStatus function(void*, byte*, size_t) pf_sfSocketTCP_Send; typedef SocketStatus function(void*, byte*, size_t) pf_sfSocketTCP_Send;
typedef SocketStatus function(void*, byte*, size_t, size_t*) pf_sfSocketTCP_Receive; typedef SocketStatus function(void*, byte*, size_t, size_t*) pf_sfSocketTCP_Receive;
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_SendPacket; typedef SocketStatus function(void*, void*) pf_sfSocketTCP_SendPacket;
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_ReceivePacket; typedef SocketStatus function(void*, void*) pf_sfSocketTCP_ReceivePacket;
typedef int function(void*) pf_sfSocketTCP_IsValid; typedef int function(void*) pf_sfSocketTCP_IsValid;
static pf_sfSocketTCP_Create sfSocketTCP_Create; static pf_sfSocketTCP_Create sfSocketTCP_Create;
static pf_sfSocketTCP_Destroy sfSocketTCP_Destroy; static pf_sfSocketTCP_Destroy sfSocketTCP_Destroy;
static pf_sfSocketTCP_Connect sfSocketTCP_Connect; static pf_sfSocketTCP_Connect sfSocketTCP_Connect;
static pf_sfSocketTCP_Listen sfSocketTCP_Listen; static pf_sfSocketTCP_Listen sfSocketTCP_Listen;
static pf_sfSocketTCP_Accept sfSocketTCP_Accept; static pf_sfSocketTCP_Accept sfSocketTCP_Accept;
static pf_sfSocketTCP_Send sfSocketTCP_Send; static pf_sfSocketTCP_Send sfSocketTCP_Send;
static pf_sfSocketTCP_Receive sfSocketTCP_Receive; static pf_sfSocketTCP_Receive sfSocketTCP_Receive;
static pf_sfSocketTCP_SendPacket sfSocketTCP_SendPacket; static pf_sfSocketTCP_SendPacket sfSocketTCP_SendPacket;
static pf_sfSocketTCP_ReceivePacket sfSocketTCP_ReceivePacket; static pf_sfSocketTCP_ReceivePacket sfSocketTCP_ReceivePacket;
static pf_sfSocketTCP_IsValid sfSocketTCP_IsValid; static pf_sfSocketTCP_IsValid sfSocketTCP_IsValid;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-network-d"); DllLoader dll = DllLoader.load("csfml-network-d");
else else
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfSocketTCP_Accept = cast(pf_sfSocketTCP_Accept)dll.getSymbol("sfSocketTCP_Accept"); sfSocketTCP_Accept = cast(pf_sfSocketTCP_Accept)dll.getSymbol("sfSocketTCP_Accept");
sfSocketTCP_Connect = cast(pf_sfSocketTCP_Connect)dll.getSymbol("sfSocketTCP_Connect"); sfSocketTCP_Connect = cast(pf_sfSocketTCP_Connect)dll.getSymbol("sfSocketTCP_Connect");
sfSocketTCP_Create = cast(pf_sfSocketTCP_Create)dll.getSymbol("sfSocketTCP_Create"); sfSocketTCP_Create = cast(pf_sfSocketTCP_Create)dll.getSymbol("sfSocketTCP_Create");
sfSocketTCP_Destroy = cast(pf_sfSocketTCP_Destroy)dll.getSymbol("sfSocketTCP_Destroy"); sfSocketTCP_Destroy = cast(pf_sfSocketTCP_Destroy)dll.getSymbol("sfSocketTCP_Destroy");
sfSocketTCP_IsValid = cast(pf_sfSocketTCP_IsValid)dll.getSymbol("sfSocketTCP_IsValid"); sfSocketTCP_IsValid = cast(pf_sfSocketTCP_IsValid)dll.getSymbol("sfSocketTCP_IsValid");
sfSocketTCP_Listen = cast(pf_sfSocketTCP_Listen)dll.getSymbol("sfSocketTCP_Listen"); sfSocketTCP_Listen = cast(pf_sfSocketTCP_Listen)dll.getSymbol("sfSocketTCP_Listen");
sfSocketTCP_Receive = cast(pf_sfSocketTCP_Receive)dll.getSymbol("sfSocketTCP_Receive"); sfSocketTCP_Receive = cast(pf_sfSocketTCP_Receive)dll.getSymbol("sfSocketTCP_Receive");
sfSocketTCP_ReceivePacket = cast(pf_sfSocketTCP_ReceivePacket)dll.getSymbol("sfSocketTCP_ReceivePacket"); sfSocketTCP_ReceivePacket = cast(pf_sfSocketTCP_ReceivePacket)dll.getSymbol("sfSocketTCP_ReceivePacket");
sfSocketTCP_Send = cast(pf_sfSocketTCP_Send)dll.getSymbol("sfSocketTCP_Send"); sfSocketTCP_Send = cast(pf_sfSocketTCP_Send)dll.getSymbol("sfSocketTCP_Send");
sfSocketTCP_SendPacket = cast(pf_sfSocketTCP_SendPacket)dll.getSymbol("sfSocketTCP_SendPacket"); sfSocketTCP_SendPacket = cast(pf_sfSocketTCP_SendPacket)dll.getSymbol("sfSocketTCP_SendPacket");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.network.socketudp; module dsfml.network.socketudp;
@ -33,126 +33,126 @@ import dsfml.network.socketstatus;
import dsfml.system.common; import dsfml.system.common;
/** /**
* SocketUDP wraps a socket using UDP protocol to * SocketUDP wraps a socket using UDP protocol to
* send data fastly (but with less safety) * send data fastly (but with less safety)
*/ */
class SocketUDP : DSFMLObject class SocketUDP : DSFMLObject
{ {
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
super(sfSocketUDP_Create()); super(sfSocketUDP_Create());
m_intermediatePacket = new Packet(); m_intermediatePacket = new Packet();
} }
override void dispose() override void dispose()
{ {
sfSocketUDP_Destroy(m_ptr); sfSocketUDP_Destroy(m_ptr);
} }
/** /**
* Bind the socket to a specific port * Bind the socket to a specific port
* *
* Params: * Params:
* port = Port to bind the socket to * port = Port to bind the socket to
* *
* Returns: * Returns:
* True if operation has been successful * True if operation has been successful
* *
*/ */
bool bind(ushort port) bool bind(ushort port)
{ {
m_port = port; m_port = port;
return cast(bool)sfSocketUDP_Bind(m_ptr, port); return cast(bool)sfSocketUDP_Bind(m_ptr, port);
} }
/** /**
* Unbind the socket from its previous port, if any * Unbind the socket from its previous port, if any
* *
* Returns: True if operation has been successful * Returns: True if operation has been successful
* *
*/ */
bool unbind() bool unbind()
{ {
m_port = 0; m_port = 0;
return cast(bool)sfSocketUDP_Unbind(m_ptr, m_port); return cast(bool)sfSocketUDP_Unbind(m_ptr, m_port);
} }
/** /**
* Send an array of bytes * Send an array of bytes
* *
* Params: * Params:
* data = bytes array to send * data = bytes array to send
* address = Address of the computer to send the packet to * address = Address of the computer to send the packet to
* port = Port to send the data to * port = Port to send the data to
* *
* Returns: * Returns:
* Status code * Status code
* *
*/ */
SocketStatus send(byte[] data, IPAddress address, ushort port) SocketStatus send(byte[] data, IPAddress address, ushort port)
{ {
return cast(SocketStatus) sfSocketUDP_Send(m_ptr, data.ptr, data.length, address, port); return cast(SocketStatus) sfSocketUDP_Send(m_ptr, data.ptr, data.length, address, port);
} }
/** /**
* Receive an array of bytes. * Receive an array of bytes.
* This function is blocking. * This function is blocking.
* *
* Params: * Params:
* data = Pointer to a byte array to fill (make sure it is big enough) * data = Pointer to a byte array to fill (make sure it is big enough)
* sizeReceived = Number of bytes received * sizeReceived = Number of bytes received
* address = Address of the computer which sent the data * address = Address of the computer which sent the data
* *
* Returns: * Returns:
* Status code * Status code
* *
* Remarks: * Remarks:
* Assert if data is null or length == 0 * Assert if data is null or length == 0
* *
*/ */
SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address) SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address)
{ {
SocketStatus ret = sfSocketUDP_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address); SocketStatus ret = sfSocketUDP_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address);
return ret; return ret;
} }
/** /**
* Send a packet of data * Send a packet of data
* *
* Params: * Params:
* packetToSend = Packet to send * packetToSend = Packet to send
* address = Address of the computer to send the packet to * address = Address of the computer to send the packet to
* port = Port to send the data to * port = Port to send the data to
* *
* Returns: * Returns:
* Status code * Status code
* *
*/ */
SocketStatus send(Packet packetToSend, IPAddress address, ushort port) SocketStatus send(Packet packetToSend, IPAddress address, ushort port)
{ {
byte[] dataArray = packetToSend.onSend(); byte[] dataArray = packetToSend.onSend();
m_intermediatePacket.append(dataArray); m_intermediatePacket.append(dataArray);
SocketStatus stat = cast(SocketStatus)sfSocketUDP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer, address, port); SocketStatus stat = cast(SocketStatus)sfSocketUDP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer, address, port);
m_intermediatePacket.clear(); m_intermediatePacket.clear();
return stat; return stat;
} }
/** /**
* Receive a packet. * Receive a packet.
* This function is blocking. * This function is blocking.
* *
* Params: * Params:
* packetToReceive = Packet to fill with received data * packetToReceive = Packet to fill with received data
* address = Address of the computer which sent the packet * address = Address of the computer which sent the packet
* *
* Returns: * Returns:
* Status code * Status code
* *
*/ */
SocketStatus receive(Packet packetToReceive, out IPAddress address) SocketStatus receive(Packet packetToReceive, out IPAddress address)
{ {
SocketStatus ret = sfSocketUDP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer, &address); SocketStatus ret = sfSocketUDP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer, &address);
packetToReceive.onReceive(m_intermediatePacket.getData); packetToReceive.onReceive(m_intermediatePacket.getData);
@ -161,87 +161,87 @@ class SocketUDP : DSFMLObject
} }
/** /**
* Check if the socket is in a valid state ; this function * Check if the socket is in a valid state ; this function
* can be called any time to check if the socket is OK * can be called any time to check if the socket is OK
* *
* Returns: * Returns:
* True if the socket is valid * True if the socket is valid
* *
*/ */
bool isValid() bool isValid()
{ {
return cast(bool)sfSocketUDP_IsValid(m_ptr); return cast(bool)sfSocketUDP_IsValid(m_ptr);
} }
/** /**
* Get the port the socket is currently bound to * Get the port the socket is currently bound to
* *
* Returns: * Returns:
* Current port (0 means the socket is not bound) * Current port (0 means the socket is not bound)
*/ */
ushort getPort() ushort getPort()
{ {
return m_port; return m_port;
} }
/// ///
bool opEquals(SocketUDP other) bool opEquals(SocketUDP other)
{ {
return (other.getNativePointer == this.getNativePointer); return (other.getNativePointer == this.getNativePointer);
} }
package: package:
this (void* ptr) this (void* ptr)
{ {
super(ptr); super(ptr);
m_intermediatePacket = new Packet(); m_intermediatePacket = new Packet();
} }
private: private:
Packet m_intermediatePacket; Packet m_intermediatePacket;
ushort m_port; ushort m_port;
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfSocketUDP_Create; typedef void* function() pf_sfSocketUDP_Create;
typedef void function(void*) pf_sfSocketUDP_Destroy; typedef void function(void*) pf_sfSocketUDP_Destroy;
typedef int function(void*, ushort) pf_sfSocketUDP_Bind; typedef int function(void*, ushort) pf_sfSocketUDP_Bind;
typedef int function(void*, ushort) pf_sfSocketUDP_Unbind; typedef int function(void*, ushort) pf_sfSocketUDP_Unbind;
typedef SocketStatus function(void*, byte*, size_t, IPAddress, ushort) pf_sfSocketUDP_Send; typedef SocketStatus function(void*, byte*, size_t, IPAddress, ushort) pf_sfSocketUDP_Send;
typedef SocketStatus function(void*, byte*, size_t, size_t*, IPAddress*) pf_sfSocketUDP_Receive; typedef SocketStatus function(void*, byte*, size_t, size_t*, IPAddress*) pf_sfSocketUDP_Receive;
typedef SocketStatus function(void*, void*, IPAddress, ushort) pf_sfSocketUDP_SendPacket; typedef SocketStatus function(void*, void*, IPAddress, ushort) pf_sfSocketUDP_SendPacket;
typedef SocketStatus function(void*, void*, IPAddress*) pf_sfSocketUDP_ReceivePacket; typedef SocketStatus function(void*, void*, IPAddress*) pf_sfSocketUDP_ReceivePacket;
typedef int function(void*) pf_sfSocketUDP_IsValid; typedef int function(void*) pf_sfSocketUDP_IsValid;
static pf_sfSocketUDP_Create sfSocketUDP_Create; static pf_sfSocketUDP_Create sfSocketUDP_Create;
static pf_sfSocketUDP_Destroy sfSocketUDP_Destroy; static pf_sfSocketUDP_Destroy sfSocketUDP_Destroy;
static pf_sfSocketUDP_Bind sfSocketUDP_Bind; static pf_sfSocketUDP_Bind sfSocketUDP_Bind;
static pf_sfSocketUDP_Unbind sfSocketUDP_Unbind; static pf_sfSocketUDP_Unbind sfSocketUDP_Unbind;
static pf_sfSocketUDP_Send sfSocketUDP_Send; static pf_sfSocketUDP_Send sfSocketUDP_Send;
static pf_sfSocketUDP_Receive sfSocketUDP_Receive; static pf_sfSocketUDP_Receive sfSocketUDP_Receive;
static pf_sfSocketUDP_SendPacket sfSocketUDP_SendPacket; static pf_sfSocketUDP_SendPacket sfSocketUDP_SendPacket;
static pf_sfSocketUDP_ReceivePacket sfSocketUDP_ReceivePacket; static pf_sfSocketUDP_ReceivePacket sfSocketUDP_ReceivePacket;
static pf_sfSocketUDP_IsValid sfSocketUDP_IsValid; static pf_sfSocketUDP_IsValid sfSocketUDP_IsValid;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-network-d"); DllLoader dll = DllLoader.load("csfml-network-d");
else else
DllLoader dll = DllLoader.load("csfml-network"); DllLoader dll = DllLoader.load("csfml-network");
sfSocketUDP_Bind = cast(pf_sfSocketUDP_Bind)dll.getSymbol("sfSocketUDP_Bind"); sfSocketUDP_Bind = cast(pf_sfSocketUDP_Bind)dll.getSymbol("sfSocketUDP_Bind");
sfSocketUDP_Create = cast(pf_sfSocketUDP_Create)dll.getSymbol("sfSocketUDP_Create"); sfSocketUDP_Create = cast(pf_sfSocketUDP_Create)dll.getSymbol("sfSocketUDP_Create");
sfSocketUDP_Destroy = cast(pf_sfSocketUDP_Destroy)dll.getSymbol("sfSocketUDP_Destroy"); sfSocketUDP_Destroy = cast(pf_sfSocketUDP_Destroy)dll.getSymbol("sfSocketUDP_Destroy");
sfSocketUDP_IsValid = cast(pf_sfSocketUDP_IsValid)dll.getSymbol("sfSocketUDP_IsValid"); sfSocketUDP_IsValid = cast(pf_sfSocketUDP_IsValid)dll.getSymbol("sfSocketUDP_IsValid");
sfSocketUDP_Receive = cast(pf_sfSocketUDP_Receive)dll.getSymbol("sfSocketUDP_Receive"); sfSocketUDP_Receive = cast(pf_sfSocketUDP_Receive)dll.getSymbol("sfSocketUDP_Receive");
sfSocketUDP_ReceivePacket = cast(pf_sfSocketUDP_ReceivePacket)dll.getSymbol("sfSocketUDP_ReceivePacket"); sfSocketUDP_ReceivePacket = cast(pf_sfSocketUDP_ReceivePacket)dll.getSymbol("sfSocketUDP_ReceivePacket");
sfSocketUDP_Send = cast(pf_sfSocketUDP_Send)dll.getSymbol("sfSocketUDP_Send"); sfSocketUDP_Send = cast(pf_sfSocketUDP_Send)dll.getSymbol("sfSocketUDP_Send");
sfSocketUDP_SendPacket = cast(pf_sfSocketUDP_SendPacket)dll.getSymbol("sfSocketUDP_SendPacket"); sfSocketUDP_SendPacket = cast(pf_sfSocketUDP_SendPacket)dll.getSymbol("sfSocketUDP_SendPacket");
sfSocketUDP_Unbind = cast(pf_sfSocketUDP_Unbind)dll.getSymbol("sfSocketUDP_Unbind"); sfSocketUDP_Unbind = cast(pf_sfSocketUDP_Unbind)dll.getSymbol("sfSocketUDP_Unbind");
} }
} }

View file

@ -1,37 +1,37 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.all; module dsfml.system.all;
version (linux) version (linux)
{ {
version (build) version (build)
{ {
pragma(link, "dl"); //Link libdl.so (dlopen, dlsym) pragma(link, "dl"); //Link libdl.so (dlopen, dlsym)
} }
} }
@ -43,4 +43,4 @@ public import
dsfml.system.sleep, dsfml.system.sleep,
// dsfml.system.thread, // thread isn't used anywhere in the library and D threading is nice, so the user can safely use standard threads // dsfml.system.thread, // thread isn't used anywhere in the library and D threading is nice, so the user can safely use standard threads
dsfml.system.vector2, dsfml.system.vector2,
dsfml.system.vector3; dsfml.system.vector3;

View file

@ -1,84 +1,84 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.alloc; module dsfml.system.alloc;
version (Tango) version (Tango)
{ {
public import tango.core.Memory; public import tango.core.Memory;
} }
else else
{ {
public import core.memory; public import core.memory;
} }
/* /*
struct GC struct GC
{ {
static void* malloc(uint size) static void* malloc(uint size)
{ {
return std.c.stdlib.malloc(size); return std.c.stdlib.malloc(size);
} }
static void free(void* ptr) static void free(void* ptr)
{ {
std.c.stdlib.free(ptr); std.c.stdlib.free(ptr);
} }
static void addRange(void* ptr, uint size) static void addRange(void* ptr, uint size)
{ {
std.gc.addRange(ptr, ptr + size); std.gc.addRange(ptr, ptr + size);
} }
static void removeRange(void* ptr) static void removeRange(void* ptr)
{ {
std.gc.removeRange(ptr); std.gc.removeRange(ptr);
} }
} }
*/ */
/* /*
* Template for native non-GCed allocation for interaction between C and D threads. * Template for native non-GCed allocation for interaction between C and D threads.
*/ */
template Alloc() template Alloc()
{ {
new (uint size) new (uint size)
{ {
void* p = GC.malloc(size); void* p = GC.malloc(size);
if (!p) if (!p)
assert(0, "Memory allocation failed"); assert(0, "Memory allocation failed");
GC.addRange(p, size); GC.addRange(p, size);
return p; return p;
} }
delete(void* p) delete(void* p)
{ {
GC.removeRange(p); GC.removeRange(p);
GC.free(p); GC.free(p);
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.clock; module dsfml.system.clock;
@ -33,69 +33,69 @@ import dsfml.system.common;
*/ */
class Clock : DSFMLObject class Clock : DSFMLObject
{ {
/** /**
* Default constructor * Default constructor
*/ */
this() this()
{ {
super(sfClock_Create()); super(sfClock_Create());
} }
/** /**
* Destructor * Destructor
*/ */
override void dispose() override void dispose()
{ {
sfClock_Destroy(m_ptr); sfClock_Destroy(m_ptr);
} }
/** /**
* Return the time elapsed since the last reset * Return the time elapsed since the last reset
* Returns: * Returns:
* Elapsed Time in seconds * Elapsed Time in seconds
*/ */
float getElapsedTime() float getElapsedTime()
{ {
return sfClock_GetTime(m_ptr); return sfClock_GetTime(m_ptr);
} }
/** /**
* Restart the timer * Restart the timer
*/ */
void reset() void reset()
{ {
sfClock_Reset(m_ptr); sfClock_Reset(m_ptr);
} }
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfClock_Create; typedef void* function() pf_sfClock_Create;
typedef void function(void*) pf_sfClock_Destroy; typedef void function(void*) pf_sfClock_Destroy;
typedef float function(void*) pf_sfClock_GetTime; typedef float function(void*) pf_sfClock_GetTime;
typedef void function(void*) pf_sfClock_Reset; typedef void function(void*) pf_sfClock_Reset;
static pf_sfClock_Create sfClock_Create; static pf_sfClock_Create sfClock_Create;
static pf_sfClock_Destroy sfClock_Destroy; static pf_sfClock_Destroy sfClock_Destroy;
static pf_sfClock_GetTime sfClock_GetTime; static pf_sfClock_GetTime sfClock_GetTime;
static pf_sfClock_Reset sfClock_Reset; static pf_sfClock_Reset sfClock_Reset;
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-system-d"); DllLoader dll = DllLoader.load("csfml-system-d");
else else
DllLoader dll = DllLoader.load("csfml-system"); DllLoader dll = DllLoader.load("csfml-system");
sfClock_Create = cast(pf_sfClock_Create)dll.getSymbol("sfClock_Create"); sfClock_Create = cast(pf_sfClock_Create)dll.getSymbol("sfClock_Create");
sfClock_Destroy = cast(pf_sfClock_Destroy)dll.getSymbol("sfClock_Destroy"); sfClock_Destroy = cast(pf_sfClock_Destroy)dll.getSymbol("sfClock_Destroy");
sfClock_GetTime = cast(pf_sfClock_GetTime)dll.getSymbol("sfClock_GetTime"); sfClock_GetTime = cast(pf_sfClock_GetTime)dll.getSymbol("sfClock_GetTime");
sfClock_Reset = cast(pf_sfClock_Reset)dll.getSymbol("sfClock_Reset"); sfClock_Reset = cast(pf_sfClock_Reset)dll.getSymbol("sfClock_Reset");
} }
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.common; module dsfml.system.common;
@ -47,7 +47,7 @@ string loadFromSharedLib(string fname)
} }
/** /**
* Base class for all DSFML classes. * Base class for all DSFML classes.
*/ */
class DSFMLObject class DSFMLObject
{ {
@ -60,32 +60,32 @@ protected:
public: public:
this(void* ptr, bool preventDelete = false) this(void* ptr, bool preventDelete = false)
{ {
m_ptr = ptr; m_ptr = ptr;
} }
~this() ~this()
{ {
if (!m_preventDelete) if (!m_preventDelete)
dispose(); dispose();
m_ptr = m_ptr.init; m_ptr = m_ptr.init;
} }
abstract void dispose(); abstract void dispose();
void* getNativePointer() void* getNativePointer()
{ {
return m_ptr; return m_ptr;
} }
void setHandled(bool handled) void setHandled(bool handled)
{ {
m_preventDelete = handled; m_preventDelete = handled;
} }
protected invariant() protected invariant()
{ {
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString); assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.dllloader; module dsfml.system.dllloader;
@ -30,161 +30,161 @@ import dsfml.system.stringutil;
version (Tango) version (Tango)
{ {
import tango.io.Console; import tango.io.Console;
import tango.sys.SharedLib; import tango.sys.SharedLib;
} }
else else
{ {
import std.stdio; import std.stdio;
version (Windows) version (Windows)
{ {
import std.c.windows.windows; import std.c.windows.windows;
alias HMODULE MODULEHANDLE; alias HMODULE MODULEHANDLE;
} }
version (linux) version (linux)
{ {
import std.c.linux.linux; import std.c.linux.linux;
alias void* MODULEHANDLE; alias void* MODULEHANDLE;
const int RTLD_NOW = 0x00002; const int RTLD_NOW = 0x00002;
const int RTLD_GLOBAL = 0x00100; const int RTLD_GLOBAL = 0x00100;
} }
} }
static this() static this()
{ {
version (Tango) version (Tango)
{ {
SharedLib.throwExceptions = false; SharedLib.throwExceptions = false;
} }
} }
private void report(string msg, string lib, string symb) private void report(string msg, string lib, string symb)
{ {
string str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")"; string str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")";
version (Tango) version (Tango)
{ {
Cerr(str).newline; Cerr(str).newline;
} }
else else
{ {
stderr.writeln(str); stderr.writeln(str);
} }
} }
/** /**
* Simple Dll loader. * Simple Dll loader.
*/ */
class DllLoader class DllLoader
{ {
static DllLoader load(string library) static DllLoader load(string library)
{ {
version (Windows) version (Windows)
{ {
string libraryName = library ~ ".dll"; string libraryName = library ~ ".dll";
} }
version (linux) version (linux)
{ {
string libraryName = "lib" ~ library ~ ".so"; string libraryName = "lib" ~ library ~ ".so";
} }
if (libraryName in alreadyLoaded) if (libraryName in alreadyLoaded)
{ {
return alreadyLoaded[libraryName]; return alreadyLoaded[libraryName];
} }
else else
{ {
DllLoader temp = new DllLoader(libraryName); DllLoader temp = new DllLoader(libraryName);
alreadyLoaded[libraryName] = temp; alreadyLoaded[libraryName] = temp;
return temp; return temp;
} }
} }
~this() ~this()
{ {
close(); close();
} }
void* getSymbol(string symbolName) void* getSymbol(string symbolName)
{ {
void* symb; void* symb;
version (Tango) version (Tango)
{ {
symb = m_lib.getSymbol(toStringz(symbolName)); symb = m_lib.getSymbol(toStringz(symbolName));
} }
else else
{ {
version (Windows) version (Windows)
{ {
symb = GetProcAddress(m_lib, toStringz(symbolName)); symb = GetProcAddress(m_lib, toStringz(symbolName));
} }
version (linux) version (linux)
{ {
symb = dlsym(m_lib, toStringz(symbolName)); symb = dlsym(m_lib, toStringz(symbolName));
} }
} }
if (symb is null) if (symb is null)
report( "Symbol cannot be found in specified library", m_libPath, symbolName); report( "Symbol cannot be found in specified library", m_libPath, symbolName);
return symb; return symb;
} }
void close() void close()
{ {
version (Tango) version (Tango)
{ {
m_lib.unload(); m_lib.unload();
} }
else else
{ {
version (Windows) version (Windows)
{ {
FreeLibrary(m_lib); FreeLibrary(m_lib);
} }
version (linux) version (linux)
{ {
dlclose(m_lib); dlclose(m_lib);
} }
alreadyLoaded.remove(this.m_libPath); alreadyLoaded.remove(this.m_libPath);
} }
} }
private: private:
this(string libraryPath) this(string libraryPath)
{ {
m_libPath = libraryPath; m_libPath = libraryPath;
version (Tango) version (Tango)
{ {
m_lib = SharedLib.load(libraryPath); m_lib = SharedLib.load(libraryPath);
} }
else else
{ {
version (Windows) version (Windows)
{ {
m_lib = LoadLibraryA(toStringz(libraryPath)); m_lib = LoadLibraryA(toStringz(libraryPath));
} }
version (linux) version (linux)
{ {
m_lib = dlopen(toStringz(libraryPath), RTLD_NOW | RTLD_GLOBAL); m_lib = dlopen(toStringz(libraryPath), RTLD_NOW | RTLD_GLOBAL);
} }
} }
if (m_lib is null) if (m_lib is null)
report("Cannot open library", m_libPath, null); report("Cannot open library", m_libPath, null);
} }
version (Tango) version (Tango)
{ {
SharedLib m_lib; SharedLib m_lib;
} }
else else
{ {
MODULEHANDLE m_lib; MODULEHANDLE m_lib;
} }
static DllLoader[string] alreadyLoaded; static DllLoader[string] alreadyLoaded;
string m_libPath; string m_libPath;
} }

View file

@ -1,43 +1,43 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.exception; module dsfml.system.exception;
class LoadingException : Exception class LoadingException : Exception
{ {
this(string msg) this(string msg)
{ {
super(msg); super(msg);
} }
} }
class NullParameterException : Exception class NullParameterException : Exception
{ {
this(string msg) this(string msg)
{ {
super(msg); super(msg);
} }
} }

View file

@ -1,103 +1,103 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.linkedlist; module dsfml.system.linkedlist;
/* /*
* Trivial implementation of Queue linked list (for internal use) * Trivial implementation of Queue linked list (for internal use)
*/ */
class LinkedList(T) class LinkedList(T)
{ {
Node!(T) head; Node!(T) head;
Node!(T) tail; Node!(T) tail;
private size_t m_count; private size_t m_count;
void enqueue(T object) void enqueue(T object)
{ {
if (empty) if (empty)
head = tail = new Node!(T)(object); head = tail = new Node!(T)(object);
else else
{ {
tail.Next = new Node!(T)(object); tail.Next = new Node!(T)(object);
tail = tail.Next; tail = tail.Next;
} }
m_count++; m_count++;
} }
T dequeue() T dequeue()
{ {
T o; T o;
if (empty) if (empty)
o = T.init; o = T.init;
else else
{ {
o = head.Data; o = head.Data;
head = head.Next; head = head.Next;
m_count--; m_count--;
} }
return o; return o;
} }
bool empty() bool empty()
{ {
return (head is null); return (head is null);
} }
size_t getCount() size_t getCount()
{ {
return m_count; return m_count;
} }
void clear() void clear()
{ {
T data; T data;
while ((data = dequeue()) !is T.init) {} while ((data = dequeue()) !is T.init) {}
} }
int opApply(int delegate(ref T) dg) int opApply(int delegate(ref T) dg)
{ {
T data; T data;
int result; int result;
while ((data = dequeue) !is T.init) while ((data = dequeue) !is T.init)
{ {
if ((result = dg(data)) != 0) if ((result = dg(data)) != 0)
break; break;
} }
return result; return result;
} }
} }
private class Node(T) private class Node(T)
{ {
Node Next; Node Next;
T Data; T Data;
this(T data) this(T data)
{ {
Data = data; Data = data;
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.lock; module dsfml.system.lock;
@ -29,38 +29,38 @@ module dsfml.system.lock;
import dsfml.system.mutex; import dsfml.system.mutex;
/** /**
* Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception. * Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception.
* *
* Remarks: * Remarks:
* Lock is a scope class, you need to mark Lock object as scope : * Lock is a scope class, you need to mark Lock object as scope :
* *
* ----------------- * -----------------
* Mutex m = new Mutex; * Mutex m = new Mutex;
* //.. * //..
* { * {
* scope Lock l = new Lock(m); * scope Lock l = new Lock(m);
* // Critical section * // Critical section
* } // End of critical (Destructor called and mutex unlocked) * } // End of critical (Destructor called and mutex unlocked)
* //.. * //..
* *
* ----------------- * -----------------
*/ */
scope class Lock scope class Lock
{ {
/** /**
* Construct the lock and lock the mutex * Construct the lock and lock the mutex
*/ */
this(Mutex m) this(Mutex m)
{ {
m_mutex = m; m_mutex = m;
m_mutex.lock(); m_mutex.lock();
} }
~this() ~this()
{ {
m_mutex.unlock(); m_mutex.unlock();
} }
private: private:
Mutex m_mutex; Mutex m_mutex;
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.mutex; module dsfml.system.mutex;
@ -29,70 +29,70 @@ module dsfml.system.mutex;
import dsfml.system.common; import dsfml.system.common;
/** /**
* Provide portable implementation of Mutual Exclusion object. * Provide portable implementation of Mutual Exclusion object.
* *
* Uses CriticalSection on Windows and pthread mutexes on linux. * Uses CriticalSection on Windows and pthread mutexes on linux.
*/ */
final class Mutex : DSFMLObject final class Mutex : DSFMLObject
{ {
/** /**
* Constructor * Constructor
*/ */
this() this()
{ {
super(sfMutex_Create()); super(sfMutex_Create());
} }
override void dispose() override void dispose()
{ {
sfMutex_Destroy(m_ptr); sfMutex_Destroy(m_ptr);
} }
/** /**
* Lock the mutex * Lock the mutex
* *
* Can be called multiples times, but each lock must be unlocked with unlock() * Can be called multiples times, but each lock must be unlocked with unlock()
*/ */
void lock() void lock()
{ {
sfMutex_Lock(m_ptr); sfMutex_Lock(m_ptr);
} }
/** /**
* Unlock the mutex * Unlock the mutex
*/ */
void unlock() void unlock()
{ {
sfMutex_Unlock(m_ptr); sfMutex_Unlock(m_ptr);
} }
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function() pf_sfMutex_Create; typedef void* function() pf_sfMutex_Create;
typedef void function(void*) pf_sfMutex_Destroy; typedef void function(void*) pf_sfMutex_Destroy;
typedef void function(void*) pf_sfMutex_Lock; typedef void function(void*) pf_sfMutex_Lock;
typedef void function(void*) pf_sfMutex_Unlock; typedef void function(void*) pf_sfMutex_Unlock;
static pf_sfMutex_Create sfMutex_Create; static pf_sfMutex_Create sfMutex_Create;
static pf_sfMutex_Destroy sfMutex_Destroy; static pf_sfMutex_Destroy sfMutex_Destroy;
static pf_sfMutex_Lock sfMutex_Lock; static pf_sfMutex_Lock sfMutex_Lock;
static pf_sfMutex_Unlock sfMutex_Unlock; static pf_sfMutex_Unlock sfMutex_Unlock;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-system-d"); DllLoader dll = DllLoader.load("csfml-system-d");
else else
DllLoader dll = DllLoader.load("csfml-system"); DllLoader dll = DllLoader.load("csfml-system");
sfMutex_Create = cast(pf_sfMutex_Create)dll.getSymbol("sfMutex_Create"); sfMutex_Create = cast(pf_sfMutex_Create)dll.getSymbol("sfMutex_Create");
sfMutex_Destroy = cast(pf_sfMutex_Destroy)dll.getSymbol("sfMutex_Destroy"); sfMutex_Destroy = cast(pf_sfMutex_Destroy)dll.getSymbol("sfMutex_Destroy");
sfMutex_Lock = cast(pf_sfMutex_Lock)dll.getSymbol("sfMutex_Lock"); sfMutex_Lock = cast(pf_sfMutex_Lock)dll.getSymbol("sfMutex_Lock");
sfMutex_Unlock = cast(pf_sfMutex_Unlock)dll.getSymbol("sfMutex_Unlock"); sfMutex_Unlock = cast(pf_sfMutex_Unlock)dll.getSymbol("sfMutex_Unlock");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.randomizer; module dsfml.system.randomizer;
@ -29,64 +29,64 @@ module dsfml.system.randomizer;
import dsfml.system.common; import dsfml.system.common;
/** /**
* Randomizer is an utility class for generating pseudo-random * Randomizer is an utility class for generating pseudo-random
* numbers * numbers
* *
* Examples: * Examples:
* ----------------------------------------------------------- * -----------------------------------------------------------
* int randI = Randomizer.Random(1, 100); * int randI = Randomizer.Random(1, 100);
* float randF = Randomizer.Random(1.0, 10.0) * float randF = Randomizer.Random(1.0, 10.0)
* ----------------------------------------------------------- * -----------------------------------------------------------
*/ */
class Randomizer class Randomizer
{ {
/** /**
* Set the seed for the generator. Using a known seed * Set the seed for the generator. Using a known seed
* allows you to reproduce the same sequence of random number * allows you to reproduce the same sequence of random number
* *
* Params: * Params:
* seed = Number to use as the seed * seed = Number to use as the seed
* *
*/ */
static void setSeed(uint seed) static void setSeed(uint seed)
{ {
sfRandom_SetSeed(seed); sfRandom_SetSeed(seed);
} }
/** /**
* Get the seed used to generate random numbers the generator. * Get the seed used to generate random numbers the generator.
* *
* Returns: * Returns:
* Current seed * Current seed
*/ */
static uint getSeed() static uint getSeed()
{ {
return sfRandom_GetSeed(); return sfRandom_GetSeed();
} }
/** /**
* Get a random float number in a given range * Get a random float number in a given range
* *
* Params: * Params:
* begin = Start of the range * begin = Start of the range
* end = End of the range * end = End of the range
* Returns: * Returns:
* Random number in [Begin, End] * Random number in [Begin, End]
*/ */
static float random(float begin, float end) static float random(float begin, float end)
{ {
return sfRandom_Float(begin, end); return sfRandom_Float(begin, end);
} }
/** /**
* Get a random integral number in a given range * Get a random integral number in a given range
* *
* Params: * Params:
* begin = Start of the range * begin = Start of the range
* end = End of the range * end = End of the range
* Returns: * Returns:
* Random number in [Begin, End] * Random number in [Begin, End]
*/ */
static int random(int begin, int end) static int random(int begin, int end)
{ {
return sfRandom_Int(begin, end); return sfRandom_Int(begin, end);
@ -95,40 +95,40 @@ class Randomizer
private: private:
/* /*
* Prevent instanciation * Prevent instanciation
*/ */
this() this()
{ {
} }
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void function(uint) pf_sfRandom_SetSeed; typedef void function(uint) pf_sfRandom_SetSeed;
typedef uint function() pf_sfRandom_GetSeed; typedef uint function() pf_sfRandom_GetSeed;
typedef float function(float, float) pf_sfRandom_Float; typedef float function(float, float) pf_sfRandom_Float;
typedef int function(int, int) pf_sfRandom_Int; typedef int function(int, int) pf_sfRandom_Int;
static pf_sfRandom_SetSeed sfRandom_SetSeed; static pf_sfRandom_SetSeed sfRandom_SetSeed;
static pf_sfRandom_GetSeed sfRandom_GetSeed; static pf_sfRandom_GetSeed sfRandom_GetSeed;
static pf_sfRandom_Float sfRandom_Float; static pf_sfRandom_Float sfRandom_Float;
static pf_sfRandom_Int sfRandom_Int; static pf_sfRandom_Int sfRandom_Int;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-system-d"); DllLoader dll = DllLoader.load("csfml-system-d");
else else
DllLoader dll = DllLoader.load("csfml-system"); DllLoader dll = DllLoader.load("csfml-system");
sfRandom_SetSeed = cast(pf_sfRandom_SetSeed)dll.getSymbol("sfRandom_SetSeed"); sfRandom_SetSeed = cast(pf_sfRandom_SetSeed)dll.getSymbol("sfRandom_SetSeed");
sfRandom_GetSeed = cast(pf_sfRandom_GetSeed)dll.getSymbol("sfRandom_GetSeed"); sfRandom_GetSeed = cast(pf_sfRandom_GetSeed)dll.getSymbol("sfRandom_GetSeed");
sfRandom_Float = cast(pf_sfRandom_Float)dll.getSymbol("sfRandom_Float"); sfRandom_Float = cast(pf_sfRandom_Float)dll.getSymbol("sfRandom_Float");
sfRandom_Int = cast(pf_sfRandom_Int)dll.getSymbol("sfRandom_Int"); sfRandom_Int = cast(pf_sfRandom_Int)dll.getSymbol("sfRandom_Int");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.sleep; module dsfml.system.sleep;
@ -42,17 +42,17 @@ static this()
else else
DllLoader dll = DllLoader.load("csfml-system"); DllLoader dll = DllLoader.load("csfml-system");
sfSleep = cast(pf_sfSleep)dll.getSymbol("sfSleep"); sfSleep = cast(pf_sfSleep)dll.getSymbol("sfSleep");
} }
/** /**
* Make the current thread sleep for a given time * Make the current thread sleep for a given time
* *
* Params: * Params:
* duration = Time to sleep, in seconds * duration = Time to sleep, in seconds
*/ */
void sleep(float duration) void sleep(float duration)
{ {
sfSleep(duration); sfSleep(duration);
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.stringutil; module dsfml.system.stringutil;
@ -40,43 +40,43 @@ else
*/ */
T* toStringz(T)(T[] str) T* toStringz(T)(T[] str)
{ {
if (str is null) if (str is null)
return null; return null;
else if (str.length && str[$ - 1] is T.init) else if (str.length && str[$ - 1] is T.init)
return str.ptr; return str.ptr;
auto ret = new Unqual!(T)[str.length + 1]; auto ret = new Unqual!(T)[str.length + 1];
ret[0 .. str.length] = str[0 .. $]; ret[0 .. str.length] = str[0 .. $];
ret[str.length] = 0; ret[str.length] = 0;
return cast(T*) ret.ptr; return cast(T*) ret.ptr;
} }
size_t stringLength(T)(T* p) size_t stringLength(T)(T* p)
{ {
if (p is null || *p == T.init) if (p is null || *p == T.init)
return 0; return 0;
size_t length; size_t length;
while (*(p + length)) while (*(p + length))
{ {
length++; length++;
} }
return length; return length;
} }
T[] fromStringz(T)(T* ptr) T[] fromStringz(T)(T* ptr)
{ {
auto ret = new Unqual!(T)[stringLength(ptr)]; auto ret = new Unqual!(T)[stringLength(ptr)];
ret[0..$] = ptr[0..ret.length]; ret[0..$] = ptr[0..ret.length];
return cast(T[]) ret; return cast(T[]) ret;
} }

View file

@ -1,158 +1,158 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.vector2; module dsfml.system.vector2;
/** /**
* Vector2 is an utility class for manipulating 2 dimensional * Vector2 is an utility class for manipulating 2 dimensional
* vectors. Template parameter defines the type of coordinates * vectors. Template parameter defines the type of coordinates
* (integer, float, ...) * (integer, float, ...)
*/ */
struct Vector2(T) struct Vector2(T)
{ {
T x; T x;
T y; T y;
static Vector2 opCall(T x, T y) static Vector2 opCall(T x, T y)
{ {
Vector2!(T) ret; Vector2!(T) ret;
ret.x = x; ret.x = x;
ret.y = y; ret.y = y;
return ret; return ret;
} }
/// unary (-) overload /// unary (-) overload
Vector2 opNeg() Vector2 opNeg()
{ {
return Vector2!(T)(-x, -y); return Vector2!(T)(-x, -y);
} }
/// (+=) overload /// (+=) overload
Vector2 opAddAssign(Vector2 other) Vector2 opAddAssign(Vector2 other)
{ {
x += other.x; x += other.x;
y += other.y; y += other.y;
return this; return this;
} }
/// (-=) overload /// (-=) overload
Vector2 opSubAssign(Vector2 other) Vector2 opSubAssign(Vector2 other)
{ {
x -= other.x; x -= other.x;
y -= other.y; y -= other.y;
return this; return this;
} }
/// (+) overload /// (+) overload
Vector2 opAdd(Vector2 other) Vector2 opAdd(Vector2 other)
{ {
return Vector2!(T)( (x + other.x), (y + other.y) ); return Vector2!(T)( (x + other.x), (y + other.y) );
} }
/// (-) overload /// (-) overload
Vector2 opSub(Vector2 other) Vector2 opSub(Vector2 other)
{ {
return Vector2!(T) ( (x - other.x), (y - other.y) ); return Vector2!(T) ( (x - other.x), (y - other.y) );
} }
/// (*) overload /// (*) overload
Vector2 opMul(int i) Vector2 opMul(int i)
{ {
return Vector2!(T) ( (x * i), (y * i) ); return Vector2!(T) ( (x * i), (y * i) );
} }
/// (*=) overload /// (*=) overload
Vector2 opMulAssign(int i) Vector2 opMulAssign(int i)
{ {
x *= i; x *= i;
y *= i; y *= i;
return this; return this;
} }
/// (/) overload /// (/) overload
Vector2 opDiv(int i) Vector2 opDiv(int i)
{ {
return Vector2!(T) ( (x / i), (y / i)); return Vector2!(T) ( (x / i), (y / i));
} }
/// (/=) overload /// (/=) overload
Vector2 opDivAssign(int i) Vector2 opDivAssign(int i)
{ {
x /= i; x /= i;
y /= i; y /= i;
return this; return this;
} }
/// ///
const bool opEquals(ref const(Vector2) other) const bool opEquals(ref const(Vector2) other)
{ {
return (x == other.x) && (y == other.y); return (x == other.x) && (y == other.y);
} }
} }
version (UnitTest) version (UnitTest)
{ {
unittest unittest
{ {
Vector2f main = Vector2f(10f, 10f); Vector2f main = Vector2f(10f, 10f);
Vector2f other = Vector2f(10f, 10f); Vector2f other = Vector2f(10f, 10f);
Vector2f result; Vector2f result;
result = -main; result = -main;
assert (result == Vector2f(-10.f, -10.f) ); assert (result == Vector2f(-10.f, -10.f) );
result = main; result = main;
result += other; result += other;
assert (result == Vector2f(20.f, 20.f)); assert (result == Vector2f(20.f, 20.f));
result = main; result = main;
result -= other; result -= other;
assert (result == Vector2f(0.f, 0.f)); assert (result == Vector2f(0.f, 0.f));
result = main + other; result = main + other;
assert (result == Vector2f(20.f, 20.f)); assert (result == Vector2f(20.f, 20.f));
result = main - other; result = main - other;
assert (result == Vector2f(0.f, 0.f)); assert (result == Vector2f(0.f, 0.f));
result = main * 10; result = main * 10;
assert (result == Vector2f(100.f, 100.f)); assert (result == Vector2f(100.f, 100.f));
result *= 2; result *= 2;
assert (result == Vector2f(200.f, 200.f)); assert (result == Vector2f(200.f, 200.f));
result = main / 2; result = main / 2;
assert (result == Vector2f(5.f, 5.f)); assert (result == Vector2f(5.f, 5.f));
result = main; result = main;
result /= 2; result /= 2;
assert (result == Vector2f(5.f, 5.f)); assert (result == Vector2f(5.f, 5.f));
} }
} }
/// Aliases /// Aliases

View file

@ -1,164 +1,164 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.system.vector3; module dsfml.system.vector3;
/** /**
* Vector3 is an utility class for manipulating 3 dimensional * Vector3 is an utility class for manipulating 3 dimensional
* vectors. Template parameter defines the type of coordinates * vectors. Template parameter defines the type of coordinates
* (integer, float, ...) * (integer, float, ...)
*/ */
struct Vector3(T) struct Vector3(T)
{ {
T x; T x;
T y; T y;
T z; T z;
static Vector3 opCall(T x, T y, T z) static Vector3 opCall(T x, T y, T z)
{ {
Vector3!(T) ret; Vector3!(T) ret;
ret.x = x; ret.x = x;
ret.y = y; ret.y = y;
ret.z = z; ret.z = z;
return ret; return ret;
} }
/// unary (-) overload /// unary (-) overload
Vector3 opNeg() Vector3 opNeg()
{ {
return Vector3!(T)(-x, -y, -z); return Vector3!(T)(-x, -y, -z);
} }
/// (+=) overload /// (+=) overload
Vector3 opAddAssign(Vector3 other) Vector3 opAddAssign(Vector3 other)
{ {
x += other.x; x += other.x;
y += other.y; y += other.y;
z += other.z; z += other.z;
return this; return this;
} }
/// (-=) overload /// (-=) overload
Vector3 opSubAssign(Vector3 other) Vector3 opSubAssign(Vector3 other)
{ {
x -= other.x; x -= other.x;
y -= other.y; y -= other.y;
z -= other.z; z -= other.z;
return this; return this;
} }
/// (+) overload /// (+) overload
Vector3 opAdd(Vector3 other) Vector3 opAdd(Vector3 other)
{ {
return Vector3!(T)( (x + other.x), (y + other.y), (z + other.z) ); return Vector3!(T)( (x + other.x), (y + other.y), (z + other.z) );
} }
/// (-) overload /// (-) overload
Vector3 opSub(Vector3 other) Vector3 opSub(Vector3 other)
{ {
return Vector3!(T) ( (x - other.x), (y - other.y), (z - other.z) ); return Vector3!(T) ( (x - other.x), (y - other.y), (z - other.z) );
} }
/// (*) overload /// (*) overload
Vector3 opMul(int i) Vector3 opMul(int i)
{ {
return Vector3!(T) ( (x * i), (y * i), (z * i) ); return Vector3!(T) ( (x * i), (y * i), (z * i) );
} }
/// (*=) overload /// (*=) overload
Vector3 opMulAssign(int i) Vector3 opMulAssign(int i)
{ {
x *= i; x *= i;
y *= i; y *= i;
z *= i; z *= i;
return this; return this;
} }
/// (/) overload /// (/) overload
Vector3 opDiv(int i) Vector3 opDiv(int i)
{ {
return Vector3!(T) ( (x / i), (y / i), (z / i) ); return Vector3!(T) ( (x / i), (y / i), (z / i) );
} }
/// (/=) overload /// (/=) overload
Vector3 opDivAssign(int i) Vector3 opDivAssign(int i)
{ {
x /= i; x /= i;
y /= i; y /= i;
z /= i; z /= i;
return this; return this;
} }
/// ///
const bool opEquals(ref const(Vector3) other) const bool opEquals(ref const(Vector3) other)
{ {
return (x == other.x) && (y == other.y) && (z == other.z) ; return (x == other.x) && (y == other.y) && (z == other.z) ;
} }
} }
version (UnitTest) version (UnitTest)
{ {
unittest unittest
{ {
Vector3f main = Vector3f(10f, 10f, 10.f); Vector3f main = Vector3f(10f, 10f, 10.f);
Vector3f other = Vector3f(10f, 10f, 10.f); Vector3f other = Vector3f(10f, 10f, 10.f);
Vector3f result; Vector3f result;
result = -main; result = -main;
assert (result == Vector3f(-10.f, -10.f, -10.f) ); assert (result == Vector3f(-10.f, -10.f, -10.f) );
result = main; result = main;
result += other; result += other;
assert (result == Vector3f(20.f, 20.f, 20.f)); assert (result == Vector3f(20.f, 20.f, 20.f));
result = main; result = main;
result -= other; result -= other;
assert (result == Vector3f(0.f, 0.f, 0.f)); assert (result == Vector3f(0.f, 0.f, 0.f));
result = main + other; result = main + other;
assert (result == Vector3f(20.f, 20.f, 20.f)); assert (result == Vector3f(20.f, 20.f, 20.f));
result = main - other; result = main - other;
assert (result == Vector3f(0.f, 0.f, 0.f)); assert (result == Vector3f(0.f, 0.f, 0.f));
result = main * 10; result = main * 10;
assert (result == Vector3f(100.f, 100.f, 100.f)); assert (result == Vector3f(100.f, 100.f, 100.f));
result *= 2; result *= 2;
assert (result == Vector3f(200.f, 200.f, 200.f)); assert (result == Vector3f(200.f, 200.f, 200.f));
result = main / 2; result = main / 2;
assert (result == Vector3f(5.f, 5.f, 5.f)); assert (result == Vector3f(5.f, 5.f, 5.f));
result = main; result = main;
result /= 2; result /= 2;
assert (result == Vector3f(5.f, 5.f, 5.f)); assert (result == Vector3f(5.f, 5.f, 5.f));
} }
} }
/// Aliases /// Aliases

View file

@ -1,33 +1,33 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.all; module dsfml.window.all;
public import public import
dsfml.window.event, dsfml.window.event,
dsfml.window.input, dsfml.window.input,
dsfml.window.videomode, dsfml.window.videomode,
dsfml.window.window, dsfml.window.window,

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.common; module dsfml.window.common;

View file

@ -1,26 +1,26 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.context; module dsfml.window.context;
@ -49,7 +49,7 @@ class Context : DSFMLObject
/** /**
* *
* Params: * Params:
* active = * active =
*/ */
void setActive(bool active) void setActive(bool active)
{ {

View file

@ -1,329 +1,329 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.event; module dsfml.window.event;
/** /**
* Definition of key codes for keyboard events * Definition of key codes for keyboard events
* *
* $(B Possibles values:)$(BR) * $(B Possibles values:)$(BR)
* Except letters and numbers, you can use :$(BR) * Except letters and numbers, you can use :$(BR)
* * LCONTROL, LSHIFT, LALT, LSYSTEM, RCONTROL, RSHIFT, RALT, RSYSTEM.$(BR) * * LCONTROL, LSHIFT, LALT, LSYSTEM, RCONTROL, RSHIFT, RALT, RSYSTEM.$(BR)
* * LBRACKET, RBRACKET, SEMICOLON, COMMA, PERIOD, QUOTE, SLASH, BACKSLASH, TILDE, EQUAL, DASH.$(BR) * * LBRACKET, RBRACKET, SEMICOLON, COMMA, PERIOD, QUOTE, SLASH, BACKSLASH, TILDE, EQUAL, DASH.$(BR)
* * SPACE, RETURN, BACK, TAB, PAGEUP, PAGEDOWN, END, HOME, INSERT, DELETE.$(BR) * * SPACE, RETURN, BACK, TAB, PAGEUP, PAGEDOWN, END, HOME, INSERT, DELETE.$(BR)
* * ADD, SUBTRACT, MULTIPLY, DIVIDE, LEFT, RIGHT, UP, DOWN.$(BR) * * ADD, SUBTRACT, MULTIPLY, DIVIDE, LEFT, RIGHT, UP, DOWN.$(BR)
* * NUMPAD0, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9.$(BR) * * NUMPAD0, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9.$(BR)
* * F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15.$(BR) * * F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15.$(BR)
*/ */
enum KeyCode enum KeyCode
{ {
A = 'a', A = 'a',
B = 'b', B = 'b',
C = 'c', C = 'c',
D = 'd', D = 'd',
E = 'e', E = 'e',
F = 'f', F = 'f',
G = 'g', G = 'g',
H = 'h', H = 'h',
I = 'i', I = 'i',
J = 'j', J = 'j',
K = 'k', K = 'k',
L = 'l', L = 'l',
M = 'm', M = 'm',
N = 'n', N = 'n',
O = 'o', O = 'o',
P = 'p', P = 'p',
Q = 'q', Q = 'q',
R = 'r', R = 'r',
S = 's', S = 's',
T = 't', T = 't',
U = 'u', U = 'u',
V = 'v', V = 'v',
W = 'w', W = 'w',
X = 'x', X = 'x',
Y = 'y', Y = 'y',
Z = 'z', Z = 'z',
NUM0 = '0', NUM0 = '0',
NUM1 = '1', NUM1 = '1',
NUM2 = '2', NUM2 = '2',
NUM3 = '3', NUM3 = '3',
NUM4 = '4', NUM4 = '4',
NUM5 = '5', NUM5 = '5',
NUM6 = '6', NUM6 = '6',
NUM7 = '7', NUM7 = '7',
NUM8 = '8', NUM8 = '8',
NUM9 = '9', NUM9 = '9',
ESCAPE = 256, ESCAPE = 256,
LCONTROL, LCONTROL,
LSHIFT, LSHIFT,
LALT, LALT,
LSYSTEM, LSYSTEM,
RCONTROL, RCONTROL,
RSHIFT, RSHIFT,
RALT, RALT,
RSYSTEM, RSYSTEM,
MENU, MENU,
LBRACKET, LBRACKET,
RBRACKET, RBRACKET,
SEMICOLON, SEMICOLON,
COMMA, COMMA,
PERIOD, PERIOD,
QUOTE, QUOTE,
SLASH, SLASH,
BACKSLASH, BACKSLASH,
TILDE, TILDE,
EQUAL, EQUAL,
DASH, DASH,
SPACE, SPACE,
RETURN, RETURN,
BACK, BACK,
TAB, TAB,
PAGEUP, PAGEUP,
PAGEDOWN, PAGEDOWN,
END, END,
HOME, HOME,
INSERT, INSERT,
DELETE, DELETE,
ADD, ADD,
SUBTRACT, SUBTRACT,
MULTIPLY, MULTIPLY,
DIVIDE, DIVIDE,
LEFT, LEFT,
RIGHT, RIGHT,
UP, UP,
DOWN, DOWN,
NUMPAD0, NUMPAD0,
NUMPAD1, NUMPAD1,
NUMPAD2, NUMPAD2,
NUMPAD3, NUMPAD3,
NUMPAD4, NUMPAD4,
NUMPAD5, NUMPAD5,
NUMPAD6, NUMPAD6,
NUMPAD7, NUMPAD7,
NUMPAD8, NUMPAD8,
NUMPAD9, NUMPAD9,
F1, F1,
F2, F2,
F3, F3,
F4, F4,
F5, F5,
F6, F6,
F7, F7,
F8, F8,
F9, F9,
F10, F10,
F11, F11,
F12, F12,
F13, F13,
F14, F14,
F15, F15,
PAUSE, PAUSE,
} }
/** /**
* Definition of button codes for mouse events * Definition of button codes for mouse events
*/ */
enum MouseButtons enum MouseButtons
{ {
LEFT, /// LEFT, ///
RIGHT, /// RIGHT, ///
MIDDLE, /// MIDDLE, ///
XBUTTON1, /// XBUTTON1, ///
XBUTTON2 /// XBUTTON2 ///
} }
/** /**
* Definition of joystick axis for joystick events * Definition of joystick axis for joystick events
*/ */
enum JoyAxis enum JoyAxis
{ {
AXISX, /// AXISX, ///
AXISY, /// AXISY, ///
AXISZ, /// AXISZ, ///
AXISR, /// AXISR, ///
AXISU, /// AXISU, ///
AXISV, /// AXISV, ///
AXISPOV /// AXISPOV ///
} }
/** /**
* Event defines a system event and its parameters * Event defines a system event and its parameters
*/ */
align(1) struct Event align(1) struct Event
{ {
enum EventType enum EventType
{ {
CLOSED, CLOSED,
RESIZED, RESIZED,
LOSTFOCUS, LOSTFOCUS,
GAINEDFOCUS, GAINEDFOCUS,
TEXTENTERED, TEXTENTERED,
KEYPRESSED, KEYPRESSED,
KEYRELEASED, KEYRELEASED,
MOUSEWHEELMOVED, MOUSEWHEELMOVED,
MOUSEBUTTONPRESSED, MOUSEBUTTONPRESSED,
MOUSEBUTTONRELEASED, MOUSEBUTTONRELEASED,
MOUSEMOVED, MOUSEMOVED,
MOUSEENTERED, MOUSEENTERED,
MOUSELEFT, MOUSELEFT,
JOYBUTTONPRESSED, JOYBUTTONPRESSED,
JOYBUTTONRELEASED, JOYBUTTONRELEASED,
JOYMOVED JOYMOVED
} }
/** /**
* Enumeration of the different types of events. Accessing a value of another event that the one received (e.g. Event.Size.Width when receiving an KEYPRESSED event) will result in undefined behavior. * Enumeration of the different types of events. Accessing a value of another event that the one received (e.g. Event.Size.Width when receiving an KEYPRESSED event) will result in undefined behavior.
* $(UL * $(UL
* $(LI CLOSED) * $(LI CLOSED)
* $(LI LOSTFOCUS) * $(LI LOSTFOCUS)
* $(LI GAINEDFOCUS) * $(LI GAINEDFOCUS)
* $(LI RESIZED * $(LI RESIZED
* $(UL * $(UL
* $(LI Event.Size.Width : new Width, in pixels.) * $(LI Event.Size.Width : new Width, in pixels.)
* $(LI Event.Size.Height : new height, in pixels.) * $(LI Event.Size.Height : new height, in pixels.)
* ) * )
* ) * )
* $(LI TEXTENTERED * $(LI TEXTENTERED
* $(UL * $(UL
* $(LI Event.Text.Unicode : dchar entered.) * $(LI Event.Text.Unicode : dchar entered.)
* ) * )
* ) * )
* $(LI KEYPRESSED, KEYRELEASED * $(LI KEYPRESSED, KEYRELEASED
* $(UL * $(UL
* $(LI Event.Key.Code : Key code of the key.) * $(LI Event.Key.Code : Key code of the key.)
* $(LI Event.Key.Alt : Alt pressed ?) * $(LI Event.Key.Alt : Alt pressed ?)
* $(LI Event.Key.Control : Control pressed ?) * $(LI Event.Key.Control : Control pressed ?)
* $(LI Event.Key.Shift : Shift pressed ?) * $(LI Event.Key.Shift : Shift pressed ?)
* ) * )
* ) * )
* $(LI MOUSEWHEELMOVED * $(LI MOUSEWHEELMOVED
* $(UL * $(UL
* $(LI Event.MouseWheel.Delta : Wheel move (positive if forward, negative else.) ) * $(LI Event.MouseWheel.Delta : Wheel move (positive if forward, negative else.) )
* ) * )
* ) * )
* $(LI MOUSEBUTTONPRESSED, MOUSEBUTTONRELEASED * $(LI MOUSEBUTTONPRESSED, MOUSEBUTTONRELEASED
* $(UL * $(UL
* $(LI Event.MouseButton.Button : Mouse button pressed.) * $(LI Event.MouseButton.Button : Mouse button pressed.)
* $(LI Event.MouseButton.X : Cursor X position.) * $(LI Event.MouseButton.X : Cursor X position.)
* $(LI Event.MouseButton.Y : Cursor X position.) * $(LI Event.MouseButton.Y : Cursor X position.)
* ) * )
* ) * )
* $(LI MOUSEMOVED * $(LI MOUSEMOVED
* $(UL * $(UL
* $(LI Event.MouseMove.X : Cursor X position. Local coordinates.) * $(LI Event.MouseMove.X : Cursor X position. Local coordinates.)
* $(LI Event.MouseMove.Y : Cursor Y position. Local coordinates.) * $(LI Event.MouseMove.Y : Cursor Y position. Local coordinates.)
* ) * )
* ) * )
* $(LI MOUSEENTERED) * $(LI MOUSEENTERED)
* $(LI MOUSELEFT) * $(LI MOUSELEFT)
* $(LI JOYBUTTONPRESSED, JOYBUTTONRELEASED * $(LI JOYBUTTONPRESSED, JOYBUTTONRELEASED
* $(UL * $(UL
* $(LI Event.JoyButton.JoystickId : Id of the joystick.) * $(LI Event.JoyButton.JoystickId : Id of the joystick.)
* $(LI Event.JoyButton.Button : Joystick button pressed.) * $(LI Event.JoyButton.Button : Joystick button pressed.)
* ) * )
* ) * )
* $(LI JOYMOVED * $(LI JOYMOVED
* $(UL * $(UL
* $(LI Event.JoyMove.JoystickId : Id of the joystick.) * $(LI Event.JoyMove.JoystickId : Id of the joystick.)
* $(LI Event.JoyMove.Axis : Moved axis.) * $(LI Event.JoyMove.Axis : Moved axis.)
* $(LI Event.JoyMove.Position : Actual position of the axis [-100, 100], except for POV [0, 360].) * $(LI Event.JoyMove.Position : Actual position of the axis [-100, 100], except for POV [0, 360].)
* ) * )
* ) * )
* ) * )
*/ */
EventType Type; EventType Type;
union union
{ {
struct SText struct SText
{ {
dchar Unicode; dchar Unicode;
} }
SText Text; SText Text;
struct SKey struct SKey
{ {
KeyCode Code; KeyCode Code;
bool Alt; bool Alt;
byte[3] Filler1; byte[3] Filler1;
bool Control; bool Control;
byte[3] Filler2; byte[3] Filler2;
bool Shift; bool Shift;
byte[3] Filler3; byte[3] Filler3;
} }
SKey Key; SKey Key;
struct SMouseMove struct SMouseMove
{ {
int X; int X;
int Y; int Y;
} }
SMouseMove MouseMove; SMouseMove MouseMove;
struct SMouseButton struct SMouseButton
{ {
MouseButtons Button; MouseButtons Button;
int X; int X;
int Y; int Y;
} }
SMouseButton MouseButton; SMouseButton MouseButton;
struct SMouseWheel struct SMouseWheel
{ {
int Delta; int Delta;
} }
SMouseWheel MouseWheel; SMouseWheel MouseWheel;
struct SJoyMove struct SJoyMove
{ {
uint JoystickId; uint JoystickId;
JoyAxis Axis; JoyAxis Axis;
float Position; float Position;
} }
SJoyMove JoyMove; SJoyMove JoyMove;
struct SJoyButton struct SJoyButton
{ {
uint JoystickId; uint JoystickId;
uint Button; uint Button;
} }
SJoyButton JoyButton; SJoyButton JoyButton;
struct SSize struct SSize
{ {
uint Width; uint Width;
uint Height; uint Height;
} }
SSize Size; SSize Size;
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.input; module dsfml.window.input;
@ -31,136 +31,136 @@ import dsfml.system.common;
import dsfml.window.event; import dsfml.window.event;
/** /**
* Input handles real-time input from keyboard and mouse. * Input handles real-time input from keyboard and mouse.
* Use it instead of events to handle continuous moves and more * Use it instead of events to handle continuous moves and more
* game-friendly inputs * game-friendly inputs
*/ */
class Input : DSFMLObject class Input : DSFMLObject
{ {
/** /**
* Get the state of a key * Get the state of a key
* *
* Params: * Params:
* key = Key to check * key = Key to check
* *
* Returns: * Returns:
* True if key is down, false if key is up * True if key is down, false if key is up
*/ */
bool isKeyDown(KeyCode key) bool isKeyDown(KeyCode key)
{ {
return cast(bool)sfInput_IsKeyDown(m_ptr, key); return cast(bool)sfInput_IsKeyDown(m_ptr, key);
} }
/** /**
* Get the state of a mouse button * Get the state of a mouse button
* *
* Params: * Params:
* button = Button to check * button = Button to check
* *
* Returns: * Returns:
* True if button is down, false if button is up * True if button is down, false if button is up
*/ */
bool isMouseButtonDown(MouseButtons button) bool isMouseButtonDown(MouseButtons button)
{ {
return cast(bool)sfInput_IsMouseButtonDown(m_ptr, button); return cast(bool)sfInput_IsMouseButtonDown(m_ptr, button);
} }
/** /**
* Get the state of a joystick button * Get the state of a joystick button
* *
* Params: * Params:
* joyId = Identifier of the joystick to check (0 or 1) * joyId = Identifier of the joystick to check (0 or 1)
* button = Button to check * button = Button to check
* *
* Returns: * Returns:
* True if button is down, false if button is up * True if button is down, false if button is up
*/ */
bool isJoystickButtonDown(uint joyId, uint button) bool isJoystickButtonDown(uint joyId, uint button)
{ {
return cast(bool)sfInput_IsJoystickButtonDown(m_ptr, joyId, button); return cast(bool)sfInput_IsJoystickButtonDown(m_ptr, joyId, button);
} }
/* /*
* Get the mouse X position * Get the mouse X position
* *
* Returns: * Returns:
* Current mouse left position, relative to owner window * Current mouse left position, relative to owner window
*/ */
int getMouseX() int getMouseX()
{ {
return sfInput_GetMouseX(m_ptr); return sfInput_GetMouseX(m_ptr);
} }
/** /**
* Get the mouse Y position * Get the mouse Y position
* *
* Returns: * Returns:
* Current mouse top position, relative to owner window * Current mouse top position, relative to owner window
* *
*/ */
int getMouseY() int getMouseY()
{ {
return sfInput_GetMouseY(m_ptr); return sfInput_GetMouseY(m_ptr);
} }
/** /**
* Get a joystick axis position * Get a joystick axis position
* *
* Params: * Params:
* joyId = Identifier of the joystick to check (0 or 1) * joyId = Identifier of the joystick to check (0 or 1)
* axis = Axis to get * axis = Axis to get
* *
* Returns: * Returns:
* Current axis position, in the range [-100, 100] (except for POV, which is [0, 360]) * Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])
*/ */
float getJoystickAxis(uint joyId, JoyAxis axis) float getJoystickAxis(uint joyId, JoyAxis axis)
{ {
return sfInput_GetJoystickAxis(m_ptr, joyId, axis); return sfInput_GetJoystickAxis(m_ptr, joyId, axis);
} }
this(void* input) this(void* input)
{ {
super(input, true); super(input, true);
} }
override void dispose() override void dispose()
{ {
// nothing to do // nothing to do
} }
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef int function(void*, KeyCode) pf_sfInput_IsKeyDown; typedef int function(void*, KeyCode) pf_sfInput_IsKeyDown;
typedef int function(void*, MouseButtons) pf_sfInput_IsMouseButtonDown; typedef int function(void*, MouseButtons) pf_sfInput_IsMouseButtonDown;
typedef int function(void*, uint, uint) pf_sfInput_IsJoystickButtonDown; typedef int function(void*, uint, uint) pf_sfInput_IsJoystickButtonDown;
typedef uint function (void*) pf_sfInput_GetMouseX; typedef uint function (void*) pf_sfInput_GetMouseX;
typedef uint function(void*) pf_sfInput_GetMouseY; typedef uint function(void*) pf_sfInput_GetMouseY;
typedef float function(void*, uint, JoyAxis) pf_sfInput_GetJoystickAxis; typedef float function(void*, uint, JoyAxis) pf_sfInput_GetJoystickAxis;
static pf_sfInput_IsKeyDown sfInput_IsKeyDown; static pf_sfInput_IsKeyDown sfInput_IsKeyDown;
static pf_sfInput_IsMouseButtonDown sfInput_IsMouseButtonDown; static pf_sfInput_IsMouseButtonDown sfInput_IsMouseButtonDown;
static pf_sfInput_IsJoystickButtonDown sfInput_IsJoystickButtonDown; static pf_sfInput_IsJoystickButtonDown sfInput_IsJoystickButtonDown;
static pf_sfInput_GetMouseX sfInput_GetMouseX; static pf_sfInput_GetMouseX sfInput_GetMouseX;
static pf_sfInput_GetMouseY sfInput_GetMouseY; static pf_sfInput_GetMouseY sfInput_GetMouseY;
static pf_sfInput_GetJoystickAxis sfInput_GetJoystickAxis; static pf_sfInput_GetJoystickAxis sfInput_GetJoystickAxis;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-window-d"); DllLoader dll = DllLoader.load("csfml-window-d");
else else
DllLoader dll = DllLoader.load("csfml-window"); DllLoader dll = DllLoader.load("csfml-window");
sfInput_IsKeyDown = cast(pf_sfInput_IsKeyDown)dll.getSymbol("sfInput_IsKeyDown"); sfInput_IsKeyDown = cast(pf_sfInput_IsKeyDown)dll.getSymbol("sfInput_IsKeyDown");
sfInput_IsMouseButtonDown = cast(pf_sfInput_IsMouseButtonDown)dll.getSymbol("sfInput_IsMouseButtonDown"); sfInput_IsMouseButtonDown = cast(pf_sfInput_IsMouseButtonDown)dll.getSymbol("sfInput_IsMouseButtonDown");
sfInput_IsJoystickButtonDown = cast(pf_sfInput_IsJoystickButtonDown)dll.getSymbol("sfInput_IsJoystickButtonDown"); sfInput_IsJoystickButtonDown = cast(pf_sfInput_IsJoystickButtonDown)dll.getSymbol("sfInput_IsJoystickButtonDown");
sfInput_GetMouseX = cast(pf_sfInput_GetMouseX)dll.getSymbol("sfInput_GetMouseX"); sfInput_GetMouseX = cast(pf_sfInput_GetMouseX)dll.getSymbol("sfInput_GetMouseX");
sfInput_GetMouseY = cast(pf_sfInput_GetMouseY)dll.getSymbol("sfInput_GetMouseY"); sfInput_GetMouseY = cast(pf_sfInput_GetMouseY)dll.getSymbol("sfInput_GetMouseY");
sfInput_GetJoystickAxis = cast(pf_sfInput_GetJoystickAxis)dll.getSymbol("sfInput_GetJoystickAxis"); sfInput_GetJoystickAxis = cast(pf_sfInput_GetJoystickAxis)dll.getSymbol("sfInput_GetJoystickAxis");
} }
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.videomode; module dsfml.window.videomode;
@ -29,9 +29,9 @@ module dsfml.window.videomode;
import dsfml.system.common; import dsfml.system.common;
/** /**
* VideoMode defines a video mode (width, height, bpp, frequency) * VideoMode defines a video mode (width, height, bpp, frequency)
* and provides static functions for getting modes supported * and provides static functions for getting modes supported
* by the display device * by the display device
*/ */
align(1) struct VideoMode align(1) struct VideoMode
{ {
@ -39,81 +39,81 @@ align(1) struct VideoMode
uint Height; /// Video mode height, in pixels uint Height; /// Video mode height, in pixels
uint BitsPerPixel = 32; /// Video mode pixel depth, in bits per pixels uint BitsPerPixel = 32; /// Video mode pixel depth, in bits per pixels
/** /**
* Get the current desktop video mode * Get the current desktop video mode
* *
* Returns: * Returns:
* Current desktop video mode * Current desktop video mode
*/ */
static VideoMode getDesktopMode() static VideoMode getDesktopMode()
{ {
return sfVideoMode_GetDesktopMode(); return sfVideoMode_GetDesktopMode();
} }
/** /**
* Get a valid video mode * Get a valid video mode
* Index must be in range [0, GetModesCount()[ * Index must be in range [0, GetModesCount()[
* Modes are sorted from best to worst * Modes are sorted from best to worst
* *
* Params: * Params:
* index = Index of video mode to get * index = Index of video mode to get
* *
* Returns: * Returns:
* Corresponding video mode (invalid mode if index is out of range) * Corresponding video mode (invalid mode if index is out of range)
*/ */
static VideoMode getMode(size_t index) static VideoMode getMode(size_t index)
{ {
return sfVideoMode_GetMode(index); return sfVideoMode_GetMode(index);
} }
/** /**
* Get valid video modes count * Get valid video modes count
* *
* Returns: * Returns:
* Number of valid video modes available * Number of valid video modes available
*/ */
static size_t getModesCount() static size_t getModesCount()
{ {
return sfVideoMode_GetModesCount(); return sfVideoMode_GetModesCount();
} }
/** /**
* Tell whether or not the video mode is supported * Tell whether or not the video mode is supported
* *
* Returns: * Returns:
* True if video mode is supported, false otherwise * True if video mode is supported, false otherwise
*/ */
bool isValid() bool isValid()
{ {
return cast(bool)sfVideoMode_IsValid(this); return cast(bool)sfVideoMode_IsValid(this);
} }
/** /**
* Comparison operator overload -- tell if two video modes are equal * Comparison operator overload -- tell if two video modes are equal
* *
* Params: * Params:
* Other : Video mode to compare * Other : Video mode to compare
* *
* Returns: * Returns:
* True if modes are equal * True if modes are equal
*/ */
const bool opEquals(ref const(VideoMode) other) const bool opEquals(ref const(VideoMode) other)
{ {
return ((other.Width == Width) && (other.Height == Height) && (other.BitsPerPixel == BitsPerPixel)); return ((other.Width == Width) && (other.Height == Height) && (other.BitsPerPixel == BitsPerPixel));
} }
} }
extern (C) extern (C)
{ {
typedef VideoMode function() pf_sfVideoMode_GetDesktopMode; typedef VideoMode function() pf_sfVideoMode_GetDesktopMode;
typedef VideoMode function(size_t) pf_sfVideoMode_GetMode; typedef VideoMode function(size_t) pf_sfVideoMode_GetMode;
typedef size_t function() pf_sfVideoMode_GetModesCount; typedef size_t function() pf_sfVideoMode_GetModesCount;
typedef int function(VideoMode) pf_sfVideoMode_IsValid; typedef int function(VideoMode) pf_sfVideoMode_IsValid;
pf_sfVideoMode_GetDesktopMode sfVideoMode_GetDesktopMode; pf_sfVideoMode_GetDesktopMode sfVideoMode_GetDesktopMode;
pf_sfVideoMode_GetMode sfVideoMode_GetMode; pf_sfVideoMode_GetMode sfVideoMode_GetMode;
pf_sfVideoMode_GetModesCount sfVideoMode_GetModesCount; pf_sfVideoMode_GetModesCount sfVideoMode_GetModesCount;
pf_sfVideoMode_IsValid sfVideoMode_IsValid; pf_sfVideoMode_IsValid sfVideoMode_IsValid;
} }
static this() static this()
@ -122,11 +122,11 @@ static this()
DllLoader dll = DllLoader.load("csfml-window-d"); DllLoader dll = DllLoader.load("csfml-window-d");
else else
DllLoader dll = DllLoader.load("csfml-window"); DllLoader dll = DllLoader.load("csfml-window");
sfVideoMode_GetDesktopMode = cast(pf_sfVideoMode_GetDesktopMode)dll.getSymbol("sfVideoMode_GetDesktopMode"); sfVideoMode_GetDesktopMode = cast(pf_sfVideoMode_GetDesktopMode)dll.getSymbol("sfVideoMode_GetDesktopMode");
sfVideoMode_GetMode = cast(pf_sfVideoMode_GetMode)dll.getSymbol("sfVideoMode_GetMode"); sfVideoMode_GetMode = cast(pf_sfVideoMode_GetMode)dll.getSymbol("sfVideoMode_GetMode");
sfVideoMode_GetModesCount = cast(pf_sfVideoMode_GetModesCount)dll.getSymbol("sfVideoMode_GetModesCount"); sfVideoMode_GetModesCount = cast(pf_sfVideoMode_GetModesCount)dll.getSymbol("sfVideoMode_GetModesCount");
sfVideoMode_IsValid = cast(pf_sfVideoMode_IsValid)dll.getSymbol("sfVideoMode_IsValid"); sfVideoMode_IsValid = cast(pf_sfVideoMode_IsValid)dll.getSymbol("sfVideoMode_IsValid");
} }

View file

@ -1,27 +1,27 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.window; module dsfml.window.window;
@ -36,15 +36,15 @@ import dsfml.system.stringutil;
/** /**
* Window style * Window style
*/ */
enum Style enum Style
{ {
NONE = 0, /// No border / title bar (this flag and all others are mutually exclusive) NONE = 0, /// No border / title bar (this flag and all others are mutually exclusive)
TITLEBAR = 1 << 0, /// Title bar + fixed border TITLEBAR = 1 << 0, /// Title bar + fixed border
RESIZE = 1 << 1, /// Titlebar + resizable border + maximize button RESIZE = 1 << 1, /// Titlebar + resizable border + maximize button
CLOSE = 1 << 2, /// Titlebar + close button CLOSE = 1 << 2, /// Titlebar + close button
FULLSCREEN = 1 << 3 /// Fullscreen mode (this flag and all others are mutually exclusive) FULLSCREEN = 1 << 3 /// Fullscreen mode (this flag and all others are mutually exclusive)
} }
@ -53,412 +53,412 @@ enum Style
*/ */
struct ContextSettings struct ContextSettings
{ {
uint DepthBits = 24; /// Bits of the depth buffer uint DepthBits = 24; /// Bits of the depth buffer
uint StencilBits = 8; /// Bits of the stencil buffer uint StencilBits = 8; /// Bits of the stencil buffer
uint AntialiasingLevel = 0; /// Level of antialiasing uint AntialiasingLevel = 0; /// Level of antialiasing
uint MajorVersion = 3; /// Major number of the context version to create uint MajorVersion = 3; /// Major number of the context version to create
uint MinorVersion = 0; /// Minor number of the context version to create uint MinorVersion = 0; /// Minor number of the context version to create
} }
/** /**
* Window is a rendering window ; it can create a new window * Window is a rendering window ; it can create a new window
* or connect to an existing one * or connect to an existing one
*/ */
class Window : DSFMLObject class Window : DSFMLObject
{ {
/** /**
* Construct a new window * Construct a new window
* *
* Params: * Params:
* mode = Video mode to use * mode = Video mode to use
* title = Title of the window * title = Title of the window
* windowStyle = Window style (Resize | Close by default) * windowStyle = Window style (Resize | Close by default)
* settings = Context settings (default is default ContextSettings values) * settings = Context settings (default is default ContextSettings values)
*/ */
this(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings()) this(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
{ {
super(sfWindow_Create(mode, toStringz(title), windowStyle, settings)); super(sfWindow_Create(mode, toStringz(title), windowStyle, settings));
} }
/** /**
* Construct the window from an existing control * Construct the window from an existing control
* *
* Params: * Params:
* handle = Platform-specific handle of the control * handle = Platform-specific handle of the control
* settings = Context settings (default is default ContextSettings values) * settings = Context settings (default is default ContextSettings values)
*/ */
this(WindowHandle handle, ContextSettings settings = ContextSettings()) this(WindowHandle handle, ContextSettings settings = ContextSettings())
{ {
super(sfWindow_CreateFromHandle(handle, settings)); super(sfWindow_CreateFromHandle(handle, settings));
} }
override void dispose() override void dispose()
{ {
m_input = null; m_input = null;
sfWindow_Destroy(m_ptr); sfWindow_Destroy(m_ptr);
} }
/** /**
* Create (or recreate) the window * Create (or recreate) the window
* *
* Input created with getInput becomes invalid. * Input created with getInput becomes invalid.
* *
* Params: * Params:
* mode = Video mode to use * mode = Video mode to use
* title = Title of the window * title = Title of the window
* windowStyle = Window style (Resize | Close by default) * windowStyle = Window style (Resize | Close by default)
* settings = Context settings (default is default ContextSettings values) * settings = Context settings (default is default ContextSettings values)
*/ */
void create(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings()) void create(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
{ {
if (m_ptr !is null) if (m_ptr !is null)
dispose(); 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 * Create (or recreate) the window from an existing control
* *
* Input created with getInput becomes invalid. * Input created with getInput becomes invalid.
* *
* Params: * Params:
* handle = Platform-specific handle of the control * handle = Platform-specific handle of the control
* settings = Context settings (default is default ContextSettings values) * settings = Context settings (default is default ContextSettings values)
*/ */
void create(WindowHandle handle, ContextSettings settings = ContextSettings()) void create(WindowHandle handle, ContextSettings settings = ContextSettings())
{ {
if (m_ptr !is null) if (m_ptr !is null)
dispose(); dispose();
m_ptr = sfWindow_CreateFromHandle(handle, settings); m_ptr = sfWindow_CreateFromHandle(handle, settings);
} }
/** /**
* Close (destroy) the window. * Close (destroy) the window.
* You can call create to recreate a valid window * You can call create to recreate a valid window
*/ */
void close() void close()
{ {
sfWindow_Close(m_ptr); sfWindow_Close(m_ptr);
} }
/** /**
* Tell whether or not a window is opened * Tell whether or not a window is opened
* *
* Returns: * Returns:
* True if window is currently open. * True if window is currently open.
*/ */
bool isOpened() bool isOpened()
{ {
return cast(bool) sfWindow_IsOpened(m_ptr); return cast(bool) sfWindow_IsOpened(m_ptr);
} }
/** /**
* Get the width of the rendering region of the window * Get the width of the rendering region of the window
* *
* Returns: * Returns:
* Width in pixels * Width in pixels
*/ */
uint getWidth() uint getWidth()
{ {
return sfWindow_GetWidth(m_ptr); return sfWindow_GetWidth(m_ptr);
} }
/** /**
* Get the height of the rendering region of the window * Get the height of the rendering region of the window
* *
* Returns: * Returns:
* Height in pixels * Height in pixels
*/ */
uint getHeight() uint getHeight()
{ {
return sfWindow_GetHeight(m_ptr); return sfWindow_GetHeight(m_ptr);
} }
/** /**
* Get the creation settings of a window * Get the creation settings of a window
* *
* Returns: * Returns:
* Settings used to create the window * Settings used to create the window
*/ */
ContextSettings getSettings() ContextSettings getSettings()
{ {
return sfWindow_GetSettings(m_ptr); return sfWindow_GetSettings(m_ptr);
} }
/** /**
* Get the event on top of events stack, if any, and pop it * Get the event on top of events stack, if any, and pop it
* *
* Params: * Params:
* eventReceived = Event to fill, if any * eventReceived = Event to fill, if any
* *
* Returns: * Returns:
* True if an event was returned, false if events stack was empty * True if an event was returned, false if events stack was empty
*/ */
bool getEvent(ref Event eventReceived) bool getEvent(ref Event eventReceived)
{ {
return cast(bool)sfWindow_GetEvent(m_ptr, &eventReceived); return cast(bool)sfWindow_GetEvent(m_ptr, &eventReceived);
} }
/** /**
* Enable / disable vertical synchronization * Enable / disable vertical synchronization
* *
* Params: * Params:
* enabled : True to enable v-sync, false to deactivate * enabled : True to enable v-sync, false to deactivate
*/ */
void useVerticalSync(bool enabled) void useVerticalSync(bool enabled)
{ {
sfWindow_UseVerticalSync(m_ptr, enabled); sfWindow_UseVerticalSync(m_ptr, enabled);
} }
/** /**
* Show or hide the mouse cursor * Show or hide the mouse cursor
* *
* Params: * Params:
* show : True to show, false to hide * show : True to show, false to hide
*/ */
void showMouseCursor(bool show) void showMouseCursor(bool show)
{ {
sfWindow_ShowMouseCursor(m_ptr, show); sfWindow_ShowMouseCursor(m_ptr, show);
} }
/** /**
* Change the position of the mouse cursor * Change the position of the mouse cursor
* *
* Params: * Params:
* left = Left coordinate of the cursor, relative to the window * left = Left coordinate of the cursor, relative to the window
* top = Top coordinate of the cursor, relative to the window * top = Top coordinate of the cursor, relative to the window
*/ */
void setCursorPosition(uint left, uint top) void setCursorPosition(uint left, uint top)
{ {
sfWindow_SetCursorPosition(m_ptr, left, top); sfWindow_SetCursorPosition(m_ptr, left, top);
} }
/** /**
* Change the position of the window on screen. * Change the position of the window on screen.
* Only works for top-level windows * Only works for top-level windows
* *
* Params: * Params:
* left = Left position * left = Left position
* top = Top position * top = Top position
*/ */
void setPosition(int left, int top) void setPosition(int left, int top)
{ {
sfWindow_SetPosition(m_ptr, left, top); sfWindow_SetPosition(m_ptr, left, top);
} }
/** /**
* change the size of the rendering region of the window * change the size of the rendering region of the window
* *
* Params: * Params:
* width : new width * width : new width
* height : new height * height : new height
*/ */
void setSize(uint width, uint height) void setSize(uint width, uint height)
{ {
sfWindow_SetSize(m_ptr, width, height); sfWindow_SetSize(m_ptr, width, height);
} }
/** /**
* Show or hide the window * Show or hide the window
* *
* Params: * Params:
* state = True to show, false to hide * state = True to show, false to hide
* *
*/ */
void show(bool state) void show(bool state)
{ {
sfWindow_Show(m_ptr, state); sfWindow_Show(m_ptr, state);
} }
/** /**
* Enable or disable automatic key-repeat for keydown events. * Enable or disable automatic key-repeat for keydown events.
* Automatic key-repeat is enabled by default. * Automatic key-repeat is enabled by default.
* *
* Params: * Params:
* enabled = true to enable, false to disable * enabled = true to enable, false to disable
*/ */
void enableKeyRepeat(bool enabled) void enableKeyRepeat(bool enabled)
{ {
sfWindow_EnableKeyRepeat(m_ptr, enabled); sfWindow_EnableKeyRepeat(m_ptr, enabled);
} }
/** /**
* Change the window's icon * Change the window's icon
* *
* Params: * Params:
* width = Icon's width, in pixels * width = Icon's width, in pixels
* height = Icon's height, in pixels * height = Icon's height, in pixels
* data = array of pixels in memory, format must be RGBA 32 bits * data = array of pixels in memory, format must be RGBA 32 bits
* *
*/ */
void setIcon(size_t width, size_t height, ubyte[] data) void setIcon(size_t width, size_t height, ubyte[] data)
{ {
sfWindow_SetIcon(m_ptr, width, height, data.ptr); sfWindow_SetIcon(m_ptr, width, height, data.ptr);
} }
/** /**
* Set the window as the current target for rendering * Set the window as the current target for rendering
* *
* Params: * Params:
* active = True to activate, false to deactivate * active = True to activate, false to deactivate
* Returns: * Returns:
* True if operation was successful, false otherwise * True if operation was successful, false otherwise
*/ */
bool setActive(bool active = true) bool setActive(bool active = true)
{ {
return cast(bool)sfWindow_SetActive(m_ptr, active); return cast(bool)sfWindow_SetActive(m_ptr, active);
} }
/** /**
* Display the window on screen * Display the window on screen
*/ */
void display() void display()
{ {
sfWindow_Display(m_ptr); sfWindow_Display(m_ptr);
} }
/** /**
* Get the input manager of the window * Get the input manager of the window
* *
* Returns: * Returns:
* An input manager * An input manager
* See_Also : * See_Also :
* Input * Input
*/ */
Input getInput() Input getInput()
{ {
if (m_input is null) if (m_input is null)
m_input = new Input(sfWindow_GetInput(m_ptr)); m_input = new Input(sfWindow_GetInput(m_ptr));
return m_input; return m_input;
} }
/** /**
* Limit the framerate to a maximum fixed frequency * Limit the framerate to a maximum fixed frequency
* *
* Params: * Params:
* limit : Framerate limit, in frames per seconds (use 0 to disable limit) * limit : Framerate limit, in frames per seconds (use 0 to disable limit)
*/ */
void setFramerateLimit(uint limit) void setFramerateLimit(uint limit)
{ {
sfWindow_SetFramerateLimit(m_ptr, limit); sfWindow_SetFramerateLimit(m_ptr, limit);
} }
/** /**
* Get time elapsed since last frame * Get time elapsed since last frame
* *
* Returns: * Returns:
* Time elapsed, in seconds * Time elapsed, in seconds
*/ */
float getFrameTime() float getFrameTime()
{ {
return sfWindow_GetFrameTime(m_ptr); return sfWindow_GetFrameTime(m_ptr);
} }
/** /**
* Change the joystick threshold, ie. the value below which * Change the joystick threshold, ie. the value below which
* no move event will be generated * no move event will be generated
* *
* Params: * Params:
* threshold : New threshold, in range [0, 100] * threshold : New threshold, in range [0, 100]
*/ */
void setJoystickThreshold(float threshold) void setJoystickThreshold(float threshold)
{ {
sfWindow_SetJoystickThreshold(m_ptr, threshold); sfWindow_SetJoystickThreshold(m_ptr, threshold);
} }
protected: protected:
this(void* ptr) this(void* ptr)
{ {
super(ptr); super(ptr);
} }
Input m_input; Input m_input;
private: private:
// External ==================================================================== // External ====================================================================
extern (C) extern (C)
{ {
typedef void* function(VideoMode, cchar*, uint, ContextSettings) pf_sfWindow_Create; typedef void* function(VideoMode, cchar*, uint, ContextSettings) pf_sfWindow_Create;
typedef void* function(WindowHandle, ContextSettings) pf_sfWindow_CreateFromHandle; typedef void* function(WindowHandle, ContextSettings) pf_sfWindow_CreateFromHandle;
typedef void function(void*) pf_sfWindow_Destroy; typedef void function(void*) pf_sfWindow_Destroy;
typedef void function(void*) pf_sfWindow_Close; typedef void function(void*) pf_sfWindow_Close;
typedef int function(void*) pf_sfWindow_IsOpened; typedef int function(void*) pf_sfWindow_IsOpened;
typedef uint function(void*) pf_sfWindow_GetWidth; typedef uint function(void*) pf_sfWindow_GetWidth;
typedef uint function(void*) pf_sfWindow_GetHeight; typedef uint function(void*) pf_sfWindow_GetHeight;
typedef ContextSettings function(void* Window) pf_sfWindow_GetSettings; typedef ContextSettings function(void* Window) pf_sfWindow_GetSettings;
typedef int function(void*, Event*) pf_sfWindow_GetEvent; typedef int function(void*, Event*) pf_sfWindow_GetEvent;
typedef void function(void*, int) pf_sfWindow_UseVerticalSync; typedef void function(void*, int) pf_sfWindow_UseVerticalSync;
typedef void function(void*, int) pf_sfWindow_ShowMouseCursor; typedef void function(void*, int) pf_sfWindow_ShowMouseCursor;
typedef void function(void*, uint, uint) pf_sfWindow_SetCursorPosition; typedef void function(void*, uint, uint) pf_sfWindow_SetCursorPosition;
typedef void function(void*, int, int) pf_sfWindow_SetPosition; typedef void function(void*, int, int) pf_sfWindow_SetPosition;
typedef void function(void*, uint, uint) pf_sfWindow_SetSize; typedef void function(void*, uint, uint) pf_sfWindow_SetSize;
typedef void function(void*, int) pf_sfWindow_Show; typedef void function(void*, int) pf_sfWindow_Show;
typedef void function(void*, int) pf_sfWindow_EnableKeyRepeat; typedef void function(void*, int) pf_sfWindow_EnableKeyRepeat;
typedef void function(void*, size_t, size_t, ubyte*) pf_sfWindow_SetIcon; typedef void function(void*, size_t, size_t, ubyte*) pf_sfWindow_SetIcon;
typedef int function(void*, int) pf_sfWindow_SetActive; typedef int function(void*, int) pf_sfWindow_SetActive;
typedef void function(void*) pf_sfWindow_Display; typedef void function(void*) pf_sfWindow_Display;
typedef void* function(void*) pf_sfWindow_GetInput; typedef void* function(void*) pf_sfWindow_GetInput;
typedef void function(void*, uint) pf_sfWindow_SetFramerateLimit; typedef void function(void*, uint) pf_sfWindow_SetFramerateLimit;
typedef float function(void*) pf_sfWindow_GetFrameTime; typedef float function(void*) pf_sfWindow_GetFrameTime;
typedef void function(void*, float) pf_sfWindow_SetJoystickThreshold; typedef void function(void*, float) pf_sfWindow_SetJoystickThreshold;
static pf_sfWindow_Create sfWindow_Create; static pf_sfWindow_Create sfWindow_Create;
static pf_sfWindow_CreateFromHandle sfWindow_CreateFromHandle; static pf_sfWindow_CreateFromHandle sfWindow_CreateFromHandle;
static pf_sfWindow_Destroy sfWindow_Destroy; static pf_sfWindow_Destroy sfWindow_Destroy;
static pf_sfWindow_Close sfWindow_Close; static pf_sfWindow_Close sfWindow_Close;
static pf_sfWindow_IsOpened sfWindow_IsOpened; static pf_sfWindow_IsOpened sfWindow_IsOpened;
static pf_sfWindow_GetWidth sfWindow_GetWidth; static pf_sfWindow_GetWidth sfWindow_GetWidth;
static pf_sfWindow_GetHeight sfWindow_GetHeight; static pf_sfWindow_GetHeight sfWindow_GetHeight;
static pf_sfWindow_GetSettings sfWindow_GetSettings; static pf_sfWindow_GetSettings sfWindow_GetSettings;
static pf_sfWindow_GetEvent sfWindow_GetEvent; static pf_sfWindow_GetEvent sfWindow_GetEvent;
static pf_sfWindow_UseVerticalSync sfWindow_UseVerticalSync; static pf_sfWindow_UseVerticalSync sfWindow_UseVerticalSync;
static pf_sfWindow_ShowMouseCursor sfWindow_ShowMouseCursor; static pf_sfWindow_ShowMouseCursor sfWindow_ShowMouseCursor;
static pf_sfWindow_SetCursorPosition sfWindow_SetCursorPosition; static pf_sfWindow_SetCursorPosition sfWindow_SetCursorPosition;
static pf_sfWindow_SetPosition sfWindow_SetPosition; static pf_sfWindow_SetPosition sfWindow_SetPosition;
static pf_sfWindow_SetSize sfWindow_SetSize; static pf_sfWindow_SetSize sfWindow_SetSize;
static pf_sfWindow_Show sfWindow_Show; static pf_sfWindow_Show sfWindow_Show;
static pf_sfWindow_EnableKeyRepeat sfWindow_EnableKeyRepeat; static pf_sfWindow_EnableKeyRepeat sfWindow_EnableKeyRepeat;
static pf_sfWindow_SetIcon sfWindow_SetIcon; static pf_sfWindow_SetIcon sfWindow_SetIcon;
static pf_sfWindow_SetActive sfWindow_SetActive; static pf_sfWindow_SetActive sfWindow_SetActive;
static pf_sfWindow_Display sfWindow_Display; static pf_sfWindow_Display sfWindow_Display;
static pf_sfWindow_GetInput sfWindow_GetInput; static pf_sfWindow_GetInput sfWindow_GetInput;
static pf_sfWindow_SetFramerateLimit sfWindow_SetFramerateLimit; static pf_sfWindow_SetFramerateLimit sfWindow_SetFramerateLimit;
static pf_sfWindow_GetFrameTime sfWindow_GetFrameTime; static pf_sfWindow_GetFrameTime sfWindow_GetFrameTime;
static pf_sfWindow_SetJoystickThreshold sfWindow_SetJoystickThreshold; static pf_sfWindow_SetJoystickThreshold sfWindow_SetJoystickThreshold;
} }
static this() static this()
{ {
debug debug
DllLoader dll = DllLoader.load("csfml-window-d"); DllLoader dll = DllLoader.load("csfml-window-d");
else else
DllLoader dll = DllLoader.load("csfml-window"); DllLoader dll = DllLoader.load("csfml-window");
sfWindow_Create = cast(pf_sfWindow_Create)dll.getSymbol("sfWindow_Create"); sfWindow_Create = cast(pf_sfWindow_Create)dll.getSymbol("sfWindow_Create");
sfWindow_CreateFromHandle = cast(pf_sfWindow_CreateFromHandle)dll.getSymbol("sfWindow_CreateFromHandle"); sfWindow_CreateFromHandle = cast(pf_sfWindow_CreateFromHandle)dll.getSymbol("sfWindow_CreateFromHandle");
sfWindow_Destroy = cast(pf_sfWindow_Destroy)dll.getSymbol("sfWindow_Destroy"); sfWindow_Destroy = cast(pf_sfWindow_Destroy)dll.getSymbol("sfWindow_Destroy");
sfWindow_Close = cast(pf_sfWindow_Close)dll.getSymbol("sfWindow_Close"); sfWindow_Close = cast(pf_sfWindow_Close)dll.getSymbol("sfWindow_Close");
sfWindow_IsOpened = cast(pf_sfWindow_IsOpened)dll.getSymbol("sfWindow_IsOpened"); sfWindow_IsOpened = cast(pf_sfWindow_IsOpened)dll.getSymbol("sfWindow_IsOpened");
sfWindow_GetWidth = cast(pf_sfWindow_GetWidth)dll.getSymbol("sfWindow_GetWidth"); sfWindow_GetWidth = cast(pf_sfWindow_GetWidth)dll.getSymbol("sfWindow_GetWidth");
sfWindow_GetHeight = cast(pf_sfWindow_GetHeight)dll.getSymbol("sfWindow_GetHeight"); sfWindow_GetHeight = cast(pf_sfWindow_GetHeight)dll.getSymbol("sfWindow_GetHeight");
sfWindow_GetSettings = cast(pf_sfWindow_GetSettings)dll.getSymbol("sfWindow_GetSettings"); sfWindow_GetSettings = cast(pf_sfWindow_GetSettings)dll.getSymbol("sfWindow_GetSettings");
sfWindow_GetEvent = cast(pf_sfWindow_GetEvent)dll.getSymbol("sfWindow_GetEvent"); sfWindow_GetEvent = cast(pf_sfWindow_GetEvent)dll.getSymbol("sfWindow_GetEvent");
sfWindow_UseVerticalSync = cast(pf_sfWindow_UseVerticalSync)dll.getSymbol("sfWindow_UseVerticalSync"); sfWindow_UseVerticalSync = cast(pf_sfWindow_UseVerticalSync)dll.getSymbol("sfWindow_UseVerticalSync");
sfWindow_ShowMouseCursor = cast(pf_sfWindow_ShowMouseCursor)dll.getSymbol("sfWindow_ShowMouseCursor"); sfWindow_ShowMouseCursor = cast(pf_sfWindow_ShowMouseCursor)dll.getSymbol("sfWindow_ShowMouseCursor");
sfWindow_SetCursorPosition = cast(pf_sfWindow_SetCursorPosition)dll.getSymbol("sfWindow_SetCursorPosition"); sfWindow_SetCursorPosition = cast(pf_sfWindow_SetCursorPosition)dll.getSymbol("sfWindow_SetCursorPosition");
sfWindow_SetPosition = cast(pf_sfWindow_SetPosition)dll.getSymbol("sfWindow_SetPosition"); sfWindow_SetPosition = cast(pf_sfWindow_SetPosition)dll.getSymbol("sfWindow_SetPosition");
sfWindow_SetSize = cast(pf_sfWindow_SetSize)dll.getSymbol("sfWindow_SetSize"); sfWindow_SetSize = cast(pf_sfWindow_SetSize)dll.getSymbol("sfWindow_SetSize");
sfWindow_Show = cast(pf_sfWindow_Show)dll.getSymbol("sfWindow_Show"); sfWindow_Show = cast(pf_sfWindow_Show)dll.getSymbol("sfWindow_Show");
sfWindow_EnableKeyRepeat = cast(pf_sfWindow_EnableKeyRepeat)dll.getSymbol("sfWindow_EnableKeyRepeat"); sfWindow_EnableKeyRepeat = cast(pf_sfWindow_EnableKeyRepeat)dll.getSymbol("sfWindow_EnableKeyRepeat");
sfWindow_SetIcon = cast(pf_sfWindow_SetIcon)dll.getSymbol("sfWindow_SetIcon"); sfWindow_SetIcon = cast(pf_sfWindow_SetIcon)dll.getSymbol("sfWindow_SetIcon");
sfWindow_SetActive = cast(pf_sfWindow_SetActive)dll.getSymbol("sfWindow_SetActive"); sfWindow_SetActive = cast(pf_sfWindow_SetActive)dll.getSymbol("sfWindow_SetActive");
sfWindow_Display = cast(pf_sfWindow_Display)dll.getSymbol("sfWindow_Display"); sfWindow_Display = cast(pf_sfWindow_Display)dll.getSymbol("sfWindow_Display");
sfWindow_GetInput = cast(pf_sfWindow_GetInput)dll.getSymbol("sfWindow_GetInput"); sfWindow_GetInput = cast(pf_sfWindow_GetInput)dll.getSymbol("sfWindow_GetInput");
sfWindow_SetFramerateLimit = cast(pf_sfWindow_SetFramerateLimit)dll.getSymbol("sfWindow_SetFramerateLimit"); sfWindow_SetFramerateLimit = cast(pf_sfWindow_SetFramerateLimit)dll.getSymbol("sfWindow_SetFramerateLimit");
sfWindow_GetFrameTime = cast(pf_sfWindow_GetFrameTime)dll.getSymbol("sfWindow_GetFrameTime"); sfWindow_GetFrameTime = cast(pf_sfWindow_GetFrameTime)dll.getSymbol("sfWindow_GetFrameTime");
sfWindow_SetJoystickThreshold = cast(pf_sfWindow_SetJoystickThreshold)dll.getSymbol("sfWindow_SetJoystickThreshold"); sfWindow_SetJoystickThreshold = cast(pf_sfWindow_SetJoystickThreshold)dll.getSymbol("sfWindow_SetJoystickThreshold");
} }
} }

View file

@ -1,34 +1,34 @@
/* /*
* DSFML - SFML Library wrapper for the D programming language. * DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com) * Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt * Copyright (C) 2010 Andreas Hollandt
* *
* This software is provided 'as-is', without any express or * This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held * implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software. * liable for any damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute * including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions: * it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; * 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software. * you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment * If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but * in the product documentation would be appreciated but
* is not required. * is not required.
* *
* 2. Altered source versions must be plainly marked as such, * 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software. * and must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
module dsfml.window.windowhandle; module dsfml.window.windowhandle;
/** /**
* Define a low-level window handle type, specific to * Define a low-level window handle type, specific to
* each platform * each platform
*/ */
version(Windows) version(Windows)
{ {
@ -37,7 +37,7 @@ version(Windows)
} }
else version(linux) else version(linux)
{ {
// Unix - X11 defines an unsigned integer handle (Window) // Unix - X11 defines an unsigned integer handle (Window)
typedef ulong WindowHandle; typedef ulong WindowHandle;
} }