Added sfTexture, renamed sfRenderImage to sfRenderTexture, removed sfSprite_GetPixel, added sfImage_FlipHorizontally and sfImage_FlipVertically

This commit is contained in:
Laurent Gomila committed 2011-08-06 14:50:14 +02:00
1 parent 29663b351d
commit f4eda513af
22 files changed
+1032 -530

No files matched your search

+5 -5
View File
@@ -145,15 +145,15 @@ int sfFont_GetLineSpacing(sfFont* font, unsigned int characterSize)
////////////////////////////////////////////////////////////
/// Get the image containing the glyphs of a given size in a font
/// Get the texture containing the glyphs of a given size in a font
////////////////////////////////////////////////////////////
const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize)
const sfTexture* sfFont_GetTexture(sfFont* font, unsigned int characterSize)
{
CSFML_CHECK_RETURN(font, NULL);
*font->Images[characterSize].This = font->This.GetImage(characterSize);
*font->Textures[characterSize].This = font->This.GetTexture(characterSize);
return &font->Images[characterSize];
return &font->Textures[characterSize];
}
@@ -162,7 +162,7 @@ const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize)
////////////////////////////////////////////////////////////
const sfFont* sfFont_GetDefaultFont(void)
{
static sfFont defaultFont = {sf::Font::GetDefaultFont(), std::map<unsigned int, sfImage>()};
static sfFont defaultFont = {sf::Font::GetDefaultFont(), std::map<unsigned int, sfTexture>()};
return &defaultFont;
}
+2 -2
View File
@@ -29,7 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/CallbackStream.h>
#include <map>
@@ -40,7 +40,7 @@
struct sfFont
{
sf::Font This;
std::map<unsigned int, sfImage> Images;
std::map<unsigned int, sfTexture> Textures;
CallbackStream Stream;
};
+25 -67
View File
@@ -27,7 +27,6 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderWindowStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
@@ -38,12 +37,7 @@
sfImage* sfImage_CreateFromColor(unsigned int width, unsigned int height, sfColor color)
{
sfImage* image = new sfImage;
if (!image->This->Create(width, height, sf::Color(color.r, color.g, color.b, color.a)))
{
delete image;
image = NULL;
}
image->This.Create(width, height, sf::Color(color.r, color.g, color.b, color.a));
return image;
}
@@ -55,12 +49,7 @@ sfImage* sfImage_CreateFromColor(unsigned int width, unsigned int height, sfColo
sfImage* sfImage_CreateFromPixels(unsigned int width, unsigned int height, const sfUint8* data)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromPixels(width, height, data))
{
delete image;
image = NULL;
}
image->This.Create(width, height, data);
return image;
}
@@ -73,7 +62,7 @@ sfImage* sfImage_CreateFromFile(const char* filename)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromFile(filename))
if (!image->This.LoadFromFile(filename))
{
delete image;
image = NULL;
@@ -90,7 +79,7 @@ sfImage* sfImage_CreateFromMemory(const void* data, size_t sizeInBytes)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromMemory(data, sizeInBytes))
if (!image->This.LoadFromMemory(data, sizeInBytes))
{
delete image;
image = NULL;
@@ -110,7 +99,7 @@ sfImage* sfImage_CreateFromStream(sfInputStream* stream)
sfImage* image = new sfImage;
CallbackStream sfmlStream(stream);
if (!image->This->LoadFromStream(sfmlStream))
if (!image->This.LoadFromStream(sfmlStream))
{
delete image;
image = NULL;
@@ -145,7 +134,7 @@ void sfImage_Destroy(sfImage* image)
////////////////////////////////////////////////////////////
sfBool sfImage_SaveToFile(const sfImage* image, const char* filename)
{
CSFML_CALL_PTR_RETURN(image, SaveToFile(filename), sfFalse);
CSFML_CALL_RETURN(image, SaveToFile(filename), sfFalse);
}
@@ -155,7 +144,7 @@ sfBool sfImage_SaveToFile(const sfImage* image, const char* filename)
void sfImage_CreateMaskFromColor(sfImage* image, sfColor colorKey, sfUint8 alpha)
{
sf::Color SFMLColor(colorKey.r, colorKey.g, colorKey.b, colorKey.a);
CSFML_CALL_PTR(image, CreateMaskFromColor(SFMLColor, alpha));
CSFML_CALL(image, CreateMaskFromColor(SFMLColor, alpha));
}
@@ -168,19 +157,7 @@ void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX
{
CSFML_CHECK(source);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR(image, Copy(*source->This, destX, destY, SFMLRect));
}
////////////////////////////////////////////////////////////
/// Create the image from the current contents of the
/// given window
////////////////////////////////////////////////////////////
CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIntRect sourceRect)
{
CSFML_CHECK_RETURN(window, sfFalse);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR_RETURN(image, CopyScreen(window->This, SFMLRect), sfFalse);
CSFML_CALL(image, Copy(source->This, destX, destY, SFMLRect));
}
@@ -191,7 +168,7 @@ CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIn
void sfImage_SetPixel(sfImage* image, unsigned int x, unsigned int y, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL_PTR(image, SetPixel(x, y, SFMLColor));
CSFML_CALL(image, SetPixel(x, y, SFMLColor));
}
@@ -203,7 +180,7 @@ sfColor sfImage_GetPixel(const sfImage* image, unsigned int x, unsigned int y)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(image, color);
sf::Color SFMLColor = image->This->GetPixel(x, y);
sf::Color SFMLColor = image->This.GetPixel(x, y);
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
@@ -216,35 +193,7 @@ sfColor sfImage_GetPixel(const sfImage* image, unsigned int x, unsigned int y)
////////////////////////////////////////////////////////////
const sfUint8* sfImage_GetPixelsPtr(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetPixelsPtr(), NULL);
}
////////////////////////////////////////////////////////////
/// Update a sub-rectangle of the image from an array of pixels
////////////////////////////////////////////////////////////
void sfImage_UpdatePixels(const sfImage* image, const sfUint8* pixels, sfIntRect rectangle)
{
sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
CSFML_CALL_PTR(image, UpdatePixels(pixels, rect));
}
////////////////////////////////////////////////////////////
/// Bind the image for rendering
////////////////////////////////////////////////////////////
void sfImage_Bind(const sfImage* image)
{
CSFML_CALL_PTR(image, Bind());
}
////////////////////////////////////////////////////////////
/// Enable or disable image smooth filter
////////////////////////////////////////////////////////////
void sfImage_SetSmooth(sfImage* image, sfBool smooth)
{
CSFML_CALL_PTR(image, SetSmooth(smooth == sfTrue));
CSFML_CALL_RETURN(image, GetPixelsPtr(), NULL);
}
@@ -253,7 +202,7 @@ void sfImage_SetSmooth(sfImage* image, sfBool smooth)
////////////////////////////////////////////////////////////
unsigned int sfImage_GetWidth(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetWidth(), 0);
CSFML_CALL_RETURN(image, GetWidth(), 0);
}
@@ -262,14 +211,23 @@ unsigned int sfImage_GetWidth(const sfImage* image)
////////////////////////////////////////////////////////////
unsigned int sfImage_GetHeight(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetHeight(), 0);
CSFML_CALL_RETURN(image, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Tells whether the smoothing filter is enabled or not on an image
/// Flip an image horizontally (left <-> right)
////////////////////////////////////////////////////////////
sfBool sfImage_IsSmooth(const sfImage* image)
void sfImage_FlipHorizontally(sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, IsSmooth(), sfFalse);
CSFML_CALL(image, FlipHorizontally());
}
////////////////////////////////////////////////////////////
/// Flip an image vertically (top <-> bottom)
////////////////////////////////////////////////////////////
void sfImage_FlipVertically(sfImage* image)
{
CSFML_CALL(image, FlipVertically());
}
+1 -26
View File
@@ -36,32 +36,7 @@
////////////////////////////////////////////////////////////
struct sfImage
{
sfImage()
{
This = new sf::Image;
OwnInstance = true;
}
sfImage(sf::Image* image)
{
This = image;
OwnInstance = false;
}
sfImage(const sfImage& image)
{
This = image.This ? new sf::Image(*image.This) : NULL;
OwnInstance = true;
}
~sfImage()
{
if (OwnInstance)
delete This;
}
sf::Image* This;
bool OwnInstance;
sf::Image This;
};
-248
View File
@@ -1,248 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.h>
#include <SFML/Graphics/RenderImageStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new renderimage
////////////////////////////////////////////////////////////
sfRenderImage* sfRenderImage_Create(unsigned int width, unsigned int height, sfBool depthBuffer)
{
sfRenderImage* renderImage = new sfRenderImage;
renderImage->This.Create(width, height, depthBuffer == sfTrue);
renderImage->Target = new sfImage(const_cast<sf::Image*>(&renderImage->This.GetImage()));
renderImage->DefaultView.This = renderImage->This.GetDefaultView();
renderImage->CurrentView.This = renderImage->This.GetView();
return renderImage;
}
////////////////////////////////////////////////////////////
/// Destroy an existing renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_Destroy(sfRenderImage* renderImage)
{
delete renderImage->Target;
delete renderImage;
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a renderimage
////////////////////////////////////////////////////////////
unsigned int sfRenderImage_GetWidth(const sfRenderImage* renderImage)
{
CSFML_CALL_RETURN(renderImage, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a renderimage
////////////////////////////////////////////////////////////
unsigned int sfRenderImage_GetHeight(const sfRenderImage* renderImage)
{
CSFML_CALL_RETURN(renderImage, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Set a renderimage as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfRenderImage_SetActive(sfRenderImage* renderImage, sfBool active)
{
CSFML_CALL_RETURN(renderImage, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderImage_SaveGLStates(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, SaveGLStates());
}
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderImage_RestoreGLStates(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, RestoreGLStates());
}
////////////////////////////////////////////////////////////
/// Update the contents of the target image
////////////////////////////////////////////////////////////
void sfRenderImage_Display(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, Display())
}
////////////////////////////////////////////////////////////
/// Draw something on a renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_DrawSprite(sfRenderImage* renderImage, const sfSprite* sprite)
{
CSFML_CHECK(sprite);
CSFML_CALL(renderImage, Draw(sprite->This));
}
void sfRenderImage_DrawShape(sfRenderImage* renderImage, const sfShape* shape)
{
CSFML_CHECK(shape);
CSFML_CALL(renderImage, Draw(shape->This));
}
void sfRenderImage_DrawText(sfRenderImage* renderImage, const sfText* text)
{
CSFML_CHECK(text);
CSFML_CALL(renderImage, Draw(text->This));
}
////////////////////////////////////////////////////////////
/// Draw something on a renderimage with a shader
////////////////////////////////////////////////////////////
void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, const sfSprite* sprite, const sfShader* shader)
{
CSFML_CHECK(sprite);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(sprite->This, shader->This));
}
void sfRenderImage_DrawShapeWithShader(sfRenderImage* renderImage, const sfShape* shape, const sfShader* shader)
{
CSFML_CHECK(shape);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(shape->This, shader->This));
}
void sfRenderImage_DrawTextWithShader(sfRenderImage* renderImage, const sfText* text, const sfShader* shader)
{
CSFML_CHECK(text);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(text->This, shader->This));
}
////////////////////////////////////////////////////////////
/// Clear the renderimage with the given color
////////////////////////////////////////////////////////////
void sfRenderImage_Clear(sfRenderImage* renderImage, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderImage, Clear(SFMLColor));
}
////////////////////////////////////////////////////////////
/// Change the current active view of a renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_SetView(sfRenderImage* renderImage, const sfView* view)
{
CSFML_CHECK(view);
CSFML_CALL(renderImage, SetView(view->This));
renderImage->CurrentView.This = view->This;
}
////////////////////////////////////////////////////////////
/// Get the current active view of a renderimage
////////////////////////////////////////////////////////////
const sfView* sfRenderImage_GetView(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return &renderImage->CurrentView;
}
////////////////////////////////////////////////////////////
/// Get the default view of a renderimage
////////////////////////////////////////////////////////////
const sfView* sfRenderImage_GetDefaultView(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return &renderImage->DefaultView;
}
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
////////////////////////////////////////////////////////////
sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderImage, rect);
sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This);
rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top;
rect.Width = SFMLrect.Width;
rect.Height = SFMLrect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Convert a point in image coordinates into view coordinates
////////////////////////////////////////////////////////////
void sfRenderImage_ConvertCoords(const sfRenderImage* renderImage, unsigned int imageX, unsigned int imageY, float* viewX, float* viewY, const sfView* targetView)
{
CSFML_CHECK(renderImage);
sf::Vector2f point;
if (targetView)
point = renderImage->This.ConvertCoords(imageX, imageY, targetView->This);
else
point = renderImage->This.ConvertCoords(imageX, imageY);
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Get the target image
////////////////////////////////////////////////////////////
const sfImage* sfRenderImage_GetImage(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return renderImage->Target;
}
+248
View File
@@ -0,0 +1,248 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderTexture.h>
#include <SFML/Graphics/RenderTextureStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new rendertexture
////////////////////////////////////////////////////////////
sfRenderTexture* sfRenderTexture_Create(unsigned int width, unsigned int height, sfBool depthBuffer)
{
sfRenderTexture* renderTexture = new sfRenderTexture;
renderTexture->This.Create(width, height, depthBuffer == sfTrue);
renderTexture->Target = new sfTexture(const_cast<sf::Texture*>(&renderTexture->This.GetTexture()));
renderTexture->DefaultView.This = renderTexture->This.GetDefaultView();
renderTexture->CurrentView.This = renderTexture->This.GetView();
return renderTexture;
}
////////////////////////////////////////////////////////////
/// Destroy an existing rendertexture
////////////////////////////////////////////////////////////
void sfRenderTexture_Destroy(sfRenderTexture* renderTexture)
{
delete renderTexture->Target;
delete renderTexture;
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a rendertexture
////////////////////////////////////////////////////////////
unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTexture)
{
CSFML_CALL_RETURN(renderTexture, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a rendertexture
////////////////////////////////////////////////////////////
unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture)
{
CSFML_CALL_RETURN(renderTexture, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Set a rendertexture as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active)
{
CSFML_CALL_RETURN(renderTexture, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderTexture_SaveGLStates(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, SaveGLStates());
}
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderTexture_RestoreGLStates(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, RestoreGLStates());
}
////////////////////////////////////////////////////////////
/// Update the contents of the target texture
////////////////////////////////////////////////////////////
void sfRenderTexture_Display(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, Display())
}
////////////////////////////////////////////////////////////
/// Draw something on a rendertexture
////////////////////////////////////////////////////////////
void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* sprite)
{
CSFML_CHECK(sprite);
CSFML_CALL(renderTexture, Draw(sprite->This));
}
void sfRenderTexture_DrawShape(sfRenderTexture* renderTexture, const sfShape* shape)
{
CSFML_CHECK(shape);
CSFML_CALL(renderTexture, Draw(shape->This));
}
void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* text)
{
CSFML_CHECK(text);
CSFML_CALL(renderTexture, Draw(text->This));
}
////////////////////////////////////////////////////////////
/// Draw something on a rendertexture with a shader
////////////////////////////////////////////////////////////
void sfRenderTexture_DrawSpriteWithShader(sfRenderTexture* renderTexture, const sfSprite* sprite, const sfShader* shader)
{
CSFML_CHECK(sprite);
CSFML_CHECK(shader);
CSFML_CALL(renderTexture, Draw(sprite->This, shader->This));
}
void sfRenderTexture_DrawShapeWithShader(sfRenderTexture* renderTexture, const sfShape* shape, const sfShader* shader)
{
CSFML_CHECK(shape);
CSFML_CHECK(shader);
CSFML_CALL(renderTexture, Draw(shape->This, shader->This));
}
void sfRenderTexture_DrawTextWithShader(sfRenderTexture* renderTexture, const sfText* text, const sfShader* shader)
{
CSFML_CHECK(text);
CSFML_CHECK(shader);
CSFML_CALL(renderTexture, Draw(text->This, shader->This));
}
////////////////////////////////////////////////////////////
/// Clear the rendertexture with the given color
////////////////////////////////////////////////////////////
void sfRenderTexture_Clear(sfRenderTexture* renderTexture, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderTexture, Clear(SFMLColor));
}
////////////////////////////////////////////////////////////
/// Change the current active view of a rendertexture
////////////////////////////////////////////////////////////
void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfView* view)
{
CSFML_CHECK(view);
CSFML_CALL(renderTexture, SetView(view->This));
renderTexture->CurrentView.This = view->This;
}
////////////////////////////////////////////////////////////
/// Get the current active view of a rendertexture
////////////////////////////////////////////////////////////
const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTexture)
{
CSFML_CHECK_RETURN(renderTexture, NULL);
return &renderTexture->CurrentView;
}
////////////////////////////////////////////////////////////
/// Get the default view of a rendertexture
////////////////////////////////////////////////////////////
const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* renderTexture)
{
CSFML_CHECK_RETURN(renderTexture, NULL);
return &renderTexture->DefaultView;
}
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
////////////////////////////////////////////////////////////
sfIntRect sfRenderTexture_GetViewport(const sfRenderTexture* renderTexture, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderTexture, rect);
sf::IntRect SFMLrect = renderTexture->This.GetViewport(view->This);
rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top;
rect.Width = SFMLrect.Width;
rect.Height = SFMLrect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Convert a point in texture coordinates into view coordinates
////////////////////////////////////////////////////////////
void sfRenderTexture_ConvertCoords(const sfRenderTexture* renderTexture, unsigned int textureX, unsigned int textureY, float* viewX, float* viewY, const sfView* targetView)
{
CSFML_CHECK(renderTexture);
sf::Vector2f point;
if (targetView)
point = renderTexture->This.ConvertCoords(textureX, textureY, targetView->This);
else
point = renderTexture->This.ConvertCoords(textureX, textureY);
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Get the target texture
////////////////////////////////////////////////////////////
const sfTexture* sfRenderTexture_GetTexture(const sfRenderTexture* renderTexture)
{
CSFML_CHECK_RETURN(renderTexture, NULL);
return renderTexture->Target;
}
@@ -22,27 +22,27 @@
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGESTRUCT_H
#define SFML_RENDERIMAGESTRUCT_H
#ifndef SFML_RENDERTEXTURESTRUCT_H
#define SFML_RENDERTEXTURESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/ViewStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfRenderWindow
// Internal structure of sfRenderTexture
////////////////////////////////////////////////////////////
struct sfRenderImage
struct sfRenderTexture
{
sf::RenderImage This;
const sfImage* Target;
sfView DefaultView;
sfView CurrentView;
sf::RenderTexture This;
const sfTexture* Target;
sfView DefaultView;
sfView CurrentView;
};
#endif // SFML_RENDERIMAGESTRUCT_H
#endif // SFML_RENDERTEXTURESTRUCT_H
+14
View File
@@ -470,3 +470,17 @@ void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned i
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Copy the current contents of a window to an image
////////////////////////////////////////////////////////////
sfImage* sfRenderWindow_Capture(const sfRenderWindow* renderWindow)
{
CSFML_CHECK(renderWindow);
sfImage* image = new sfImage;
image->This = renderWindow->This.Capture();
return image;
}
+2 -2
View File
@@ -27,7 +27,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shader.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
@@ -145,7 +145,7 @@ void sfShader_SetParameter4(sfShader* shader, const char* name, float x, float y
////////////////////////////////////////////////////////////
/// Set a texture parameter in a shader
////////////////////////////////////////////////////////////
void sfShader_SetTexture(sfShader* shader, const char* name, const sfImage* texture)
void sfShader_SetTexture(sfShader* shader, const char* name, const sfTexture* texture)
{
CSFML_CHECK(texture);
CSFML_CALL(shader, SetTexture(name, *texture->This))
+18 -29
View File
@@ -37,12 +37,8 @@
////////////////////////////////////////////////////////////
sfSprite* sfSprite_Create(void)
{
sfSprite* sprite = new sfSprite;
sprite->Image = NULL;
sprite->SubRect.Left = sprite->This.GetSubRect().Left;
sprite->SubRect.Top = sprite->This.GetSubRect().Top;
sprite->SubRect.Width = sprite->This.GetSubRect().Width;
sprite->SubRect.Height = sprite->This.GetSubRect().Height;
sfSprite* sprite = new sfSprite;
sprite->Texture = NULL;
return sprite;
}
@@ -302,14 +298,14 @@ void sfSprite_TransformToGlobal(const sfSprite* sprite, float pointX, float poin
////////////////////////////////////////////////////////////
/// Change the image of a sprite
/// Change the texture of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNewSize)
void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool adjustToNewSize)
{
if (image)
if (texture && texture->This)
{
CSFML_CALL(sprite, SetImage(*image->This, adjustToNewSize == sfTrue))
sprite->Image = image;
CSFML_CALL(sprite, SetTexture(*texture->This, adjustToNewSize == sfTrue))
sprite->Texture = texture;
}
}
@@ -320,7 +316,6 @@ void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNe
void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle)
{
CSFML_CALL(sprite, SetSubRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)))
sprite->SubRect = rectangle;
}
@@ -352,13 +347,13 @@ void sfSprite_FlipY(sfSprite* sprite, sfBool flipped)
////////////////////////////////////////////////////////////
/// Get the source image of a sprite
/// Get the source texture of a sprite
////////////////////////////////////////////////////////////
const sfImage* sfSprite_GetImage(const sfSprite* sprite)
const sfTexture* sfSprite_GetTexture(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL)
return sprite->Image;
return sprite->Texture;
}
@@ -370,7 +365,14 @@ sfIntRect sfSprite_GetSubRect(const sfSprite* sprite)
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
return sprite->SubRect;
sf::IntRect sfmlRect = sprite->This.GetSubRect();
rect.Left = sfmlRect.Left;
rect.Top = sfmlRect.Top;
rect.Width = sfmlRect.Width;
rect.Height = sfmlRect.Height;
return rect;
}
@@ -390,16 +392,3 @@ float sfSprite_GetHeight(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetSize().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the color of a given pixel in a sprite
////////////////////////////////////////////////////////////
sfColor sfSprite_GetPixel(const sfSprite* sprite, unsigned int x, unsigned int y)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, color)
sf::Color SFMLColor = sprite->This.GetPixel(x, y);
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
+3 -5
View File
@@ -29,8 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/TextureStruct.h>
////////////////////////////////////////////////////////////
@@ -38,9 +37,8 @@
////////////////////////////////////////////////////////////
struct sfSprite
{
sf::Sprite This;
const sfImage* Image;
sfIntRect SubRect;
sf::Sprite This;
const sfTexture* Texture;
};
+295
View File
@@ -0,0 +1,295 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Texture.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderWindowStruct.h>
#include <SFML/Window/WindowStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
////////////////////////////////////////////////////////////
/// Create a new texture
////////////////////////////////////////////////////////////
sfTexture* sfTexture_Create(unsigned int width, unsigned int height)
{
sfTexture* texture = new sfTexture;
if (!texture->This->Create(width, height))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from a file
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntRect* area)
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
if (!texture->This->LoadFromFile(filename))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from a file in memory
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
if (!texture->This->LoadFromMemory(data, sizeInBytes))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from a custom stream
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfIntRect* area)
{
CSFML_CHECK_RETURN(stream, NULL);
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
CallbackStream sfmlStream(stream);
if (!texture->This->LoadFromStream(sfmlStream))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from an image
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfIntRect* area)
{
CSFML_CHECK_RETURN(image, NULL);
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
if (!texture->This->LoadFromImage(image->This, rect))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Copy an existing texture
////////////////////////////////////////////////////////////
sfTexture* sfTexture_Copy(sfTexture* texture)
{
CSFML_CHECK_RETURN(texture, NULL);
return new sfTexture(*texture);
}
////////////////////////////////////////////////////////////
/// Destroy an existing texture
////////////////////////////////////////////////////////////
void sfTexture_Destroy(sfTexture* texture)
{
delete texture;
}
////////////////////////////////////////////////////////////
/// Return the width of the texture
////////////////////////////////////////////////////////////
unsigned int sfTexture_GetWidth(const sfTexture* texture)
{
CSFML_CALL_PTR_RETURN(texture, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Return the height of the texture
////////////////////////////////////////////////////////////
unsigned int sfTexture_GetHeight(const sfTexture* texture)
{
CSFML_CALL_PTR_RETURN(texture, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Copy a texture's pixels to an image
////////////////////////////////////////////////////////////
sfImage* sfTexture_CopyToImage(const sfTexture* texture)
{
CSFML_CHECK_RETURN(texture, NULL);
CSFML_CHECK_RETURN(texture->This, NULL);
sfImage* image = new sfImage;
image->This = texture->This->CopyToImage();
return image;
}
////////////////////////////////////////////////////////////
/// Update a texture from an array of pixels
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromPixels(sfTexture* texture, const sfUint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y)
{
CSFML_CALL_PTR(texture, Update(pixels, width, height, x, y));
}
////////////////////////////////////////////////////////////
/// Update a texture from an image
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromImage(sfTexture* texture, const sfImage* image, unsigned int x, unsigned int y)
{
CSFML_CHECK(image);
CSFML_CALL_PTR(texture, Update(image->This, x, y));
}
////////////////////////////////////////////////////////////
/// Update a texture from the contents of a window
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromWindow(sfTexture* texture, const sfWindow* window, unsigned int x, unsigned int y)
{
CSFML_CHECK(window);
CSFML_CALL_PTR(texture, Update(window->This, x, y));
}
////////////////////////////////////////////////////////////
/// Update a texture from the contents of a render-window
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromRenderWindow(sfTexture* texture, const sfRenderWindow* renderWindow, unsigned int x, unsigned int y)
{
CSFML_CHECK(renderWindow);
CSFML_CALL_PTR(texture, Update(renderWindow->This, x, y));
}
////////////////////////////////////////////////////////////
/// Activate a texture for rendering
////////////////////////////////////////////////////////////
void sfTexture_Bind(const sfTexture* texture)
{
CSFML_CALL_PTR(texture, Bind());
}
////////////////////////////////////////////////////////////
/// Enable or disable the smooth filter on a texture
////////////////////////////////////////////////////////////
void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth)
{
CSFML_CALL_PTR(texture, SetSmooth(smooth == sfTrue));
}
////////////////////////////////////////////////////////////
/// Tell whether the smooth filter is enabled or not for a texture
////////////////////////////////////////////////////////////
sfBool sfTexture_IsSmooth(const sfTexture* texture)
{
CSFML_CHECK_RETURN(texture, sfFalse);
CSFML_CHECK_RETURN(texture->This, sfFalse);
return texture->This->IsSmooth();
}
////////////////////////////////////////////////////////////
/// Convert a rectangle of pixels into texture coordinates
////////////////////////////////////////////////////////////
sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle)
{
sfFloatRect result = {0, 0, 0, 0};
CSFML_CHECK_RETURN(texture, result);
CSFML_CHECK_RETURN(texture->This, result);
sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
sf::FloatRect sfmlResult = texture->This->GetTexCoords(rect);
result.Left = sfmlResult.Left;
result.Top = sfmlResult.Top;
result.Width = sfmlResult.Width;
result.Height = sfmlResult.Height;
return result;
}
////////////////////////////////////////////////////////////
/// Get the maximum texture size allowed
////////////////////////////////////////////////////////////
unsigned int sfTexture_GetMaximumSize()
{
return sf::Texture::GetMaximumSize();
}
+68
View File
@@ -0,0 +1,68 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TEXTURESTRUCT_H
#define SFML_TEXTURESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Texture.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfTexture
////////////////////////////////////////////////////////////
struct sfTexture
{
sfTexture()
{
This = new sf::Texture;
OwnInstance = true;
}
sfTexture(sf::Texture* texture)
{
This = texture;
OwnInstance = false;
}
sfTexture(const sfTexture& texture)
{
This = texture.This ? new sf::Texture(*texture.This) : NULL;
OwnInstance = true;
}
~sfTexture()
{
if (OwnInstance)
delete This;
}
sf::Texture* This;
bool OwnInstance;
};
#endif // SFML_TEXTURESTRUCT_H