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 );
66 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
67 glDisable( GL_DEPTH_TEST );
69 glDrawBuffer( GL_FRONT );
72 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
76 glDisable( GL_TEXTURE_2D );
77 glBegin( GL_LINE_LOOP );
78 glVertex2f( m_rectangle.x, m_rectangle.y + m_rectangle.h );
79 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y + m_rectangle.h );
80 glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y );
81 glVertex2f( m_rectangle.x, m_rectangle.y );
84 glBegin( GL_LINE_LOOP );
85 glVertex2f( rectangle.x, rectangle.y + rectangle.h );
86 glVertex2f( rectangle.x + rectangle.w, rectangle.y + rectangle.h );
87 glVertex2f( rectangle.x + rectangle.w, rectangle.y );
88 glVertex2f( rectangle.x, rectangle.y );
91 glDrawBuffer( GL_BACK );
92 GlobalOpenGL_debugAssertNoErrors();
93 //glwidget_swap_buffers( m_widget );
94 glwidget_make_current( m_widget );
97 m_rectangle = rectangle;