diff options
Diffstat (limited to 'dw/style.cc')
-rw-r--r-- | dw/style.cc | 339 |
1 files changed, 184 insertions, 155 deletions
diff --git a/dw/style.cc b/dw/style.cc index ae0f4526..4276862a 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -431,7 +431,9 @@ 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; @@ -460,35 +462,38 @@ 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; - view->drawPolygon (style->borderColor.top, shading, true, points, 4); + 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); } break; case BORDER_RIDGE: 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, true, 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; + view->drawPolygon (style->borderColor.top, shading, filled, convex, + points, 4); + 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, true, points, 4); + view->drawPolygon (style->borderColor.top, shading, filled, convex, + points, 4); break; case BORDER_DOUBLE: w = (int) rint(style->borderWidth.top / 3.0); @@ -499,20 +504,22 @@ 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; - view->drawPolygon (style->borderColor.top, shading, true, 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; - view->drawPolygon (style->borderColor.top, shading, true, points, 4); + 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].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; } } @@ -521,7 +528,9 @@ 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; @@ -550,13 +559,14 @@ 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; - view->drawPolygon (style->borderColor.bottom, shading, true, points, 4); + 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); } break; case BORDER_RIDGE: @@ -564,23 +574,25 @@ 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, true, points, 4); + 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, true, points, 4); + view->drawPolygon (style->borderColor.bottom, shading, filled, convex, + points, 4); break; case BORDER_DOUBLE: w = (int) rint(style->borderWidth.bottom / 3.0); @@ -591,20 +603,22 @@ 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; - view->drawPolygon (style->borderColor.bottom, shading, true, 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; - view->drawPolygon (style->borderColor.bottom, shading, true, points, 4); + 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].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; } } @@ -613,7 +627,9 @@ 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; @@ -641,13 +657,14 @@ 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; - view->drawPolygon (style->borderColor.left, shading, true, points, 4); + 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); } break; case BORDER_RIDGE: @@ -655,22 +672,24 @@ 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, true, 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; + view->drawPolygon (style->borderColor.left, shading, filled, convex, + points, 4); + 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, true, points, 4); + view->drawPolygon (style->borderColor.left, shading, filled, convex, + points, 4); break; case BORDER_DOUBLE: w = (int) rint(style->borderWidth.left / 3.0); @@ -681,20 +700,22 @@ 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; - view->drawPolygon (style->borderColor.left, shading, true, 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; - view->drawPolygon (style->borderColor.left, shading, true, points, 4); + 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].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; } } @@ -703,7 +724,9 @@ 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; @@ -731,13 +754,14 @@ 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; - view->drawPolygon (style->borderColor.right, shading, true,points,4); + 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); } break; case BORDER_RIDGE: @@ -745,22 +769,24 @@ 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, true, 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; + view->drawPolygon (style->borderColor.right, shading, filled, convex, + points, 4); + 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, true, points, 4); + view->drawPolygon (style->borderColor.right, shading, filled, convex, + points, 4); break; case BORDER_DOUBLE: w = (int) rint(style->borderWidth.right / 3.0); @@ -771,20 +797,22 @@ 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; - view->drawPolygon (style->borderColor.right, shading, true, 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; - view->drawPolygon (style->borderColor.right, shading, true, points, 4); + 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].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; } } @@ -799,8 +827,7 @@ void drawBorder (View *view, Rectangle *area, Style *style, bool inverse) { /** \todo a lot! */ - Color::Shading dark, light, normal; - int xb1, yb1, xb2, yb2, xp1, yp1, xp2, yp2; + int xb1, yb1, xb2, yb2; // top left and bottom right point of outer border boundary xb1 = x + style->margin.left; @@ -808,15 +835,17 @@ void drawBorder (View *view, Rectangle *area, xb2 = x + (width > 0 ? width - 1 : 0) - style->margin.right; yb2 = y + (height > 0 ? height - 1 : 0) - style->margin.bottom; - // top left and bottom right point of inner border boundary - xp1 = xb1 + style->borderWidth.left; - yp1 = yb1 + style->borderWidth.top; - xp2 = xb2 - style->borderWidth.right; - yp2 = yb2 - style->borderWidth.bottom; - - light = inverse ? Color::SHADING_DARK : Color::SHADING_LIGHT; - dark = inverse ? Color::SHADING_LIGHT : Color::SHADING_DARK; - normal = inverse ? Color::SHADING_INVERSE : Color::SHADING_NORMAL; + /* + // top left and bottom right point of inner border boundary + xp1 = xb1 + style->borderWidth.left; + yp1 = yb1 + style->borderWidth.top; + xp2 = xb2 - style->borderWidth.right; + yp2 = yb2 - style->borderWidth.bottom; + + light = inverse ? Color::SHADING_DARK : Color::SHADING_LIGHT; + dark = inverse ? Color::SHADING_LIGHT : Color::SHADING_DARK; + normal = inverse ? Color::SHADING_INVERSE : Color::SHADING_NORMAL; + */ drawBorderRight(view, style, xb2, yb1, xb2, yb2); drawBorderLeft(view, style, xb1, yb1, xb1, yb2); |