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
25 #include <gtk/gtkwidget.h>
26 #include "math/vector.h"
29 #include "gtkutil/glwidget.h"
32 #include <gtk/gtkglwidget.h>
34 //#include "stream/stringstream.h"
41 : x( 0 ), y( 0 ), w( 0 ), h( 0 )
43 rectangle_t( float _x, float _y, float _w, float _h )
44 : x( _x ), y( _y ), w( _w ), h( _h )
55 Coord2D( float _x, float _y )
60 inline Coord2D coord2d_device2screen( const Coord2D& coord, unsigned int width, unsigned int height ){
61 return Coord2D( ( ( coord.x + 1.0f ) * 0.5f ) * width, ( ( coord.y + 1.0f ) * 0.5f ) * height );
64 inline rectangle_t rectangle_from_area( const float min[2], const float max[2], unsigned int width, unsigned int height ){
65 Coord2D botleft( coord2d_device2screen( Coord2D( min[0], min[1] ), width, height ) );
66 Coord2D topright( coord2d_device2screen( Coord2D( max[0], max[1] ), width, height ) );
67 return rectangle_t( botleft.x, botleft.y, topright.x - botleft.x, topright.y - botleft.y );
72 rectangle_t m_rectangle;
76 XORRectangle( GtkWidget* widget ) : m_widget( widget ){
80 void set( rectangle_t rectangle ){
81 if ( GTK_WIDGET_REALIZED( m_widget ) ) {
82 if( m_rectangle.w != rectangle.w || m_rectangle.h != rectangle.h ){
83 //if( !(m_rectangle.w == 0 && m_rectangle.h == 0 && rectangle.w == 0 && rectangle.h == 0) ){
84 //globalOutputStream() << "m_x" << m_rectangle.x << " m_y" << m_rectangle.y << " m_w" << m_rectangle.w << " m_h" << m_rectangle.h << "\n";
85 //globalOutputStream() << "__x" << rectangle.x << " __y" << rectangle.y << " __w" << rectangle.w << " __h" << rectangle.h << "\n";
86 if ( glwidget_make_current( m_widget ) != FALSE ) {
87 GlobalOpenGL_debugAssertNoErrors();
90 gdk_gl_drawable_get_size( gtk_widget_get_gl_drawable( m_widget ), &width, &height );
92 glViewport( 0, 0, width, height );
93 glMatrixMode( GL_PROJECTION );
95 glOrtho( 0, width, 0, height, -100, 100 );
96 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
97 glDisable( GL_DEPTH_TEST );
99 glDrawBuffer( GL_FRONT );
101 glEnable( GL_BLEND );
102 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
105 glColor3f( 1, 1, 1 );
106 glDisable( GL_TEXTURE_2D );
107 glBegin( GL_LINE_LOOP );
108 glVertex2f( m_rectangle.x, m_rectangle.y + m_rectangle.h );
109 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y + m_rectangle.h );
110 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y );
111 glVertex2f( m_rectangle.x, m_rectangle.y );
114 glBegin( GL_LINE_LOOP );
115 glVertex2f( rectangle.x, rectangle.y + rectangle.h );
116 glVertex2f( rectangle.x + rectangle.w, rectangle.y + rectangle.h );
117 glVertex2f( rectangle.x + rectangle.w, rectangle.y );
118 glVertex2f( rectangle.x, rectangle.y );
121 glDrawBuffer( GL_BACK );
122 GlobalOpenGL_debugAssertNoErrors();
123 //glwidget_swap_buffers( m_widget );
124 glwidget_make_current( m_widget );
127 m_rectangle = rectangle;