Skip to content

Commit

Permalink
Added an override for point_in_rect that takes a tpoint argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 22, 2016
1 parent 80115b1 commit 374eb2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sdl/rect.cpp
Expand Up @@ -12,10 +12,10 @@
See the COPYING file for more details.
*/

#include "gui/core/point.hpp"
#include "sdl/rect.hpp"
#include "sdl/utils.hpp"


namespace sdl
{

Expand All @@ -31,12 +31,16 @@ SDL_Rect create_rect(const int x, const int y, const int w, const int h)
return rect;
}


bool point_in_rect(int x, int y, const SDL_Rect& rect)
{
return x >= rect.x && y >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
}

bool point_in_rect(const gui2::tpoint& point, const SDL_Rect& rect)
{
return point.x >= rect.x && point.y >= rect.y && point.x < rect.x + rect.w && point.y < rect.y + rect.h;
}

bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2)
{
return (rect1.x < rect2.x+rect2.w && rect2.x < rect1.x+rect1.w &&
Expand Down
5 changes: 5 additions & 0 deletions src/sdl/rect.hpp
Expand Up @@ -25,6 +25,9 @@

#include <SDL_rect.h>

namespace gui2 {
class tpoint;
}

namespace sdl
{
Expand All @@ -51,6 +54,8 @@ SDL_Rect create_rect(const int x, const int y, const int w, const int h);
*/
bool point_in_rect(int x, int y, const SDL_Rect& rect);

bool point_in_rect(const gui2::tpoint& point, const SDL_Rect& rect);

/**
* Tests whether two rectangles overlap.
*
Expand Down

1 comment on commit 374eb2e

@CelticMinstrel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an overload, not an override!

Please sign in to comment.