summaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2011-08-04 07:13:13 +0000
committercorvid <corvid@lavabit.com>2011-08-04 07:13:13 +0000
commitbc05ad05cb92d0b67c6354c2ffe96b4957257242 (patch)
tree693ba73943b0e42feccd994c608328ccbe6ae920 /dw
parentb0b6145de9007ec837a90121c1af5bc86d5e9dfd (diff)
rm my FLTK2-era points array optimisation for drawPolygon()
(I had made it use that less-clear int[][2] interface because fltk2 let you add all of the vertices in one call.) It feels good to change that nasty-looking pointArray in Polygon::draw().
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkviewbase.cc6
-rw-r--r--dw/fltkviewbase.hh3
-rw-r--r--dw/style.cc252
-rw-r--r--dw/types.cc7
-rw-r--r--dw/view.hh2
5 files changed, 137 insertions, 133 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc
index ce8dc475..a9cd6bcc 100644
--- a/dw/fltkviewbase.cc
+++ b/dw/fltkviewbase.cc
@@ -478,7 +478,7 @@ void FltkViewBase::drawArc (core::style::Color *color,
void FltkViewBase::drawPolygon (core::style::Color *color,
core::style::Color::Shading shading,
- bool filled, bool convex, int points[][2],
+ bool filled, bool convex, core::Point *points,
int npoints)
{
if (npoints > 0) {
@@ -493,8 +493,8 @@ void FltkViewBase::drawPolygon (core::style::Color *color,
fl_begin_loop();
for (int i = 0; i < npoints; i++) {
- fl_vertex(translateCanvasXToViewX(points[i][0]),
- translateCanvasYToViewY(points[i][1]));
+ fl_vertex(translateCanvasXToViewX(points[i].x),
+ translateCanvasYToViewY(points[i].y));
}
if (filled) {
if (convex)
diff --git a/dw/fltkviewbase.hh b/dw/fltkviewbase.hh
index e6e85694..b8d1e874 100644
--- a/dw/fltkviewbase.hh
+++ b/dw/fltkviewbase.hh
@@ -98,7 +98,8 @@ public:
int angle1, int angle2);
void drawPolygon (core::style::Color *color,
core::style::Color::Shading shading,
- bool filled, bool convex, int points[][2], int npoints);
+ bool filled, bool convex,
+ core::Point *points, int npoints);
core::View *getClippingView (int x, int y, int width, int height);
void mergeClippingView (core::View *clippingView);
diff --git a/dw/style.cc b/dw/style.cc
index c8cab24f..d11abf82 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -423,7 +423,8 @@ static void drawBorderTop(View *view, Style *style,
int x1, int y1, int x2, int y2)
{
- int points[4][2], d, w;
+ int d, w;
+ Point points[4];
const bool filled = true, convex = true;
bool ridge = false, inset = false, dotted = false;
Color::Shading shading = Color::SHADING_NORMAL;
@@ -453,12 +454,12 @@ static void drawBorderTop(View *view, Style *style,
if (style->borderWidth.top == 1) {
view->drawLine(style->borderColor.top, shading, x1, y1, x2, y2);
} else {
- points[0][0] = x1;
- points[1][0] = x2 + 1;
- points[0][1] = points[1][1] = y1;
- points[2][0] = points[1][0] - style->borderWidth.right;
- points[3][0] = x1 + style->borderWidth.left;
- points[2][1] = points[3][1] = points[0][1] + style->borderWidth.top;
+ points[0].x = x1;
+ points[1].x = x2 + 1;
+ points[0].y = points[1].y = y1;
+ points[2].x = points[1].x - style->borderWidth.right;
+ points[3].x = x1 + style->borderWidth.left;
+ points[2].y = points[3].y = points[0].y + style->borderWidth.top;
view->drawPolygon (style->borderColor.top, shading, filled, convex,
points, 4);
}
@@ -467,21 +468,21 @@ static void drawBorderTop(View *view, Style *style,
ridge = true;
case BORDER_GROOVE:
d = style->borderWidth.top & 1;
- points[0][0] = x1;
- points[1][0] = x2 + 1;
- points[0][1] = points[1][1] = y1;
- points[2][0] = x2 - style->borderWidth.right / 2;
- points[3][0] = x1 + style->borderWidth.left / 2;
- points[2][1] = points[3][1] = y1 + style->borderWidth.top / 2 + d;
+ points[0].x = x1;
+ points[1].x = x2 + 1;
+ points[0].y = points[1].y = y1;
+ points[2].x = x2 - style->borderWidth.right / 2;
+ points[3].x = x1 + style->borderWidth.left / 2;
+ points[2].y = points[3].y = y1 + style->borderWidth.top / 2 + d;
shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
view->drawPolygon (style->borderColor.top, shading, filled, convex,
points, 4);
- points[0][0] = x1 + style->borderWidth.left / 2 + d;
- points[1][0] = x2 - style->borderWidth.right / 2 + 1 - d;
- points[0][1] = points[1][1] = y1 + style->borderWidth.top / 2 + d;
- points[2][0] = x2 - style->borderWidth.right + 1 - d;
- points[3][0] = x1 + style->borderWidth.left;
- points[2][1] = points[3][1] = y1 + style->borderWidth.top;
+ points[0].x = x1 + style->borderWidth.left / 2 + d;
+ points[1].x = x2 - style->borderWidth.right / 2 + 1 - d;
+ points[0].y = points[1].y = y1 + style->borderWidth.top / 2 + d;
+ points[2].x = x2 - style->borderWidth.right + 1 - d;
+ points[3].x = x1 + style->borderWidth.left;
+ points[2].y = points[3].y = y1 + style->borderWidth.top;
shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
view->drawPolygon (style->borderColor.top, shading, filled, convex,
points, 4);
@@ -495,20 +496,20 @@ static void drawBorderTop(View *view, Style *style,
view->drawLine(style->borderColor.top, shading, x1, y1, x2, y2);
break;
}
- points[0][0] = x1;
- points[1][0] = x2 + 1;
- points[0][1] = points[1][1] = y1;
- points[2][0] = points[1][0] - w_r;
- points[3][0] = points[0][0] + w_l;
- points[2][1] = points[3][1] = points[0][1] + w;
+ points[0].x = x1;
+ points[1].x = x2 + 1;
+ points[0].y = points[1].y = y1;
+ points[2].x = points[1].x - w_r;
+ points[3].x = points[0].x + w_l;
+ points[2].y = points[3].y = points[0].y + w;
view->drawPolygon (style->borderColor.top, shading, filled, convex,
points, 4);
- points[0][0] = x1 + style->borderWidth.left - w_l;
- points[1][0] = x2 + 1 - style->borderWidth.right + w_r;
- points[0][1] = points[1][1] = y1 + w + d;
- points[2][0] = x2 + 1 - style->borderWidth.right;
- points[3][0] = x1 + style->borderWidth.left;
- points[2][1] = points[3][1] = y1 + style->borderWidth.top;
+ points[0].x = x1 + style->borderWidth.left - w_l;
+ points[1].x = x2 + 1 - style->borderWidth.right + w_r;
+ points[0].y = points[1].y = y1 + w + d;
+ points[2].x = x2 + 1 - style->borderWidth.right;
+ points[3].x = x1 + style->borderWidth.left;
+ points[2].y = points[3].y = y1 + style->borderWidth.top;
view->drawPolygon (style->borderColor.top, shading, filled, convex,
points, 4);
break;
@@ -519,7 +520,8 @@ static void drawBorderBottom(View *view, Style *style,
int x1, int y1, int x2, int y2)
{
- int points[4][2], d, w;
+ int d, w;
+ Point points[4];
const bool filled = true, convex = true;
bool ridge = false, inset = false, dotted = false;
Color::Shading shading = Color::SHADING_NORMAL;
@@ -549,12 +551,12 @@ static void drawBorderBottom(View *view, Style *style,
if (style->borderWidth.bottom == 1) { /* 1 pixel line */
view->drawLine(style->borderColor.bottom, shading, x1, y1, x2, y2);
} else {
- points[0][0] = x1 - 1;
- points[1][0] = x2 + 2;
- points[0][1] = points[1][1] = y1 + 1;
- points[2][0] = points[1][0] - style->borderWidth.right;
- points[3][0] = points[0][0] + style->borderWidth.left;
- points[2][1] = points[3][1] = points[0][1]-style->borderWidth.bottom;
+ points[0].x = x1 - 1;
+ points[1].x = x2 + 2;
+ points[0].y = points[1].y = y1 + 1;
+ points[2].x = points[1].x - style->borderWidth.right;
+ points[3].x = points[0].x + style->borderWidth.left;
+ points[2].y = points[3].y = points[0].y-style->borderWidth.bottom;
view->drawPolygon (style->borderColor.bottom, shading, filled, convex,
points, 4);
}
@@ -564,22 +566,22 @@ static void drawBorderBottom(View *view, Style *style,
case BORDER_GROOVE:
w = style->borderWidth.bottom;
d = w & 1;
- points[0][0] = x1 - 1;
- points[1][0] = x2 + 2 - d;
- points[0][1] = points[1][1] = y1 + 1;
- points[2][0] = points[1][0] - style->borderWidth.right / 2;
- points[3][0] = points[0][0] + style->borderWidth.left / 2 + d;
- points[2][1] = points[3][1] = points[0][1] - w/2 - d;
+ points[0].x = x1 - 1;
+ points[1].x = x2 + 2 - d;
+ points[0].y = points[1].y = y1 + 1;
+ points[2].x = points[1].x - style->borderWidth.right / 2;
+ points[3].x = points[0].x + style->borderWidth.left / 2 + d;
+ points[2].y = points[3].y = points[0].y - w/2 - d;
shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
view->drawPolygon (style->borderColor.bottom, shading, filled, convex,
points, 4);
// clockwise
- points[0][0] = x1 + style->borderWidth.left - 1;
- points[1][0] = x2 + 1 - style->borderWidth.right + 1;
- points[0][1] = points[1][1] = y1 - w + 1;
- points[2][0] = points[1][0] + style->borderWidth.right / 2;
- points[3][0] = points[0][0] - style->borderWidth.left / 2;
- points[2][1] = points[3][1] = points[0][1] + w/2;
+ points[0].x = x1 + style->borderWidth.left - 1;
+ points[1].x = x2 + 1 - style->borderWidth.right + 1;
+ points[0].y = points[1].y = y1 - w + 1;
+ points[2].x = points[1].x + style->borderWidth.right / 2;
+ points[3].x = points[0].x - style->borderWidth.left / 2;
+ points[2].y = points[3].y = points[0].y + w/2;
shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
view->drawPolygon (style->borderColor.bottom, shading, filled, convex,
points, 4);
@@ -593,20 +595,20 @@ static void drawBorderBottom(View *view, Style *style,
view->drawLine(style->borderColor.bottom, shading, x1, y1, x2, y2);
break;
}
- points[0][0] = x2 + 2;
- points[1][0] = x1 - 1;
- points[0][1] = points[1][1] = y1 + 1;
- points[2][0] = points[1][0] + w_l;
- points[3][0] = points[0][0] - w_r;
- points[2][1] = points[3][1] = points[0][1] - w;
+ points[0].x = x2 + 2;
+ points[1].x = x1 - 1;
+ points[0].y = points[1].y = y1 + 1;
+ points[2].x = points[1].x + w_l;
+ points[3].x = points[0].x - w_r;
+ points[2].y = points[3].y = points[0].y - w;
view->drawPolygon (style->borderColor.bottom, shading, filled, convex,
points, 4);
- points[0][0] = x2 + 2 - style->borderWidth.right + w_r;
- points[1][0] = x1 - 1 + style->borderWidth.left - w_l;
- points[0][1] = points[1][1] = y1 + 1 - w - d;
- points[2][0] = x1 - 1 + style->borderWidth.left;
- points[3][0] = x2 + 2 - style->borderWidth.right;
- points[2][1] = points[3][1] = y1 + 1 - style->borderWidth.bottom;
+ points[0].x = x2 + 2 - style->borderWidth.right + w_r;
+ points[1].x = x1 - 1 + style->borderWidth.left - w_l;
+ points[0].y = points[1].y = y1 + 1 - w - d;
+ points[2].x = x1 - 1 + style->borderWidth.left;
+ points[3].x = x2 + 2 - style->borderWidth.right;
+ points[2].y = points[3].y = y1 + 1 - style->borderWidth.bottom;
view->drawPolygon (style->borderColor.bottom, shading, filled, convex,
points, 4);
break;
@@ -617,7 +619,8 @@ static void drawBorderLeft(View *view, Style *style,
int x1, int y1, int x2, int y2)
{
- int points[4][2], d, w;
+ int d, w;
+ Point points[4];
bool filled = true, convex = true;
bool ridge = false, inset = false, dotted = false;
Color::Shading shading = Color::SHADING_NORMAL;
@@ -646,12 +649,12 @@ static void drawBorderLeft(View *view, Style *style,
if (style->borderWidth.left == 1) { /* 1 pixel line */
view->drawLine(style->borderColor.left, shading, x1, y1, x2, y2);
} else {
- points[0][0] = points[1][0] = x1;
- points[0][1] = y1 - 1;
- points[1][1] = y2 + 1;
- points[2][0] = points[3][0] = points[0][0] + style->borderWidth.left;
- points[2][1] = points[1][1] - style->borderWidth.bottom;
- points[3][1] = points[0][1] + style->borderWidth.top;
+ points[0].x = points[1].x = x1;
+ points[0].y = y1 - 1;
+ points[1].y = y2 + 1;
+ points[2].x = points[3].x = points[0].x + style->borderWidth.left;
+ points[2].y = points[1].y - style->borderWidth.bottom;
+ points[3].y = points[0].y + style->borderWidth.top;
view->drawPolygon (style->borderColor.left, shading, filled, convex,
points, 4);
}
@@ -661,21 +664,21 @@ static void drawBorderLeft(View *view, Style *style,
case BORDER_GROOVE:
w = style->borderWidth.left;
d = w & 1;
- points[0][0] = points[1][0] = x1;
- points[0][1] = y1;
- points[1][1] = y2;
- points[2][0] = points[3][0] = x1 + w / 2 + d;
- points[2][1] = y2 - style->borderWidth.bottom / 2;
- points[3][1] = y1 + style->borderWidth.top / 2;
+ points[0].x = points[1].x = x1;
+ points[0].y = y1;
+ points[1].y = y2;
+ points[2].x = points[3].x = x1 + w / 2 + d;
+ points[2].y = y2 - style->borderWidth.bottom / 2;
+ points[3].y = y1 + style->borderWidth.top / 2;
shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
view->drawPolygon (style->borderColor.left, shading, filled, convex,
points, 4);
- points[0][0] = points[1][0] = x1 + w / 2 + d;
- points[0][1] = y1 + style->borderWidth.top / 2;
- points[1][1] = y2 - style->borderWidth.bottom / 2;
- points[2][0] = points[3][0] = x1 + w;
- points[2][1] = y2 - style->borderWidth.bottom;
- points[3][1] = y1 + style->borderWidth.top;
+ points[0].x = points[1].x = x1 + w / 2 + d;
+ points[0].y = y1 + style->borderWidth.top / 2;
+ points[1].y = y2 - style->borderWidth.bottom / 2;
+ points[2].x = points[3].x = x1 + w;
+ points[2].y = y2 - style->borderWidth.bottom;
+ points[3].y = y1 + style->borderWidth.top;
shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
view->drawPolygon (style->borderColor.left, shading, filled, convex,
points, 4);
@@ -689,20 +692,20 @@ static void drawBorderLeft(View *view, Style *style,
view->drawLine(style->borderColor.left, shading, x1, y1, x2, y2-1);
break;
}
- points[0][0] = points[1][0] = x1;
- points[0][1] = y1 - 1;
- points[1][1] = y2 + 1;
- points[2][0] = points[3][0] = points[0][0] + w;
- points[2][1] = points[1][1] - w_b;
- points[3][1] = points[0][1] + w_t;
+ points[0].x = points[1].x = x1;
+ points[0].y = y1 - 1;
+ points[1].y = y2 + 1;
+ points[2].x = points[3].x = points[0].x + w;
+ points[2].y = points[1].y - w_b;
+ points[3].y = points[0].y + w_t;
view->drawPolygon (style->borderColor.left, shading, filled, convex,
points, 4);
- points[0][0] = points[1][0] = x1 + w + d;
- points[0][1] = y1 - 1 + style->borderWidth.top - w_t;
- points[1][1] = y2 + 1 - style->borderWidth.bottom + w_b;
- points[2][0] = points[3][0] = points[0][0] + w;
- points[2][1] = y2 + 1 - style->borderWidth.bottom;
- points[3][1] = y1 - 1 + style->borderWidth.top;
+ points[0].x = points[1].x = x1 + w + d;
+ points[0].y = y1 - 1 + style->borderWidth.top - w_t;
+ points[1].y = y2 + 1 - style->borderWidth.bottom + w_b;
+ points[2].x = points[3].x = points[0].x + w;
+ points[2].y = y2 + 1 - style->borderWidth.bottom;
+ points[3].y = y1 - 1 + style->borderWidth.top;
view->drawPolygon (style->borderColor.left, shading, filled, convex,
points, 4);
break;
@@ -713,7 +716,8 @@ static void drawBorderRight(View *view, Style *style,
int x1, int y1, int x2, int y2)
{
- int points[4][2], d, w;
+ int d, w;
+ Point points[4];
const bool filled = true, convex = true;
bool ridge = false, inset = false, dotted = false;
Color::Shading shading = Color::SHADING_NORMAL;
@@ -742,12 +746,12 @@ static void drawBorderRight(View *view, Style *style,
if (style->borderWidth.right == 1) { /* 1 pixel line */
view->drawLine(style->borderColor.right, shading, x1, y1, x2, y2);
} else {
- points[0][0] = points[1][0] = x1 + 1;
- points[0][1] = y1 - 1;
- points[1][1] = y2 + 1;
- points[2][0] = points[3][0] = points[0][0]-style->borderWidth.right;
- points[2][1] = points[1][1] - style->borderWidth.bottom;
- points[3][1] = points[0][1] + style->borderWidth.top;
+ points[0].x = points[1].x = x1 + 1;
+ points[0].y = y1 - 1;
+ points[1].y = y2 + 1;
+ points[2].x = points[3].x = points[0].x-style->borderWidth.right;
+ points[2].y = points[1].y - style->borderWidth.bottom;
+ points[3].y = points[0].y + style->borderWidth.top;
view->drawPolygon (style->borderColor.right, shading, filled, convex,
points,4);
}
@@ -757,21 +761,21 @@ static void drawBorderRight(View *view, Style *style,
case BORDER_GROOVE:
w = style->borderWidth.right;
d = w & 1;
- points[0][0] = points[1][0] = x1 + 1;
- points[0][1] = y1;
- points[1][1] = y2;
- points[2][0] = points[3][0] = points[0][0] - w / 2 - d;
- points[2][1] = y2 - style->borderWidth.bottom / 2;
- points[3][1] = points[0][1] + style->borderWidth.top / 2;
+ points[0].x = points[1].x = x1 + 1;
+ points[0].y = y1;
+ points[1].y = y2;
+ points[2].x = points[3].x = points[0].x - w / 2 - d;
+ points[2].y = y2 - style->borderWidth.bottom / 2;
+ points[3].y = points[0].y + style->borderWidth.top / 2;
shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
view->drawPolygon (style->borderColor.right, shading, filled, convex,
points, 4);
- points[0][0] = points[1][0] = x1 + 1 - w / 2 - d;
- points[0][1] = y1 + style->borderWidth.top / 2;
- points[1][1] = y2 - style->borderWidth.bottom / 2;
- points[2][0] = points[3][0] = x1 + 1 - w;
- points[2][1] = y2 - style->borderWidth.bottom;
- points[3][1] = y1 + style->borderWidth.top;
+ points[0].x = points[1].x = x1 + 1 - w / 2 - d;
+ points[0].y = y1 + style->borderWidth.top / 2;
+ points[1].y = y2 - style->borderWidth.bottom / 2;
+ points[2].x = points[3].x = x1 + 1 - w;
+ points[2].y = y2 - style->borderWidth.bottom;
+ points[3].y = y1 + style->borderWidth.top;
shading = (ridge) ? Color::SHADING_LIGHT: Color::SHADING_DARK;
view->drawPolygon (style->borderColor.right, shading, filled, convex,
points, 4);
@@ -785,20 +789,20 @@ static void drawBorderRight(View *view, Style *style,
view->drawLine(style->borderColor.right, shading, x1, y1, x2, y2);
break;
}
- points[0][0] = points[1][0] = x1 + 1;
- points[0][1] = y1 - 1;
- points[1][1] = y2 + 1;
- points[2][0] = points[3][0] = points[0][0] - w;
- points[2][1] = points[1][1] - w_b;
- points[3][1] = points[0][1] + w_t;
+ points[0].x = points[1].x = x1 + 1;
+ points[0].y = y1 - 1;
+ points[1].y = y2 + 1;
+ points[2].x = points[3].x = points[0].x - w;
+ points[2].y = points[1].y - w_b;
+ points[3].y = points[0].y + w_t;
view->drawPolygon (style->borderColor.right, shading, filled, convex,
points, 4);
- points[0][0] = points[1][0] = x1 + 1 - w - d;
- points[0][1] = y1 - 1 + style->borderWidth.top - w_t;
- points[1][1] = y2 + 1 - style->borderWidth.bottom + w_b;
- points[2][0] = points[3][0] = points[0][0] - w;
- points[2][1] = y2 + 1 - style->borderWidth.bottom;
- points[3][1] = y1 - 1 + style->borderWidth.top;
+ points[0].x = points[1].x = x1 + 1 - w - d;
+ points[0].y = y1 - 1 + style->borderWidth.top - w_t;
+ points[1].y = y2 + 1 - style->borderWidth.bottom + w_b;
+ points[2].x = points[3].x = points[0].x - w;
+ points[2].y = y2 + 1 - style->borderWidth.bottom;
+ points[3].y = y1 - 1 + style->borderWidth.top;
view->drawPolygon (style->borderColor.right, shading, filled, convex,
points, 4);
break;
diff --git a/dw/types.cc b/dw/types.cc
index 9dcedeea..074cb352 100644
--- a/dw/types.cc
+++ b/dw/types.cc
@@ -141,12 +141,11 @@ void Polygon::draw (core::View *view, core::style::Style *style, int x, int y)
if (points->size()) {
int i;
const bool filled = false, convex = false;
- int (*pointArray)[2] =
- (int (*)[2]) malloc(points->size() * sizeof(*pointArray));
+ Point *pointArray = (Point *)malloc(points->size()*sizeof(struct Point));
for (i = 0; i < points->size(); i++) {
- pointArray[i][0] = x + points->getRef(i)->x;
- pointArray[i][1] = y + points->getRef(i)->y;
+ pointArray[i].x = x + points->getRef(i)->x;
+ pointArray[i].y = y + points->getRef(i)->y;
}
view->drawPolygon(style->color, core::style::Color::SHADING_NORMAL,
filled, convex, pointArray, i);
diff --git a/dw/view.hh b/dw/view.hh
index 0c8011c7..f0afdcb5 100644
--- a/dw/view.hh
+++ b/dw/view.hh
@@ -173,7 +173,7 @@ public:
int angle1, int angle2) = 0;
virtual void drawPolygon (style::Color *color,
style::Color::Shading shading,
- bool filled, bool convex, int points[][2],
+ bool filled, bool convex, Point *points,
int npoints) = 0;
virtual void drawText (style::Font *font,
style::Color *color,