Hi!

Yesterday i've downloaded dia 0.30 and i think it's great and very
usable, even in the present state.
But while using it, i thought i would be a nice feature , if the
diagram-view  would "autoscroll" when
box-selecting. So i took a look at the sourcecode and included this
feature. I've done that by adding a  "method"
gboolean ddisplay_autoscroll(DDisplay* ddisp, const Point* pos, const
Point* delta)
to the DDisplay -object. pos is the position of the event (in
screenspace) and delta the delta (in worldspace) between the actual
point (in worldspace) and last ("dragged") point (in worldspace).
This routine must be called for every mouse motion, which will support
autoscrolling. The function returns TRUE, if autoscrolling has occured,
FALSE otherwise.
The autoscrolling  can be dis-\ enable via DDisplay->autoscroll_enabled.
The scrolling behaviour can be changed by changing
DDisplay->autoscroll_border
DDisplay->autoscroll_amount

The only point where i've already added the call to this function is in
modify_tool.c

I've attached my patches to the source, you can patch it by entering the
directory where the dia-0.30 directory is rooted and then invoking
patch:
patch < autoscroll.patch

Any comments?

Matthias
--- /usr/local/src/dia-0.30/app/modify_tool.c   Sat Jan 16 15:27:17 1999
+++ src/dia-0.30/app/modify_tool.c      Wed Jan 27 00:35:18 1999
@@ -230,6 +230,9 @@
 }
 
 
+#define SCROLL_BORDER 8
+#define SCROLL_AMOUNT 16
+
 static void
 modify_motion(ModifyTool *tool, GdkEventMotion *event,
              DDisplay *ddisp)
@@ -237,10 +240,45 @@
   Point to;
   Point now, delta;
   ConnectionPoint *connectionpoint;
+  gboolean scrolled=FALSE;
+  guint16 width, height;
 
   if (tool->state==STATE_NONE)
     return; /* Fast path... */
   
+  width=GTK_WIDGET(ddisp->canvas)->allocation.width;
+  height=GTK_WIDGET(ddisp->canvas)->allocation.height;
+
+  ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y);
+  
+  if((to.x-tool->last_to.x>=0)&&(event->x>width-SCROLL_BORDER))
+  {
+    delta.x=SCROLL_AMOUNT;
+  }
+  else if((to.x-tool->last_to.x<=0)&&(event->x<SCROLL_BORDER))
+  {
+    delta.x=-SCROLL_AMOUNT;
+  }
+  if((to.y-tool->last_to.y>=0)&&(event->y>height-SCROLL_BORDER))
+  {
+    delta.y=SCROLL_AMOUNT;
+  }
+  else if((to.y-tool->last_to.y<=0)&&(event->y<SCROLL_BORDER))
+  {
+    delta.y=-SCROLL_AMOUNT;
+  }
+
+  if((delta.x!=0)||(delta.y!=0))
+  {
+    delta.x=ddisplay_untransform_length(ddisp, delta.x);
+    delta.y=ddisplay_untransform_length(ddisp, delta.y);
+    
+    ddisplay_scroll(ddisp, &delta);
+    ddisplay_flush(ddisp);
+    
+    scrolled=TRUE;
+  }
+
   ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y);
 
   switch (tool->state) {
@@ -292,13 +330,16 @@
     diagram_flush(ddisp->diagram);
     break;
   case STATE_BOX_SELECT:
-    
-    gdk_draw_rectangle (ddisp->renderer->pixmap, tool->gc, FALSE,
-                       tool->x1, tool->y1,
-                       tool->x2 - tool->x1, tool->y2 - tool->y1);
-    ddisplay_add_display_area(ddisp,
-                             tool->x1-1, tool->y1-1,
-                             tool->x2+1, tool->y2+1);
+
+    if(!scrolled)
+    {
+      gdk_draw_rectangle (ddisp->renderer->pixmap, tool->gc, FALSE,
+                         tool->x1, tool->y1,
+                         tool->x2 - tool->x1, tool->y2 - tool->y1);
+      ddisplay_add_display_area(ddisp,
+                               tool->x1-1, tool->y1-1,
+                               tool->x2+1, tool->y2+1);
+    }
 
     tool->end_box = to;
 

Reply via email to