]> granicus.if.org Git - graphviz/commitdiff
need to split graph->absolute from absolute->device transformations
authorellson <devnull@localhost>
Wed, 2 Aug 2006 18:18:59 +0000 (18:18 +0000)
committerellson <devnull@localhost>
Wed, 2 Aug 2006 18:18:59 +0000 (18:18 +0000)
lib/common/emit.c
lib/gvc/gvcjob.h
lib/gvc/gvevent.c
lib/gvc/gvrender.c

index 623398a7c77ca4e7d276f7f22e0d9d705ad55e8e..04c26e14b9dfba6632267d55043f9e4678b3cee3 100644 (file)
@@ -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.);
 
index 9249617c9f8df6671ac4163aa44d29f22c9a4755..d9cb9c859effd467c3d015c2e49cc8870f912e9f 100644 (file)
@@ -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,
index 0e2e9294dd44a856e5eefd0c5a3d17110a74d67b..a397e10ae51d8fe631eede1f1aacec831accb820 100644 (file)
@@ -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;
index aeb924502e88aea278a8b10e5361cba21e64f4e7..38c3e828ff2cf56650a42c9012db2f6aa4232b87 100644 (file)
@@ -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++) {