2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined ( INCLUDED_XORRECTANGLE_H )
23 #define INCLUDED_XORRECTANGLE_H
26 #include <uilib/uilib.h>
27 #include "math/vector.h"
33 : x( 0 ), y( 0 ), w( 0 ), h( 0 )
35 rectangle_t( float _x, float _y, float _w, float _h )
36 : x( _x ), y( _y ), w( _w ), h( _h )
47 Coord2D( float _x, float _y )
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 );
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 );
65 rectangle_t m_rectangle;
70 bool initialised() const {
74 if ( !initialised() ) {
75 cr = gdk_cairo_create(gtk_widget_get_window(m_widget));
79 const int x = float_to_integer( m_rectangle.x );
80 const int y = float_to_integer( m_rectangle.y );
81 const int w = float_to_integer( m_rectangle.w );
82 const int h = float_to_integer( m_rectangle.h );
83 GtkAllocation allocation;
84 gtk_widget_get_allocation(m_widget, &allocation);
85 cairo_rectangle(cr, x, -(h) - (y - allocation.height), w, h);
86 cairo_set_source_rgb(cr, 1, 1, 1);
87 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE);
92 XORRectangle( ui::Widget widget ) : m_widget( widget ), cr( 0 ) {
95 if ( initialised() ) {
99 void set( rectangle_t rectangle ){
100 if ( gtk_widget_get_realized( m_widget ) ) {
103 m_rectangle = rectangle;