aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/image.cc40
-rw-r--r--dw/image.hh3
-rw-r--r--dw/types.cc46
-rw-r--r--dw/types.hh9
4 files changed, 97 insertions, 1 deletions
diff --git a/dw/image.cc b/dw/image.cc
index 457fe8d8..13212cdc 100644
--- a/dw/image.cc
+++ b/dw/image.cc
@@ -38,6 +38,18 @@ ImageMapsList::ImageMap::~ImageMap ()
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 @@ void ImageMapsList::setCurrentMapDefaultLink (int link)
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 @@ void Image::draw (core::View *view, core::Rectangle *area)
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 @@ void Image::draw (core::View *view, core::Rectangle *area)
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 */
diff --git a/dw/image.hh b/dw/image.hh
index 94855faf..8e133b28 100644
--- a/dw/image.hh
+++ b/dw/image.hh
@@ -39,6 +39,7 @@ private:
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 @@ public:
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);
};
diff --git a/dw/types.cc b/dw/types.cc
index eec74dba..3bc78ded 100644
--- a/dw/types.cc
+++ b/dw/types.cc
@@ -39,6 +39,17 @@ Rectangle::Rectangle (int x, int y, int width, int height)
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 @@ Circle::Circle (int x, int y, int radius)
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 @@ Polygon::~Polygon ()
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 ();
diff --git a/dw/types.hh b/dw/types.hh
index a0f862e6..ce643239 100644
--- a/dw/types.hh
+++ b/dw/types.hh
@@ -8,6 +8,10 @@
namespace dw {
namespace core {
+namespace style {
+ class Style;
+}
+
enum HPosition
{
HPOS_LEFT,
@@ -54,6 +58,8 @@ class Shape: public lout::object::Object
{
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 @@ public:
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 @@ public:
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 @@ public:
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);
};