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:
parent
8431753ba3
commit
2f2fc5d4fa
|
@ -1,37 +1,37 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.all;
|
||||
|
||||
public import
|
||||
dsfml.audio.listener,
|
||||
dsfml.audio.music,
|
||||
dsfml.audio.sound,
|
||||
dsfml.audio.soundbuffer,
|
||||
dsfml.audio.soundbufferrecorder,
|
||||
dsfml.audio.soundrecorder,
|
||||
dsfml.audio.soundstatus,
|
||||
dsfml.audio.soundstream;
|
||||
dsfml.audio.listener,
|
||||
dsfml.audio.music,
|
||||
dsfml.audio.sound,
|
||||
dsfml.audio.soundbuffer,
|
||||
dsfml.audio.soundbufferrecorder,
|
||||
dsfml.audio.soundrecorder,
|
||||
dsfml.audio.soundstatus,
|
||||
dsfml.audio.soundstream;
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.listener;
|
||||
|
@ -30,122 +30,122 @@ import dsfml.system.common;
|
|||
import dsfml.system.vector3;
|
||||
|
||||
/**
|
||||
* Listener is a global interface for defining the audio
|
||||
* listener properties ; the audio listener is the point in
|
||||
* the scene from where all the sounds are heard.
|
||||
*
|
||||
* See_Also:
|
||||
* SFML Tutorial for sound spatialization example.
|
||||
* Listener is a global interface for defining the audio
|
||||
* listener properties ; the audio listener is the point in
|
||||
* the scene from where all the sounds are heard.
|
||||
*
|
||||
* See_Also:
|
||||
* SFML Tutorial for sound spatialization example.
|
||||
*/
|
||||
class Listener
|
||||
{
|
||||
|
||||
/**
|
||||
* Change the global volume of all the sounds.
|
||||
* The default volume is 100
|
||||
*
|
||||
* Params:
|
||||
* volume = New global volume, in the range [0, 100]
|
||||
*/
|
||||
static void setGlobalVolume(float volume)
|
||||
in
|
||||
{
|
||||
assert (volume >= 0.f && volume <= 100.f);
|
||||
}
|
||||
body
|
||||
/**
|
||||
* Change the global volume of all the sounds.
|
||||
* The default volume is 100
|
||||
*
|
||||
* Params:
|
||||
* volume = New global volume, in the range [0, 100]
|
||||
*/
|
||||
static void setGlobalVolume(float volume)
|
||||
in
|
||||
{
|
||||
assert (volume >= 0.f && volume <= 100.f);
|
||||
}
|
||||
body
|
||||
{
|
||||
sfListener_SetGlobalVolume(volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value of the global volume of all the sounds
|
||||
*
|
||||
* Returns:
|
||||
* Current global volume, in the range [0, 100]
|
||||
*/
|
||||
static float getGlobalVolume()
|
||||
/**
|
||||
* Get the current value of the global volume of all the sounds
|
||||
*
|
||||
* Returns:
|
||||
* Current global volume, in the range [0, 100]
|
||||
*/
|
||||
static float getGlobalVolume()
|
||||
{
|
||||
return sfListener_GetGlobalVolume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the position of the listener.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* posX = X 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
|
||||
*/
|
||||
static void setPosition(float posX, float posY, float posZ)
|
||||
/**
|
||||
* Change the position of the listener.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* posX = X 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
|
||||
*/
|
||||
static void setPosition(float posX, float posY, float posZ)
|
||||
{
|
||||
sfListener_SetPosition(posX, posY, posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the position of the listener.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* position = new position
|
||||
*/
|
||||
static void setPosition(Vector3f position)
|
||||
/**
|
||||
* Change the position of the listener.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* position = new position
|
||||
*/
|
||||
static void setPosition(Vector3f position)
|
||||
{
|
||||
sfListener_SetPosition(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current position of the listener
|
||||
*
|
||||
* Returns:
|
||||
* Current position
|
||||
*/
|
||||
static Vector3f getPosition()
|
||||
/**
|
||||
* Get the current position of the listener
|
||||
*
|
||||
* Returns:
|
||||
* Current position
|
||||
*/
|
||||
static Vector3f getPosition()
|
||||
{
|
||||
Vector3f ret;
|
||||
Vector3f ret;
|
||||
sfListener_GetPosition(&ret.x, &ret.y, &ret.z);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the orientation of the listener (the point
|
||||
* he must look at).
|
||||
* The default target is (0, 0, -1)
|
||||
*
|
||||
* Params:
|
||||
* targetX = 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
|
||||
*/
|
||||
static void setTarget(float targetX, float targetY, float targetZ)
|
||||
/**
|
||||
* Change the orientation of the listener (the point
|
||||
* he must look at).
|
||||
* The default target is (0, 0, -1)
|
||||
*
|
||||
* Params:
|
||||
* targetX = 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
|
||||
*/
|
||||
static void setTarget(float targetX, float targetY, float targetZ)
|
||||
{
|
||||
sfListener_SetTarget(targetX, targetY, targetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the orientation of the listener (the point
|
||||
* he must look at).
|
||||
* The default target is (0, 0, -1)
|
||||
*
|
||||
* Params:
|
||||
* target = Position of the point the listener must look at
|
||||
*/
|
||||
static void setTarget(Vector3f position)
|
||||
/**
|
||||
* Change the orientation of the listener (the point
|
||||
* he must look at).
|
||||
* The default target is (0, 0, -1)
|
||||
*
|
||||
* Params:
|
||||
* target = Position of the point the listener must look at
|
||||
*/
|
||||
static void setTarget(Vector3f position)
|
||||
{
|
||||
sfListener_SetTarget(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current orientation of the listener (the point
|
||||
* he's looking at)
|
||||
*
|
||||
* Returns:
|
||||
* Position of the point the listener is looking at
|
||||
*/
|
||||
static Vector3f getTarget()
|
||||
/**
|
||||
* Get the current orientation of the listener (the point
|
||||
* he's looking at)
|
||||
*
|
||||
* Returns:
|
||||
* Position of the point the listener is looking at
|
||||
*/
|
||||
static Vector3f getTarget()
|
||||
{
|
||||
Vector3f ret;
|
||||
Vector3f ret;
|
||||
sfListener_GetTarget(&ret.x, &ret.y, &ret.z);
|
||||
return ret;
|
||||
}
|
||||
|
@ -154,35 +154,35 @@ private:
|
|||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(float) pf_sfListener_SetGlobalVolume;
|
||||
typedef float function() pf_sfListener_GetGlobalVolume;
|
||||
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_SetTarget;
|
||||
typedef void function(float*, float*, float*) pf_sfListener_GetTarget;
|
||||
|
||||
static pf_sfListener_SetGlobalVolume sfListener_SetGlobalVolume;
|
||||
static pf_sfListener_GetGlobalVolume sfListener_GetGlobalVolume;
|
||||
static pf_sfListener_SetPosition sfListener_SetPosition;
|
||||
static pf_sfListener_GetPosition sfListener_GetPosition;
|
||||
static pf_sfListener_SetTarget sfListener_SetTarget;
|
||||
static pf_sfListener_GetTarget sfListener_GetTarget;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(float) pf_sfListener_SetGlobalVolume;
|
||||
typedef float function() pf_sfListener_GetGlobalVolume;
|
||||
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_SetTarget;
|
||||
typedef void function(float*, float*, float*) pf_sfListener_GetTarget;
|
||||
|
||||
static pf_sfListener_SetGlobalVolume sfListener_SetGlobalVolume;
|
||||
static pf_sfListener_GetGlobalVolume sfListener_GetGlobalVolume;
|
||||
static pf_sfListener_SetPosition sfListener_SetPosition;
|
||||
static pf_sfListener_GetPosition sfListener_GetPosition;
|
||||
static pf_sfListener_SetTarget sfListener_SetTarget;
|
||||
static pf_sfListener_GetTarget sfListener_GetTarget;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-audio-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-audio");
|
||||
|
||||
sfListener_SetGlobalVolume = cast(pf_sfListener_SetGlobalVolume)dll.getSymbol("sfListener_SetGlobalVolume");
|
||||
sfListener_GetGlobalVolume = cast(pf_sfListener_GetGlobalVolume)dll.getSymbol("sfListener_GetGlobalVolume");
|
||||
sfListener_SetPosition = cast(pf_sfListener_SetPosition)dll.getSymbol("sfListener_SetPosition");
|
||||
sfListener_GetPosition = cast(pf_sfListener_GetPosition)dll.getSymbol("sfListener_GetPosition");
|
||||
sfListener_SetTarget = cast(pf_sfListener_SetTarget)dll.getSymbol("sfListener_SetTarget");
|
||||
sfListener_GetTarget = cast(pf_sfListener_GetTarget)dll.getSymbol("sfListener_GetTarget");
|
||||
}
|
||||
|
||||
sfListener_SetGlobalVolume = cast(pf_sfListener_SetGlobalVolume)dll.getSymbol("sfListener_SetGlobalVolume");
|
||||
sfListener_GetGlobalVolume = cast(pf_sfListener_GetGlobalVolume)dll.getSymbol("sfListener_GetGlobalVolume");
|
||||
sfListener_SetPosition = cast(pf_sfListener_SetPosition)dll.getSymbol("sfListener_SetPosition");
|
||||
sfListener_GetPosition = cast(pf_sfListener_GetPosition)dll.getSymbol("sfListener_GetPosition");
|
||||
sfListener_SetTarget = cast(pf_sfListener_SetTarget)dll.getSymbol("sfListener_SetTarget");
|
||||
sfListener_GetTarget = cast(pf_sfListener_GetTarget)dll.getSymbol("sfListener_GetTarget");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.music;
|
||||
|
@ -39,278 +39,278 @@ import dsfml.system.vector3;
|
|||
*/
|
||||
class Music : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Open a music file (doesn't play it -- call Play for that)
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the file to open
|
||||
*
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
/**
|
||||
* Open a music file (doesn't play it -- call Play for that)
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the file to open
|
||||
*
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a music file from memory (doesn't play it -- call Play() for that)
|
||||
*
|
||||
* Params:
|
||||
* data = file data in memory
|
||||
*
|
||||
*/
|
||||
this(byte[] data)
|
||||
{
|
||||
/**
|
||||
* Open a music file from memory (doesn't play it -- call Play() for that)
|
||||
*
|
||||
* Params:
|
||||
* data = file data in memory
|
||||
*
|
||||
*/
|
||||
this(byte[] data)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
override void dispose()
|
||||
{
|
||||
sfMusic_Destroy(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start playing the audio stream
|
||||
*/
|
||||
void play()
|
||||
{
|
||||
/**
|
||||
* Start playing the audio stream
|
||||
*/
|
||||
void play()
|
||||
{
|
||||
sfMusic_Play(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop playing the audio stream
|
||||
*/
|
||||
void stop()
|
||||
{
|
||||
/**
|
||||
* Stop playing the audio stream
|
||||
*/
|
||||
void stop()
|
||||
{
|
||||
sfMusic_Stop(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the audio stream
|
||||
*/
|
||||
void pause()
|
||||
{
|
||||
/**
|
||||
* Pause the audio stream
|
||||
*/
|
||||
void pause()
|
||||
{
|
||||
sfMusic_Pause(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of channels (1 = mono, 2 = stereo)
|
||||
*
|
||||
* Returns:
|
||||
* Number of channels
|
||||
*/
|
||||
uint getChannelsCount()
|
||||
{
|
||||
/**
|
||||
* Return the number of channels (1 = mono, 2 = stereo)
|
||||
*
|
||||
* Returns:
|
||||
* Number of channels
|
||||
*/
|
||||
uint getChannelsCount()
|
||||
{
|
||||
return sfMusic_GetChannelsCount(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stream sample rate
|
||||
*
|
||||
* Returns:
|
||||
* Stream frequency (number of samples per second)
|
||||
*/
|
||||
uint getSampleRate()
|
||||
{
|
||||
/**
|
||||
* Get the stream sample rate
|
||||
*
|
||||
* Returns:
|
||||
* Stream frequency (number of samples per second)
|
||||
*/
|
||||
uint getSampleRate()
|
||||
{
|
||||
return sfMusic_GetSampleRate(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the music duration
|
||||
*
|
||||
* Returns:
|
||||
* Music duration, in seconds
|
||||
*/
|
||||
float getDuration()
|
||||
{
|
||||
/**
|
||||
* Get the music duration
|
||||
*
|
||||
* Returns:
|
||||
* Music duration, in seconds
|
||||
*/
|
||||
float getDuration()
|
||||
{
|
||||
return sfMusic_GetDuration(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of the stream (stopped, paused, playing)
|
||||
*
|
||||
* Returns:
|
||||
* Current status of the sound
|
||||
*/
|
||||
SoundStatus getStatus()
|
||||
{
|
||||
/**
|
||||
* Get the status of the stream (stopped, paused, playing)
|
||||
*
|
||||
* Returns:
|
||||
* Current status of the sound
|
||||
*/
|
||||
SoundStatus getStatus()
|
||||
{
|
||||
return sfMusic_GetStatus(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell whether or not the music is looping
|
||||
*
|
||||
* Returns:
|
||||
* True if the music is looping, false otherwise
|
||||
*/
|
||||
bool getLoop()
|
||||
{
|
||||
/**
|
||||
* Tell whether or not the music is looping
|
||||
*
|
||||
* Returns:
|
||||
* True if the music is looping, false otherwise
|
||||
*/
|
||||
bool getLoop()
|
||||
{
|
||||
return cast(bool)sfMusic_GetLoop(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pitch
|
||||
*
|
||||
* Returns:
|
||||
* Pitch value
|
||||
*/
|
||||
float getPitch()
|
||||
{
|
||||
/**
|
||||
* Get the pitch
|
||||
*
|
||||
* Returns:
|
||||
* Pitch value
|
||||
*/
|
||||
float getPitch()
|
||||
{
|
||||
return sfMusic_GetPitch(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the volume
|
||||
*
|
||||
* Returns:
|
||||
* Volume value (in range [1, 100])
|
||||
*/
|
||||
float getVolume()
|
||||
{
|
||||
/**
|
||||
* Get the volume
|
||||
*
|
||||
* Returns:
|
||||
* Volume value (in range [1, 100])
|
||||
*/
|
||||
float getVolume()
|
||||
{
|
||||
return sfMusic_GetVolume(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound position
|
||||
*
|
||||
* Returns:
|
||||
* Current position of the music.
|
||||
*/
|
||||
Vector3f getPosition()
|
||||
{
|
||||
/**
|
||||
* Get the sound position
|
||||
*
|
||||
* Returns:
|
||||
* Current position of the music.
|
||||
*/
|
||||
Vector3f getPosition()
|
||||
{
|
||||
Vector3f ret;
|
||||
sfMusic_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum distance
|
||||
*
|
||||
* Returns:
|
||||
* Minimum distance for the sound
|
||||
*/
|
||||
float getMinDistance()
|
||||
{
|
||||
/**
|
||||
* Get the minimum distance
|
||||
*
|
||||
* Returns:
|
||||
* Minimum distance for the sound
|
||||
*/
|
||||
float getMinDistance()
|
||||
{
|
||||
return sfMusic_GetMinDistance(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attenuation factor
|
||||
*
|
||||
* Returns:
|
||||
* Attenuation factor of the sound
|
||||
*
|
||||
*/
|
||||
float getAttenuation()
|
||||
{
|
||||
/**
|
||||
* Get the attenuation factor
|
||||
*
|
||||
* Returns:
|
||||
* Attenuation factor of the sound
|
||||
*
|
||||
*/
|
||||
float getAttenuation()
|
||||
{
|
||||
return sfMusic_GetAttenuation(m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the music loop state.
|
||||
* This parameter is disabled by default
|
||||
*
|
||||
* Params:
|
||||
* loop = True to play in loop, false to play once
|
||||
*/
|
||||
void setLoop(bool loop)
|
||||
{
|
||||
/**
|
||||
* Set the music loop state.
|
||||
* This parameter is disabled by default
|
||||
*
|
||||
* Params:
|
||||
* loop = True to play in loop, false to play once
|
||||
*/
|
||||
void setLoop(bool loop)
|
||||
{
|
||||
sfMusic_SetLoop(m_ptr, loop);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound pitch.
|
||||
* The default pitch is 1
|
||||
*
|
||||
* Params:
|
||||
* pitch = New pitch
|
||||
*
|
||||
*/
|
||||
void setPitch(float pitch)
|
||||
{
|
||||
/**
|
||||
* Set the sound pitch.
|
||||
* The default pitch is 1
|
||||
*
|
||||
* Params:
|
||||
* pitch = New pitch
|
||||
*
|
||||
*/
|
||||
void setPitch(float pitch)
|
||||
{
|
||||
sfMusic_SetPitch(m_ptr, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound volume.
|
||||
* The default volume is 100
|
||||
*
|
||||
* Params:
|
||||
* volume = Volume (in range [0, 100])
|
||||
*
|
||||
*/
|
||||
void setVolume(float volume)
|
||||
in
|
||||
{
|
||||
/**
|
||||
* Set the sound volume.
|
||||
* The default volume is 100
|
||||
*
|
||||
* Params:
|
||||
* volume = Volume (in range [0, 100])
|
||||
*
|
||||
*/
|
||||
void setVolume(float volume)
|
||||
in
|
||||
{
|
||||
assert (volume >= 0.f && volume <= 100.f);
|
||||
}
|
||||
body
|
||||
{
|
||||
}
|
||||
body
|
||||
{
|
||||
sfMusic_SetVolume(m_ptr, volume);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* x = X 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
|
||||
*
|
||||
*/
|
||||
void setPosition(float x, float y, float z)
|
||||
{
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* x = X 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
|
||||
*
|
||||
*/
|
||||
void setPosition(float x, float y, float z)
|
||||
{
|
||||
sfMusic_SetPosition(m_ptr, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* position = new position
|
||||
*
|
||||
*/
|
||||
void setPosition(Vector3f position)
|
||||
{
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* position = new position
|
||||
*
|
||||
*/
|
||||
void setPosition(Vector3f position)
|
||||
{
|
||||
sfMusic_SetPosition(m_ptr, position.x, position.y, position.z);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum distance - closer than thsi distance
|
||||
* the listener will hear the sound at its maximum volume.
|
||||
* The default distance is 1.0
|
||||
*
|
||||
* Params:
|
||||
* minDistance = new minimum distance for the sound
|
||||
*/
|
||||
void setMinDistance(float minDistance)
|
||||
{
|
||||
/**
|
||||
* Set the minimum distance - closer than thsi distance
|
||||
* the listener will hear the sound at its maximum volume.
|
||||
* The default distance is 1.0
|
||||
*
|
||||
* Params:
|
||||
* minDistance = new minimum distance for the sound
|
||||
*/
|
||||
void setMinDistance(float minDistance)
|
||||
{
|
||||
sfMusic_SetMinDistance(m_ptr, minDistance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the attenuation factor - the higher the attenuation, the
|
||||
* more the sound will be attenuated with distance from listener.
|
||||
* The default attenuation factor 1.0
|
||||
*
|
||||
* Params:
|
||||
* attenuation = new attenuation factor for the sound
|
||||
*/
|
||||
void setAttenuation(float attenuation)
|
||||
{
|
||||
/**
|
||||
* Set the attenuation factor - the higher the attenuation, the
|
||||
* more the sound will be attenuated with distance from listener.
|
||||
* The default attenuation factor 1.0
|
||||
*
|
||||
* Params:
|
||||
* attenuation = new attenuation factor for the sound
|
||||
*/
|
||||
void setAttenuation(float attenuation)
|
||||
{
|
||||
sfMusic_SetAttenuation(m_ptr, attenuation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the music's position relative to the listener's position, or absolute.
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.sound;
|
||||
|
@ -34,39 +34,39 @@ import dsfml.system.exception;
|
|||
import dsfml.system.vector3;
|
||||
|
||||
/**
|
||||
* Sound defines the properties of the sound such as position,
|
||||
* volume, pitch, etc.
|
||||
* Sound defines the properties of the sound such as position,
|
||||
* volume, pitch, etc.
|
||||
*/
|
||||
class Sound : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSound_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the sound from its parameters
|
||||
*
|
||||
* Params:
|
||||
* buffer = Sound buffer to play
|
||||
* loop = Loop flag (false by default)
|
||||
* pitch = Value of the pitch (1 by default)
|
||||
* volume = Volume (100 by default)
|
||||
* x = X position (0 by default)
|
||||
* y = Y position (0 by default)
|
||||
* z = Z position (0 by default)
|
||||
*
|
||||
* Throws:
|
||||
* 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)
|
||||
/**
|
||||
* Construct the sound from its parameters
|
||||
*
|
||||
* Params:
|
||||
* buffer = Sound buffer to play
|
||||
* loop = Loop flag (false by default)
|
||||
* pitch = Value of the pitch (1 by default)
|
||||
* volume = Volume (100 by default)
|
||||
* x = X position (0 by default)
|
||||
* y = Y position (0 by default)
|
||||
* z = Z position (0 by default)
|
||||
*
|
||||
* Throws:
|
||||
* 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)
|
||||
{
|
||||
if (buffer is null)
|
||||
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
|
||||
|
||||
if (buffer is null)
|
||||
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
|
||||
|
||||
super(sfSound_Create());
|
||||
sfSound_SetBuffer(m_ptr, buffer.getNativePointer());
|
||||
sfSound_SetLoop(m_ptr, loop);
|
||||
|
@ -76,257 +76,257 @@ class Sound : DSFMLObject
|
|||
}
|
||||
|
||||
|
||||
override void dispose()
|
||||
override void dispose()
|
||||
{
|
||||
sfSound_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the sound
|
||||
*/
|
||||
void play()
|
||||
/**
|
||||
* Play the sound
|
||||
*/
|
||||
void play()
|
||||
{
|
||||
sfSound_Play(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the sound
|
||||
*/
|
||||
void pause()
|
||||
/**
|
||||
* Pause the sound
|
||||
*/
|
||||
void pause()
|
||||
{
|
||||
sfSound_Pause(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the sound
|
||||
*/
|
||||
void stop()
|
||||
/**
|
||||
* Stop the sound
|
||||
*/
|
||||
void stop()
|
||||
{
|
||||
sfSound_Stop(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source buffer
|
||||
*
|
||||
* Params:
|
||||
* buffer = New sound buffer to bind to the sound
|
||||
*/
|
||||
void setBuffer(SoundBuffer buffer)
|
||||
/**
|
||||
* Set the source buffer
|
||||
*
|
||||
* Params:
|
||||
* buffer = New sound buffer to bind to the sound
|
||||
*/
|
||||
void setBuffer(SoundBuffer buffer)
|
||||
{
|
||||
if (buffer is null)
|
||||
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
|
||||
|
||||
if (buffer is null)
|
||||
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
|
||||
|
||||
m_buffer = buffer;
|
||||
sfSound_SetBuffer(m_ptr, buffer.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound loop state.
|
||||
* This parameter is disabled by default
|
||||
*
|
||||
* Params:
|
||||
* loop = True to play in loop, false to play once
|
||||
*/
|
||||
void setLoop(bool loop)
|
||||
/**
|
||||
* Set the sound loop state.
|
||||
* This parameter is disabled by default
|
||||
*
|
||||
* Params:
|
||||
* loop = True to play in loop, false to play once
|
||||
*/
|
||||
void setLoop(bool loop)
|
||||
{
|
||||
sfSound_SetLoop(m_ptr, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound pitch.
|
||||
* The default pitch is 1
|
||||
*
|
||||
* Params:
|
||||
* pitch = New pitch
|
||||
*/
|
||||
void setPitch(float pitch)
|
||||
/**
|
||||
* Set the sound pitch.
|
||||
* The default pitch is 1
|
||||
*
|
||||
* Params:
|
||||
* pitch = New pitch
|
||||
*/
|
||||
void setPitch(float pitch)
|
||||
{
|
||||
sfSound_SetPitch(m_ptr, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound volume.
|
||||
* The default volume is 100
|
||||
*
|
||||
* Params:
|
||||
* volume = Volume (in range [0, 100])
|
||||
*/
|
||||
void setVolume(float volume)
|
||||
in
|
||||
{
|
||||
assert(volume >= 0 && volume <= 100);
|
||||
}
|
||||
body
|
||||
/**
|
||||
* Set the sound volume.
|
||||
* The default volume is 100
|
||||
*
|
||||
* Params:
|
||||
* volume = Volume (in range [0, 100])
|
||||
*/
|
||||
void setVolume(float volume)
|
||||
in
|
||||
{
|
||||
assert(volume >= 0 && volume <= 100);
|
||||
}
|
||||
body
|
||||
{
|
||||
sfSound_SetVolume(m_ptr, volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* x = X 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
|
||||
*/
|
||||
void setPosition(float x, float y, float z)
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params:
|
||||
* x = X 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
|
||||
*/
|
||||
void setPosition(float x, float y, float z)
|
||||
{
|
||||
sfSound_SetPosition(m_ptr, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params :
|
||||
* position = new position
|
||||
*/
|
||||
void setPosition(Vector3f position)
|
||||
{
|
||||
sfSound_SetPosition(m_ptr, position.x, position.y, position.z);
|
||||
}
|
||||
/**
|
||||
* Set the sound position.
|
||||
* The default position is (0, 0, 0)
|
||||
*
|
||||
* Params :
|
||||
* position = new position
|
||||
*/
|
||||
void setPosition(Vector3f position)
|
||||
{
|
||||
sfSound_SetPosition(m_ptr, position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum distance - closer than this distance
|
||||
* the listener will hear the sound at its maximum volume.
|
||||
* The default distance is 1.0
|
||||
*
|
||||
* Params:
|
||||
* minDistance = new minimum distance for the sound
|
||||
*/
|
||||
void setMinDistance(float minDistance)
|
||||
{
|
||||
sfSound_SetMinDistance(m_ptr, minDistance);
|
||||
}
|
||||
/**
|
||||
* Set the minimum distance - closer than this distance
|
||||
* the listener will hear the sound at its maximum volume.
|
||||
* The default distance is 1.0
|
||||
*
|
||||
* Params:
|
||||
* minDistance = new minimum distance for the sound
|
||||
*/
|
||||
void setMinDistance(float minDistance)
|
||||
{
|
||||
sfSound_SetMinDistance(m_ptr, minDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the attenuation factor - the higher the attenuation, the
|
||||
* more the sound will be attenuated with distance from listener.
|
||||
* The default attenuation factor 1.0
|
||||
*
|
||||
* Params:
|
||||
* attenuation = new attenuation factor for the sound
|
||||
*/
|
||||
void setAttenuation(float attenuation)
|
||||
{
|
||||
sfSound_SetAttenuation(m_ptr, attenuation);
|
||||
}
|
||||
/**
|
||||
* Set the attenuation factor - the higher the attenuation, the
|
||||
* more the sound will be attenuated with distance from listener.
|
||||
* The default attenuation factor 1.0
|
||||
*
|
||||
* Params:
|
||||
* attenuation = new attenuation factor for the sound
|
||||
*/
|
||||
void setAttenuation(float attenuation)
|
||||
{
|
||||
sfSound_SetAttenuation(m_ptr, attenuation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current playing offset of a sound
|
||||
*
|
||||
* Params:
|
||||
* offset = new playing position, expressed in seconds
|
||||
*/
|
||||
void setPlayingOffset(float offset)
|
||||
{
|
||||
sfSound_SetPlayingOffset(m_ptr, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current playing offset of a sound
|
||||
*
|
||||
* Params:
|
||||
* offset = new playing position, expressed in seconds
|
||||
*/
|
||||
void setPlayingOffset(float offset)
|
||||
{
|
||||
sfSound_SetPlayingOffset(m_ptr, offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the source buffer
|
||||
*
|
||||
* Returns:
|
||||
* Sound buffer bound to the sound (can be NULL)
|
||||
*/
|
||||
SoundBuffer getBuffer()
|
||||
/**
|
||||
* Get the source buffer
|
||||
*
|
||||
* Returns:
|
||||
* Sound buffer bound to the sound (can be NULL)
|
||||
*/
|
||||
SoundBuffer getBuffer()
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether or not the sound is looping
|
||||
*
|
||||
* Returns:
|
||||
* True if the sound is looping, false otherwise
|
||||
*/
|
||||
bool getLoop()
|
||||
/**
|
||||
* Tell whether or not the sound is looping
|
||||
*
|
||||
* Returns:
|
||||
* True if the sound is looping, false otherwise
|
||||
*/
|
||||
bool getLoop()
|
||||
{
|
||||
|
||||
return cast(bool)(sfSound_GetLoop(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pitch
|
||||
*
|
||||
* Returns:
|
||||
* Pitch value
|
||||
*/
|
||||
float getPitch()
|
||||
/**
|
||||
* Get the pitch
|
||||
*
|
||||
* Returns:
|
||||
* Pitch value
|
||||
*/
|
||||
float getPitch()
|
||||
{
|
||||
return sfSound_GetPitch(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the volume
|
||||
*
|
||||
* Returns:
|
||||
* Volume value (in range [1, 100])
|
||||
*/
|
||||
float getVolume()
|
||||
/**
|
||||
* Get the volume
|
||||
*
|
||||
* Returns:
|
||||
* Volume value (in range [1, 100])
|
||||
*/
|
||||
float getVolume()
|
||||
{
|
||||
return sfSound_GetVolume(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound position
|
||||
*
|
||||
* Params:
|
||||
* x = X 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
|
||||
*/
|
||||
Vector3f getPosition()
|
||||
/**
|
||||
* Get the sound position
|
||||
*
|
||||
* Params:
|
||||
* x = X 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
|
||||
*/
|
||||
Vector3f getPosition()
|
||||
{
|
||||
Vector3f ret;
|
||||
Vector3f ret;
|
||||
sfSound_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum distance
|
||||
*
|
||||
* Returns:
|
||||
* Minimum distance for the sound
|
||||
*/
|
||||
float getMinDistance()
|
||||
{
|
||||
return sfSound_GetMinDistance(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the minimum distance
|
||||
*
|
||||
* Returns:
|
||||
* Minimum distance for the sound
|
||||
*/
|
||||
float getMinDistance()
|
||||
{
|
||||
return sfSound_GetMinDistance(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attenuation factor
|
||||
*
|
||||
* Returns:
|
||||
* Attenuation factor of the sound
|
||||
*
|
||||
*/
|
||||
float getAttenuation()
|
||||
{
|
||||
return sfSound_GetAttenuation(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the attenuation factor
|
||||
*
|
||||
* Returns:
|
||||
* Attenuation factor of the sound
|
||||
*
|
||||
*/
|
||||
float getAttenuation()
|
||||
{
|
||||
return sfSound_GetAttenuation(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the status of the sound (stopped, paused, playing)
|
||||
*
|
||||
* Returns:
|
||||
* Current status of the sound
|
||||
*/
|
||||
SoundStatus getStatus()
|
||||
/**
|
||||
* Get the status of the sound (stopped, paused, playing)
|
||||
*
|
||||
* Returns:
|
||||
* Current status of the sound
|
||||
*/
|
||||
SoundStatus getStatus()
|
||||
{
|
||||
return sfSound_GetStatus(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current playing position of the sound
|
||||
*
|
||||
* Returns:
|
||||
* Current playing position, expressed in seconds
|
||||
*/
|
||||
float getPlayingOffset()
|
||||
/**
|
||||
* Get the current playing position of the sound
|
||||
*
|
||||
* Returns:
|
||||
* Current playing position, expressed in seconds
|
||||
*/
|
||||
float getPlayingOffset()
|
||||
{
|
||||
return sfSound_GetPlayingOffset(m_ptr);
|
||||
}
|
||||
|
@ -361,90 +361,90 @@ private:
|
|||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSound_Create;
|
||||
typedef void function(void*) pf_sfSound_Destroy;
|
||||
typedef void function(void*) pf_sfSound_Play;
|
||||
typedef void function(void*) pf_sfSound_Pause;
|
||||
typedef void function(void*) pf_sfSound_Stop;
|
||||
typedef void function(void*, void*) pf_sfSound_SetBuffer;
|
||||
typedef void* function(void*) pf_sfSound_GetBuffer;
|
||||
typedef void function(void*, int) pf_sfSound_SetLoop;
|
||||
typedef int function(void*) pf_sfSound_GetLoop;
|
||||
typedef SoundStatus function(void*) pf_sfSound_GetStatus;
|
||||
typedef void function(void*, float) pf_sfSound_SetPitch;
|
||||
typedef void function(void*, float) pf_sfSound_SetVolume;
|
||||
typedef void function(void*, float, float, float) pf_sfSound_SetPosition;
|
||||
typedef float function(void*) pf_sfSound_GetPitch;
|
||||
typedef float function(void*) pf_sfSound_GetVolume;
|
||||
typedef void function(void*, float*, float*, float*) pf_sfSound_GetPosition;
|
||||
typedef float function(void*) pf_sfSound_GetPlayingOffset;
|
||||
typedef float function(void*) pf_sfSound_GetMinDistance;
|
||||
typedef float function(void*) pf_sfSound_GetAttenuation;
|
||||
typedef void function(void*, float) pf_sfSound_SetMinDistance;
|
||||
typedef void function(void*, float) pf_sfSound_SetAttenuation;
|
||||
typedef void function(void*, float) pf_sfSound_SetPlayingOffset;
|
||||
|
||||
static void function(void*, bool) sfSound_SetRelativeToListener;
|
||||
static bool function(void*) sfSound_IsRelativeToListener;
|
||||
|
||||
static pf_sfSound_Create sfSound_Create;
|
||||
static pf_sfSound_Destroy sfSound_Destroy;
|
||||
static pf_sfSound_Play sfSound_Play;
|
||||
static pf_sfSound_Pause sfSound_Pause;
|
||||
static pf_sfSound_Stop sfSound_Stop;
|
||||
static pf_sfSound_SetBuffer sfSound_SetBuffer;
|
||||
static pf_sfSound_GetBuffer sfSound_GetBuffer;
|
||||
static pf_sfSound_SetLoop sfSound_SetLoop;
|
||||
static pf_sfSound_GetLoop sfSound_GetLoop;
|
||||
static pf_sfSound_GetStatus sfSound_GetStatus;
|
||||
static pf_sfSound_SetPitch sfSound_SetPitch;
|
||||
static pf_sfSound_SetVolume sfSound_SetVolume;
|
||||
static pf_sfSound_SetPosition sfSound_SetPosition;
|
||||
static pf_sfSound_GetPitch sfSound_GetPitch;
|
||||
static pf_sfSound_GetVolume sfSound_GetVolume;
|
||||
static pf_sfSound_GetPosition sfSound_GetPosition;
|
||||
static pf_sfSound_GetPlayingOffset sfSound_GetPlayingOffset;
|
||||
static pf_sfSound_GetMinDistance sfSound_GetMinDistance;
|
||||
static pf_sfSound_GetAttenuation sfSound_GetAttenuation;
|
||||
static pf_sfSound_SetMinDistance sfSound_SetMinDistance;
|
||||
static pf_sfSound_SetAttenuation sfSound_SetAttenuation;
|
||||
static pf_sfSound_SetPlayingOffset sfSound_SetPlayingOffset;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSound_Create;
|
||||
typedef void function(void*) pf_sfSound_Destroy;
|
||||
typedef void function(void*) pf_sfSound_Play;
|
||||
typedef void function(void*) pf_sfSound_Pause;
|
||||
typedef void function(void*) pf_sfSound_Stop;
|
||||
typedef void function(void*, void*) pf_sfSound_SetBuffer;
|
||||
typedef void* function(void*) pf_sfSound_GetBuffer;
|
||||
typedef void function(void*, int) pf_sfSound_SetLoop;
|
||||
typedef int function(void*) pf_sfSound_GetLoop;
|
||||
typedef SoundStatus function(void*) pf_sfSound_GetStatus;
|
||||
typedef void function(void*, float) pf_sfSound_SetPitch;
|
||||
typedef void function(void*, float) pf_sfSound_SetVolume;
|
||||
typedef void function(void*, float, float, float) pf_sfSound_SetPosition;
|
||||
typedef float function(void*) pf_sfSound_GetPitch;
|
||||
typedef float function(void*) pf_sfSound_GetVolume;
|
||||
typedef void function(void*, float*, float*, float*) pf_sfSound_GetPosition;
|
||||
typedef float function(void*) pf_sfSound_GetPlayingOffset;
|
||||
typedef float function(void*) pf_sfSound_GetMinDistance;
|
||||
typedef float function(void*) pf_sfSound_GetAttenuation;
|
||||
typedef void function(void*, float) pf_sfSound_SetMinDistance;
|
||||
typedef void function(void*, float) pf_sfSound_SetAttenuation;
|
||||
typedef void function(void*, float) pf_sfSound_SetPlayingOffset;
|
||||
|
||||
static void function(void*, bool) sfSound_SetRelativeToListener;
|
||||
static bool function(void*) sfSound_IsRelativeToListener;
|
||||
|
||||
static pf_sfSound_Create sfSound_Create;
|
||||
static pf_sfSound_Destroy sfSound_Destroy;
|
||||
static pf_sfSound_Play sfSound_Play;
|
||||
static pf_sfSound_Pause sfSound_Pause;
|
||||
static pf_sfSound_Stop sfSound_Stop;
|
||||
static pf_sfSound_SetBuffer sfSound_SetBuffer;
|
||||
static pf_sfSound_GetBuffer sfSound_GetBuffer;
|
||||
static pf_sfSound_SetLoop sfSound_SetLoop;
|
||||
static pf_sfSound_GetLoop sfSound_GetLoop;
|
||||
static pf_sfSound_GetStatus sfSound_GetStatus;
|
||||
static pf_sfSound_SetPitch sfSound_SetPitch;
|
||||
static pf_sfSound_SetVolume sfSound_SetVolume;
|
||||
static pf_sfSound_SetPosition sfSound_SetPosition;
|
||||
static pf_sfSound_GetPitch sfSound_GetPitch;
|
||||
static pf_sfSound_GetVolume sfSound_GetVolume;
|
||||
static pf_sfSound_GetPosition sfSound_GetPosition;
|
||||
static pf_sfSound_GetPlayingOffset sfSound_GetPlayingOffset;
|
||||
static pf_sfSound_GetMinDistance sfSound_GetMinDistance;
|
||||
static pf_sfSound_GetAttenuation sfSound_GetAttenuation;
|
||||
static pf_sfSound_SetMinDistance sfSound_SetMinDistance;
|
||||
static pf_sfSound_SetAttenuation sfSound_SetAttenuation;
|
||||
static pf_sfSound_SetPlayingOffset sfSound_SetPlayingOffset;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-audio-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-audio");
|
||||
|
||||
sfSound_Create = cast(pf_sfSound_Create)dll.getSymbol("sfSound_Create");
|
||||
sfSound_Destroy = cast(pf_sfSound_Destroy)dll.getSymbol("sfSound_Destroy");
|
||||
sfSound_Play = cast(pf_sfSound_Play)dll.getSymbol("sfSound_Play");
|
||||
sfSound_Pause = cast(pf_sfSound_Pause)dll.getSymbol("sfSound_Pause");
|
||||
sfSound_Stop = cast(pf_sfSound_Stop)dll.getSymbol("sfSound_Stop");
|
||||
sfSound_SetBuffer = cast(pf_sfSound_SetBuffer)dll.getSymbol("sfSound_SetBuffer");
|
||||
sfSound_GetBuffer = cast(pf_sfSound_GetBuffer)dll.getSymbol("sfSound_GetBuffer");
|
||||
sfSound_SetLoop = cast(pf_sfSound_SetLoop)dll.getSymbol("sfSound_SetLoop");
|
||||
sfSound_GetLoop = cast(pf_sfSound_GetLoop)dll.getSymbol("sfSound_GetLoop");
|
||||
sfSound_GetStatus = cast(pf_sfSound_GetStatus)dll.getSymbol("sfSound_GetStatus");
|
||||
sfSound_SetPitch = cast(pf_sfSound_SetPitch)dll.getSymbol("sfSound_SetPitch");
|
||||
sfSound_SetVolume = cast(pf_sfSound_SetVolume)dll.getSymbol("sfSound_SetVolume");
|
||||
sfSound_SetPosition = cast(pf_sfSound_SetPosition)dll.getSymbol("sfSound_SetPosition");
|
||||
sfSound_GetPitch = cast(pf_sfSound_GetPitch)dll.getSymbol("sfSound_GetPitch");
|
||||
sfSound_GetVolume = cast(pf_sfSound_GetVolume)dll.getSymbol("sfSound_GetVolume");
|
||||
sfSound_GetPosition = cast(pf_sfSound_GetPosition)dll.getSymbol("sfSound_GetPosition");
|
||||
sfSound_GetPlayingOffset = cast(pf_sfSound_GetPlayingOffset)dll.getSymbol("sfSound_GetPlayingOffset");
|
||||
sfSound_GetMinDistance = cast(pf_sfSound_GetMinDistance)dll.getSymbol("sfSound_GetMinDistance");
|
||||
sfSound_GetAttenuation = cast(pf_sfSound_GetAttenuation)dll.getSymbol("sfSound_GetAttenuation");
|
||||
sfSound_SetMinDistance = cast(pf_sfSound_SetMinDistance)dll.getSymbol("sfSound_SetMinDistance");
|
||||
sfSound_SetAttenuation = cast(pf_sfSound_SetAttenuation)dll.getSymbol("sfSound_SetAttenuation");
|
||||
sfSound_SetPlayingOffset = cast(pf_sfSound_SetPlayingOffset)dll.getSymbol("sfSound_SetPlayingOffset");
|
||||
|
||||
mixin(loadFromSharedLib("sfSound_SetRelativeToListener"));
|
||||
mixin(loadFromSharedLib("sfSound_IsRelativeToListener"));
|
||||
|
||||
sfSound_Create = cast(pf_sfSound_Create)dll.getSymbol("sfSound_Create");
|
||||
sfSound_Destroy = cast(pf_sfSound_Destroy)dll.getSymbol("sfSound_Destroy");
|
||||
sfSound_Play = cast(pf_sfSound_Play)dll.getSymbol("sfSound_Play");
|
||||
sfSound_Pause = cast(pf_sfSound_Pause)dll.getSymbol("sfSound_Pause");
|
||||
sfSound_Stop = cast(pf_sfSound_Stop)dll.getSymbol("sfSound_Stop");
|
||||
sfSound_SetBuffer = cast(pf_sfSound_SetBuffer)dll.getSymbol("sfSound_SetBuffer");
|
||||
sfSound_GetBuffer = cast(pf_sfSound_GetBuffer)dll.getSymbol("sfSound_GetBuffer");
|
||||
sfSound_SetLoop = cast(pf_sfSound_SetLoop)dll.getSymbol("sfSound_SetLoop");
|
||||
sfSound_GetLoop = cast(pf_sfSound_GetLoop)dll.getSymbol("sfSound_GetLoop");
|
||||
sfSound_GetStatus = cast(pf_sfSound_GetStatus)dll.getSymbol("sfSound_GetStatus");
|
||||
sfSound_SetPitch = cast(pf_sfSound_SetPitch)dll.getSymbol("sfSound_SetPitch");
|
||||
sfSound_SetVolume = cast(pf_sfSound_SetVolume)dll.getSymbol("sfSound_SetVolume");
|
||||
sfSound_SetPosition = cast(pf_sfSound_SetPosition)dll.getSymbol("sfSound_SetPosition");
|
||||
sfSound_GetPitch = cast(pf_sfSound_GetPitch)dll.getSymbol("sfSound_GetPitch");
|
||||
sfSound_GetVolume = cast(pf_sfSound_GetVolume)dll.getSymbol("sfSound_GetVolume");
|
||||
sfSound_GetPosition = cast(pf_sfSound_GetPosition)dll.getSymbol("sfSound_GetPosition");
|
||||
sfSound_GetPlayingOffset = cast(pf_sfSound_GetPlayingOffset)dll.getSymbol("sfSound_GetPlayingOffset");
|
||||
sfSound_GetMinDistance = cast(pf_sfSound_GetMinDistance)dll.getSymbol("sfSound_GetMinDistance");
|
||||
sfSound_GetAttenuation = cast(pf_sfSound_GetAttenuation)dll.getSymbol("sfSound_GetAttenuation");
|
||||
sfSound_SetMinDistance = cast(pf_sfSound_SetMinDistance)dll.getSymbol("sfSound_SetMinDistance");
|
||||
sfSound_SetAttenuation = cast(pf_sfSound_SetAttenuation)dll.getSymbol("sfSound_SetAttenuation");
|
||||
sfSound_SetPlayingOffset = cast(pf_sfSound_SetPlayingOffset)dll.getSymbol("sfSound_SetPlayingOffset");
|
||||
|
||||
mixin(loadFromSharedLib("sfSound_SetRelativeToListener"));
|
||||
mixin(loadFromSharedLib("sfSound_IsRelativeToListener"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.soundbuffer;
|
||||
|
@ -32,83 +32,83 @@ import dsfml.system.stringutil;
|
|||
|
||||
|
||||
/**
|
||||
* SoundBuffer is the low-level for loading and manipulating
|
||||
* sound buffers
|
||||
* SoundBuffer is the low-level for loading and manipulating
|
||||
* sound buffers
|
||||
*/
|
||||
class SoundBuffer : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Load the sound buffer from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the sound file to load
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException on failure
|
||||
*/
|
||||
this(string filename)
|
||||
/**
|
||||
* Load the sound buffer from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the sound file to load
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException on failure
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfSoundBuffer_CreateFromFile(toStringz(filename)));
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfSoundBuffer_CreateFromFile(toStringz(filename)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the sound buffer from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = Array of file data in memory
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException on failure
|
||||
*/
|
||||
this(byte[] data)
|
||||
/**
|
||||
* Load the sound buffer from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = Array of file data in memory
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException on failure
|
||||
*/
|
||||
this(byte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new Exception("LoadingException : Memory stream is invalid.");
|
||||
if (data is null || data.length == 0)
|
||||
throw new Exception("LoadingException : Memory stream is invalid.");
|
||||
|
||||
super(sfSoundBuffer_CreateFromMemory(data.ptr, data.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the sound buffer from an array of samples - assumed format for
|
||||
* samples is 16 bits signed integer
|
||||
*
|
||||
* Params:
|
||||
* samples = Array of samples in memory
|
||||
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
|
||||
* sampleRate = Frequency (number of samples to play per second)
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException on failure
|
||||
*/
|
||||
this(short[] samples, uint channelsCount, uint sampleRate)
|
||||
/**
|
||||
* Load the sound buffer from an array of samples - assumed format for
|
||||
* samples is 16 bits signed integer
|
||||
*
|
||||
* Params:
|
||||
* samples = Array of samples in memory
|
||||
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
|
||||
* sampleRate = Frequency (number of samples to play per second)
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException on failure
|
||||
*/
|
||||
this(short[] samples, uint channelsCount, uint sampleRate)
|
||||
{
|
||||
if (samples is null || samples.length == 0)
|
||||
throw new Exception("LoadingException : Samples array is invalid.");
|
||||
if (samples is null || samples.length == 0)
|
||||
throw new Exception("LoadingException : Samples array is invalid.");
|
||||
|
||||
super(sfSoundBuffer_CreateFromSamples(samples.ptr, samples.length, channelsCount, sampleRate));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
override void dispose()
|
||||
{
|
||||
sfSoundBuffer_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the sound buffer to a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the sound file to write
|
||||
*
|
||||
* Returns:
|
||||
* True if saving has been successful
|
||||
*/
|
||||
bool saveToFile(string filename)
|
||||
{
|
||||
/**
|
||||
* Save the sound buffer to a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the sound file to write
|
||||
*
|
||||
* Returns:
|
||||
* True if saving has been successful
|
||||
*/
|
||||
bool saveToFile(string filename)
|
||||
{
|
||||
if (filename !is null && filename.length > 0 )
|
||||
{
|
||||
return cast(bool)sfSoundBuffer_SaveToFile(m_ptr, toStringz(filename));
|
||||
|
@ -116,115 +116,115 @@ class SoundBuffer : DSFMLObject
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sound samples
|
||||
*
|
||||
* Returns:
|
||||
* Array of sound samples, in 16 bits signed integer format
|
||||
*/
|
||||
short[] getSamples()
|
||||
/**
|
||||
* Return the sound samples
|
||||
*
|
||||
* Returns:
|
||||
* Array of sound samples, in 16 bits signed integer format
|
||||
*/
|
||||
short[] getSamples()
|
||||
{
|
||||
short* temp = null;
|
||||
temp = sfSoundBuffer_GetSamples(m_ptr);
|
||||
short* temp = null;
|
||||
temp = sfSoundBuffer_GetSamples(m_ptr);
|
||||
|
||||
return temp is null ? null : temp[0..getSamplesCount];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the samples count
|
||||
*
|
||||
* Returns:
|
||||
* Number of samples
|
||||
*/
|
||||
size_t getSamplesCount()
|
||||
/**
|
||||
* Return the samples count
|
||||
*
|
||||
* Returns:
|
||||
* Number of samples
|
||||
*/
|
||||
size_t getSamplesCount()
|
||||
{
|
||||
return sfSoundBuffer_GetSamplesCount(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sample rate
|
||||
*
|
||||
* Returns:
|
||||
* Sound frequency (number of samples per second)
|
||||
*/
|
||||
uint getSampleRate()
|
||||
/**
|
||||
* Get the sample rate
|
||||
*
|
||||
* Returns:
|
||||
* Sound frequency (number of samples per second)
|
||||
*/
|
||||
uint getSampleRate()
|
||||
{
|
||||
return sfSoundBuffer_GetSampleRate(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of channels (1 = mono, 2 = stereo, ...)
|
||||
*
|
||||
* Returns:
|
||||
* Number of channels
|
||||
*/
|
||||
uint getChannelsCount()
|
||||
/**
|
||||
* Return the number of channels (1 = mono, 2 = stereo, ...)
|
||||
*
|
||||
* Returns:
|
||||
* Number of channels
|
||||
*/
|
||||
uint getChannelsCount()
|
||||
{
|
||||
return sfSoundBuffer_GetChannelsCount(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound duration
|
||||
*
|
||||
* Returns:
|
||||
* Sound duration, in seconds
|
||||
*/
|
||||
float getDuration()
|
||||
/**
|
||||
* Get the sound duration
|
||||
*
|
||||
* Returns:
|
||||
* Sound duration, in seconds
|
||||
*/
|
||||
float getDuration()
|
||||
{
|
||||
return sfSoundBuffer_GetDuration(m_ptr);
|
||||
}
|
||||
|
||||
package:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
package:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
|
||||
private:
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile;
|
||||
typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory;
|
||||
typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples;
|
||||
typedef void function(void*) pf_sfSoundBuffer_Destroy;
|
||||
typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile;
|
||||
typedef short* function(void*) pf_sfSoundBuffer_GetSamples;
|
||||
typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount;
|
||||
typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate;
|
||||
typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount;
|
||||
typedef float function(void*) pf_sfSoundBuffer_GetDuration;
|
||||
|
||||
static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile;
|
||||
static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory;
|
||||
static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples;
|
||||
static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy;
|
||||
static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile;
|
||||
static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples;
|
||||
static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount;
|
||||
static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate;
|
||||
static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount;
|
||||
static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile;
|
||||
typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory;
|
||||
typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples;
|
||||
typedef void function(void*) pf_sfSoundBuffer_Destroy;
|
||||
typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile;
|
||||
typedef short* function(void*) pf_sfSoundBuffer_GetSamples;
|
||||
typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount;
|
||||
typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate;
|
||||
typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount;
|
||||
typedef float function(void*) pf_sfSoundBuffer_GetDuration;
|
||||
|
||||
static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile;
|
||||
static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory;
|
||||
static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples;
|
||||
static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy;
|
||||
static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile;
|
||||
static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples;
|
||||
static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount;
|
||||
static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate;
|
||||
static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount;
|
||||
static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-audio-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-audio");
|
||||
|
||||
sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile");
|
||||
sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory");
|
||||
sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples");
|
||||
sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy");
|
||||
sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile");
|
||||
sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples");
|
||||
sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount");
|
||||
sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate");
|
||||
sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount");
|
||||
sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration");
|
||||
}
|
||||
|
||||
sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile");
|
||||
sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory");
|
||||
sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples");
|
||||
sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy");
|
||||
sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile");
|
||||
sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples");
|
||||
sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount");
|
||||
sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate");
|
||||
sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount");
|
||||
sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.soundbufferrecorder;
|
||||
|
@ -32,78 +32,78 @@ import dsfml.audio.soundbuffer;
|
|||
import dsfml.audio.soundrecorder;
|
||||
|
||||
/**
|
||||
* Specialized sfSoundRecorder which saves the captured
|
||||
* audio data into a sound buffer
|
||||
* Specialized sfSoundRecorder which saves the captured
|
||||
* audio data into a sound buffer
|
||||
*/
|
||||
class SoundBufferRecorder : SoundRecorder
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSoundBufferRecorder_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSoundBufferRecorder_Destroy(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSoundBufferRecorder_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSoundBufferRecorder_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound buffer containing the captured audio data
|
||||
*
|
||||
* Returns:
|
||||
* SoundBuffer containing the captured audio data
|
||||
*
|
||||
*/
|
||||
SoundBuffer getBuffer()
|
||||
{
|
||||
return new SoundBuffer(sfSoundBufferRecorder_GetBuffer(m_ptr));
|
||||
}
|
||||
/**
|
||||
* Get the sound buffer containing the captured audio data
|
||||
*
|
||||
* Returns:
|
||||
* SoundBuffer containing the captured audio data
|
||||
*
|
||||
*/
|
||||
SoundBuffer getBuffer()
|
||||
{
|
||||
return new SoundBuffer(sfSoundBufferRecorder_GetBuffer(m_ptr));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
override bool onStart()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override bool onStart()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override bool onProcessSamples(short[] s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
override bool onProcessSamples(short[] s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
override void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSoundBufferRecorder_Create;
|
||||
typedef void function(void*) pf_sfSoundBufferRecorder_Destroy;
|
||||
typedef void* function(void*) pf_sfSoundBufferRecorder_GetBuffer;
|
||||
|
||||
static pf_sfSoundBufferRecorder_Create sfSoundBufferRecorder_Create;
|
||||
static pf_sfSoundBufferRecorder_Destroy sfSoundBufferRecorder_Destroy;
|
||||
static pf_sfSoundBufferRecorder_GetBuffer sfSoundBufferRecorder_GetBuffer;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSoundBufferRecorder_Create;
|
||||
typedef void function(void*) pf_sfSoundBufferRecorder_Destroy;
|
||||
typedef void* function(void*) pf_sfSoundBufferRecorder_GetBuffer;
|
||||
|
||||
static pf_sfSoundBufferRecorder_Create sfSoundBufferRecorder_Create;
|
||||
static pf_sfSoundBufferRecorder_Destroy sfSoundBufferRecorder_Destroy;
|
||||
static pf_sfSoundBufferRecorder_GetBuffer sfSoundBufferRecorder_GetBuffer;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-audio-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-audio");
|
||||
|
||||
sfSoundBufferRecorder_Create = cast(pf_sfSoundBufferRecorder_Create)dll.getSymbol("sfSoundBufferRecorder_Create");
|
||||
sfSoundBufferRecorder_Destroy = cast(pf_sfSoundBufferRecorder_Destroy)dll.getSymbol("sfSoundBufferRecorder_Destroy");
|
||||
sfSoundBufferRecorder_GetBuffer = cast(pf_sfSoundBufferRecorder_GetBuffer)dll.getSymbol("sfSoundBufferRecorder_GetBuffer");
|
||||
}
|
||||
|
||||
sfSoundBufferRecorder_Create = cast(pf_sfSoundBufferRecorder_Create)dll.getSymbol("sfSoundBufferRecorder_Create");
|
||||
sfSoundBufferRecorder_Destroy = cast(pf_sfSoundBufferRecorder_Destroy)dll.getSymbol("sfSoundBufferRecorder_Destroy");
|
||||
sfSoundBufferRecorder_GetBuffer = cast(pf_sfSoundBufferRecorder_GetBuffer)dll.getSymbol("sfSoundBufferRecorder_GetBuffer");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.soundrecorder;
|
||||
|
@ -38,300 +38,300 @@ import dsfml.system.lock;
|
|||
import core.thread;
|
||||
|
||||
/**
|
||||
* SoundRecorder is an interface for capturing sound data.
|
||||
*
|
||||
* $(B onProcessSamples and onStop will be called by a different thread, take care of synchronization issues.)
|
||||
*
|
||||
* Examples:
|
||||
* -------
|
||||
* class MySoundRecorder : SoundRecorder
|
||||
* {
|
||||
* this()
|
||||
* {
|
||||
*
|
||||
* }
|
||||
*
|
||||
* protected bool onStart()
|
||||
* {
|
||||
* return true;
|
||||
* }
|
||||
*
|
||||
* protected void onStop()
|
||||
* {
|
||||
*
|
||||
* }
|
||||
*
|
||||
* protected bool onProcessSamples(out short[])
|
||||
* {
|
||||
* // Process data here
|
||||
*
|
||||
* return true; //return true to continue capture, else return false
|
||||
* }
|
||||
* }
|
||||
* -------
|
||||
* SoundRecorder is an interface for capturing sound data.
|
||||
*
|
||||
* $(B onProcessSamples and onStop will be called by a different thread, take care of synchronization issues.)
|
||||
*
|
||||
* Examples:
|
||||
* -------
|
||||
* class MySoundRecorder : SoundRecorder
|
||||
* {
|
||||
* this()
|
||||
* {
|
||||
*
|
||||
* }
|
||||
*
|
||||
* protected bool onStart()
|
||||
* {
|
||||
* return true;
|
||||
* }
|
||||
*
|
||||
* protected void onStop()
|
||||
* {
|
||||
*
|
||||
* }
|
||||
*
|
||||
* protected bool onProcessSamples(out short[])
|
||||
* {
|
||||
* // Process data here
|
||||
*
|
||||
* return true; //return true to continue capture, else return false
|
||||
* }
|
||||
* }
|
||||
* -------
|
||||
*/
|
||||
abstract class SoundRecorder : DSFMLObject
|
||||
{
|
||||
override void dispose()
|
||||
{
|
||||
if (m_flag)
|
||||
stop();
|
||||
override void dispose()
|
||||
{
|
||||
if (m_flag)
|
||||
stop();
|
||||
|
||||
m_instances.remove(m_id);
|
||||
sfSoundRecorder_Destroy(m_ptr);
|
||||
}
|
||||
m_instances.remove(m_id);
|
||||
sfSoundRecorder_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start the capture.
|
||||
*
|
||||
* Only one capture can happen at the same time
|
||||
*
|
||||
* Params:
|
||||
* sampleRate : Sound frequency (the more samples, the higher the quality)
|
||||
* (44100 by default = CD quality)
|
||||
*/
|
||||
void start(uint sampleRate = 44100)
|
||||
{
|
||||
sfSoundRecorder_Start(m_ptr, sampleRate);
|
||||
m_t = new Thread(&threadPoll);
|
||||
m_t.start();
|
||||
}
|
||||
/**
|
||||
* Start the capture.
|
||||
*
|
||||
* Only one capture can happen at the same time
|
||||
*
|
||||
* Params:
|
||||
* sampleRate : Sound frequency (the more samples, the higher the quality)
|
||||
* (44100 by default = CD quality)
|
||||
*/
|
||||
void start(uint sampleRate = 44100)
|
||||
{
|
||||
sfSoundRecorder_Start(m_ptr, sampleRate);
|
||||
m_t = new Thread(&threadPoll);
|
||||
m_t.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the capture
|
||||
*/
|
||||
void stop()
|
||||
{
|
||||
sfSoundRecorder_Stop(m_ptr);
|
||||
m_flag = false;
|
||||
m_t.join();
|
||||
m_t = null;
|
||||
}
|
||||
/**
|
||||
* Stop the capture
|
||||
*/
|
||||
void stop()
|
||||
{
|
||||
sfSoundRecorder_Stop(m_ptr);
|
||||
m_flag = false;
|
||||
m_t.join();
|
||||
m_t = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sample rate
|
||||
*
|
||||
* Returns:
|
||||
* Frequency, in samples per second
|
||||
*/
|
||||
uint getSampleRate()
|
||||
{
|
||||
return sfSoundRecorder_GetSampleRate(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the sample rate
|
||||
*
|
||||
* Returns:
|
||||
* Frequency, in samples per second
|
||||
*/
|
||||
uint getSampleRate()
|
||||
{
|
||||
return sfSoundRecorder_GetSampleRate(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the system supports sound capture.
|
||||
* If not, this class won't be usable
|
||||
*
|
||||
* Returns:
|
||||
* True if audio capture is supported
|
||||
*
|
||||
*/
|
||||
static bool canCapture()
|
||||
{
|
||||
return cast(bool)sfSoundRecorder_CanCapture();
|
||||
}
|
||||
/**
|
||||
* Tell if the system supports sound capture.
|
||||
* If not, this class won't be usable
|
||||
*
|
||||
* Returns:
|
||||
* True if audio capture is supported
|
||||
*
|
||||
*/
|
||||
static bool canCapture()
|
||||
{
|
||||
return cast(bool)sfSoundRecorder_CanCapture();
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Protected constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
m_id = ++seed;
|
||||
m_instances[m_id] = this;
|
||||
super(sfSoundRecorder_Create(&internalOnStart, &internalCallback, &internalOnStop, &m_id));
|
||||
|
||||
init(true);
|
||||
}
|
||||
/**
|
||||
* Protected constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
m_id = ++seed;
|
||||
m_instances[m_id] = this;
|
||||
super(sfSoundRecorder_Create(&internalOnStart, &internalCallback, &internalOnStop, &m_id));
|
||||
|
||||
init(true);
|
||||
}
|
||||
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
|
||||
init(false);
|
||||
}
|
||||
init(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start recording audio data
|
||||
*
|
||||
* Returns:
|
||||
* False to abort recording audio data, true to start
|
||||
*/
|
||||
abstract bool onStart();
|
||||
|
||||
/**
|
||||
* Stop recording audio data
|
||||
*/
|
||||
abstract void onStop();
|
||||
|
||||
/**
|
||||
* callback function
|
||||
*
|
||||
* Parameters:
|
||||
* samples = Array of samples
|
||||
*
|
||||
* Returns:
|
||||
* true to continue recording, false to stop.
|
||||
*/
|
||||
abstract bool onProcessSamples(short[] samples);
|
||||
/**
|
||||
* Start recording audio data
|
||||
*
|
||||
* Returns:
|
||||
* False to abort recording audio data, true to start
|
||||
*/
|
||||
abstract bool onStart();
|
||||
|
||||
/**
|
||||
* Stop recording audio data
|
||||
*/
|
||||
abstract void onStop();
|
||||
|
||||
/**
|
||||
* callback function
|
||||
*
|
||||
* Parameters:
|
||||
* samples = Array of samples
|
||||
*
|
||||
* Returns:
|
||||
* true to continue recording, false to stop.
|
||||
*/
|
||||
abstract bool onProcessSamples(short[] samples);
|
||||
|
||||
bool m_disposed;
|
||||
bool m_disposed;
|
||||
private:
|
||||
/*
|
||||
* an init function to initialize id of the object.
|
||||
*/
|
||||
void init(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
m_list = new LinkedList!(Samples)();
|
||||
|
||||
m_flag = true;
|
||||
m_continue = true;
|
||||
|
||||
m_mutex = new Mutex();
|
||||
}
|
||||
}
|
||||
|
||||
void* m_userData;
|
||||
int m_id;
|
||||
|
||||
static int seed = 0;
|
||||
static SoundRecorder[int] m_instances;
|
||||
|
||||
/*
|
||||
* Extern C callback function
|
||||
*
|
||||
* 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
|
||||
* in the associative array.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
extern(C) static int internalCallback(short* s, size_t size, void* user)
|
||||
{
|
||||
int id;
|
||||
// retrieve instance
|
||||
if ((id = *cast(int*)(user)) in m_instances)
|
||||
{
|
||||
SoundRecorder temp = m_instances[id];
|
||||
scope Lock l = new Lock(temp.m_mutex);
|
||||
if (temp.m_continue)
|
||||
// this new is allowed because Samples is an custom alloc class.
|
||||
temp.m_list.enqueue(new Samples(s, size));
|
||||
return temp.m_continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* an init function to initialize id of the object.
|
||||
*/
|
||||
void init(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
m_list = new LinkedList!(Samples)();
|
||||
|
||||
m_flag = true;
|
||||
m_continue = true;
|
||||
|
||||
m_mutex = new Mutex();
|
||||
}
|
||||
}
|
||||
|
||||
void* m_userData;
|
||||
int m_id;
|
||||
|
||||
static int seed = 0;
|
||||
static SoundRecorder[int] m_instances;
|
||||
|
||||
/*
|
||||
* Extern C callback function
|
||||
*
|
||||
* 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
|
||||
* in the associative array.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
extern(C) static int internalCallback(short* s, size_t size, void* user)
|
||||
{
|
||||
int id;
|
||||
// retrieve instance
|
||||
if ((id = *cast(int*)(user)) in m_instances)
|
||||
{
|
||||
SoundRecorder temp = m_instances[id];
|
||||
scope Lock l = new Lock(temp.m_mutex);
|
||||
if (temp.m_continue)
|
||||
// this new is allowed because Samples is an custom alloc class.
|
||||
temp.m_list.enqueue(new Samples(s, size));
|
||||
return temp.m_continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
extern(C) static int internalOnStart(void* user)
|
||||
{
|
||||
int id;
|
||||
bool ret = false;
|
||||
if ((id = *cast(int*)(user)) in m_instances)
|
||||
{
|
||||
SoundRecorder temp = m_instances[id];
|
||||
ret = temp.onStart();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
extern(C) static int internalOnStart(void* user)
|
||||
{
|
||||
int id;
|
||||
bool ret = false;
|
||||
if ((id = *cast(int*)(user)) in m_instances)
|
||||
{
|
||||
SoundRecorder temp = m_instances[id];
|
||||
ret = temp.onStart();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern(C) static void internalOnStop(void* user)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/*
|
||||
* Managed thread loop
|
||||
*/
|
||||
void threadPoll()
|
||||
{
|
||||
while (m_flag)
|
||||
{
|
||||
sleep(0.05f);
|
||||
// if samples are available
|
||||
if (!m_list.empty)
|
||||
{
|
||||
// Lock ressources
|
||||
scope Lock l = new Lock(m_mutex);
|
||||
|
||||
Samples s = m_list.dequeue;
|
||||
m_continue = this.onProcessSamples(s.data[0..s.length].dup);
|
||||
|
||||
delete s;
|
||||
|
||||
if (!m_continue)
|
||||
{
|
||||
// delete all samples left
|
||||
foreach(Samples dummy; m_list)
|
||||
delete dummy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onStop();
|
||||
}
|
||||
|
||||
Mutex m_mutex;
|
||||
|
||||
bool m_flag;
|
||||
bool m_continue = true;
|
||||
LinkedList!(Samples) m_list;
|
||||
Thread m_t;
|
||||
|
||||
extern(C) static void internalOnStop(void* user)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/*
|
||||
* Managed thread loop
|
||||
*/
|
||||
void threadPoll()
|
||||
{
|
||||
while (m_flag)
|
||||
{
|
||||
sleep(0.05f);
|
||||
// if samples are available
|
||||
if (!m_list.empty)
|
||||
{
|
||||
// Lock ressources
|
||||
scope Lock l = new Lock(m_mutex);
|
||||
|
||||
Samples s = m_list.dequeue;
|
||||
m_continue = this.onProcessSamples(s.data[0..s.length].dup);
|
||||
|
||||
delete s;
|
||||
|
||||
if (!m_continue)
|
||||
{
|
||||
// delete all samples left
|
||||
foreach(Samples dummy; m_list)
|
||||
delete dummy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onStop();
|
||||
}
|
||||
|
||||
Mutex m_mutex;
|
||||
|
||||
bool m_flag;
|
||||
bool m_continue = true;
|
||||
LinkedList!(Samples) m_list;
|
||||
Thread m_t;
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
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*, uint SampleRate) pf_sfSoundRecorder_Start;
|
||||
typedef void function(void*) pf_sfSoundRecorder_Stop;
|
||||
typedef uint function(void*) pf_sfSoundRecorder_GetSampleRate;
|
||||
typedef int function() pf_sfSoundRecorder_CanCapture;
|
||||
|
||||
static pf_sfSoundRecorder_Create sfSoundRecorder_Create;
|
||||
static pf_sfSoundRecorder_Destroy sfSoundRecorder_Destroy;
|
||||
static pf_sfSoundRecorder_Start sfSoundRecorder_Start;
|
||||
static pf_sfSoundRecorder_Stop sfSoundRecorder_Stop;
|
||||
static pf_sfSoundRecorder_GetSampleRate sfSoundRecorder_GetSampleRate;
|
||||
static pf_sfSoundRecorder_CanCapture sfSoundRecorder_CanCapture;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
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*, uint SampleRate) pf_sfSoundRecorder_Start;
|
||||
typedef void function(void*) pf_sfSoundRecorder_Stop;
|
||||
typedef uint function(void*) pf_sfSoundRecorder_GetSampleRate;
|
||||
typedef int function() pf_sfSoundRecorder_CanCapture;
|
||||
|
||||
static pf_sfSoundRecorder_Create sfSoundRecorder_Create;
|
||||
static pf_sfSoundRecorder_Destroy sfSoundRecorder_Destroy;
|
||||
static pf_sfSoundRecorder_Start sfSoundRecorder_Start;
|
||||
static pf_sfSoundRecorder_Stop sfSoundRecorder_Stop;
|
||||
static pf_sfSoundRecorder_GetSampleRate sfSoundRecorder_GetSampleRate;
|
||||
static pf_sfSoundRecorder_CanCapture sfSoundRecorder_CanCapture;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-audio-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-audio");
|
||||
|
||||
sfSoundRecorder_Create = cast(pf_sfSoundRecorder_Create)dll.getSymbol("sfSoundRecorder_Create");
|
||||
sfSoundRecorder_Destroy = cast(pf_sfSoundRecorder_Destroy)dll.getSymbol("sfSoundRecorder_Destroy");
|
||||
sfSoundRecorder_Start = cast(pf_sfSoundRecorder_Start)dll.getSymbol("sfSoundRecorder_Start");
|
||||
sfSoundRecorder_Stop = cast(pf_sfSoundRecorder_Stop)dll.getSymbol("sfSoundRecorder_Stop");
|
||||
sfSoundRecorder_GetSampleRate = cast(pf_sfSoundRecorder_GetSampleRate)dll.getSymbol("sfSoundRecorder_GetSampleRate");
|
||||
sfSoundRecorder_CanCapture = cast(pf_sfSoundRecorder_CanCapture)dll.getSymbol("sfSoundRecorder_CanCapture");
|
||||
}
|
||||
|
||||
sfSoundRecorder_Create = cast(pf_sfSoundRecorder_Create)dll.getSymbol("sfSoundRecorder_Create");
|
||||
sfSoundRecorder_Destroy = cast(pf_sfSoundRecorder_Destroy)dll.getSymbol("sfSoundRecorder_Destroy");
|
||||
sfSoundRecorder_Start = cast(pf_sfSoundRecorder_Start)dll.getSymbol("sfSoundRecorder_Start");
|
||||
sfSoundRecorder_Stop = cast(pf_sfSoundRecorder_Stop)dll.getSymbol("sfSoundRecorder_Stop");
|
||||
sfSoundRecorder_GetSampleRate = cast(pf_sfSoundRecorder_GetSampleRate)dll.getSymbol("sfSoundRecorder_GetSampleRate");
|
||||
sfSoundRecorder_CanCapture = cast(pf_sfSoundRecorder_CanCapture)dll.getSymbol("sfSoundRecorder_CanCapture");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Use explicit alloc to allow instaciation by C thread
|
||||
private class Samples
|
||||
{
|
||||
mixin Alloc;
|
||||
|
||||
this(short* data, size_t length)
|
||||
{
|
||||
this.data = data;
|
||||
this.length = length;
|
||||
}
|
||||
mixin Alloc;
|
||||
|
||||
this(short* data, size_t length)
|
||||
{
|
||||
this.data = data;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public short* data;
|
||||
public size_t length;
|
||||
public short* data;
|
||||
public size_t length;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.audio.soundstatus;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,42 +1,42 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.all;
|
||||
|
||||
public import
|
||||
dsfml.graphics.blendmode,
|
||||
dsfml.graphics.color,
|
||||
dsfml.graphics.font,
|
||||
dsfml.graphics.idrawable,
|
||||
dsfml.graphics.image,
|
||||
dsfml.graphics.shader,
|
||||
dsfml.graphics.rect,
|
||||
dsfml.graphics.renderwindow,
|
||||
dsfml.graphics.shape,
|
||||
dsfml.graphics.sprite,
|
||||
dsfml.graphics.text,
|
||||
dsfml.graphics.textstyle,
|
||||
dsfml.graphics.view;
|
||||
dsfml.graphics.blendmode,
|
||||
dsfml.graphics.color,
|
||||
dsfml.graphics.font,
|
||||
dsfml.graphics.idrawable,
|
||||
dsfml.graphics.image,
|
||||
dsfml.graphics.shader,
|
||||
dsfml.graphics.rect,
|
||||
dsfml.graphics.renderwindow,
|
||||
dsfml.graphics.shape,
|
||||
dsfml.graphics.sprite,
|
||||
dsfml.graphics.text,
|
||||
dsfml.graphics.textstyle,
|
||||
dsfml.graphics.view;
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.blendmode;
|
||||
|
||||
/**
|
||||
* Enumerate the blending modes for drawable objects.
|
||||
* Enumerate the blending modes for drawable objects.
|
||||
*/
|
||||
enum BlendMode
|
||||
{
|
||||
ALPHA, /// Pixel = Src * a + Dest * (1 - a)
|
||||
ADD, /// Pixel = Src + Dest
|
||||
ALPHA, /// Pixel = Src * a + Dest * (1 - a)
|
||||
ADD, /// Pixel = Src + Dest
|
||||
MULTIPLY, /// Pixel = Src * Dest
|
||||
NONE /// No blending
|
||||
NONE /// No blending
|
||||
}
|
||||
|
|
|
@ -1,132 +1,132 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.color;
|
||||
|
||||
|
||||
/**
|
||||
* Color is an utility structure for manipulating colors
|
||||
* Color is an utility structure for manipulating colors
|
||||
*/
|
||||
struct Color
|
||||
{
|
||||
ubyte r; /// Red component
|
||||
ubyte g; /// Green component
|
||||
ubyte b; /// Blue component
|
||||
ubyte a = 255; /// Alpha (transparency) component
|
||||
ubyte r; /// Red component
|
||||
ubyte g; /// Green component
|
||||
ubyte b; /// Blue component
|
||||
ubyte a = 255; /// Alpha (transparency) component
|
||||
|
||||
/**
|
||||
* Construct the color from its 4 RGBA components
|
||||
*
|
||||
* Params:
|
||||
* r = Red component (0 .. 255)
|
||||
* g = Green component (0 .. 255)
|
||||
* b = Blue component (0 .. 255)
|
||||
* a = Alpha component (0 .. 255) (255 by default)
|
||||
*/
|
||||
/**
|
||||
* Construct the color from its 4 RGBA components
|
||||
*
|
||||
* Params:
|
||||
* r = Red component (0 .. 255)
|
||||
* g = Green component (0 .. 255)
|
||||
* b = Blue component (0 .. 255)
|
||||
* 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;
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
c.a = a;
|
||||
|
||||
return c;
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
c.a = a;
|
||||
|
||||
return c;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Operator == and != overload to compare two colors
|
||||
*/
|
||||
const bool opEquals(ref const(Color) color2)
|
||||
{
|
||||
return
|
||||
(r == color2.r)
|
||||
&& (g == color2.g)
|
||||
&& (b == color2.b)
|
||||
&& (a == color2.a);
|
||||
}
|
||||
/**
|
||||
* Operator + overload to add two colors
|
||||
*/
|
||||
Color opAdd(Color color2)
|
||||
{
|
||||
ubyte r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
|
||||
ubyte g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
|
||||
ubyte b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
|
||||
ubyte a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
/**
|
||||
* Operator == and != overload to compare two colors
|
||||
*/
|
||||
const bool opEquals(ref const(Color) color2)
|
||||
{
|
||||
return
|
||||
(r == color2.r)
|
||||
&& (g == color2.g)
|
||||
&& (b == color2.b)
|
||||
&& (a == color2.a);
|
||||
}
|
||||
/**
|
||||
* Operator + overload to add two colors
|
||||
*/
|
||||
Color opAdd(Color color2)
|
||||
{
|
||||
ubyte r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
|
||||
ubyte g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
|
||||
ubyte b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
|
||||
ubyte a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator += overload
|
||||
*/
|
||||
Color opAddAssign(Color color2)
|
||||
{
|
||||
this.r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
|
||||
this.g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
|
||||
this.b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
|
||||
this.a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Operator += overload
|
||||
*/
|
||||
Color opAddAssign(Color color2)
|
||||
{
|
||||
this.r = this.r + color2.r > 255 ? 255 : cast(ubyte) (this.r + color2.r);
|
||||
this.g = this.g + color2.g > 255 ? 255 : cast(ubyte) (this.g + color2.g);
|
||||
this.b = this.b + color2.b > 255 ? 255 : cast(ubyte) (this.b + color2.b);
|
||||
this.a = this.a + color2.a > 255 ? 255 : cast(ubyte) (this.a + color2.a);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator * overload to modulate colors
|
||||
*/
|
||||
Color opMul(Color color2)
|
||||
{
|
||||
ubyte r = cast(ubyte) (this.r * color2.r / 255);
|
||||
ubyte g = cast(ubyte) (this.g * color2.g / 255);
|
||||
ubyte b = cast(ubyte) (this.b * color2.b / 255);
|
||||
ubyte a = cast(ubyte) (this.a * color2.a / 255);
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
/**
|
||||
* Operator * overload to modulate colors
|
||||
*/
|
||||
Color opMul(Color color2)
|
||||
{
|
||||
ubyte r = cast(ubyte) (this.r * color2.r / 255);
|
||||
ubyte g = cast(ubyte) (this.g * color2.g / 255);
|
||||
ubyte b = cast(ubyte) (this.b * color2.b / 255);
|
||||
ubyte a = cast(ubyte) (this.a * color2.a / 255);
|
||||
|
||||
return Color(r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator *= overload
|
||||
*/
|
||||
Color opMulAssign(Color color2)
|
||||
{
|
||||
this.r = cast(ubyte) (this.r * color2.r / 255);
|
||||
this.g = cast(ubyte) (this.g * color2.g / 255);
|
||||
this.b = cast(ubyte) (this.b * color2.b / 255);
|
||||
this.a = cast(ubyte) (this.a * color2.a / 255);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
static const Color BLACK = {0, 0, 0}; /// Black 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 GREEN = {0, 255, 0}; /// Green 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 MAGENTA = {255, 0, 255}; /// Magenta predefined color
|
||||
static const Color CYAN = {0, 255, 255}; /// Cyan predefined color
|
||||
/**
|
||||
* Operator *= overload
|
||||
*/
|
||||
Color opMulAssign(Color color2)
|
||||
{
|
||||
this.r = cast(ubyte) (this.r * color2.r / 255);
|
||||
this.g = cast(ubyte) (this.g * color2.g / 255);
|
||||
this.b = cast(ubyte) (this.b * color2.b / 255);
|
||||
this.a = cast(ubyte) (this.a * color2.a / 255);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
static const Color BLACK = {0, 0, 0}; /// Black 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 GREEN = {0, 255, 0}; /// Green 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 MAGENTA = {255, 0, 255}; /// Magenta predefined color
|
||||
static const Color CYAN = {0, 255, 255}; /// Cyan predefined color
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.common;
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.drawableimpl;
|
||||
|
@ -37,14 +37,14 @@ import dsfml.graphics.shader;
|
|||
|
||||
package
|
||||
{
|
||||
struct sfSprite{};
|
||||
struct sfShape{};
|
||||
struct sfText{};
|
||||
struct sfSprite{};
|
||||
struct sfShape{};
|
||||
struct sfText{};
|
||||
}
|
||||
|
||||
/*
|
||||
* Package base class of all drawable.
|
||||
* Provide implementation of IDrawable and functions aliases.
|
||||
* Package base class of all drawable.
|
||||
* Provide implementation of IDrawable and functions aliases.
|
||||
*/
|
||||
package class Drawableimpl(T) : DSFMLObject, IDrawable
|
||||
{
|
||||
|
@ -60,274 +60,274 @@ protected:
|
|||
}
|
||||
|
||||
public:
|
||||
void setX(float x)
|
||||
{
|
||||
sfDrawable_SetX(m_ptr, x);
|
||||
}
|
||||
void setX(float x)
|
||||
{
|
||||
sfDrawable_SetX(m_ptr, x);
|
||||
}
|
||||
|
||||
void setY(float y)
|
||||
{
|
||||
sfDrawable_SetY(m_ptr, y);
|
||||
}
|
||||
void setY(float y)
|
||||
{
|
||||
sfDrawable_SetY(m_ptr, y);
|
||||
}
|
||||
|
||||
void setPosition(float x, float y)
|
||||
{
|
||||
sfDrawable_SetPosition(m_ptr, x, y);
|
||||
}
|
||||
void setPosition(float x, float y)
|
||||
{
|
||||
sfDrawable_SetPosition(m_ptr, x, y);
|
||||
}
|
||||
|
||||
void setPosition(Vector2f vec)
|
||||
{
|
||||
sfDrawable_SetPosition(m_ptr, vec.x, vec.y);
|
||||
}
|
||||
void setPosition(Vector2f vec)
|
||||
{
|
||||
sfDrawable_SetPosition(m_ptr, vec.x, vec.y);
|
||||
}
|
||||
|
||||
void setScaleX(float scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
sfDrawable_SetScaleX(m_ptr, scale);
|
||||
}
|
||||
|
||||
void setScaleY(float scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
sfDrawable_SetScaleY(m_ptr, scale);
|
||||
}
|
||||
void setScaleX(float scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
sfDrawable_SetScaleX(m_ptr, scale);
|
||||
}
|
||||
|
||||
void setScaleY(float scale)
|
||||
{
|
||||
if (scale > 0)
|
||||
sfDrawable_SetScaleY(m_ptr, scale);
|
||||
}
|
||||
|
||||
void setScale(float scaleX, float scaleY)
|
||||
{
|
||||
if (scaleX > 0 && scaleY > 0)
|
||||
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
|
||||
}
|
||||
void setScale(float scaleX, float scaleY)
|
||||
{
|
||||
if (scaleX > 0 && scaleY > 0)
|
||||
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
|
||||
}
|
||||
|
||||
void setScale(Vector2f scale)
|
||||
{
|
||||
if (scale.x > 0 && scale.y > 0)
|
||||
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
|
||||
}
|
||||
void setScale(Vector2f scale)
|
||||
{
|
||||
if (scale.x > 0 && scale.y > 0)
|
||||
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
|
||||
}
|
||||
|
||||
void setOrigin(float originX, float originY)
|
||||
{
|
||||
sfDrawable_SetOrigin(m_ptr, originX, originY);
|
||||
}
|
||||
void setOrigin(float originX, float originY)
|
||||
{
|
||||
sfDrawable_SetOrigin(m_ptr, originX, originY);
|
||||
}
|
||||
|
||||
void setOrigin(Vector2f origin)
|
||||
{
|
||||
sfDrawable_SetOrigin(m_ptr, origin.x, origin.y);
|
||||
}
|
||||
void setOrigin(Vector2f origin)
|
||||
{
|
||||
sfDrawable_SetOrigin(m_ptr, origin.x, origin.y);
|
||||
}
|
||||
|
||||
void setRotation(float angle)
|
||||
{
|
||||
sfDrawable_SetRotation(m_ptr, angle);
|
||||
}
|
||||
void setRotation(float angle)
|
||||
{
|
||||
sfDrawable_SetRotation(m_ptr, angle);
|
||||
}
|
||||
|
||||
void setColor(Color c)
|
||||
{
|
||||
sfDrawable_SetColor(m_ptr, c);
|
||||
}
|
||||
|
||||
void setBlendMode(BlendMode mode)
|
||||
void setColor(Color c)
|
||||
{
|
||||
sfDrawable_SetColor(m_ptr, c);
|
||||
}
|
||||
|
||||
void setBlendMode(BlendMode mode)
|
||||
{
|
||||
sfDrawable_SetBlendMode(m_ptr, mode);
|
||||
}
|
||||
|
||||
Vector2f getPosition()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr));
|
||||
}
|
||||
Vector2f getPosition()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetX(m_ptr), sfDrawable_GetY(m_ptr));
|
||||
}
|
||||
|
||||
Vector2f getScale()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr));
|
||||
}
|
||||
Vector2f getScale()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetScaleX(m_ptr), sfDrawable_GetScaleY(m_ptr));
|
||||
}
|
||||
|
||||
Vector2f getOrigin()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr));
|
||||
}
|
||||
|
||||
float getRotation()
|
||||
{
|
||||
return sfDrawable_GetRotation(m_ptr);
|
||||
}
|
||||
Vector2f getOrigin()
|
||||
{
|
||||
return Vector2f(sfDrawable_GetOriginX(m_ptr), sfDrawable_GetOriginY(m_ptr));
|
||||
}
|
||||
|
||||
float getRotation()
|
||||
{
|
||||
return sfDrawable_GetRotation(m_ptr);
|
||||
}
|
||||
|
||||
Color getColor()
|
||||
{
|
||||
return sfDrawable_GetColor(m_ptr);
|
||||
}
|
||||
Color getColor()
|
||||
{
|
||||
return sfDrawable_GetColor(m_ptr);
|
||||
}
|
||||
|
||||
BlendMode getBlendMode()
|
||||
BlendMode getBlendMode()
|
||||
{
|
||||
return cast(BlendMode)(sfDrawable_GetBlendMode(m_ptr));
|
||||
}
|
||||
|
||||
void rotate(float angle)
|
||||
{
|
||||
sfDrawable_Rotate(m_ptr, angle);
|
||||
}
|
||||
void rotate(float angle)
|
||||
{
|
||||
sfDrawable_Rotate(m_ptr, angle);
|
||||
}
|
||||
|
||||
void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offsetX, offsetY);
|
||||
}
|
||||
void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offsetX, offsetY);
|
||||
}
|
||||
|
||||
void move(Vector2f offset)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offset.x, offset.y);
|
||||
}
|
||||
void move(Vector2f offset)
|
||||
{
|
||||
sfDrawable_Move(m_ptr, offset.x, offset.y);
|
||||
}
|
||||
|
||||
void scale(float scaleX, float scaleY)
|
||||
{
|
||||
if (scaleX > 0 && scaleY > 0)
|
||||
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
|
||||
}
|
||||
void scale(float scaleX, float scaleY)
|
||||
{
|
||||
if (scaleX > 0 && scaleY > 0)
|
||||
sfDrawable_SetScale(m_ptr, scaleX, scaleY);
|
||||
}
|
||||
|
||||
void scale(Vector2f scale)
|
||||
{
|
||||
if (scale.x > 0 && scale.y > 0)
|
||||
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
|
||||
}
|
||||
|
||||
Vector2f tranformToLocal(Vector2f point)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
void scale(Vector2f scale)
|
||||
{
|
||||
if (scale.x > 0 && scale.y > 0)
|
||||
sfDrawable_SetScale(m_ptr, scale.x, scale.y);
|
||||
}
|
||||
|
||||
Vector2f tranformToLocal(Vector2f point)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Vector2f tranformToGlobal(Vector2f point)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
Vector2f tranformToGlobal(Vector2f point)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfDrawable_TransformToLocal(m_ptr, point.x, point.y, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void render(RenderWindow window)
|
||||
{
|
||||
sfRenderWindow_DrawThis(window.getNativePointer, m_ptr);
|
||||
}
|
||||
|
||||
void renderWithShader(RenderWindow window, Shader shader)
|
||||
{
|
||||
sfRenderWindow_DrawThisWithShader(window.getNativePointer, m_ptr, shader.getNativePointer);
|
||||
}
|
||||
void render(RenderWindow window)
|
||||
{
|
||||
sfRenderWindow_DrawThis(window.getNativePointer, m_ptr);
|
||||
}
|
||||
|
||||
void renderWithShader(RenderWindow window, Shader shader)
|
||||
{
|
||||
sfRenderWindow_DrawThisWithShader(window.getNativePointer, m_ptr, shader.getNativePointer);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfDrawable_Destroy(m_ptr);
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
sfDrawable_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfDrawable_Create;
|
||||
typedef void function(void*) pf_sfDrawable_Destroy;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetX;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetY;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetPosition;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetScaleX;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetScaleY;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetScale;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetRotation;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetOrigin;
|
||||
typedef void function(void*, Color) pf_sfDrawable_SetColor;
|
||||
typedef void function(void*, BlendMode) pf_sfDrawable_SetBlendMode;
|
||||
typedef float function(void*) pf_sfDrawable_GetX;
|
||||
typedef float function(void*) pf_sfDrawable_GetY;
|
||||
typedef float function(void*) pf_sfDrawable_GetScaleX;
|
||||
typedef float function(void*) pf_sfDrawable_GetScaleY;
|
||||
typedef float function(void*) pf_sfDrawable_GetRotation;
|
||||
typedef float function(void*) pf_sfDrawable_GetOriginX;
|
||||
typedef float function(void*) pf_sfDrawable_GetOriginY;
|
||||
typedef Color function(void*) pf_sfDrawable_GetColor;
|
||||
typedef BlendMode function(void*) pf_sfDrawable_GetBlendMode;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_Move;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_Scale;
|
||||
typedef void function(void*, float) pf_sfDrawable_Rotate;
|
||||
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToLocal;
|
||||
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToGlobal;
|
||||
|
||||
typedef void function(void*, void*) pf_sfRenderWindow_DrawThis;
|
||||
typedef void function(void*, void*, void*) pf_sfRenderWindow_DrawThisWithShader;
|
||||
|
||||
static pf_sfDrawable_Create sfDrawable_Create;
|
||||
static pf_sfDrawable_Destroy sfDrawable_Destroy;
|
||||
static pf_sfDrawable_SetX sfDrawable_SetX;
|
||||
static pf_sfDrawable_SetY sfDrawable_SetY;
|
||||
static pf_sfDrawable_SetPosition sfDrawable_SetPosition;
|
||||
static pf_sfDrawable_SetScaleX sfDrawable_SetScaleX;
|
||||
static pf_sfDrawable_SetScaleY sfDrawable_SetScaleY;
|
||||
static pf_sfDrawable_SetScale sfDrawable_SetScale;
|
||||
static pf_sfDrawable_SetRotation sfDrawable_SetRotation;
|
||||
static pf_sfDrawable_SetOrigin sfDrawable_SetOrigin;
|
||||
static pf_sfDrawable_SetColor sfDrawable_SetColor;
|
||||
static pf_sfDrawable_SetBlendMode sfDrawable_SetBlendMode;
|
||||
static pf_sfDrawable_GetX sfDrawable_GetX;
|
||||
static pf_sfDrawable_GetY sfDrawable_GetY;
|
||||
static pf_sfDrawable_GetScaleX sfDrawable_GetScaleX;
|
||||
static pf_sfDrawable_GetScaleY sfDrawable_GetScaleY;
|
||||
static pf_sfDrawable_GetRotation sfDrawable_GetRotation;
|
||||
static pf_sfDrawable_GetOriginX sfDrawable_GetOriginX;
|
||||
static pf_sfDrawable_GetOriginY sfDrawable_GetOriginY;
|
||||
static pf_sfDrawable_GetColor sfDrawable_GetColor;
|
||||
static pf_sfDrawable_GetBlendMode sfDrawable_GetBlendMode;
|
||||
static pf_sfDrawable_Move sfDrawable_Move;
|
||||
static pf_sfDrawable_Scale sfDrawable_Scale;
|
||||
static pf_sfDrawable_Rotate sfDrawable_Rotate;
|
||||
static pf_sfDrawable_TransformToLocal sfDrawable_TransformToLocal;
|
||||
static pf_sfDrawable_TransformToGlobal sfDrawable_TransformToGlobal;
|
||||
|
||||
static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis;
|
||||
static pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfDrawable_Create;
|
||||
typedef void function(void*) pf_sfDrawable_Destroy;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetX;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetY;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetPosition;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetScaleX;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetScaleY;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetScale;
|
||||
typedef void function(void*, float) pf_sfDrawable_SetRotation;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_SetOrigin;
|
||||
typedef void function(void*, Color) pf_sfDrawable_SetColor;
|
||||
typedef void function(void*, BlendMode) pf_sfDrawable_SetBlendMode;
|
||||
typedef float function(void*) pf_sfDrawable_GetX;
|
||||
typedef float function(void*) pf_sfDrawable_GetY;
|
||||
typedef float function(void*) pf_sfDrawable_GetScaleX;
|
||||
typedef float function(void*) pf_sfDrawable_GetScaleY;
|
||||
typedef float function(void*) pf_sfDrawable_GetRotation;
|
||||
typedef float function(void*) pf_sfDrawable_GetOriginX;
|
||||
typedef float function(void*) pf_sfDrawable_GetOriginY;
|
||||
typedef Color function(void*) pf_sfDrawable_GetColor;
|
||||
typedef BlendMode function(void*) pf_sfDrawable_GetBlendMode;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_Move;
|
||||
typedef void function(void*, float, float) pf_sfDrawable_Scale;
|
||||
typedef void function(void*, float) pf_sfDrawable_Rotate;
|
||||
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToLocal;
|
||||
typedef void function(void*, float, float, float*, float*) pf_sfDrawable_TransformToGlobal;
|
||||
|
||||
typedef void function(void*, void*) pf_sfRenderWindow_DrawThis;
|
||||
typedef void function(void*, void*, void*) pf_sfRenderWindow_DrawThisWithShader;
|
||||
|
||||
static pf_sfDrawable_Create sfDrawable_Create;
|
||||
static pf_sfDrawable_Destroy sfDrawable_Destroy;
|
||||
static pf_sfDrawable_SetX sfDrawable_SetX;
|
||||
static pf_sfDrawable_SetY sfDrawable_SetY;
|
||||
static pf_sfDrawable_SetPosition sfDrawable_SetPosition;
|
||||
static pf_sfDrawable_SetScaleX sfDrawable_SetScaleX;
|
||||
static pf_sfDrawable_SetScaleY sfDrawable_SetScaleY;
|
||||
static pf_sfDrawable_SetScale sfDrawable_SetScale;
|
||||
static pf_sfDrawable_SetRotation sfDrawable_SetRotation;
|
||||
static pf_sfDrawable_SetOrigin sfDrawable_SetOrigin;
|
||||
static pf_sfDrawable_SetColor sfDrawable_SetColor;
|
||||
static pf_sfDrawable_SetBlendMode sfDrawable_SetBlendMode;
|
||||
static pf_sfDrawable_GetX sfDrawable_GetX;
|
||||
static pf_sfDrawable_GetY sfDrawable_GetY;
|
||||
static pf_sfDrawable_GetScaleX sfDrawable_GetScaleX;
|
||||
static pf_sfDrawable_GetScaleY sfDrawable_GetScaleY;
|
||||
static pf_sfDrawable_GetRotation sfDrawable_GetRotation;
|
||||
static pf_sfDrawable_GetOriginX sfDrawable_GetOriginX;
|
||||
static pf_sfDrawable_GetOriginY sfDrawable_GetOriginY;
|
||||
static pf_sfDrawable_GetColor sfDrawable_GetColor;
|
||||
static pf_sfDrawable_GetBlendMode sfDrawable_GetBlendMode;
|
||||
static pf_sfDrawable_Move sfDrawable_Move;
|
||||
static pf_sfDrawable_Scale sfDrawable_Scale;
|
||||
static pf_sfDrawable_Rotate sfDrawable_Rotate;
|
||||
static pf_sfDrawable_TransformToLocal sfDrawable_TransformToLocal;
|
||||
static pf_sfDrawable_TransformToGlobal sfDrawable_TransformToGlobal;
|
||||
|
||||
static pf_sfRenderWindow_DrawThis sfRenderWindow_DrawThis;
|
||||
static pf_sfRenderWindow_DrawThisWithShader sfRenderWindow_DrawThisWithShader;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
static if (is (T : sfSprite))
|
||||
{
|
||||
string symbol = "sfSprite";
|
||||
}
|
||||
else static if (is (T : sfText))
|
||||
{
|
||||
string symbol = "sfText";
|
||||
}
|
||||
else static if (is (T : sfShape))
|
||||
{
|
||||
string symbol = "sfShape";
|
||||
}
|
||||
|
||||
sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create");
|
||||
sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy");
|
||||
sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX");
|
||||
sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY");
|
||||
sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition");
|
||||
sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX");
|
||||
sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY");
|
||||
sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale");
|
||||
sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation");
|
||||
sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin");
|
||||
sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor");
|
||||
sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode");
|
||||
sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX");
|
||||
sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY");
|
||||
sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX");
|
||||
sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(symbol ~ "_GetScaleX");
|
||||
sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation");
|
||||
sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX");
|
||||
sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY");
|
||||
sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor");
|
||||
sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode");
|
||||
sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move");
|
||||
sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale");
|
||||
sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate");
|
||||
sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal");
|
||||
sfDrawable_TransformToGlobal = cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal");
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
static if (is (T : sfSprite))
|
||||
{
|
||||
string symbol = "sfSprite";
|
||||
}
|
||||
else static if (is (T : sfText))
|
||||
{
|
||||
string symbol = "sfText";
|
||||
}
|
||||
else static if (is (T : sfShape))
|
||||
{
|
||||
string symbol = "sfShape";
|
||||
}
|
||||
|
||||
sfDrawable_Create = cast(pf_sfDrawable_Create)dll.getSymbol(symbol ~ "_Create");
|
||||
sfDrawable_Destroy = cast(pf_sfDrawable_Destroy)dll.getSymbol(symbol ~ "_Destroy");
|
||||
sfDrawable_SetX = cast(pf_sfDrawable_SetX)dll.getSymbol(symbol ~ "_SetX");
|
||||
sfDrawable_SetY = cast(pf_sfDrawable_SetY)dll.getSymbol(symbol ~ "_SetY");
|
||||
sfDrawable_SetPosition = cast(pf_sfDrawable_SetPosition)dll.getSymbol(symbol ~ "_SetPosition");
|
||||
sfDrawable_SetScaleX = cast(pf_sfDrawable_SetScaleX)dll.getSymbol(symbol ~ "_SetScaleX");
|
||||
sfDrawable_SetScaleY = cast(pf_sfDrawable_SetScaleY)dll.getSymbol(symbol ~ "_SetScaleY");
|
||||
sfDrawable_SetScale = cast(pf_sfDrawable_SetScale)dll.getSymbol(symbol ~ "_SetScale");
|
||||
sfDrawable_SetRotation = cast(pf_sfDrawable_SetRotation)dll.getSymbol(symbol ~ "_SetRotation");
|
||||
sfDrawable_SetOrigin = cast(pf_sfDrawable_SetOrigin)dll.getSymbol(symbol ~ "_SetOrigin");
|
||||
sfDrawable_SetColor = cast(pf_sfDrawable_SetColor)dll.getSymbol(symbol ~ "_SetColor");
|
||||
sfDrawable_SetBlendMode = cast(pf_sfDrawable_SetBlendMode)dll.getSymbol(symbol ~ "_SetBlendMode");
|
||||
sfDrawable_GetX = cast(pf_sfDrawable_GetX)dll.getSymbol(symbol ~ "_GetX");
|
||||
sfDrawable_GetY = cast(pf_sfDrawable_GetY)dll.getSymbol(symbol ~ "_GetY");
|
||||
sfDrawable_GetScaleX = cast(pf_sfDrawable_GetScaleX)dll.getSymbol(symbol ~ "_GetScaleX");
|
||||
sfDrawable_GetScaleY = cast(pf_sfDrawable_GetScaleY)dll.getSymbol(symbol ~ "_GetScaleX");
|
||||
sfDrawable_GetRotation = cast(pf_sfDrawable_GetRotation)dll.getSymbol(symbol ~ "_GetRotation");
|
||||
sfDrawable_GetOriginX = cast(pf_sfDrawable_GetOriginX)dll.getSymbol(symbol ~ "_GetOriginX");
|
||||
sfDrawable_GetOriginY = cast(pf_sfDrawable_GetOriginY)dll.getSymbol(symbol ~ "_GetOriginY");
|
||||
sfDrawable_GetColor = cast(pf_sfDrawable_GetColor)dll.getSymbol(symbol ~ "_GetColor");
|
||||
sfDrawable_GetBlendMode = cast(pf_sfDrawable_GetBlendMode)dll.getSymbol(symbol ~ "_GetBlendMode");
|
||||
sfDrawable_Move = cast(pf_sfDrawable_Move)dll.getSymbol(symbol ~ "_Move");
|
||||
sfDrawable_Scale = cast(pf_sfDrawable_Scale)dll.getSymbol(symbol ~ "_Scale");
|
||||
sfDrawable_Rotate = cast(pf_sfDrawable_Rotate)dll.getSymbol(symbol ~ "_Rotate");
|
||||
sfDrawable_TransformToLocal = cast(pf_sfDrawable_TransformToLocal)dll.getSymbol(symbol ~ "_TransformToLocal");
|
||||
sfDrawable_TransformToGlobal = cast(pf_sfDrawable_TransformToGlobal)dll.getSymbol(symbol ~ "_TransformToGlobal");
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.font;
|
||||
|
@ -43,8 +43,8 @@ struct Glyph
|
|||
}
|
||||
|
||||
/**
|
||||
* Font is the low-level class for loading and
|
||||
* manipulating character fonts.
|
||||
* Font is the low-level class for loading and
|
||||
* manipulating character fonts.
|
||||
*/
|
||||
class Font : DSFMLObject
|
||||
{
|
||||
|
@ -53,54 +53,54 @@ private:
|
|||
public:
|
||||
|
||||
/**
|
||||
* Get SFML default built-in font (Arial)
|
||||
*/
|
||||
static Font getDefaultFont()
|
||||
{
|
||||
if (s_default is null)
|
||||
s_default = new Font(sfFont_GetDefaultFont());
|
||||
return s_default;
|
||||
}
|
||||
* Get SFML default built-in font (Arial)
|
||||
*/
|
||||
static Font getDefaultFont()
|
||||
{
|
||||
if (s_default is null)
|
||||
s_default = new Font(sfFont_GetDefaultFont());
|
||||
return s_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* construct the Font from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = font file to load
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
/**
|
||||
* construct the Font from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = font file to load
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfFont_CreateFromFile(toStringz(filename)));
|
||||
}
|
||||
|
||||
/**
|
||||
* construct the Font from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = data to load
|
||||
*/
|
||||
this(ubyte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new Exception("LoadingException : Memory stream is invalid.");
|
||||
super(sfFont_CreateFromFile(toStringz(filename)));
|
||||
}
|
||||
|
||||
/**
|
||||
* construct the Font from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = data to load
|
||||
*/
|
||||
this(ubyte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new Exception("LoadingException : Memory stream is invalid.");
|
||||
|
||||
super(sfFont_CreateFromMemory(data.ptr, data.length));
|
||||
}
|
||||
super(sfFont_CreateFromMemory(data.ptr, data.length));
|
||||
}
|
||||
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfFont_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfFont_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
package:
|
||||
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.idrawable;
|
||||
|
@ -35,259 +35,259 @@ import dsfml.graphics.color,
|
|||
|
||||
|
||||
/**
|
||||
* Interface for drawable object
|
||||
*
|
||||
* Shape, Text and Sprite implement IDrawable
|
||||
* Interface for drawable object
|
||||
*
|
||||
* Shape, Text and Sprite implement IDrawable
|
||||
*/
|
||||
interface IDrawable
|
||||
{
|
||||
/**
|
||||
* Set the left position of the object
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
*/
|
||||
void setX(float x);
|
||||
/**
|
||||
* Set the left position of the object
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
*/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Set the top position of the object
|
||||
*
|
||||
* Params:
|
||||
* y = New top coordinate
|
||||
*/
|
||||
void setY(float y);
|
||||
/**
|
||||
* Set the top position of the object
|
||||
*
|
||||
* Params:
|
||||
* y = New top coordinate
|
||||
*/
|
||||
void setY(float y);
|
||||
|
||||
|
||||
/**
|
||||
* Set the position of the object
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
* y = New top coordinate
|
||||
*/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Set the position of the object
|
||||
*
|
||||
* Params:
|
||||
* vec = new position
|
||||
*/
|
||||
void setPosition(Vector2f vec);
|
||||
|
||||
/**
|
||||
* Set the horizontal scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = New horizontal scale (Strictly positive)
|
||||
*/
|
||||
void setScaleX(float scale);
|
||||
|
||||
/**
|
||||
* Set the vertical scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = New vertical scale (Strictly positive)
|
||||
*/
|
||||
void setScaleY(float scale);
|
||||
/**
|
||||
* Set the position of the object
|
||||
*
|
||||
* Params:
|
||||
* x = New left coordinate
|
||||
* y = New top coordinate
|
||||
*/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Set the position of the object
|
||||
*
|
||||
* Params:
|
||||
* vec = new position
|
||||
*/
|
||||
void setPosition(Vector2f vec);
|
||||
|
||||
/**
|
||||
* Set the horizontal scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = New horizontal scale (Strictly positive)
|
||||
*/
|
||||
void setScaleX(float scale);
|
||||
|
||||
/**
|
||||
* Set the vertical scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = New vertical scale (Strictly positive)
|
||||
*/
|
||||
void setScaleY(float scale);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scaleX = New horizontal scale
|
||||
* scaleY = New vertical scale
|
||||
*/
|
||||
void setScale(float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = new scale
|
||||
*/
|
||||
void setScale(Vector2f scale);
|
||||
|
||||
/**
|
||||
* Set the origin of the object, in coordinates relative to the
|
||||
* top-left of the object (take 2 values).
|
||||
* The default origin is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* originX : X coordinate of the origin
|
||||
* originY : Y coordinate of the origin
|
||||
*/
|
||||
void setOrigin(float originX, float originY);
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scaleX = New horizontal scale
|
||||
* scaleY = New vertical scale
|
||||
*/
|
||||
void setScale(float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scale = new scale
|
||||
*/
|
||||
void setScale(Vector2f scale);
|
||||
|
||||
/**
|
||||
* Set the origin of the object, in coordinates relative to the
|
||||
* top-left of the object (take 2 values).
|
||||
* The default origin is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* originX : X coordinate of the origin
|
||||
* originY : Y coordinate of the origin
|
||||
*/
|
||||
void setOrigin(float originX, float originY);
|
||||
|
||||
/**
|
||||
* Set the origin of the object, in coordinates relative to the
|
||||
* top-left of the object (take a 2D vector).
|
||||
* The default origin is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* origin : New origin
|
||||
*/
|
||||
void setOrigin(Vector2f origin);
|
||||
/**
|
||||
* Set the origin of the object, in coordinates relative to the
|
||||
* top-left of the object (take a 2D vector).
|
||||
* The default origin is (0, 0)
|
||||
*
|
||||
* Params:
|
||||
* origin : New origin
|
||||
*/
|
||||
void setOrigin(Vector2f origin);
|
||||
|
||||
|
||||
/**
|
||||
* Set the rotation of the object
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation, in degree
|
||||
*/
|
||||
void setRotation(float angle);
|
||||
|
||||
/**
|
||||
* Set the color
|
||||
*
|
||||
* Params:
|
||||
* c = New color
|
||||
*/
|
||||
void setColor(Color c);
|
||||
|
||||
/**
|
||||
* Set the blending mode for the object.
|
||||
* The default blend mode is Blend.Alpha
|
||||
*
|
||||
* Params:
|
||||
* mode = New blending mode
|
||||
*/
|
||||
void setBlendMode(BlendMode mode);
|
||||
|
||||
/**
|
||||
* Set the rotation of the object
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation, in degree
|
||||
*/
|
||||
void setRotation(float angle);
|
||||
|
||||
/**
|
||||
* Set the color
|
||||
*
|
||||
* Params:
|
||||
* c = New color
|
||||
*/
|
||||
void setColor(Color c);
|
||||
|
||||
/**
|
||||
* Set the blending mode for the object.
|
||||
* The default blend mode is Blend.Alpha
|
||||
*
|
||||
* Params:
|
||||
* mode = New blending mode
|
||||
*/
|
||||
void setBlendMode(BlendMode mode);
|
||||
|
||||
/**
|
||||
* Get the position of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position
|
||||
*
|
||||
*/
|
||||
Vector2f getPosition();
|
||||
/**
|
||||
* Get the position of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position
|
||||
*
|
||||
*/
|
||||
Vector2f getPosition();
|
||||
|
||||
/**
|
||||
* Get the current scale of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current scale
|
||||
*/
|
||||
Vector2f getScale();
|
||||
|
||||
/**
|
||||
* Get the origin of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position of the origin
|
||||
*
|
||||
*/
|
||||
Vector2f getOrigin();
|
||||
|
||||
/**
|
||||
* Get the rotation angle of the object
|
||||
*
|
||||
* Returns:
|
||||
* Angle of rotation, in degree
|
||||
*/
|
||||
float getRotation();
|
||||
|
||||
/**
|
||||
* Get the color of the string
|
||||
*
|
||||
* Returns:
|
||||
* Current color
|
||||
*/
|
||||
Color getColor();
|
||||
/**
|
||||
* Get the current scale of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current scale
|
||||
*/
|
||||
Vector2f getScale();
|
||||
|
||||
/**
|
||||
* Get the origin of the object
|
||||
*
|
||||
* Returns:
|
||||
* Current position of the origin
|
||||
*
|
||||
*/
|
||||
Vector2f getOrigin();
|
||||
|
||||
/**
|
||||
* Get the rotation angle of the object
|
||||
*
|
||||
* Returns:
|
||||
* Angle of rotation, in degree
|
||||
*/
|
||||
float getRotation();
|
||||
|
||||
/**
|
||||
* Get the color of the string
|
||||
*
|
||||
* Returns:
|
||||
* Current color
|
||||
*/
|
||||
Color getColor();
|
||||
|
||||
/**
|
||||
* Get the current blending mode
|
||||
*
|
||||
* Returns:
|
||||
* Current blending mode
|
||||
*/
|
||||
BlendMode getBlendMode();
|
||||
/**
|
||||
* Get the current blending mode
|
||||
*
|
||||
* Returns:
|
||||
* Current blending mode
|
||||
*/
|
||||
BlendMode getBlendMode();
|
||||
|
||||
/**
|
||||
* Rotate the object
|
||||
* Angle is added to the current orientation of the objet
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation in degree
|
||||
*/
|
||||
void rotate(float angle);
|
||||
/**
|
||||
* Rotate the object
|
||||
* Angle is added to the current orientation of the objet
|
||||
*
|
||||
* Params:
|
||||
* angle = Angle of rotation in degree
|
||||
*/
|
||||
void rotate(float angle);
|
||||
|
||||
/**
|
||||
* Move the object
|
||||
* New offset is added to object current position
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset on the X axis
|
||||
* offsetY = Offset on the Y axis
|
||||
*/
|
||||
void move(float offsetX, float offsetY);
|
||||
|
||||
/**
|
||||
* Move the object
|
||||
* New offset is added to object current position
|
||||
*
|
||||
* Params:
|
||||
* offset = Amount of units to move the object of
|
||||
*/
|
||||
void move(Vector2f offset);
|
||||
/**
|
||||
* Move the object
|
||||
* New offset is added to object current position
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset on the X axis
|
||||
* offsetY = Offset on the Y axis
|
||||
*/
|
||||
void move(float offsetX, float offsetY);
|
||||
|
||||
/**
|
||||
* Move the object
|
||||
* New offset is added to object current position
|
||||
*
|
||||
* Params:
|
||||
* offset = Amount of units to move the object of
|
||||
*/
|
||||
void move(Vector2f offset);
|
||||
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scaleX = New horizontal scale (Strictly positive)
|
||||
* scaleY = New vertical scale (Strictly positive)
|
||||
*/
|
||||
void scale(float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* Scale the object (take a 2D vector)
|
||||
*
|
||||
* Params:
|
||||
* factor = Scaling factors (both values must be strictly positive)
|
||||
*/
|
||||
void scale(Vector2f factor);
|
||||
|
||||
/**
|
||||
* Transform a point from global coordinates into local coordinates
|
||||
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f tranformToLocal(Vector2f point);
|
||||
/**
|
||||
* Set the scale of the object
|
||||
*
|
||||
* Params:
|
||||
* scaleX = New horizontal scale (Strictly positive)
|
||||
* scaleY = New vertical scale (Strictly positive)
|
||||
*/
|
||||
void scale(float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* Scale the object (take a 2D vector)
|
||||
*
|
||||
* Params:
|
||||
* factor = Scaling factors (both values must be strictly positive)
|
||||
*/
|
||||
void scale(Vector2f factor);
|
||||
|
||||
/**
|
||||
* Transform a point from global coordinates into local coordinates
|
||||
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f tranformToLocal(Vector2f point);
|
||||
|
||||
/**
|
||||
* Transform a point from local coordinates into global coordinates
|
||||
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f tranformToGlobal(Vector2f point);
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object
|
||||
*
|
||||
* Params:
|
||||
* window = Target into which render the object
|
||||
*/
|
||||
void render(RenderWindow window);
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object with a shader
|
||||
*
|
||||
* Params:
|
||||
* window = Render target
|
||||
* shader = Shader to use
|
||||
*/
|
||||
void renderWithShader(RenderWindow window, Shader shader);
|
||||
/**
|
||||
* Transform a point from local coordinates into global coordinates
|
||||
* (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
*
|
||||
* Params:
|
||||
* point = Point to transform
|
||||
*
|
||||
* Returns:
|
||||
* Transformed point
|
||||
*/
|
||||
Vector2f tranformToGlobal(Vector2f point);
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object
|
||||
*
|
||||
* Params:
|
||||
* window = Target into which render the object
|
||||
*/
|
||||
void render(RenderWindow window);
|
||||
|
||||
/**
|
||||
* Render the specific geometry of the object with a shader
|
||||
*
|
||||
* Params:
|
||||
* window = Render target
|
||||
* shader = Shader to use
|
||||
*/
|
||||
void renderWithShader(RenderWindow window, Shader shader);
|
||||
}
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
|
||||
|
@ -37,331 +37,331 @@ import dsfml.system.common,
|
|||
|
||||
|
||||
/**
|
||||
* Image is the low-level class for loading and
|
||||
* manipulating images
|
||||
* Image is the low-level class for loading and
|
||||
* manipulating images
|
||||
*/
|
||||
class Image : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfImage_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an empty image
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* col = Image color (black by default)
|
||||
*/
|
||||
this(uint width, uint height, Color col = Color.BLACK)
|
||||
/**
|
||||
* Construct an empty image
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* col = Image color (black by default)
|
||||
*/
|
||||
this(uint width, uint height, Color col = Color.BLACK)
|
||||
{
|
||||
super(sfImage_CreateFromColor(width, height, col));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the image from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the image file to load
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException if filename is empty or null.
|
||||
*/
|
||||
this(string filename)
|
||||
/**
|
||||
* Construct the image from a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the image file to load
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException if filename is empty or null.
|
||||
*/
|
||||
this(string filename)
|
||||
{
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
if (filename is null || filename.length == 0)
|
||||
throw new LoadingException("LoadingException : Filename is invalid.");
|
||||
|
||||
super(sfImage_CreateFromFile(toStringz(filename)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the image from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = array of data in memory
|
||||
* Throws:
|
||||
* LoadingException if data is empty or null.
|
||||
*/
|
||||
this(ubyte[] data)
|
||||
/**
|
||||
* Construct the image from a file in memory
|
||||
*
|
||||
* Params:
|
||||
* data = array of data in memory
|
||||
* Throws:
|
||||
* LoadingException if data is empty or null.
|
||||
*/
|
||||
this(ubyte[] data)
|
||||
{
|
||||
if (data is null || data.length == 0)
|
||||
throw new LoadingException("LoadingException : Memory stream is invalid.");
|
||||
|
||||
if (data is null || data.length == 0)
|
||||
throw new LoadingException("LoadingException : Memory stream is invalid.");
|
||||
|
||||
super(sfImage_CreateFromMemory(data.ptr, data.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the image directly from an array of pixels
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* data = array of pixels in memory (assumed format is RGBA)
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException if data length doesn't match Width * Height * 4
|
||||
*/
|
||||
this(uint width, uint height, ubyte[] data)
|
||||
/**
|
||||
* Construct the image directly from an array of pixels
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* data = array of pixels in memory (assumed format is RGBA)
|
||||
*
|
||||
* Throws:
|
||||
* LoadingException if data length doesn't match Width * Height * 4
|
||||
*/
|
||||
this(uint width, uint height, ubyte[] data)
|
||||
{
|
||||
if (width * height * 4 != data.length)
|
||||
throw new LoadingException("LoadingException : Pixels array length doesn't match the specified size.");
|
||||
|
||||
if (width * height * 4 != data.length)
|
||||
throw new LoadingException("LoadingException : Pixels array length doesn't match the specified size.");
|
||||
|
||||
super(sfImage_CreateFromPixels(width, height, data.ptr));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
override void dispose()
|
||||
{
|
||||
sfImage_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the content of the image to a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the file to save (overwritten if already exist)
|
||||
*
|
||||
* Returns:
|
||||
* True if saving was successful
|
||||
*/
|
||||
bool saveToFile(string filename)
|
||||
/**
|
||||
* Save the content of the image to a file
|
||||
*
|
||||
* Params:
|
||||
* filename = Path of the file to save (overwritten if already exist)
|
||||
*
|
||||
* Returns:
|
||||
* True if saving was successful
|
||||
*/
|
||||
bool saveToFile(string filename)
|
||||
{
|
||||
return cast(bool)sfImage_SaveToFile(m_ptr, toStringz(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty image
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* col = Image color (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* True if creation was successful
|
||||
*/
|
||||
bool create(uint width, uint height, Color col = Color.BLACK)
|
||||
/**
|
||||
* Create an empty image
|
||||
*
|
||||
* Params:
|
||||
* width = Image width
|
||||
* height = Image height
|
||||
* col = Image color (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* True if creation was successful
|
||||
*/
|
||||
bool create(uint width, uint height, Color col = Color.BLACK)
|
||||
{
|
||||
m_ptr = sfImage_CreateFromColor(width, height, col);
|
||||
return (m_ptr !is null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create transparency mask from a specified colorkey
|
||||
*
|
||||
* Params:
|
||||
* colorKey = Color to become transparent
|
||||
* alpha = Alpha value to use for transparent pixels (0 by default)
|
||||
*/
|
||||
void createMaskFromColor(Color colorKey, ubyte alpha = 0)
|
||||
/**
|
||||
* Create transparency mask from a specified colorkey
|
||||
*
|
||||
* Params:
|
||||
* colorKey = Color to become transparent
|
||||
* alpha = Alpha value to use for transparent pixels (0 by default)
|
||||
*/
|
||||
void createMaskFromColor(Color colorKey, ubyte alpha = 0)
|
||||
{
|
||||
sfImage_CreateMaskFromColor(m_ptr, colorKey, alpha);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Create the image from the current contents of the
|
||||
// * given window
|
||||
// *
|
||||
// * Params:
|
||||
// * window = Window to capture
|
||||
// * sourceRect = Sub-rectangle of the screen to copy (empty by default - entire image)
|
||||
// *
|
||||
// * Returns:
|
||||
// * True if copy was successful
|
||||
// */
|
||||
// void copyScreen(RenderWindow window, IntRect sourceRect = new IntRect())
|
||||
// {
|
||||
// return cast(bool)sfImage_CopyScreen(m_ptr, window.getNativePointer, sourceRect.toCIntRect());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Copy pixels from another image onto this one.
|
||||
* This function does a slow pixel copy and should only
|
||||
* be used at initialization time
|
||||
*
|
||||
* Params:
|
||||
* source = Source image to copy
|
||||
* destX = X coordinate of the destination position
|
||||
* destY = Y coordinate of the destination position
|
||||
* sourceRect = Sub-rectangle of the source image to copy
|
||||
*/
|
||||
void copy(Image source, uint destX, uint destY, IntRect sourceRect = new IntRect())
|
||||
{
|
||||
sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect.toCIntRect());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Create the image from the current contents of the
|
||||
// * given window
|
||||
// *
|
||||
// * Params:
|
||||
// * window = Window to capture
|
||||
// * sourceRect = Sub-rectangle of the screen to copy (empty by default - entire image)
|
||||
// *
|
||||
// * Returns:
|
||||
// * True if copy was successful
|
||||
// */
|
||||
// void copyScreen(RenderWindow window, IntRect sourceRect = new IntRect())
|
||||
// {
|
||||
// return cast(bool)sfImage_CopyScreen(m_ptr, window.getNativePointer, sourceRect.toCIntRect());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Copy pixels from another image onto this one.
|
||||
* This function does a slow pixel copy and should only
|
||||
* be used at initialization time
|
||||
*
|
||||
* Params:
|
||||
* source = Source image to copy
|
||||
* destX = X coordinate of the destination position
|
||||
* destY = Y coordinate of the destination position
|
||||
* sourceRect = Sub-rectangle of the source image to copy
|
||||
*/
|
||||
void copy(Image source, uint destX, uint destY, IntRect sourceRect = new IntRect())
|
||||
{
|
||||
sfImage_Copy(m_ptr, source.getNativePointer, destX, destY, sourceRect.toCIntRect());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color of a pixel
|
||||
* Don't forget to call Update when you end modifying pixels
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of pixel in the image
|
||||
* y = Y coordinate of pixel in the image
|
||||
* col = New color for pixel (X, Y)
|
||||
*/
|
||||
void setPixel(uint x, uint y, Color col)
|
||||
/**
|
||||
* Change the color of a pixel
|
||||
* Don't forget to call Update when you end modifying pixels
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of pixel in the image
|
||||
* y = Y coordinate of pixel in the image
|
||||
* col = New color for pixel (X, Y)
|
||||
*/
|
||||
void setPixel(uint x, uint y, Color col)
|
||||
{
|
||||
sfImage_SetPixel(m_ptr, x, y, col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pixel from the image
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of pixel in the image
|
||||
* y = Y coordinate of pixel in the image
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel (x, y)
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
/**
|
||||
* Get a pixel from the image
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of pixel in the image
|
||||
* y = Y coordinate of pixel in the image
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel (x, y)
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
{
|
||||
return sfImage_GetPixel(m_ptr, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of pixels (8 bits integers RGBA)
|
||||
* Array size is GetWidth() x GetHeight() x 4
|
||||
* This array becomes invalid if you reload or resize the image
|
||||
*
|
||||
* Returns:
|
||||
* array of pixels
|
||||
*/
|
||||
ubyte[] getPixelsArray()
|
||||
/**
|
||||
* Get an array of pixels (8 bits integers RGBA)
|
||||
* Array size is GetWidth() x GetHeight() x 4
|
||||
* This array becomes invalid if you reload or resize the image
|
||||
*
|
||||
* Returns:
|
||||
* array of pixels
|
||||
*/
|
||||
ubyte[] getPixelsArray()
|
||||
{
|
||||
return sfImage_GetPixelsPtr(m_ptr)[0..getWidth() * getHeight() * 4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the image for rendering
|
||||
*/
|
||||
void bind()
|
||||
/**
|
||||
* Bind the image for rendering
|
||||
*/
|
||||
void bind()
|
||||
{
|
||||
sfImage_Bind(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable image smooth filter.
|
||||
* This parameter is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* smooth = True to enable smoothing filter, false to disable it
|
||||
*/
|
||||
void setSmooth(bool smooth)
|
||||
/**
|
||||
* Enable or disable image smooth filter.
|
||||
* This parameter is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* smooth = True to enable smoothing filter, false to disable it
|
||||
*/
|
||||
void setSmooth(bool smooth)
|
||||
{
|
||||
sfImage_SetSmooth(m_ptr, smooth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the width of the image
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint getWidth()
|
||||
/**
|
||||
* Return the width of the image
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint getWidth()
|
||||
{
|
||||
return sfImage_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of the image
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint getHeight()
|
||||
/**
|
||||
* Return the height of the image
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint getHeight()
|
||||
{
|
||||
return sfImage_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the smooth filtering is enabled or not
|
||||
*
|
||||
* Returns:
|
||||
* True if image smoothing is enabled
|
||||
*/
|
||||
bool isSmooth()
|
||||
{
|
||||
return cast(bool)sfImage_IsSmooth(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tells whether the smooth filtering is enabled or not
|
||||
*
|
||||
* Returns:
|
||||
* True if image smoothing is enabled
|
||||
*/
|
||||
bool isSmooth()
|
||||
{
|
||||
return cast(bool)sfImage_IsSmooth(m_ptr);
|
||||
}
|
||||
|
||||
package:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfImage_Create;
|
||||
typedef void* function(uint, uint, Color) pf_sfImage_CreateFromColor;
|
||||
typedef void* function(uint, uint, ubyte*) pf_sfImage_CreateFromPixels;
|
||||
typedef void* function(cchar*) pf_sfImage_CreateFromFile;
|
||||
typedef void* function(ubyte* ,size_t) pf_sfImage_CreateFromMemory;
|
||||
typedef void function(void*) pf_sfImage_Destroy;
|
||||
typedef int function(void*, cchar*) pf_sfImage_SaveToFile;
|
||||
typedef void function(void*, Color, ubyte) pf_sfImage_CreateMaskFromColor;
|
||||
typedef int function(void*, void*, sfIntRect) pf_sfImage_CopyScreen;
|
||||
typedef void function(void*, void*, uint, uint, sfIntRect) pf_sfImage_Copy;
|
||||
typedef void function(void*, uint, uint, Color) pf_sfImage_SetPixel;
|
||||
typedef Color function(void*, uint, uint) pf_sfImage_GetPixel;
|
||||
typedef ubyte* function(void*) pf_sfImage_GetPixelsPtr;
|
||||
typedef void function(void*) pf_sfImage_Bind;
|
||||
typedef void function(void*, int) pf_sfImage_SetSmooth;
|
||||
typedef uint function(void*) pf_sfImage_GetWidth;
|
||||
typedef uint function(void*) pf_sfImage_GetHeight;
|
||||
typedef int function(void*) pf_sfImage_IsSmooth;
|
||||
|
||||
static pf_sfImage_Create sfImage_Create;
|
||||
static pf_sfImage_CreateFromColor sfImage_CreateFromColor;
|
||||
static pf_sfImage_CreateFromPixels sfImage_CreateFromPixels;
|
||||
static pf_sfImage_CreateFromFile sfImage_CreateFromFile;
|
||||
static pf_sfImage_CreateFromMemory sfImage_CreateFromMemory;
|
||||
static pf_sfImage_Destroy sfImage_Destroy;
|
||||
static pf_sfImage_SaveToFile sfImage_SaveToFile;
|
||||
static pf_sfImage_CreateMaskFromColor sfImage_CreateMaskFromColor;
|
||||
static pf_sfImage_CopyScreen sfImage_CopyScreen;
|
||||
static pf_sfImage_Copy sfImage_Copy;
|
||||
static pf_sfImage_SetPixel sfImage_SetPixel;
|
||||
static pf_sfImage_GetPixel sfImage_GetPixel;
|
||||
static pf_sfImage_GetPixelsPtr sfImage_GetPixelsPtr;
|
||||
static pf_sfImage_Bind sfImage_Bind;
|
||||
static pf_sfImage_SetSmooth sfImage_SetSmooth;
|
||||
static pf_sfImage_GetWidth sfImage_GetWidth;
|
||||
static pf_sfImage_GetHeight sfImage_GetHeight;
|
||||
static pf_sfImage_IsSmooth sfImage_IsSmooth;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfImage_Create;
|
||||
typedef void* function(uint, uint, Color) pf_sfImage_CreateFromColor;
|
||||
typedef void* function(uint, uint, ubyte*) pf_sfImage_CreateFromPixels;
|
||||
typedef void* function(cchar*) pf_sfImage_CreateFromFile;
|
||||
typedef void* function(ubyte* ,size_t) pf_sfImage_CreateFromMemory;
|
||||
typedef void function(void*) pf_sfImage_Destroy;
|
||||
typedef int function(void*, cchar*) pf_sfImage_SaveToFile;
|
||||
typedef void function(void*, Color, ubyte) pf_sfImage_CreateMaskFromColor;
|
||||
typedef int function(void*, void*, sfIntRect) pf_sfImage_CopyScreen;
|
||||
typedef void function(void*, void*, uint, uint, sfIntRect) pf_sfImage_Copy;
|
||||
typedef void function(void*, uint, uint, Color) pf_sfImage_SetPixel;
|
||||
typedef Color function(void*, uint, uint) pf_sfImage_GetPixel;
|
||||
typedef ubyte* function(void*) pf_sfImage_GetPixelsPtr;
|
||||
typedef void function(void*) pf_sfImage_Bind;
|
||||
typedef void function(void*, int) pf_sfImage_SetSmooth;
|
||||
typedef uint function(void*) pf_sfImage_GetWidth;
|
||||
typedef uint function(void*) pf_sfImage_GetHeight;
|
||||
typedef int function(void*) pf_sfImage_IsSmooth;
|
||||
|
||||
static pf_sfImage_Create sfImage_Create;
|
||||
static pf_sfImage_CreateFromColor sfImage_CreateFromColor;
|
||||
static pf_sfImage_CreateFromPixels sfImage_CreateFromPixels;
|
||||
static pf_sfImage_CreateFromFile sfImage_CreateFromFile;
|
||||
static pf_sfImage_CreateFromMemory sfImage_CreateFromMemory;
|
||||
static pf_sfImage_Destroy sfImage_Destroy;
|
||||
static pf_sfImage_SaveToFile sfImage_SaveToFile;
|
||||
static pf_sfImage_CreateMaskFromColor sfImage_CreateMaskFromColor;
|
||||
static pf_sfImage_CopyScreen sfImage_CopyScreen;
|
||||
static pf_sfImage_Copy sfImage_Copy;
|
||||
static pf_sfImage_SetPixel sfImage_SetPixel;
|
||||
static pf_sfImage_GetPixel sfImage_GetPixel;
|
||||
static pf_sfImage_GetPixelsPtr sfImage_GetPixelsPtr;
|
||||
static pf_sfImage_Bind sfImage_Bind;
|
||||
static pf_sfImage_SetSmooth sfImage_SetSmooth;
|
||||
static pf_sfImage_GetWidth sfImage_GetWidth;
|
||||
static pf_sfImage_GetHeight sfImage_GetHeight;
|
||||
static pf_sfImage_IsSmooth sfImage_IsSmooth;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfImage_Create = cast(pf_sfImage_Create)dll.getSymbol("sfImage_Create");
|
||||
sfImage_CreateFromColor = cast(pf_sfImage_CreateFromColor)dll.getSymbol("sfImage_CreateFromColor");
|
||||
sfImage_CreateFromPixels = cast(pf_sfImage_CreateFromPixels)dll.getSymbol("sfImage_CreateFromPixels");
|
||||
sfImage_CreateFromFile = cast(pf_sfImage_CreateFromFile)dll.getSymbol("sfImage_CreateFromFile");
|
||||
sfImage_CreateFromMemory = cast(pf_sfImage_CreateFromMemory)dll.getSymbol("sfImage_CreateFromMemory");
|
||||
sfImage_Destroy = cast(pf_sfImage_Destroy)dll.getSymbol("sfImage_Destroy");
|
||||
sfImage_SaveToFile = cast(pf_sfImage_SaveToFile)dll.getSymbol("sfImage_SaveToFile");
|
||||
sfImage_CreateMaskFromColor = cast(pf_sfImage_CreateMaskFromColor)dll.getSymbol("sfImage_CreateMaskFromColor");
|
||||
sfImage_CopyScreen = cast(pf_sfImage_CopyScreen)dll.getSymbol("sfImage_CopyScreen");
|
||||
sfImage_Copy = cast(pf_sfImage_Copy)dll.getSymbol("sfImage_Copy");
|
||||
sfImage_SetPixel = cast(pf_sfImage_SetPixel)dll.getSymbol("sfImage_SetPixel");
|
||||
sfImage_GetPixel = cast(pf_sfImage_GetPixel)dll.getSymbol("sfImage_GetPixel");
|
||||
sfImage_GetPixelsPtr = cast(pf_sfImage_GetPixelsPtr)dll.getSymbol("sfImage_GetPixelsPtr");
|
||||
sfImage_Bind = cast(pf_sfImage_Bind)dll.getSymbol("sfImage_Bind");
|
||||
sfImage_SetSmooth = cast(pf_sfImage_SetSmooth)dll.getSymbol("sfImage_SetSmooth");
|
||||
sfImage_GetWidth = cast(pf_sfImage_GetWidth)dll.getSymbol("sfImage_GetWidth");
|
||||
sfImage_GetHeight = cast(pf_sfImage_GetHeight)dll.getSymbol("sfImage_GetHeight");
|
||||
sfImage_IsSmooth = cast(pf_sfImage_IsSmooth)dll.getSymbol("sfImage_IsSmooth");
|
||||
}
|
||||
|
||||
sfImage_Create = cast(pf_sfImage_Create)dll.getSymbol("sfImage_Create");
|
||||
sfImage_CreateFromColor = cast(pf_sfImage_CreateFromColor)dll.getSymbol("sfImage_CreateFromColor");
|
||||
sfImage_CreateFromPixels = cast(pf_sfImage_CreateFromPixels)dll.getSymbol("sfImage_CreateFromPixels");
|
||||
sfImage_CreateFromFile = cast(pf_sfImage_CreateFromFile)dll.getSymbol("sfImage_CreateFromFile");
|
||||
sfImage_CreateFromMemory = cast(pf_sfImage_CreateFromMemory)dll.getSymbol("sfImage_CreateFromMemory");
|
||||
sfImage_Destroy = cast(pf_sfImage_Destroy)dll.getSymbol("sfImage_Destroy");
|
||||
sfImage_SaveToFile = cast(pf_sfImage_SaveToFile)dll.getSymbol("sfImage_SaveToFile");
|
||||
sfImage_CreateMaskFromColor = cast(pf_sfImage_CreateMaskFromColor)dll.getSymbol("sfImage_CreateMaskFromColor");
|
||||
sfImage_CopyScreen = cast(pf_sfImage_CopyScreen)dll.getSymbol("sfImage_CopyScreen");
|
||||
sfImage_Copy = cast(pf_sfImage_Copy)dll.getSymbol("sfImage_Copy");
|
||||
sfImage_SetPixel = cast(pf_sfImage_SetPixel)dll.getSymbol("sfImage_SetPixel");
|
||||
sfImage_GetPixel = cast(pf_sfImage_GetPixel)dll.getSymbol("sfImage_GetPixel");
|
||||
sfImage_GetPixelsPtr = cast(pf_sfImage_GetPixelsPtr)dll.getSymbol("sfImage_GetPixelsPtr");
|
||||
sfImage_Bind = cast(pf_sfImage_Bind)dll.getSymbol("sfImage_Bind");
|
||||
sfImage_SetSmooth = cast(pf_sfImage_SetSmooth)dll.getSymbol("sfImage_SetSmooth");
|
||||
sfImage_GetWidth = cast(pf_sfImage_GetWidth)dll.getSymbol("sfImage_GetWidth");
|
||||
sfImage_GetHeight = cast(pf_sfImage_GetHeight)dll.getSymbol("sfImage_GetHeight");
|
||||
sfImage_IsSmooth = cast(pf_sfImage_IsSmooth)dll.getSymbol("sfImage_IsSmooth");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,287 +1,287 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.rect;
|
||||
|
||||
struct sfFloatRect
|
||||
{
|
||||
float Left;
|
||||
float Top;
|
||||
float Right;
|
||||
float Bottom;
|
||||
float Left;
|
||||
float Top;
|
||||
float Right;
|
||||
float Bottom;
|
||||
}
|
||||
|
||||
struct sfIntRect
|
||||
{
|
||||
int Left;
|
||||
int Top;
|
||||
int Right;
|
||||
int Bottom;
|
||||
int Left;
|
||||
int Top;
|
||||
int Right;
|
||||
int Bottom;
|
||||
}
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
import tango.core.Traits;
|
||||
import tango.core.Traits;
|
||||
}
|
||||
else
|
||||
{
|
||||
template isIntegerType(T)
|
||||
{
|
||||
const bool isIntegerType =
|
||||
is (T == byte) ||
|
||||
is (T == short) ||
|
||||
is (T == int) ||
|
||||
is (T == long);
|
||||
}
|
||||
template isIntegerType(T)
|
||||
{
|
||||
const bool isIntegerType =
|
||||
is (T == byte) ||
|
||||
is (T == short) ||
|
||||
is (T == int) ||
|
||||
is (T == long);
|
||||
}
|
||||
|
||||
template isRealType(T)
|
||||
{
|
||||
const bool isRealType =
|
||||
is (T == float) ||
|
||||
is (T == double) ||
|
||||
is (T == real);
|
||||
}
|
||||
}
|
||||
template isRealType(T)
|
||||
{
|
||||
const bool isRealType =
|
||||
is (T == float) ||
|
||||
is (T == double) ||
|
||||
is (T == real);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Rect is an utility class for manipulating rectangles.
|
||||
* Template parameter defines the type of coordinates (integer float, ...)
|
||||
* Rect is an utility class for manipulating rectangles.
|
||||
* Template parameter defines the type of coordinates (integer float, ...)
|
||||
*/
|
||||
|
||||
class Rect (T)
|
||||
{
|
||||
|
||||
private:
|
||||
T m_Left; // Left coordinate of the rectangle
|
||||
T m_Top; // Top coordinate of the rectangle
|
||||
T m_Right; // Right coordinate of the rectangle
|
||||
T m_Bottom; // Bottom coordinate of the rectangle
|
||||
T m_Left; // Left coordinate of the rectangle
|
||||
T m_Top; // Top coordinate of the rectangle
|
||||
T m_Right; // Right coordinate of the rectangle
|
||||
T m_Bottom; // Bottom coordinate of the rectangle
|
||||
|
||||
public:
|
||||
static if (!isIntegerType!(T) && !isRealType!(T))
|
||||
{
|
||||
static assert (0, "This type is not supported by Rectangle");
|
||||
}
|
||||
|
||||
T min(T)(T i, T j)
|
||||
{
|
||||
return i < j ? i : j;
|
||||
}
|
||||
|
||||
T max(T)(T i, T j)
|
||||
{
|
||||
return i > j ? i : j;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
m_Left = 0;
|
||||
m_Top = 0;
|
||||
m_Right = 0;
|
||||
m_Bottom = 0;
|
||||
}
|
||||
{
|
||||
static assert (0, "This type is not supported by Rectangle");
|
||||
}
|
||||
|
||||
T min(T)(T i, T j)
|
||||
{
|
||||
return i < j ? i : j;
|
||||
}
|
||||
|
||||
T max(T)(T i, T j)
|
||||
{
|
||||
return i > j ? i : j;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
m_Left = 0;
|
||||
m_Top = 0;
|
||||
m_Right = 0;
|
||||
m_Bottom = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the rectangle from its coordinates
|
||||
*
|
||||
* Params:
|
||||
* leftCoord = Left coordinate of the rectangle
|
||||
* topCoord = Top coordinate of the rectangle
|
||||
* rightCoord = Right coordinate of the rectangle
|
||||
* bottomCoord = Bottom coordinate of the rectangle
|
||||
*/
|
||||
this(T leftCoord, T topCoord, T rightCoord, T bottomCoord)
|
||||
{
|
||||
m_Left = leftCoord;
|
||||
m_Top = topCoord;
|
||||
m_Right = rightCoord;
|
||||
m_Bottom = bottomCoord;
|
||||
}
|
||||
/**
|
||||
* Construct the rectangle from its coordinates
|
||||
*
|
||||
* Params:
|
||||
* leftCoord = Left coordinate of the rectangle
|
||||
* topCoord = Top coordinate of the rectangle
|
||||
* rightCoord = Right coordinate of the rectangle
|
||||
* bottomCoord = Bottom coordinate of the rectangle
|
||||
*/
|
||||
this(T leftCoord, T topCoord, T rightCoord, T bottomCoord)
|
||||
{
|
||||
m_Left = leftCoord;
|
||||
m_Top = topCoord;
|
||||
m_Right = rightCoord;
|
||||
m_Bottom = bottomCoord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the rectangle
|
||||
*
|
||||
* Returns:
|
||||
* Width of rectangle
|
||||
*/
|
||||
T getWidth()
|
||||
{
|
||||
return m_Right - m_Left;
|
||||
}
|
||||
/**
|
||||
* Get the width of the rectangle
|
||||
*
|
||||
* Returns:
|
||||
* Width of rectangle
|
||||
*/
|
||||
T getWidth()
|
||||
{
|
||||
return m_Right - m_Left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the rectangle
|
||||
*
|
||||
* Returns:
|
||||
* Height of rectangle
|
||||
*/
|
||||
T getHeight()
|
||||
{
|
||||
return m_Bottom - m_Top;
|
||||
}
|
||||
/**
|
||||
* Get the height of the rectangle
|
||||
*
|
||||
* Returns:
|
||||
* Height of rectangle
|
||||
*/
|
||||
T getHeight()
|
||||
{
|
||||
return m_Bottom - m_Top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the whole rectangle by the given offset
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Horizontal offset
|
||||
* offsetY = Vertical offset
|
||||
*/
|
||||
void offset(T offsetX, T offsetY)
|
||||
{
|
||||
m_Left += offsetX;
|
||||
m_Right += offsetX;
|
||||
m_Top += offsetY;
|
||||
m_Bottom += offsetY;
|
||||
}
|
||||
/**
|
||||
* Move the whole rectangle by the given offset
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Horizontal offset
|
||||
* offsetY = Vertical offset
|
||||
*/
|
||||
void offset(T offsetX, T offsetY)
|
||||
{
|
||||
m_Left += offsetX;
|
||||
m_Right += offsetX;
|
||||
m_Top += offsetY;
|
||||
m_Bottom += offsetY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is inside the rectangle's area
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of the point to test
|
||||
* y = Y coordinate of the point to test
|
||||
*
|
||||
* Returns:
|
||||
* True if the point is inside
|
||||
*/
|
||||
bool contains(T x, T y)
|
||||
{
|
||||
return (x >= m_Left) && (x <= m_Right) && (y >= m_Top) && (y <= m_Bottom);
|
||||
}
|
||||
/**
|
||||
* Check if a point is inside the rectangle's area
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate of the point to test
|
||||
* y = Y coordinate of the point to test
|
||||
*
|
||||
* Returns:
|
||||
* True if the point is inside
|
||||
*/
|
||||
bool contains(T x, T y)
|
||||
{
|
||||
return (x >= m_Left) && (x <= m_Right) && (y >= m_Top) && (y <= m_Bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check intersection between two rectangles
|
||||
*
|
||||
* Params:
|
||||
* rectangle = Rectangle to test
|
||||
* overlappingRect = Rectangle to be filled with overlapping rect (NULL by default)
|
||||
*
|
||||
* Returns:
|
||||
* True if rectangles overlap
|
||||
*/
|
||||
bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = null)
|
||||
{
|
||||
// Compute overlapping rect
|
||||
Rect!(T) overlapping = new Rect!(T)(
|
||||
max(m_Left, rectangle.getLeft),
|
||||
max(m_Top, rectangle.getTop),
|
||||
min(m_Right, rectangle.getRight),
|
||||
min(m_Bottom, rectangle.getBottom)
|
||||
);
|
||||
|
||||
// If overlapping rect is valid, then there is intersection
|
||||
if ((overlapping.getLeft() < overlapping.getRight() ) && (overlapping.getTop() < overlapping.getBottom()))
|
||||
{
|
||||
overlappingRect = overlapping;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlappingRect = new Rect!(T)();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left Coordinate
|
||||
*/
|
||||
void setLeft(T left)
|
||||
{
|
||||
m_Left = left;
|
||||
}
|
||||
/**
|
||||
* Check intersection between two rectangles
|
||||
*
|
||||
* Params:
|
||||
* rectangle = Rectangle to test
|
||||
* overlappingRect = Rectangle to be filled with overlapping rect (NULL by default)
|
||||
*
|
||||
* Returns:
|
||||
* True if rectangles overlap
|
||||
*/
|
||||
bool intersects(Rect!(T) rectangle, out Rect!(T) overlappingRect = null)
|
||||
{
|
||||
// Compute overlapping rect
|
||||
Rect!(T) overlapping = new Rect!(T)(
|
||||
max(m_Left, rectangle.getLeft),
|
||||
max(m_Top, rectangle.getTop),
|
||||
min(m_Right, rectangle.getRight),
|
||||
min(m_Bottom, rectangle.getBottom)
|
||||
);
|
||||
|
||||
// If overlapping rect is valid, then there is intersection
|
||||
if ((overlapping.getLeft() < overlapping.getRight() ) && (overlapping.getTop() < overlapping.getBottom()))
|
||||
{
|
||||
overlappingRect = overlapping;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlappingRect = new Rect!(T)();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left Coordinate
|
||||
*/
|
||||
void setLeft(T left)
|
||||
{
|
||||
m_Left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top Coordinate
|
||||
*/
|
||||
void setTop(T top)
|
||||
{
|
||||
m_Top = top;
|
||||
}
|
||||
/**
|
||||
* Set top Coordinate
|
||||
*/
|
||||
void setTop(T top)
|
||||
{
|
||||
m_Top = top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right Coordinate
|
||||
*/
|
||||
void setRight(T right)
|
||||
{
|
||||
m_Right = right;
|
||||
}
|
||||
/**
|
||||
* Set right Coordinate
|
||||
*/
|
||||
void setRight(T right)
|
||||
{
|
||||
m_Right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bottom Coordinate
|
||||
*/
|
||||
void setBottom(T bottom)
|
||||
{
|
||||
m_Bottom = bottom;
|
||||
}
|
||||
/**
|
||||
* Set bottom Coordinate
|
||||
*/
|
||||
void setBottom(T bottom)
|
||||
{
|
||||
m_Bottom = bottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left Coordinate
|
||||
*/
|
||||
T getLeft()
|
||||
{
|
||||
return m_Left;
|
||||
}
|
||||
/**
|
||||
* Get left Coordinate
|
||||
*/
|
||||
T getLeft()
|
||||
{
|
||||
return m_Left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top Coordinate
|
||||
*/
|
||||
T getTop()
|
||||
{
|
||||
return m_Top;
|
||||
}
|
||||
/**
|
||||
* Get top Coordinate
|
||||
*/
|
||||
T getTop()
|
||||
{
|
||||
return m_Top;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get right Coordinate
|
||||
*/
|
||||
T getRight()
|
||||
{
|
||||
return m_Right;
|
||||
}
|
||||
/**
|
||||
* Get right Coordinate
|
||||
*/
|
||||
T getRight()
|
||||
{
|
||||
return m_Right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bottom Coordinate
|
||||
*/
|
||||
T getBottom()
|
||||
{
|
||||
return m_Bottom;
|
||||
}
|
||||
/**
|
||||
* Get bottom Coordinate
|
||||
*/
|
||||
T getBottom()
|
||||
{
|
||||
return m_Bottom;
|
||||
}
|
||||
|
||||
package:
|
||||
sfFloatRect toCFloatRect()
|
||||
{
|
||||
return sfFloatRect(m_Left, m_Top, m_Right, m_Bottom);
|
||||
}
|
||||
|
||||
sfIntRect toCIntRect()
|
||||
{
|
||||
return sfIntRect(cast(int)m_Left, cast(int)m_Top, cast(int)m_Right, cast(int)m_Bottom);
|
||||
}
|
||||
sfFloatRect toCFloatRect()
|
||||
{
|
||||
return sfFloatRect(m_Left, m_Top, m_Right, m_Bottom);
|
||||
}
|
||||
|
||||
sfIntRect toCIntRect()
|
||||
{
|
||||
return sfIntRect(cast(int)m_Left, cast(int)m_Top, cast(int)m_Right, cast(int)m_Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
///Alias
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.renderwindow;
|
||||
|
@ -48,190 +48,190 @@ import dsfml.system.common,
|
|||
dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* Simple wrapper for Window that allows easy 2D rendering.
|
||||
* Simple wrapper for Window that allows easy 2D rendering.
|
||||
*/
|
||||
class RenderWindow : Window
|
||||
{
|
||||
private:
|
||||
private:
|
||||
View m_view = null;
|
||||
View m_defaultView = null;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct the window
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(VideoMode mode, string title, 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:
|
||||
* drawable = IDrawable to draw
|
||||
* shader = Shader to use
|
||||
* 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
|
||||
*
|
||||
* Params:
|
||||
* drawable = IDrawable to draw
|
||||
* shader = Shader to use
|
||||
*/
|
||||
void draw(IDrawable drawable, Shader shader)
|
||||
{
|
||||
drawable.renderWithShader(this, shader);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw a sprite, shape or text
|
||||
*
|
||||
* Params:
|
||||
* drawable = IDrawable to draw
|
||||
*/
|
||||
void draw(IDrawable drawable)
|
||||
{
|
||||
drawable.render(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the screen with the given color.
|
||||
*
|
||||
* Params:
|
||||
* col = Fill color
|
||||
*/
|
||||
void clear(Color col = Color.BLACK)
|
||||
{
|
||||
sfRenderWindow_Clear(m_ptr, col);
|
||||
}
|
||||
* Draw a sprite, shape or text
|
||||
*
|
||||
* Params:
|
||||
* drawable = IDrawable to draw
|
||||
*/
|
||||
void draw(IDrawable drawable)
|
||||
{
|
||||
drawable.render(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the screen with the given color.
|
||||
*
|
||||
* Params:
|
||||
* col = Fill color
|
||||
*/
|
||||
void clear(Color col = Color.BLACK)
|
||||
{
|
||||
sfRenderWindow_Clear(m_ptr, col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current active view.
|
||||
* The current view is defined with the initial size of the window
|
||||
*
|
||||
* Params:
|
||||
* newView = Pointer to the new view (pass getDefaultView to set the default view)
|
||||
*/
|
||||
void setView(View newView)
|
||||
{
|
||||
if (m_view !is null)
|
||||
{
|
||||
m_view.setHandled(false);
|
||||
}
|
||||
|
||||
sfRenderWindow_SetView(m_ptr, newView.getNativePointer);
|
||||
|
||||
m_view = newView;
|
||||
m_view.setHandled(true);
|
||||
}
|
||||
/**
|
||||
* Change the current active view.
|
||||
* The current view is defined with the initial size of the window
|
||||
*
|
||||
* Params:
|
||||
* newView = Pointer to the new view (pass getDefaultView to set the default view)
|
||||
*/
|
||||
void setView(View newView)
|
||||
{
|
||||
if (m_view !is null)
|
||||
{
|
||||
m_view.setHandled(false);
|
||||
}
|
||||
|
||||
sfRenderWindow_SetView(m_ptr, newView.getNativePointer);
|
||||
|
||||
m_view = newView;
|
||||
m_view.setHandled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current view rectangle
|
||||
*
|
||||
* Returns:
|
||||
* current view rectangle, in global coordinates
|
||||
*/
|
||||
View getView()
|
||||
{
|
||||
if (m_view is null)
|
||||
{
|
||||
void* cView = sfRenderWindow_GetView(m_ptr);
|
||||
m_view = new View(cView, true);
|
||||
}
|
||||
return m_view;
|
||||
}
|
||||
/**
|
||||
* Get the current view rectangle
|
||||
*
|
||||
* Returns:
|
||||
* current view rectangle, in global coordinates
|
||||
*/
|
||||
View getView()
|
||||
{
|
||||
if (m_view is null)
|
||||
{
|
||||
void* cView = sfRenderWindow_GetView(m_ptr);
|
||||
m_view = new View(cView, true);
|
||||
}
|
||||
return m_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default view
|
||||
*
|
||||
* Returns:
|
||||
* default view
|
||||
*/
|
||||
View getDefaultView()
|
||||
{
|
||||
if (m_defaultView is null)
|
||||
{
|
||||
void* cView = sfRenderWindow_GetDefaultView(m_ptr);
|
||||
m_defaultView = new View(cView, true);
|
||||
}
|
||||
return m_defaultView;
|
||||
}
|
||||
/**
|
||||
* Get the default view
|
||||
*
|
||||
* Returns:
|
||||
* default view
|
||||
*/
|
||||
View getDefaultView()
|
||||
{
|
||||
if (m_defaultView is null)
|
||||
{
|
||||
void* cView = sfRenderWindow_GetDefaultView(m_ptr);
|
||||
m_defaultView = new View(cView, true);
|
||||
}
|
||||
return m_defaultView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point in window coordinates into view coordinates
|
||||
*
|
||||
* Params:
|
||||
* windowX = X coordinate of the point to convert, relative to the window
|
||||
* windowY = Y coordinate of the point to convert, relative to the window
|
||||
* targetView = Target view to convert the point to (pass NULL to use the current view)
|
||||
*
|
||||
* Returns:
|
||||
* Converted point
|
||||
*/
|
||||
Vector2f convertCoords(uint windowX, uint windowY, View targetView = null)
|
||||
{
|
||||
Vector2f vec;
|
||||
sfRenderWindow_ConvertCoords(m_ptr, windowX, windowY, &vec.x, &vec.y, targetView is null ? null : targetView.getNativePointer);
|
||||
return vec;
|
||||
}
|
||||
/**
|
||||
* Convert a point in window coordinates into view coordinates
|
||||
*
|
||||
* Params:
|
||||
* windowX = X coordinate of the point to convert, relative to the window
|
||||
* windowY = Y coordinate of the point to convert, relative to the window
|
||||
* targetView = Target view to convert the point to (pass NULL to use the current view)
|
||||
*
|
||||
* Returns:
|
||||
* Converted point
|
||||
*/
|
||||
Vector2f convertCoords(uint windowX, uint windowY, View targetView = null)
|
||||
{
|
||||
Vector2f vec;
|
||||
sfRenderWindow_ConvertCoords(m_ptr, windowX, windowY, &vec.x, &vec.y, targetView is null ? null : targetView.getNativePointer);
|
||||
return vec;
|
||||
}
|
||||
}
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.shader;
|
||||
|
@ -35,100 +35,100 @@ import dsfml.system.stringutil;
|
|||
|
||||
|
||||
/**
|
||||
* Define loading methods for effect
|
||||
* Define loading methods for effect
|
||||
*/
|
||||
enum LoadingType
|
||||
{
|
||||
FROMFILE, /// string represents a file path
|
||||
FROMSTRING /// string represents effect code
|
||||
FROMFILE, /// string represents a file path
|
||||
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:
|
||||
* $(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.
|
||||
* See_Also:
|
||||
* $(LINK2 http://www.sfml-dev.org/tutorials/graphics-postfx.php, SFML post FX tutorial) from more informations about Post effects and GLSL fragment shaders syntax.
|
||||
*/
|
||||
class Shader : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* construct the effect
|
||||
*
|
||||
* Params:
|
||||
* effect = Path of a file or string containing the effect.
|
||||
* type = type of the effect (default is FROMFILE)
|
||||
*/
|
||||
this(string effect, LoadingType type = LoadingType.FROMFILE)
|
||||
/**
|
||||
* construct the effect
|
||||
*
|
||||
* Params:
|
||||
* effect = Path of a file or string containing the effect.
|
||||
* type = type of the effect (default is FROMFILE)
|
||||
*/
|
||||
this(string effect, LoadingType type = LoadingType.FROMFILE)
|
||||
{
|
||||
if (effect is null || effect.length == 0)
|
||||
throw new LoadingException("LoadingException : Effect is invalid.");
|
||||
|
||||
if (type == LoadingType.FROMFILE)
|
||||
super(sfShader_CreateFromFile(toStringz(effect)));
|
||||
else
|
||||
super(sfShader_CreateFromMemory(toStringz(effect)));
|
||||
if (effect is null || effect.length == 0)
|
||||
throw new LoadingException("LoadingException : Effect is invalid.");
|
||||
|
||||
if (type == LoadingType.FROMFILE)
|
||||
super(sfShader_CreateFromFile(toStringz(effect)));
|
||||
else
|
||||
super(sfShader_CreateFromMemory(toStringz(effect)));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
override void dispose()
|
||||
{
|
||||
sfShader_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change parameters of the effect
|
||||
*
|
||||
* Params:
|
||||
* name = Parameter name in the effect
|
||||
*/
|
||||
void setParameter(string name, float x)
|
||||
/**
|
||||
* Change parameters of the effect
|
||||
*
|
||||
* Params:
|
||||
* name = Parameter name in the effect
|
||||
*/
|
||||
void setParameter(string name, float x)
|
||||
{
|
||||
sfShader_SetParameter1(m_ptr, toStringz(name), x);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y)
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y)
|
||||
{
|
||||
sfShader_SetParameter2(m_ptr, toStringz(name), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y, float z)
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y, float z)
|
||||
{
|
||||
sfShader_SetParameter3(m_ptr, toStringz(name), x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y, float z, float w)
|
||||
/**
|
||||
* ditto
|
||||
*/
|
||||
void setParameter(string name, float x, float y, float z, float w)
|
||||
{
|
||||
sfShader_SetParameter4(m_ptr, toStringz(name), x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a texture parameter
|
||||
*
|
||||
* Params:
|
||||
* name = Texture name in the effect
|
||||
* texture = Image to set (pass NULL to use content of current framebuffer)
|
||||
*/
|
||||
void setTexture(string name, Image texture)
|
||||
/**
|
||||
* Set a texture parameter
|
||||
*
|
||||
* Params:
|
||||
* name = Texture name in the effect
|
||||
* texture = Image to set (pass NULL to use content of current framebuffer)
|
||||
*/
|
||||
void setTexture(string name, Image texture)
|
||||
{
|
||||
m_texture = texture;
|
||||
m_texture = texture;
|
||||
sfShader_SetTexture(m_ptr, toStringz(name), texture is null ? null : texture.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether or not the system supports shaders
|
||||
*
|
||||
* Returns:
|
||||
* True if the system can use shaders
|
||||
*/
|
||||
static bool isAvailable()
|
||||
/**
|
||||
* Tell whether or not the system supports shaders
|
||||
*
|
||||
* Returns:
|
||||
* True if the system can use shaders
|
||||
*/
|
||||
static bool isAvailable()
|
||||
{
|
||||
return cast(bool)sfShader_IsAvailable();
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.shape;
|
||||
|
@ -33,305 +33,305 @@ import dsfml.graphics.color;
|
|||
import dsfml.graphics.drawableimpl;
|
||||
|
||||
/**
|
||||
* Shape defines a drawable convex shape ; it also defines
|
||||
* helper functions to draw simple shapes like
|
||||
* lines, rectangles, circles, etc.
|
||||
* Shape defines a drawable convex shape ; it also defines
|
||||
* helper functions to draw simple shapes like
|
||||
* lines, rectangles, circles, etc.
|
||||
*/
|
||||
class Shape : Drawableimpl!(sfShape)
|
||||
{
|
||||
this()
|
||||
{
|
||||
super();
|
||||
}
|
||||
this()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the point
|
||||
* y = Y position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
void addPoint(float x, float y, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, x, y, col, outlineCol);
|
||||
}
|
||||
/**
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the point
|
||||
* y = Y position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
void addPoint(float x, float y, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, x, y, col, outlineCol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* position = position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
|
||||
}
|
||||
/**
|
||||
* Add a point to the shape
|
||||
*
|
||||
* Params:
|
||||
* position = position of the point
|
||||
* col = Color of the point (white by default)
|
||||
* outlineCol = Outline color of the point (black by default)
|
||||
*/
|
||||
void addPoint(Vector2f position, Color col = Color.WHITE, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
sfShape_AddPoint(m_ptr, position.x, position.x, col, outlineCol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable filling the shape.
|
||||
* Fill is enabled by default.
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
void enableFill(bool enable)
|
||||
{
|
||||
sfShape_EnableFill(m_ptr, enable);
|
||||
}
|
||||
/**
|
||||
* Enable or disable filling the shape.
|
||||
* Fill is enabled by default.
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
void enableFill(bool enable)
|
||||
{
|
||||
sfShape_EnableFill(m_ptr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable drawing a shape outline.
|
||||
* Outline is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
void enableOutline(bool enable)
|
||||
{
|
||||
sfShape_EnableOutline(m_ptr, enable);
|
||||
}
|
||||
/**
|
||||
* Enable or disable drawing a shape outline.
|
||||
* Outline is enabled by default
|
||||
*
|
||||
* Params:
|
||||
* enable = True to enable, false to disable
|
||||
*/
|
||||
void enableOutline(bool enable)
|
||||
{
|
||||
sfShape_EnableOutline(m_ptr, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the width of a shape outline
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
*/
|
||||
void setOutlineWidth(float width)
|
||||
{
|
||||
sfShape_SetOutlineWidth(m_ptr, width);
|
||||
}
|
||||
/**
|
||||
* Change the width of a shape outline
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
*/
|
||||
void setOutlineWidth(float width)
|
||||
{
|
||||
sfShape_SetOutlineWidth(m_ptr, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the shape outline
|
||||
*
|
||||
* Returns:
|
||||
* Current outline width
|
||||
*
|
||||
*/
|
||||
float getOutlineWidth()
|
||||
{
|
||||
return sfShape_GetOutlineWidth(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the width of the shape outline
|
||||
*
|
||||
* Returns:
|
||||
* Current outline width
|
||||
*
|
||||
*/
|
||||
float getOutlineWidth()
|
||||
{
|
||||
return sfShape_GetOutlineWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of points composing a shape
|
||||
*
|
||||
* Returns:
|
||||
* Total number of points
|
||||
*/
|
||||
uint getNbPoints()
|
||||
{
|
||||
return sfShape_GetNbPoints(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the number of points composing a shape
|
||||
*
|
||||
* Returns:
|
||||
* Total number of points
|
||||
*/
|
||||
uint getNbPoints()
|
||||
{
|
||||
return sfShape_GetNbPoints(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point of the shape
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* position of the point
|
||||
*/
|
||||
Vector2f getPointPosition(uint index)
|
||||
{
|
||||
float x, y;
|
||||
sfShape_GetPointPosition(m_ptr, index, &x, &y);
|
||||
return Vector2f(x, y);
|
||||
}
|
||||
/**
|
||||
* Get a point of the shape
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* position of the point
|
||||
*/
|
||||
Vector2f getPointPosition(uint index)
|
||||
{
|
||||
float x, y;
|
||||
sfShape_GetPointPosition(m_ptr, index, &x, &y);
|
||||
return Vector2f(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of a shape point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* position = New position of the point
|
||||
*/
|
||||
void setPointPosition(uint index, Vector2f position)
|
||||
{
|
||||
sfShape_SetPointPosition(m_ptr, index, position.x, position.y);
|
||||
}
|
||||
/**
|
||||
* Set the position of a shape point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* position = New position of the point
|
||||
*/
|
||||
void setPointPosition(uint index, Vector2f position)
|
||||
{
|
||||
sfShape_SetPointPosition(m_ptr, index, position.x, position.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the point
|
||||
*/
|
||||
Color getPointColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointColor(m_ptr, index);
|
||||
}
|
||||
/**
|
||||
* Get the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the point
|
||||
*/
|
||||
Color getPointColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointColor(m_ptr, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
void setPointColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointColor(m_ptr, index, color);
|
||||
}
|
||||
/**
|
||||
* Set the color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
void setPointColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointColor(m_ptr, index, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the outline
|
||||
*/
|
||||
Color getPointOutlineColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointOutlineColor(m_ptr, index);
|
||||
}
|
||||
/**
|
||||
* Get the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
*
|
||||
* Returns:
|
||||
* Color of the outline
|
||||
*/
|
||||
Color getPointOutlineColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointOutlineColor(m_ptr, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
void setPointOutlineColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointOutlineColor(m_ptr, index, color);
|
||||
}
|
||||
/**
|
||||
* Set the outline color of a shape's point
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the point
|
||||
* color = new color of the point
|
||||
*/
|
||||
void setPointOutlineColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointOutlineColor(m_ptr, index, color);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a shape made of a single line
|
||||
*
|
||||
* Params:
|
||||
* p1X, p1Y = Position of the first point
|
||||
* p2X, p2Y = Position second point
|
||||
* thickness = Line thickness
|
||||
* col = Color used to draw the line
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* New line shape
|
||||
*/
|
||||
static Shape line(float p1X, float p1Y, float p2X, float p2Y, float thickness, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
|
||||
return new Shape(sfShape_CreateLine(p1X, p1Y, p2X, p2Y, thickness, col, outline, outlineCol));
|
||||
}
|
||||
/**
|
||||
* Create a shape made of a single line
|
||||
*
|
||||
* Params:
|
||||
* p1X, p1Y = Position of the first point
|
||||
* p2X, p2Y = Position second point
|
||||
* thickness = Line thickness
|
||||
* col = Color used to draw the line
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* New line shape
|
||||
*/
|
||||
static Shape line(float p1X, float p1Y, float p2X, float p2Y, float thickness, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
|
||||
return new Shape(sfShape_CreateLine(p1X, p1Y, p2X, p2Y, thickness, col, outline, outlineCol));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shape made of a single rectangle
|
||||
*
|
||||
* Params:
|
||||
* p1X = X position of the first point
|
||||
* p1Y = Y position of the first point
|
||||
* p2X = X position second point
|
||||
* p2Y = Y position second point
|
||||
* col = Color used to fill the rectangle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new rectangle shape
|
||||
*/
|
||||
static Shape rectangle(float 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));
|
||||
}
|
||||
/**
|
||||
* Create a shape made of a single rectangle
|
||||
*
|
||||
* Params:
|
||||
* p1X = X position of the first point
|
||||
* p1Y = Y position of the first point
|
||||
* p2X = X position second point
|
||||
* p2Y = Y position second point
|
||||
* col = Color used to fill the rectangle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new rectangle shape
|
||||
*/
|
||||
static Shape rectangle(float 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a shape made of a single circle
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the center
|
||||
* y = Y position of the center
|
||||
* radius = Radius
|
||||
* col = Color used to fill the circle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new circle shape
|
||||
*/
|
||||
static Shape circle(float x, float y, float radius, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
return new Shape(sfShape_CreateCircle(x, y, radius, col, outline, outlineCol));
|
||||
}
|
||||
/**
|
||||
* Create a shape made of a single circle
|
||||
*
|
||||
* Params:
|
||||
* x = X position of the center
|
||||
* y = Y position of the center
|
||||
* radius = Radius
|
||||
* col = Color used to fill the circle
|
||||
* outline = Outline width (0 by default)
|
||||
* outlineCol = Color used to draw the outline (black by default)
|
||||
*
|
||||
* Returns:
|
||||
* new circle shape
|
||||
*/
|
||||
static Shape circle(float x, float y, float radius, Color col, float outline = 0.f, Color outlineCol = Color.BLACK)
|
||||
{
|
||||
return new Shape(sfShape_CreateCircle(x, y, radius, col, outline, outlineCol));
|
||||
}
|
||||
|
||||
private:
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
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, Color, float, Color) pf_sfShape_CreateCircle;
|
||||
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_EnableOutline;
|
||||
typedef void function (void* Shape, float Width) pf_sfShape_SetOutlineWidth;
|
||||
typedef float function (void* Shape) pf_sfShape_GetOutlineWidth;
|
||||
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_SetPointPosition;
|
||||
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointColor;
|
||||
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointColor;
|
||||
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointOutlineColor;
|
||||
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointOutlineColor;
|
||||
|
||||
static pf_sfShape_CreateLine sfShape_CreateLine;
|
||||
static pf_sfShape_CreateRectangle sfShape_CreateRectangle;
|
||||
static pf_sfShape_CreateCircle sfShape_CreateCircle;
|
||||
static pf_sfShape_AddPoint sfShape_AddPoint;
|
||||
static pf_sfShape_EnableFill sfShape_EnableFill;
|
||||
static pf_sfShape_EnableOutline sfShape_EnableOutline;
|
||||
static pf_sfShape_SetOutlineWidth sfShape_SetOutlineWidth;
|
||||
static pf_sfShape_GetOutlineWidth sfShape_GetOutlineWidth;
|
||||
static pf_sfShape_GetNbPoints sfShape_GetNbPoints;
|
||||
static pf_sfShape_GetPointPosition sfShape_GetPointPosition;
|
||||
static pf_sfShape_SetPointPosition sfShape_SetPointPosition;
|
||||
static pf_sfShape_GetPointColor sfShape_GetPointColor;
|
||||
static pf_sfShape_SetPointColor sfShape_SetPointColor;
|
||||
static pf_sfShape_GetPointOutlineColor sfShape_GetPointOutlineColor;
|
||||
static pf_sfShape_SetPointOutlineColor sfShape_SetPointOutlineColor;
|
||||
}
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
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, Color, float, Color) pf_sfShape_CreateCircle;
|
||||
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_EnableOutline;
|
||||
typedef void function (void* Shape, float Width) pf_sfShape_SetOutlineWidth;
|
||||
typedef float function (void* Shape) pf_sfShape_GetOutlineWidth;
|
||||
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_SetPointPosition;
|
||||
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointColor;
|
||||
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointColor;
|
||||
typedef Color function (void* Shape, uint index) pf_sfShape_GetPointOutlineColor;
|
||||
typedef void function (void* Shape, uint index, Color color) pf_sfShape_SetPointOutlineColor;
|
||||
|
||||
static pf_sfShape_CreateLine sfShape_CreateLine;
|
||||
static pf_sfShape_CreateRectangle sfShape_CreateRectangle;
|
||||
static pf_sfShape_CreateCircle sfShape_CreateCircle;
|
||||
static pf_sfShape_AddPoint sfShape_AddPoint;
|
||||
static pf_sfShape_EnableFill sfShape_EnableFill;
|
||||
static pf_sfShape_EnableOutline sfShape_EnableOutline;
|
||||
static pf_sfShape_SetOutlineWidth sfShape_SetOutlineWidth;
|
||||
static pf_sfShape_GetOutlineWidth sfShape_GetOutlineWidth;
|
||||
static pf_sfShape_GetNbPoints sfShape_GetNbPoints;
|
||||
static pf_sfShape_GetPointPosition sfShape_GetPointPosition;
|
||||
static pf_sfShape_SetPointPosition sfShape_SetPointPosition;
|
||||
static pf_sfShape_GetPointColor sfShape_GetPointColor;
|
||||
static pf_sfShape_SetPointColor sfShape_SetPointColor;
|
||||
static pf_sfShape_GetPointOutlineColor sfShape_GetPointOutlineColor;
|
||||
static pf_sfShape_SetPointOutlineColor sfShape_SetPointOutlineColor;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfShape_CreateLine = cast(pf_sfShape_CreateLine)dll.getSymbol("sfShape_CreateLine");
|
||||
sfShape_CreateRectangle = cast(pf_sfShape_CreateRectangle)dll.getSymbol("sfShape_CreateRectangle");
|
||||
sfShape_CreateCircle = cast(pf_sfShape_CreateCircle)dll.getSymbol("sfShape_CreateCircle");
|
||||
sfShape_AddPoint = cast(pf_sfShape_AddPoint)dll.getSymbol("sfShape_AddPoint");
|
||||
sfShape_EnableFill = cast(pf_sfShape_EnableFill)dll.getSymbol("sfShape_EnableFill");
|
||||
sfShape_EnableOutline = cast(pf_sfShape_EnableOutline)dll.getSymbol("sfShape_EnableOutline");
|
||||
sfShape_SetOutlineWidth = cast(pf_sfShape_SetOutlineWidth)dll.getSymbol("sfShape_SetOutlineWidth");
|
||||
sfShape_GetOutlineWidth = cast(pf_sfShape_GetOutlineWidth)dll.getSymbol("sfShape_GetOutlineWidth");
|
||||
sfShape_GetNbPoints = cast(pf_sfShape_GetNbPoints)dll.getSymbol("sfShape_GetNbPoints");
|
||||
sfShape_GetPointPosition = cast(pf_sfShape_GetPointPosition)dll.getSymbol("sfShape_GetPointPosition");
|
||||
sfShape_SetPointPosition = cast(pf_sfShape_SetPointPosition)dll.getSymbol("sfShape_SetPointPosition");
|
||||
sfShape_GetPointColor = cast (pf_sfShape_GetPointColor)dll.getSymbol("sfShape_GetPointColor");
|
||||
sfShape_SetPointColor = cast (pf_sfShape_SetPointColor)dll.getSymbol("sfShape_SetPointColor");
|
||||
sfShape_GetPointOutlineColor = cast(pf_sfShape_GetPointOutlineColor)dll.getSymbol("sfShape_GetPointOutlineColor");
|
||||
sfShape_SetPointOutlineColor = cast(pf_sfShape_SetPointOutlineColor)dll.getSymbol("sfShape_SetPointOutlineColor");
|
||||
}
|
||||
|
||||
sfShape_CreateLine = cast(pf_sfShape_CreateLine)dll.getSymbol("sfShape_CreateLine");
|
||||
sfShape_CreateRectangle = cast(pf_sfShape_CreateRectangle)dll.getSymbol("sfShape_CreateRectangle");
|
||||
sfShape_CreateCircle = cast(pf_sfShape_CreateCircle)dll.getSymbol("sfShape_CreateCircle");
|
||||
sfShape_AddPoint = cast(pf_sfShape_AddPoint)dll.getSymbol("sfShape_AddPoint");
|
||||
sfShape_EnableFill = cast(pf_sfShape_EnableFill)dll.getSymbol("sfShape_EnableFill");
|
||||
sfShape_EnableOutline = cast(pf_sfShape_EnableOutline)dll.getSymbol("sfShape_EnableOutline");
|
||||
sfShape_SetOutlineWidth = cast(pf_sfShape_SetOutlineWidth)dll.getSymbol("sfShape_SetOutlineWidth");
|
||||
sfShape_GetOutlineWidth = cast(pf_sfShape_GetOutlineWidth)dll.getSymbol("sfShape_GetOutlineWidth");
|
||||
sfShape_GetNbPoints = cast(pf_sfShape_GetNbPoints)dll.getSymbol("sfShape_GetNbPoints");
|
||||
sfShape_GetPointPosition = cast(pf_sfShape_GetPointPosition)dll.getSymbol("sfShape_GetPointPosition");
|
||||
sfShape_SetPointPosition = cast(pf_sfShape_SetPointPosition)dll.getSymbol("sfShape_SetPointPosition");
|
||||
sfShape_GetPointColor = cast (pf_sfShape_GetPointColor)dll.getSymbol("sfShape_GetPointColor");
|
||||
sfShape_SetPointColor = cast (pf_sfShape_SetPointColor)dll.getSymbol("sfShape_SetPointColor");
|
||||
sfShape_GetPointOutlineColor = cast(pf_sfShape_GetPointOutlineColor)dll.getSymbol("sfShape_GetPointOutlineColor");
|
||||
sfShape_SetPointOutlineColor = cast(pf_sfShape_SetPointOutlineColor)dll.getSymbol("sfShape_SetPointOutlineColor");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.sprite;
|
||||
|
@ -35,218 +35,218 @@ import dsfml.graphics.rect;
|
|||
import dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* Sprite defines a sprite : texture, transformations,
|
||||
* color, and draw on screen
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
* Sprite defines a sprite : texture, transformations,
|
||||
* color, and draw on screen
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
*/
|
||||
class Sprite : Drawableimpl!(sfSprite)
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the sprite from a source image
|
||||
*
|
||||
* Params:
|
||||
* img = Image of the sprite
|
||||
* left = Left coordinate of the sprite (0 by default)
|
||||
* top = Top coordinate of the sprite (0 by default)
|
||||
* scaleX = Horizontal scale (1 by default)
|
||||
* scaleY= Vertical scale (1 by default)
|
||||
* rotation = Orientation, in degrees (0 by default)
|
||||
* col = Color of the sprite (white by default)
|
||||
*/
|
||||
this(Image img, float left = 0.f, float top = 0.f, float scaleX = 1.f, float scaleY = 1.f, float rotation = 0.f, Color col = Color.WHITE)
|
||||
{
|
||||
m_image = img;
|
||||
sfSprite_SetImage(m_ptr, img.getNativePointer);
|
||||
setX(left);
|
||||
setY(top);
|
||||
setScaleX(scaleX);
|
||||
setScaleY(scaleY);
|
||||
setRotation(rotation);
|
||||
setColor(col);
|
||||
}
|
||||
/**
|
||||
* Construct the sprite from a source image
|
||||
*
|
||||
* Params:
|
||||
* img = Image of the sprite
|
||||
* left = Left coordinate of the sprite (0 by default)
|
||||
* top = Top coordinate of the sprite (0 by default)
|
||||
* scaleX = Horizontal scale (1 by default)
|
||||
* scaleY= Vertical scale (1 by default)
|
||||
* rotation = Orientation, in degrees (0 by default)
|
||||
* col = Color of the sprite (white by default)
|
||||
*/
|
||||
this(Image img, float left = 0.f, float top = 0.f, float scaleX = 1.f, float scaleY = 1.f, float rotation = 0.f, Color col = Color.WHITE)
|
||||
{
|
||||
m_image = img;
|
||||
sfSprite_SetImage(m_ptr, img.getNativePointer);
|
||||
setX(left);
|
||||
setY(top);
|
||||
setScaleX(scaleX);
|
||||
setScaleY(scaleY);
|
||||
setRotation(rotation);
|
||||
setColor(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image of the sprite
|
||||
*
|
||||
* Params:
|
||||
* img = New image
|
||||
*/
|
||||
void setImage(Image img)
|
||||
{
|
||||
assert(img !is null, "Trying to set a null image.");
|
||||
sfSprite_SetImage(m_ptr, img.getNativePointer);
|
||||
m_image = img;
|
||||
}
|
||||
/**
|
||||
* Change the image of the sprite
|
||||
*
|
||||
* Params:
|
||||
* img = New image
|
||||
*/
|
||||
void setImage(Image img)
|
||||
{
|
||||
assert(img !is null, "Trying to set a null image.");
|
||||
sfSprite_SetImage(m_ptr, img.getNativePointer);
|
||||
m_image = img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sub-rectangle of a sprite inside the source image.
|
||||
*
|
||||
* Params:
|
||||
* rect = New sub-rectangle
|
||||
*/
|
||||
void setSubRect(IntRect rect)
|
||||
{
|
||||
sfIntRect r = rect.toCIntRect();
|
||||
sfSprite_SetSubRect(m_ptr, &r);
|
||||
m_subRect = rect;
|
||||
}
|
||||
/**
|
||||
* Set the sub-rectangle of a sprite inside the source image.
|
||||
*
|
||||
* Params:
|
||||
* rect = New sub-rectangle
|
||||
*/
|
||||
void setSubRect(IntRect rect)
|
||||
{
|
||||
sfIntRect r = rect.toCIntRect();
|
||||
sfSprite_SetSubRect(m_ptr, &r);
|
||||
m_subRect = rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the sprite (by changing its scale factors).
|
||||
* The default size is defined by the subrect
|
||||
*
|
||||
* Params:
|
||||
* width = New width (must be strictly positive)
|
||||
* height = New height (must be strictly positive)
|
||||
*/
|
||||
void resize(float width, float height)
|
||||
{
|
||||
if (width > 0 && height > 0)
|
||||
sfSprite_Resize(m_ptr, width, height);
|
||||
}
|
||||
/**
|
||||
* Resize the sprite (by changing its scale factors).
|
||||
* The default size is defined by the subrect
|
||||
*
|
||||
* Params:
|
||||
* width = New width (must be strictly positive)
|
||||
* height = New height (must be strictly positive)
|
||||
*/
|
||||
void resize(float width, float height)
|
||||
{
|
||||
if (width > 0 && height > 0)
|
||||
sfSprite_Resize(m_ptr, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the sprite (by changing its scale factors).
|
||||
* The default size is defined by the subrect
|
||||
*
|
||||
* Params:
|
||||
* size = New size (both coordinates must be strictly positive)
|
||||
*/
|
||||
void resize(Vector2f size)
|
||||
{
|
||||
if (size.x > 0 && size.y > 0)
|
||||
sfSprite_Resize(m_ptr, size.x, size.y);
|
||||
}
|
||||
/**
|
||||
* Resize the sprite (by changing its scale factors).
|
||||
* The default size is defined by the subrect
|
||||
*
|
||||
* Params:
|
||||
* size = New size (both coordinates must be strictly positive)
|
||||
*/
|
||||
void resize(Vector2f size)
|
||||
{
|
||||
if (size.x > 0 && size.y > 0)
|
||||
sfSprite_Resize(m_ptr, size.x, size.y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flip the sprite horizontally
|
||||
*
|
||||
* Params:
|
||||
* flipped = True to flip the sprite
|
||||
*/
|
||||
void flipX(bool flipped)
|
||||
{
|
||||
sfSprite_FlipX(m_ptr, flipped);
|
||||
}
|
||||
/**
|
||||
* Flip the sprite horizontally
|
||||
*
|
||||
* Params:
|
||||
* flipped = True to flip the sprite
|
||||
*/
|
||||
void flipX(bool flipped)
|
||||
{
|
||||
sfSprite_FlipX(m_ptr, flipped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip the sprite vertically
|
||||
*
|
||||
* Params:
|
||||
* flipped = True to flip the sprite
|
||||
*/
|
||||
void flipY(bool flipped)
|
||||
{
|
||||
sfSprite_FlipY(m_ptr, flipped);
|
||||
}
|
||||
/**
|
||||
* Flip the sprite vertically
|
||||
*
|
||||
* Params:
|
||||
* flipped = True to flip the sprite
|
||||
*/
|
||||
void flipY(bool flipped)
|
||||
{
|
||||
sfSprite_FlipY(m_ptr, flipped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source image of the sprite
|
||||
*
|
||||
* Returns:
|
||||
* Pointer to the image (can be NULL)
|
||||
*/
|
||||
Image getImage()
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
/**
|
||||
* Get the source image of the sprite
|
||||
*
|
||||
* Returns:
|
||||
* Pointer to the image (can be NULL)
|
||||
*/
|
||||
Image getImage()
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sub-rectangle of the sprite inside the source image
|
||||
*
|
||||
* Returns:
|
||||
* Sub-rectangle
|
||||
*/
|
||||
IntRect getSubRect()
|
||||
{
|
||||
if (m_subRect is null)
|
||||
m_subRect = new IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
|
||||
|
||||
return m_subRect;
|
||||
}
|
||||
/**
|
||||
* Get the sub-rectangle of the sprite inside the source image
|
||||
*
|
||||
* Returns:
|
||||
* Sub-rectangle
|
||||
*/
|
||||
IntRect getSubRect()
|
||||
{
|
||||
if (m_subRect is null)
|
||||
m_subRect = new IntRect(0, 0, m_image.getWidth(), m_image.getHeight());
|
||||
|
||||
return m_subRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sprite size
|
||||
*
|
||||
* Returns:
|
||||
* Size of the sprite
|
||||
*/
|
||||
Vector2f getSize()
|
||||
{
|
||||
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
|
||||
}
|
||||
/**
|
||||
* Get the sprite size
|
||||
*
|
||||
* Returns:
|
||||
* Size of the sprite
|
||||
*/
|
||||
Vector2f getSize()
|
||||
{
|
||||
return Vector2f(sfSprite_GetWidth(m_ptr), sfSprite_GetHeight(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of a given pixel in the sprite
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate
|
||||
* y = Y coordinate
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
{
|
||||
return sfSprite_GetPixel(m_ptr, x, y);
|
||||
}
|
||||
/**
|
||||
* Get the color of a given pixel in the sprite
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinate
|
||||
* y = Y coordinate
|
||||
*
|
||||
* Returns:
|
||||
* Color of pixel
|
||||
*/
|
||||
Color getPixel(uint x, uint y)
|
||||
{
|
||||
return sfSprite_GetPixel(m_ptr, x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
Image m_image; //< Image used to draw the sprite
|
||||
IntRect m_subRect; //< Sub-rectangle of source image to assign to the sprite
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*, void*) pf_sfSprite_SetImage;
|
||||
typedef void function(void*, sfIntRect*) pf_sfSprite_SetSubRect;
|
||||
typedef void function(void*, float, float) pf_sfSprite_Resize;
|
||||
typedef void function(void*, int) pf_sfSprite_FlipX;
|
||||
typedef void function(void*, int) pf_sfSprite_FlipY;
|
||||
typedef void* function(void*) pf_sfSprite_GetImage;
|
||||
typedef void* function(void*) pf_sfSprite_GetSubRect;
|
||||
typedef float function(void*) pf_sfSprite_GetWidth;
|
||||
typedef float function(void*) pf_sfSprite_GetHeight;
|
||||
typedef Color function(void*, uint, uint) pf_sfSprite_GetPixel;
|
||||
|
||||
static pf_sfSprite_SetImage sfSprite_SetImage;
|
||||
static pf_sfSprite_SetSubRect sfSprite_SetSubRect;
|
||||
static pf_sfSprite_Resize sfSprite_Resize;
|
||||
static pf_sfSprite_FlipX sfSprite_FlipX;
|
||||
static pf_sfSprite_FlipY sfSprite_FlipY;
|
||||
static pf_sfSprite_GetImage sfSprite_GetImage;
|
||||
static pf_sfSprite_GetSubRect sfSprite_GetSubRect;
|
||||
static pf_sfSprite_GetWidth sfSprite_GetWidth;
|
||||
static pf_sfSprite_GetHeight sfSprite_GetHeight;
|
||||
static pf_sfSprite_GetPixel sfSprite_GetPixel;
|
||||
}
|
||||
Image m_image; //< Image used to draw the sprite
|
||||
IntRect m_subRect; //< Sub-rectangle of source image to assign to the sprite
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*, void*) pf_sfSprite_SetImage;
|
||||
typedef void function(void*, sfIntRect*) pf_sfSprite_SetSubRect;
|
||||
typedef void function(void*, float, float) pf_sfSprite_Resize;
|
||||
typedef void function(void*, int) pf_sfSprite_FlipX;
|
||||
typedef void function(void*, int) pf_sfSprite_FlipY;
|
||||
typedef void* function(void*) pf_sfSprite_GetImage;
|
||||
typedef void* function(void*) pf_sfSprite_GetSubRect;
|
||||
typedef float function(void*) pf_sfSprite_GetWidth;
|
||||
typedef float function(void*) pf_sfSprite_GetHeight;
|
||||
typedef Color function(void*, uint, uint) pf_sfSprite_GetPixel;
|
||||
|
||||
static pf_sfSprite_SetImage sfSprite_SetImage;
|
||||
static pf_sfSprite_SetSubRect sfSprite_SetSubRect;
|
||||
static pf_sfSprite_Resize sfSprite_Resize;
|
||||
static pf_sfSprite_FlipX sfSprite_FlipX;
|
||||
static pf_sfSprite_FlipY sfSprite_FlipY;
|
||||
static pf_sfSprite_GetImage sfSprite_GetImage;
|
||||
static pf_sfSprite_GetSubRect sfSprite_GetSubRect;
|
||||
static pf_sfSprite_GetWidth sfSprite_GetWidth;
|
||||
static pf_sfSprite_GetHeight sfSprite_GetHeight;
|
||||
static pf_sfSprite_GetPixel sfSprite_GetPixel;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfSprite_SetImage = cast(pf_sfSprite_SetImage)dll.getSymbol("sfSprite_SetImage");
|
||||
sfSprite_SetSubRect = cast(pf_sfSprite_SetSubRect)dll.getSymbol("sfSprite_SetSubRect");
|
||||
sfSprite_Resize = cast(pf_sfSprite_Resize)dll.getSymbol("sfSprite_Resize");
|
||||
sfSprite_FlipX = cast(pf_sfSprite_FlipX)dll.getSymbol("sfSprite_FlipX");
|
||||
sfSprite_FlipY = cast(pf_sfSprite_FlipY)dll.getSymbol("sfSprite_FlipY");
|
||||
sfSprite_GetImage = cast(pf_sfSprite_GetImage)dll.getSymbol("sfSprite_GetImage");
|
||||
sfSprite_GetSubRect = cast(pf_sfSprite_GetSubRect)dll.getSymbol("sfSprite_GetSubRect");
|
||||
sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth");
|
||||
sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight");
|
||||
sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("sfSprite_GetPixel");
|
||||
}
|
||||
|
||||
|
||||
sfSprite_SetImage = cast(pf_sfSprite_SetImage)dll.getSymbol("sfSprite_SetImage");
|
||||
sfSprite_SetSubRect = cast(pf_sfSprite_SetSubRect)dll.getSymbol("sfSprite_SetSubRect");
|
||||
sfSprite_Resize = cast(pf_sfSprite_Resize)dll.getSymbol("sfSprite_Resize");
|
||||
sfSprite_FlipX = cast(pf_sfSprite_FlipX)dll.getSymbol("sfSprite_FlipX");
|
||||
sfSprite_FlipY = cast(pf_sfSprite_FlipY)dll.getSymbol("sfSprite_FlipY");
|
||||
sfSprite_GetImage = cast(pf_sfSprite_GetImage)dll.getSymbol("sfSprite_GetImage");
|
||||
sfSprite_GetSubRect = cast(pf_sfSprite_GetSubRect)dll.getSymbol("sfSprite_GetSubRect");
|
||||
sfSprite_GetWidth = cast(pf_sfSprite_GetWidth)dll.getSymbol("sfSprite_GetWidth");
|
||||
sfSprite_GetHeight = cast(pf_sfSprite_GetHeight)dll.getSymbol("sfSprite_GetHeight");
|
||||
sfSprite_GetPixel = cast(pf_sfSprite_GetPixel)dll.getSymbol("sfSprite_GetPixel");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.text;
|
||||
|
@ -38,35 +38,35 @@ import dsfml.system.vector2;
|
|||
|
||||
|
||||
/**
|
||||
* Text defines a graphical 2D text, that can be drawn on screen
|
||||
*
|
||||
* All string litterals used must be prefixed with c for utf-8
|
||||
* and d for utf-32 string.
|
||||
*
|
||||
* Examples :
|
||||
* ---------------------------------------------------------------
|
||||
* Text s = new Text("Hello"c);
|
||||
* //this(string, Font, float)
|
||||
* s = new Text("Hello"d);
|
||||
* //this(dstring, Font, float)
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
* Text defines a graphical 2D text, that can be drawn on screen
|
||||
*
|
||||
* All string litterals used must be prefixed with c for utf-8
|
||||
* and d for utf-32 string.
|
||||
*
|
||||
* Examples :
|
||||
* ---------------------------------------------------------------
|
||||
* Text s = new Text("Hello"c);
|
||||
* //this(string, Font, float)
|
||||
* s = new Text("Hello"d);
|
||||
* //this(dstring, Font, float)
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* See_Also:
|
||||
* IDrawable
|
||||
*/
|
||||
class Text : Drawableimpl!(sfText)
|
||||
{
|
||||
/**
|
||||
* Construct the string from a text
|
||||
*
|
||||
* Prefixs string litterals with c
|
||||
*
|
||||
* Params:
|
||||
* text = Text assigned to the string
|
||||
* font = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(string text, Font font = Font.getDefaultFont(), uint size = 30)
|
||||
/**
|
||||
* Construct the string from a text
|
||||
*
|
||||
* Prefixs string litterals with c
|
||||
*
|
||||
* Params:
|
||||
* text = Text assigned to the string
|
||||
* font = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(string text, Font font = Font.getDefaultFont(), uint size = 30)
|
||||
{
|
||||
super();
|
||||
m_font = font;
|
||||
|
@ -75,17 +75,17 @@ class Text : Drawableimpl!(sfText)
|
|||
setCharacterSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the string from a unicode text
|
||||
*
|
||||
* Prefixs string litterals with d
|
||||
*
|
||||
* Params:
|
||||
* text = Text assigned to the string
|
||||
* font = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(dstring text, Font font = Font.getDefaultFont(), uint size = 30)
|
||||
/**
|
||||
* Construct the string from a unicode text
|
||||
*
|
||||
* Prefixs string litterals with d
|
||||
*
|
||||
* Params:
|
||||
* text = Text assigned to the string
|
||||
* font = Font used to draw the string (use default font)
|
||||
* size = Characters size, in pixels (32 by default)
|
||||
*/
|
||||
this(dstring text, Font font = Font.getDefaultFont(), uint size = 30)
|
||||
{
|
||||
super();
|
||||
m_font = font;
|
||||
|
@ -94,145 +94,145 @@ class Text : Drawableimpl!(sfText)
|
|||
setCharacterSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text (from a multibyte string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*
|
||||
*/
|
||||
void setString(string text)
|
||||
/**
|
||||
* Set the text (from a multibyte string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*
|
||||
*/
|
||||
void setString(string text)
|
||||
{
|
||||
sfText_SetString(m_ptr,toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text (from a unicode string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void setString(dstring text)
|
||||
/**
|
||||
* Set the text (from a unicode string)
|
||||
*
|
||||
* Params:
|
||||
* text = New text
|
||||
*/
|
||||
void setString(dstring text)
|
||||
{
|
||||
sfText_SetUnicodeString(m_ptr, toStringz(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font of the string
|
||||
*
|
||||
* Params:
|
||||
* font = Font filename
|
||||
*/
|
||||
void setFont(Font font)
|
||||
/**
|
||||
* Set the font of the string
|
||||
*
|
||||
* Params:
|
||||
* font = Font filename
|
||||
*/
|
||||
void setFont(Font font)
|
||||
{
|
||||
m_font = font;
|
||||
m_font = font;
|
||||
sfText_SetFont(m_ptr, font.getNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the string
|
||||
*
|
||||
* Params:
|
||||
* size = New size, in pixels
|
||||
*/
|
||||
void setCharacterSize(uint size)
|
||||
/**
|
||||
* Set the size of the string
|
||||
*
|
||||
* Params:
|
||||
* size = New size, in pixels
|
||||
*/
|
||||
void setCharacterSize(uint size)
|
||||
{
|
||||
sfText_SetCharacterSize(m_ptr, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style of the text
|
||||
* The default style is Regular
|
||||
*
|
||||
* Params:
|
||||
* TextStyle = New text style, (combination of Style enum values)
|
||||
*
|
||||
*/
|
||||
void setStyle(TextStyle style)
|
||||
{
|
||||
sfText_SetStyle(m_ptr, style);
|
||||
}
|
||||
/**
|
||||
* Set the style of the text
|
||||
* The default style is Regular
|
||||
*
|
||||
* Params:
|
||||
* TextStyle = New text style, (combination of Style enum values)
|
||||
*
|
||||
*/
|
||||
void setStyle(TextStyle style)
|
||||
{
|
||||
sfText_SetStyle(m_ptr, style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a unicode string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
dstring getUnicodeText()
|
||||
/**
|
||||
* Get the text (returns a unicode string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
dstring getUnicodeText()
|
||||
{
|
||||
return fromStringz(sfText_GetUnicodeString(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text (returns a multibyte string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
string getText()
|
||||
/**
|
||||
* Get the text (returns a multibyte string)
|
||||
*
|
||||
* Returns:
|
||||
* Text
|
||||
*/
|
||||
string getText()
|
||||
{
|
||||
return fromStringz(sfText_GetString(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the font used by the string
|
||||
*
|
||||
* Returns:
|
||||
* Font name
|
||||
*/
|
||||
Font getFont()
|
||||
/**
|
||||
* Get the font used by the string
|
||||
*
|
||||
* Returns:
|
||||
* Font name
|
||||
*/
|
||||
Font getFont()
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the characters
|
||||
*
|
||||
* Returns:
|
||||
* Size of the characters
|
||||
*/
|
||||
uint getCharacterSize()
|
||||
/**
|
||||
* Get the size of the characters
|
||||
*
|
||||
* Returns:
|
||||
* Size of the characters
|
||||
*/
|
||||
uint getCharacterSize()
|
||||
{
|
||||
return sfText_GetCharacterSize(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current font style
|
||||
*
|
||||
* Returns:
|
||||
* Font style
|
||||
*/
|
||||
TextStyle getStyle()
|
||||
{
|
||||
return sfText_GetStyle(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the visual position of the Index-th character of the string,
|
||||
* in coordinates relative to the string
|
||||
* (note : translation, center, rotation and scale are not applied)
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the character
|
||||
*
|
||||
* Returns:
|
||||
* Position of the Index-th character (end of string of Index is out of range)
|
||||
*/
|
||||
Vector2f getCharacterPos(size_t index)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfText_GetCharacterPos(m_ptr, index, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string rectangle on screen
|
||||
*
|
||||
* Returns:
|
||||
* Rectangle contaning the string in screen coordinates
|
||||
*/
|
||||
FloatRect getRect()
|
||||
/**
|
||||
* Get the current font style
|
||||
*
|
||||
* Returns:
|
||||
* Font style
|
||||
*/
|
||||
TextStyle getStyle()
|
||||
{
|
||||
return sfText_GetStyle(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the visual position of the Index-th character of the string,
|
||||
* in coordinates relative to the string
|
||||
* (note : translation, center, rotation and scale are not applied)
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the character
|
||||
*
|
||||
* Returns:
|
||||
* Position of the Index-th character (end of string of Index is out of range)
|
||||
*/
|
||||
Vector2f getCharacterPos(size_t index)
|
||||
{
|
||||
Vector2f ret;
|
||||
sfText_GetCharacterPos(m_ptr, index, &ret.x, &ret.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string rectangle on screen
|
||||
*
|
||||
* Returns:
|
||||
* Rectangle contaning the string in screen coordinates
|
||||
*/
|
||||
FloatRect getRect()
|
||||
{
|
||||
sfFloatRect sfRect = sfText_GetRect(m_ptr);
|
||||
|
||||
|
@ -240,55 +240,55 @@ class Text : Drawableimpl!(sfText)
|
|||
}
|
||||
|
||||
private:
|
||||
Font m_font;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*, cchar*) pf_sfText_SetString;
|
||||
typedef void function(void*, cdchar*) pf_sfText_SetUnicodeString;
|
||||
typedef void function(void*, void*) pf_sfText_SetFont;
|
||||
typedef void function(void*, uint) pf_sfText_SetCharacterSize;
|
||||
typedef void function(void*, TextStyle) pf_sfText_SetStyle;
|
||||
typedef idchar* function(void*) pf_sfText_GetUnicodeString;
|
||||
typedef ichar* function(void*) pf_sfText_GetString;
|
||||
typedef void* function(void*) pf_sfText_GetFont;
|
||||
typedef uint function(void*) pf_sfText_GetCharacterSize;
|
||||
typedef TextStyle function (void*) pf_sfText_GetStyle;
|
||||
typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos;
|
||||
typedef sfFloatRect function(void*) pf_sfText_GetRect;
|
||||
|
||||
static pf_sfText_SetString sfText_SetString;
|
||||
static pf_sfText_SetUnicodeString sfText_SetUnicodeString;
|
||||
static pf_sfText_SetFont sfText_SetFont;
|
||||
static pf_sfText_SetCharacterSize sfText_SetCharacterSize;
|
||||
static pf_sfText_SetStyle sfText_SetStyle;
|
||||
static pf_sfText_GetUnicodeString sfText_GetUnicodeString;
|
||||
static pf_sfText_GetString sfText_GetString;
|
||||
static pf_sfText_GetFont sfText_GetFont;
|
||||
static pf_sfText_GetCharacterSize sfText_GetCharacterSize;
|
||||
static pf_sfText_GetStyle sfText_GetStyle;
|
||||
static pf_sfText_GetCharacterPos sfText_GetCharacterPos;
|
||||
static pf_sfText_GetRect sfText_GetRect;
|
||||
}
|
||||
Font m_font;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*, cchar*) pf_sfText_SetString;
|
||||
typedef void function(void*, cdchar*) pf_sfText_SetUnicodeString;
|
||||
typedef void function(void*, void*) pf_sfText_SetFont;
|
||||
typedef void function(void*, uint) pf_sfText_SetCharacterSize;
|
||||
typedef void function(void*, TextStyle) pf_sfText_SetStyle;
|
||||
typedef idchar* function(void*) pf_sfText_GetUnicodeString;
|
||||
typedef ichar* function(void*) pf_sfText_GetString;
|
||||
typedef void* function(void*) pf_sfText_GetFont;
|
||||
typedef uint function(void*) pf_sfText_GetCharacterSize;
|
||||
typedef TextStyle function (void*) pf_sfText_GetStyle;
|
||||
typedef void function(void*, size_t, float*, float*) pf_sfText_GetCharacterPos;
|
||||
typedef sfFloatRect function(void*) pf_sfText_GetRect;
|
||||
|
||||
static pf_sfText_SetString sfText_SetString;
|
||||
static pf_sfText_SetUnicodeString sfText_SetUnicodeString;
|
||||
static pf_sfText_SetFont sfText_SetFont;
|
||||
static pf_sfText_SetCharacterSize sfText_SetCharacterSize;
|
||||
static pf_sfText_SetStyle sfText_SetStyle;
|
||||
static pf_sfText_GetUnicodeString sfText_GetUnicodeString;
|
||||
static pf_sfText_GetString sfText_GetString;
|
||||
static pf_sfText_GetFont sfText_GetFont;
|
||||
static pf_sfText_GetCharacterSize sfText_GetCharacterSize;
|
||||
static pf_sfText_GetStyle sfText_GetStyle;
|
||||
static pf_sfText_GetCharacterPos sfText_GetCharacterPos;
|
||||
static pf_sfText_GetRect sfText_GetRect;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-graphics-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-graphics");
|
||||
|
||||
sfText_SetString = cast(pf_sfText_SetString)dll.getSymbol("sfText_SetString");
|
||||
sfText_SetUnicodeString = cast(pf_sfText_SetUnicodeString)dll.getSymbol("sfText_SetUnicodeString");
|
||||
sfText_SetFont = cast(pf_sfText_SetFont)dll.getSymbol("sfText_SetFont");
|
||||
sfText_SetCharacterSize = cast(pf_sfText_SetCharacterSize)dll.getSymbol("sfText_SetCharacterSize");
|
||||
sfText_SetStyle = cast(pf_sfText_SetStyle)dll.getSymbol("sfText_SetStyle");
|
||||
sfText_GetUnicodeString = cast(pf_sfText_GetUnicodeString)dll.getSymbol("sfText_GetUnicodeString");
|
||||
sfText_GetString = cast(pf_sfText_GetString)dll.getSymbol("sfText_GetString");
|
||||
sfText_GetFont = cast(pf_sfText_GetFont)dll.getSymbol("sfText_GetFont");
|
||||
sfText_GetCharacterSize = cast(pf_sfText_GetCharacterSize)dll.getSymbol("sfText_GetCharacterSize");
|
||||
sfText_GetStyle = cast(pf_sfText_GetStyle)dll.getSymbol("sfText_GetStyle");
|
||||
sfText_GetCharacterPos = cast(pf_sfText_GetCharacterPos)dll.getSymbol("sfText_GetCharacterPos");
|
||||
sfText_GetRect = cast(pf_sfText_GetRect)dll.getSymbol("sfText_GetRect");
|
||||
}
|
||||
|
||||
sfText_SetString = cast(pf_sfText_SetString)dll.getSymbol("sfText_SetString");
|
||||
sfText_SetUnicodeString = cast(pf_sfText_SetUnicodeString)dll.getSymbol("sfText_SetUnicodeString");
|
||||
sfText_SetFont = cast(pf_sfText_SetFont)dll.getSymbol("sfText_SetFont");
|
||||
sfText_SetCharacterSize = cast(pf_sfText_SetCharacterSize)dll.getSymbol("sfText_SetCharacterSize");
|
||||
sfText_SetStyle = cast(pf_sfText_SetStyle)dll.getSymbol("sfText_SetStyle");
|
||||
sfText_GetUnicodeString = cast(pf_sfText_GetUnicodeString)dll.getSymbol("sfText_GetUnicodeString");
|
||||
sfText_GetString = cast(pf_sfText_GetString)dll.getSymbol("sfText_GetString");
|
||||
sfText_GetFont = cast(pf_sfText_GetFont)dll.getSymbol("sfText_GetFont");
|
||||
sfText_GetCharacterSize = cast(pf_sfText_GetCharacterSize)dll.getSymbol("sfText_GetCharacterSize");
|
||||
sfText_GetStyle = cast(pf_sfText_GetStyle)dll.getSymbol("sfText_GetStyle");
|
||||
sfText_GetCharacterPos = cast(pf_sfText_GetCharacterPos)dll.getSymbol("sfText_GetCharacterPos");
|
||||
sfText_GetRect = cast(pf_sfText_GetRect)dll.getSymbol("sfText_GetRect");
|
||||
}
|
||||
}
|
|
@ -1,38 +1,38 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.textstyle;
|
||||
|
||||
/**
|
||||
* Enumerate the string drawing styles
|
||||
* Enumerate the string drawing styles
|
||||
*/
|
||||
enum TextStyle
|
||||
{
|
||||
REGULAR = 0, /// Regular characters, no style
|
||||
BOLD = 1 << 0, /// Characters are bold
|
||||
ITALIC = 1 << 1, /// Characters are in italic
|
||||
UNDERLINED = 1 << 2 /// Characters are underlined
|
||||
REGULAR = 0, /// Regular characters, no style
|
||||
BOLD = 1 << 0, /// Characters are bold
|
||||
ITALIC = 1 << 1, /// Characters are in italic
|
||||
UNDERLINED = 1 << 2 /// Characters are underlined
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.graphics.view;
|
||||
|
@ -33,8 +33,8 @@ import dsfml.system.common,
|
|||
dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* This class defines a view (position, size and zoom) ;
|
||||
* you can consider it as a camera
|
||||
* This class defines a view (position, size and zoom) ;
|
||||
* you can consider it as a camera
|
||||
*/
|
||||
class View : DSFMLObject
|
||||
{
|
||||
|
@ -43,200 +43,200 @@ private:
|
|||
bool m_isModified = true;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Default view (1000 x 1000)
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfView_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* center = center of the view
|
||||
* size = size of the view (width, height)
|
||||
*/
|
||||
this(Vector2f center, Vector2f size)
|
||||
{
|
||||
super(sfView_CreateFromRect(sfFloatRect(center.x - size.x / 2, center.y - size.y / 2, center.x + size.x / 2, center.y + size.y / 2) ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* rect = Rectangle defining the position and size of the view
|
||||
*/
|
||||
this(FloatRect rect)
|
||||
{
|
||||
super(sfView_CreateFromRect(rect.toCFloatRect()));
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Default view (1000 x 1000)
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfView_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* center = center of the view
|
||||
* size = size of the view (width, height)
|
||||
*/
|
||||
this(Vector2f center, Vector2f size)
|
||||
{
|
||||
super(sfView_CreateFromRect(sfFloatRect(center.x - size.x / 2, center.y - size.y / 2, center.x + size.x / 2, center.y + size.y / 2) ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* rect = Rectangle defining the position and size of the view
|
||||
*/
|
||||
this(FloatRect rect)
|
||||
{
|
||||
super(sfView_CreateFromRect(rect.toCFloatRect()));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfView_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the center of the view
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinates of the new center
|
||||
* y = Y coordinates of the new center
|
||||
*/
|
||||
void setCenter(float x, float y)
|
||||
{
|
||||
sfView_SetCenter(m_ptr, x, y);
|
||||
m_isModified = true;
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
sfView_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the center of the view
|
||||
*
|
||||
* Params:
|
||||
* x = X coordinates of the new center
|
||||
* y = Y coordinates of the new center
|
||||
*/
|
||||
void setCenter(float x, float y)
|
||||
{
|
||||
sfView_SetCenter(m_ptr, x, y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the center of the view
|
||||
*
|
||||
* Params:
|
||||
* center = New center
|
||||
*/
|
||||
void setCenter(Vector2f center)
|
||||
{
|
||||
sfView_SetCenter(m_ptr, center.x, center.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
/**
|
||||
* Change the center of the view
|
||||
*
|
||||
* Params:
|
||||
* center = New center
|
||||
*/
|
||||
void setCenter(Vector2f center)
|
||||
{
|
||||
sfView_SetCenter(m_ptr, center.x, center.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
* height = New height
|
||||
*/
|
||||
void setSize(float width, float height)
|
||||
{
|
||||
sfView_SetSize(m_ptr, width, height);
|
||||
m_isModified = true;
|
||||
}
|
||||
/**
|
||||
* Change the size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* width = New width
|
||||
* height = New height
|
||||
*/
|
||||
void setSize(float width, float height)
|
||||
{
|
||||
sfView_SetSize(m_ptr, width, height);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* size = New size
|
||||
*/
|
||||
void setSize(Vector2f size)
|
||||
{
|
||||
sfView_SetSize(m_ptr, size.x, size.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
/**
|
||||
* Change the size of the view (take 2 values)
|
||||
*
|
||||
* Params:
|
||||
* size = New size
|
||||
*/
|
||||
void setSize(Vector2f size)
|
||||
{
|
||||
sfView_SetSize(m_ptr, size.x, size.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the view from a rectangle
|
||||
*
|
||||
* Params:
|
||||
* viewport : Rectangle defining the position and size of the view
|
||||
*/
|
||||
void setViewport(FloatRect viewport)
|
||||
{
|
||||
sfView_SetViewport(m_ptr, viewport.toCFloatRect());
|
||||
m_viewport = viewport;
|
||||
}
|
||||
/**
|
||||
* Rebuild the view from a rectangle
|
||||
*
|
||||
* Params:
|
||||
* viewport : Rectangle defining the position and size of the view
|
||||
*/
|
||||
void setViewport(FloatRect viewport)
|
||||
{
|
||||
sfView_SetViewport(m_ptr, viewport.toCFloatRect());
|
||||
m_viewport = viewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the center of the view
|
||||
*
|
||||
* Returns:
|
||||
* Center of the view
|
||||
*/
|
||||
Vector2f GetCenter()
|
||||
{
|
||||
return Vector2f(sfView_GetCenterX(m_ptr), sfView_GetCenterY(m_ptr));
|
||||
}
|
||||
/**
|
||||
* Get the center of the view
|
||||
*
|
||||
* Returns:
|
||||
* Center of the view
|
||||
*/
|
||||
Vector2f GetCenter()
|
||||
{
|
||||
return Vector2f(sfView_GetCenterX(m_ptr), sfView_GetCenterY(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the view
|
||||
*
|
||||
* Returns:
|
||||
* size of the view
|
||||
*/
|
||||
Vector2f getSize()
|
||||
{
|
||||
return Vector2f(sfView_GetWidth(m_ptr), sfView_GetHeight(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the view
|
||||
*
|
||||
* Returns:
|
||||
* width of the view
|
||||
*/
|
||||
float getWidth()
|
||||
{
|
||||
return sfView_GetWidth(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the size of the view
|
||||
*
|
||||
* Returns:
|
||||
* size of the view
|
||||
*/
|
||||
Vector2f getSize()
|
||||
{
|
||||
return Vector2f(sfView_GetWidth(m_ptr), sfView_GetHeight(m_ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the view
|
||||
*
|
||||
* Returns:
|
||||
* width of the view
|
||||
*/
|
||||
float getWidth()
|
||||
{
|
||||
return sfView_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the view
|
||||
*
|
||||
* Returns:
|
||||
* height of the view
|
||||
*/
|
||||
float getHeight()
|
||||
{
|
||||
return sfView_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounding retangle of the view
|
||||
*/
|
||||
FloatRect getViewport()
|
||||
{
|
||||
if (m_isModified)
|
||||
{
|
||||
m_isModified = false;
|
||||
sfFloatRect cViewport = sfView_GetViewport(m_ptr);
|
||||
m_viewport = new FloatRect(cViewport.Left, cViewport.Top, cViewport.Right, cViewport.Bottom);
|
||||
}
|
||||
return m_viewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset to move the view, on X axis
|
||||
* offsetY = Offset to move the view, on Y axis
|
||||
*/
|
||||
void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfView_Move(m_ptr, offsetX, offsetY);
|
||||
m_isModified = true;
|
||||
}
|
||||
/**
|
||||
* Get the height of the view
|
||||
*
|
||||
* Returns:
|
||||
* height of the view
|
||||
*/
|
||||
float getHeight()
|
||||
{
|
||||
return sfView_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bounding retangle of the view
|
||||
*/
|
||||
FloatRect getViewport()
|
||||
{
|
||||
if (m_isModified)
|
||||
{
|
||||
m_isModified = false;
|
||||
sfFloatRect cViewport = sfView_GetViewport(m_ptr);
|
||||
m_viewport = new FloatRect(cViewport.Left, cViewport.Top, cViewport.Right, cViewport.Bottom);
|
||||
}
|
||||
return m_viewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offsetX = Offset to move the view, on X axis
|
||||
* offsetY = Offset to move the view, on Y axis
|
||||
*/
|
||||
void move(float offsetX, float offsetY)
|
||||
{
|
||||
sfView_Move(m_ptr, offsetX, offsetY);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offset = offsetto move the view
|
||||
*/
|
||||
void move(Vector2f offset)
|
||||
{
|
||||
sfView_Move(m_ptr, offset.x, offset.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the view rectangle to simulate a zoom / unzoom effect
|
||||
*
|
||||
* Params:
|
||||
* factor = Zoom factor to apply, relative to the current zoom
|
||||
*/
|
||||
void zoom(float factor)
|
||||
{
|
||||
sfView_Zoom(m_ptr, factor);
|
||||
m_isModified = true;
|
||||
}
|
||||
/**
|
||||
* Move the view
|
||||
*
|
||||
* Params:
|
||||
* offset = offsetto move the view
|
||||
*/
|
||||
void move(Vector2f offset)
|
||||
{
|
||||
sfView_Move(m_ptr, offset.x, offset.y);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the view rectangle to simulate a zoom / unzoom effect
|
||||
*
|
||||
* Params:
|
||||
* factor = Zoom factor to apply, relative to the current zoom
|
||||
*/
|
||||
void zoom(float factor)
|
||||
{
|
||||
sfView_Zoom(m_ptr, factor);
|
||||
m_isModified = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the view relatively to its current orientation.
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.all;
|
||||
|
||||
public import
|
||||
dsfml.network.ftp,
|
||||
dsfml.network.http,
|
||||
dsfml.network.ipaddress,
|
||||
dsfml.network.packet,
|
||||
dsfml.network.selector,
|
||||
dsfml.network.socketstatus,
|
||||
dsfml.network.sockettcp,
|
||||
dsfml.network.socketudp;
|
||||
dsfml.network.ftp,
|
||||
dsfml.network.http,
|
||||
dsfml.network.ipaddress,
|
||||
dsfml.network.packet,
|
||||
dsfml.network.selector,
|
||||
dsfml.network.socketstatus,
|
||||
dsfml.network.sockettcp,
|
||||
dsfml.network.socketudp;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.http;
|
||||
|
@ -30,369 +30,369 @@ import dsfml.system.stringutil;
|
|||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* HTTP methods enumeration
|
||||
* HTTP methods enumeration
|
||||
*/
|
||||
enum HttpMethod
|
||||
{
|
||||
GET, ///< Request in get mode, standard method to retrieve a page
|
||||
POST, ///< Request in post mode, usually to send data to a page
|
||||
HEAD ///< Request a page's header only
|
||||
GET, ///< Request in get mode, standard method to retrieve a page
|
||||
POST, ///< Request in post mode, usually to send data to a page
|
||||
HEAD ///< Request a page's header only
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP response status code
|
||||
* HTTP response status code
|
||||
*/
|
||||
enum HttpStatus
|
||||
{
|
||||
// 2xx: success
|
||||
OK = 200, ///< Most common code returned when operation was successful
|
||||
CREATED = 201, ///< The resource has successfully been created
|
||||
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
|
||||
// 2xx: success
|
||||
OK = 200, ///< Most common code returned when operation was successful
|
||||
CREATED = 201, ///< The resource has successfully been created
|
||||
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
|
||||
|
||||
// 3xx: redirection
|
||||
MULTIPLECHOICES = 300, ///< The requested page can be accessed from several locations
|
||||
MOVEDPERMANENTLY = 301, ///< The requested page has permanently 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
|
||||
// 3xx: redirection
|
||||
MULTIPLECHOICES = 300, ///< The requested page can be accessed from several locations
|
||||
MOVEDPERMANENTLY = 301, ///< The requested page has permanently 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
|
||||
|
||||
// 4xx: client error
|
||||
BADREQUEST = 400, ///< The server couldn't understand the request (syntax error)
|
||||
UNAUTHORIZED = 401, ///< The requested page needs an authentification to be accessed
|
||||
FORBIDDEN = 403, ///< The requested page cannot be accessed at all, even with authentification
|
||||
NOTFOUND = 404, ///< The requested page doesn't exist
|
||||
// 4xx: client error
|
||||
BADREQUEST = 400, ///< The server couldn't understand the request (syntax error)
|
||||
UNAUTHORIZED = 401, ///< The requested page needs an authentification to be accessed
|
||||
FORBIDDEN = 403, ///< The requested page cannot be accessed at all, even with authentification
|
||||
NOTFOUND = 404, ///< The requested page doesn't exist
|
||||
|
||||
// 5xx: server error
|
||||
INTERNALSERVERERROR = 500, ///< The server encountered an unexpected error
|
||||
NOTIMPLEMENTED = 501, ///< The server doesn't implement a requested feature
|
||||
BADGATEWAY = 502, ///< The gateway server has received an error from the source server
|
||||
SERVICENOTAVAILABLE = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
|
||||
// 5xx: server error
|
||||
INTERNALSERVERERROR = 500, ///< The server encountered an unexpected error
|
||||
NOTIMPLEMENTED = 501, ///< The server doesn't implement a requested feature
|
||||
BADGATEWAY = 502, ///< The gateway server has received an error from the source server
|
||||
SERVICENOTAVAILABLE = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
|
||||
|
||||
// 10xx: SFML custom codes
|
||||
INVALIDRESPONSE = 1000, ///< Response is not a valid HTTP one
|
||||
CONNECTIONFAILED = 1001 ///< Connection with server failed
|
||||
// 10xx: SFML custom codes
|
||||
INVALIDRESPONSE = 1000, ///< Response is not a valid HTTP one
|
||||
CONNECTIONFAILED = 1001 ///< Connection with server failed
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides methods for manipulating the HTTP protocol (described in
|
||||
* RFC 1945).
|
||||
* It can connect to a website, get files, send requests
|
||||
* This class provides methods for manipulating the HTTP protocol (described in
|
||||
* RFC 1945).
|
||||
* It can connect to a website, get files, send requests
|
||||
*/
|
||||
class Http : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Wrapper for a http request, which is basically :
|
||||
* - a header with a method, a target URI and a set of field/value pairs
|
||||
* - an optional body (for POST requests)
|
||||
*/
|
||||
static class Response : DSFMLObject
|
||||
{
|
||||
override void dispose()
|
||||
{
|
||||
sfHttpResponse_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a field
|
||||
*
|
||||
* Params:
|
||||
* field = Name of the field to get (case-insensitive)
|
||||
* Returns:
|
||||
* Value of the field, or enpty string if not found
|
||||
*/
|
||||
string getField(string field)
|
||||
{
|
||||
return fromStringz(sfHttpResponse_GetField(m_ptr, toStringz(field)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header status code
|
||||
*
|
||||
* Returns:
|
||||
* header status code
|
||||
*/
|
||||
HttpStatus getStatus()
|
||||
{
|
||||
return sfHttpResponse_GetStatus(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the major HTTP version number of the response
|
||||
*
|
||||
* Returns:
|
||||
* Major version number
|
||||
*/
|
||||
uint getMajorHTTPVersion()
|
||||
{
|
||||
return sfHttpResponse_GetMajorVersion(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minor HTTP version number of the response
|
||||
*
|
||||
* Returns:
|
||||
* Minor version number
|
||||
*/
|
||||
uint getMinorHTTPVersion()
|
||||
{
|
||||
return sfHttpResponse_GetMinorVersion(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the body of the response. The body can contain :
|
||||
* - the requested page (for GET requests)
|
||||
* - a response from the server (for POST requests)
|
||||
* - nothing (for HEAD requests)
|
||||
* - an error message (in case of an error)
|
||||
*
|
||||
* Returns:
|
||||
* the response body
|
||||
*/
|
||||
string getBody()
|
||||
{
|
||||
return fromStringz(sfHttpResponse_GetBody(m_ptr));
|
||||
}
|
||||
|
||||
private:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
// External ================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*) pf_sfHttpResponse_Destroy;
|
||||
typedef char* function(void*, char*) pf_sfHttpResponse_GetField;
|
||||
typedef HttpStatus function(void*) pf_sfHttpResponse_GetStatus;
|
||||
typedef uint function(void*) pf_sfHttpResponse_GetMajorVersion;
|
||||
typedef uint function(void*) pf_sfHttpResponse_GetMinorVersion;
|
||||
typedef char* function(void*) pf_sfHttpResponse_GetBody;
|
||||
/**
|
||||
* Wrapper for a http request, which is basically :
|
||||
* - a header with a method, a target URI and a set of field/value pairs
|
||||
* - an optional body (for POST requests)
|
||||
*/
|
||||
static class Response : DSFMLObject
|
||||
{
|
||||
override void dispose()
|
||||
{
|
||||
sfHttpResponse_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a field
|
||||
*
|
||||
* Params:
|
||||
* field = Name of the field to get (case-insensitive)
|
||||
* Returns:
|
||||
* Value of the field, or enpty string if not found
|
||||
*/
|
||||
string getField(string field)
|
||||
{
|
||||
return fromStringz(sfHttpResponse_GetField(m_ptr, toStringz(field)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header status code
|
||||
*
|
||||
* Returns:
|
||||
* header status code
|
||||
*/
|
||||
HttpStatus getStatus()
|
||||
{
|
||||
return sfHttpResponse_GetStatus(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the major HTTP version number of the response
|
||||
*
|
||||
* Returns:
|
||||
* Major version number
|
||||
*/
|
||||
uint getMajorHTTPVersion()
|
||||
{
|
||||
return sfHttpResponse_GetMajorVersion(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minor HTTP version number of the response
|
||||
*
|
||||
* Returns:
|
||||
* Minor version number
|
||||
*/
|
||||
uint getMinorHTTPVersion()
|
||||
{
|
||||
return sfHttpResponse_GetMinorVersion(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the body of the response. The body can contain :
|
||||
* - the requested page (for GET requests)
|
||||
* - a response from the server (for POST requests)
|
||||
* - nothing (for HEAD requests)
|
||||
* - an error message (in case of an error)
|
||||
*
|
||||
* Returns:
|
||||
* the response body
|
||||
*/
|
||||
string getBody()
|
||||
{
|
||||
return fromStringz(sfHttpResponse_GetBody(m_ptr));
|
||||
}
|
||||
|
||||
private:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
// External ================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(void*) pf_sfHttpResponse_Destroy;
|
||||
typedef char* function(void*, char*) pf_sfHttpResponse_GetField;
|
||||
typedef HttpStatus function(void*) pf_sfHttpResponse_GetStatus;
|
||||
typedef uint function(void*) pf_sfHttpResponse_GetMajorVersion;
|
||||
typedef uint function(void*) pf_sfHttpResponse_GetMinorVersion;
|
||||
typedef char* function(void*) pf_sfHttpResponse_GetBody;
|
||||
|
||||
static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy;
|
||||
static pf_sfHttpResponse_GetField sfHttpResponse_GetField;
|
||||
static pf_sfHttpResponse_GetStatus sfHttpResponse_GetStatus;
|
||||
static pf_sfHttpResponse_GetMajorVersion sfHttpResponse_GetMajorVersion;
|
||||
static pf_sfHttpResponse_GetMinorVersion sfHttpResponse_GetMinorVersion;
|
||||
static pf_sfHttpResponse_GetBody sfHttpResponse_GetBody;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfHttpResponse_Destroy = cast(pf_sfHttpResponse_Destroy)dll.getSymbol("sfHttpResponse_Destroy");
|
||||
sfHttpResponse_GetField = cast(pf_sfHttpResponse_GetField)dll.getSymbol("sfHttpResponse_GetField");
|
||||
sfHttpResponse_GetStatus = cast(pf_sfHttpResponse_GetStatus)dll.getSymbol("sfHttpResponse_GetStatus");
|
||||
sfHttpResponse_GetMajorVersion = cast(pf_sfHttpResponse_GetMajorVersion)dll.getSymbol("sfHttpResponse_GetMajorVersion");
|
||||
sfHttpResponse_GetMinorVersion = cast(pf_sfHttpResponse_GetMinorVersion)dll.getSymbol("sfHttpResponse_GetMinorVersion");
|
||||
sfHttpResponse_GetBody = cast(pf_sfHttpResponse_GetBody)dll.getSymbol("sfHttpResponse_GetBody");
|
||||
}
|
||||
}
|
||||
static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy;
|
||||
static pf_sfHttpResponse_GetField sfHttpResponse_GetField;
|
||||
static pf_sfHttpResponse_GetStatus sfHttpResponse_GetStatus;
|
||||
static pf_sfHttpResponse_GetMajorVersion sfHttpResponse_GetMajorVersion;
|
||||
static pf_sfHttpResponse_GetMinorVersion sfHttpResponse_GetMinorVersion;
|
||||
static pf_sfHttpResponse_GetBody sfHttpResponse_GetBody;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfHttpResponse_Destroy = cast(pf_sfHttpResponse_Destroy)dll.getSymbol("sfHttpResponse_Destroy");
|
||||
sfHttpResponse_GetField = cast(pf_sfHttpResponse_GetField)dll.getSymbol("sfHttpResponse_GetField");
|
||||
sfHttpResponse_GetStatus = cast(pf_sfHttpResponse_GetStatus)dll.getSymbol("sfHttpResponse_GetStatus");
|
||||
sfHttpResponse_GetMajorVersion = cast(pf_sfHttpResponse_GetMajorVersion)dll.getSymbol("sfHttpResponse_GetMajorVersion");
|
||||
sfHttpResponse_GetMinorVersion = cast(pf_sfHttpResponse_GetMinorVersion)dll.getSymbol("sfHttpResponse_GetMinorVersion");
|
||||
sfHttpResponse_GetBody = cast(pf_sfHttpResponse_GetBody)dll.getSymbol("sfHttpResponse_GetBody");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for a HTTP response which is basically :
|
||||
* - a header with a status code and a set of field/value pairs
|
||||
* - a body (the content of the requested resource)
|
||||
*/
|
||||
static class Request : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* requestMethod = Method to use for the request (Get by default)
|
||||
* uri = Target URI ("/" by default -- index page)
|
||||
* requestBody = Content of the request's body (empty by default)
|
||||
*/
|
||||
this(HttpMethod requestMethod = HttpMethod.GET, string uri = "/", string requestBody = "")
|
||||
{
|
||||
super(sfHttpRequest_Create());
|
||||
sfHttpRequest_SetMethod(m_ptr, requestMethod);
|
||||
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
|
||||
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a field. Field is created if it doesn't exists.
|
||||
*
|
||||
* Params:
|
||||
* field = name of the field to set (case-insensitive)
|
||||
* value = value of the field
|
||||
*/
|
||||
void setField(string field, string value)
|
||||
{
|
||||
sfHttpRequest_SetField(m_ptr, toStringz(field), toStringz(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request method.
|
||||
*
|
||||
* Params:
|
||||
* requestMethod = Method to use for the request.
|
||||
*/
|
||||
void setMethod(HttpMethod requestMethod)
|
||||
{
|
||||
sfHttpRequest_SetMethod(m_ptr, requestMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target URI of the request.
|
||||
*
|
||||
* Params:
|
||||
* uri = URI to request, local to the host.
|
||||
* Returns:
|
||||
*/
|
||||
void setURI(string uri)
|
||||
{
|
||||
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP version of the request.
|
||||
*
|
||||
* Params:
|
||||
* major = Major version number
|
||||
* minor = Minor version number
|
||||
*/
|
||||
void setHttpVersion(uint major, uint minor)
|
||||
{
|
||||
sfHttpRequest_SetHttpVersion(m_ptr, major, minor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body of the request. This parameter is optionnal and make sense
|
||||
* only for POST requests.
|
||||
*
|
||||
* Params:
|
||||
* requestBody = Content of the request body.
|
||||
*/
|
||||
void setBody(string requestBody)
|
||||
{
|
||||
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// External ================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfHttpRequest_Create;
|
||||
typedef void function(void*) pf_sfHttpRequest_Destroy;
|
||||
typedef void function(void*, char*, char*) pf_sfHttpRequest_SetField;
|
||||
typedef void function(void*, HttpMethod) pf_sfHttpRequest_SetMethod;
|
||||
typedef void function(void*, char*) pf_sfHttpRequest_SetURI;
|
||||
typedef void function(void*, uint, uint) pf_sfHttpRequest_SetHttpVersion;
|
||||
typedef void function(void*, char*) pf_sfHttpRequest_SetBody;
|
||||
|
||||
static pf_sfHttpRequest_Create sfHttpRequest_Create;
|
||||
static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy;
|
||||
static pf_sfHttpRequest_SetField sfHttpRequest_SetField;
|
||||
static pf_sfHttpRequest_SetMethod sfHttpRequest_SetMethod;
|
||||
static pf_sfHttpRequest_SetURI sfHttpRequest_SetURI;
|
||||
static pf_sfHttpRequest_SetHttpVersion sfHttpRequest_SetHttpVersion;
|
||||
static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfHttpRequest_Create = cast(pf_sfHttpRequest_Create)dll.getSymbol("sfHttpRequest_Create");
|
||||
sfHttpRequest_Destroy = cast(pf_sfHttpRequest_Destroy)dll.getSymbol("sfHttpRequest_Destroy");
|
||||
sfHttpRequest_SetField = cast(pf_sfHttpRequest_SetField)dll.getSymbol("sfHttpRequest_SetField");
|
||||
sfHttpRequest_SetMethod = cast(pf_sfHttpRequest_SetMethod)dll.getSymbol("sfHttpRequest_SetMethod");
|
||||
sfHttpRequest_SetURI = cast(pf_sfHttpRequest_SetURI)dll.getSymbol("sfHttpRequest_SetURI");
|
||||
sfHttpRequest_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion");
|
||||
sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfHttp_Create());
|
||||
}
|
||||
/**
|
||||
* Wrapper for a HTTP response which is basically :
|
||||
* - a header with a status code and a set of field/value pairs
|
||||
* - a body (the content of the requested resource)
|
||||
*/
|
||||
static class Request : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* requestMethod = Method to use for the request (Get by default)
|
||||
* uri = Target URI ("/" by default -- index page)
|
||||
* requestBody = Content of the request's body (empty by default)
|
||||
*/
|
||||
this(HttpMethod requestMethod = HttpMethod.GET, string uri = "/", string requestBody = "")
|
||||
{
|
||||
super(sfHttpRequest_Create());
|
||||
sfHttpRequest_SetMethod(m_ptr, requestMethod);
|
||||
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
|
||||
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a field. Field is created if it doesn't exists.
|
||||
*
|
||||
* Params:
|
||||
* field = name of the field to set (case-insensitive)
|
||||
* value = value of the field
|
||||
*/
|
||||
void setField(string field, string value)
|
||||
{
|
||||
sfHttpRequest_SetField(m_ptr, toStringz(field), toStringz(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request method.
|
||||
*
|
||||
* Params:
|
||||
* requestMethod = Method to use for the request.
|
||||
*/
|
||||
void setMethod(HttpMethod requestMethod)
|
||||
{
|
||||
sfHttpRequest_SetMethod(m_ptr, requestMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target URI of the request.
|
||||
*
|
||||
* Params:
|
||||
* uri = URI to request, local to the host.
|
||||
* Returns:
|
||||
*/
|
||||
void setURI(string uri)
|
||||
{
|
||||
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP version of the request.
|
||||
*
|
||||
* Params:
|
||||
* major = Major version number
|
||||
* minor = Minor version number
|
||||
*/
|
||||
void setHttpVersion(uint major, uint minor)
|
||||
{
|
||||
sfHttpRequest_SetHttpVersion(m_ptr, major, minor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body of the request. This parameter is optionnal and make sense
|
||||
* only for POST requests.
|
||||
*
|
||||
* Params:
|
||||
* requestBody = Content of the request body.
|
||||
*/
|
||||
void setBody(string requestBody)
|
||||
{
|
||||
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// External ================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfHttpRequest_Create;
|
||||
typedef void function(void*) pf_sfHttpRequest_Destroy;
|
||||
typedef void function(void*, char*, char*) pf_sfHttpRequest_SetField;
|
||||
typedef void function(void*, HttpMethod) pf_sfHttpRequest_SetMethod;
|
||||
typedef void function(void*, char*) pf_sfHttpRequest_SetURI;
|
||||
typedef void function(void*, uint, uint) pf_sfHttpRequest_SetHttpVersion;
|
||||
typedef void function(void*, char*) pf_sfHttpRequest_SetBody;
|
||||
|
||||
static pf_sfHttpRequest_Create sfHttpRequest_Create;
|
||||
static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy;
|
||||
static pf_sfHttpRequest_SetField sfHttpRequest_SetField;
|
||||
static pf_sfHttpRequest_SetMethod sfHttpRequest_SetMethod;
|
||||
static pf_sfHttpRequest_SetURI sfHttpRequest_SetURI;
|
||||
static pf_sfHttpRequest_SetHttpVersion sfHttpRequest_SetHttpVersion;
|
||||
static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfHttpRequest_Create = cast(pf_sfHttpRequest_Create)dll.getSymbol("sfHttpRequest_Create");
|
||||
sfHttpRequest_Destroy = cast(pf_sfHttpRequest_Destroy)dll.getSymbol("sfHttpRequest_Destroy");
|
||||
sfHttpRequest_SetField = cast(pf_sfHttpRequest_SetField)dll.getSymbol("sfHttpRequest_SetField");
|
||||
sfHttpRequest_SetMethod = cast(pf_sfHttpRequest_SetMethod)dll.getSymbol("sfHttpRequest_SetMethod");
|
||||
sfHttpRequest_SetURI = cast(pf_sfHttpRequest_SetURI)dll.getSymbol("sfHttpRequest_SetURI");
|
||||
sfHttpRequest_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion");
|
||||
sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfHttp_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* host = Web server to connect to
|
||||
* port = port to use for connection (0 by default -- use the standard port of the protocol)
|
||||
*/
|
||||
this(string host, ushort port = 0)
|
||||
{
|
||||
super(sfHttp_Create());
|
||||
sfHttp_SetHost(m_ptr, toStringz(host), port);
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Params:
|
||||
* host = Web server to connect to
|
||||
* port = port to use for connection (0 by default -- use the standard port of the protocol)
|
||||
*/
|
||||
this(string host, ushort port = 0)
|
||||
{
|
||||
super(sfHttp_Create());
|
||||
sfHttp_SetHost(m_ptr, toStringz(host), port);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfHttp_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target host.
|
||||
*
|
||||
* Params:
|
||||
* host = Web server to connect to
|
||||
* port = port to use for connection (0 by default -- use the standard port of the protocol)
|
||||
*/
|
||||
void setHost(string host, ushort port = 0)
|
||||
{
|
||||
sfHttp_SetHost(m_ptr, toStringz(host), port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HTTP request and return the server's response.
|
||||
* You must be connected to a host before sending requests.
|
||||
* Any missing mandatory header field will be added with an appropriate value.
|
||||
*
|
||||
* 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
|
||||
* application.
|
||||
*
|
||||
* Params:
|
||||
* req = Request to send
|
||||
*
|
||||
* Returns:
|
||||
* Server's response
|
||||
*/
|
||||
override void dispose()
|
||||
{
|
||||
sfHttp_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target host.
|
||||
*
|
||||
* Params:
|
||||
* host = Web server to connect to
|
||||
* port = port to use for connection (0 by default -- use the standard port of the protocol)
|
||||
*/
|
||||
void setHost(string host, ushort port = 0)
|
||||
{
|
||||
sfHttp_SetHost(m_ptr, toStringz(host), port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HTTP request and return the server's response.
|
||||
* You must be connected to a host before sending requests.
|
||||
* Any missing mandatory header field will be added with an appropriate value.
|
||||
*
|
||||
* 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
|
||||
* application.
|
||||
*
|
||||
* Params:
|
||||
* req = Request to send
|
||||
*
|
||||
* Returns:
|
||||
* Server's response
|
||||
*/
|
||||
|
||||
Response sendRequest(Request req)
|
||||
{
|
||||
return new Response( sfHttp_SendRequest(m_ptr, req.getNativePointer) );
|
||||
}
|
||||
|
||||
Response sendRequest(Request req)
|
||||
{
|
||||
return new Response( sfHttp_SendRequest(m_ptr, req.getNativePointer) );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfHttp_Create;
|
||||
typedef void function(void*) pf_sfHttp_Destroy;
|
||||
typedef void function(void*, char*, ushort) pf_sfHttp_SetHost;
|
||||
typedef void* function(void*, void*) pf_sfHttp_SendRequest;
|
||||
|
||||
static pf_sfHttp_Create sfHttp_Create;
|
||||
static pf_sfHttp_Destroy sfHttp_Destroy;
|
||||
static pf_sfHttp_SetHost sfHttp_SetHost;
|
||||
static pf_sfHttp_SendRequest sfHttp_SendRequest;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfHttp_Create;
|
||||
typedef void function(void*) pf_sfHttp_Destroy;
|
||||
typedef void function(void*, char*, ushort) pf_sfHttp_SetHost;
|
||||
typedef void* function(void*, void*) pf_sfHttp_SendRequest;
|
||||
|
||||
static pf_sfHttp_Create sfHttp_Create;
|
||||
static pf_sfHttp_Destroy sfHttp_Destroy;
|
||||
static pf_sfHttp_SetHost sfHttp_SetHost;
|
||||
static pf_sfHttp_SendRequest sfHttp_SendRequest;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfHttp_Create = cast(pf_sfHttp_Create)dll.getSymbol("sfHttp_Create");
|
||||
sfHttp_Destroy = cast(pf_sfHttp_Destroy)dll.getSymbol("sfHttp_Destroy");
|
||||
sfHttp_SetHost = cast(pf_sfHttp_SetHost)dll.getSymbol("sfHttp_SetHost");
|
||||
sfHttp_SendRequest = cast(pf_sfHttp_SendRequest)dll.getSymbol("sfHttp_SendRequest");
|
||||
}
|
||||
|
||||
sfHttp_Create = cast(pf_sfHttp_Create)dll.getSymbol("sfHttp_Create");
|
||||
sfHttp_Destroy = cast(pf_sfHttp_Destroy)dll.getSymbol("sfHttp_Destroy");
|
||||
sfHttp_SetHost = cast(pf_sfHttp_SetHost)dll.getSymbol("sfHttp_SetHost");
|
||||
sfHttp_SendRequest = cast(pf_sfHttp_SendRequest)dll.getSymbol("sfHttp_SendRequest");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.ipaddress;
|
||||
|
@ -30,111 +30,111 @@ import dsfml.system.common;
|
|||
import dsfml.system.stringutil;
|
||||
|
||||
/**
|
||||
* IPAddress provides easy manipulation of IP v4 addresses
|
||||
* IPAddress provides easy manipulation of IP v4 addresses
|
||||
*/
|
||||
struct IPAddress
|
||||
{
|
||||
/**
|
||||
* Construct the address from a string
|
||||
*
|
||||
* Params:
|
||||
* address = IP address ("xxx.xxx.xxx.xxx") or network name
|
||||
*
|
||||
*/
|
||||
static IPAddress opCall(string address)
|
||||
{
|
||||
return sfIPAddress_FromString(toStringz(address));
|
||||
}
|
||||
/**
|
||||
* Construct the address from a string
|
||||
*
|
||||
* Params:
|
||||
* address = IP address ("xxx.xxx.xxx.xxx") or network name
|
||||
*
|
||||
*/
|
||||
static IPAddress opCall(string address)
|
||||
{
|
||||
return sfIPAddress_FromString(toStringz(address));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the address from 4 bytes
|
||||
*
|
||||
* Params:
|
||||
* byte0 = First byte of the address
|
||||
* byte1 = Second byte of the address
|
||||
* byte2 = Third byte of the address
|
||||
* byte3 = Fourth byte of the address
|
||||
*
|
||||
*/
|
||||
static IPAddress opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3)
|
||||
{
|
||||
return sfIPAddress_FromBytes(byte0, byte1, byte2, byte3);
|
||||
}
|
||||
/**
|
||||
* Construct the address from 4 bytes
|
||||
*
|
||||
* Params:
|
||||
* byte0 = First byte of the address
|
||||
* byte1 = Second byte of the address
|
||||
* byte2 = Third byte of the address
|
||||
* byte3 = Fourth byte of the address
|
||||
*
|
||||
*/
|
||||
static IPAddress opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3)
|
||||
{
|
||||
return sfIPAddress_FromBytes(byte0, byte1, byte2, byte3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the address from a 32 bits integer
|
||||
*
|
||||
* Params:
|
||||
* address = 4 bytes of the address packed into a 32 bits integer
|
||||
*
|
||||
*/
|
||||
static IPAddress opCall(uint address)
|
||||
{
|
||||
return sfIPAddress_FromInteger(address);
|
||||
}
|
||||
/**
|
||||
* Construct the address from a 32 bits integer
|
||||
*
|
||||
* Params:
|
||||
* address = 4 bytes of the address packed into a 32 bits integer
|
||||
*
|
||||
*/
|
||||
static IPAddress opCall(uint address)
|
||||
{
|
||||
return sfIPAddress_FromInteger(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the address is a valid one
|
||||
*
|
||||
* Returns:
|
||||
* True if address has a valid syntax
|
||||
*
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfIPAddress_IsValid(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the computer's local IP address (from the LAN point of view)
|
||||
*
|
||||
* Returns:
|
||||
* Local IP address
|
||||
*
|
||||
*/
|
||||
static IPAddress getLocalAddress()
|
||||
{
|
||||
return sfIPAddress_GetLocalAddress();
|
||||
}
|
||||
/**
|
||||
* Tell if the address is a valid one
|
||||
*
|
||||
* Returns:
|
||||
* True if address has a valid syntax
|
||||
*
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfIPAddress_IsValid(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the computer's local IP address (from the LAN point of view)
|
||||
*
|
||||
* Returns:
|
||||
* Local IP address
|
||||
*
|
||||
*/
|
||||
static IPAddress getLocalAddress()
|
||||
{
|
||||
return sfIPAddress_GetLocalAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* distant website ; as a consequence, this function may be
|
||||
* very slow -- use it as few as possible !
|
||||
*
|
||||
* Returns:
|
||||
* Public IP address
|
||||
*
|
||||
*/
|
||||
static IPAddress getPublicAddress()
|
||||
{
|
||||
return sfIPAddress_GetPublicAddress();
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
* distant website ; as a consequence, this function may be
|
||||
* very slow -- use it as few as possible !
|
||||
*
|
||||
* Returns:
|
||||
* Public IP address
|
||||
*
|
||||
*/
|
||||
static IPAddress getPublicAddress()
|
||||
{
|
||||
return sfIPAddress_GetPublicAddress();
|
||||
}
|
||||
|
||||
bool opEqual(IPAddress other)
|
||||
{
|
||||
return Address == other.Address;
|
||||
}
|
||||
bool opEqual(IPAddress other)
|
||||
{
|
||||
return Address == other.Address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local host address (to connect to the same computer).
|
||||
*/
|
||||
static IPAddress LOCALHOST()
|
||||
{
|
||||
return sfIPAddress_LocalHost();
|
||||
}
|
||||
/**
|
||||
* Local host address (to connect to the same computer).
|
||||
*/
|
||||
static IPAddress LOCALHOST()
|
||||
{
|
||||
return sfIPAddress_LocalHost();
|
||||
}
|
||||
|
||||
byte[16] Address;
|
||||
|
||||
byte[16] Address;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
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(uint) pf_sfIPAddress_FromInteger;
|
||||
typedef int function(IPAddress) pf_sfIPAddress_IsValid;
|
||||
|
@ -157,12 +157,12 @@ static this()
|
|||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfIPAddress_FromBytes = cast(pf_sfIPAddress_FromBytes)dll.getSymbol("sfIPAddress_FromBytes");
|
||||
sfIPAddress_FromString = cast(pf_sfIPAddress_FromString)dll.getSymbol("sfIPAddress_FromString");
|
||||
sfIPAddress_FromInteger = cast(pf_sfIPAddress_FromInteger)dll.getSymbol("sfIPAddress_FromInteger");
|
||||
sfIPAddress_GetLocalAddress = cast(pf_sfIPAddress_GetLocalAddress)dll.getSymbol("sfIPAddress_GetLocalAddress");
|
||||
sfIPAddress_GetPublicAddress = cast(pf_sfIPAddress_GetPublicAddress)dll.getSymbol("sfIPAddress_GetPublicAddress");
|
||||
sfIPAddress_IsValid = cast(pf_sfIPAddress_IsValid)dll.getSymbol("sfIPAddress_IsValid");
|
||||
sfIPAddress_LocalHost = cast(pf_sfIPAddress_LocalHost)dll.getSymbol("sfIPAddress_LocalHost");
|
||||
|
||||
sfIPAddress_FromBytes = cast(pf_sfIPAddress_FromBytes)dll.getSymbol("sfIPAddress_FromBytes");
|
||||
sfIPAddress_FromString = cast(pf_sfIPAddress_FromString)dll.getSymbol("sfIPAddress_FromString");
|
||||
sfIPAddress_FromInteger = cast(pf_sfIPAddress_FromInteger)dll.getSymbol("sfIPAddress_FromInteger");
|
||||
sfIPAddress_GetLocalAddress = cast(pf_sfIPAddress_GetLocalAddress)dll.getSymbol("sfIPAddress_GetLocalAddress");
|
||||
sfIPAddress_GetPublicAddress = cast(pf_sfIPAddress_GetPublicAddress)dll.getSymbol("sfIPAddress_GetPublicAddress");
|
||||
sfIPAddress_IsValid = cast(pf_sfIPAddress_IsValid)dll.getSymbol("sfIPAddress_IsValid");
|
||||
sfIPAddress_LocalHost = cast(pf_sfIPAddress_LocalHost)dll.getSymbol("sfIPAddress_LocalHost");
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.packet;
|
||||
|
@ -30,388 +30,388 @@ import dsfml.system.common;
|
|||
import dsfml.system.stringutil;
|
||||
|
||||
/**
|
||||
* Packet wraps data to send / to receive through the network
|
||||
*
|
||||
* 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.
|
||||
* Packet wraps data to send / to receive through the network
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Litterals integer are promoted to int.
|
||||
* Litterals floating point are promoted to float.
|
||||
*
|
||||
* Extraction or insertion can be specified with explicit template.
|
||||
* Examples:
|
||||
* ------------------------------------------------------------
|
||||
* Packet p = new Packet();
|
||||
*
|
||||
* int i = 32, j = 42;
|
||||
* string k = hello;
|
||||
*
|
||||
* p.set(i, k, j); //Set the data in the packet
|
||||
*
|
||||
* int a, b;
|
||||
* string c;
|
||||
* p.get(a, c, b); //Get data from the packet
|
||||
*
|
||||
* //...
|
||||
*
|
||||
* Packet p = new Packet();
|
||||
* p.set!(byte)(5); // Litteral are inserted with byte type
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* See_Also:
|
||||
* $(LINK2 http://www.digitalmars.com/d/1.0/lex.html, D litterals Specification) for more informations.
|
||||
* Litterals integer are promoted to int.
|
||||
* Litterals floating point are promoted to float.
|
||||
*
|
||||
* Extraction or insertion can be specified with explicit template.
|
||||
* Examples:
|
||||
* ------------------------------------------------------------
|
||||
* Packet p = new Packet();
|
||||
*
|
||||
* int i = 32, j = 42;
|
||||
* string k = hello;
|
||||
*
|
||||
* p.set(i, k, j); //Set the data in the packet
|
||||
*
|
||||
* int a, b;
|
||||
* string c;
|
||||
* p.get(a, c, b); //Get data from the packet
|
||||
*
|
||||
* //...
|
||||
*
|
||||
* Packet p = new Packet();
|
||||
* p.set!(byte)(5); // Litteral are inserted with byte type
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* See_Also:
|
||||
* $(LINK2 http://www.digitalmars.com/d/1.0/lex.html, D litterals Specification) for more informations.
|
||||
*/
|
||||
class Packet : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfPacket_Create());
|
||||
}
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfPacket_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfPacket_Destroy(m_ptr);
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
sfPacket_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to the end of the packet.
|
||||
*
|
||||
* Params:
|
||||
* data = Array of data to append
|
||||
*
|
||||
*/
|
||||
void append(byte[] data)
|
||||
{
|
||||
if (data !is null)
|
||||
sfPacket_Append(m_ptr, data.ptr, data.length);
|
||||
}
|
||||
/**
|
||||
* Append data to the end of the packet.
|
||||
*
|
||||
* Params:
|
||||
* data = Array of data to append
|
||||
*
|
||||
*/
|
||||
void append(byte[] data)
|
||||
{
|
||||
if (data !is null)
|
||||
sfPacket_Append(m_ptr, data.ptr, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the packet data
|
||||
*
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
sfPacket_Clear(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Clear the packet data
|
||||
*
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
sfPacket_Clear(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array to the data contained in the packet
|
||||
* $(B the returned array may be invalid after you
|
||||
* append data to the packet)
|
||||
*
|
||||
* Returns:
|
||||
* array of data
|
||||
*
|
||||
* Remarks:
|
||||
* return an array of $(B all) data in the packet.
|
||||
*
|
||||
* ----------
|
||||
* Packet p = new Packet();
|
||||
*
|
||||
* string str1 = "Hi";
|
||||
* string str2 = "Hello";
|
||||
*
|
||||
* p.set(str1, str2);
|
||||
*
|
||||
* // Retrieve str1 from packet
|
||||
* string str3;
|
||||
* p.get(str3);
|
||||
*
|
||||
* // Returns an array containing str1 and str2.
|
||||
* byte[] ptr = p.getData();
|
||||
* ----------
|
||||
*/
|
||||
byte[] getData()
|
||||
{
|
||||
if (canRead)
|
||||
return sfPacket_GetData(m_ptr)[0..getDataSize];
|
||||
}
|
||||
/**
|
||||
* Get an array to the data contained in the packet
|
||||
* $(B the returned array may be invalid after you
|
||||
* append data to the packet)
|
||||
*
|
||||
* Returns:
|
||||
* array of data
|
||||
*
|
||||
* Remarks:
|
||||
* return an array of $(B all) data in the packet.
|
||||
*
|
||||
* ----------
|
||||
* Packet p = new Packet();
|
||||
*
|
||||
* string str1 = "Hi";
|
||||
* string str2 = "Hello";
|
||||
*
|
||||
* p.set(str1, str2);
|
||||
*
|
||||
* // Retrieve str1 from packet
|
||||
* string str3;
|
||||
* p.get(str3);
|
||||
*
|
||||
* // Returns an array containing str1 and str2.
|
||||
* byte[] ptr = p.getData();
|
||||
* ----------
|
||||
*/
|
||||
byte[] getData()
|
||||
{
|
||||
if (canRead)
|
||||
return sfPacket_GetData(m_ptr)[0..getDataSize];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the size of the data contained in the packet
|
||||
*
|
||||
* Returns:
|
||||
* Data size, in bytes
|
||||
*/
|
||||
uint getDataSize()
|
||||
{
|
||||
return sfPacket_GetDataSize(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the reading position has reached the end of the packet
|
||||
*
|
||||
* Returns:
|
||||
* true if all data have been read.
|
||||
*/
|
||||
bool endOfPacket()
|
||||
{
|
||||
return cast(bool)sfPacket_EndOfPacket(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Tell if the packet is valid for reading
|
||||
*
|
||||
* Returns:
|
||||
* True if data can be extracted from the packet
|
||||
*
|
||||
*/
|
||||
bool canRead()
|
||||
{
|
||||
return cast(bool)sfPacket_CanRead(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add new variables to the packet
|
||||
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
|
||||
*/
|
||||
Packet set(T...)(T t)
|
||||
{
|
||||
foreach (v; t)
|
||||
internalSet(t);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the data contained in the packet
|
||||
*
|
||||
* Returns:
|
||||
* Data size, in bytes
|
||||
*/
|
||||
uint getDataSize()
|
||||
{
|
||||
return sfPacket_GetDataSize(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the reading position has reached the end of the packet
|
||||
*
|
||||
* Returns:
|
||||
* true if all data have been read.
|
||||
*/
|
||||
bool endOfPacket()
|
||||
{
|
||||
return cast(bool)sfPacket_EndOfPacket(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Tell if the packet is valid for reading
|
||||
*
|
||||
* Returns:
|
||||
* True if data can be extracted from the packet
|
||||
*
|
||||
*/
|
||||
bool canRead()
|
||||
{
|
||||
return cast(bool)sfPacket_CanRead(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add new variables to the packet
|
||||
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
|
||||
*/
|
||||
Packet set(T...)(T t)
|
||||
{
|
||||
foreach (v; t)
|
||||
internalSet(t);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve data from the packet
|
||||
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
|
||||
*/
|
||||
Packet get(T...)(ref T t)
|
||||
{
|
||||
foreach (v; t)
|
||||
internalGet(t);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Retrieve data from the packet
|
||||
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
|
||||
*/
|
||||
Packet get(T...)(ref T t)
|
||||
{
|
||||
foreach (v; t)
|
||||
internalGet(t);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before packet is send
|
||||
*
|
||||
* Params:
|
||||
* size = Variable to fill with the size of the data to send
|
||||
* Returns:
|
||||
* Array of byte to send
|
||||
*/
|
||||
byte[] onSend()
|
||||
{
|
||||
return getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after a packet has been received
|
||||
*
|
||||
* Params:
|
||||
* data = Array of byte received
|
||||
*/
|
||||
void onReceive(byte[] data)
|
||||
{
|
||||
append(data);
|
||||
}
|
||||
/**
|
||||
* Called before packet is send
|
||||
*
|
||||
* Params:
|
||||
* size = Variable to fill with the size of the data to send
|
||||
* Returns:
|
||||
* Array of byte to send
|
||||
*/
|
||||
byte[] onSend()
|
||||
{
|
||||
return getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after a packet has been received
|
||||
*
|
||||
* Params:
|
||||
* data = Array of byte received
|
||||
*/
|
||||
void onReceive(byte[] data)
|
||||
{
|
||||
append(data);
|
||||
}
|
||||
|
||||
private:
|
||||
void internalGet(ref bool data)
|
||||
{
|
||||
data = cast(bool)sfPacket_ReadInt32(m_ptr);
|
||||
}
|
||||
void internalGet(ref byte data)
|
||||
{
|
||||
data = sfPacket_ReadInt8(m_ptr);
|
||||
}
|
||||
void internalGet(ref ubyte data)
|
||||
{
|
||||
data = sfPacket_ReadUint8(m_ptr);
|
||||
}
|
||||
void internalGet(ref short data)
|
||||
{
|
||||
data = sfPacket_ReadInt16(m_ptr);
|
||||
}
|
||||
void internalGet(ref ushort data)
|
||||
{
|
||||
data = sfPacket_ReadUint16(m_ptr);
|
||||
}
|
||||
void internalGet(ref int data)
|
||||
{
|
||||
data = sfPacket_ReadInt32(m_ptr);
|
||||
}
|
||||
void internalGet(ref uint data)
|
||||
{
|
||||
data = sfPacket_ReadUint32(m_ptr);
|
||||
}
|
||||
void internalGet(ref float data)
|
||||
{
|
||||
data = sfPacket_ReadFloat(m_ptr);
|
||||
}
|
||||
void internalGet(ref double data)
|
||||
{
|
||||
data = sfPacket_ReadDouble(m_ptr);
|
||||
}
|
||||
void internalGet(ref string data)
|
||||
{
|
||||
scope string temp = new char[sfPacket_GetDataSize(m_ptr)];
|
||||
sfPacket_ReadString(m_ptr, temp.ptr);
|
||||
size_t l = fromStringz(temp.ptr).length;
|
||||
data = new char[l];
|
||||
data[] = temp[0 .. l];
|
||||
}
|
||||
|
||||
void internalGet(ref wstring data)
|
||||
{
|
||||
scope wstring temp = new wchar[sfPacket_GetDataSize(m_ptr)];
|
||||
sfPacket_ReadWideString(m_ptr, temp.ptr);
|
||||
size_t l = fromStringz(temp.ptr).length;
|
||||
data = new wchar[l];
|
||||
data[] = temp[0 .. l];
|
||||
}
|
||||
|
||||
void internalSet(bool data)
|
||||
{
|
||||
sfPacket_WriteInt32(m_ptr, cast(int)data);
|
||||
}
|
||||
void internalSet(byte data)
|
||||
{
|
||||
sfPacket_WriteInt8(m_ptr, data);
|
||||
}
|
||||
void internalSet(ubyte data)
|
||||
{
|
||||
sfPacket_WriteUint8(m_ptr, data);
|
||||
}
|
||||
void internalSet(short data)
|
||||
{
|
||||
sfPacket_WriteInt16(m_ptr, data);
|
||||
}
|
||||
void internalSet(ushort data)
|
||||
{
|
||||
sfPacket_WriteUint16(m_ptr, data);
|
||||
}
|
||||
void internalSet(int data)
|
||||
{
|
||||
sfPacket_WriteInt32(m_ptr, data);
|
||||
}
|
||||
void internalSet(uint data)
|
||||
{
|
||||
sfPacket_WriteUint32(m_ptr, data);
|
||||
}
|
||||
void internalSet(float data)
|
||||
{
|
||||
sfPacket_WriteFloat(m_ptr, data);
|
||||
}
|
||||
void internalSet(double data)
|
||||
{
|
||||
sfPacket_WriteDouble(m_ptr, data);
|
||||
}
|
||||
void internalSet(string data)
|
||||
{
|
||||
sfPacket_WriteString(m_ptr, toStringz(data));
|
||||
}
|
||||
void internalGet(ref bool data)
|
||||
{
|
||||
data = cast(bool)sfPacket_ReadInt32(m_ptr);
|
||||
}
|
||||
void internalGet(ref byte data)
|
||||
{
|
||||
data = sfPacket_ReadInt8(m_ptr);
|
||||
}
|
||||
void internalGet(ref ubyte data)
|
||||
{
|
||||
data = sfPacket_ReadUint8(m_ptr);
|
||||
}
|
||||
void internalGet(ref short data)
|
||||
{
|
||||
data = sfPacket_ReadInt16(m_ptr);
|
||||
}
|
||||
void internalGet(ref ushort data)
|
||||
{
|
||||
data = sfPacket_ReadUint16(m_ptr);
|
||||
}
|
||||
void internalGet(ref int data)
|
||||
{
|
||||
data = sfPacket_ReadInt32(m_ptr);
|
||||
}
|
||||
void internalGet(ref uint data)
|
||||
{
|
||||
data = sfPacket_ReadUint32(m_ptr);
|
||||
}
|
||||
void internalGet(ref float data)
|
||||
{
|
||||
data = sfPacket_ReadFloat(m_ptr);
|
||||
}
|
||||
void internalGet(ref double data)
|
||||
{
|
||||
data = sfPacket_ReadDouble(m_ptr);
|
||||
}
|
||||
void internalGet(ref string data)
|
||||
{
|
||||
scope string temp = new char[sfPacket_GetDataSize(m_ptr)];
|
||||
sfPacket_ReadString(m_ptr, temp.ptr);
|
||||
size_t l = fromStringz(temp.ptr).length;
|
||||
data = new char[l];
|
||||
data[] = temp[0 .. l];
|
||||
}
|
||||
|
||||
void internalGet(ref wstring data)
|
||||
{
|
||||
scope wstring temp = new wchar[sfPacket_GetDataSize(m_ptr)];
|
||||
sfPacket_ReadWideString(m_ptr, temp.ptr);
|
||||
size_t l = fromStringz(temp.ptr).length;
|
||||
data = new wchar[l];
|
||||
data[] = temp[0 .. l];
|
||||
}
|
||||
|
||||
void internalSet(bool data)
|
||||
{
|
||||
sfPacket_WriteInt32(m_ptr, cast(int)data);
|
||||
}
|
||||
void internalSet(byte data)
|
||||
{
|
||||
sfPacket_WriteInt8(m_ptr, data);
|
||||
}
|
||||
void internalSet(ubyte data)
|
||||
{
|
||||
sfPacket_WriteUint8(m_ptr, data);
|
||||
}
|
||||
void internalSet(short data)
|
||||
{
|
||||
sfPacket_WriteInt16(m_ptr, data);
|
||||
}
|
||||
void internalSet(ushort data)
|
||||
{
|
||||
sfPacket_WriteUint16(m_ptr, data);
|
||||
}
|
||||
void internalSet(int data)
|
||||
{
|
||||
sfPacket_WriteInt32(m_ptr, data);
|
||||
}
|
||||
void internalSet(uint data)
|
||||
{
|
||||
sfPacket_WriteUint32(m_ptr, data);
|
||||
}
|
||||
void internalSet(float data)
|
||||
{
|
||||
sfPacket_WriteFloat(m_ptr, data);
|
||||
}
|
||||
void internalSet(double data)
|
||||
{
|
||||
sfPacket_WriteDouble(m_ptr, data);
|
||||
}
|
||||
void internalSet(string data)
|
||||
{
|
||||
sfPacket_WriteString(m_ptr, toStringz(data));
|
||||
}
|
||||
|
||||
void internalSet(wstring data)
|
||||
{
|
||||
sfPacket_WriteWideString(m_ptr, toStringz(data));
|
||||
}
|
||||
void internalSet(wstring data)
|
||||
{
|
||||
sfPacket_WriteWideString(m_ptr, toStringz(data));
|
||||
}
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfPacket_Create;
|
||||
typedef void function(void*) pf_sfPacket_Destroy;
|
||||
typedef void function(void*, void*, size_t) pf_sfPacket_Append;
|
||||
typedef void function(void*) pf_sfPacket_Clear;
|
||||
typedef byte* function(void*) pf_sfPacket_GetData;
|
||||
typedef uint function(void*) pf_sfPacket_GetDataSize;
|
||||
typedef int function(void*) pf_sfPacket_EndOfPacket;
|
||||
typedef int function(void*) pf_sfPacket_CanRead;
|
||||
typedef byte function(void*) pf_sfPacket_ReadInt8;
|
||||
typedef ubyte function(void*) pf_sfPacket_ReadUint8;
|
||||
typedef short function(void*) pf_sfPacket_ReadInt16;
|
||||
typedef ushort function(void*) pf_sfPacket_ReadUint16;
|
||||
typedef int function(void*) pf_sfPacket_ReadInt32;
|
||||
typedef uint function(void*) pf_sfPacket_ReadUint32;
|
||||
typedef float function(void*) pf_sfPacket_ReadFloat;
|
||||
typedef double function(void*) pf_sfPacket_ReadDouble;
|
||||
typedef void function(void*, char*) pf_sfPacket_ReadString;
|
||||
typedef void function(void*, wchar*) pf_sfPacket_ReadWideString;
|
||||
typedef void function(void*, byte) pf_sfPacket_WriteInt8;
|
||||
typedef void function(void*, ubyte) pf_sfPacket_WriteUint8;
|
||||
typedef void function(void*, short) pf_sfPacket_WriteInt16;
|
||||
typedef void function(void*, ushort) pf_sfPacket_WriteUint16;
|
||||
typedef void function(void*, int) pf_sfPacket_WriteInt32;
|
||||
typedef void function(void*, uint) pf_sfPacket_WriteUint32;
|
||||
typedef void function(void*, float) pf_sfPacket_WriteFloat;
|
||||
typedef void function(void*, double) pf_sfPacket_WriteDouble;
|
||||
typedef void function(void*, char*) pf_sfPacket_WriteString;
|
||||
typedef void function(void*, wchar*) pf_sfPacket_WriteWideString;
|
||||
|
||||
static pf_sfPacket_Create sfPacket_Create;
|
||||
static pf_sfPacket_Destroy sfPacket_Destroy;
|
||||
static pf_sfPacket_Append sfPacket_Append;
|
||||
static pf_sfPacket_Clear sfPacket_Clear;
|
||||
static pf_sfPacket_GetData sfPacket_GetData;
|
||||
static pf_sfPacket_GetDataSize sfPacket_GetDataSize;
|
||||
static pf_sfPacket_EndOfPacket sfPacket_EndOfPacket;
|
||||
static pf_sfPacket_CanRead sfPacket_CanRead;
|
||||
static pf_sfPacket_ReadInt8 sfPacket_ReadInt8;
|
||||
static pf_sfPacket_ReadUint8 sfPacket_ReadUint8;
|
||||
static pf_sfPacket_ReadInt16 sfPacket_ReadInt16;
|
||||
static pf_sfPacket_ReadUint16 sfPacket_ReadUint16;
|
||||
static pf_sfPacket_ReadInt32 sfPacket_ReadInt32;
|
||||
static pf_sfPacket_ReadUint32 sfPacket_ReadUint32;
|
||||
static pf_sfPacket_ReadFloat sfPacket_ReadFloat;
|
||||
static pf_sfPacket_ReadDouble sfPacket_ReadDouble;
|
||||
static pf_sfPacket_ReadString sfPacket_ReadString;
|
||||
static pf_sfPacket_ReadWideString sfPacket_ReadWideString;
|
||||
static pf_sfPacket_WriteInt8 sfPacket_WriteInt8;
|
||||
static pf_sfPacket_WriteUint8 sfPacket_WriteUint8;
|
||||
static pf_sfPacket_WriteInt16 sfPacket_WriteInt16;
|
||||
static pf_sfPacket_WriteUint16 sfPacket_WriteUint16;
|
||||
static pf_sfPacket_WriteInt32 sfPacket_WriteInt32;
|
||||
static pf_sfPacket_WriteUint32 sfPacket_WriteUint32;
|
||||
static pf_sfPacket_WriteFloat sfPacket_WriteFloat;
|
||||
static pf_sfPacket_WriteDouble sfPacket_WriteDouble;
|
||||
static pf_sfPacket_WriteString sfPacket_WriteString;
|
||||
static pf_sfPacket_WriteWideString sfPacket_WriteWideString;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfPacket_Create;
|
||||
typedef void function(void*) pf_sfPacket_Destroy;
|
||||
typedef void function(void*, void*, size_t) pf_sfPacket_Append;
|
||||
typedef void function(void*) pf_sfPacket_Clear;
|
||||
typedef byte* function(void*) pf_sfPacket_GetData;
|
||||
typedef uint function(void*) pf_sfPacket_GetDataSize;
|
||||
typedef int function(void*) pf_sfPacket_EndOfPacket;
|
||||
typedef int function(void*) pf_sfPacket_CanRead;
|
||||
typedef byte function(void*) pf_sfPacket_ReadInt8;
|
||||
typedef ubyte function(void*) pf_sfPacket_ReadUint8;
|
||||
typedef short function(void*) pf_sfPacket_ReadInt16;
|
||||
typedef ushort function(void*) pf_sfPacket_ReadUint16;
|
||||
typedef int function(void*) pf_sfPacket_ReadInt32;
|
||||
typedef uint function(void*) pf_sfPacket_ReadUint32;
|
||||
typedef float function(void*) pf_sfPacket_ReadFloat;
|
||||
typedef double function(void*) pf_sfPacket_ReadDouble;
|
||||
typedef void function(void*, char*) pf_sfPacket_ReadString;
|
||||
typedef void function(void*, wchar*) pf_sfPacket_ReadWideString;
|
||||
typedef void function(void*, byte) pf_sfPacket_WriteInt8;
|
||||
typedef void function(void*, ubyte) pf_sfPacket_WriteUint8;
|
||||
typedef void function(void*, short) pf_sfPacket_WriteInt16;
|
||||
typedef void function(void*, ushort) pf_sfPacket_WriteUint16;
|
||||
typedef void function(void*, int) pf_sfPacket_WriteInt32;
|
||||
typedef void function(void*, uint) pf_sfPacket_WriteUint32;
|
||||
typedef void function(void*, float) pf_sfPacket_WriteFloat;
|
||||
typedef void function(void*, double) pf_sfPacket_WriteDouble;
|
||||
typedef void function(void*, char*) pf_sfPacket_WriteString;
|
||||
typedef void function(void*, wchar*) pf_sfPacket_WriteWideString;
|
||||
|
||||
static pf_sfPacket_Create sfPacket_Create;
|
||||
static pf_sfPacket_Destroy sfPacket_Destroy;
|
||||
static pf_sfPacket_Append sfPacket_Append;
|
||||
static pf_sfPacket_Clear sfPacket_Clear;
|
||||
static pf_sfPacket_GetData sfPacket_GetData;
|
||||
static pf_sfPacket_GetDataSize sfPacket_GetDataSize;
|
||||
static pf_sfPacket_EndOfPacket sfPacket_EndOfPacket;
|
||||
static pf_sfPacket_CanRead sfPacket_CanRead;
|
||||
static pf_sfPacket_ReadInt8 sfPacket_ReadInt8;
|
||||
static pf_sfPacket_ReadUint8 sfPacket_ReadUint8;
|
||||
static pf_sfPacket_ReadInt16 sfPacket_ReadInt16;
|
||||
static pf_sfPacket_ReadUint16 sfPacket_ReadUint16;
|
||||
static pf_sfPacket_ReadInt32 sfPacket_ReadInt32;
|
||||
static pf_sfPacket_ReadUint32 sfPacket_ReadUint32;
|
||||
static pf_sfPacket_ReadFloat sfPacket_ReadFloat;
|
||||
static pf_sfPacket_ReadDouble sfPacket_ReadDouble;
|
||||
static pf_sfPacket_ReadString sfPacket_ReadString;
|
||||
static pf_sfPacket_ReadWideString sfPacket_ReadWideString;
|
||||
static pf_sfPacket_WriteInt8 sfPacket_WriteInt8;
|
||||
static pf_sfPacket_WriteUint8 sfPacket_WriteUint8;
|
||||
static pf_sfPacket_WriteInt16 sfPacket_WriteInt16;
|
||||
static pf_sfPacket_WriteUint16 sfPacket_WriteUint16;
|
||||
static pf_sfPacket_WriteInt32 sfPacket_WriteInt32;
|
||||
static pf_sfPacket_WriteUint32 sfPacket_WriteUint32;
|
||||
static pf_sfPacket_WriteFloat sfPacket_WriteFloat;
|
||||
static pf_sfPacket_WriteDouble sfPacket_WriteDouble;
|
||||
static pf_sfPacket_WriteString sfPacket_WriteString;
|
||||
static pf_sfPacket_WriteWideString sfPacket_WriteWideString;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfPacket_Append = cast(pf_sfPacket_Append)dll.getSymbol("sfPacket_Append");
|
||||
sfPacket_CanRead = cast(pf_sfPacket_CanRead)dll.getSymbol("sfPacket_CanRead");
|
||||
sfPacket_Clear = cast(pf_sfPacket_Clear)dll.getSymbol("sfPacket_Clear");
|
||||
sfPacket_Create = cast(pf_sfPacket_Create)dll.getSymbol("sfPacket_Create");
|
||||
sfPacket_Destroy = cast(pf_sfPacket_Destroy)dll.getSymbol("sfPacket_Destroy");
|
||||
sfPacket_EndOfPacket = cast(pf_sfPacket_EndOfPacket)dll.getSymbol("sfPacket_EndOfPacket");
|
||||
sfPacket_GetData = cast(pf_sfPacket_GetData)dll.getSymbol("sfPacket_GetData");
|
||||
sfPacket_GetDataSize = cast(pf_sfPacket_GetDataSize)dll.getSymbol("sfPacket_GetDataSize");
|
||||
sfPacket_ReadDouble = cast(pf_sfPacket_ReadDouble)dll.getSymbol("sfPacket_ReadDouble");
|
||||
sfPacket_ReadFloat = cast(pf_sfPacket_ReadFloat)dll.getSymbol("sfPacket_ReadFloat");
|
||||
sfPacket_ReadInt16 = cast(pf_sfPacket_ReadInt16)dll.getSymbol("sfPacket_ReadInt16");
|
||||
sfPacket_ReadInt32 = cast(pf_sfPacket_ReadInt32)dll.getSymbol("sfPacket_ReadInt32");
|
||||
sfPacket_ReadInt8 = cast(pf_sfPacket_ReadInt8)dll.getSymbol("sfPacket_ReadInt8");
|
||||
sfPacket_ReadString = cast(pf_sfPacket_ReadString)dll.getSymbol("sfPacket_ReadString");
|
||||
sfPacket_ReadWideString = cast(pf_sfPacket_ReadWideString)dll.getSymbol("sfPacket_ReadWideString");
|
||||
sfPacket_ReadUint16 = cast(pf_sfPacket_ReadUint16)dll.getSymbol("sfPacket_ReadUint16");
|
||||
sfPacket_ReadUint32 = cast(pf_sfPacket_ReadUint32)dll.getSymbol("sfPacket_ReadUint32");
|
||||
sfPacket_ReadUint8 = cast(pf_sfPacket_ReadUint8)dll.getSymbol("sfPacket_ReadUint8");
|
||||
sfPacket_WriteDouble = cast(pf_sfPacket_WriteDouble)dll.getSymbol("sfPacket_WriteDouble");
|
||||
sfPacket_WriteFloat = cast(pf_sfPacket_WriteFloat)dll.getSymbol("sfPacket_WriteFloat");
|
||||
sfPacket_WriteInt16 = cast(pf_sfPacket_WriteInt16)dll.getSymbol("sfPacket_WriteInt16");
|
||||
sfPacket_WriteInt32 = cast(pf_sfPacket_WriteInt32)dll.getSymbol("sfPacket_WriteInt32");
|
||||
sfPacket_WriteInt8 = cast(pf_sfPacket_WriteInt8)dll.getSymbol("sfPacket_WriteInt8");
|
||||
sfPacket_WriteString = cast(pf_sfPacket_WriteString)dll.getSymbol("sfPacket_WriteString");
|
||||
sfPacket_WriteWideString = cast(pf_sfPacket_WriteWideString)dll.getSymbol("sfPacket_WriteWideString");
|
||||
sfPacket_WriteUint16 = cast(pf_sfPacket_WriteUint16)dll.getSymbol("sfPacket_WriteUint16");
|
||||
sfPacket_WriteUint32 = cast(pf_sfPacket_WriteUint32)dll.getSymbol("sfPacket_WriteUint32");
|
||||
sfPacket_WriteUint8 = cast(pf_sfPacket_WriteUint8)dll.getSymbol("sfPacket_WriteUint8");
|
||||
}
|
||||
|
||||
sfPacket_Append = cast(pf_sfPacket_Append)dll.getSymbol("sfPacket_Append");
|
||||
sfPacket_CanRead = cast(pf_sfPacket_CanRead)dll.getSymbol("sfPacket_CanRead");
|
||||
sfPacket_Clear = cast(pf_sfPacket_Clear)dll.getSymbol("sfPacket_Clear");
|
||||
sfPacket_Create = cast(pf_sfPacket_Create)dll.getSymbol("sfPacket_Create");
|
||||
sfPacket_Destroy = cast(pf_sfPacket_Destroy)dll.getSymbol("sfPacket_Destroy");
|
||||
sfPacket_EndOfPacket = cast(pf_sfPacket_EndOfPacket)dll.getSymbol("sfPacket_EndOfPacket");
|
||||
sfPacket_GetData = cast(pf_sfPacket_GetData)dll.getSymbol("sfPacket_GetData");
|
||||
sfPacket_GetDataSize = cast(pf_sfPacket_GetDataSize)dll.getSymbol("sfPacket_GetDataSize");
|
||||
sfPacket_ReadDouble = cast(pf_sfPacket_ReadDouble)dll.getSymbol("sfPacket_ReadDouble");
|
||||
sfPacket_ReadFloat = cast(pf_sfPacket_ReadFloat)dll.getSymbol("sfPacket_ReadFloat");
|
||||
sfPacket_ReadInt16 = cast(pf_sfPacket_ReadInt16)dll.getSymbol("sfPacket_ReadInt16");
|
||||
sfPacket_ReadInt32 = cast(pf_sfPacket_ReadInt32)dll.getSymbol("sfPacket_ReadInt32");
|
||||
sfPacket_ReadInt8 = cast(pf_sfPacket_ReadInt8)dll.getSymbol("sfPacket_ReadInt8");
|
||||
sfPacket_ReadString = cast(pf_sfPacket_ReadString)dll.getSymbol("sfPacket_ReadString");
|
||||
sfPacket_ReadWideString = cast(pf_sfPacket_ReadWideString)dll.getSymbol("sfPacket_ReadWideString");
|
||||
sfPacket_ReadUint16 = cast(pf_sfPacket_ReadUint16)dll.getSymbol("sfPacket_ReadUint16");
|
||||
sfPacket_ReadUint32 = cast(pf_sfPacket_ReadUint32)dll.getSymbol("sfPacket_ReadUint32");
|
||||
sfPacket_ReadUint8 = cast(pf_sfPacket_ReadUint8)dll.getSymbol("sfPacket_ReadUint8");
|
||||
sfPacket_WriteDouble = cast(pf_sfPacket_WriteDouble)dll.getSymbol("sfPacket_WriteDouble");
|
||||
sfPacket_WriteFloat = cast(pf_sfPacket_WriteFloat)dll.getSymbol("sfPacket_WriteFloat");
|
||||
sfPacket_WriteInt16 = cast(pf_sfPacket_WriteInt16)dll.getSymbol("sfPacket_WriteInt16");
|
||||
sfPacket_WriteInt32 = cast(pf_sfPacket_WriteInt32)dll.getSymbol("sfPacket_WriteInt32");
|
||||
sfPacket_WriteInt8 = cast(pf_sfPacket_WriteInt8)dll.getSymbol("sfPacket_WriteInt8");
|
||||
sfPacket_WriteString = cast(pf_sfPacket_WriteString)dll.getSymbol("sfPacket_WriteString");
|
||||
sfPacket_WriteWideString = cast(pf_sfPacket_WriteWideString)dll.getSymbol("sfPacket_WriteWideString");
|
||||
sfPacket_WriteUint16 = cast(pf_sfPacket_WriteUint16)dll.getSymbol("sfPacket_WriteUint16");
|
||||
sfPacket_WriteUint32 = cast(pf_sfPacket_WriteUint32)dll.getSymbol("sfPacket_WriteUint32");
|
||||
sfPacket_WriteUint8 = cast(pf_sfPacket_WriteUint8)dll.getSymbol("sfPacket_WriteUint8");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.selector;
|
||||
|
@ -38,152 +38,152 @@ import dsfml.system.common;
|
|||
*/
|
||||
class Selector(T) : DSFMLObject
|
||||
{
|
||||
//Ensure type is correct
|
||||
static if (!is(T : SocketTCP) && !is(T : SocketUDP))
|
||||
static assert("Only SocketTCP and SocketUDP are valid for Selector.");
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSelector_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSelector_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a socket to watch
|
||||
*
|
||||
* Params:
|
||||
* socket = A tcp or udp socket
|
||||
*/
|
||||
void add(T socket)
|
||||
{
|
||||
if (!(socket.getNativePointer in m_watchedSockets))
|
||||
{
|
||||
sfSelector_Add(m_ptr, socket.getNativePointer);
|
||||
m_watchedSockets[socket.getNativePointer] = socket;
|
||||
m_numSocketsWatched++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a previously added socket
|
||||
*
|
||||
* Params:
|
||||
* socket = A tcp or udp socket
|
||||
*/
|
||||
void remove(T socket)
|
||||
{
|
||||
if (socket.getNativePointer in m_watchedSockets)
|
||||
{
|
||||
sfSelector_Remove(m_ptr, socket.getNativePointer);
|
||||
m_watchedSockets.remove(socket.getNativePointer);
|
||||
m_numSocketsWatched--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all sockets being watched
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
sfSelector_Clear(m_ptr);
|
||||
foreach(key; m_watchedSockets.keys)
|
||||
m_watchedSockets.remove(key);
|
||||
m_numSocketsWatched = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait and collect sockets which are ready for reading.
|
||||
* This functions will return either when at least one socket
|
||||
* is ready, or when the given time is out
|
||||
*
|
||||
* Params:
|
||||
* timeout = Maximum time to wait, in seconds (0 to disable timeout)
|
||||
*
|
||||
* Returns:
|
||||
* Number of sockets ready
|
||||
*/
|
||||
uint wait(float timeout = 0.f)
|
||||
{
|
||||
return sfSelector_Wait(m_ptr, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* After a call to Wait(), get the Index-th socket which is
|
||||
* ready for reading. The total number of sockets ready
|
||||
* is the integer returned by the previous call to Wait()
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the socket to get
|
||||
*
|
||||
* Returns:
|
||||
* The Index-th socket
|
||||
*/
|
||||
T GetSocketsReady(uint index)
|
||||
{
|
||||
return m_watchedSockets[sfSelector_GetSocketReady(m_ptr, index)];
|
||||
}
|
||||
|
||||
//Ensure type is correct
|
||||
static if (!is(T : SocketTCP) && !is(T : SocketUDP))
|
||||
static assert("Only SocketTCP and SocketUDP are valid for Selector.");
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSelector_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSelector_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a socket to watch
|
||||
*
|
||||
* Params:
|
||||
* socket = A tcp or udp socket
|
||||
*/
|
||||
void add(T socket)
|
||||
{
|
||||
if (!(socket.getNativePointer in m_watchedSockets))
|
||||
{
|
||||
sfSelector_Add(m_ptr, socket.getNativePointer);
|
||||
m_watchedSockets[socket.getNativePointer] = socket;
|
||||
m_numSocketsWatched++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a previously added socket
|
||||
*
|
||||
* Params:
|
||||
* socket = A tcp or udp socket
|
||||
*/
|
||||
void remove(T socket)
|
||||
{
|
||||
if (socket.getNativePointer in m_watchedSockets)
|
||||
{
|
||||
sfSelector_Remove(m_ptr, socket.getNativePointer);
|
||||
m_watchedSockets.remove(socket.getNativePointer);
|
||||
m_numSocketsWatched--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all sockets being watched
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
sfSelector_Clear(m_ptr);
|
||||
foreach(key; m_watchedSockets.keys)
|
||||
m_watchedSockets.remove(key);
|
||||
m_numSocketsWatched = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait and collect sockets which are ready for reading.
|
||||
* This functions will return either when at least one socket
|
||||
* is ready, or when the given time is out
|
||||
*
|
||||
* Params:
|
||||
* timeout = Maximum time to wait, in seconds (0 to disable timeout)
|
||||
*
|
||||
* Returns:
|
||||
* Number of sockets ready
|
||||
*/
|
||||
uint wait(float timeout = 0.f)
|
||||
{
|
||||
return sfSelector_Wait(m_ptr, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* After a call to Wait(), get the Index-th socket which is
|
||||
* ready for reading. The total number of sockets ready
|
||||
* is the integer returned by the previous call to Wait()
|
||||
*
|
||||
* Params:
|
||||
* index = Index of the socket to get
|
||||
*
|
||||
* Returns:
|
||||
* The Index-th socket
|
||||
*/
|
||||
T GetSocketsReady(uint index)
|
||||
{
|
||||
return m_watchedSockets[sfSelector_GetSocketReady(m_ptr, index)];
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
size_t m_numSocketsWatched;
|
||||
T[void*] m_watchedSockets;
|
||||
|
||||
size_t m_numSocketsWatched;
|
||||
T[void*] m_watchedSockets;
|
||||
|
||||
// External ====================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSelector_Create;
|
||||
typedef void function(void*) pf_sfSelector_Destroy;
|
||||
typedef void function(void*, void*) pf_sfSelector_Add;
|
||||
typedef void function(void*, void*) pf_sfSelector_Remove;
|
||||
typedef void function(void*) pf_sfSelector_Clear;
|
||||
typedef uint function(void*, float) pf_sfSelector_Wait;
|
||||
typedef void* function(void*, uint) pf_sfSelector_GetSocketReady;
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSelector_Create;
|
||||
typedef void function(void*) pf_sfSelector_Destroy;
|
||||
typedef void function(void*, void*) pf_sfSelector_Add;
|
||||
typedef void function(void*, void*) pf_sfSelector_Remove;
|
||||
typedef void function(void*) pf_sfSelector_Clear;
|
||||
typedef uint function(void*, float) pf_sfSelector_Wait;
|
||||
typedef void* function(void*, uint) pf_sfSelector_GetSocketReady;
|
||||
|
||||
static pf_sfSelector_Create sfSelector_Create;
|
||||
static pf_sfSelector_Destroy sfSelector_Destroy;
|
||||
static pf_sfSelector_Add sfSelector_Add;
|
||||
static pf_sfSelector_Remove sfSelector_Remove;
|
||||
static pf_sfSelector_Clear sfSelector_Clear;
|
||||
static pf_sfSelector_Wait sfSelector_Wait;
|
||||
static pf_sfSelector_GetSocketReady sfSelector_GetSocketReady;
|
||||
}
|
||||
static pf_sfSelector_Create sfSelector_Create;
|
||||
static pf_sfSelector_Destroy sfSelector_Destroy;
|
||||
static pf_sfSelector_Add sfSelector_Add;
|
||||
static pf_sfSelector_Remove sfSelector_Remove;
|
||||
static pf_sfSelector_Clear sfSelector_Clear;
|
||||
static pf_sfSelector_Wait sfSelector_Wait;
|
||||
static pf_sfSelector_GetSocketReady sfSelector_GetSocketReady;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
static if (is (T : SocketTCP))
|
||||
{
|
||||
string symbol = "sfSelectorTCP";
|
||||
}
|
||||
else static if (is (T : SocketUDP))
|
||||
{
|
||||
string symbol = "sfSelectorUDP";
|
||||
}
|
||||
|
||||
sfSelector_Add = cast(pf_sfSelector_Add)dll.getSymbol(symbol ~ "_Add");
|
||||
sfSelector_Clear = cast(pf_sfSelector_Clear)dll.getSymbol(symbol ~ "_Clear");
|
||||
sfSelector_Create = cast(pf_sfSelector_Create)dll.getSymbol(symbol ~ "_Create");
|
||||
sfSelector_Destroy = cast(pf_sfSelector_Destroy)dll.getSymbol(symbol ~ "_Destroy");
|
||||
sfSelector_GetSocketReady = cast(pf_sfSelector_GetSocketReady)dll.getSymbol(symbol ~ "_GetSocketReady");
|
||||
sfSelector_Wait = cast(pf_sfSelector_Wait)dll.getSymbol(symbol ~ "_Wait");
|
||||
sfSelector_Remove = cast(pf_sfSelector_Remove)dll.getSymbol(symbol ~ "_Remove");
|
||||
}
|
||||
|
||||
static if (is (T : SocketTCP))
|
||||
{
|
||||
string symbol = "sfSelectorTCP";
|
||||
}
|
||||
else static if (is (T : SocketUDP))
|
||||
{
|
||||
string symbol = "sfSelectorUDP";
|
||||
}
|
||||
|
||||
sfSelector_Add = cast(pf_sfSelector_Add)dll.getSymbol(symbol ~ "_Add");
|
||||
sfSelector_Clear = cast(pf_sfSelector_Clear)dll.getSymbol(symbol ~ "_Clear");
|
||||
sfSelector_Create = cast(pf_sfSelector_Create)dll.getSymbol(symbol ~ "_Create");
|
||||
sfSelector_Destroy = cast(pf_sfSelector_Destroy)dll.getSymbol(symbol ~ "_Destroy");
|
||||
sfSelector_GetSocketReady = cast(pf_sfSelector_GetSocketReady)dll.getSymbol(symbol ~ "_GetSocketReady");
|
||||
sfSelector_Wait = cast(pf_sfSelector_Wait)dll.getSymbol(symbol ~ "_Wait");
|
||||
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;
|
||||
/// ditto
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.socketstatus;
|
||||
|
||||
/**
|
||||
* Enumeration of status returned by socket functions
|
||||
* Enumeration of status returned by socket functions
|
||||
*/
|
||||
enum SocketStatus
|
||||
{
|
||||
DONE, ///
|
||||
NOTREADY, ///
|
||||
DONE, ///
|
||||
NOTREADY, ///
|
||||
DISCONNECTED, ///
|
||||
UNEXPECTEDERROR ///
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.sockettcp;
|
||||
|
@ -33,240 +33,240 @@ import dsfml.network.socketstatus;
|
|||
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
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSocketTCP_Create());
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSocketTCP_Create());
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSocketTCP_Destroy(m_ptr);
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
sfSocketTCP_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to another computer on a specified port
|
||||
*
|
||||
* Params:
|
||||
* port = Port to use for transfers (warning : ports < 1024 are reserved)
|
||||
* hostAddress = IP Address of the host to connect to
|
||||
* timeout = Maximum time to wait in seconds (0 by default : no timeout)
|
||||
*
|
||||
* Returns:
|
||||
* True if operation has been successful
|
||||
*/
|
||||
bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f)
|
||||
{
|
||||
return cast(bool) !sfSocketTCP_Connect(m_ptr, port, hostAddress, timeout);
|
||||
}
|
||||
/**
|
||||
* Connect to another computer on a specified port
|
||||
*
|
||||
* Params:
|
||||
* port = Port to use for transfers (warning : ports < 1024 are reserved)
|
||||
* hostAddress = IP Address of the host to connect to
|
||||
* timeout = Maximum time to wait in seconds (0 by default : no timeout)
|
||||
*
|
||||
* Returns:
|
||||
* True if operation has been successful
|
||||
*/
|
||||
bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f)
|
||||
{
|
||||
return cast(bool) !sfSocketTCP_Connect(m_ptr, port, hostAddress, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to a specified port for incoming data or connections
|
||||
*
|
||||
* Params:
|
||||
* port = Port to listen to
|
||||
*
|
||||
* Returns:
|
||||
* True if operation has been successful
|
||||
*/
|
||||
bool listen(ushort port)
|
||||
{
|
||||
return cast(bool)sfSocketTCP_Listen(m_ptr, port);
|
||||
}
|
||||
/**
|
||||
* Listen to a specified port for incoming data or connections
|
||||
*
|
||||
* Params:
|
||||
* port = Port to listen to
|
||||
*
|
||||
* Returns:
|
||||
* True if operation has been successful
|
||||
*/
|
||||
bool listen(ushort port)
|
||||
{
|
||||
return cast(bool)sfSocketTCP_Listen(m_ptr, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a connection (must be listening to a port).
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* connected = Socket containing the connection with the connected client
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus accept(SocketTCP connected)
|
||||
{
|
||||
void* temp = null;
|
||||
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, null);
|
||||
connected.m_ptr = temp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a connection (must be listening to a port).
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* connected = Socket containing the connection with the connected client
|
||||
* address = Pointer to an address to fill with client infos
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus accept(SocketTCP connected, out IPAddress address)
|
||||
{
|
||||
void* temp = null;
|
||||
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, &address);
|
||||
connected.m_ptr = temp;
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Wait for a connection (must be listening to a port).
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* connected = Socket containing the connection with the connected client
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus accept(SocketTCP connected)
|
||||
{
|
||||
void* temp = null;
|
||||
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, null);
|
||||
connected.m_ptr = temp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a connection (must be listening to a port).
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* connected = Socket containing the connection with the connected client
|
||||
* address = Pointer to an address to fill with client infos
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus accept(SocketTCP connected, out IPAddress address)
|
||||
{
|
||||
void* temp = null;
|
||||
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, &address);
|
||||
connected.m_ptr = temp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an array of bytes to the host (must be connected first)
|
||||
*
|
||||
* Params:
|
||||
* data = array of bytes to send
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus send(byte[] data)
|
||||
{
|
||||
if (data && data.length > 0)
|
||||
return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length);
|
||||
}
|
||||
/**
|
||||
* Send an array of bytes to the host (must be connected first)
|
||||
*
|
||||
* Params:
|
||||
* data = array of bytes to send
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus send(byte[] data)
|
||||
{
|
||||
if (data && data.length > 0)
|
||||
return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive an array of bytes from the host (must be connected first).
|
||||
* This function will block until a connection was accepted
|
||||
*
|
||||
* Params:
|
||||
* data = array to fill (make sure it is big enough)
|
||||
* sizeReceived = Number of bytes received
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
* Remarks:
|
||||
* Assert if data is null or length == 0
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(byte[] data, out size_t sizeReceived)
|
||||
{
|
||||
if (data && data.length > 0)
|
||||
return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
|
||||
}
|
||||
/**
|
||||
* Receive an array of bytes from the host (must be connected first).
|
||||
* This function will block until a connection was accepted
|
||||
*
|
||||
* Params:
|
||||
* data = array to fill (make sure it is big enough)
|
||||
* sizeReceived = Number of bytes received
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
* Remarks:
|
||||
* Assert if data is null or length == 0
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(byte[] data, out size_t sizeReceived)
|
||||
{
|
||||
if (data && data.length > 0)
|
||||
return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a packet of data to the host (must be connected first)
|
||||
*
|
||||
* Params:
|
||||
* packetToSend = Packet to send
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus send(Packet packetToSend)
|
||||
{
|
||||
byte[] dataArray = packetToSend.onSend();
|
||||
m_intermediatePacket.append(dataArray);
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketTCP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
/**
|
||||
* Send a packet of data to the host (must be connected first)
|
||||
*
|
||||
* Params:
|
||||
* packetToSend = Packet to send
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus send(Packet packetToSend)
|
||||
{
|
||||
byte[] dataArray = packetToSend.onSend();
|
||||
m_intermediatePacket.append(dataArray);
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketTCP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a packet from the host (must be connected first).
|
||||
* This function will block if the socket is blocking
|
||||
*
|
||||
* Params:
|
||||
* packetToReceive = Packet to fill with received data
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(Packet packetToReceive)
|
||||
{
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketTCP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer);
|
||||
packetToReceive.onReceive(m_intermediatePacket.getData);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
/**
|
||||
* Receive a packet from the host (must be connected first).
|
||||
* This function will block if the socket is blocking
|
||||
*
|
||||
* Params:
|
||||
* packetToReceive = Packet to fill with received data
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(Packet packetToReceive)
|
||||
{
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketTCP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer);
|
||||
packetToReceive.onReceive(m_intermediatePacket.getData);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the socket is in a valid state ; this function
|
||||
* can be called any time to check if the socket is OK
|
||||
*
|
||||
* Returns:
|
||||
* True if the socket is valid
|
||||
*
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfSocketTCP_IsValid(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Check if the socket is in a valid state ; this function
|
||||
* can be called any time to check if the socket is OK
|
||||
*
|
||||
* Returns:
|
||||
* True if the socket is valid
|
||||
*
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfSocketTCP_IsValid(m_ptr);
|
||||
}
|
||||
|
||||
///
|
||||
bool opEquals(SocketTCP other)
|
||||
{
|
||||
return (other.getNativePointer == this.getNativePointer);
|
||||
}
|
||||
///
|
||||
bool opEquals(SocketTCP other)
|
||||
{
|
||||
return (other.getNativePointer == this.getNativePointer);
|
||||
}
|
||||
|
||||
|
||||
package:
|
||||
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Packet m_intermediatePacket;
|
||||
Packet m_intermediatePacket;
|
||||
|
||||
// External ====================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSocketTCP_Create;
|
||||
typedef void function(void*) pf_sfSocketTCP_Destroy;
|
||||
typedef int function(void*, ushort, IPAddress, float) pf_sfSocketTCP_Connect;
|
||||
typedef int function(void*, ushort) pf_sfSocketTCP_Listen;
|
||||
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, size_t*) pf_sfSocketTCP_Receive;
|
||||
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_SendPacket;
|
||||
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_ReceivePacket;
|
||||
typedef int function(void*) pf_sfSocketTCP_IsValid;
|
||||
|
||||
static pf_sfSocketTCP_Create sfSocketTCP_Create;
|
||||
static pf_sfSocketTCP_Destroy sfSocketTCP_Destroy;
|
||||
static pf_sfSocketTCP_Connect sfSocketTCP_Connect;
|
||||
static pf_sfSocketTCP_Listen sfSocketTCP_Listen;
|
||||
static pf_sfSocketTCP_Accept sfSocketTCP_Accept;
|
||||
static pf_sfSocketTCP_Send sfSocketTCP_Send;
|
||||
static pf_sfSocketTCP_Receive sfSocketTCP_Receive;
|
||||
static pf_sfSocketTCP_SendPacket sfSocketTCP_SendPacket;
|
||||
static pf_sfSocketTCP_ReceivePacket sfSocketTCP_ReceivePacket;
|
||||
static pf_sfSocketTCP_IsValid sfSocketTCP_IsValid;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSocketTCP_Create;
|
||||
typedef void function(void*) pf_sfSocketTCP_Destroy;
|
||||
typedef int function(void*, ushort, IPAddress, float) pf_sfSocketTCP_Connect;
|
||||
typedef int function(void*, ushort) pf_sfSocketTCP_Listen;
|
||||
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, size_t*) pf_sfSocketTCP_Receive;
|
||||
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_SendPacket;
|
||||
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_ReceivePacket;
|
||||
typedef int function(void*) pf_sfSocketTCP_IsValid;
|
||||
|
||||
static pf_sfSocketTCP_Create sfSocketTCP_Create;
|
||||
static pf_sfSocketTCP_Destroy sfSocketTCP_Destroy;
|
||||
static pf_sfSocketTCP_Connect sfSocketTCP_Connect;
|
||||
static pf_sfSocketTCP_Listen sfSocketTCP_Listen;
|
||||
static pf_sfSocketTCP_Accept sfSocketTCP_Accept;
|
||||
static pf_sfSocketTCP_Send sfSocketTCP_Send;
|
||||
static pf_sfSocketTCP_Receive sfSocketTCP_Receive;
|
||||
static pf_sfSocketTCP_SendPacket sfSocketTCP_SendPacket;
|
||||
static pf_sfSocketTCP_ReceivePacket sfSocketTCP_ReceivePacket;
|
||||
static pf_sfSocketTCP_IsValid sfSocketTCP_IsValid;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfSocketTCP_Accept = cast(pf_sfSocketTCP_Accept)dll.getSymbol("sfSocketTCP_Accept");
|
||||
sfSocketTCP_Connect = cast(pf_sfSocketTCP_Connect)dll.getSymbol("sfSocketTCP_Connect");
|
||||
sfSocketTCP_Create = cast(pf_sfSocketTCP_Create)dll.getSymbol("sfSocketTCP_Create");
|
||||
sfSocketTCP_Destroy = cast(pf_sfSocketTCP_Destroy)dll.getSymbol("sfSocketTCP_Destroy");
|
||||
sfSocketTCP_IsValid = cast(pf_sfSocketTCP_IsValid)dll.getSymbol("sfSocketTCP_IsValid");
|
||||
sfSocketTCP_Listen = cast(pf_sfSocketTCP_Listen)dll.getSymbol("sfSocketTCP_Listen");
|
||||
sfSocketTCP_Receive = cast(pf_sfSocketTCP_Receive)dll.getSymbol("sfSocketTCP_Receive");
|
||||
sfSocketTCP_ReceivePacket = cast(pf_sfSocketTCP_ReceivePacket)dll.getSymbol("sfSocketTCP_ReceivePacket");
|
||||
sfSocketTCP_Send = cast(pf_sfSocketTCP_Send)dll.getSymbol("sfSocketTCP_Send");
|
||||
sfSocketTCP_SendPacket = cast(pf_sfSocketTCP_SendPacket)dll.getSymbol("sfSocketTCP_SendPacket");
|
||||
}
|
||||
|
||||
sfSocketTCP_Accept = cast(pf_sfSocketTCP_Accept)dll.getSymbol("sfSocketTCP_Accept");
|
||||
sfSocketTCP_Connect = cast(pf_sfSocketTCP_Connect)dll.getSymbol("sfSocketTCP_Connect");
|
||||
sfSocketTCP_Create = cast(pf_sfSocketTCP_Create)dll.getSymbol("sfSocketTCP_Create");
|
||||
sfSocketTCP_Destroy = cast(pf_sfSocketTCP_Destroy)dll.getSymbol("sfSocketTCP_Destroy");
|
||||
sfSocketTCP_IsValid = cast(pf_sfSocketTCP_IsValid)dll.getSymbol("sfSocketTCP_IsValid");
|
||||
sfSocketTCP_Listen = cast(pf_sfSocketTCP_Listen)dll.getSymbol("sfSocketTCP_Listen");
|
||||
sfSocketTCP_Receive = cast(pf_sfSocketTCP_Receive)dll.getSymbol("sfSocketTCP_Receive");
|
||||
sfSocketTCP_ReceivePacket = cast(pf_sfSocketTCP_ReceivePacket)dll.getSymbol("sfSocketTCP_ReceivePacket");
|
||||
sfSocketTCP_Send = cast(pf_sfSocketTCP_Send)dll.getSymbol("sfSocketTCP_Send");
|
||||
sfSocketTCP_SendPacket = cast(pf_sfSocketTCP_SendPacket)dll.getSymbol("sfSocketTCP_SendPacket");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.socketudp;
|
||||
|
@ -33,126 +33,126 @@ import dsfml.network.socketstatus;
|
|||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* SocketUDP wraps a socket using UDP protocol to
|
||||
* send data fastly (but with less safety)
|
||||
* SocketUDP wraps a socket using UDP protocol to
|
||||
* send data fastly (but with less safety)
|
||||
*/
|
||||
class SocketUDP : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSocketUDP_Create());
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
override void dispose()
|
||||
{
|
||||
sfSocketUDP_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the socket to a specific port
|
||||
*
|
||||
* Params:
|
||||
* port = Port to bind the socket to
|
||||
*
|
||||
* Returns:
|
||||
* True if operation has been successful
|
||||
*
|
||||
*/
|
||||
bool bind(ushort port)
|
||||
/**
|
||||
* Bind the socket to a specific port
|
||||
*
|
||||
* Params:
|
||||
* port = Port to bind the socket to
|
||||
*
|
||||
* Returns:
|
||||
* True if operation has been successful
|
||||
*
|
||||
*/
|
||||
bool bind(ushort port)
|
||||
{
|
||||
m_port = port;
|
||||
return cast(bool)sfSocketUDP_Bind(m_ptr, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind the socket from its previous port, if any
|
||||
*
|
||||
* Returns: True if operation has been successful
|
||||
*
|
||||
*/
|
||||
bool unbind()
|
||||
/**
|
||||
* Unbind the socket from its previous port, if any
|
||||
*
|
||||
* Returns: True if operation has been successful
|
||||
*
|
||||
*/
|
||||
bool unbind()
|
||||
{
|
||||
m_port = 0;
|
||||
return cast(bool)sfSocketUDP_Unbind(m_ptr, m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an array of bytes
|
||||
*
|
||||
* Params:
|
||||
* data = bytes array to send
|
||||
* address = Address of the computer to send the packet to
|
||||
* port = Port to send the data to
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus send(byte[] data, IPAddress address, ushort port)
|
||||
/**
|
||||
* Send an array of bytes
|
||||
*
|
||||
* Params:
|
||||
* data = bytes array to send
|
||||
* address = Address of the computer to send the packet to
|
||||
* port = Port to send the data to
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus send(byte[] data, IPAddress address, ushort port)
|
||||
{
|
||||
return cast(SocketStatus) sfSocketUDP_Send(m_ptr, data.ptr, data.length, address, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive an array of bytes.
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* data = Pointer to a byte array to fill (make sure it is big enough)
|
||||
* sizeReceived = Number of bytes received
|
||||
* address = Address of the computer which sent the data
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
* Remarks:
|
||||
* Assert if data is null or length == 0
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address)
|
||||
/**
|
||||
* Receive an array of bytes.
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* data = Pointer to a byte array to fill (make sure it is big enough)
|
||||
* sizeReceived = Number of bytes received
|
||||
* address = Address of the computer which sent the data
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
* Remarks:
|
||||
* Assert if data is null or length == 0
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address)
|
||||
{
|
||||
SocketStatus ret = sfSocketUDP_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet of data
|
||||
*
|
||||
* Params:
|
||||
* packetToSend = Packet to send
|
||||
* address = Address of the computer to send the packet to
|
||||
* port = Port to send the data to
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus send(Packet packetToSend, IPAddress address, ushort port)
|
||||
/**
|
||||
* Send a packet of data
|
||||
*
|
||||
* Params:
|
||||
* packetToSend = Packet to send
|
||||
* address = Address of the computer to send the packet to
|
||||
* port = Port to send the data to
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus send(Packet packetToSend, IPAddress address, ushort port)
|
||||
{
|
||||
byte[] dataArray = packetToSend.onSend();
|
||||
m_intermediatePacket.append(dataArray);
|
||||
byte[] dataArray = packetToSend.onSend();
|
||||
m_intermediatePacket.append(dataArray);
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketUDP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer, address, port);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive a packet.
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* packetToReceive = Packet to fill with received data
|
||||
* address = Address of the computer which sent the packet
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(Packet packetToReceive, out IPAddress address)
|
||||
/**
|
||||
* Receive a packet.
|
||||
* This function is blocking.
|
||||
*
|
||||
* Params:
|
||||
* packetToReceive = Packet to fill with received data
|
||||
* address = Address of the computer which sent the packet
|
||||
*
|
||||
* Returns:
|
||||
* Status code
|
||||
*
|
||||
*/
|
||||
SocketStatus receive(Packet packetToReceive, out IPAddress address)
|
||||
{
|
||||
SocketStatus ret = sfSocketUDP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer, &address);
|
||||
packetToReceive.onReceive(m_intermediatePacket.getData);
|
||||
|
@ -161,87 +161,87 @@ class SocketUDP : DSFMLObject
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the socket is in a valid state ; this function
|
||||
* can be called any time to check if the socket is OK
|
||||
*
|
||||
* Returns:
|
||||
* True if the socket is valid
|
||||
*
|
||||
*/
|
||||
bool isValid()
|
||||
/**
|
||||
* Check if the socket is in a valid state ; this function
|
||||
* can be called any time to check if the socket is OK
|
||||
*
|
||||
* Returns:
|
||||
* True if the socket is valid
|
||||
*
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfSocketUDP_IsValid(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port the socket is currently bound to
|
||||
*
|
||||
* Returns:
|
||||
* Current port (0 means the socket is not bound)
|
||||
*/
|
||||
ushort getPort()
|
||||
/**
|
||||
* Get the port the socket is currently bound to
|
||||
*
|
||||
* Returns:
|
||||
* Current port (0 means the socket is not bound)
|
||||
*/
|
||||
ushort getPort()
|
||||
{
|
||||
return m_port;
|
||||
}
|
||||
|
||||
///
|
||||
bool opEquals(SocketUDP other)
|
||||
///
|
||||
bool opEquals(SocketUDP other)
|
||||
{
|
||||
return (other.getNativePointer == this.getNativePointer);
|
||||
}
|
||||
|
||||
package:
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
this (void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
private:
|
||||
Packet m_intermediatePacket;
|
||||
Packet m_intermediatePacket;
|
||||
ushort m_port;
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSocketUDP_Create;
|
||||
typedef void function(void*) pf_sfSocketUDP_Destroy;
|
||||
typedef int function(void*, ushort) pf_sfSocketUDP_Bind;
|
||||
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, size_t*, IPAddress*) pf_sfSocketUDP_Receive;
|
||||
typedef SocketStatus function(void*, void*, IPAddress, ushort) pf_sfSocketUDP_SendPacket;
|
||||
typedef SocketStatus function(void*, void*, IPAddress*) pf_sfSocketUDP_ReceivePacket;
|
||||
typedef int function(void*) pf_sfSocketUDP_IsValid;
|
||||
|
||||
static pf_sfSocketUDP_Create sfSocketUDP_Create;
|
||||
static pf_sfSocketUDP_Destroy sfSocketUDP_Destroy;
|
||||
static pf_sfSocketUDP_Bind sfSocketUDP_Bind;
|
||||
static pf_sfSocketUDP_Unbind sfSocketUDP_Unbind;
|
||||
static pf_sfSocketUDP_Send sfSocketUDP_Send;
|
||||
static pf_sfSocketUDP_Receive sfSocketUDP_Receive;
|
||||
static pf_sfSocketUDP_SendPacket sfSocketUDP_SendPacket;
|
||||
static pf_sfSocketUDP_ReceivePacket sfSocketUDP_ReceivePacket;
|
||||
static pf_sfSocketUDP_IsValid sfSocketUDP_IsValid;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfSocketUDP_Create;
|
||||
typedef void function(void*) pf_sfSocketUDP_Destroy;
|
||||
typedef int function(void*, ushort) pf_sfSocketUDP_Bind;
|
||||
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, size_t*, IPAddress*) pf_sfSocketUDP_Receive;
|
||||
typedef SocketStatus function(void*, void*, IPAddress, ushort) pf_sfSocketUDP_SendPacket;
|
||||
typedef SocketStatus function(void*, void*, IPAddress*) pf_sfSocketUDP_ReceivePacket;
|
||||
typedef int function(void*) pf_sfSocketUDP_IsValid;
|
||||
|
||||
static pf_sfSocketUDP_Create sfSocketUDP_Create;
|
||||
static pf_sfSocketUDP_Destroy sfSocketUDP_Destroy;
|
||||
static pf_sfSocketUDP_Bind sfSocketUDP_Bind;
|
||||
static pf_sfSocketUDP_Unbind sfSocketUDP_Unbind;
|
||||
static pf_sfSocketUDP_Send sfSocketUDP_Send;
|
||||
static pf_sfSocketUDP_Receive sfSocketUDP_Receive;
|
||||
static pf_sfSocketUDP_SendPacket sfSocketUDP_SendPacket;
|
||||
static pf_sfSocketUDP_ReceivePacket sfSocketUDP_ReceivePacket;
|
||||
static pf_sfSocketUDP_IsValid sfSocketUDP_IsValid;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfSocketUDP_Bind = cast(pf_sfSocketUDP_Bind)dll.getSymbol("sfSocketUDP_Bind");
|
||||
sfSocketUDP_Create = cast(pf_sfSocketUDP_Create)dll.getSymbol("sfSocketUDP_Create");
|
||||
sfSocketUDP_Destroy = cast(pf_sfSocketUDP_Destroy)dll.getSymbol("sfSocketUDP_Destroy");
|
||||
sfSocketUDP_IsValid = cast(pf_sfSocketUDP_IsValid)dll.getSymbol("sfSocketUDP_IsValid");
|
||||
sfSocketUDP_Receive = cast(pf_sfSocketUDP_Receive)dll.getSymbol("sfSocketUDP_Receive");
|
||||
sfSocketUDP_ReceivePacket = cast(pf_sfSocketUDP_ReceivePacket)dll.getSymbol("sfSocketUDP_ReceivePacket");
|
||||
sfSocketUDP_Send = cast(pf_sfSocketUDP_Send)dll.getSymbol("sfSocketUDP_Send");
|
||||
sfSocketUDP_SendPacket = cast(pf_sfSocketUDP_SendPacket)dll.getSymbol("sfSocketUDP_SendPacket");
|
||||
sfSocketUDP_Unbind = cast(pf_sfSocketUDP_Unbind)dll.getSymbol("sfSocketUDP_Unbind");
|
||||
}
|
||||
|
||||
sfSocketUDP_Bind = cast(pf_sfSocketUDP_Bind)dll.getSymbol("sfSocketUDP_Bind");
|
||||
sfSocketUDP_Create = cast(pf_sfSocketUDP_Create)dll.getSymbol("sfSocketUDP_Create");
|
||||
sfSocketUDP_Destroy = cast(pf_sfSocketUDP_Destroy)dll.getSymbol("sfSocketUDP_Destroy");
|
||||
sfSocketUDP_IsValid = cast(pf_sfSocketUDP_IsValid)dll.getSymbol("sfSocketUDP_IsValid");
|
||||
sfSocketUDP_Receive = cast(pf_sfSocketUDP_Receive)dll.getSymbol("sfSocketUDP_Receive");
|
||||
sfSocketUDP_ReceivePacket = cast(pf_sfSocketUDP_ReceivePacket)dll.getSymbol("sfSocketUDP_ReceivePacket");
|
||||
sfSocketUDP_Send = cast(pf_sfSocketUDP_Send)dll.getSymbol("sfSocketUDP_Send");
|
||||
sfSocketUDP_SendPacket = cast(pf_sfSocketUDP_SendPacket)dll.getSymbol("sfSocketUDP_SendPacket");
|
||||
sfSocketUDP_Unbind = cast(pf_sfSocketUDP_Unbind)dll.getSymbol("sfSocketUDP_Unbind");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.all;
|
||||
|
||||
version (linux)
|
||||
{
|
||||
version (build)
|
||||
{
|
||||
pragma(link, "dl"); //Link libdl.so (dlopen, dlsym)
|
||||
}
|
||||
version (build)
|
||||
{
|
||||
pragma(link, "dl"); //Link libdl.so (dlopen, dlsym)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,4 +43,4 @@ public import
|
|||
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.vector2,
|
||||
dsfml.system.vector3;
|
||||
dsfml.system.vector3;
|
||||
|
|
|
@ -1,84 +1,84 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.alloc;
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
public import tango.core.Memory;
|
||||
public import tango.core.Memory;
|
||||
}
|
||||
else
|
||||
{
|
||||
public import core.memory;
|
||||
public import core.memory;
|
||||
}
|
||||
|
||||
/*
|
||||
struct GC
|
||||
{
|
||||
static void* malloc(uint size)
|
||||
{
|
||||
return std.c.stdlib.malloc(size);
|
||||
}
|
||||
|
||||
static void free(void* ptr)
|
||||
{
|
||||
std.c.stdlib.free(ptr);
|
||||
}
|
||||
|
||||
static void addRange(void* ptr, uint size)
|
||||
{
|
||||
std.gc.addRange(ptr, ptr + size);
|
||||
}
|
||||
|
||||
static void removeRange(void* ptr)
|
||||
{
|
||||
std.gc.removeRange(ptr);
|
||||
}
|
||||
}
|
||||
struct GC
|
||||
{
|
||||
static void* malloc(uint size)
|
||||
{
|
||||
return std.c.stdlib.malloc(size);
|
||||
}
|
||||
|
||||
static void free(void* ptr)
|
||||
{
|
||||
std.c.stdlib.free(ptr);
|
||||
}
|
||||
|
||||
static void addRange(void* ptr, uint size)
|
||||
{
|
||||
std.gc.addRange(ptr, ptr + size);
|
||||
}
|
||||
|
||||
static void removeRange(void* 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()
|
||||
{
|
||||
new (uint size)
|
||||
{
|
||||
void* p = GC.malloc(size);
|
||||
if (!p)
|
||||
assert(0, "Memory allocation failed");
|
||||
|
||||
GC.addRange(p, size);
|
||||
return p;
|
||||
}
|
||||
new (uint size)
|
||||
{
|
||||
void* p = GC.malloc(size);
|
||||
if (!p)
|
||||
assert(0, "Memory allocation failed");
|
||||
|
||||
GC.addRange(p, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
delete(void* p)
|
||||
{
|
||||
GC.removeRange(p);
|
||||
GC.free(p);
|
||||
}
|
||||
delete(void* p)
|
||||
{
|
||||
GC.removeRange(p);
|
||||
GC.free(p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.clock;
|
||||
|
@ -33,69 +33,69 @@ import dsfml.system.common;
|
|||
*/
|
||||
class Clock : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfClock_Create());
|
||||
}
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfClock_Create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
override void dispose()
|
||||
{
|
||||
sfClock_Destroy(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
override void dispose()
|
||||
{
|
||||
sfClock_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the time elapsed since the last reset
|
||||
* Returns:
|
||||
* Elapsed Time in seconds
|
||||
*/
|
||||
float getElapsedTime()
|
||||
{
|
||||
return sfClock_GetTime(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Return the time elapsed since the last reset
|
||||
* Returns:
|
||||
* Elapsed Time in seconds
|
||||
*/
|
||||
float getElapsedTime()
|
||||
{
|
||||
return sfClock_GetTime(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart the timer
|
||||
*/
|
||||
void reset()
|
||||
{
|
||||
sfClock_Reset(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Restart the timer
|
||||
*/
|
||||
void reset()
|
||||
{
|
||||
sfClock_Reset(m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfClock_Create;
|
||||
typedef void function(void*) pf_sfClock_Destroy;
|
||||
typedef float function(void*) pf_sfClock_GetTime;
|
||||
typedef void function(void*) pf_sfClock_Reset;
|
||||
|
||||
static pf_sfClock_Create sfClock_Create;
|
||||
static pf_sfClock_Destroy sfClock_Destroy;
|
||||
static pf_sfClock_GetTime sfClock_GetTime;
|
||||
static pf_sfClock_Reset sfClock_Reset;
|
||||
|
||||
static this()
|
||||
{
|
||||
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfClock_Create;
|
||||
typedef void function(void*) pf_sfClock_Destroy;
|
||||
typedef float function(void*) pf_sfClock_GetTime;
|
||||
typedef void function(void*) pf_sfClock_Reset;
|
||||
|
||||
static pf_sfClock_Create sfClock_Create;
|
||||
static pf_sfClock_Destroy sfClock_Destroy;
|
||||
static pf_sfClock_GetTime sfClock_GetTime;
|
||||
static pf_sfClock_Reset sfClock_Reset;
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-system-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-system");
|
||||
|
||||
sfClock_Create = cast(pf_sfClock_Create)dll.getSymbol("sfClock_Create");
|
||||
sfClock_Destroy = cast(pf_sfClock_Destroy)dll.getSymbol("sfClock_Destroy");
|
||||
sfClock_GetTime = cast(pf_sfClock_GetTime)dll.getSymbol("sfClock_GetTime");
|
||||
sfClock_Reset = cast(pf_sfClock_Reset)dll.getSymbol("sfClock_Reset");
|
||||
}
|
||||
}
|
||||
|
||||
sfClock_Create = cast(pf_sfClock_Create)dll.getSymbol("sfClock_Create");
|
||||
sfClock_Destroy = cast(pf_sfClock_Destroy)dll.getSymbol("sfClock_Destroy");
|
||||
sfClock_GetTime = cast(pf_sfClock_GetTime)dll.getSymbol("sfClock_GetTime");
|
||||
sfClock_Reset = cast(pf_sfClock_Reset)dll.getSymbol("sfClock_Reset");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -60,32 +60,32 @@ protected:
|
|||
public:
|
||||
|
||||
this(void* ptr, bool preventDelete = false)
|
||||
{
|
||||
m_ptr = ptr;
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
if (!m_preventDelete)
|
||||
dispose();
|
||||
|
||||
m_ptr = m_ptr.init;
|
||||
}
|
||||
|
||||
abstract void dispose();
|
||||
|
||||
void* getNativePointer()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
{
|
||||
m_ptr = ptr;
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
if (!m_preventDelete)
|
||||
dispose();
|
||||
|
||||
m_ptr = m_ptr.init;
|
||||
}
|
||||
|
||||
abstract void dispose();
|
||||
|
||||
void* getNativePointer()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
void setHandled(bool handled)
|
||||
{
|
||||
m_preventDelete = handled;
|
||||
}
|
||||
|
||||
protected invariant()
|
||||
{
|
||||
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
|
||||
}
|
||||
void setHandled(bool handled)
|
||||
{
|
||||
m_preventDelete = handled;
|
||||
}
|
||||
|
||||
protected invariant()
|
||||
{
|
||||
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
|
||||
}
|
||||
}
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.dllloader;
|
||||
|
@ -30,161 +30,161 @@ import dsfml.system.stringutil;
|
|||
|
||||
version (Tango)
|
||||
{
|
||||
import tango.io.Console;
|
||||
import tango.sys.SharedLib;
|
||||
import tango.io.Console;
|
||||
import tango.sys.SharedLib;
|
||||
}
|
||||
else
|
||||
{
|
||||
import std.stdio;
|
||||
|
||||
version (Windows)
|
||||
{
|
||||
import std.c.windows.windows;
|
||||
alias HMODULE MODULEHANDLE;
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
import std.c.linux.linux;
|
||||
alias void* MODULEHANDLE;
|
||||
|
||||
const int RTLD_NOW = 0x00002;
|
||||
const int RTLD_GLOBAL = 0x00100;
|
||||
}
|
||||
import std.stdio;
|
||||
|
||||
version (Windows)
|
||||
{
|
||||
import std.c.windows.windows;
|
||||
alias HMODULE MODULEHANDLE;
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
import std.c.linux.linux;
|
||||
alias void* MODULEHANDLE;
|
||||
|
||||
const int RTLD_NOW = 0x00002;
|
||||
const int RTLD_GLOBAL = 0x00100;
|
||||
}
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
version (Tango)
|
||||
{
|
||||
SharedLib.throwExceptions = false;
|
||||
}
|
||||
version (Tango)
|
||||
{
|
||||
SharedLib.throwExceptions = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void report(string msg, string lib, string symb)
|
||||
{
|
||||
string str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")";
|
||||
version (Tango)
|
||||
{
|
||||
Cerr(str).newline;
|
||||
}
|
||||
else
|
||||
{
|
||||
stderr.writeln(str);
|
||||
}
|
||||
string str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")";
|
||||
version (Tango)
|
||||
{
|
||||
Cerr(str).newline;
|
||||
}
|
||||
else
|
||||
{
|
||||
stderr.writeln(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple Dll loader.
|
||||
* Simple Dll loader.
|
||||
*/
|
||||
class DllLoader
|
||||
{
|
||||
static DllLoader load(string library)
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
string libraryName = library ~ ".dll";
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
string libraryName = "lib" ~ library ~ ".so";
|
||||
}
|
||||
|
||||
if (libraryName in alreadyLoaded)
|
||||
{
|
||||
return alreadyLoaded[libraryName];
|
||||
}
|
||||
else
|
||||
{
|
||||
DllLoader temp = new DllLoader(libraryName);
|
||||
alreadyLoaded[libraryName] = temp;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
close();
|
||||
}
|
||||
static DllLoader load(string library)
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
string libraryName = library ~ ".dll";
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
string libraryName = "lib" ~ library ~ ".so";
|
||||
}
|
||||
|
||||
if (libraryName in alreadyLoaded)
|
||||
{
|
||||
return alreadyLoaded[libraryName];
|
||||
}
|
||||
else
|
||||
{
|
||||
DllLoader temp = new DllLoader(libraryName);
|
||||
alreadyLoaded[libraryName] = temp;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void* getSymbol(string symbolName)
|
||||
{
|
||||
void* symb;
|
||||
version (Tango)
|
||||
{
|
||||
symb = m_lib.getSymbol(toStringz(symbolName));
|
||||
}
|
||||
else
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
symb = GetProcAddress(m_lib, toStringz(symbolName));
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
symb = dlsym(m_lib, toStringz(symbolName));
|
||||
}
|
||||
}
|
||||
|
||||
if (symb is null)
|
||||
report( "Symbol cannot be found in specified library", m_libPath, symbolName);
|
||||
|
||||
return symb;
|
||||
}
|
||||
void* getSymbol(string symbolName)
|
||||
{
|
||||
void* symb;
|
||||
version (Tango)
|
||||
{
|
||||
symb = m_lib.getSymbol(toStringz(symbolName));
|
||||
}
|
||||
else
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
symb = GetProcAddress(m_lib, toStringz(symbolName));
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
symb = dlsym(m_lib, toStringz(symbolName));
|
||||
}
|
||||
}
|
||||
|
||||
if (symb is null)
|
||||
report( "Symbol cannot be found in specified library", m_libPath, symbolName);
|
||||
|
||||
return symb;
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
version (Tango)
|
||||
{
|
||||
m_lib.unload();
|
||||
}
|
||||
else
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
FreeLibrary(m_lib);
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
dlclose(m_lib);
|
||||
}
|
||||
alreadyLoaded.remove(this.m_libPath);
|
||||
}
|
||||
}
|
||||
void close()
|
||||
{
|
||||
version (Tango)
|
||||
{
|
||||
m_lib.unload();
|
||||
}
|
||||
else
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
FreeLibrary(m_lib);
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
dlclose(m_lib);
|
||||
}
|
||||
alreadyLoaded.remove(this.m_libPath);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
this(string libraryPath)
|
||||
{
|
||||
m_libPath = libraryPath;
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
m_lib = SharedLib.load(libraryPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
m_lib = LoadLibraryA(toStringz(libraryPath));
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
m_lib = dlopen(toStringz(libraryPath), RTLD_NOW | RTLD_GLOBAL);
|
||||
}
|
||||
}
|
||||
if (m_lib is null)
|
||||
report("Cannot open library", m_libPath, null);
|
||||
}
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
SharedLib m_lib;
|
||||
}
|
||||
else
|
||||
{
|
||||
MODULEHANDLE m_lib;
|
||||
}
|
||||
|
||||
static DllLoader[string] alreadyLoaded;
|
||||
string m_libPath;
|
||||
this(string libraryPath)
|
||||
{
|
||||
m_libPath = libraryPath;
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
m_lib = SharedLib.load(libraryPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
version (Windows)
|
||||
{
|
||||
m_lib = LoadLibraryA(toStringz(libraryPath));
|
||||
}
|
||||
version (linux)
|
||||
{
|
||||
m_lib = dlopen(toStringz(libraryPath), RTLD_NOW | RTLD_GLOBAL);
|
||||
}
|
||||
}
|
||||
if (m_lib is null)
|
||||
report("Cannot open library", m_libPath, null);
|
||||
}
|
||||
|
||||
version (Tango)
|
||||
{
|
||||
SharedLib m_lib;
|
||||
}
|
||||
else
|
||||
{
|
||||
MODULEHANDLE m_lib;
|
||||
}
|
||||
|
||||
static DllLoader[string] alreadyLoaded;
|
||||
string m_libPath;
|
||||
}
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.exception;
|
||||
|
||||
class LoadingException : Exception
|
||||
{
|
||||
this(string msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
this(string msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
class NullParameterException : Exception
|
||||
{
|
||||
this(string msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
this(string msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,103 +1,103 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
Node!(T) head;
|
||||
Node!(T) tail;
|
||||
private size_t m_count;
|
||||
|
||||
void enqueue(T object)
|
||||
{
|
||||
if (empty)
|
||||
head = tail = new Node!(T)(object);
|
||||
else
|
||||
{
|
||||
tail.Next = new Node!(T)(object);
|
||||
tail = tail.Next;
|
||||
}
|
||||
m_count++;
|
||||
}
|
||||
|
||||
T dequeue()
|
||||
{
|
||||
T o;
|
||||
if (empty)
|
||||
o = T.init;
|
||||
else
|
||||
{
|
||||
o = head.Data;
|
||||
head = head.Next;
|
||||
m_count--;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
bool empty()
|
||||
{
|
||||
return (head is null);
|
||||
}
|
||||
Node!(T) head;
|
||||
Node!(T) tail;
|
||||
private size_t m_count;
|
||||
|
||||
void enqueue(T object)
|
||||
{
|
||||
if (empty)
|
||||
head = tail = new Node!(T)(object);
|
||||
else
|
||||
{
|
||||
tail.Next = new Node!(T)(object);
|
||||
tail = tail.Next;
|
||||
}
|
||||
m_count++;
|
||||
}
|
||||
|
||||
T dequeue()
|
||||
{
|
||||
T o;
|
||||
if (empty)
|
||||
o = T.init;
|
||||
else
|
||||
{
|
||||
o = head.Data;
|
||||
head = head.Next;
|
||||
m_count--;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
bool empty()
|
||||
{
|
||||
return (head is null);
|
||||
}
|
||||
|
||||
size_t getCount()
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
size_t getCount()
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
T data;
|
||||
while ((data = dequeue()) !is T.init) {}
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
T data;
|
||||
while ((data = dequeue()) !is T.init) {}
|
||||
}
|
||||
|
||||
int opApply(int delegate(ref T) dg)
|
||||
{
|
||||
T data;
|
||||
int result;
|
||||
while ((data = dequeue) !is T.init)
|
||||
{
|
||||
if ((result = dg(data)) != 0)
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int opApply(int delegate(ref T) dg)
|
||||
{
|
||||
T data;
|
||||
int result;
|
||||
while ((data = dequeue) !is T.init)
|
||||
{
|
||||
if ((result = dg(data)) != 0)
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class Node(T)
|
||||
{
|
||||
Node Next;
|
||||
T Data;
|
||||
|
||||
this(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
Node Next;
|
||||
T Data;
|
||||
|
||||
this(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.lock;
|
||||
|
@ -29,38 +29,38 @@ module dsfml.system.lock;
|
|||
import dsfml.system.mutex;
|
||||
|
||||
/**
|
||||
* Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception.
|
||||
*
|
||||
* Remarks:
|
||||
* Lock is a scope class, you need to mark Lock object as scope :
|
||||
*
|
||||
* -----------------
|
||||
* Mutex m = new Mutex;
|
||||
* //..
|
||||
* {
|
||||
* scope Lock l = new Lock(m);
|
||||
* // Critical section
|
||||
* } // End of critical (Destructor called and mutex unlocked)
|
||||
* //..
|
||||
* Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception.
|
||||
*
|
||||
* Remarks:
|
||||
* Lock is a scope class, you need to mark Lock object as scope :
|
||||
*
|
||||
* -----------------
|
||||
* Mutex m = new Mutex;
|
||||
* //..
|
||||
* {
|
||||
* scope Lock l = new Lock(m);
|
||||
* // Critical section
|
||||
* } // End of critical (Destructor called and mutex unlocked)
|
||||
* //..
|
||||
*
|
||||
* -----------------
|
||||
* -----------------
|
||||
*/
|
||||
scope class Lock
|
||||
{
|
||||
/**
|
||||
* Construct the lock and lock the mutex
|
||||
*/
|
||||
this(Mutex m)
|
||||
{
|
||||
m_mutex = m;
|
||||
m_mutex.lock();
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
m_mutex.unlock();
|
||||
}
|
||||
/**
|
||||
* Construct the lock and lock the mutex
|
||||
*/
|
||||
this(Mutex m)
|
||||
{
|
||||
m_mutex = m;
|
||||
m_mutex.lock();
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex m_mutex;
|
||||
Mutex m_mutex;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.mutex;
|
||||
|
@ -29,70 +29,70 @@ module dsfml.system.mutex;
|
|||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* Provide portable implementation of Mutual Exclusion object.
|
||||
*
|
||||
* Uses CriticalSection on Windows and pthread mutexes on linux.
|
||||
* Provide portable implementation of Mutual Exclusion object.
|
||||
*
|
||||
* Uses CriticalSection on Windows and pthread mutexes on linux.
|
||||
*/
|
||||
final class Mutex : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfMutex_Create());
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfMutex_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfMutex_Destroy(m_ptr);
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
sfMutex_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the mutex
|
||||
*
|
||||
* Can be called multiples times, but each lock must be unlocked with unlock()
|
||||
*/
|
||||
void lock()
|
||||
{
|
||||
sfMutex_Lock(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock the mutex
|
||||
*/
|
||||
void unlock()
|
||||
{
|
||||
sfMutex_Unlock(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Lock the mutex
|
||||
*
|
||||
* Can be called multiples times, but each lock must be unlocked with unlock()
|
||||
*/
|
||||
void lock()
|
||||
{
|
||||
sfMutex_Lock(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock the mutex
|
||||
*/
|
||||
void unlock()
|
||||
{
|
||||
sfMutex_Unlock(m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfMutex_Create;
|
||||
typedef void function(void*) pf_sfMutex_Destroy;
|
||||
typedef void function(void*) pf_sfMutex_Lock;
|
||||
typedef void function(void*) pf_sfMutex_Unlock;
|
||||
|
||||
static pf_sfMutex_Create sfMutex_Create;
|
||||
static pf_sfMutex_Destroy sfMutex_Destroy;
|
||||
static pf_sfMutex_Lock sfMutex_Lock;
|
||||
static pf_sfMutex_Unlock sfMutex_Unlock;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function() pf_sfMutex_Create;
|
||||
typedef void function(void*) pf_sfMutex_Destroy;
|
||||
typedef void function(void*) pf_sfMutex_Lock;
|
||||
typedef void function(void*) pf_sfMutex_Unlock;
|
||||
|
||||
static pf_sfMutex_Create sfMutex_Create;
|
||||
static pf_sfMutex_Destroy sfMutex_Destroy;
|
||||
static pf_sfMutex_Lock sfMutex_Lock;
|
||||
static pf_sfMutex_Unlock sfMutex_Unlock;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-system-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-system");
|
||||
|
||||
sfMutex_Create = cast(pf_sfMutex_Create)dll.getSymbol("sfMutex_Create");
|
||||
sfMutex_Destroy = cast(pf_sfMutex_Destroy)dll.getSymbol("sfMutex_Destroy");
|
||||
sfMutex_Lock = cast(pf_sfMutex_Lock)dll.getSymbol("sfMutex_Lock");
|
||||
sfMutex_Unlock = cast(pf_sfMutex_Unlock)dll.getSymbol("sfMutex_Unlock");
|
||||
}
|
||||
|
||||
sfMutex_Create = cast(pf_sfMutex_Create)dll.getSymbol("sfMutex_Create");
|
||||
sfMutex_Destroy = cast(pf_sfMutex_Destroy)dll.getSymbol("sfMutex_Destroy");
|
||||
sfMutex_Lock = cast(pf_sfMutex_Lock)dll.getSymbol("sfMutex_Lock");
|
||||
sfMutex_Unlock = cast(pf_sfMutex_Unlock)dll.getSymbol("sfMutex_Unlock");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.randomizer;
|
||||
|
@ -29,64 +29,64 @@ module dsfml.system.randomizer;
|
|||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* Randomizer is an utility class for generating pseudo-random
|
||||
* numbers
|
||||
*
|
||||
* Examples:
|
||||
* -----------------------------------------------------------
|
||||
* int randI = Randomizer.Random(1, 100);
|
||||
* float randF = Randomizer.Random(1.0, 10.0)
|
||||
* -----------------------------------------------------------
|
||||
* Randomizer is an utility class for generating pseudo-random
|
||||
* numbers
|
||||
*
|
||||
* Examples:
|
||||
* -----------------------------------------------------------
|
||||
* int randI = Randomizer.Random(1, 100);
|
||||
* float randF = Randomizer.Random(1.0, 10.0)
|
||||
* -----------------------------------------------------------
|
||||
*/
|
||||
class Randomizer
|
||||
{
|
||||
/**
|
||||
* Set the seed for the generator. Using a known seed
|
||||
* allows you to reproduce the same sequence of random number
|
||||
*
|
||||
* Params:
|
||||
* seed = Number to use as the seed
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Set the seed for the generator. Using a known seed
|
||||
* allows you to reproduce the same sequence of random number
|
||||
*
|
||||
* Params:
|
||||
* seed = Number to use as the seed
|
||||
*
|
||||
*/
|
||||
static void setSeed(uint seed)
|
||||
{
|
||||
sfRandom_SetSeed(seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the seed used to generate random numbers the generator.
|
||||
*
|
||||
* Returns:
|
||||
* Current seed
|
||||
*/
|
||||
/**
|
||||
* Get the seed used to generate random numbers the generator.
|
||||
*
|
||||
* Returns:
|
||||
* Current seed
|
||||
*/
|
||||
static uint getSeed()
|
||||
{
|
||||
return sfRandom_GetSeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random float number in a given range
|
||||
*
|
||||
* Params:
|
||||
* begin = Start of the range
|
||||
* end = End of the range
|
||||
* Returns:
|
||||
* Random number in [Begin, End]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a random float number in a given range
|
||||
*
|
||||
* Params:
|
||||
* begin = Start of the range
|
||||
* end = End of the range
|
||||
* Returns:
|
||||
* Random number in [Begin, End]
|
||||
*/
|
||||
static float random(float begin, float end)
|
||||
{
|
||||
return sfRandom_Float(begin, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random integral number in a given range
|
||||
*
|
||||
* Params:
|
||||
* begin = Start of the range
|
||||
* end = End of the range
|
||||
* Returns:
|
||||
* Random number in [Begin, End]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get a random integral number in a given range
|
||||
*
|
||||
* Params:
|
||||
* begin = Start of the range
|
||||
* end = End of the range
|
||||
* Returns:
|
||||
* Random number in [Begin, End]
|
||||
*/
|
||||
static int random(int begin, int end)
|
||||
{
|
||||
return sfRandom_Int(begin, end);
|
||||
|
@ -95,40 +95,40 @@ class Randomizer
|
|||
|
||||
private:
|
||||
|
||||
/*
|
||||
* Prevent instanciation
|
||||
*/
|
||||
this()
|
||||
{
|
||||
|
||||
}
|
||||
/*
|
||||
* Prevent instanciation
|
||||
*/
|
||||
this()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(uint) pf_sfRandom_SetSeed;
|
||||
typedef uint function() pf_sfRandom_GetSeed;
|
||||
typedef float function(float, float) pf_sfRandom_Float;
|
||||
typedef int function(int, int) pf_sfRandom_Int;
|
||||
|
||||
static pf_sfRandom_SetSeed sfRandom_SetSeed;
|
||||
static pf_sfRandom_GetSeed sfRandom_GetSeed;
|
||||
static pf_sfRandom_Float sfRandom_Float;
|
||||
static pf_sfRandom_Int sfRandom_Int;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void function(uint) pf_sfRandom_SetSeed;
|
||||
typedef uint function() pf_sfRandom_GetSeed;
|
||||
typedef float function(float, float) pf_sfRandom_Float;
|
||||
typedef int function(int, int) pf_sfRandom_Int;
|
||||
|
||||
static pf_sfRandom_SetSeed sfRandom_SetSeed;
|
||||
static pf_sfRandom_GetSeed sfRandom_GetSeed;
|
||||
static pf_sfRandom_Float sfRandom_Float;
|
||||
static pf_sfRandom_Int sfRandom_Int;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-system-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-system");
|
||||
|
||||
sfRandom_SetSeed = cast(pf_sfRandom_SetSeed)dll.getSymbol("sfRandom_SetSeed");
|
||||
sfRandom_GetSeed = cast(pf_sfRandom_GetSeed)dll.getSymbol("sfRandom_GetSeed");
|
||||
sfRandom_Float = cast(pf_sfRandom_Float)dll.getSymbol("sfRandom_Float");
|
||||
sfRandom_Int = cast(pf_sfRandom_Int)dll.getSymbol("sfRandom_Int");
|
||||
}
|
||||
|
||||
sfRandom_SetSeed = cast(pf_sfRandom_SetSeed)dll.getSymbol("sfRandom_SetSeed");
|
||||
sfRandom_GetSeed = cast(pf_sfRandom_GetSeed)dll.getSymbol("sfRandom_GetSeed");
|
||||
sfRandom_Float = cast(pf_sfRandom_Float)dll.getSymbol("sfRandom_Float");
|
||||
sfRandom_Int = cast(pf_sfRandom_Int)dll.getSymbol("sfRandom_Int");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.sleep;
|
||||
|
@ -42,17 +42,17 @@ static this()
|
|||
else
|
||||
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:
|
||||
* duration = Time to sleep, in seconds
|
||||
* Params:
|
||||
* duration = Time to sleep, in seconds
|
||||
*/
|
||||
void sleep(float duration)
|
||||
{
|
||||
sfSleep(duration);
|
||||
sfSleep(duration);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.stringutil;
|
||||
|
@ -40,43 +40,43 @@ else
|
|||
*/
|
||||
|
||||
|
||||
T* toStringz(T)(T[] str)
|
||||
{
|
||||
if (str is null)
|
||||
return null;
|
||||
else if (str.length && str[$ - 1] is T.init)
|
||||
return str.ptr;
|
||||
T* toStringz(T)(T[] str)
|
||||
{
|
||||
if (str is null)
|
||||
return null;
|
||||
else if (str.length && str[$ - 1] is T.init)
|
||||
return str.ptr;
|
||||
|
||||
auto ret = new Unqual!(T)[str.length + 1];
|
||||
|
||||
ret[0 .. str.length] = str[0 .. $];
|
||||
ret[str.length] = 0;
|
||||
|
||||
return cast(T*) ret.ptr;
|
||||
}
|
||||
auto ret = new Unqual!(T)[str.length + 1];
|
||||
|
||||
ret[0 .. str.length] = str[0 .. $];
|
||||
ret[str.length] = 0;
|
||||
|
||||
return cast(T*) ret.ptr;
|
||||
}
|
||||
|
||||
|
||||
size_t stringLength(T)(T* p)
|
||||
{
|
||||
if (p is null || *p == T.init)
|
||||
return 0;
|
||||
|
||||
size_t length;
|
||||
|
||||
while (*(p + length))
|
||||
{
|
||||
length++;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
size_t stringLength(T)(T* p)
|
||||
{
|
||||
if (p is null || *p == T.init)
|
||||
return 0;
|
||||
|
||||
size_t length;
|
||||
|
||||
while (*(p + length))
|
||||
{
|
||||
length++;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
T[] fromStringz(T)(T* ptr)
|
||||
{
|
||||
auto ret = new Unqual!(T)[stringLength(ptr)];
|
||||
ret[0..$] = ptr[0..ret.length];
|
||||
|
||||
return cast(T[]) ret;
|
||||
}
|
||||
T[] fromStringz(T)(T* ptr)
|
||||
{
|
||||
auto ret = new Unqual!(T)[stringLength(ptr)];
|
||||
ret[0..$] = ptr[0..ret.length];
|
||||
|
||||
return cast(T[]) ret;
|
||||
}
|
||||
|
||||
|
|
@ -1,158 +1,158 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.vector2;
|
||||
|
||||
/**
|
||||
* Vector2 is an utility class for manipulating 2 dimensional
|
||||
* vectors. Template parameter defines the type of coordinates
|
||||
* (integer, float, ...)
|
||||
* Vector2 is an utility class for manipulating 2 dimensional
|
||||
* vectors. Template parameter defines the type of coordinates
|
||||
* (integer, float, ...)
|
||||
*/
|
||||
struct Vector2(T)
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T x;
|
||||
T y;
|
||||
|
||||
static Vector2 opCall(T x, T y)
|
||||
{
|
||||
Vector2!(T) ret;
|
||||
|
||||
ret.x = x;
|
||||
ret.y = y;
|
||||
|
||||
return ret;
|
||||
}
|
||||
static Vector2 opCall(T x, T y)
|
||||
{
|
||||
Vector2!(T) ret;
|
||||
|
||||
ret.x = x;
|
||||
ret.y = y;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// unary (-) overload
|
||||
Vector2 opNeg()
|
||||
{
|
||||
return Vector2!(T)(-x, -y);
|
||||
}
|
||||
/// unary (-) overload
|
||||
Vector2 opNeg()
|
||||
{
|
||||
return Vector2!(T)(-x, -y);
|
||||
}
|
||||
|
||||
/// (+=) overload
|
||||
Vector2 opAddAssign(Vector2 other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return this;
|
||||
}
|
||||
/// (+=) overload
|
||||
Vector2 opAddAssign(Vector2 other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// (-=) overload
|
||||
Vector2 opSubAssign(Vector2 other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
return this;
|
||||
}
|
||||
/// (-=) overload
|
||||
Vector2 opSubAssign(Vector2 other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// (+) overload
|
||||
Vector2 opAdd(Vector2 other)
|
||||
{
|
||||
return Vector2!(T)( (x + other.x), (y + other.y) );
|
||||
}
|
||||
/// (+) overload
|
||||
Vector2 opAdd(Vector2 other)
|
||||
{
|
||||
return Vector2!(T)( (x + other.x), (y + other.y) );
|
||||
}
|
||||
|
||||
/// (-) overload
|
||||
Vector2 opSub(Vector2 other)
|
||||
{
|
||||
return Vector2!(T) ( (x - other.x), (y - other.y) );
|
||||
}
|
||||
|
||||
/// (*) overload
|
||||
Vector2 opMul(int i)
|
||||
{
|
||||
return Vector2!(T) ( (x * i), (y * i) );
|
||||
}
|
||||
/// (-) overload
|
||||
Vector2 opSub(Vector2 other)
|
||||
{
|
||||
return Vector2!(T) ( (x - other.x), (y - other.y) );
|
||||
}
|
||||
|
||||
/// (*) overload
|
||||
Vector2 opMul(int i)
|
||||
{
|
||||
return Vector2!(T) ( (x * i), (y * i) );
|
||||
}
|
||||
|
||||
/// (*=) overload
|
||||
Vector2 opMulAssign(int i)
|
||||
{
|
||||
x *= i;
|
||||
y *= i;
|
||||
return this;
|
||||
}
|
||||
/// (*=) overload
|
||||
Vector2 opMulAssign(int i)
|
||||
{
|
||||
x *= i;
|
||||
y *= i;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// (/) overload
|
||||
Vector2 opDiv(int i)
|
||||
{
|
||||
return Vector2!(T) ( (x / i), (y / i));
|
||||
}
|
||||
/// (/) overload
|
||||
Vector2 opDiv(int i)
|
||||
{
|
||||
return Vector2!(T) ( (x / i), (y / i));
|
||||
}
|
||||
|
||||
/// (/=) overload
|
||||
Vector2 opDivAssign(int i)
|
||||
{
|
||||
x /= i;
|
||||
y /= i;
|
||||
return this;
|
||||
}
|
||||
/// (/=) overload
|
||||
Vector2 opDivAssign(int i)
|
||||
{
|
||||
x /= i;
|
||||
y /= i;
|
||||
return this;
|
||||
}
|
||||
|
||||
///
|
||||
const bool opEquals(ref const(Vector2) other)
|
||||
{
|
||||
return (x == other.x) && (y == other.y);
|
||||
}
|
||||
///
|
||||
const bool opEquals(ref const(Vector2) other)
|
||||
{
|
||||
return (x == other.x) && (y == other.y);
|
||||
}
|
||||
}
|
||||
|
||||
version (UnitTest)
|
||||
{
|
||||
unittest
|
||||
{
|
||||
Vector2f main = Vector2f(10f, 10f);
|
||||
Vector2f other = Vector2f(10f, 10f);
|
||||
Vector2f result;
|
||||
|
||||
result = -main;
|
||||
assert (result == Vector2f(-10.f, -10.f) );
|
||||
|
||||
result = main;
|
||||
result += other;
|
||||
assert (result == Vector2f(20.f, 20.f));
|
||||
|
||||
result = main;
|
||||
result -= other;
|
||||
assert (result == Vector2f(0.f, 0.f));
|
||||
|
||||
result = main + other;
|
||||
assert (result == Vector2f(20.f, 20.f));
|
||||
|
||||
result = main - other;
|
||||
assert (result == Vector2f(0.f, 0.f));
|
||||
|
||||
result = main * 10;
|
||||
assert (result == Vector2f(100.f, 100.f));
|
||||
|
||||
result *= 2;
|
||||
assert (result == Vector2f(200.f, 200.f));
|
||||
|
||||
result = main / 2;
|
||||
assert (result == Vector2f(5.f, 5.f));
|
||||
|
||||
result = main;
|
||||
result /= 2;
|
||||
assert (result == Vector2f(5.f, 5.f));
|
||||
}
|
||||
unittest
|
||||
{
|
||||
Vector2f main = Vector2f(10f, 10f);
|
||||
Vector2f other = Vector2f(10f, 10f);
|
||||
Vector2f result;
|
||||
|
||||
result = -main;
|
||||
assert (result == Vector2f(-10.f, -10.f) );
|
||||
|
||||
result = main;
|
||||
result += other;
|
||||
assert (result == Vector2f(20.f, 20.f));
|
||||
|
||||
result = main;
|
||||
result -= other;
|
||||
assert (result == Vector2f(0.f, 0.f));
|
||||
|
||||
result = main + other;
|
||||
assert (result == Vector2f(20.f, 20.f));
|
||||
|
||||
result = main - other;
|
||||
assert (result == Vector2f(0.f, 0.f));
|
||||
|
||||
result = main * 10;
|
||||
assert (result == Vector2f(100.f, 100.f));
|
||||
|
||||
result *= 2;
|
||||
assert (result == Vector2f(200.f, 200.f));
|
||||
|
||||
result = main / 2;
|
||||
assert (result == Vector2f(5.f, 5.f));
|
||||
|
||||
result = main;
|
||||
result /= 2;
|
||||
assert (result == Vector2f(5.f, 5.f));
|
||||
}
|
||||
}
|
||||
|
||||
/// Aliases
|
||||
|
|
|
@ -1,164 +1,164 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.system.vector3;
|
||||
|
||||
/**
|
||||
* Vector3 is an utility class for manipulating 3 dimensional
|
||||
* vectors. Template parameter defines the type of coordinates
|
||||
* (integer, float, ...)
|
||||
* Vector3 is an utility class for manipulating 3 dimensional
|
||||
* vectors. Template parameter defines the type of coordinates
|
||||
* (integer, float, ...)
|
||||
*/
|
||||
struct Vector3(T)
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
static Vector3 opCall(T x, T y, T z)
|
||||
{
|
||||
Vector3!(T) ret;
|
||||
|
||||
ret.x = x;
|
||||
ret.y = y;
|
||||
ret.z = z;
|
||||
|
||||
return ret;
|
||||
}
|
||||
static Vector3 opCall(T x, T y, T z)
|
||||
{
|
||||
Vector3!(T) ret;
|
||||
|
||||
ret.x = x;
|
||||
ret.y = y;
|
||||
ret.z = z;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// unary (-) overload
|
||||
Vector3 opNeg()
|
||||
{
|
||||
return Vector3!(T)(-x, -y, -z);
|
||||
}
|
||||
/// unary (-) overload
|
||||
Vector3 opNeg()
|
||||
{
|
||||
return Vector3!(T)(-x, -y, -z);
|
||||
}
|
||||
|
||||
/// (+=) overload
|
||||
Vector3 opAddAssign(Vector3 other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
z += other.z;
|
||||
return this;
|
||||
}
|
||||
/// (+=) overload
|
||||
Vector3 opAddAssign(Vector3 other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
z += other.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// (-=) overload
|
||||
Vector3 opSubAssign(Vector3 other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
z -= other.z;
|
||||
return this;
|
||||
}
|
||||
/// (-=) overload
|
||||
Vector3 opSubAssign(Vector3 other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
z -= other.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// (+) overload
|
||||
Vector3 opAdd(Vector3 other)
|
||||
{
|
||||
return Vector3!(T)( (x + other.x), (y + other.y), (z + other.z) );
|
||||
}
|
||||
/// (+) overload
|
||||
Vector3 opAdd(Vector3 other)
|
||||
{
|
||||
return Vector3!(T)( (x + other.x), (y + other.y), (z + other.z) );
|
||||
}
|
||||
|
||||
/// (-) overload
|
||||
Vector3 opSub(Vector3 other)
|
||||
{
|
||||
return Vector3!(T) ( (x - other.x), (y - other.y), (z - other.z) );
|
||||
}
|
||||
/// (-) overload
|
||||
Vector3 opSub(Vector3 other)
|
||||
{
|
||||
return Vector3!(T) ( (x - other.x), (y - other.y), (z - other.z) );
|
||||
}
|
||||
|
||||
/// (*) overload
|
||||
Vector3 opMul(int i)
|
||||
{
|
||||
return Vector3!(T) ( (x * i), (y * i), (z * i) );
|
||||
}
|
||||
/// (*) overload
|
||||
Vector3 opMul(int i)
|
||||
{
|
||||
return Vector3!(T) ( (x * i), (y * i), (z * i) );
|
||||
}
|
||||
|
||||
/// (*=) overload
|
||||
Vector3 opMulAssign(int i)
|
||||
{
|
||||
x *= i;
|
||||
y *= i;
|
||||
z *= i;
|
||||
return this;
|
||||
}
|
||||
/// (*=) overload
|
||||
Vector3 opMulAssign(int i)
|
||||
{
|
||||
x *= i;
|
||||
y *= i;
|
||||
z *= i;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// (/) overload
|
||||
Vector3 opDiv(int i)
|
||||
{
|
||||
return Vector3!(T) ( (x / i), (y / i), (z / i) );
|
||||
}
|
||||
/// (/) overload
|
||||
Vector3 opDiv(int i)
|
||||
{
|
||||
return Vector3!(T) ( (x / i), (y / i), (z / i) );
|
||||
}
|
||||
|
||||
/// (/=) overload
|
||||
Vector3 opDivAssign(int i)
|
||||
{
|
||||
x /= i;
|
||||
y /= i;
|
||||
z /= i;
|
||||
return this;
|
||||
}
|
||||
/// (/=) overload
|
||||
Vector3 opDivAssign(int i)
|
||||
{
|
||||
x /= i;
|
||||
y /= i;
|
||||
z /= i;
|
||||
return this;
|
||||
}
|
||||
|
||||
///
|
||||
const bool opEquals(ref const(Vector3) other)
|
||||
{
|
||||
return (x == other.x) && (y == other.y) && (z == other.z) ;
|
||||
}
|
||||
///
|
||||
const bool opEquals(ref const(Vector3) other)
|
||||
{
|
||||
return (x == other.x) && (y == other.y) && (z == other.z) ;
|
||||
}
|
||||
}
|
||||
|
||||
version (UnitTest)
|
||||
{
|
||||
unittest
|
||||
{
|
||||
Vector3f main = Vector3f(10f, 10f, 10.f);
|
||||
Vector3f other = Vector3f(10f, 10f, 10.f);
|
||||
Vector3f result;
|
||||
|
||||
result = -main;
|
||||
assert (result == Vector3f(-10.f, -10.f, -10.f) );
|
||||
|
||||
result = main;
|
||||
result += other;
|
||||
assert (result == Vector3f(20.f, 20.f, 20.f));
|
||||
|
||||
result = main;
|
||||
result -= other;
|
||||
assert (result == Vector3f(0.f, 0.f, 0.f));
|
||||
|
||||
result = main + other;
|
||||
assert (result == Vector3f(20.f, 20.f, 20.f));
|
||||
|
||||
result = main - other;
|
||||
assert (result == Vector3f(0.f, 0.f, 0.f));
|
||||
|
||||
result = main * 10;
|
||||
assert (result == Vector3f(100.f, 100.f, 100.f));
|
||||
|
||||
result *= 2;
|
||||
assert (result == Vector3f(200.f, 200.f, 200.f));
|
||||
|
||||
result = main / 2;
|
||||
assert (result == Vector3f(5.f, 5.f, 5.f));
|
||||
|
||||
result = main;
|
||||
result /= 2;
|
||||
assert (result == Vector3f(5.f, 5.f, 5.f));
|
||||
}
|
||||
unittest
|
||||
{
|
||||
Vector3f main = Vector3f(10f, 10f, 10.f);
|
||||
Vector3f other = Vector3f(10f, 10f, 10.f);
|
||||
Vector3f result;
|
||||
|
||||
result = -main;
|
||||
assert (result == Vector3f(-10.f, -10.f, -10.f) );
|
||||
|
||||
result = main;
|
||||
result += other;
|
||||
assert (result == Vector3f(20.f, 20.f, 20.f));
|
||||
|
||||
result = main;
|
||||
result -= other;
|
||||
assert (result == Vector3f(0.f, 0.f, 0.f));
|
||||
|
||||
result = main + other;
|
||||
assert (result == Vector3f(20.f, 20.f, 20.f));
|
||||
|
||||
result = main - other;
|
||||
assert (result == Vector3f(0.f, 0.f, 0.f));
|
||||
|
||||
result = main * 10;
|
||||
assert (result == Vector3f(100.f, 100.f, 100.f));
|
||||
|
||||
result *= 2;
|
||||
assert (result == Vector3f(200.f, 200.f, 200.f));
|
||||
|
||||
result = main / 2;
|
||||
assert (result == Vector3f(5.f, 5.f, 5.f));
|
||||
|
||||
result = main;
|
||||
result /= 2;
|
||||
assert (result == Vector3f(5.f, 5.f, 5.f));
|
||||
}
|
||||
}
|
||||
|
||||
/// Aliases
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.all;
|
||||
|
||||
public import
|
||||
dsfml.window.event,
|
||||
dsfml.window.event,
|
||||
dsfml.window.input,
|
||||
dsfml.window.videomode,
|
||||
dsfml.window.window,
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.common;
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.context;
|
||||
|
@ -49,7 +49,7 @@ class Context : DSFMLObject
|
|||
/**
|
||||
*
|
||||
* Params:
|
||||
* active =
|
||||
* active =
|
||||
*/
|
||||
void setActive(bool active)
|
||||
{
|
||||
|
|
|
@ -1,329 +1,329 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.event;
|
||||
|
||||
/**
|
||||
* Definition of key codes for keyboard events
|
||||
*
|
||||
* $(B Possibles values:)$(BR)
|
||||
* Except letters and numbers, you can use :$(BR)
|
||||
* * LCONTROL, LSHIFT, LALT, LSYSTEM, RCONTROL, RSHIFT, RALT, RSYSTEM.$(BR)
|
||||
* * LBRACKET, RBRACKET, SEMICOLON, COMMA, PERIOD, QUOTE, SLASH, BACKSLASH, TILDE, EQUAL, DASH.$(BR)
|
||||
* * SPACE, RETURN, BACK, TAB, PAGEUP, PAGEDOWN, END, HOME, INSERT, DELETE.$(BR)
|
||||
* * ADD, SUBTRACT, MULTIPLY, DIVIDE, LEFT, RIGHT, UP, DOWN.$(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)
|
||||
* Definition of key codes for keyboard events
|
||||
*
|
||||
* $(B Possibles values:)$(BR)
|
||||
* Except letters and numbers, you can use :$(BR)
|
||||
* * LCONTROL, LSHIFT, LALT, LSYSTEM, RCONTROL, RSHIFT, RALT, RSYSTEM.$(BR)
|
||||
* * LBRACKET, RBRACKET, SEMICOLON, COMMA, PERIOD, QUOTE, SLASH, BACKSLASH, TILDE, EQUAL, DASH.$(BR)
|
||||
* * SPACE, RETURN, BACK, TAB, PAGEUP, PAGEDOWN, END, HOME, INSERT, DELETE.$(BR)
|
||||
* * ADD, SUBTRACT, MULTIPLY, DIVIDE, LEFT, RIGHT, UP, DOWN.$(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)
|
||||
*/
|
||||
enum KeyCode
|
||||
{
|
||||
A = 'a',
|
||||
B = 'b',
|
||||
C = 'c',
|
||||
D = 'd',
|
||||
E = 'e',
|
||||
F = 'f',
|
||||
G = 'g',
|
||||
H = 'h',
|
||||
I = 'i',
|
||||
J = 'j',
|
||||
K = 'k',
|
||||
L = 'l',
|
||||
M = 'm',
|
||||
N = 'n',
|
||||
O = 'o',
|
||||
P = 'p',
|
||||
Q = 'q',
|
||||
R = 'r',
|
||||
S = 's',
|
||||
T = 't',
|
||||
U = 'u',
|
||||
V = 'v',
|
||||
W = 'w',
|
||||
X = 'x',
|
||||
Y = 'y',
|
||||
Z = 'z',
|
||||
NUM0 = '0',
|
||||
NUM1 = '1',
|
||||
NUM2 = '2',
|
||||
NUM3 = '3',
|
||||
NUM4 = '4',
|
||||
NUM5 = '5',
|
||||
NUM6 = '6',
|
||||
NUM7 = '7',
|
||||
NUM8 = '8',
|
||||
NUM9 = '9',
|
||||
ESCAPE = 256,
|
||||
LCONTROL,
|
||||
LSHIFT,
|
||||
LALT,
|
||||
LSYSTEM,
|
||||
RCONTROL,
|
||||
RSHIFT,
|
||||
RALT,
|
||||
RSYSTEM,
|
||||
MENU,
|
||||
LBRACKET,
|
||||
RBRACKET,
|
||||
SEMICOLON,
|
||||
COMMA,
|
||||
PERIOD,
|
||||
QUOTE,
|
||||
SLASH,
|
||||
BACKSLASH,
|
||||
TILDE,
|
||||
EQUAL,
|
||||
DASH,
|
||||
SPACE,
|
||||
RETURN,
|
||||
BACK,
|
||||
TAB,
|
||||
PAGEUP,
|
||||
PAGEDOWN,
|
||||
END,
|
||||
HOME,
|
||||
INSERT,
|
||||
DELETE,
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
MULTIPLY,
|
||||
DIVIDE,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN,
|
||||
NUMPAD0,
|
||||
NUMPAD1,
|
||||
NUMPAD2,
|
||||
NUMPAD3,
|
||||
NUMPAD4,
|
||||
NUMPAD5,
|
||||
NUMPAD6,
|
||||
NUMPAD7,
|
||||
NUMPAD8,
|
||||
NUMPAD9,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
F13,
|
||||
F14,
|
||||
F15,
|
||||
PAUSE,
|
||||
A = 'a',
|
||||
B = 'b',
|
||||
C = 'c',
|
||||
D = 'd',
|
||||
E = 'e',
|
||||
F = 'f',
|
||||
G = 'g',
|
||||
H = 'h',
|
||||
I = 'i',
|
||||
J = 'j',
|
||||
K = 'k',
|
||||
L = 'l',
|
||||
M = 'm',
|
||||
N = 'n',
|
||||
O = 'o',
|
||||
P = 'p',
|
||||
Q = 'q',
|
||||
R = 'r',
|
||||
S = 's',
|
||||
T = 't',
|
||||
U = 'u',
|
||||
V = 'v',
|
||||
W = 'w',
|
||||
X = 'x',
|
||||
Y = 'y',
|
||||
Z = 'z',
|
||||
NUM0 = '0',
|
||||
NUM1 = '1',
|
||||
NUM2 = '2',
|
||||
NUM3 = '3',
|
||||
NUM4 = '4',
|
||||
NUM5 = '5',
|
||||
NUM6 = '6',
|
||||
NUM7 = '7',
|
||||
NUM8 = '8',
|
||||
NUM9 = '9',
|
||||
ESCAPE = 256,
|
||||
LCONTROL,
|
||||
LSHIFT,
|
||||
LALT,
|
||||
LSYSTEM,
|
||||
RCONTROL,
|
||||
RSHIFT,
|
||||
RALT,
|
||||
RSYSTEM,
|
||||
MENU,
|
||||
LBRACKET,
|
||||
RBRACKET,
|
||||
SEMICOLON,
|
||||
COMMA,
|
||||
PERIOD,
|
||||
QUOTE,
|
||||
SLASH,
|
||||
BACKSLASH,
|
||||
TILDE,
|
||||
EQUAL,
|
||||
DASH,
|
||||
SPACE,
|
||||
RETURN,
|
||||
BACK,
|
||||
TAB,
|
||||
PAGEUP,
|
||||
PAGEDOWN,
|
||||
END,
|
||||
HOME,
|
||||
INSERT,
|
||||
DELETE,
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
MULTIPLY,
|
||||
DIVIDE,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN,
|
||||
NUMPAD0,
|
||||
NUMPAD1,
|
||||
NUMPAD2,
|
||||
NUMPAD3,
|
||||
NUMPAD4,
|
||||
NUMPAD5,
|
||||
NUMPAD6,
|
||||
NUMPAD7,
|
||||
NUMPAD8,
|
||||
NUMPAD9,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
F13,
|
||||
F14,
|
||||
F15,
|
||||
PAUSE,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Definition of button codes for mouse events
|
||||
* Definition of button codes for mouse events
|
||||
*/
|
||||
enum MouseButtons
|
||||
{
|
||||
LEFT, ///
|
||||
RIGHT, ///
|
||||
MIDDLE, ///
|
||||
XBUTTON1, ///
|
||||
XBUTTON2 ///
|
||||
LEFT, ///
|
||||
RIGHT, ///
|
||||
MIDDLE, ///
|
||||
XBUTTON1, ///
|
||||
XBUTTON2 ///
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Definition of joystick axis for joystick events
|
||||
* Definition of joystick axis for joystick events
|
||||
*/
|
||||
enum JoyAxis
|
||||
{
|
||||
AXISX, ///
|
||||
AXISY, ///
|
||||
AXISZ, ///
|
||||
AXISR, ///
|
||||
AXISU, ///
|
||||
AXISV, ///
|
||||
AXISPOV ///
|
||||
AXISX, ///
|
||||
AXISY, ///
|
||||
AXISZ, ///
|
||||
AXISR, ///
|
||||
AXISU, ///
|
||||
AXISV, ///
|
||||
AXISPOV ///
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Event defines a system event and its parameters
|
||||
* Event defines a system event and its parameters
|
||||
*/
|
||||
align(1) struct Event
|
||||
{
|
||||
enum EventType
|
||||
{
|
||||
CLOSED,
|
||||
RESIZED,
|
||||
LOSTFOCUS,
|
||||
GAINEDFOCUS,
|
||||
TEXTENTERED,
|
||||
KEYPRESSED,
|
||||
KEYRELEASED,
|
||||
MOUSEWHEELMOVED,
|
||||
MOUSEBUTTONPRESSED,
|
||||
MOUSEBUTTONRELEASED,
|
||||
MOUSEMOVED,
|
||||
MOUSEENTERED,
|
||||
MOUSELEFT,
|
||||
JOYBUTTONPRESSED,
|
||||
JOYBUTTONRELEASED,
|
||||
JOYMOVED
|
||||
}
|
||||
enum EventType
|
||||
{
|
||||
CLOSED,
|
||||
RESIZED,
|
||||
LOSTFOCUS,
|
||||
GAINEDFOCUS,
|
||||
TEXTENTERED,
|
||||
KEYPRESSED,
|
||||
KEYRELEASED,
|
||||
MOUSEWHEELMOVED,
|
||||
MOUSEBUTTONPRESSED,
|
||||
MOUSEBUTTONRELEASED,
|
||||
MOUSEMOVED,
|
||||
MOUSEENTERED,
|
||||
MOUSELEFT,
|
||||
JOYBUTTONPRESSED,
|
||||
JOYBUTTONRELEASED,
|
||||
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.
|
||||
* $(UL
|
||||
* $(LI CLOSED)
|
||||
* $(LI LOSTFOCUS)
|
||||
* $(LI GAINEDFOCUS)
|
||||
* $(LI RESIZED
|
||||
* $(UL
|
||||
* $(LI Event.Size.Width : new Width, in pixels.)
|
||||
* $(LI Event.Size.Height : new height, in pixels.)
|
||||
* )
|
||||
* )
|
||||
* $(LI TEXTENTERED
|
||||
* $(UL
|
||||
* $(LI Event.Text.Unicode : dchar entered.)
|
||||
* )
|
||||
* )
|
||||
* $(LI KEYPRESSED, KEYRELEASED
|
||||
* $(UL
|
||||
* $(LI Event.Key.Code : Key code of the key.)
|
||||
* $(LI Event.Key.Alt : Alt pressed ?)
|
||||
* $(LI Event.Key.Control : Control pressed ?)
|
||||
* $(LI Event.Key.Shift : Shift pressed ?)
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEWHEELMOVED
|
||||
* $(UL
|
||||
* $(LI Event.MouseWheel.Delta : Wheel move (positive if forward, negative else.) )
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEBUTTONPRESSED, MOUSEBUTTONRELEASED
|
||||
* $(UL
|
||||
* $(LI Event.MouseButton.Button : Mouse button pressed.)
|
||||
* $(LI Event.MouseButton.X : Cursor X position.)
|
||||
* $(LI Event.MouseButton.Y : Cursor X position.)
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEMOVED
|
||||
* $(UL
|
||||
* $(LI Event.MouseMove.X : Cursor X position. Local coordinates.)
|
||||
* $(LI Event.MouseMove.Y : Cursor Y position. Local coordinates.)
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEENTERED)
|
||||
* $(LI MOUSELEFT)
|
||||
* $(LI JOYBUTTONPRESSED, JOYBUTTONRELEASED
|
||||
* $(UL
|
||||
* $(LI Event.JoyButton.JoystickId : Id of the joystick.)
|
||||
* $(LI Event.JoyButton.Button : Joystick button pressed.)
|
||||
* )
|
||||
* )
|
||||
* $(LI JOYMOVED
|
||||
* $(UL
|
||||
* $(LI Event.JoyMove.JoystickId : Id of the joystick.)
|
||||
* $(LI Event.JoyMove.Axis : Moved axis.)
|
||||
* $(LI Event.JoyMove.Position : Actual position of the axis [-100, 100], except for POV [0, 360].)
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
EventType Type;
|
||||
|
||||
union
|
||||
{
|
||||
struct SText
|
||||
{
|
||||
dchar Unicode;
|
||||
}
|
||||
SText Text;
|
||||
|
||||
struct SKey
|
||||
{
|
||||
KeyCode Code;
|
||||
bool Alt;
|
||||
byte[3] Filler1;
|
||||
bool Control;
|
||||
byte[3] Filler2;
|
||||
bool Shift;
|
||||
byte[3] Filler3;
|
||||
}
|
||||
SKey Key;
|
||||
|
||||
struct SMouseMove
|
||||
{
|
||||
int X;
|
||||
int Y;
|
||||
}
|
||||
SMouseMove MouseMove;
|
||||
|
||||
struct SMouseButton
|
||||
{
|
||||
MouseButtons Button;
|
||||
int X;
|
||||
int Y;
|
||||
}
|
||||
SMouseButton MouseButton;
|
||||
|
||||
struct SMouseWheel
|
||||
{
|
||||
int Delta;
|
||||
}
|
||||
SMouseWheel MouseWheel;
|
||||
|
||||
struct SJoyMove
|
||||
{
|
||||
uint JoystickId;
|
||||
JoyAxis Axis;
|
||||
float Position;
|
||||
}
|
||||
SJoyMove JoyMove;
|
||||
|
||||
struct SJoyButton
|
||||
{
|
||||
uint JoystickId;
|
||||
uint Button;
|
||||
}
|
||||
SJoyButton JoyButton;
|
||||
|
||||
struct SSize
|
||||
{
|
||||
uint Width;
|
||||
uint Height;
|
||||
}
|
||||
SSize Size;
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
* $(LI CLOSED)
|
||||
* $(LI LOSTFOCUS)
|
||||
* $(LI GAINEDFOCUS)
|
||||
* $(LI RESIZED
|
||||
* $(UL
|
||||
* $(LI Event.Size.Width : new Width, in pixels.)
|
||||
* $(LI Event.Size.Height : new height, in pixels.)
|
||||
* )
|
||||
* )
|
||||
* $(LI TEXTENTERED
|
||||
* $(UL
|
||||
* $(LI Event.Text.Unicode : dchar entered.)
|
||||
* )
|
||||
* )
|
||||
* $(LI KEYPRESSED, KEYRELEASED
|
||||
* $(UL
|
||||
* $(LI Event.Key.Code : Key code of the key.)
|
||||
* $(LI Event.Key.Alt : Alt pressed ?)
|
||||
* $(LI Event.Key.Control : Control pressed ?)
|
||||
* $(LI Event.Key.Shift : Shift pressed ?)
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEWHEELMOVED
|
||||
* $(UL
|
||||
* $(LI Event.MouseWheel.Delta : Wheel move (positive if forward, negative else.) )
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEBUTTONPRESSED, MOUSEBUTTONRELEASED
|
||||
* $(UL
|
||||
* $(LI Event.MouseButton.Button : Mouse button pressed.)
|
||||
* $(LI Event.MouseButton.X : Cursor X position.)
|
||||
* $(LI Event.MouseButton.Y : Cursor X position.)
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEMOVED
|
||||
* $(UL
|
||||
* $(LI Event.MouseMove.X : Cursor X position. Local coordinates.)
|
||||
* $(LI Event.MouseMove.Y : Cursor Y position. Local coordinates.)
|
||||
* )
|
||||
* )
|
||||
* $(LI MOUSEENTERED)
|
||||
* $(LI MOUSELEFT)
|
||||
* $(LI JOYBUTTONPRESSED, JOYBUTTONRELEASED
|
||||
* $(UL
|
||||
* $(LI Event.JoyButton.JoystickId : Id of the joystick.)
|
||||
* $(LI Event.JoyButton.Button : Joystick button pressed.)
|
||||
* )
|
||||
* )
|
||||
* $(LI JOYMOVED
|
||||
* $(UL
|
||||
* $(LI Event.JoyMove.JoystickId : Id of the joystick.)
|
||||
* $(LI Event.JoyMove.Axis : Moved axis.)
|
||||
* $(LI Event.JoyMove.Position : Actual position of the axis [-100, 100], except for POV [0, 360].)
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
EventType Type;
|
||||
|
||||
union
|
||||
{
|
||||
struct SText
|
||||
{
|
||||
dchar Unicode;
|
||||
}
|
||||
SText Text;
|
||||
|
||||
struct SKey
|
||||
{
|
||||
KeyCode Code;
|
||||
bool Alt;
|
||||
byte[3] Filler1;
|
||||
bool Control;
|
||||
byte[3] Filler2;
|
||||
bool Shift;
|
||||
byte[3] Filler3;
|
||||
}
|
||||
SKey Key;
|
||||
|
||||
struct SMouseMove
|
||||
{
|
||||
int X;
|
||||
int Y;
|
||||
}
|
||||
SMouseMove MouseMove;
|
||||
|
||||
struct SMouseButton
|
||||
{
|
||||
MouseButtons Button;
|
||||
int X;
|
||||
int Y;
|
||||
}
|
||||
SMouseButton MouseButton;
|
||||
|
||||
struct SMouseWheel
|
||||
{
|
||||
int Delta;
|
||||
}
|
||||
SMouseWheel MouseWheel;
|
||||
|
||||
struct SJoyMove
|
||||
{
|
||||
uint JoystickId;
|
||||
JoyAxis Axis;
|
||||
float Position;
|
||||
}
|
||||
SJoyMove JoyMove;
|
||||
|
||||
struct SJoyButton
|
||||
{
|
||||
uint JoystickId;
|
||||
uint Button;
|
||||
}
|
||||
SJoyButton JoyButton;
|
||||
|
||||
struct SSize
|
||||
{
|
||||
uint Width;
|
||||
uint Height;
|
||||
}
|
||||
SSize Size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.input;
|
||||
|
@ -31,136 +31,136 @@ import dsfml.system.common;
|
|||
import dsfml.window.event;
|
||||
|
||||
/**
|
||||
* Input handles real-time input from keyboard and mouse.
|
||||
* Use it instead of events to handle continuous moves and more
|
||||
* game-friendly inputs
|
||||
* Input handles real-time input from keyboard and mouse.
|
||||
* Use it instead of events to handle continuous moves and more
|
||||
* game-friendly inputs
|
||||
*/
|
||||
class Input : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Get the state of a key
|
||||
*
|
||||
* Params:
|
||||
* key = Key to check
|
||||
*
|
||||
* Returns:
|
||||
* True if key is down, false if key is up
|
||||
*/
|
||||
bool isKeyDown(KeyCode key)
|
||||
/**
|
||||
* Get the state of a key
|
||||
*
|
||||
* Params:
|
||||
* key = Key to check
|
||||
*
|
||||
* Returns:
|
||||
* True if key is down, false if key is up
|
||||
*/
|
||||
bool isKeyDown(KeyCode key)
|
||||
{
|
||||
return cast(bool)sfInput_IsKeyDown(m_ptr, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of a mouse button
|
||||
*
|
||||
* Params:
|
||||
* button = Button to check
|
||||
*
|
||||
* Returns:
|
||||
* True if button is down, false if button is up
|
||||
*/
|
||||
bool isMouseButtonDown(MouseButtons button)
|
||||
/**
|
||||
* Get the state of a mouse button
|
||||
*
|
||||
* Params:
|
||||
* button = Button to check
|
||||
*
|
||||
* Returns:
|
||||
* True if button is down, false if button is up
|
||||
*/
|
||||
bool isMouseButtonDown(MouseButtons button)
|
||||
{
|
||||
return cast(bool)sfInput_IsMouseButtonDown(m_ptr, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of a joystick button
|
||||
*
|
||||
* Params:
|
||||
* joyId = Identifier of the joystick to check (0 or 1)
|
||||
* button = Button to check
|
||||
*
|
||||
* Returns:
|
||||
* True if button is down, false if button is up
|
||||
*/
|
||||
bool isJoystickButtonDown(uint joyId, uint button)
|
||||
/**
|
||||
* Get the state of a joystick button
|
||||
*
|
||||
* Params:
|
||||
* joyId = Identifier of the joystick to check (0 or 1)
|
||||
* button = Button to check
|
||||
*
|
||||
* Returns:
|
||||
* True if button is down, false if button is up
|
||||
*/
|
||||
bool isJoystickButtonDown(uint joyId, uint button)
|
||||
{
|
||||
return cast(bool)sfInput_IsJoystickButtonDown(m_ptr, joyId, button);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the mouse X position
|
||||
*
|
||||
* Returns:
|
||||
* Current mouse left position, relative to owner window
|
||||
*/
|
||||
int getMouseX()
|
||||
/*
|
||||
* Get the mouse X position
|
||||
*
|
||||
* Returns:
|
||||
* Current mouse left position, relative to owner window
|
||||
*/
|
||||
int getMouseX()
|
||||
{
|
||||
return sfInput_GetMouseX(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mouse Y position
|
||||
*
|
||||
* Returns:
|
||||
* Current mouse top position, relative to owner window
|
||||
*
|
||||
*/
|
||||
int getMouseY()
|
||||
/**
|
||||
* Get the mouse Y position
|
||||
*
|
||||
* Returns:
|
||||
* Current mouse top position, relative to owner window
|
||||
*
|
||||
*/
|
||||
int getMouseY()
|
||||
{
|
||||
return sfInput_GetMouseY(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a joystick axis position
|
||||
*
|
||||
* Params:
|
||||
* joyId = Identifier of the joystick to check (0 or 1)
|
||||
* axis = Axis to get
|
||||
*
|
||||
* Returns:
|
||||
* Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])
|
||||
*/
|
||||
float getJoystickAxis(uint joyId, JoyAxis axis)
|
||||
/**
|
||||
* Get a joystick axis position
|
||||
*
|
||||
* Params:
|
||||
* joyId = Identifier of the joystick to check (0 or 1)
|
||||
* axis = Axis to get
|
||||
*
|
||||
* Returns:
|
||||
* Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])
|
||||
*/
|
||||
float getJoystickAxis(uint joyId, JoyAxis axis)
|
||||
{
|
||||
return sfInput_GetJoystickAxis(m_ptr, joyId, axis);
|
||||
}
|
||||
|
||||
this(void* input)
|
||||
this(void* input)
|
||||
{
|
||||
super(input, true);
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// External ====================================================================
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef int function(void*, KeyCode) pf_sfInput_IsKeyDown;
|
||||
typedef int function(void*, MouseButtons) pf_sfInput_IsMouseButtonDown;
|
||||
typedef int function(void*, uint, uint) pf_sfInput_IsJoystickButtonDown;
|
||||
typedef uint function (void*) pf_sfInput_GetMouseX;
|
||||
typedef uint function(void*) pf_sfInput_GetMouseY;
|
||||
typedef float function(void*, uint, JoyAxis) pf_sfInput_GetJoystickAxis;
|
||||
|
||||
static pf_sfInput_IsKeyDown sfInput_IsKeyDown;
|
||||
static pf_sfInput_IsMouseButtonDown sfInput_IsMouseButtonDown;
|
||||
static pf_sfInput_IsJoystickButtonDown sfInput_IsJoystickButtonDown;
|
||||
static pf_sfInput_GetMouseX sfInput_GetMouseX;
|
||||
static pf_sfInput_GetMouseY sfInput_GetMouseY;
|
||||
static pf_sfInput_GetJoystickAxis sfInput_GetJoystickAxis;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef int function(void*, KeyCode) pf_sfInput_IsKeyDown;
|
||||
typedef int function(void*, MouseButtons) pf_sfInput_IsMouseButtonDown;
|
||||
typedef int function(void*, uint, uint) pf_sfInput_IsJoystickButtonDown;
|
||||
typedef uint function (void*) pf_sfInput_GetMouseX;
|
||||
typedef uint function(void*) pf_sfInput_GetMouseY;
|
||||
typedef float function(void*, uint, JoyAxis) pf_sfInput_GetJoystickAxis;
|
||||
|
||||
static pf_sfInput_IsKeyDown sfInput_IsKeyDown;
|
||||
static pf_sfInput_IsMouseButtonDown sfInput_IsMouseButtonDown;
|
||||
static pf_sfInput_IsJoystickButtonDown sfInput_IsJoystickButtonDown;
|
||||
static pf_sfInput_GetMouseX sfInput_GetMouseX;
|
||||
static pf_sfInput_GetMouseY sfInput_GetMouseY;
|
||||
static pf_sfInput_GetJoystickAxis sfInput_GetJoystickAxis;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-window-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-window");
|
||||
|
||||
sfInput_IsKeyDown = cast(pf_sfInput_IsKeyDown)dll.getSymbol("sfInput_IsKeyDown");
|
||||
sfInput_IsMouseButtonDown = cast(pf_sfInput_IsMouseButtonDown)dll.getSymbol("sfInput_IsMouseButtonDown");
|
||||
sfInput_IsJoystickButtonDown = cast(pf_sfInput_IsJoystickButtonDown)dll.getSymbol("sfInput_IsJoystickButtonDown");
|
||||
sfInput_GetMouseX = cast(pf_sfInput_GetMouseX)dll.getSymbol("sfInput_GetMouseX");
|
||||
sfInput_GetMouseY = cast(pf_sfInput_GetMouseY)dll.getSymbol("sfInput_GetMouseY");
|
||||
sfInput_GetJoystickAxis = cast(pf_sfInput_GetJoystickAxis)dll.getSymbol("sfInput_GetJoystickAxis");
|
||||
}
|
||||
|
||||
sfInput_IsKeyDown = cast(pf_sfInput_IsKeyDown)dll.getSymbol("sfInput_IsKeyDown");
|
||||
sfInput_IsMouseButtonDown = cast(pf_sfInput_IsMouseButtonDown)dll.getSymbol("sfInput_IsMouseButtonDown");
|
||||
sfInput_IsJoystickButtonDown = cast(pf_sfInput_IsJoystickButtonDown)dll.getSymbol("sfInput_IsJoystickButtonDown");
|
||||
sfInput_GetMouseX = cast(pf_sfInput_GetMouseX)dll.getSymbol("sfInput_GetMouseX");
|
||||
sfInput_GetMouseY = cast(pf_sfInput_GetMouseY)dll.getSymbol("sfInput_GetMouseY");
|
||||
sfInput_GetJoystickAxis = cast(pf_sfInput_GetJoystickAxis)dll.getSymbol("sfInput_GetJoystickAxis");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.videomode;
|
||||
|
@ -29,9 +29,9 @@ module dsfml.window.videomode;
|
|||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* VideoMode defines a video mode (width, height, bpp, frequency)
|
||||
* and provides static functions for getting modes supported
|
||||
* by the display device
|
||||
* VideoMode defines a video mode (width, height, bpp, frequency)
|
||||
* and provides static functions for getting modes supported
|
||||
* by the display device
|
||||
*/
|
||||
align(1) struct VideoMode
|
||||
{
|
||||
|
@ -39,81 +39,81 @@ align(1) struct VideoMode
|
|||
uint Height; /// Video mode height, in pixels
|
||||
uint BitsPerPixel = 32; /// Video mode pixel depth, in bits per pixels
|
||||
|
||||
/**
|
||||
* Get the current desktop video mode
|
||||
*
|
||||
* Returns:
|
||||
* Current desktop video mode
|
||||
*/
|
||||
static VideoMode getDesktopMode()
|
||||
{
|
||||
return sfVideoMode_GetDesktopMode();
|
||||
}
|
||||
/**
|
||||
* Get the current desktop video mode
|
||||
*
|
||||
* Returns:
|
||||
* Current desktop video mode
|
||||
*/
|
||||
static VideoMode getDesktopMode()
|
||||
{
|
||||
return sfVideoMode_GetDesktopMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a valid video mode
|
||||
* Index must be in range [0, GetModesCount()[
|
||||
* Modes are sorted from best to worst
|
||||
*
|
||||
* Params:
|
||||
* index = Index of video mode to get
|
||||
*
|
||||
* Returns:
|
||||
* Corresponding video mode (invalid mode if index is out of range)
|
||||
*/
|
||||
static VideoMode getMode(size_t index)
|
||||
{
|
||||
return sfVideoMode_GetMode(index);
|
||||
}
|
||||
/**
|
||||
* Get a valid video mode
|
||||
* Index must be in range [0, GetModesCount()[
|
||||
* Modes are sorted from best to worst
|
||||
*
|
||||
* Params:
|
||||
* index = Index of video mode to get
|
||||
*
|
||||
* Returns:
|
||||
* Corresponding video mode (invalid mode if index is out of range)
|
||||
*/
|
||||
static VideoMode getMode(size_t index)
|
||||
{
|
||||
return sfVideoMode_GetMode(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid video modes count
|
||||
*
|
||||
* Returns:
|
||||
* Number of valid video modes available
|
||||
*/
|
||||
static size_t getModesCount()
|
||||
{
|
||||
return sfVideoMode_GetModesCount();
|
||||
}
|
||||
/**
|
||||
* Get valid video modes count
|
||||
*
|
||||
* Returns:
|
||||
* Number of valid video modes available
|
||||
*/
|
||||
static size_t getModesCount()
|
||||
{
|
||||
return sfVideoMode_GetModesCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether or not the video mode is supported
|
||||
*
|
||||
* Returns:
|
||||
* True if video mode is supported, false otherwise
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfVideoMode_IsValid(this);
|
||||
}
|
||||
/**
|
||||
* Tell whether or not the video mode is supported
|
||||
*
|
||||
* Returns:
|
||||
* True if video mode is supported, false otherwise
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfVideoMode_IsValid(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison operator overload -- tell if two video modes are equal
|
||||
*
|
||||
* Params:
|
||||
* Other : Video mode to compare
|
||||
*
|
||||
* Returns:
|
||||
* True if modes are equal
|
||||
*/
|
||||
const bool opEquals(ref const(VideoMode) other)
|
||||
{
|
||||
return ((other.Width == Width) && (other.Height == Height) && (other.BitsPerPixel == BitsPerPixel));
|
||||
}
|
||||
/**
|
||||
* Comparison operator overload -- tell if two video modes are equal
|
||||
*
|
||||
* Params:
|
||||
* Other : Video mode to compare
|
||||
*
|
||||
* Returns:
|
||||
* True if modes are equal
|
||||
*/
|
||||
const bool opEquals(ref const(VideoMode) other)
|
||||
{
|
||||
return ((other.Width == Width) && (other.Height == Height) && (other.BitsPerPixel == BitsPerPixel));
|
||||
}
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef VideoMode function() pf_sfVideoMode_GetDesktopMode;
|
||||
typedef VideoMode function(size_t) pf_sfVideoMode_GetMode;
|
||||
typedef size_t function() pf_sfVideoMode_GetModesCount;
|
||||
typedef int function(VideoMode) pf_sfVideoMode_IsValid;
|
||||
|
||||
pf_sfVideoMode_GetDesktopMode sfVideoMode_GetDesktopMode;
|
||||
pf_sfVideoMode_GetMode sfVideoMode_GetMode;
|
||||
pf_sfVideoMode_GetModesCount sfVideoMode_GetModesCount;
|
||||
pf_sfVideoMode_IsValid sfVideoMode_IsValid;
|
||||
typedef VideoMode function() pf_sfVideoMode_GetDesktopMode;
|
||||
typedef VideoMode function(size_t) pf_sfVideoMode_GetMode;
|
||||
typedef size_t function() pf_sfVideoMode_GetModesCount;
|
||||
typedef int function(VideoMode) pf_sfVideoMode_IsValid;
|
||||
|
||||
pf_sfVideoMode_GetDesktopMode sfVideoMode_GetDesktopMode;
|
||||
pf_sfVideoMode_GetMode sfVideoMode_GetMode;
|
||||
pf_sfVideoMode_GetModesCount sfVideoMode_GetModesCount;
|
||||
pf_sfVideoMode_IsValid sfVideoMode_IsValid;
|
||||
}
|
||||
|
||||
static this()
|
||||
|
@ -122,11 +122,11 @@ static this()
|
|||
DllLoader dll = DllLoader.load("csfml-window-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-window");
|
||||
|
||||
sfVideoMode_GetDesktopMode = cast(pf_sfVideoMode_GetDesktopMode)dll.getSymbol("sfVideoMode_GetDesktopMode");
|
||||
sfVideoMode_GetMode = cast(pf_sfVideoMode_GetMode)dll.getSymbol("sfVideoMode_GetMode");
|
||||
sfVideoMode_GetModesCount = cast(pf_sfVideoMode_GetModesCount)dll.getSymbol("sfVideoMode_GetModesCount");
|
||||
sfVideoMode_IsValid = cast(pf_sfVideoMode_IsValid)dll.getSymbol("sfVideoMode_IsValid");
|
||||
|
||||
sfVideoMode_GetDesktopMode = cast(pf_sfVideoMode_GetDesktopMode)dll.getSymbol("sfVideoMode_GetDesktopMode");
|
||||
sfVideoMode_GetMode = cast(pf_sfVideoMode_GetMode)dll.getSymbol("sfVideoMode_GetMode");
|
||||
sfVideoMode_GetModesCount = cast(pf_sfVideoMode_GetModesCount)dll.getSymbol("sfVideoMode_GetModesCount");
|
||||
sfVideoMode_IsValid = cast(pf_sfVideoMode_IsValid)dll.getSymbol("sfVideoMode_IsValid");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.window;
|
||||
|
@ -36,15 +36,15 @@ import dsfml.system.stringutil;
|
|||
|
||||
|
||||
/**
|
||||
* Window style
|
||||
* Window style
|
||||
*/
|
||||
enum Style
|
||||
{
|
||||
NONE = 0, /// No border / title bar (this flag and all others are mutually exclusive)
|
||||
TITLEBAR = 1 << 0, /// Title bar + fixed border
|
||||
RESIZE = 1 << 1, /// Titlebar + resizable border + maximize button
|
||||
CLOSE = 1 << 2, /// Titlebar + close button
|
||||
FULLSCREEN = 1 << 3 /// Fullscreen mode (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
|
||||
RESIZE = 1 << 1, /// Titlebar + resizable border + maximize button
|
||||
CLOSE = 1 << 2, /// Titlebar + close button
|
||||
FULLSCREEN = 1 << 3 /// Fullscreen mode (this flag and all others are mutually exclusive)
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,412 +53,412 @@ enum Style
|
|||
*/
|
||||
struct ContextSettings
|
||||
{
|
||||
uint DepthBits = 24; /// Bits of the depth buffer
|
||||
uint StencilBits = 8; /// Bits of the stencil buffer
|
||||
uint AntialiasingLevel = 0; /// Level of antialiasing
|
||||
uint DepthBits = 24; /// Bits of the depth buffer
|
||||
uint StencilBits = 8; /// Bits of the stencil buffer
|
||||
uint AntialiasingLevel = 0; /// Level of antialiasing
|
||||
uint MajorVersion = 3; /// Major 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
|
||||
* or connect to an existing one
|
||||
* Window is a rendering window ; it can create a new window
|
||||
* or connect to an existing one
|
||||
*/
|
||||
class Window : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Construct a new window
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
super(sfWindow_Create(mode, toStringz(title), windowStyle, settings));
|
||||
}
|
||||
{
|
||||
/**
|
||||
* Construct a new window
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
super(sfWindow_Create(mode, toStringz(title), windowStyle, settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the window from an existing control
|
||||
*
|
||||
* Params:
|
||||
* handle = Platform-specific handle of the control
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(WindowHandle handle, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
super(sfWindow_CreateFromHandle(handle, settings));
|
||||
}
|
||||
/**
|
||||
* Construct the window from an existing control
|
||||
*
|
||||
* Params:
|
||||
* handle = Platform-specific handle of the control
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
this(WindowHandle handle, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
super(sfWindow_CreateFromHandle(handle, settings));
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
m_input = null;
|
||||
sfWindow_Destroy(m_ptr);
|
||||
}
|
||||
override void dispose()
|
||||
{
|
||||
m_input = null;
|
||||
sfWindow_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create (or recreate) the window
|
||||
*
|
||||
* Input created with getInput becomes invalid.
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
void create(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
/**
|
||||
* Create (or recreate) the window
|
||||
*
|
||||
* Input created with getInput becomes invalid.
|
||||
*
|
||||
* Params:
|
||||
* mode = Video mode to use
|
||||
* title = Title of the window
|
||||
* windowStyle = Window style (Resize | Close by default)
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
void create(VideoMode mode, string title, Style windowStyle = Style.RESIZE | Style.CLOSE, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
|
||||
m_ptr = sfWindow_Create(mode, toStringz(title), windowStyle, settings);
|
||||
}
|
||||
m_ptr = sfWindow_Create(mode, toStringz(title), windowStyle, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create (or recreate) the window from an existing control
|
||||
*
|
||||
* Input created with getInput becomes invalid.
|
||||
*
|
||||
* Params:
|
||||
* handle = Platform-specific handle of the control
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
void create(WindowHandle handle, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
/**
|
||||
* Create (or recreate) the window from an existing control
|
||||
*
|
||||
* Input created with getInput becomes invalid.
|
||||
*
|
||||
* Params:
|
||||
* handle = Platform-specific handle of the control
|
||||
* settings = Context settings (default is default ContextSettings values)
|
||||
*/
|
||||
void create(WindowHandle handle, ContextSettings settings = ContextSettings())
|
||||
{
|
||||
if (m_ptr !is null)
|
||||
dispose();
|
||||
|
||||
m_ptr = sfWindow_CreateFromHandle(handle, settings);
|
||||
}
|
||||
m_ptr = sfWindow_CreateFromHandle(handle, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close (destroy) the window.
|
||||
* You can call create to recreate a valid window
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
sfWindow_Close(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Close (destroy) the window.
|
||||
* You can call create to recreate a valid window
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
sfWindow_Close(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether or not a window is opened
|
||||
*
|
||||
* Returns:
|
||||
* True if window is currently open.
|
||||
*/
|
||||
bool isOpened()
|
||||
{
|
||||
return cast(bool) sfWindow_IsOpened(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the width of the rendering region of the window
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint getWidth()
|
||||
{
|
||||
return sfWindow_GetWidth(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Tell whether or not a window is opened
|
||||
*
|
||||
* Returns:
|
||||
* True if window is currently open.
|
||||
*/
|
||||
bool isOpened()
|
||||
{
|
||||
return cast(bool) sfWindow_IsOpened(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the width of the rendering region of the window
|
||||
*
|
||||
* Returns:
|
||||
* Width in pixels
|
||||
*/
|
||||
uint getWidth()
|
||||
{
|
||||
return sfWindow_GetWidth(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the rendering region of the window
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint getHeight()
|
||||
{
|
||||
return sfWindow_GetHeight(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the height of the rendering region of the window
|
||||
*
|
||||
* Returns:
|
||||
* Height in pixels
|
||||
*/
|
||||
uint getHeight()
|
||||
{
|
||||
return sfWindow_GetHeight(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creation settings of a window
|
||||
*
|
||||
* Returns:
|
||||
* Settings used to create the window
|
||||
*/
|
||||
ContextSettings getSettings()
|
||||
{
|
||||
return sfWindow_GetSettings(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get the creation settings of a window
|
||||
*
|
||||
* Returns:
|
||||
* Settings used to create the window
|
||||
*/
|
||||
ContextSettings getSettings()
|
||||
{
|
||||
return sfWindow_GetSettings(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the event on top of events stack, if any, and pop it
|
||||
*
|
||||
* Params:
|
||||
* eventReceived = Event to fill, if any
|
||||
*
|
||||
* Returns:
|
||||
* True if an event was returned, false if events stack was empty
|
||||
*/
|
||||
bool getEvent(ref Event eventReceived)
|
||||
{
|
||||
return cast(bool)sfWindow_GetEvent(m_ptr, &eventReceived);
|
||||
}
|
||||
/**
|
||||
* Get the event on top of events stack, if any, and pop it
|
||||
*
|
||||
* Params:
|
||||
* eventReceived = Event to fill, if any
|
||||
*
|
||||
* Returns:
|
||||
* True if an event was returned, false if events stack was empty
|
||||
*/
|
||||
bool getEvent(ref Event eventReceived)
|
||||
{
|
||||
return cast(bool)sfWindow_GetEvent(m_ptr, &eventReceived);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable / disable vertical synchronization
|
||||
*
|
||||
* Params:
|
||||
* enabled : True to enable v-sync, false to deactivate
|
||||
*/
|
||||
void useVerticalSync(bool enabled)
|
||||
{
|
||||
sfWindow_UseVerticalSync(m_ptr, enabled);
|
||||
}
|
||||
/**
|
||||
* Enable / disable vertical synchronization
|
||||
*
|
||||
* Params:
|
||||
* enabled : True to enable v-sync, false to deactivate
|
||||
*/
|
||||
void useVerticalSync(bool enabled)
|
||||
{
|
||||
sfWindow_UseVerticalSync(m_ptr, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or hide the mouse cursor
|
||||
*
|
||||
* Params:
|
||||
* show : True to show, false to hide
|
||||
*/
|
||||
void showMouseCursor(bool show)
|
||||
{
|
||||
sfWindow_ShowMouseCursor(m_ptr, show);
|
||||
}
|
||||
/**
|
||||
* Show or hide the mouse cursor
|
||||
*
|
||||
* Params:
|
||||
* show : True to show, false to hide
|
||||
*/
|
||||
void showMouseCursor(bool show)
|
||||
{
|
||||
sfWindow_ShowMouseCursor(m_ptr, show);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the position of the mouse cursor
|
||||
*
|
||||
* Params:
|
||||
* left = Left coordinate of the cursor, relative to the window
|
||||
* top = Top coordinate of the cursor, relative to the window
|
||||
*/
|
||||
void setCursorPosition(uint left, uint top)
|
||||
{
|
||||
sfWindow_SetCursorPosition(m_ptr, left, top);
|
||||
}
|
||||
/**
|
||||
* Change the position of the mouse cursor
|
||||
*
|
||||
* Params:
|
||||
* left = Left coordinate of the cursor, relative to the window
|
||||
* top = Top coordinate of the cursor, relative to the window
|
||||
*/
|
||||
void setCursorPosition(uint left, uint top)
|
||||
{
|
||||
sfWindow_SetCursorPosition(m_ptr, left, top);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the position of the window on screen.
|
||||
* Only works for top-level windows
|
||||
*
|
||||
* Params:
|
||||
* left = Left position
|
||||
* top = Top position
|
||||
*/
|
||||
void setPosition(int left, int top)
|
||||
{
|
||||
sfWindow_SetPosition(m_ptr, left, top);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the size of the rendering region of the window
|
||||
*
|
||||
* Params:
|
||||
* width : new width
|
||||
* height : new height
|
||||
*/
|
||||
void setSize(uint width, uint height)
|
||||
{
|
||||
sfWindow_SetSize(m_ptr, width, height);
|
||||
}
|
||||
/**
|
||||
* Change the position of the window on screen.
|
||||
* Only works for top-level windows
|
||||
*
|
||||
* Params:
|
||||
* left = Left position
|
||||
* top = Top position
|
||||
*/
|
||||
void setPosition(int left, int top)
|
||||
{
|
||||
sfWindow_SetPosition(m_ptr, left, top);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the size of the rendering region of the window
|
||||
*
|
||||
* Params:
|
||||
* width : new width
|
||||
* height : new height
|
||||
*/
|
||||
void setSize(uint width, uint height)
|
||||
{
|
||||
sfWindow_SetSize(m_ptr, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or hide the window
|
||||
*
|
||||
* Params:
|
||||
* state = True to show, false to hide
|
||||
*
|
||||
*/
|
||||
void show(bool state)
|
||||
{
|
||||
sfWindow_Show(m_ptr, state);
|
||||
}
|
||||
/**
|
||||
* Show or hide the window
|
||||
*
|
||||
* Params:
|
||||
* state = True to show, false to hide
|
||||
*
|
||||
*/
|
||||
void show(bool state)
|
||||
{
|
||||
sfWindow_Show(m_ptr, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable automatic key-repeat for keydown events.
|
||||
* Automatic key-repeat is enabled by default.
|
||||
*
|
||||
* Params:
|
||||
* enabled = true to enable, false to disable
|
||||
*/
|
||||
void enableKeyRepeat(bool enabled)
|
||||
{
|
||||
sfWindow_EnableKeyRepeat(m_ptr, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the window's icon
|
||||
*
|
||||
* Params:
|
||||
* width = Icon's width, in pixels
|
||||
* height = Icon's height, in pixels
|
||||
* data = array of pixels in memory, format must be RGBA 32 bits
|
||||
*
|
||||
*/
|
||||
void setIcon(size_t width, size_t height, ubyte[] data)
|
||||
{
|
||||
sfWindow_SetIcon(m_ptr, width, height, data.ptr);
|
||||
}
|
||||
/**
|
||||
* Enable or disable automatic key-repeat for keydown events.
|
||||
* Automatic key-repeat is enabled by default.
|
||||
*
|
||||
* Params:
|
||||
* enabled = true to enable, false to disable
|
||||
*/
|
||||
void enableKeyRepeat(bool enabled)
|
||||
{
|
||||
sfWindow_EnableKeyRepeat(m_ptr, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the window's icon
|
||||
*
|
||||
* Params:
|
||||
* width = Icon's width, in pixels
|
||||
* height = Icon's height, in pixels
|
||||
* data = array of pixels in memory, format must be RGBA 32 bits
|
||||
*
|
||||
*/
|
||||
void setIcon(size_t width, size_t height, ubyte[] data)
|
||||
{
|
||||
sfWindow_SetIcon(m_ptr, width, height, data.ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the window as the current target for rendering
|
||||
*
|
||||
* Params:
|
||||
* active = True to activate, false to deactivate
|
||||
* Returns:
|
||||
* True if operation was successful, false otherwise
|
||||
*/
|
||||
bool setActive(bool active = true)
|
||||
{
|
||||
return cast(bool)sfWindow_SetActive(m_ptr, active);
|
||||
}
|
||||
/**
|
||||
* Set the window as the current target for rendering
|
||||
*
|
||||
* Params:
|
||||
* active = True to activate, false to deactivate
|
||||
* Returns:
|
||||
* True if operation was successful, false otherwise
|
||||
*/
|
||||
bool setActive(bool active = true)
|
||||
{
|
||||
return cast(bool)sfWindow_SetActive(m_ptr, active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the window on screen
|
||||
*/
|
||||
void display()
|
||||
{
|
||||
sfWindow_Display(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Display the window on screen
|
||||
*/
|
||||
void display()
|
||||
{
|
||||
sfWindow_Display(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the input manager of the window
|
||||
*
|
||||
* Returns:
|
||||
* An input manager
|
||||
* See_Also :
|
||||
* Input
|
||||
*/
|
||||
Input getInput()
|
||||
{
|
||||
if (m_input is null)
|
||||
m_input = new Input(sfWindow_GetInput(m_ptr));
|
||||
return m_input;
|
||||
}
|
||||
/**
|
||||
* Get the input manager of the window
|
||||
*
|
||||
* Returns:
|
||||
* An input manager
|
||||
* See_Also :
|
||||
* Input
|
||||
*/
|
||||
Input getInput()
|
||||
{
|
||||
if (m_input is null)
|
||||
m_input = new Input(sfWindow_GetInput(m_ptr));
|
||||
return m_input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the framerate to a maximum fixed frequency
|
||||
*
|
||||
* Params:
|
||||
* limit : Framerate limit, in frames per seconds (use 0 to disable limit)
|
||||
*/
|
||||
void setFramerateLimit(uint limit)
|
||||
{
|
||||
sfWindow_SetFramerateLimit(m_ptr, limit);
|
||||
}
|
||||
/**
|
||||
* Limit the framerate to a maximum fixed frequency
|
||||
*
|
||||
* Params:
|
||||
* limit : Framerate limit, in frames per seconds (use 0 to disable limit)
|
||||
*/
|
||||
void setFramerateLimit(uint limit)
|
||||
{
|
||||
sfWindow_SetFramerateLimit(m_ptr, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time elapsed since last frame
|
||||
*
|
||||
* Returns:
|
||||
* Time elapsed, in seconds
|
||||
*/
|
||||
float getFrameTime()
|
||||
{
|
||||
return sfWindow_GetFrameTime(m_ptr);
|
||||
}
|
||||
/**
|
||||
* Get time elapsed since last frame
|
||||
*
|
||||
* Returns:
|
||||
* Time elapsed, in seconds
|
||||
*/
|
||||
float getFrameTime()
|
||||
{
|
||||
return sfWindow_GetFrameTime(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the joystick threshold, ie. the value below which
|
||||
* no move event will be generated
|
||||
*
|
||||
* Params:
|
||||
* threshold : New threshold, in range [0, 100]
|
||||
*/
|
||||
void setJoystickThreshold(float threshold)
|
||||
{
|
||||
sfWindow_SetJoystickThreshold(m_ptr, threshold);
|
||||
}
|
||||
/**
|
||||
* Change the joystick threshold, ie. the value below which
|
||||
* no move event will be generated
|
||||
*
|
||||
* Params:
|
||||
* threshold : New threshold, in range [0, 100]
|
||||
*/
|
||||
void setJoystickThreshold(float threshold)
|
||||
{
|
||||
sfWindow_SetJoystickThreshold(m_ptr, threshold);
|
||||
}
|
||||
|
||||
protected:
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
this(void* ptr)
|
||||
{
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
Input m_input;
|
||||
Input m_input;
|
||||
private:
|
||||
|
||||
|
||||
// External ====================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function(VideoMode, cchar*, uint, ContextSettings) pf_sfWindow_Create;
|
||||
typedef void* function(WindowHandle, ContextSettings) pf_sfWindow_CreateFromHandle;
|
||||
typedef void function(void*) pf_sfWindow_Destroy;
|
||||
typedef void function(void*) pf_sfWindow_Close;
|
||||
typedef int function(void*) pf_sfWindow_IsOpened;
|
||||
typedef uint function(void*) pf_sfWindow_GetWidth;
|
||||
typedef uint function(void*) pf_sfWindow_GetHeight;
|
||||
typedef ContextSettings function(void* Window) pf_sfWindow_GetSettings;
|
||||
typedef int function(void*, Event*) pf_sfWindow_GetEvent;
|
||||
typedef void function(void*, int) pf_sfWindow_UseVerticalSync;
|
||||
typedef void function(void*, int) pf_sfWindow_ShowMouseCursor;
|
||||
typedef void function(void*, uint, uint) pf_sfWindow_SetCursorPosition;
|
||||
typedef void function(void*, int, int) pf_sfWindow_SetPosition;
|
||||
typedef void function(void*, uint, uint) pf_sfWindow_SetSize;
|
||||
typedef void function(void*, int) pf_sfWindow_Show;
|
||||
typedef void function(void*, int) pf_sfWindow_EnableKeyRepeat;
|
||||
typedef void function(void*, size_t, size_t, ubyte*) pf_sfWindow_SetIcon;
|
||||
typedef int function(void*, int) pf_sfWindow_SetActive;
|
||||
typedef void function(void*) pf_sfWindow_Display;
|
||||
typedef void* function(void*) pf_sfWindow_GetInput;
|
||||
typedef void function(void*, uint) pf_sfWindow_SetFramerateLimit;
|
||||
typedef float function(void*) pf_sfWindow_GetFrameTime;
|
||||
typedef void function(void*, float) pf_sfWindow_SetJoystickThreshold;
|
||||
|
||||
static pf_sfWindow_Create sfWindow_Create;
|
||||
static pf_sfWindow_CreateFromHandle sfWindow_CreateFromHandle;
|
||||
static pf_sfWindow_Destroy sfWindow_Destroy;
|
||||
static pf_sfWindow_Close sfWindow_Close;
|
||||
static pf_sfWindow_IsOpened sfWindow_IsOpened;
|
||||
static pf_sfWindow_GetWidth sfWindow_GetWidth;
|
||||
static pf_sfWindow_GetHeight sfWindow_GetHeight;
|
||||
static pf_sfWindow_GetSettings sfWindow_GetSettings;
|
||||
static pf_sfWindow_GetEvent sfWindow_GetEvent;
|
||||
static pf_sfWindow_UseVerticalSync sfWindow_UseVerticalSync;
|
||||
static pf_sfWindow_ShowMouseCursor sfWindow_ShowMouseCursor;
|
||||
static pf_sfWindow_SetCursorPosition sfWindow_SetCursorPosition;
|
||||
static pf_sfWindow_SetPosition sfWindow_SetPosition;
|
||||
static pf_sfWindow_SetSize sfWindow_SetSize;
|
||||
static pf_sfWindow_Show sfWindow_Show;
|
||||
static pf_sfWindow_EnableKeyRepeat sfWindow_EnableKeyRepeat;
|
||||
static pf_sfWindow_SetIcon sfWindow_SetIcon;
|
||||
static pf_sfWindow_SetActive sfWindow_SetActive;
|
||||
static pf_sfWindow_Display sfWindow_Display;
|
||||
static pf_sfWindow_GetInput sfWindow_GetInput;
|
||||
static pf_sfWindow_SetFramerateLimit sfWindow_SetFramerateLimit;
|
||||
static pf_sfWindow_GetFrameTime sfWindow_GetFrameTime;
|
||||
static pf_sfWindow_SetJoystickThreshold sfWindow_SetJoystickThreshold;
|
||||
}
|
||||
extern (C)
|
||||
{
|
||||
typedef void* function(VideoMode, cchar*, uint, ContextSettings) pf_sfWindow_Create;
|
||||
typedef void* function(WindowHandle, ContextSettings) pf_sfWindow_CreateFromHandle;
|
||||
typedef void function(void*) pf_sfWindow_Destroy;
|
||||
typedef void function(void*) pf_sfWindow_Close;
|
||||
typedef int function(void*) pf_sfWindow_IsOpened;
|
||||
typedef uint function(void*) pf_sfWindow_GetWidth;
|
||||
typedef uint function(void*) pf_sfWindow_GetHeight;
|
||||
typedef ContextSettings function(void* Window) pf_sfWindow_GetSettings;
|
||||
typedef int function(void*, Event*) pf_sfWindow_GetEvent;
|
||||
typedef void function(void*, int) pf_sfWindow_UseVerticalSync;
|
||||
typedef void function(void*, int) pf_sfWindow_ShowMouseCursor;
|
||||
typedef void function(void*, uint, uint) pf_sfWindow_SetCursorPosition;
|
||||
typedef void function(void*, int, int) pf_sfWindow_SetPosition;
|
||||
typedef void function(void*, uint, uint) pf_sfWindow_SetSize;
|
||||
typedef void function(void*, int) pf_sfWindow_Show;
|
||||
typedef void function(void*, int) pf_sfWindow_EnableKeyRepeat;
|
||||
typedef void function(void*, size_t, size_t, ubyte*) pf_sfWindow_SetIcon;
|
||||
typedef int function(void*, int) pf_sfWindow_SetActive;
|
||||
typedef void function(void*) pf_sfWindow_Display;
|
||||
typedef void* function(void*) pf_sfWindow_GetInput;
|
||||
typedef void function(void*, uint) pf_sfWindow_SetFramerateLimit;
|
||||
typedef float function(void*) pf_sfWindow_GetFrameTime;
|
||||
typedef void function(void*, float) pf_sfWindow_SetJoystickThreshold;
|
||||
|
||||
static pf_sfWindow_Create sfWindow_Create;
|
||||
static pf_sfWindow_CreateFromHandle sfWindow_CreateFromHandle;
|
||||
static pf_sfWindow_Destroy sfWindow_Destroy;
|
||||
static pf_sfWindow_Close sfWindow_Close;
|
||||
static pf_sfWindow_IsOpened sfWindow_IsOpened;
|
||||
static pf_sfWindow_GetWidth sfWindow_GetWidth;
|
||||
static pf_sfWindow_GetHeight sfWindow_GetHeight;
|
||||
static pf_sfWindow_GetSettings sfWindow_GetSettings;
|
||||
static pf_sfWindow_GetEvent sfWindow_GetEvent;
|
||||
static pf_sfWindow_UseVerticalSync sfWindow_UseVerticalSync;
|
||||
static pf_sfWindow_ShowMouseCursor sfWindow_ShowMouseCursor;
|
||||
static pf_sfWindow_SetCursorPosition sfWindow_SetCursorPosition;
|
||||
static pf_sfWindow_SetPosition sfWindow_SetPosition;
|
||||
static pf_sfWindow_SetSize sfWindow_SetSize;
|
||||
static pf_sfWindow_Show sfWindow_Show;
|
||||
static pf_sfWindow_EnableKeyRepeat sfWindow_EnableKeyRepeat;
|
||||
static pf_sfWindow_SetIcon sfWindow_SetIcon;
|
||||
static pf_sfWindow_SetActive sfWindow_SetActive;
|
||||
static pf_sfWindow_Display sfWindow_Display;
|
||||
static pf_sfWindow_GetInput sfWindow_GetInput;
|
||||
static pf_sfWindow_SetFramerateLimit sfWindow_SetFramerateLimit;
|
||||
static pf_sfWindow_GetFrameTime sfWindow_GetFrameTime;
|
||||
static pf_sfWindow_SetJoystickThreshold sfWindow_SetJoystickThreshold;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-window-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-window");
|
||||
|
||||
sfWindow_Create = cast(pf_sfWindow_Create)dll.getSymbol("sfWindow_Create");
|
||||
sfWindow_CreateFromHandle = cast(pf_sfWindow_CreateFromHandle)dll.getSymbol("sfWindow_CreateFromHandle");
|
||||
sfWindow_Destroy = cast(pf_sfWindow_Destroy)dll.getSymbol("sfWindow_Destroy");
|
||||
sfWindow_Close = cast(pf_sfWindow_Close)dll.getSymbol("sfWindow_Close");
|
||||
sfWindow_IsOpened = cast(pf_sfWindow_IsOpened)dll.getSymbol("sfWindow_IsOpened");
|
||||
sfWindow_GetWidth = cast(pf_sfWindow_GetWidth)dll.getSymbol("sfWindow_GetWidth");
|
||||
sfWindow_GetHeight = cast(pf_sfWindow_GetHeight)dll.getSymbol("sfWindow_GetHeight");
|
||||
sfWindow_GetSettings = cast(pf_sfWindow_GetSettings)dll.getSymbol("sfWindow_GetSettings");
|
||||
sfWindow_GetEvent = cast(pf_sfWindow_GetEvent)dll.getSymbol("sfWindow_GetEvent");
|
||||
sfWindow_UseVerticalSync = cast(pf_sfWindow_UseVerticalSync)dll.getSymbol("sfWindow_UseVerticalSync");
|
||||
sfWindow_ShowMouseCursor = cast(pf_sfWindow_ShowMouseCursor)dll.getSymbol("sfWindow_ShowMouseCursor");
|
||||
sfWindow_SetCursorPosition = cast(pf_sfWindow_SetCursorPosition)dll.getSymbol("sfWindow_SetCursorPosition");
|
||||
sfWindow_SetPosition = cast(pf_sfWindow_SetPosition)dll.getSymbol("sfWindow_SetPosition");
|
||||
sfWindow_SetSize = cast(pf_sfWindow_SetSize)dll.getSymbol("sfWindow_SetSize");
|
||||
sfWindow_Show = cast(pf_sfWindow_Show)dll.getSymbol("sfWindow_Show");
|
||||
sfWindow_EnableKeyRepeat = cast(pf_sfWindow_EnableKeyRepeat)dll.getSymbol("sfWindow_EnableKeyRepeat");
|
||||
sfWindow_SetIcon = cast(pf_sfWindow_SetIcon)dll.getSymbol("sfWindow_SetIcon");
|
||||
sfWindow_SetActive = cast(pf_sfWindow_SetActive)dll.getSymbol("sfWindow_SetActive");
|
||||
sfWindow_Display = cast(pf_sfWindow_Display)dll.getSymbol("sfWindow_Display");
|
||||
sfWindow_GetInput = cast(pf_sfWindow_GetInput)dll.getSymbol("sfWindow_GetInput");
|
||||
sfWindow_SetFramerateLimit = cast(pf_sfWindow_SetFramerateLimit)dll.getSymbol("sfWindow_SetFramerateLimit");
|
||||
sfWindow_GetFrameTime = cast(pf_sfWindow_GetFrameTime)dll.getSymbol("sfWindow_GetFrameTime");
|
||||
sfWindow_SetJoystickThreshold = cast(pf_sfWindow_SetJoystickThreshold)dll.getSymbol("sfWindow_SetJoystickThreshold");
|
||||
}
|
||||
|
||||
sfWindow_Create = cast(pf_sfWindow_Create)dll.getSymbol("sfWindow_Create");
|
||||
sfWindow_CreateFromHandle = cast(pf_sfWindow_CreateFromHandle)dll.getSymbol("sfWindow_CreateFromHandle");
|
||||
sfWindow_Destroy = cast(pf_sfWindow_Destroy)dll.getSymbol("sfWindow_Destroy");
|
||||
sfWindow_Close = cast(pf_sfWindow_Close)dll.getSymbol("sfWindow_Close");
|
||||
sfWindow_IsOpened = cast(pf_sfWindow_IsOpened)dll.getSymbol("sfWindow_IsOpened");
|
||||
sfWindow_GetWidth = cast(pf_sfWindow_GetWidth)dll.getSymbol("sfWindow_GetWidth");
|
||||
sfWindow_GetHeight = cast(pf_sfWindow_GetHeight)dll.getSymbol("sfWindow_GetHeight");
|
||||
sfWindow_GetSettings = cast(pf_sfWindow_GetSettings)dll.getSymbol("sfWindow_GetSettings");
|
||||
sfWindow_GetEvent = cast(pf_sfWindow_GetEvent)dll.getSymbol("sfWindow_GetEvent");
|
||||
sfWindow_UseVerticalSync = cast(pf_sfWindow_UseVerticalSync)dll.getSymbol("sfWindow_UseVerticalSync");
|
||||
sfWindow_ShowMouseCursor = cast(pf_sfWindow_ShowMouseCursor)dll.getSymbol("sfWindow_ShowMouseCursor");
|
||||
sfWindow_SetCursorPosition = cast(pf_sfWindow_SetCursorPosition)dll.getSymbol("sfWindow_SetCursorPosition");
|
||||
sfWindow_SetPosition = cast(pf_sfWindow_SetPosition)dll.getSymbol("sfWindow_SetPosition");
|
||||
sfWindow_SetSize = cast(pf_sfWindow_SetSize)dll.getSymbol("sfWindow_SetSize");
|
||||
sfWindow_Show = cast(pf_sfWindow_Show)dll.getSymbol("sfWindow_Show");
|
||||
sfWindow_EnableKeyRepeat = cast(pf_sfWindow_EnableKeyRepeat)dll.getSymbol("sfWindow_EnableKeyRepeat");
|
||||
sfWindow_SetIcon = cast(pf_sfWindow_SetIcon)dll.getSymbol("sfWindow_SetIcon");
|
||||
sfWindow_SetActive = cast(pf_sfWindow_SetActive)dll.getSymbol("sfWindow_SetActive");
|
||||
sfWindow_Display = cast(pf_sfWindow_Display)dll.getSymbol("sfWindow_Display");
|
||||
sfWindow_GetInput = cast(pf_sfWindow_GetInput)dll.getSymbol("sfWindow_GetInput");
|
||||
sfWindow_SetFramerateLimit = cast(pf_sfWindow_SetFramerateLimit)dll.getSymbol("sfWindow_SetFramerateLimit");
|
||||
sfWindow_GetFrameTime = cast(pf_sfWindow_GetFrameTime)dll.getSymbol("sfWindow_GetFrameTime");
|
||||
sfWindow_SetJoystickThreshold = cast(pf_sfWindow_SetJoystickThreshold)dll.getSymbol("sfWindow_SetJoystickThreshold");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.window.windowhandle;
|
||||
|
||||
/**
|
||||
* Define a low-level window handle type, specific to
|
||||
* each platform
|
||||
* Define a low-level window handle type, specific to
|
||||
* each platform
|
||||
*/
|
||||
version(Windows)
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ version(Windows)
|
|||
}
|
||||
else version(linux)
|
||||
{
|
||||
// Unix - X11 defines an unsigned integer handle (Window)
|
||||
typedef ulong WindowHandle;
|
||||
// Unix - X11 defines an unsigned integer handle (Window)
|
||||
typedef ulong WindowHandle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue