mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Update constant attribute to function in class Rect, Point, ErrorViewer,
Texture
This commit is contained in:
parent
5581a57e1b
commit
4d636586c2
|
@ -258,13 +258,13 @@ namespace MiniEngine
|
||||||
return SDL_RectEquals(&a,&b)==SDL_TRUE;
|
return SDL_RectEquals(&a,&b)==SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rect::hasIntersection(const Rect& r)
|
bool Rect::hasIntersection(const Rect& r) const
|
||||||
{
|
{
|
||||||
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
|
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
|
||||||
return SDL_HasIntersection(&a,&b)==SDL_TRUE;
|
return SDL_HasIntersection(&a,&b)==SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect Rect::getIntersection(const Rect& r)
|
Rect Rect::getIntersection(const Rect& r) const
|
||||||
{
|
{
|
||||||
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
|
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
|
||||||
if(SDL_IntersectRect(&a,&b,&c)==SDL_TRUE)
|
if(SDL_IntersectRect(&a,&b,&c)==SDL_TRUE)
|
||||||
|
@ -277,7 +277,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect Rect::getUnion(const Rect& r)
|
Rect Rect::getUnion(const Rect& r) const
|
||||||
{
|
{
|
||||||
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
|
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
|
||||||
SDL_UnionRect(&a,&b,&c);//void
|
SDL_UnionRect(&a,&b,&c);//void
|
||||||
|
@ -295,7 +295,7 @@ namespace MiniEngine
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Point Point::toSDLPoint()
|
SDL_Point Point::toSDLPoint() const
|
||||||
{
|
{
|
||||||
SDL_Point p;
|
SDL_Point p;
|
||||||
p.x = x;
|
p.x = x;
|
||||||
|
@ -303,7 +303,7 @@ namespace MiniEngine
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Point::inRect(Rect rect)
|
bool Point::inRect(const Rect& rect) const
|
||||||
{
|
{
|
||||||
auto p = toSDLPoint();
|
auto p = toSDLPoint();
|
||||||
auto r = rect.toSDLRect();
|
auto r = rect.toSDLRect();
|
||||||
|
@ -363,7 +363,7 @@ namespace MiniEngine
|
||||||
str = SDL_GetError();
|
str = SDL_GetError();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ErrorViewer::getError()
|
std::string ErrorViewer::getError() const
|
||||||
{
|
{
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -738,19 +738,22 @@ namespace MiniEngine
|
||||||
return _get();
|
return _get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::_set(SDL_Texture* p)//private
|
//private
|
||||||
|
void Texture::_set(SDL_Texture* p)
|
||||||
{
|
{
|
||||||
_text.reset(p,SDL_DestroyTexture);
|
_text.reset(p,SDL_DestroyTexture);
|
||||||
updateInfo();
|
updateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::_clear()//private
|
//private
|
||||||
|
void Texture::_clear()
|
||||||
{
|
{
|
||||||
_text.reset();
|
_text.reset();
|
||||||
updateInfo();
|
updateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Texture* Texture::_get()//private
|
//private
|
||||||
|
SDL_Texture* Texture::_get() const
|
||||||
{
|
{
|
||||||
return _text.get();
|
return _text.get();
|
||||||
}
|
}
|
||||||
|
@ -765,17 +768,17 @@ namespace MiniEngine
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Texture::getw()
|
int Texture::getw() const
|
||||||
{
|
{
|
||||||
return rect.w;
|
return rect.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Texture::geth()
|
int Texture::geth() const
|
||||||
{
|
{
|
||||||
return rect.h;
|
return rect.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture::isReady()
|
bool Texture::isReady() const
|
||||||
{
|
{
|
||||||
return (_get() != nullptr);
|
return (_get() != nullptr);
|
||||||
}
|
}
|
||||||
|
@ -785,7 +788,7 @@ namespace MiniEngine
|
||||||
return SDL_SetTextureBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
return SDL_SetTextureBlendMode(_get(), _internal::getSDLBlendModeFromBlendMode(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
BlendMode Texture::getBlendMode()
|
BlendMode Texture::getBlendMode() const
|
||||||
{
|
{
|
||||||
SDL_BlendMode temp;
|
SDL_BlendMode temp;
|
||||||
SDL_GetTextureBlendMode(_get(), &temp);
|
SDL_GetTextureBlendMode(_get(), &temp);
|
||||||
|
@ -800,14 +803,14 @@ namespace MiniEngine
|
||||||
return SDL_SetTextureAlphaMod(_get(), temp);
|
return SDL_SetTextureAlphaMod(_get(), temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Texture::getAlphaMode()
|
int Texture::getAlphaMode() const
|
||||||
{
|
{
|
||||||
Uint8 temp;
|
Uint8 temp;
|
||||||
SDL_GetTextureAlphaMod(_get(), &temp);
|
SDL_GetTextureAlphaMod(_get(), &temp);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorMode Texture::getColorMode()
|
ColorMode Texture::getColorMode() const
|
||||||
{
|
{
|
||||||
ColorMode pack;
|
ColorMode pack;
|
||||||
Uint8 r, g, b;
|
Uint8 r, g, b;
|
||||||
|
@ -823,7 +826,7 @@ namespace MiniEngine
|
||||||
return SDL_SetTextureColorMod(_get(), mode.r, mode.g, mode.b);
|
return SDL_SetTextureColorMod(_get(), mode.r, mode.g, mode.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBA Texture::getRGBA()
|
RGBA Texture::getRGBA() const
|
||||||
{
|
{
|
||||||
return RGBA(getColorMode(), getAlphaMode());
|
return RGBA(getColorMode(), getAlphaMode());
|
||||||
}
|
}
|
||||||
|
@ -835,8 +838,8 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
/// updateInfo() must be called after Texture is changed.
|
/// updateInfo() must be called after Texture is changed.
|
||||||
|
//protected
|
||||||
void Texture::updateInfo()//protected
|
void Texture::updateInfo()
|
||||||
{
|
{
|
||||||
if(_get()==nullptr)
|
if(_get()==nullptr)
|
||||||
{
|
{
|
||||||
|
|
28
MiniEngine.h
28
MiniEngine.h
|
@ -20,9 +20,9 @@ namespace MiniEngine
|
||||||
SDL_Rect toSDLRect() const;
|
SDL_Rect toSDLRect() const;
|
||||||
bool isEmpty();
|
bool isEmpty();
|
||||||
bool operator == (const Rect&) const;
|
bool operator == (const Rect&) const;
|
||||||
bool hasIntersection(const Rect&);
|
bool hasIntersection(const Rect&) const;
|
||||||
Rect getIntersection(const Rect&);
|
Rect getIntersection(const Rect&) const;
|
||||||
Rect getUnion(const Rect&);
|
Rect getUnion(const Rect&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Point
|
class Point
|
||||||
|
@ -31,8 +31,8 @@ namespace MiniEngine
|
||||||
int x, y;
|
int x, y;
|
||||||
Point(int X, int Y);
|
Point(int X, int Y);
|
||||||
Point();
|
Point();
|
||||||
SDL_Point toSDLPoint();
|
SDL_Point toSDLPoint() const;
|
||||||
bool inRect(Rect rect);
|
bool inRect(const Rect& rect) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ColorMode
|
class ColorMode
|
||||||
|
@ -67,7 +67,7 @@ namespace MiniEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void fetch();
|
void fetch();
|
||||||
std::string getError();
|
std::string getError() const;
|
||||||
const char* what() const throw() override;
|
const char* what() const throw() override;
|
||||||
private:
|
private:
|
||||||
std::string str;
|
std::string str;
|
||||||
|
@ -178,18 +178,18 @@ namespace MiniEngine
|
||||||
Texture();
|
Texture();
|
||||||
~Texture() = default;
|
~Texture() = default;
|
||||||
Rect getSize();
|
Rect getSize();
|
||||||
int getw();
|
int getw() const;
|
||||||
int geth();
|
int geth() const;
|
||||||
bool isReady();
|
bool isReady() const;
|
||||||
int setBlendMode(BlendMode mode);
|
int setBlendMode(BlendMode mode);
|
||||||
BlendMode getBlendMode();
|
BlendMode getBlendMode() const;
|
||||||
/// Alpha: 0: Transparent 255: opaque
|
/// Alpha: 0: Transparent 255: opaque
|
||||||
int setAlphaMode(int alpha);
|
int setAlphaMode(int alpha);
|
||||||
int getAlphaMode();
|
int getAlphaMode() const;
|
||||||
|
|
||||||
ColorMode getColorMode();
|
ColorMode getColorMode() const;
|
||||||
int setColorMode(ColorMode mode);
|
int setColorMode(ColorMode mode);
|
||||||
RGBA getRGBA();
|
RGBA getRGBA() const;
|
||||||
void setRGBA(RGBA pack);
|
void setRGBA(RGBA pack);
|
||||||
|
|
||||||
void release();
|
void release();
|
||||||
|
@ -200,7 +200,7 @@ namespace MiniEngine
|
||||||
std::shared_ptr<SDL_Texture> _text;
|
std::shared_ptr<SDL_Texture> _text;
|
||||||
void _set(SDL_Texture*);
|
void _set(SDL_Texture*);
|
||||||
void _clear();
|
void _clear();
|
||||||
SDL_Texture* _get();
|
SDL_Texture* _get() const;
|
||||||
Rect rect;
|
Rect rect;
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user