aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-09-15 14:59:06 +0200
committerSebastian Geerken <devnull@localhost>2013-09-15 14:59:06 +0200
commit2435de82b60cadb0283ef1636fbe078cf2beac0f (patch)
tree479915a54287c33e349912227b9c9944dd640586
parent0ab5863987ec411ebf1ead15ff64de4b7766666e (diff)
Very simple implementation of ExternalImgRenderer (used to immediately draw imgbuf updates); concretization for widgets.
-rw-r--r--dw/style.cc22
-rw-r--r--dw/style.hh55
-rw-r--r--dw/widget.cc65
-rw-r--r--dw/widget.hh22
4 files changed, 162 insertions, 2 deletions
diff --git a/dw/style.cc b/dw/style.cc
index fca8d5d1..2328c1e4 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -485,6 +485,28 @@ StyleImage::~StyleImage ()
delete styleImgRenderer;
}
+void StyleImage::ExternalImgRenderer::setBuffer (core::Imgbuf *buffer,
+ bool resize)
+{
+ // Nothing to do?
+}
+
+void StyleImage::ExternalImgRenderer::drawRow (int row)
+{
+ // Extremely simple implementation
+ Style *style;
+ if (readyToDraw () && (style = getStyle ())) {
+ int x, y, width, height;
+ getArea (&x, &y, &width, &height);
+ draw (x + style->margin.left + style->borderWidth.left,
+ y + style->margin.top + style->borderWidth.top,
+ width - style->margin.left - style->borderWidth.left
+ - style->margin.right - style->borderWidth.right,
+ height - style->margin.top - style->borderWidth.top
+ - style->margin.bottom - style->borderWidth.bottom);
+ }
+}
+
// ----------------------------------------------------------------------
/*
diff --git a/dw/style.hh b/dw/style.hh
index c09a52f0..217ed4b8 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -723,6 +723,48 @@ private:
~StyleImage ();
public:
+ /**
+ * \brief Useful (but not mandatory) base class for updates of
+ * areas with background images.
+ */
+ class ExternalImgRenderer: public ImgRenderer
+ {
+ public:
+ void setBuffer (core::Imgbuf *buffer, bool resize);
+ void drawRow (int row);
+
+ /**
+ * \brief If this method returns false, nothing is done at all.
+ */
+ virtual bool readyToDraw () = 0;
+
+ /**
+ * \brief Return the total area this background image is
+ * attached to, in canvas coordinates.
+ */
+ virtual void getArea (int *x, int *y, int *width, int *height) = 0;
+
+ /**
+ * \brief Return the "reference area".
+ *
+ * See comment of "drawBackground".
+ */
+ virtual void getRefArea (int *xRef, int *yRef, int *widthRef,
+ int *heightRef) = 0;
+
+
+ /**
+ * \brief Return the style this background image is part of.
+ */
+ virtual Style *getStyle () = 0;
+
+ /**
+ * \brief Draw (or queue for drawing) an area, which is given in
+ * canvas coordinates.
+ */
+ virtual void draw (int x, int y, int width, int height) = 0;
+ };
+
static StyleImage *create () { return new StyleImage (); }
inline void ref () { refCount++; }
@@ -731,6 +773,19 @@ public:
inline Imgbuf *getImgbuf () { return imgbuf; }
inline ImgRenderer *getMainImgRenderer () { return imgRendererDist; }
+
+ /**
+ * \brief Add an additional ImgRenderer, especially used for
+ * drawing.
+ */
+ inline void putExternalImgRenderer (ImgRenderer *ir)
+ { imgRendererDist->put (ir); }
+
+ /**
+ * \brief Remove a previously added additional ImgRenderer.
+ */
+ inline void removeExternalImgRenderer (ImgRenderer *ir)
+ { imgRendererDist->remove (ir); }
};
void drawBorder (View *view, Layout *layout, Rectangle *area,
diff --git a/dw/widget.cc b/dw/widget.cc
index 766d2500..317d5eeb 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -32,6 +32,46 @@ namespace core {
// ----------------------------------------------------------------------
+bool Widget::WidgetImgRenderer::readyToDraw ()
+{
+ return widget->wasAllocated ();
+}
+
+void Widget::WidgetImgRenderer::getArea (int *x, int *y, int *width,
+ int *height)
+{
+ *x = widget->allocation.x;
+ *y = widget->allocation.y;
+ *width = widget->allocation.width;
+ *height = widget->getHeight ();
+}
+
+void Widget::WidgetImgRenderer::getRefArea (int *xRef, int *yRef, int *widthRef,
+ int *heightRef)
+{
+ /**
+ * \todo Reference should be the containing block (which will be
+ * introduced later), not the widget allocation.
+ */
+ *xRef = widget->allocation.x;
+ *yRef = widget->allocation.y;
+ *widthRef = widget->allocation.width;
+ *heightRef = widget->getHeight ();
+}
+
+style::Style *Widget::WidgetImgRenderer::getStyle ()
+{
+ return widget->getStyle ();
+}
+
+void Widget::WidgetImgRenderer::draw (int x, int y, int width, int height)
+{
+ widget->queueDrawArea (x - widget->allocation.x, y - widget->allocation.y,
+ width, height);
+}
+
+// ----------------------------------------------------------------------
+
int Widget::CLASS_ID = -1;
Widget::Widget ()
@@ -55,6 +95,8 @@ Widget::Widget ()
deleteCallbackData = NULL;
deleteCallbackFunc = NULL;
+
+ widgetImgRenderer = NULL;
}
Widget::~Widget ()
@@ -62,6 +104,12 @@ Widget::~Widget ()
if (deleteCallbackFunc)
deleteCallbackFunc (deleteCallbackData);
+ if (widgetImgRenderer) {
+ if (style && style->backgroundImage)
+ style->backgroundImage->removeExternalImgRenderer (widgetImgRenderer);
+ delete widgetImgRenderer;
+ }
+
if (style)
style->unref ();
@@ -281,6 +329,10 @@ void Widget::setStyle (style::Style *style)
{
bool sizeChanged;
+ if (widgetImgRenderer && this->style && this->style->backgroundImage)
+ this->style->backgroundImage->removeExternalImgRenderer
+ (widgetImgRenderer);
+
style->ref ();
if (this->style) {
@@ -291,6 +343,15 @@ void Widget::setStyle (style::Style *style)
this->style = style;
+ if (style && style->backgroundImage) {
+ // Create instance of WidgetImgRenderer when needed. Until this
+ // widget is deleted, "widgetImgRenderer" will be kept, since it
+ // is not specific to the style, but only to this widget.
+ if (widgetImgRenderer == NULL)
+ widgetImgRenderer = new WidgetImgRenderer (this);
+ style->backgroundImage->putExternalImgRenderer (widgetImgRenderer);
+ }
+
if (layout != NULL) {
layout->updateCursor ();
}
@@ -352,7 +413,7 @@ void Widget::drawBox (View *view, style::Style *style, Rectangle *area,
/**
* \todo Reference should be the containing block (which will be
- * introduced later), not the widget allocation.
+ * introduced later), not the widget allocation.
*/
style::drawBackground (view, layout, &canvasArea,
allocation.x + x, allocation.y + y, width, height,
@@ -379,7 +440,7 @@ void Widget::drawWidgetBox (View *view, Rectangle *area, bool inverse)
/**
* \todo Reference should be the containing block (which will be
- * introduced later), not the widget allocation.
+ * introduced later), not the widget allocation.
*/
style::drawBackground (view, layout, &canvasArea, allocation.x, allocation.y,
allocation.width, getHeight (), allocation.x,
diff --git a/dw/widget.hh b/dw/widget.hh
index 6942221b..c836d117 100644
--- a/dw/widget.hh
+++ b/dw/widget.hh
@@ -74,6 +74,28 @@ protected:
BLOCK_LEVEL = 1 << 6,
};
+ /**
+ * \brief Implementation which represents the whole widget.
+ *
+ * The only instance is set created needed.
+ */
+ class WidgetImgRenderer: public style::StyleImage::ExternalImgRenderer
+ {
+ private:
+ Widget *widget;
+
+ public:
+ inline WidgetImgRenderer (Widget *widget) { this->widget = widget; }
+
+ bool readyToDraw ();
+ void getArea (int *x, int *y, int *width, int *height);
+ void getRefArea (int *xRef, int *yRef, int *widthRef, int *heightRef);
+ style::Style *getStyle ();
+ void draw (int x, int y, int width, int height);
+ };
+
+ WidgetImgRenderer *widgetImgRenderer;
+
private:
/**
* \brief The parent widget, NULL for top-level widgets.