Commit 58cfde68 authored by Erwan Tulou's avatar Erwan Tulou

skins2: cosmetic

parent 4490c867
......@@ -31,7 +31,6 @@
#include "../src/top_window.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
#include "../utils/position.hpp"
#include "../utils/var_percent.hpp"
......
......@@ -29,6 +29,7 @@
#include "../utils/bezier.hpp"
#include "../utils/fsm.hpp"
#include "../utils/observer.hpp"
#include "../utils/position.hpp"
class GenericBitmap;
......
......@@ -92,109 +92,4 @@ private:
}
};
class rect
{
public:
rect( int v_x = 0, int v_y = 0, int v_width = 0, int v_height = 0 )
: x( v_x ), y( v_y ), width( v_width ), height( v_height ) { }
~rect() { }
int x;
int y;
int width;
int height;
// rect2 fully included in rect1
static bool isIncluded( const rect& rect2, const rect& rect1 )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
return x2 >= x1 && x2 + w2 <= x1 + w1
&& y2 >= y1 && y2 + h2 <= y1 + h1;
}
static bool areDisjunct( const rect& rect2, const rect& rect1 )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
return y2 + h2 -1 < y1 // rect2 above rect1
|| y2 > y1 + h1 - 1 // rect2 under rect1
|| x2 > x1 + w1 -1 // rect2 right of rect1
|| x2 + w2 - 1 < x1; // rect2 left of rect1
}
static bool intersect( const rect& rect1, const rect& rect2, rect* pRect )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
if( areDisjunct( rect1, rect2 ) )
return false;
else
{
int left = max( x1, x2 );
int right = min( x1 + w1 - 1, x2 + w2 - 1 );
int top = max( y1, y2 );
int bottom = min( y1 + h1 - 1, y2 + h2 -1 );
pRect->x = left;
pRect->y = top;
pRect->width = right - left + 1;
pRect->height = bottom - top + 1;
return pRect->width > 0 && pRect->height > 0;
}
}
static bool join( const rect& rect1, const rect& rect2, rect* pRect )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
int left = min( x1, x2 );
int right = max( x1 + w1 - 1, x2 + w2 - 1 );
int top = min( y1, y2 );
int bottom = max( y1 + h1 - 1, y2 + h2 -1 );
pRect->x = left;
pRect->y = top;
pRect->width = right - left + 1;
pRect->height = bottom - top + 1;
return pRect->width > 0 && pRect->height > 0;
}
static int min( int x, int y ) { return x < y ? x : y; }
static int max( int x, int y ) { return x < y ? y : x; }
};
#endif
......@@ -162,4 +162,107 @@ private:
};
class rect
{
public:
rect( int v_x = 0, int v_y = 0, int v_width = 0, int v_height = 0 )
: x( v_x ), y( v_y ), width( v_width ), height( v_height ) { }
~rect() { }
int x;
int y;
int width;
int height;
// rect2 fully included in rect1
static bool isIncluded( const rect& rect2, const rect& rect1 )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
return x2 >= x1 && x2 + w2 <= x1 + w1
&& y2 >= y1 && y2 + h2 <= y1 + h1;
}
static bool areDisjunct( const rect& rect2, const rect& rect1 )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
return y2 + h2 -1 < y1 // rect2 above rect1
|| y2 > y1 + h1 - 1 // rect2 under rect1
|| x2 > x1 + w1 -1 // rect2 right of rect1
|| x2 + w2 - 1 < x1; // rect2 left of rect1
}
static bool intersect( const rect& rect1, const rect& rect2, rect* pRect )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
if( areDisjunct( rect1, rect2 ) )
return false;
else
{
int left = max( x1, x2 );
int right = min( x1 + w1 - 1, x2 + w2 - 1 );
int top = max( y1, y2 );
int bottom = min( y1 + h1 - 1, y2 + h2 -1 );
pRect->x = left;
pRect->y = top;
pRect->width = right - left + 1;
pRect->height = bottom - top + 1;
return pRect->width > 0 && pRect->height > 0;
}
}
static bool join( const rect& rect1, const rect& rect2, rect* pRect )
{
int x1 = rect1.x;
int y1 = rect1.y;
int w1 = rect1.width;
int h1 = rect1.height;
int x2 = rect2.x;
int y2 = rect2.y;
int w2 = rect2.width;
int h2 = rect2.height;
int left = min( x1, x2 );
int right = max( x1 + w1 - 1, x2 + w2 - 1 );
int top = min( y1, y2 );
int bottom = max( y1 + h1 - 1, y2 + h2 -1 );
pRect->x = left;
pRect->y = top;
pRect->width = right - left + 1;
pRect->height = bottom - top + 1;
return pRect->width > 0 && pRect->height > 0;
}
static int min( int x, int y ) { return x < y ? x : y; }
static int max( int x, int y ) { return x < y ? y : x; }
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment