1 #include "xorrectangle.h"
5 #define GARUX_DISABLE_BAD_XORRECTANGLE
7 #if !defined(GARUX_DISABLE_BAD_XORRECTANGLE) && GTK_TARGET == 2
8 #include "gtkutil/glwidget.h"
11 #include <gtk/gtkglwidget.h>
12 #endif // !GARUX_DISABLE_BAD_XORRECTANGLE && GTK_TARGET == 2
14 //#include "stream/stringstream.h"
16 bool XORRectangle::initialised() const
21 void XORRectangle::lazy_init()
24 cr = gdk_cairo_create(gtk_widget_get_window(m_widget));
28 void XORRectangle::draw() const
30 #ifndef WORKAROUND_MACOS_GTK2_DESTROY
31 const int x = float_to_integer(m_rectangle.x);
32 const int y = float_to_integer(m_rectangle.y);
33 const int w = float_to_integer(m_rectangle.w);
34 const int h = float_to_integer(m_rectangle.h);
35 GtkAllocation allocation;
36 gtk_widget_get_allocation(m_widget, &allocation);
37 cairo_rectangle(cr, x, -(h) - (y - allocation.height), w, h);
38 cairo_set_source_rgb(cr, 1, 1, 1);
39 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE);
44 XORRectangle::XORRectangle(ui::GLArea widget) : m_widget(widget), cr(0)
48 XORRectangle::~XORRectangle()
51 #ifndef WORKAROUND_MACOS_GTK2_DESTROY
57 void XORRectangle::set(rectangle_t rectangle)
59 if (gtk_widget_get_realized(m_widget)) {
60 #if !defined(GARUX_DISABLE_BAD_XORRECTANGLE) && GTK_TARGET == 2
61 if( m_rectangle.w != rectangle.w || m_rectangle.h != rectangle.h ){
62 //if( !(m_rectangle.w == 0 && m_rectangle.h == 0 && rectangle.w == 0 && rectangle.h == 0) ){
63 //globalOutputStream() << "m_x" << m_rectangle.x << " m_y" << m_rectangle.y << " m_w" << m_rectangle.w << " m_h" << m_rectangle.h << "\n";
64 //globalOutputStream() << "__x" << rectangle.x << " __y" << rectangle.y << " __w" << rectangle.w << " __h" << rectangle.h << "\n";
65 if ( glwidget_make_current( m_widget ) != FALSE ) {
66 GlobalOpenGL_debugAssertNoErrors();
69 gdk_gl_drawable_get_size( gtk_widget_get_gl_drawable( m_widget ), &width, &height );
71 glViewport( 0, 0, width, height );
72 glMatrixMode( GL_PROJECTION );
74 glOrtho( 0, width, 0, height, -100, 100 );
76 glMatrixMode( GL_MODELVIEW );
79 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
80 glDisable( GL_DEPTH_TEST );
82 glDrawBuffer( GL_FRONT );
85 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
89 glDisable( GL_TEXTURE_2D );
90 glBegin( GL_LINE_LOOP );
91 glVertex2f( m_rectangle.x, m_rectangle.y + m_rectangle.h );
92 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y + m_rectangle.h );
93 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y );
94 glVertex2f( m_rectangle.x, m_rectangle.y );
97 glBegin( GL_LINE_LOOP );
98 glVertex2f( rectangle.x, rectangle.y + rectangle.h );
99 glVertex2f( rectangle.x + rectangle.w, rectangle.y + rectangle.h );
100 glVertex2f( rectangle.x + rectangle.w, rectangle.y );
101 glVertex2f( rectangle.x, rectangle.y );
104 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
105 glDrawBuffer( GL_BACK );
106 GlobalOpenGL_debugAssertNoErrors();
107 //glwidget_swap_buffers( m_widget );
108 glwidget_make_current( m_widget );
111 m_rectangle = rectangle;
112 #else // GARUX_DISABLE_BAD_XORRECTANGLE || GTK_TARGET != 2
115 m_rectangle = rectangle;
117 #endif // !GARUX_DISABLE_BAD_XORRECTANGLE && GTK_TARGET == 2