]> granicus.if.org Git - graphviz/commitdiff
SMYRNA:customized mouse actions feauture added
authorarif <devnull@localhost>
Mon, 9 Nov 2009 20:52:51 +0000 (20:52 +0000)
committerarif <devnull@localhost>
Mon, 9 Nov 2009 20:52:51 +0000 (20:52 +0000)
cmd/smyrna/gltemplate.c
cmd/smyrna/gui/appmouse.c
cmd/smyrna/hotkeymap.c
cmd/smyrna/hotkeymap.h
cmd/smyrna/smyrnadefs.h
cmd/smyrna/viewport.c
share/gui/mouse_actions.txt [new file with mode: 0644]

index 005578b5ce83bb5e8d9b0e3bbc9015cb16f856e7..adc2cf09e3b887a8898bb415c87ed94230e54263 100755 (executable)
@@ -318,6 +318,7 @@ static gboolean key_release_event(GtkWidget * widget, GdkEventKey * event, gpoin
 {
  //   printf ("key is released:%d\n",event->keyval);
     view->keymap.down=0;
+    view->keymap.keyVal=0;
     originate_distorded_coordinates(view->Topview);
 
 }
index 1b08f042012802c50580c36759da457963c93de8..eb63b0d87e8831972e5876cc1c1021ec8cfa1b4b 100644 (file)
 
     static float prevX=0;
     static float prevY=0;
+static int apply_actions(ViewInfo* v,int x,int y)
+{
+    int a;
+    a=get_mode(v);
+    if (a==MM_ROTATE)
+
+    {
+       view->arcball->MousePt.s.X = (GLfloat) x;
+       view->arcball->MousePt.s.Y = (GLfloat) y;
+       if (!view->arcball->isDragging) {
+           arcmouseClick(view);
+        view->arcball->isDragging = 1;
+       } else 
+                   arcmouseDrag(view);
+       return;
+    }
+    if (a==MM_PAN)
+    {
+       glmotion_pan(v);
+    }
+    if (a==MM_MOVE)
+        move_TVnodes();
 
+    if(a==MM_RECTANGULAR_SELECT)
+    {
+       if (!view->mouse.down)
+           rectangle_select(v);
+    }
+
+    if (a==MM_SINGLE_SELECT) 
+        pick_node_from_coords(view->mouse.GLfinalPos.x,view->mouse.GLfinalPos.y,view->mouse.GLfinalPos.z);
+
+    if (a==MM_FISHEYE_PICK) 
+    {
+
+       if (view->activeGraph >= 0) 
+       {
+           if (view->Topview->is_top_fisheye) 
+               changetopfishfocus(view->Topview,&view->mouse.GLpos.x,&view->mouse.GLpos.y,  0, 1);
+           else    /*single right click*/
+               /*      pick_node_from_coords(view->mouse.GLpos.x, view->mouse.GLpos.y,view->mouse.GLpos.z);*/
+
+           {;}
+
+
+       }
+    }
+
+
+
+
+}
 
 static int singleclick(ViewInfo* v)
 {
@@ -39,15 +90,11 @@ static void appmouse_left_click(ViewInfo* v,int x,int y)
 }
 static void appmouse_right_click(ViewInfo* v,int x,int y)
 {
-    if (!view->Topview->is_top_fisheye) 
-        pick_node_from_coords(view->mouse.GLfinalPos.x,view->mouse.GLfinalPos.y,view->mouse.GLfinalPos.z);
 }
-
-
 static void appmouse_down(ViewInfo* v,int x,int y)
 {
-        view->mouse.dragX = 0;
-       view->mouse.dragY = 0;
+    view->mouse.dragX = 0;
+    view->mouse.dragY = 0;
     v->mouse.down=1;
     v->mouse.initPos.x=x;
     v->mouse.initPos.y=y;
@@ -70,8 +117,6 @@ static void appmouse_up(ViewInfo* v,int x,int y)
     v->mouse.down=0;
     v->mouse.finalPos.x=x;
     v->mouse.finalPos.y=y;
-    view->mouse.dragX = 0;
-    view->mouse.dragY = 0;
     a=get_mode(v);
     GetFixedOGLPos((float) x,y,v->GLDepth, &v->mouse.GLfinalPos.x,&v->mouse.GLfinalPos.y,&v->mouse.GLfinalPos.z);
     if(singleclick(v))
@@ -83,45 +128,22 @@ static void appmouse_up(ViewInfo* v,int x,int y)
     }
     if ((a== MM_FISHEYE_MAGNIFIER) || (a == MM_MAGNIFIER))     //fisheye mag mouse release, stop distortion
         originate_distorded_coordinates(v->Topview);
-
-
+    apply_actions(v,x,y);
+    view->mouse.dragX = 0;
+    view->mouse.dragY = 0;
 
 }
 static void appmouse_drag(ViewInfo* v,int x,int y)
 {
     static float x2,y2;
-    int a=get_mode(v);
     v->mouse.pos.x=x;
     v->mouse.pos.y=y;
     GetFixedOGLPos((float) x,y,v->GLDepth, &v->mouse.GLpos.x,&v->mouse.GLpos.y,&v->mouse.GLpos.z);
     x2=v->mouse.GLpos.x;
     y2=v->mouse.GLpos.y;
-
     prevX=x2;
     prevY=y2;
-    if (a==MM_ROTATE)
-
-    {
-       view->arcball->MousePt.s.X = (GLfloat) x;
-       view->arcball->MousePt.s.Y = (GLfloat) y;
-       if (!view->arcball->isDragging) {
-           arcmouseClick(view);
-        view->arcball->isDragging = 1;
-       } else 
-                   arcmouseDrag(view);
-       return;
-    }
-    if (a==MM_PAN)
-       glmotion_pan(v);
-    if (a==MM_MOVE)
-        move_TVnodes();
-
-    if(a==MM_RECTANGULAR_SELECT)
-    {
-
-    }
-
-
+    apply_actions(v,x,y);
 }
 
 void appmouse_left_click_down(ViewInfo* v,int x,int y)
@@ -157,24 +179,7 @@ void appmouse_right_click_down(ViewInfo* v,int x,int y)
 void appmouse_right_click_up(ViewInfo* v,int x,int y)
 {
     appmouse_up(v,x,y);
-    if(singleclick(v))
-    {
-       if (view->activeGraph >= 0) 
-       {
-           if (view->Topview->is_top_fisheye) 
-               changetopfishfocus(view->Topview,&view->mouse.GLpos.x,&view->mouse.GLpos.y,  0, 1);
-           else    /*single right click*/
-/*     pick_node_from_coords(view->mouse.GLpos.x, view->mouse.GLpos.y,
-                             view->mouse.GLpos.z);*/
-
-           {;}
-
-
-       }
-
-    }
-    else    /*update selection values*/
-       rectangle_select(v);
 }
 void appmouse_right_drag(ViewInfo* v,int x,int y)
 {
index 7c2e43d7c3fcc9becf1024440afa0898796b28e5..f6e22375cc21bd97bbf8165973de23ea58841f45 100644 (file)
@@ -1,6 +1,87 @@
 
 #include "hotkeymap.h"
-int get_mode(ViewInfo* v)
+
+int static get_mouse_mode(const char* s)
+{
+    if (strcmp(s,"MM_PAN")==0)
+       return MM_PAN;
+    if (strcmp(s,"MM_ZOOM")==0)
+       return MM_ZOOM;
+    if (strcmp(s,"MM_ROTATE")==0)
+       return MM_ROTATE;
+    if (strcmp(s,"MM_SINGLE_SELECT")==0)
+       return MM_SINGLE_SELECT;
+    if (strcmp(s,"MM_RECTANGULAR_SELECT")==0)
+       return MM_RECTANGULAR_SELECT;
+    if (strcmp(s,"MM_RECTANGULAR_X_SELECT")==0)
+       return MM_RECTANGULAR_X_SELECT;
+    if (strcmp(s,"MM_MOVE")==0)
+       return MM_MOVE;
+    if (strcmp(s,"MM_MOVE")==0)
+       return MM_MOVE;
+    if (strcmp(s,"MM_MAGNIFIER")==0)
+       return MM_MAGNIFIER;
+    if (strcmp(s,"MM_FISHEYE_MAGNIFIER")==0)
+       return MM_FISHEYE_MAGNIFIER;
+    if (strcmp(s,"MM_FISHEYE_PICK")==0)
+       return MM_FISHEYE_PICK;
+
+    
+    return -1;
+
+}
+
+
+int static get_button(const char* s)
+{
+
+    if (strcmp(s,"B_LSHIFT")==0)
+       return B_LSHIFT;
+    if (strcmp(s,"B_RSHIFT")==0)
+       return B_RSHIFT;
+    if (strcmp(s,"B_LCTRL")==0)
+       return B_LCTRL;
+    if (strcmp(s,"B_RCTRL")==0)
+       return B_RCTRL;
+    if (strcmp(s,"0")==0)
+       return 0;
+
+}
+int static get_view_mode(const char* s)
+{
+    if (strcmp(s,"ALL")==0)
+       return smyrna_all;
+    if (strcmp(s,"2D")==0)
+       return smyrna_2D;
+    if (strcmp(s,"3D")==0)
+       return smyrna_3D;
+    if (strcmp(s,"FISHEYE")==0)
+       return smyrna_fisheye;
+    if (strcmp(s,"NO_FISHEYE")==0)
+       return smyrna_all_but_fisheye;
+    return -1;
+}
+int static get_mouse_button(const char* s)
+{
+
+    if (strcmp(s,"LEFT")==0)
+       return glMouseLeftButton;
+    if (strcmp(s,"RIGHT")==0)
+       return glMouseRightButton;
+    if (strcmp(s,"MIDDLE")==0)
+       return glMouseMiddleButton;
+    return -1;
+}
+int static get_drag(const char* s)
+{
+    if (s[0] == '1')
+       return 1;
+    return 0;
+}
+
+
+
+void load_mouse_actions (char* modefile,ViewInfo* v)
 {
 /*#define MM_PAN                                       0
 #define MM_ZOOM                                        1
@@ -11,6 +92,142 @@ int get_mode(ViewInfo* v)
 #define MM_MOVE                                        10
 #define MM_MAGNIFIER                   20
 #define MM_FISHEYE_MAGNIFIER   21*/
+    /*file parsing is temporarrily not available*/
+    int ind=0;
+    int i=0;
+    FILE* file;
+    char line[BUFSIZ];
+    char* a;
+    char* action_file = smyrnaPath ("mouse_actions.txt");
+    file = fopen(action_file, "r");
+    if (file != NULL) 
+       {
+               int ind=0;
+               while (fgets(line, BUFSIZ, file) != NULL) 
+               {
+                       int idx=0;
+                       a=strtok(line,",");
+
+                       if ((line[0]=='#') || (line[0]==' ')|| (strlen(line)==0))
+                               continue;
+
+                       v->mouse_action_count++;
+                       v->mouse_actions=realloc(v->mouse_actions,v->mouse_action_count * sizeof(mouse_action_t));
+                       v->mouse_actions[ind].action=get_mouse_mode(a);
+                       v->mouse_actions[ind].index=i;
+
+                       while ((a=strtok(NULL,",")))
+                       {
+                           //#Action(0),hotkey(1),view_mode(2),mouse_button(3),drag(4)
+                           switch (idx)
+                               {
+                                       case 0: 
+                                           v->mouse_actions[ind].hotkey=get_button(a);
+                                               break;
+                                       case 1: 
+                                               v->mouse_actions[ind].mode=get_view_mode(a);
+                                               break;
+                                       case 2: 
+                                               v->mouse_actions[ind].type=get_mouse_button(a);
+                                               break;
+                                       case 3: 
+                                               v->mouse_actions[ind].drag=get_drag(a);
+                                               break;
+
+                               }
+                               idx ++;
+                       }
+                       ind++;
+               }
+       }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+    v->mouse_action_count=7;
+    v->mouse_actions=realloc(v->mouse_actions,v->mouse_action_count * sizeof(mouse_action_t));
+    v->mouse_actions[ind].action=MM_PAN;
+    v->mouse_actions[ind].drag=1;
+    v->mouse_actions[ind].hotkey=0;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_all;
+    v->mouse_actions[ind].type=glMouseLeftButton;
+
+    ind++;
+
+    v->mouse_actions[ind].action=MM_ROTATE;
+    v->mouse_actions[ind].drag=1;
+    v->mouse_actions[ind].hotkey=B_LSHIFT;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_3D;
+    v->mouse_actions[ind].type=glMouseLeftButton;
+
+    ind++;
+
+    v->mouse_actions[ind].action=MM_SINGLE_SELECT;
+    v->mouse_actions[ind].drag=0;
+    v->mouse_actions[ind].hotkey=0;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_all_but_fisheye;
+    v->mouse_actions[ind].type=glMouseLeftButton;
+
+    ind++;
+
+    v->mouse_actions[ind].action=MM_RECTANGULAR_SELECT;
+    v->mouse_actions[ind].drag=1;
+    v->mouse_actions[ind].hotkey=0;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_all;
+    v->mouse_actions[ind].type=glMouseRightButton;
+
+    ind++;
+
+    v->mouse_actions[ind].action=MM_MOVE;
+    v->mouse_actions[ind].drag=1;
+    v->mouse_actions[ind].hotkey=B_LCTRL;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_2D;
+    v->mouse_actions[ind].type=glMouseLeftButton;
+
+    ind++;
+
+    v->mouse_actions[ind].action=MM_FISHEYE_MAGNIFIER;
+    v->mouse_actions[ind].drag=1;
+    v->mouse_actions[ind].hotkey=B_LSHIFT;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_2D;
+    v->mouse_actions[ind].type=glMouseLeftButton;
+
+    ind++;
+
+    v->mouse_actions[ind].action=MM_FISHEYE_PICK;
+    v->mouse_actions[ind].drag=0;
+    v->mouse_actions[ind].hotkey=0;
+    v->mouse_actions[ind].index=ind;
+    v->mouse_actions[ind].mode=smyrna_fisheye;
+    v->mouse_actions[ind].type=glMouseRightButton;
+*/
+}
+
+
+
+
+
+
+int get_mode(ViewInfo* v)
+{
 
 
 /*#define F_BUTTON1   B_LSHIFT
@@ -21,9 +238,42 @@ int get_mode(ViewInfo* v)
 #define MOUSE_BUTTON_1 LEFT_MOUSE_BUTTON
 #define MOUSE_BUTTON_2  RIGHT_MOUSE_BUTTON
 #define MOUSE_BUTTON_3 MIDDLE_MOUSE_BUTTON*/
+//typedef enum {smyrna_2D,smyrna_3D,smyrna_fisheye} smyrna_view_mode;
+    int ind=0;
+    glMouseButtonType curMouseType=v->mouse.t;
+    int curDragging=((v->mouse.dragX != 0)||(v->mouse.dragY != 0));
+    smyrna_view_mode view_mode;
+    view_mode=smyrna_2D;
+    if (v->active_camera >= 0 )
+       view_mode=smyrna_3D;
+    if(v->Topview->is_top_fisheye)
+       view_mode=smyrna_fisheye;
+    
+
+    for (;ind < v->mouse_action_count ; ind ++)
+    {
 
+       if ((v->mouse_actions[ind].hotkey==v->keymap.keyVal)
+               &&
+               (v->mouse_actions[ind].type==curMouseType)
+                   &&
+               (v->mouse_actions[ind].drag==curDragging) 
+                   &&
+                   ((v->mouse_actions[ind].mode==view_mode)||( v->mouse_actions[ind].mode==smyrna_all)||
+                   ((v->mouse_actions[ind].mode==smyrna_all_but_fisheye)&&(view_mode !=smyrna_fisheye))
+                   ))
+       {
+           return v->mouse_actions[ind].action;
 
-    if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->keymap.down) && (view->keymap.keyVal ==F_BUTTON1) && (view->active_camera==-1))
+       }
+    }
+    return -1;
+
+
+
+
+
+/*    if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->keymap.down) && (view->keymap.keyVal ==F_BUTTON1) && (view->active_camera==-1))
        return MM_FISHEYE_MAGNIFIER;
     if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->keymap.down) && (view->keymap.keyVal == F_BUTTON1) && (view->active_camera>-1))
        return MM_ROTATE;
@@ -32,7 +282,8 @@ int get_mode(ViewInfo* v)
     if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->mouse.down) ) 
        return MM_PAN;
     if ((view->mouse.t==MOUSE_BUTTON_2)&&(view->mouse.down) ) 
-       return MM_RECTANGULAR_SELECT;
+       return MM_RECTANGULAR_SELECT;*/
+
+
 
-    return 0;
 }
index 86fbb3e9a21119c021f3e21c1293b934dfc06d6d..9bc07885bb140f53eff3faa70c7539b315157a72 100644 (file)
 
 
 
-
+extern void load_mouse_actions (char* modefile,ViewInfo* v);
 
 extern int get_mode(ViewInfo* v);
 
 
 
+
 #endif
index 7f74814ccc7445b06b32fef0312763d8d1cb7121..dcc10e6887eaf190f65cc4ca6ab889e530c0dd05 100644 (file)
@@ -69,6 +69,7 @@ typedef struct _ArcBall_t ArcBall_t;
 #define MM_MOVE                                        10
 #define MM_MAGNIFIER                   20
 #define MM_FISHEYE_MAGNIFIER   21
+#define MM_FISHEYE_PICK                22  /*fisheye select foci point*/
 
 
 
@@ -103,6 +104,7 @@ typedef struct _ArcBall_t ArcBall_t;
 #define MAX_FILTERED_ATTR_COUNT 50
 
 typedef enum {attr_alpha,attr_float,attr_int,attr_bool,attr_drowdown,attr_color} attr_data_type;
+typedef enum {smyrna_all,smyrna_2D,smyrna_3D,smyrna_fisheye,smyrna_all_but_fisheye} smyrna_view_mode;
 
 
 typedef struct{
@@ -245,6 +247,17 @@ typedef struct
 
     typedef enum { GEpixels, GEinches, GEmm } GEunit;
 
+
+    typedef struct 
+    {
+       int index;
+       int action;
+       int hotkey;
+       glMouseButtonType type;
+       int drag;
+       smyrna_view_mode mode;
+    }mouse_action_t;
+
     typedef struct _object_data        //has to be attached to every Node, Edge, Graph and cluster
     {
        Agrec_t h;
@@ -648,6 +661,8 @@ typedef struct
        GtkComboBox *graphComboBox;     /*pointer to graph combo box at top right */
        ArcBall_t *arcball;
        keymap_t keymap;
+       mouse_action_t* mouse_actions;  /*customizable moouse interraction list*/
+       int mouse_action_count;
 
     } ViewInfo;
 /*rotation steps*/
index 1d5216236b2ac8d3db36d4a9f5b7d2071bddb215..2e1a1c6f0b1e9ae43b0ea72a40fb44932e551308 100755 (executable)
@@ -34,6 +34,8 @@
 #include "topviewsettings.h"
 #include "md5.h"
 #include "arcball.h"
+#include "hotkeymap.h"
+
 
 
   /* Forward declarations */
@@ -481,6 +483,8 @@ void init_viewport(ViewInfo * view)
     view->flush = 1;
     view->arcball = NEW(ArcBall_t);
     view->keymap.down=0;
+    load_mouse_actions (NULL,view);
+
     /*add default camera */
     //create fontset
 }
diff --git a/share/gui/mouse_actions.txt b/share/gui/mouse_actions.txt
new file mode 100644 (file)
index 0000000..2f18510
--- /dev/null
@@ -0,0 +1,34 @@
+#Handled actions:
+#MM_PAN                
+#MM_ROTATE
+#MM_SINGLE_SELECT
+#MM_RECTANGULAR_SELECT
+#MM_MOVE
+#MM_FISHEYE_MAGNIFIER
+#keys:These are pre defined keys in the code , more keys can be added by using their GTK key event correspondants, 0 means no key
+#B_LSHIFT      Left Shift
+#B_RSHIFT      Right Shift
+#B_LCTRL       Left CTRL
+#B_RCTRL       Right CTRL
+#view modes , use one from the following list for each line
+#ALL           Action is always active
+#2D            active only in 2D mode
+#3D            active in only 3D mode
+#FISHEYE       active in only fisheye mode
+#NO_FISHEYE    active when mode is not fisheye
+#mouse_button
+#LEFT
+#RIGHT
+#MIDDLE
+#drag
+#specify if action requires mouse to be dragged
+#Line format
+#Action,hotkey,view_mode,mouse_button,drag
+#COMBO1
+MM_PAN,0,ALL,LEFT,1
+MM_ROTATE,B_LSHIFT,3D,LEFT,1
+MM_SINGLE_SELECT,0,NO_FISHEYE,RIGHT,0 
+MM_RECTANGULAR_SELECT,0,ALL,RIGHT,1 
+MM_MOVE,B_LCTRL,2D,LEFT,1 
+MM_FISHEYE_MAGNIFIER,B_LSHIFT,2D,LEFT,1 
+MM_FISHEYE_PICK,0,FISHEYE,RIGHT,0 
\ No newline at end of file