From: ellson Date: Wed, 2 Aug 2006 18:18:59 +0000 (+0000) Subject: need to split graph->absolute from absolute->device transformations X-Git-Tag: LAST_LIBGRAPH~32^2~6010 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7928f697c549813a9eb66d79b61d9dbc49d5ffd0;p=graphviz need to split graph->absolute from absolute->device transformations --- diff --git a/lib/common/emit.c b/lib/common/emit.c index 623398a7c..04c26e14b 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -794,9 +794,6 @@ static void setup_page(GVJ_t * job, graph_t * g) job->translation.y = -job->pageBox.LL.y + job->pageBoundingBox.LL.y / job->scale.y; } } - - job->compscale = job->scale; - job->compscale.y *= (job->flags & GVRENDER_Y_GOES_DOWN) ? -1. : 1.; } #if 0 @@ -1921,6 +1918,9 @@ static void setup_view(GVJ_t * job, graph_t * g) job->scale.x = job->zoom * job->dpi.x / POINTS_PER_INCH; job->scale.y = job->zoom * job->dpi.y / POINTS_PER_INCH; + job->devscale.x = job->dpi.x / POINTS_PER_INCH; + job->devscale.y = job->dpi.y / POINTS_PER_INCH * ((job->flags & GVRENDER_Y_GOES_DOWN) ? -1. : 1.); + sx = job->width / (job->scale.x * 2.); sy = job->height / (job->scale.y * 2.); diff --git a/lib/gvc/gvcjob.h b/lib/gvc/gvcjob.h index 9249617c9..d9cb9c859 100644 --- a/lib/gvc/gvcjob.h +++ b/lib/gvc/gvcjob.h @@ -270,9 +270,9 @@ extern "C" { box pageBoundingBox;/* rotated boundingBox - device units */ box boundingBox; /* cumulative boundingBox over all pages - device units */ - pointf scale; /* composite device scale (zoom and dpi) */ + pointf scale; /* composite device to graph units (zoom and dpi) */ pointf translation; /* composite translation */ - pointf compscale; /* composite device scale incl: zoom, dpi, y_goes_down */ + pointf devscale; /* composite device to points: dpi, y_goes_down */ bool fit_mode, needs_refresh, diff --git a/lib/gvc/gvevent.c b/lib/gvc/gvevent.c index 0e2e9294d..a397e10ae 100644 --- a/lib/gvc/gvevent.c +++ b/lib/gvc/gvevent.c @@ -292,10 +292,15 @@ static void gvevent_enter_obj(GVJ_t * job) static void gvevent_find_current_obj(GVJ_t * job, pointf pointer) { void *obj; - pointf p, translation = job->translation, scale = job->compscale; boxf b; double closeenough; + pointf p, translation, scale; + translation = job->translation; + scale.x = job->zoom * job->devscale.x; + scale.y = job->zoom * job->devscale.y; + + /* transform position in device units to poition in graph units */ if (job->rotation) { p.x = pointer.y / scale.y - translation.x; p.y = -pointer.x / scale.x - translation.y; @@ -306,10 +311,10 @@ static void gvevent_find_current_obj(GVJ_t * job, pointf pointer) } #if 0 -fprintf(stderr,"pointer = %g,%g compscale = %g,%g comptrans = %g,%g, graphpoint = %g,%g\n", +fprintf(stderr,"pointer = %g,%g scale = %g,%g translation = %g,%g, graphpoint = %g,%g\n", pointer.x, pointer.y, scale.x, scale.y, - trans.x, trans.y, + translation.x, translation.y, p.x, p.y); #endif @@ -410,9 +415,9 @@ static void gvevent_button_press(GVJ_t * job, int button, pointf pointer) /* scrollwheel zoom in at current mouse x,y */ job->fit_mode = 0; job->focus.x += (pointer.x - job->width / 2.) - * (ZOOMFACTOR - 1.) / job->zoom; - job->focus.y += -(pointer.y - job->height / 2.) - * (ZOOMFACTOR - 1.) / job->zoom; + * (ZOOMFACTOR - 1.) / (job->zoom * job->devscale.x); + job->focus.y += (pointer.y - job->height / 2.) + * (ZOOMFACTOR - 1.) / (job->zoom * job->devscale.y); job->zoom *= ZOOMFACTOR; job->needs_refresh = 1; break; @@ -420,9 +425,9 @@ static void gvevent_button_press(GVJ_t * job, int button, pointf pointer) job->fit_mode = 0; job->zoom /= ZOOMFACTOR; job->focus.x -= (pointer.x - job->width / 2.) - * (ZOOMFACTOR - 1.) / job->zoom; + * (ZOOMFACTOR - 1.) / (job->zoom * job->devscale.x); job->focus.y -= -(pointer.y - job->height / 2.) - * (ZOOMFACTOR - 1.) / job->zoom; + * (ZOOMFACTOR - 1.) / (job->zoom * job->devscale.y); job->needs_refresh = 1; break; } @@ -437,8 +442,9 @@ static void gvevent_button_release(GVJ_t *job, int button, pointf pointer) static void gvevent_motion(GVJ_t * job, pointf pointer) { - double dx = pointer.x - job->oldpointer.x; - double dy = pointer.y - job->oldpointer.y; + /* dx,dy change in position, in device independent points */ + double dx = (pointer.x - job->oldpointer.x) / job->devscale.x; + double dy = (pointer.y - job->oldpointer.y) / job->devscale.y; if (abs(dx) < EPSILON && abs(dy) < EPSILON) /* ignore motion events with no motion */ return; @@ -451,8 +457,8 @@ static void gvevent_motion(GVJ_t * job, pointf pointer) /* FIXME - to be implemented */ break; case 2: /* drag with button 2 - pan graph */ - job->focus.x -= dx / job->zoom; - job->focus.y -= -dy / job->zoom; + job->focus.x -= dx / job->zoom; + job->focus.y -= dy / job->zoom; job->needs_refresh = 1; break; case 3: /* drag with button 3 - drag inserted node or uncompleted edge */ @@ -518,6 +524,7 @@ static int toggle_fit_cb(GVJ_t * job) { job->fit_mode = !job->fit_mode; if (job->fit_mode) { + /* FIXME - this code looks wrong */ int dflt_width, dflt_height; dflt_width = job->width; dflt_height = job->height; diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index aeb924502..38c3e828f 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -167,7 +167,11 @@ void gvrender_end_job(GVJ_t * job) pointf gvrender_ptf(GVJ_t *job, pointf p) { - pointf rv, translation = job->translation, scale = job->compscale; + pointf rv, translation, scale; + + translation = job->translation; + scale.x = job->zoom * job->devscale.x; + scale.y = job->zoom * job->devscale.y; if (job->rotation) { rv.x = -(p.y + translation.y) * scale.x; @@ -185,8 +189,12 @@ pointf gvrender_ptf(GVJ_t *job, pointf p) pointf* gvrender_ptf_A(GVJ_t *job, pointf *af, pointf *AF, int n) { int i; - pointf translation = job->translation, scale = job->compscale; double t; + pointf translation, scale; + + translation = job->translation; + scale.x = job->zoom * job->devscale.x; + scale.y = job->zoom * job->devscale.y; if (job->rotation) { for (i = 0; i < n; i++) {