From 846e726a53c564fc3765bc1c175877e497c2a10b Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 22 Jul 2017 17:15:15 +1000 Subject: [PATCH] Remove from gtkutil/xorrectangle.h --- libs/gtkutil/CMakeLists.txt | 2 +- libs/gtkutil/xorrectangle.cpp | 50 +++++++++++++++++++++++++++++++++++ libs/gtkutil/xorrectangle.h | 45 ++++++------------------------- 3 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 libs/gtkutil/xorrectangle.cpp diff --git a/libs/gtkutil/CMakeLists.txt b/libs/gtkutil/CMakeLists.txt index 7781a1ef..a0bb6d99 100644 --- a/libs/gtkutil/CMakeLists.txt +++ b/libs/gtkutil/CMakeLists.txt @@ -21,7 +21,7 @@ add_library(gtkutil toolbar.cpp toolbar.h widget.cpp widget.h window.cpp window.h - xorrectangle.h + xorrectangle.cpp xorrectangle.h ) target_include_directories(gtkutil PRIVATE uilib) diff --git a/libs/gtkutil/xorrectangle.cpp b/libs/gtkutil/xorrectangle.cpp new file mode 100644 index 00000000..364c24e3 --- /dev/null +++ b/libs/gtkutil/xorrectangle.cpp @@ -0,0 +1,50 @@ +#include "xorrectangle.h" + +#include + +bool XORRectangle::initialised() const +{ + return cr != nullptr; +} + +void XORRectangle::lazy_init() +{ + if (!initialised()) { + cr = gdk_cairo_create(gtk_widget_get_window(m_widget)); + } +} + +void XORRectangle::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); +} + +XORRectangle::XORRectangle(ui::Widget widget) : m_widget(widget), cr(0) +{ +} + +XORRectangle::~XORRectangle() +{ + if (initialised()) { + cairo_destroy(cr); + } +} + +void XORRectangle::set(rectangle_t rectangle) +{ + if (gtk_widget_get_realized(m_widget)) { + lazy_init(); + draw(); + m_rectangle = rectangle; + draw(); + } +} 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 ); }; -- 2.39.2