changeset 1617:db2b2e40a177

draw image maps when image not loaded http://lists.auriga.wearlab.de/pipermail/dillo-dev/2010-March/007393.html (Johannes has already fixed the Rectangle clipping problem. Why the polygons aren't shown initially isn't known yet.)
author corvid <corvid@lavabit.com>
date Thu, 11 Mar 2010 16:47:09 +0000
parents 29662d35e068
children 3e2034b39789
files dw/image.cc dw/image.hh dw/types.cc dw/types.hh
diffstat 4 files changed, 97 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dw/image.cc	Thu Mar 11 16:27:37 2010 +0100
+++ b/dw/image.cc	Thu Mar 11 16:47:09 2010 +0000
@@ -38,6 +38,18 @@
    delete shapesAndLinks;
 }
 
+void ImageMapsList::ImageMap::draw (core::View *view,core::style::Style *style,
+                                    int x, int y)
+{
+   container::typed::Iterator <ShapeAndLink> it;
+
+   for (it = shapesAndLinks->iterator (); it.hasNext (); ) {
+      ShapeAndLink *shapeAndLink = it.getNext ();
+
+      shapeAndLink->shape->draw(view, style, x, y);
+   }
+}
+
 void ImageMapsList::ImageMap::add (core::Shape *shape, int link) {
    ShapeAndLink *shapeAndLink = new ShapeAndLink ();
    shapeAndLink->shape = shape;
@@ -105,6 +117,15 @@
    currentMap->setDefaultLink (link);
 }
 
+void ImageMapsList::drawMap (lout::object::Object *key, core::View *view,
+                             core::style::Style *style, int x, int y)
+{
+   ImageMap *map = imageMaps->get (key);
+
+   if (map)
+      map->draw(view, style, x, y);
+}
+
 int ImageMapsList::link (object::Object *key, int x, int y)
 {
    int link = -1;
@@ -348,12 +369,17 @@
                           intersection.x - dx, intersection.y - dy,
                           intersection.width, intersection.height);
    } else {
+      core::View *clippingView;
+
       if (altText && altText[0]) {
+         core::View *usedView = view;
+
+         clippingView = NULL;
+
          if (altTextWidth == -1)
             altTextWidth =
                layout->textWidth (getStyle()->font, altText, strlen (altText));
 
-         core::View *clippingView = NULL, *usedView = view;
          if ((getContentWidth() < altTextWidth) ||
              (getContentHeight() <
               getStyle()->font->ascent + getStyle()->font->descent)) {
@@ -374,6 +400,18 @@
          if (clippingView)
             view->mergeClippingView (clippingView);
       }
+      if (mapKey) {
+         clippingView = view->getClippingView (allocation.x +
+                                               getStyle()->boxOffsetX (),
+                                               allocation.y +
+                                               getStyle()->boxOffsetY (),
+                                               getContentWidth(),
+                                               getContentHeight());
+         mapList->drawMap(mapKey, clippingView, getStyle(),
+                          allocation.x + getStyle()->boxOffsetX (),
+                          allocation.y + getStyle()->boxOffsetY ());
+         view->mergeClippingView (clippingView);
+      }
    }
 
    /** TODO: draw selection */
--- a/dw/image.hh	Thu Mar 11 16:27:37 2010 +0100
+++ b/dw/image.hh	Thu Mar 11 16:47:09 2010 +0000
@@ -39,6 +39,7 @@
          ImageMap ();
          ~ImageMap ();
 
+         void draw (core::View *view, core::style::Style *style, int x, int y);
          void add (core::Shape *shape, int link);
          void setDefaultLink (int link) { defaultLink = link; };
          int link (int x, int y);
@@ -55,6 +56,8 @@
    void startNewMap (lout::object::Object *key);
    void addShapeToCurrentMap (core::Shape *shape, int link);
    void setCurrentMapDefaultLink (int link);
+   void drawMap(lout::object::Object *key, core::View *view,
+                core::style::Style *style, int x, int y);
    int link (lout::object::Object *key, int x, int y);
 };
 
--- a/dw/types.cc	Thu Mar 11 16:27:37 2010 +0100
+++ b/dw/types.cc	Thu Mar 11 16:47:09 2010 +0000
@@ -39,6 +39,17 @@
    this->height = height;
 }
 
+/*
+ * Draw rectangle in view relative to point (x,y).
+ */
+void Rectangle::draw (core::View *view, core::style::Style *style, int x,int y)
+{
+   const bool filled = false;
+
+   view->drawRectangle(style->color, core::style::Color::SHADING_NORMAL,filled,
+                       x + this->x, y + this->y, this->width, this->height);
+}
+
 /**
  * Return whether this rectangle and otherRect intersect. If yes,
  * return the intersection rectangle in dest.
@@ -124,6 +135,20 @@
    this->radius = radius;
 }
 
+/*
+ * Draw circle in view relative to point (x,y).
+ */
+void Circle::draw (core::View *view, core::style::Style *style, int x, int y)
+{
+   const bool filled = false;
+
+   /* drawArc()  wants x, y, w, h for a rectangle, and then it draws the arc
+    * inside that */
+   view->drawArc(style->color, core::style::Color::SHADING_NORMAL, filled,
+                 x + this->x - this->radius, y + this->y - this->radius,
+                 2 * this->radius, 2 * this->radius, 0, 360);
+}
+
 bool Circle::isPointWithin (int x, int y)
 {
    return
@@ -145,6 +170,27 @@
    delete points;
 }
 
+/*
+ * Draw polygon in view relative to point (x,y).
+ */
+void Polygon::draw (core::View *view, core::style::Style *style, int x, int y)
+{
+   if (points->size()) {
+      int i;
+      const bool filled = false;
+      int (*pointArray)[2] =
+                     (int (*)[2]) malloc(points->size() * sizeof(*pointArray));
+
+      for (i = 0; i < points->size(); i++) {
+         pointArray[i][0] = x + points->getRef(i)->x;
+         pointArray[i][1] = y + points->getRef(i)->y;
+      }
+      view->drawPolygon(style->color, core::style::Color::SHADING_NORMAL,
+                        filled, pointArray, i);
+      free(pointArray);
+   }
+}
+
 void Polygon::addPoint (int x, int y)
 {
    points->increase ();
--- a/dw/types.hh	Thu Mar 11 16:27:37 2010 +0100
+++ b/dw/types.hh	Thu Mar 11 16:47:09 2010 +0000
@@ -8,6 +8,10 @@
 namespace dw {
 namespace core {
 
+namespace style {
+   class Style;
+}
+
 enum HPosition
 {
    HPOS_LEFT,
@@ -54,6 +58,8 @@
 {
 public:
    virtual bool isPointWithin (int x, int y) = 0;
+   virtual void draw (core::View *view, core::style::Style *style, int x,
+                      int y) = 0;
 };
 
 /**
@@ -70,6 +76,7 @@
    inline Rectangle () { }
    Rectangle (int x, int y, int width, int height);
 
+   void draw (core::View *view, core::style::Style *style, int x, int y);
    bool intersectsWith (Rectangle *otherRect, Rectangle *dest);
    bool isSubsetOf (Rectangle *otherRect);
    bool isPointWithin (int x, int y);
@@ -86,6 +93,7 @@
 
    Circle (int x, int y, int radius);
 
+   void draw (core::View *view, core::style::Style *style, int x, int y);
    bool isPointWithin (int x, int y);
 };
 
@@ -116,6 +124,7 @@
    Polygon ();
    ~Polygon ();
 
+   void draw (core::View *view, core::style::Style *style, int x, int y);
    void addPoint (int x, int y);
    bool isPointWithin (int x, int y);
 };