Browse Source

Widget drawing with cairo in local coordinates

pull/131/head
JP Cimalando falkTX <falktx@gmail.com> 6 years ago
parent
commit
409c581f29
Signed by: falkTX <falktx@gmail.com> GPG Key ID: 2D3445A829213837
3 changed files with 22 additions and 15 deletions
  1. +15
    -0
      dgl/src/WidgetPrivateData.cpp
  2. +2
    -6
      examples/CairoUI/DemoWidgetBanner.cpp
  3. +5
    -9
      examples/CairoUI/DemoWidgetClickable.cpp

+ 15
- 0
dgl/src/WidgetPrivateData.cpp View File

@@ -19,6 +19,9 @@
#ifdef DGL_OPENGL #ifdef DGL_OPENGL
# include "../OpenGL.hpp" # include "../OpenGL.hpp"
#endif #endif
#ifdef DGL_CAIRO
# include "../Cairo.hpp"
#endif


START_NAMESPACE_DGL START_NAMESPACE_DGL


@@ -73,6 +76,14 @@ void Widget::PrivateData::display(const uint width,
} }
#endif #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 // display widget
self->onDisplay(); self->onDisplay();


@@ -84,6 +95,10 @@ void Widget::PrivateData::display(const uint width,
} }
#endif #endif


#ifdef DGL_CAIRO
cairo_set_matrix(cr, &matrix);
#endif

displaySubWidgets(width, height, scaling); displaySubWidgets(width, height, scaling);
} }




+ 2
- 6
examples/CairoUI/DemoWidgetBanner.cpp View File

@@ -59,11 +59,7 @@ void DemoWidgetBanner::onDisplay()
{ {
cairo_t* cr = getParentWindow().getGraphicsContext().cairo; cairo_t* cr = getParentWindow().getGraphicsContext().cairo;


Point<int> pt = getAbsolutePos();
Size<uint> sz = getSize(); Size<uint> sz = getSize();

int x = pt.getX();
int y = pt.getY();
int w = sz.getWidth(); int w = sz.getWidth();
int h = sz.getHeight(); int h = sz.getHeight();


@@ -75,8 +71,8 @@ void DemoWidgetBanner::onDisplay()
{ {
for (int c = 0; c < columns; ++c) 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]; char ch = banner[c + r * columns];
if (ch != ' ') if (ch != ' ')


+ 5
- 9
examples/CairoUI/DemoWidgetClickable.cpp View File

@@ -28,11 +28,7 @@ void DemoWidgetClickable::onDisplay()
{ {
cairo_t* cr = getParentWindow().getGraphicsContext().cairo; cairo_t* cr = getParentWindow().getGraphicsContext().cairo;


Point<int> pt = getAbsolutePos();
Size<uint> sz = getSize(); Size<uint> sz = getSize();

int x = pt.getX();
int y = pt.getY();
int w = sz.getWidth(); int w = sz.getWidth();
int h = sz.getHeight(); int h = sz.getHeight();


@@ -48,17 +44,17 @@ void DemoWidgetClickable::onDisplay()
cairo_set_source_rgb(cr, 0.0, 0.0, 0.75); cairo_set_source_rgb(cr, 0.0, 0.0, 0.75);
break; break;
} }
cairo_rectangle(cr, x, y, w, h);
cairo_rectangle(cr, 0, 0, w, h);
cairo_fill(cr); cairo_fill(cr);


cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
cairo_new_path(cr); 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_stroke(cr);
cairo_new_path(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); cairo_stroke(cr);
} }




Loading…
Cancel
Save