commit 409c581f29601382547a7cd3d387518b765364ef
parent 8b4a301d6088cade779c4097a5f34fe743ebaadd
Author: JP Cimalando <jp-dev@inbox.ru>
Date: Thu, 7 Feb 2019 21:27:32 +0100
Widget drawing with cairo in local coordinates
Diffstat:
3 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/dgl/src/WidgetPrivateData.cpp b/dgl/src/WidgetPrivateData.cpp
@@ -19,6 +19,9 @@
#ifdef DGL_OPENGL
# include "../OpenGL.hpp"
#endif
+#ifdef DGL_CAIRO
+# include "../Cairo.hpp"
+#endif
START_NAMESPACE_DGL
@@ -73,6 +76,14 @@ void Widget::PrivateData::display(const uint width,
}
#endif
+#ifdef DGL_CAIRO
+ cairo_t* cr = parent.getGraphicsContext().cairo;
+ cairo_matrix_t matrix;
+ cairo_get_matrix(cr, &matrix);
+ cairo_translate(cr, absolutePos.getX(), absolutePos.getY());
+ // TODO: scaling with cairo
+#endif
+
// display widget
self->onDisplay();
@@ -84,6 +95,10 @@ void Widget::PrivateData::display(const uint width,
}
#endif
+#ifdef DGL_CAIRO
+ cairo_set_matrix(cr, &matrix);
+#endif
+
displaySubWidgets(width, height, scaling);
}
diff --git a/examples/CairoUI/DemoWidgetBanner.cpp b/examples/CairoUI/DemoWidgetBanner.cpp
@@ -59,11 +59,7 @@ void DemoWidgetBanner::onDisplay()
{
cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
- Point<int> pt = getAbsolutePos();
Size<uint> sz = getSize();
-
- int x = pt.getX();
- int y = pt.getY();
int w = sz.getWidth();
int h = sz.getHeight();
@@ -75,8 +71,8 @@ void DemoWidgetBanner::onDisplay()
{
for (int c = 0; c < columns; ++c)
{
- double cx = x + xoff + radius + c * diameter;
- double cy = y + yoff + radius + r * diameter;
+ double cx = xoff + radius + c * diameter;
+ double cy = yoff + radius + r * diameter;
char ch = banner[c + r * columns];
if (ch != ' ')
diff --git a/examples/CairoUI/DemoWidgetClickable.cpp b/examples/CairoUI/DemoWidgetClickable.cpp
@@ -28,11 +28,7 @@ void DemoWidgetClickable::onDisplay()
{
cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
- Point<int> pt = getAbsolutePos();
Size<uint> sz = getSize();
-
- int x = pt.getX();
- int y = pt.getY();
int w = sz.getWidth();
int h = sz.getHeight();
@@ -48,17 +44,17 @@ void DemoWidgetClickable::onDisplay()
cairo_set_source_rgb(cr, 0.0, 0.0, 0.75);
break;
}
- cairo_rectangle(cr, x, y, w, h);
+ cairo_rectangle(cr, 0, 0, w, h);
cairo_fill(cr);
cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
cairo_new_path(cr);
- cairo_move_to(cr, x + 0.25 * w, y + 0.25 * h);
- cairo_line_to(cr, x + 0.75 * w, y + 0.75 * h);
+ cairo_move_to(cr, 0.25 * w, 0.25 * h);
+ cairo_line_to(cr, 0.75 * w, 0.75 * h);
cairo_stroke(cr);
cairo_new_path(cr);
- cairo_move_to(cr, x + 0.75 * w, y + 0.25 * h);
- cairo_line_to(cr, x + 0.25 * w, y + 0.75 * h);
+ cairo_move_to(cr, 0.75 * w, 0.25 * h);
+ cairo_line_to(cr, 0.25 * w, 0.75 * h);
cairo_stroke(cr);
}