2020-11-17 11:16:16 +00:00
|
|
|
#include "xorrectangle.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
bool XORRectangle::initialised() const
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
return !!cr;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XORRectangle::lazy_init()
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
if (!initialised()) {
|
|
|
|
cr = gdk_cairo_create(gtk_widget_get_window(m_widget));
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XORRectangle::draw() const
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
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);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XORRectangle::XORRectangle(ui::GLArea widget) : m_widget(widget), cr(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XORRectangle::~XORRectangle()
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
if (initialised()) {
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XORRectangle::set(rectangle_t rectangle)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
if (gtk_widget_get_realized(m_widget)) {
|
|
|
|
lazy_init();
|
|
|
|
draw();
|
|
|
|
m_rectangle = rectangle;
|
|
|
|
draw();
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|