1 #include "xorrectangle.h"
5 #include "gtkutil/glwidget.h"
8 #include <gtk/gtkglwidget.h>
10 //#include "stream/stringstream.h"
12 bool XORRectangle::initialised() const
17 void XORRectangle::lazy_init()
20 cr = gdk_cairo_create(gtk_widget_get_window(m_widget));
24 void XORRectangle::draw() const
26 const int x = float_to_integer(m_rectangle.x);
27 const int y = float_to_integer(m_rectangle.y);
28 const int w = float_to_integer(m_rectangle.w);
29 const int h = float_to_integer(m_rectangle.h);
30 GtkAllocation allocation;
31 gtk_widget_get_allocation(m_widget, &allocation);
32 cairo_rectangle(cr, x, -(h) - (y - allocation.height), w, h);
33 cairo_set_source_rgb(cr, 1, 1, 1);
34 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE);
38 XORRectangle::XORRectangle(ui::GLArea widget) : m_widget(widget), cr(0)
42 XORRectangle::~XORRectangle()
49 void XORRectangle::set(rectangle_t rectangle)
51 if (gtk_widget_get_realized(m_widget)) {
52 if( m_rectangle.w != rectangle.w || m_rectangle.h != rectangle.h ){
53 //if( !(m_rectangle.w == 0 && m_rectangle.h == 0 && rectangle.w == 0 && rectangle.h == 0) ){
54 //globalOutputStream() << "m_x" << m_rectangle.x << " m_y" << m_rectangle.y << " m_w" << m_rectangle.w << " m_h" << m_rectangle.h << "\n";
55 //globalOutputStream() << "__x" << rectangle.x << " __y" << rectangle.y << " __w" << rectangle.w << " __h" << rectangle.h << "\n";
56 if ( glwidget_make_current( m_widget ) != FALSE ) {
57 GlobalOpenGL_debugAssertNoErrors();
60 gdk_gl_drawable_get_size( gtk_widget_get_gl_drawable( m_widget ), &width, &height );
62 glViewport( 0, 0, width, height );
63 glMatrixMode( GL_PROJECTION );
65 glOrtho( 0, width, 0, height, -100, 100 );
67 glMatrixMode( GL_MODELVIEW );
70 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
71 glDisable( GL_DEPTH_TEST );
73 glDrawBuffer( GL_FRONT );
76 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
80 glDisable( GL_TEXTURE_2D );
81 glBegin( GL_LINE_LOOP );
82 glVertex2f( m_rectangle.x, m_rectangle.y + m_rectangle.h );
83 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y + m_rectangle.h );
84 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y );
85 glVertex2f( m_rectangle.x, m_rectangle.y );
88 glBegin( GL_LINE_LOOP );
89 glVertex2f( rectangle.x, rectangle.y + rectangle.h );
90 glVertex2f( rectangle.x + rectangle.w, rectangle.y + rectangle.h );
91 glVertex2f( rectangle.x + rectangle.w, rectangle.y );
92 glVertex2f( rectangle.x, rectangle.y );
95 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
96 glDrawBuffer( GL_BACK );
97 GlobalOpenGL_debugAssertNoErrors();
98 //glwidget_swap_buffers( m_widget );
99 glwidget_make_current( m_widget );
102 m_rectangle = rectangle;