]> granicus.if.org Git - graphviz/commitdiff
panning is added to 3d views
authorarif <devnull@localhost>
Thu, 10 Apr 2008 20:26:27 +0000 (20:26 +0000)
committerarif <devnull@localhost>
Thu, 10 Apr 2008 20:26:27 +0000 (20:26 +0000)
glmotion.c and glmotion.h is added to seperate motion functions from gltemplate

cmd/smyrna/glexpose.c
cmd/smyrna/glmotion.c [new file with mode: 0644]
cmd/smyrna/glmotion.h [new file with mode: 0644]
cmd/smyrna/gltemplate.c
cmd/smyrna/smyrnadefs.h
lib/glcomp/glutils.c

index 4333b956533e83a1568eb9c096f2c6f871e1f2cb..8d87eebd683ea89a33f300eb4fd5147d18e36165 100644 (file)
@@ -43,12 +43,11 @@ int glupdatecamera(ViewInfo * view)
                view->cameras[view->active_camera]->camera_vectorx,
                view->cameras[view->active_camera]->camera_vectory,
                view->cameras[view->active_camera]->camera_vectorz);*/
-               gluLookAt(view->panx, view->pany, view->zoom * -1, view->panx,
-                       view->pany, 0.0, 0.0, 1.0, 0.0);
+               gluLookAt(view->cameras[view->active_camera]->targetx, view->cameras[view->active_camera]->targety, view->cameras[view->active_camera]->r, view->cameras[view->active_camera]->targetx,
+               view->cameras[view->active_camera]->targety, 0.0, 0.0, 1.0, 0.0);
+//                     glTranslatef(view->cameras[view->active_camera]->targetx/pow(view->cameras[view->active_camera]->r,0.125),view->cameras[view->active_camera]->targety/pow(view->cameras[view->active_camera]->r,0.125),0);
                        glRotatef(view->cameras[view->active_camera]->angley,1,0,0);
                        glRotatef(view->cameras[view->active_camera]->anglex,0,1,0);
-
-
        }
        GetOGLPosRef(1, view->h - 5, &(view->clipX1), &(view->clipY1),
                 &(view->clipZ1));
@@ -59,7 +58,11 @@ int glupdatecamera(ViewInfo * view)
                glScalef(1/view->zoom*-1,1/view->zoom*-1,1/view->zoom*-1);
        }
        else
+       {
                glScalef(1/view->cameras[view->active_camera]->r,1/view->cameras[view->active_camera]->r,1/view->cameras[view->active_camera]->r);
+
+       }
+
        return 1;
 }
 
diff --git a/cmd/smyrna/glmotion.c b/cmd/smyrna/glmotion.c
new file mode 100644 (file)
index 0000000..d934f3b
--- /dev/null
@@ -0,0 +1,111 @@
+#include "glmotion.h"
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtkgl.h>
+#include <gdk/gdkcursor.h>
+#include "draw.h"
+#include "topview.h"
+#include "glutils.h"
+
+gboolean redraw = FALSE;
+
+int glmotion_main(ViewInfo * v,GdkEventMotion * event,GtkWidget * widget)
+{
+       
+       redraw = FALSE;
+       /*panning */
+    if ((event->state & GDK_BUTTON1_MASK)&& (v->mouse.mouse_mode == MM_PAN))
+               glmotion_pan(v);
+
+       return 1;
+       /*rotating, only in 3d v */
+    if ((v->active_camera >=0)&&(v->mouse.button==rightmousebutton))
+               glmotion_rotate(v);
+
+       /*zooming */
+    if ((event->state & GDK_BUTTON1_MASK)&& (v->mouse.mouse_mode == MM_ZOOM))
+               glmotion_zoom(v);
+
+
+       /*selection rect */
+    if ((event->state & GDK_BUTTON1_MASK)
+       && ((v->mouse.mouse_mode == MM_RECTANGULAR_SELECT)
+           || (v->mouse.mouse_mode == 5)))
+       {
+                       GetFixedOGLPos((int) v->mouse.mouse_X, (int) v->mouse.mouse_Y, v->GLDepth, &(v->GLx2),
+                      &(v->GLy2), &(v->GLz2));
+               redraw = TRUE;
+    }
+    if ((event->state & GDK_BUTTON1_MASK)
+       && (v->mouse.mouse_mode == MM_MOVE)) {
+       GetFixedOGLPos((int) v->mouse.mouse_X, (int) v->mouse.mouse_Y, v->GLDepth, &(v->GLx2),
+                      &(v->GLy2), &(v->GLz2));
+       redraw = TRUE;
+    }
+/*    if ((event->state & GDK_BUTTON1_MASK)
+       && ((v->mouse.mouse_mode == MM_MAGNIFIER)
+           || (v->mouse.mouse_mode == MM_FISHEYE_MAGNIFIER))) {
+       v->mouse.mouse_X = (int) x;
+       v->mouse.mouse_Y = (int) y;
+       redraw = TRUE;
+    }*/
+
+    if (redraw)
+       gdk_window_invalidate_rect(widget->window, &widget->allocation,
+                                  FALSE);
+
+       return 1;
+}
+int glmotion_zoom(ViewInfo * v)
+{
+       char buf[256];
+
+       float real_zoom,xx;
+       if(v->active_camera==-1)
+               real_zoom=v->zoom + v->mouse.dx / 10 * (v->zoom * -1 / 20);
+       else
+               real_zoom=(v->cameras[v->active_camera]->r + v->mouse.dx / 10 * (v->cameras[v->active_camera]->r  / 20))*-1;
+
+       if (real_zoom > MAX_ZOOM)
+               real_zoom = (float) MAX_ZOOM;
+       if (real_zoom < MIN_ZOOM)
+               real_zoom = (float) MIN_ZOOM;
+       if(v->active_camera==-1)
+               v->zoom = real_zoom;
+       else
+               v->cameras[v->active_camera]->r=real_zoom*-1;
+       /*set label to new zoom value */
+       xx = ((float) 100.0 - (float) 1.0) * (v->zoom -
+                    (float) MIN_ZOOM) / ((float) MAX_ZOOM - (float) MIN_ZOOM) + (float) 1.0;
+       sprintf(buf, "%i", (int) xx);
+       glCompLabelSetText((glCompLabel *) v->Topview->customptr, buf);
+       return 1;
+}
+int glmotion_pan(ViewInfo * v)
+{
+               float gldx,gldy;
+               if(v->active_camera ==-1)
+               {
+                       gldx=GetOGLDistance(v->mouse.dx)/v->zoom*-1;
+                       gldy=GetOGLDistance(v->mouse.dy)/v->zoom*-1;
+                       v->panx=v->panx-gldx;
+                       v->pany=v->pany+gldy;
+               }
+               else
+               {
+                       gldx=GetOGLDistance(v->mouse.dx)/v->cameras[v->active_camera]->r;
+                       gldy=GetOGLDistance(v->mouse.dy)/v->cameras[v->active_camera]->r;
+                       v->cameras[v->active_camera]->x-=gldx;
+                       v->cameras[v->active_camera]->y-=gldy;
+                       v->cameras[v->active_camera]->targetx-=gldx;
+                       v->cameras[v->active_camera]->targety+=gldy;
+               }
+
+               redraw = TRUE;
+}
+int glmotion_rotate(ViewInfo * v)
+{
+       v->cameras[v->active_camera]->angley-=v->mouse.dy/5;
+       v->cameras[v->active_camera]->anglex-=v->mouse.dx/5;
+       return 1;
+}
diff --git a/cmd/smyrna/glmotion.h b/cmd/smyrna/glmotion.h
new file mode 100644 (file)
index 0000000..2a91ad0
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef GLMOTION_H
+#define GLMOTION_H
+#include "viewport.h"
+int glmotion_main(ViewInfo * v,GdkEventMotion * event,GtkWidget * widget);
+int glmotion_zoom(ViewInfo * v);
+int glmotion_pan(ViewInfo * v);
+int glmotion_rotate(ViewInfo * v);
+#endif
\ No newline at end of file
index 05faad209762dc63d84a70ec98f54de67b9162db..63c8c143403c0b55b67080fc9c22d124b591efab 100755 (executable)
@@ -22,6 +22,7 @@
 #include "gltemplate.h"
 #include "glutils.h"
 #include "glexpose.h"
+#include "glmotion.h"
 #include "glmenu.h"
 #include "selection.h"
 #include "glcompset.h"
@@ -251,14 +252,16 @@ static gboolean button_press_event(GtkWidget * widget,
     begin_x = (float) event->x;
     begin_y = (float) event->y;
 
+    if (event->button == 3)    //right click
+               view->mouse.button = rightmousebutton;
 
 
     if (event->button == 1)    //left click
     {
                view->prevpanx = view->panx;
                view->prevpany = view->pany;
-
                view->mouse.mouse_down = 1;
+               view->mouse.button = leftmousebutton;
        if (GetOGLPosRef
            ((int) begin_x, (int) begin_y, &(view->GLx), &(view->GLy),
             &(view->GLz))) {
@@ -355,24 +358,23 @@ static gboolean motion_notify_event(GtkWidget * widget,
        gboolean redraw = FALSE;
     dx = x - begin_x;
     dy = y - begin_y;
-    /*panning */
+
+       view->mouse.dx=dx;
+       view->mouse.dy=dy;
+
+       /*panning */
     if ((event->state & GDK_BUTTON1_MASK)
        && (view->mouse.mouse_mode == MM_PAN))
        {
-                       gldx=GetOGLDistance(dx)/view->zoom*-1;
-                       gldy=GetOGLDistance(dy)/view->zoom*-1;
-               if(view->active_camera ==-1)
-               {
-                       view->panx=view->panx-gldx;
-                       view->pany=view->pany+gldy;
-               }
-               else
-               {
+               if(glmotion_main(view,event,widget))
+                               redraw = TRUE;
+       }
+       /*rotating, only in 3d view */
+    if ((view->active_camera >=0)&&(view->mouse.button==rightmousebutton) )
+       {
                        view->cameras[view->active_camera]->angley-=dy/5;
                        view->cameras[view->active_camera]->anglex-=dx/5;
-//                     set_camera_x_y(view->cameras[view->active_camera]);
-               }
-               redraw = TRUE;
+                               redraw = TRUE;
        }
     /*zooming */
     if ((event->state & GDK_BUTTON1_MASK)
@@ -547,8 +549,11 @@ void create_window(GdkGLConfig * glconfig, GtkWidget * vbox)
                                 glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
 
     gtk_widget_add_events(view->drawing_area,
-                         GDK_BUTTON1_MOTION_MASK |
+//  GDK_BUTTON_MOTION_MASK     = 1 << 4,
+                       GDK_BUTTON_MOTION_MASK |
+                       GDK_BUTTON1_MOTION_MASK |
                          GDK_BUTTON2_MOTION_MASK |
+                               GDK_BUTTON3_MOTION_MASK |
                          GDK_BUTTON_PRESS_MASK |
                          GDK_BUTTON_RELEASE_MASK |
                          GDK_VISIBILITY_NOTIFY_MASK);
@@ -574,12 +579,12 @@ void create_window(GdkGLConfig * glconfig, GtkWidget * vbox)
 
     /* Popup menu. */
 
-    menu = create_popup_menu(view->drawing_area);
/*   menu = create_popup_menu(view->drawing_area);
 
     /* Signal handler */
-    g_signal_connect_swapped(G_OBJECT(view->drawing_area),
+  /*  g_signal_connect_swapped(G_OBJECT(view->drawing_area),
                             "button_press_event",
                             G_CALLBACK(button_press_event_popup_menu),
-                            menu);
+                            menu);*/
 
 }
index 84db1047548ec136120c4c1e873d6c00246ce103..8b9036ffc73e65da14319bcf24e291eb6bb04621 100644 (file)
@@ -76,6 +76,8 @@
 #define NODE_CIRCLE_LIMIT      -7.3
 
 typedef enum { nodshapedot,nodeshapecircle} node_shape;
+typedef enum { leftmousebutton,rightmousebutton,thirdmousebutton} clicked_mouse_button;
+
 
 typedef struct {
     float R;
@@ -180,8 +182,13 @@ enum {
 typedef struct _mouse_attr {
     int mouse_down;
     int mouse_mode;
-    int mouse_X;
-    int mouse_Y;
+    float mouse_X;
+    float mouse_Y;
+       float begin_x;
+       float begin_y;
+       float dx;
+       float dy;
+       clicked_mouse_button button;
 } mouse_attr;
 
 
index 049c51d96700c6ba552112ce172f4b1af98576d4..cea19074bb1fedc688657806ecf39fabf73c1d72 100644 (file)
@@ -108,7 +108,9 @@ float GetOGLDistance(int l)
     GLdouble projection[16];
     GLfloat winX, winY;
     float kts = 1;
-    //glTranslatef (0.0,0.0,0.0);
+
+
+
 
        glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
     glGetDoublev(GL_PROJECTION_MATRIX, projection);