sync with SFML: VideoMode.GetFullscreenModes

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1455 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-03-13 02:42:45 +00:00
parent 1c72b919e7
commit 81fd4c5d1d
2 changed files with 103 additions and 149 deletions

View File

@ -30,10 +30,12 @@ import dsfml.system.common;
import dsfml.system.stringutil; import dsfml.system.stringutil;
/** /**
* IPAddress provides easy manipulation of IP v4 addresses * IPAddress provides easy manipulation of IP v4 addresses
*/ */
struct IPAddress struct IPAddress
{ {
byte[16] Address;
/** /**
* Construct the address from a string * Construct the address from a string
* *
@ -41,9 +43,9 @@ struct IPAddress
* address = IP address ("xxx.xxx.xxx.xxx") or network name * address = IP address ("xxx.xxx.xxx.xxx") or network name
* *
*/ */
static IPAddress opCall(string address) static opCall(string address)
{ {
return sfIPAddress_FromString(toStringz(address)); return sfIpAddress_FromString(toStringz(address));
} }
@ -57,9 +59,9 @@ struct IPAddress
* byte3 = Fourth byte of the address * byte3 = Fourth byte of the address
* *
*/ */
static IPAddress opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3) static opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3)
{ {
return sfIPAddress_FromBytes(byte0, byte1, byte2, byte3); return sfIpAddress_FromBytes(byte0, byte1, byte2, byte3);
} }
/** /**
@ -69,9 +71,9 @@ struct IPAddress
* address = 4 bytes of the address packed into a 32 bits integer * address = 4 bytes of the address packed into a 32 bits integer
* *
*/ */
static IPAddress opCall(uint address) static opCall(uint address)
{ {
return sfIPAddress_FromInteger(address); return sfIpAddress_FromInteger(address);
} }
/** /**
@ -83,9 +85,11 @@ struct IPAddress
*/ */
bool isValid() bool isValid()
{ {
return cast(bool)sfIPAddress_IsValid(this); return cast(bool)sfIpAddress_IsValid(this);
} }
@property
{
/** /**
* Get the computer's local IP address (from the LAN point of view) * Get the computer's local IP address (from the LAN point of view)
* *
@ -93,9 +97,9 @@ struct IPAddress
* Local IP address * Local IP address
* *
*/ */
static IPAddress getLocalAddress() static IPAddress localAddress()
{ {
return sfIPAddress_GetLocalAddress(); return sfIpAddress_GetLocalAddress();
} }
/** /**
@ -108,61 +112,38 @@ struct IPAddress
* Public IP address * Public IP address
* *
*/ */
static IPAddress getPublicAddress() static IPAddress publicAddress()
{ {
return sfIPAddress_GetPublicAddress(); return sfIpAddress_GetPublicAddress();
} }
bool opEqual(IPAddress other)
{
return Address == other.Address;
}
/** /**
* Local host address (to connect to the same computer). * Local host address (to connect to the same computer).
*/ */
static IPAddress LOCALHOST() static IPAddress localHost()
{ {
return sfIPAddress_LocalHost(); return sfIpAddress_LocalHost();
}
}
const bool opEquals(ref const(IPAddress) other)
{
return Address == other.Address;
} }
byte[16] Address;
} }
private: private:
extern (C) static extern(C)
{ {
typedef IPAddress function(cchar*) pf_sfIPAddress_FromString; IPAddress function(cchar*) sfIpAddress_FromString;
typedef IPAddress function(ubyte, ubyte, ubyte, ubyte) pf_sfIPAddress_FromBytes; IPAddress function(ubyte, ubyte, ubyte, ubyte)sfIpAddress_FromBytes;
typedef IPAddress function(uint) pf_sfIPAddress_FromInteger; IPAddress function(uint) sfIpAddress_FromInteger;
typedef int function(IPAddress) pf_sfIPAddress_IsValid; int function(IPAddress) sfIpAddress_IsValid;
typedef IPAddress function() pf_sfIPAddress_GetLocalAddress; IPAddress function() sfIpAddress_GetLocalAddress;
typedef IPAddress function() pf_sfIPAddress_GetPublicAddress; IPAddress function() sfIpAddress_GetPublicAddress;
typedef IPAddress function() pf_sfIPAddress_LocalHost; IPAddress function() sfIpAddress_LocalHost;
static pf_sfIPAddress_FromString sfIPAddress_FromString;
static pf_sfIPAddress_FromBytes sfIPAddress_FromBytes;
static pf_sfIPAddress_FromInteger sfIPAddress_FromInteger;
static pf_sfIPAddress_IsValid sfIPAddress_IsValid;
static pf_sfIPAddress_GetLocalAddress sfIPAddress_GetLocalAddress;
static pf_sfIPAddress_GetPublicAddress sfIPAddress_GetPublicAddress;
static pf_sfIPAddress_LocalHost sfIPAddress_LocalHost;
} }
static this() mixin(loadFromSharedLib2("csfml-network", "sfIpAddress",
{ "FromBytes", "FromString", "FromInteger", "GetLocalAddress", "GetPublicAddress", "IsValid", "LocalHost"));
debug
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");
}

View File

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