mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add BlendMode caster
This commit is contained in:
parent
3267be4a4e
commit
085463c873
|
@ -17,6 +17,41 @@
|
||||||
|
|
||||||
namespace MiniEngine
|
namespace MiniEngine
|
||||||
{
|
{
|
||||||
|
namespace _internal
|
||||||
|
{
|
||||||
|
BlendMode getBlendModeFromSDLBlendMode(SDL_BlendMode mode)
|
||||||
|
{
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
case SDL_BLENDMODE_ADD:
|
||||||
|
return BlendMode::Add;
|
||||||
|
case SDL_BLENDMODE_BLEND:
|
||||||
|
return BlendMode::Blend;
|
||||||
|
case SDL_BLENDMODE_MOD:
|
||||||
|
return BlendMode::Mod;
|
||||||
|
case SDL_BLENDMODE_NONE:
|
||||||
|
default:/// return BlendMode::None on default.
|
||||||
|
return BlendMode::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_BlendMode getSDLBlendModeFromBlendMode(BlendMode mode)
|
||||||
|
{
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
case BlendMode::Add:
|
||||||
|
return SDL_BLENDMODE_ADD;
|
||||||
|
case BlendMode::Blend:
|
||||||
|
return SDL_BLENDMODE_BLEND;
|
||||||
|
case BlendMode::Mod:
|
||||||
|
return SDL_BLENDMODE_MOD;
|
||||||
|
case BlendMode::None:
|
||||||
|
default:/// return SDL_BLENDMODE_NONE on default.
|
||||||
|
return SDL_BLENDMODE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}/// End of namespace _internal
|
||||||
|
|
||||||
Rect::Rect(int X, int Y, int W, int H)
|
Rect::Rect(int X, int Y, int W, int H)
|
||||||
{
|
{
|
||||||
x = X;
|
x = X;
|
||||||
|
@ -213,6 +248,19 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlendMode Surface::getBlendMode()
|
||||||
|
{
|
||||||
|
SDL_BlendMode temp;
|
||||||
|
/// FIXME: return value are ignored.
|
||||||
|
SDL_GetSurfaceBlendMode(_get(),&temp);
|
||||||
|
return _internal::getBlendModeFromSDLBlendMode(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Surface::setBlendMode(BlendMode mode)
|
||||||
|
{
|
||||||
|
return SDL_SetSurfaceBlendMode(_get(),_internal::getSDLBlendModeFromBlendMode(mode));
|
||||||
|
}
|
||||||
|
|
||||||
int Surface::savePNG(const std::string& filename)
|
int Surface::savePNG(const std::string& filename)
|
||||||
{
|
{
|
||||||
return IMG_SavePNG(_get(),filename.c_str());
|
return IMG_SavePNG(_get(),filename.c_str());
|
||||||
|
@ -262,14 +310,14 @@ namespace MiniEngine
|
||||||
|
|
||||||
int Texture::setBlendMode(BlendMode mode)
|
int Texture::setBlendMode(BlendMode mode)
|
||||||
{
|
{
|
||||||
return SDL_SetTextureBlendMode(_get(), static_cast<SDL_BlendMode>(mode));
|
return SDL_SetTextureBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
BlendMode Texture::getBlendMode()
|
BlendMode Texture::getBlendMode()
|
||||||
{
|
{
|
||||||
SDL_BlendMode temp;
|
SDL_BlendMode temp;
|
||||||
SDL_GetTextureBlendMode(_get(), &temp);
|
SDL_GetTextureBlendMode(_get(), &temp);
|
||||||
return static_cast<BlendMode>(temp);
|
return _internal::getBlendModeFromSDLBlendMode(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alpha: 0: Transparent 255: opaque
|
/// Alpha: 0: Transparent 255: opaque
|
||||||
|
@ -356,16 +404,18 @@ namespace MiniEngine
|
||||||
|
|
||||||
int Renderer::setBlendMode(BlendMode mode)
|
int Renderer::setBlendMode(BlendMode mode)
|
||||||
{
|
{
|
||||||
return SDL_SetRenderDrawBlendMode(_get(), static_cast<SDL_BlendMode>(mode));
|
return SDL_SetRenderDrawBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
BlendMode Renderer::getBlendMode()
|
BlendMode Renderer::getBlendMode()
|
||||||
{
|
{
|
||||||
SDL_BlendMode temp;
|
SDL_BlendMode temp;
|
||||||
SDL_GetRenderDrawBlendMode(_get(), &temp);
|
SDL_GetRenderDrawBlendMode(_get(), &temp);
|
||||||
return static_cast<BlendMode>(temp);
|
return _internal::getBlendModeFromSDLBlendMode(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Renderer::setTarget(Texture & t)
|
int Renderer::setTarget(Texture & t)
|
||||||
{
|
{
|
||||||
return SDL_SetRenderTarget(_get(), t._get());
|
return SDL_SetRenderTarget(_get(), t._get());
|
||||||
|
|
18
MiniEngine.h
18
MiniEngine.h
|
@ -89,13 +89,7 @@ namespace MiniEngine
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BlendMode
|
enum class BlendMode { None,Blend,Add,Mod };
|
||||||
{
|
|
||||||
None = SDL_BLENDMODE_NONE,
|
|
||||||
Blend = SDL_BLENDMODE_BLEND,
|
|
||||||
Add = SDL_BLENDMODE_ADD,
|
|
||||||
Mod = SDL_BLENDMODE_MOD
|
|
||||||
};
|
|
||||||
|
|
||||||
class Surface
|
class Surface
|
||||||
{
|
{
|
||||||
|
@ -104,6 +98,8 @@ namespace MiniEngine
|
||||||
int savePNG(const std::string& filename);
|
int savePNG(const std::string& filename);
|
||||||
int getw();
|
int getw();
|
||||||
int geth();
|
int geth();
|
||||||
|
BlendMode getBlendMode();
|
||||||
|
int setBlendMode(BlendMode mode);
|
||||||
protected:
|
protected:
|
||||||
Surface() = default;
|
Surface() = default;
|
||||||
private:
|
private:
|
||||||
|
@ -150,13 +146,7 @@ namespace MiniEngine
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class RendererType
|
enum class RendererType { Software, Accelerated, PresentSync, TargetTexture };
|
||||||
{
|
|
||||||
Software,
|
|
||||||
Accelerated,
|
|
||||||
PresentSync,
|
|
||||||
TargetTexture
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class FlipMode { None, Horizontal, Vertical };
|
enum class FlipMode { None, Horizontal, Vertical };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user