From ad2b328d8a387a562b85a5e114ce261df536991b Mon Sep 17 00:00:00 2001 From: Thomas Jaeger Date: Sat, 25 Oct 2008 17:12:11 -0400 Subject: [PATCH] Higher quality strokes --- easystroke.svg | 81 +++++++++++++++++++++++++------------------------- main.cc | 1 + stroke.cc | 2 +- win.cc | 51 ++++++++++++++++++------------- 4 files changed, 72 insertions(+), 63 deletions(-) diff --git a/easystroke.svg b/easystroke.svg index cb3d5ac9..e3d02a73 100644 --- a/easystroke.svg +++ b/easystroke.svg @@ -1,46 +1,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main.cc b/main.cc index 720d0e8b..c4d43784 100644 --- a/main.cc +++ b/main.cc @@ -1390,6 +1390,7 @@ void Main::handle_event(XEvent &ev) { } } if (ev.type == grabber->event_presence && verbosity >= 1) { + // TODO printf("Info: Device Presence not implemented\n"); } } diff --git a/stroke.cc b/stroke.cc index 97db5fda..f6f578d1 100644 --- a/stroke.cc +++ b/stroke.cc @@ -382,7 +382,7 @@ Glib::RefPtr Stroke::drawEmpty(int size) { RStroke Stroke::trefoil() { PreStroke s; - const int n = 80; + const int n = 40; const double pi = 3.141592653589793238462643; for (int i = 0; i<=n; i++) { double phi = pi*(-4.0*i/n)-2.7; diff --git a/win.cc b/win.cc index 86b725cd..09b762a8 100644 --- a/win.cc +++ b/win.cc @@ -22,38 +22,47 @@ Glib::RefPtr widgets; -inline void curve(const Cairo::RefPtr ctx, - const Stroke::Point &p1, const Stroke::Point &p2, const Stroke::Point &p3, const Stroke::Point &p4) { - ctx->move_to(p2.x, p2.y); - ctx->line_to(p3.x, p3.y); - ctx->stroke(); -} - void Stroke::draw(Cairo::RefPtr surface, int x, int y, int w, int h, bool big, bool invert) const { const Cairo::RefPtr ctx = Cairo::Context::create (surface); x++; y++; w -= 2; h -= 2; ctx->save(); ctx->translate(x,y); ctx->scale(w,h); - ctx->set_line_width((big ? 7.0 : 4.0)/(w+h)); + ctx->set_line_width((big ? 8.0 : 4.0)/(w+h)); if (size()) { + ctx->set_line_cap(Cairo::LINE_CAP_ROUND); int n = points.size(); - const std::vector &p = points; - for (int j = 0;; j++) { + float lambda = sqrt(3)-2.0; + float sum = lambda / (1 - lambda); + std::vector y(n); + y[0].x = sum * points[0].x; + y[0].y = sum * points[0].y; + for (int j = 0; j < n-1; j++) { + y[j+1].x = lambda * (y[j].x + points[j].x); + y[j+1].y = lambda * (y[j].y + points[j].y); + } + std::vector z(n); + z[n-1].x = -1.0 * sum * points[n-1].x; + z[n-1].y = -1.0 * sum * points[n-1].y; + for (int j = n-1; j > 0; j--) { + z[j-1].x = lambda * (z[j].x - points[j].x); + z[j-1].y = lambda * (z[j].y - points[j].y); + } + for (int j = 0; j < n-1; j++) { // j -> j+1 if (invert) - ctx->set_source_rgba(1-p[j].time, p[j].time, 0, 1); + ctx->set_source_rgba(1-points[j].time, points[j].time, 0, 1); else - ctx->set_source_rgba(0, p[j].time, 1-p[j].time, 1); - if (j == 0) { - curve(ctx, p[j], p[j], p[j+1], p[j+2]); - continue; - } - if (j == n-2) { - curve(ctx, p[j-1], p[j], p[j+1], p[j+1]); - break; - } - curve(ctx, p[j-1], p[j], p[j+1], p[j+2]); + ctx->set_source_rgba(0, points[j].time, 1-points[j].time, 1); + ctx->move_to(points[j].x, points[j].y); + ctx->curve_to( + points[j].x + y[j].x + z[j].x, + points[j].y + y[j].y + z[j].y, + points[j+1].x - y[j+1].x - z[j+1].x, + points[j+1].y - y[j+1].y - z[j+1].y, + points[j+1].x, + points[j+1].y); + ctx->stroke(); } } else if (!button) { if (invert)