mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
+ toString for Color
* IDrawable.render now correctly takes an IRenderTarget git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1446 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
ef216acc5f
commit
64fb9a139a
@ -26,38 +26,21 @@
|
|||||||
|
|
||||||
module dsfml.graphics.color;
|
module dsfml.graphics.color;
|
||||||
|
|
||||||
|
import std.string;
|
||||||
|
|
||||||
|
alias RGBA Color; // standard Color is RGBA
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Color is an utility structure for manipulating colors
|
* Color is an utility structure for manipulating colors
|
||||||
*/
|
*/
|
||||||
struct Color
|
struct RGBA
|
||||||
{
|
{
|
||||||
|
align(1):
|
||||||
ubyte r; /// Red component
|
ubyte r; /// Red component
|
||||||
ubyte g; /// Green component
|
ubyte g; /// Green component
|
||||||
ubyte b; /// Blue component
|
ubyte b; /// Blue component
|
||||||
ubyte a = 255; /// Alpha (transparency) component
|
ubyte a = 255; /// Alpha (transparency) component, 255 = opaque
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)
|
|
||||||
{
|
|
||||||
Color c;
|
|
||||||
c.r = r;
|
|
||||||
c.g = g;
|
|
||||||
c.b = b;
|
|
||||||
c.a = a;
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Operator == and != overload to compare two colors
|
* Operator == and != overload to compare two colors
|
||||||
*/
|
*/
|
||||||
@ -121,12 +104,20 @@ struct Color
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Color BLACK = {0, 0, 0}; /// Black predefined color
|
string toString()
|
||||||
static const Color WHITE = {255, 255, 255}; /// White predefined color
|
{
|
||||||
static const Color RED = {255, 0, 0}; /// Red predefined color
|
return std.string.format("(%d,%d,%d,%d)", r,g,b,a);
|
||||||
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 immutable
|
||||||
static const Color MAGENTA = {255, 0, 255}; /// Magenta predefined color
|
{
|
||||||
static const Color CYAN = {0, 255, 255}; /// Cyan predefined color
|
Color BLACK = Color(0, 0, 0); /// Black predefined color
|
||||||
|
Color WHITE = Color(255, 255, 255); /// White predefined color
|
||||||
|
Color RED = Color(255, 0, 0); /// Red predefined color
|
||||||
|
Color GREEN = Color(0, 255, 0); /// Green predefined color
|
||||||
|
Color BLUE = Color(0, 0, 255); /// Blue predefined color
|
||||||
|
Color YELLOW = Color(255, 0, 255); /// Yellow predefined color
|
||||||
|
Color MAGENTA = Color(255, 0, 255); /// Magenta predefined color
|
||||||
|
Color CYAN = Color(0, 255, 255); /// Cyan predefined color
|
||||||
|
}
|
||||||
}
|
}
|
@ -29,6 +29,7 @@ module dsfml.graphics.drawableimpl;
|
|||||||
public import dsfml.system.common;
|
public import dsfml.system.common;
|
||||||
import dsfml.system.vector2;
|
import dsfml.system.vector2;
|
||||||
|
|
||||||
|
import dsfml.graphics.irendertarget;
|
||||||
import dsfml.graphics.idrawable,
|
import dsfml.graphics.idrawable,
|
||||||
dsfml.graphics.color,
|
dsfml.graphics.color,
|
||||||
dsfml.graphics.blendmode,
|
dsfml.graphics.blendmode,
|
||||||
@ -195,24 +196,14 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(RenderWindow window)
|
void render(IRenderTarget window)
|
||||||
{
|
{
|
||||||
sfRenderWindow_DrawThis(window.getNativePointer(), m_ptr);
|
sfRenderWindow_DrawThis((cast(DSFMLObject)window).getNativePointer(), m_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderWithShader(RenderWindow window, Shader shader)
|
void renderWithShader(IRenderTarget window, Shader shader)
|
||||||
{
|
{
|
||||||
sfRenderWindow_DrawThisWithShader(window.getNativePointer, m_ptr, shader.getNativePointer);
|
sfRenderWindow_DrawThisWithShader((cast(DSFMLObject)window).getNativePointer, m_ptr, shader.getNativePointer);
|
||||||
}
|
|
||||||
|
|
||||||
void render(RenderImage image)
|
|
||||||
{
|
|
||||||
sfRenderImage_DrawThis(image.getNativePointer(), m_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderWithShader(RenderImage image, Shader shader)
|
|
||||||
{
|
|
||||||
sfRenderImage_DrawThisWithShader(image.getNativePointer, m_ptr, shader.getNativePointer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override void dispose()
|
override void dispose()
|
||||||
|
@ -28,6 +28,7 @@ module dsfml.graphics.idrawable;
|
|||||||
|
|
||||||
import dsfml.system.vector2;
|
import dsfml.system.vector2;
|
||||||
|
|
||||||
|
import dsfml.graphics.irendertarget;
|
||||||
import dsfml.graphics.color,
|
import dsfml.graphics.color,
|
||||||
dsfml.graphics.blendmode,
|
dsfml.graphics.blendmode,
|
||||||
dsfml.graphics.renderwindow,
|
dsfml.graphics.renderwindow,
|
||||||
@ -281,7 +282,7 @@ interface IDrawable
|
|||||||
* Params:
|
* Params:
|
||||||
* window = Target into which render the object
|
* window = Target into which render the object
|
||||||
*/
|
*/
|
||||||
void render(RenderWindow window);
|
void render(IRenderTarget window);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the specific geometry of the object with a shader
|
* Render the specific geometry of the object with a shader
|
||||||
@ -290,22 +291,5 @@ interface IDrawable
|
|||||||
* window = Render target
|
* window = Render target
|
||||||
* shader = Shader to use
|
* shader = Shader to use
|
||||||
*/
|
*/
|
||||||
void renderWithShader(RenderWindow window, Shader shader);
|
void renderWithShader(IRenderTarget window, Shader shader);
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the specific geometry of the object
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* image = Target into which render the object
|
|
||||||
*/
|
|
||||||
void render(RenderImage image);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the specific geometry of the object with a shader
|
|
||||||
*
|
|
||||||
* Params:
|
|
||||||
* image = Render target
|
|
||||||
* shader = Shader to use
|
|
||||||
*/
|
|
||||||
void renderWithShader(RenderImage image, Shader shader);
|
|
||||||
}
|
}
|
@ -98,7 +98,7 @@ public:
|
|||||||
this(ubyte[] data)
|
this(ubyte[] data)
|
||||||
{
|
{
|
||||||
if (data is null || data.length == 0)
|
if (data is null || data.length == 0)
|
||||||
throw new LoadingException("LoadingException : Memory stream is invalid.");
|
throw new LoadingException("Memory stream is invalid.");
|
||||||
|
|
||||||
super(sfImage_CreateFromMemory(data.ptr, data.length));
|
super(sfImage_CreateFromMemory(data.ptr, data.length));
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public:
|
|||||||
this(uint width, uint height, ubyte[] data)
|
this(uint width, uint height, ubyte[] data)
|
||||||
{
|
{
|
||||||
if (width * height * 4 != data.length)
|
if (width * height * 4 != data.length)
|
||||||
throw new LoadingException("LoadingException : Pixels array length doesn't match the specified size.");
|
throw new LoadingException("Pixels array length doesn't match the specified size.");
|
||||||
|
|
||||||
super(sfImage_CreateFromPixels(width, height, data.ptr));
|
super(sfImage_CreateFromPixels(width, height, data.ptr));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user