X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=libs%2Fgtkutil%2Fxorrectangle.h;h=8c3ca3cf03c7ced2c74e57c1f78be15a7c1097cd;hb=846e726a53c564fc3765bc1c175877e497c2a10b;hp=6c6abdf531c6512eed6e5792b9afc1c27366a69f;hpb=05c4f87ffdaa10249971244a12b6e1985f23758c;p=xonotic%2Fnetradiant.git diff --git a/libs/gtkutil/xorrectangle.h b/libs/gtkutil/xorrectangle.h index 6c6abdf5..8c3ca3cf 100644 --- a/libs/gtkutil/xorrectangle.h +++ b/libs/gtkutil/xorrectangle.h @@ -22,7 +22,7 @@ #if !defined ( INCLUDED_XORRECTANGLE_H ) #define INCLUDED_XORRECTANGLE_H -#include +#include #include #include "math/vector.h" @@ -64,46 +64,17 @@ class XORRectangle rectangle_t m_rectangle; -GtkWidget* m_widget; +ui::Widget m_widget; cairo_t *cr; -bool initialised() const { - return cr != nullptr; -} -void lazy_init(){ - if ( !initialised() ) { - cr = gdk_cairo_create(gtk_widget_get_window(m_widget)); - } -} -void draw() const { - const int x = float_to_integer( m_rectangle.x ); - const int y = float_to_integer( m_rectangle.y ); - const int w = float_to_integer( m_rectangle.w ); - const int h = float_to_integer( m_rectangle.h ); - GtkAllocation allocation; - gtk_widget_get_allocation(m_widget, &allocation); - cairo_rectangle(cr, x, -(h) - (y - allocation.height), w, h); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); - cairo_stroke(cr); -} +bool initialised() const; +void lazy_init(); +void draw() const; public: -XORRectangle( ui::Widget widget ) : m_widget( widget ), cr( 0 ) { -} -~XORRectangle(){ - if ( initialised() ) { - cairo_destroy(cr); - } -} -void set( rectangle_t rectangle ){ - if ( gtk_widget_get_realized( m_widget ) ) { - lazy_init(); - draw(); - m_rectangle = rectangle; - draw(); - } -} +XORRectangle( ui::Widget widget ); +~XORRectangle(); +void set( rectangle_t rectangle ); };