| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined ( INCLUDED_XORRECTANGLE_H ) |
| 23 |
#define INCLUDED_XORRECTANGLE_H |
| 24 |
|
| 25 |
#include <cairo.h> |
| 26 |
#include <uilib/uilib.h> |
| 27 |
#include "math/vector.h" |
| 28 |
|
| 29 |
class rectangle_t |
| 30 |
{ |
| 31 |
public: |
| 32 |
rectangle_t() |
| 33 |
: x( 0 ), y( 0 ), w( 0 ), h( 0 ) |
| 34 |
{} |
| 35 |
rectangle_t( float _x, float _y, float _w, float _h ) |
| 36 |
: x( _x ), y( _y ), w( _w ), h( _h ) |
| 37 |
{} |
| 38 |
float x; |
| 39 |
float y; |
| 40 |
float w; |
| 41 |
float h; |
| 42 |
}; |
| 43 |
|
| 44 |
struct Coord2D |
| 45 |
{ |
| 46 |
float x, y; |
| 47 |
Coord2D( float _x, float _y ) |
| 48 |
: x( _x ), y( _y ){ |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
inline Coord2D coord2d_device2screen( const Coord2D& coord, unsigned int width, unsigned int height ){ |
| 53 |
return Coord2D( ( ( coord.x + 1.0f ) * 0.5f ) * width, ( ( coord.y + 1.0f ) * 0.5f ) * height ); |
| 54 |
} |
| 55 |
|
| 56 |
inline rectangle_t rectangle_from_area( const float min[2], const float max[2], unsigned int width, unsigned int height ){ |
| 57 |
Coord2D botleft( coord2d_device2screen( Coord2D( min[0], min[1] ), width, height ) ); |
| 58 |
Coord2D topright( coord2d_device2screen( Coord2D( max[0], max[1] ), width, height ) ); |
| 59 |
return rectangle_t( botleft.x, botleft.y, topright.x - botleft.x, topright.y - botleft.y ); |
| 60 |
} |
| 61 |
|
| 62 |
class XORRectangle |
| 63 |
{ |
| 64 |
|
| 65 |
rectangle_t m_rectangle; |
| 66 |
|
| 67 |
ui::GLArea m_widget; |
| 68 |
cairo_t *cr; |
| 69 |
|
| 70 |
bool initialised() const; |
| 71 |
void lazy_init(); |
| 72 |
void draw() const; |
| 73 |
|
| 74 |
public: |
| 75 |
XORRectangle( ui::GLArea widget ); |
| 76 |
~XORRectangle(); |
| 77 |
void set( rectangle_t rectangle ); |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
#endif |