From c1f41315d15c6755efe087da8f3ea22ff177f32d Mon Sep 17 00:00:00 2001 From: arif Date: Mon, 9 Nov 2009 20:52:51 +0000 Subject: [PATCH] SMYRNA:customized mouse actions feauture added --- cmd/smyrna/gltemplate.c | 1 + cmd/smyrna/gui/appmouse.c | 111 ++++++++-------- cmd/smyrna/hotkeymap.c | 259 +++++++++++++++++++++++++++++++++++- cmd/smyrna/hotkeymap.h | 3 +- cmd/smyrna/smyrnadefs.h | 15 +++ cmd/smyrna/viewport.c | 4 + share/gui/mouse_actions.txt | 34 +++++ 7 files changed, 369 insertions(+), 58 deletions(-) create mode 100644 share/gui/mouse_actions.txt diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index 005578b5c..adc2cf09e 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -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); } diff --git a/cmd/smyrna/gui/appmouse.c b/cmd/smyrna/gui/appmouse.c index 1b08f0420..eb63b0d87 100644 --- a/cmd/smyrna/gui/appmouse.c +++ b/cmd/smyrna/gui/appmouse.c @@ -26,7 +26,58 @@ 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) { diff --git a/cmd/smyrna/hotkeymap.c b/cmd/smyrna/hotkeymap.c index 7c2e43d7c..f6e22375c 100644 --- a/cmd/smyrna/hotkeymap.c +++ b/cmd/smyrna/hotkeymap.c @@ -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; } diff --git a/cmd/smyrna/hotkeymap.h b/cmd/smyrna/hotkeymap.h index 86fbb3e9a..9bc07885b 100644 --- a/cmd/smyrna/hotkeymap.h +++ b/cmd/smyrna/hotkeymap.h @@ -40,10 +40,11 @@ - +extern void load_mouse_actions (char* modefile,ViewInfo* v); extern int get_mode(ViewInfo* v); + #endif diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index 7f74814cc..dcc10e688 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -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*/ diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 1d5216236..2e1a1c6f0 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -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 index 000000000..2f1851078 --- /dev/null +++ b/share/gui/mouse_actions.txt @@ -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 -- 2.40.0