|
@@ -5,11 +5,19 @@
|
|
|
#include "SDL_framerate.h"
|
|
#include "SDL_framerate.h"
|
|
|
#include <map>
|
|
#include <map>
|
|
|
#include <list>
|
|
#include <list>
|
|
|
|
|
+#include <algorithm>
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
#ifdef __GNUC__
|
|
|
#define sprintf_s snprintf
|
|
#define sprintf_s snprintf
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#ifdef max
|
|
|
|
|
+#undef max
|
|
|
|
|
+#endif
|
|
|
|
|
+#ifdef min
|
|
|
|
|
+#undef min
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
class CDefEssential;
|
|
class CDefEssential;
|
|
|
class AdventureMapButton;
|
|
class AdventureMapButton;
|
|
|
class CHighlightableButtonsGroup;
|
|
class CHighlightableButtonsGroup;
|
|
@@ -92,37 +100,45 @@ struct Rect : public SDL_Rect
|
|
|
y = Y;
|
|
y = Y;
|
|
|
w = W;
|
|
w = W;
|
|
|
h = H;
|
|
h = H;
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
Rect(const SDL_Rect & r)
|
|
Rect(const SDL_Rect & r)
|
|
|
{
|
|
{
|
|
|
x = r.x;
|
|
x = r.x;
|
|
|
y = r.y;
|
|
y = r.y;
|
|
|
w = r.w;
|
|
w = r.w;
|
|
|
h = r.h;
|
|
h = r.h;
|
|
|
- };
|
|
|
|
|
- bool isIn(int qx, int qy)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ bool isIn(int qx, int qy) const
|
|
|
{
|
|
{
|
|
|
if (qx > x && qx<x+w && qy>y && qy<y+h)
|
|
if (qx > x && qx<x+w && qy>y && qy<y+h)
|
|
|
return true;
|
|
return true;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- bool isIn(const Point &q)
|
|
|
|
|
|
|
+ bool isIn(const Point &q) const
|
|
|
{
|
|
{
|
|
|
return isIn(q.x,q.y);
|
|
return isIn(q.x,q.y);
|
|
|
}
|
|
}
|
|
|
- Point topLeft()
|
|
|
|
|
|
|
+ Point topLeft() const
|
|
|
{
|
|
{
|
|
|
return Point(x,y);
|
|
return Point(x,y);
|
|
|
}
|
|
}
|
|
|
- Point bottomRight()
|
|
|
|
|
|
|
+ Point topRight() const
|
|
|
|
|
+ {
|
|
|
|
|
+ return Point(x+w,y);
|
|
|
|
|
+ }
|
|
|
|
|
+ Point bottomLeft() const
|
|
|
|
|
+ {
|
|
|
|
|
+ return Point(x,y+h);
|
|
|
|
|
+ }
|
|
|
|
|
+ Point bottomRight() const
|
|
|
{
|
|
{
|
|
|
return Point(x+w,y+h);
|
|
return Point(x+w,y+h);
|
|
|
}
|
|
}
|
|
|
- Rect operator+(const Rect &p)
|
|
|
|
|
|
|
+ Rect operator+(const Rect &p) const
|
|
|
{
|
|
{
|
|
|
return Rect(x+p.x,y+p.y,w,h);
|
|
return Rect(x+p.x,y+p.y,w,h);
|
|
|
}
|
|
}
|
|
|
- Rect operator+(const Point &p)
|
|
|
|
|
|
|
+ Rect operator+(const Point &p) const
|
|
|
{
|
|
{
|
|
|
return Rect(x+p.x,y+p.y,w,h);
|
|
return Rect(x+p.x,y+p.y,w,h);
|
|
|
}
|
|
}
|
|
@@ -132,6 +148,27 @@ struct Rect : public SDL_Rect
|
|
|
y += p.y;
|
|
y += p.y;
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
+ Rect operator&(const Rect &p) const //rect intersection
|
|
|
|
|
+ {
|
|
|
|
|
+ bool intersect = isIn(p.topLeft()) || isIn(p.bottomRight()) || isIn(p.topRight()) || isIn(p.bottomLeft());
|
|
|
|
|
+
|
|
|
|
|
+ if(intersect)
|
|
|
|
|
+ {
|
|
|
|
|
+ Rect ret;
|
|
|
|
|
+ ret.x = std::max(this->x, p.x);
|
|
|
|
|
+ ret.y = std::max(this->y, p.y);
|
|
|
|
|
+ Point bR; //bottomRight point of returned rect
|
|
|
|
|
+ bR.x = std::min(this->w+this->x, p.w+p.x);
|
|
|
|
|
+ bR.y = std::min(this->h+this->y, p.h+p.y);
|
|
|
|
|
+ ret.w = bR.x - ret.x;
|
|
|
|
|
+ ret.h = bR.y - ret.y;
|
|
|
|
|
+ return ret;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ return Rect();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
class IShowable
|
|
class IShowable
|