aboutsummaryrefslogtreecommitdiff
path: root/dw/fltkviewbase.cc
diff options
context:
space:
mode:
authorJorge Arellano Cid <jcid@dillo.org>2010-11-13 13:15:55 -0300
committerJorge Arellano Cid <jcid@dillo.org>2010-11-13 13:15:55 -0300
commit415a9c17ea71a0b4b53bbda1c39e495cf7ae2d1b (patch)
tree9954b9bdb37333591229d1224469269059936a8b /dw/fltkviewbase.cc
parenta12f6e9121d0049ed5f68b52c5d54ac35802a605 (diff)
Full CSS border-style implementation
The drawBorder{Top,Bottom,Left,Right} functions are similar. They use a trapezium as draw polygon, or drawTypedLine() for dots and dashes. Although the concept is simple, achieving pixel accuracy is laborious [1]. [1] http://www.dillo.org/css_compat/tests/border-style.html
Diffstat (limited to 'dw/fltkviewbase.cc')
-rw-r--r--dw/fltkviewbase.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc
index 3fb43cb1..373e5454 100644
--- a/dw/fltkviewbase.cc
+++ b/dw/fltkviewbase.cc
@@ -369,6 +369,39 @@ void FltkViewBase::drawLine (core::style::Color *color,
translateCanvasXToViewX (x2), translateCanvasYToViewY (y2));
}
+void FltkViewBase::drawTypedLine (core::style::Color *color,
+ core::style::Color::Shading shading,
+ core::style::LineType type, int width,
+ int x1, int y1, int x2, int y2)
+{
+ char dashes[3], w, ng, d, gap, len;
+ const int f = 2;
+
+ w = (width == 1) ? 0 : width;
+ if (type == core::style::LINE_DOTTED) {
+ /* customized drawing for dotted lines */
+ len = (x2 == x1) ? y2 - y1 + 1 : (y2 == y1) ? x2 - x1 + 1 : 0;
+ ng = len / f*width;
+ d = len % f*width;
+ gap = ng ? d/ng + (w > 3 ? 2 : 0) : 0;
+ dashes[0] = 1; dashes[1] = f*width-gap; dashes[2] = 0;
+ line_style(::fltk::DASH + ::fltk::CAP_ROUND, w, dashes);
+
+ /* These formulas also work, but ain't pretty ;)
+ * line_style(::fltk::DOT + ::fltk::CAP_ROUND, w);
+ * dashes[0] = 1; dashes[1] = 3*width-2; dashes[2] = 0;
+ */
+ } else if (type == core::style::LINE_DASHED) {
+ line_style(::fltk::DASH + ::fltk::CAP_ROUND, w);
+ }
+
+ setcolor(((FltkColor*)color)->colors[shading]);
+ drawLine (color, shading, x1, y1, x2, y2);
+
+ if (type != core::style::LINE_NORMAL)
+ line_style(::fltk::SOLID);
+}
+
void FltkViewBase::drawRectangle (core::style::Color *color,
core::style::Color::Shading shading,
bool filled,