mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Add getters and checks for nullness
This commit is contained in:
parent
3011a62589
commit
aa615060e4
@ -19,6 +19,8 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL2/SDL_rect.h>
|
||||
|
||||
#include <SDL2pp/Point.hh>
|
||||
@ -65,4 +67,18 @@ const SDL_Point* Point::Get() const {
|
||||
return point_.get();
|
||||
}
|
||||
|
||||
bool Point::IsNull() const {
|
||||
return point_ == nullptr;
|
||||
}
|
||||
|
||||
int Point::GetX() const {
|
||||
assert(!IsNull());
|
||||
return point_->x;
|
||||
}
|
||||
|
||||
int Point::GetY() const {
|
||||
assert(!IsNull());
|
||||
return point_->y;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,11 @@ public:
|
||||
|
||||
SDL_Point* Get();
|
||||
const SDL_Point* Get() const;
|
||||
|
||||
bool IsNull() const;
|
||||
|
||||
int GetX() const;
|
||||
int GetY() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <SDL2/SDL_rect.h>
|
||||
|
||||
#include <SDL2pp/Rect.hh>
|
||||
@ -75,4 +77,38 @@ Rect Rect::FromCenter(int cx, int cy, int w, int h) {
|
||||
return Rect(cx - w/2, cy - h/2, cx + w - w/2, cy + h - h/2);
|
||||
}
|
||||
|
||||
bool Rect::IsNull() const {
|
||||
return rect_ == nullptr;
|
||||
}
|
||||
|
||||
int Rect::GetX() const {
|
||||
assert(!IsNull());
|
||||
return rect_->x;
|
||||
}
|
||||
|
||||
int Rect::GetY() const {
|
||||
assert(!IsNull());
|
||||
return rect_->y;
|
||||
}
|
||||
|
||||
int Rect::GetW() const {
|
||||
assert(!IsNull());
|
||||
return rect_->w;
|
||||
}
|
||||
|
||||
int Rect::GetH() const {
|
||||
assert(!IsNull());
|
||||
return rect_->h;
|
||||
}
|
||||
|
||||
int Rect::GetX2() const {
|
||||
assert(!IsNull());
|
||||
return rect_->x + rect_->w;
|
||||
}
|
||||
|
||||
int Rect::GetY2() const {
|
||||
assert(!IsNull());
|
||||
return rect_->y + rect_->h;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,6 +48,15 @@ public:
|
||||
|
||||
SDL_Rect* Get();
|
||||
const SDL_Rect* Get() const;
|
||||
|
||||
bool IsNull() const;
|
||||
|
||||
int GetX() const;
|
||||
int GetY() const;
|
||||
int GetW() const;
|
||||
int GetH() const;
|
||||
int GetX2() const;
|
||||
int GetY2() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user