2021-02-26 09:29:10 +08:00
|
|
|
#include <gtk/gtk.h>
|
2021-02-26 17:09:05 +08:00
|
|
|
#include <cstdio>
|
2021-02-26 09:29:10 +08:00
|
|
|
|
2021-02-26 17:09:05 +08:00
|
|
|
typedef struct {
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
}MousePos;
|
2021-02-26 09:29:10 +08:00
|
|
|
|
2021-02-26 17:09:05 +08:00
|
|
|
//static double start_x,start_y;
|
|
|
|
|
|
|
|
void drag_begin(GtkGesture *gesture,double x,double y,MousePos *pos){
|
|
|
|
pos->x=x;
|
|
|
|
pos->y=y;
|
2021-02-26 09:29:10 +08:00
|
|
|
freopen("drag.txt","a",stdout);
|
|
|
|
g_print("%lf %lf\n",x,y);
|
|
|
|
fclose(stdout);
|
|
|
|
}
|
|
|
|
|
2021-02-26 17:09:05 +08:00
|
|
|
void drag_update(GtkGesture *gesture,double x,double y,MousePos *pos){
|
2021-02-26 09:29:10 +08:00
|
|
|
freopen("drag.txt","a",stdout);
|
2021-02-26 17:09:05 +08:00
|
|
|
g_print("%lf %lf\n",x+pos->x,y+pos->y);
|
2021-02-26 09:29:10 +08:00
|
|
|
fclose(stdout);
|
|
|
|
}
|
|
|
|
|
2021-02-26 17:09:05 +08:00
|
|
|
void drag_end(GtkGesture *gesture,double x,double y,MousePos *pos){
|
2021-02-26 09:29:10 +08:00
|
|
|
freopen("drag.txt","a",stdout);
|
2021-02-26 17:09:05 +08:00
|
|
|
g_print("%lf %lf\n",x+pos->x,y+pos->y);
|
2021-02-26 09:29:10 +08:00
|
|
|
fclose(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pressed(GtkGestureMultiPress *gesture,int n_press,double x,double y,gpointer user_data){
|
2021-02-26 17:09:05 +08:00
|
|
|
g_print("%d\n",n_press);
|
|
|
|
freopen("drag.txt","w",stdout);
|
|
|
|
printf("\0");
|
|
|
|
fclose(stdout);
|
2021-02-26 09:29:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gtkmain(GtkApplication *app,gpointer user_data){
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkGesture *press,*drag;
|
|
|
|
//Create a window
|
|
|
|
window=gtk_application_window_new(app);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window),"Mouse Event Test");
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(window),640,360);
|
|
|
|
gtk_window_set_icon_name(GTK_WINDOW(window),"org.gtk.daleclack");
|
|
|
|
//Create gestures
|
|
|
|
|
2021-02-26 17:09:05 +08:00
|
|
|
static MousePos pos;
|
2021-02-26 09:29:10 +08:00
|
|
|
//"Drag" gesture
|
|
|
|
drag=gtk_gesture_drag_new(window);
|
|
|
|
|
|
|
|
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(drag),GDK_BUTTON_PRIMARY);
|
2021-02-26 17:09:05 +08:00
|
|
|
g_signal_connect(drag,"drag-begin",G_CALLBACK(drag_begin),&pos);
|
|
|
|
g_signal_connect(drag,"drag-update",G_CALLBACK(drag_update),&pos);
|
|
|
|
g_signal_connect(drag,"drag-end",G_CALLBACK(drag_end),&pos);
|
2021-02-26 09:29:10 +08:00
|
|
|
|
|
|
|
//"Press" gesture
|
|
|
|
|
|
|
|
press=gtk_gesture_multi_press_new(window);
|
|
|
|
|
|
|
|
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(press),GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect(press,"pressed",G_CALLBACK(pressed),NULL);
|
|
|
|
|
|
|
|
gtk_widget_show_all(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc,char *argv[]){
|
|
|
|
GtkApplication *app;
|
|
|
|
int status;
|
|
|
|
app=gtk_application_new("org.gtk.daleclack",G_APPLICATION_NON_UNIQUE);
|
|
|
|
g_signal_connect(app,"activate",G_CALLBACK(gtkmain),NULL);
|
|
|
|
status=g_application_run(G_APPLICATION(app),argc,argv);
|
|
|
|
return status;
|
|
|
|
}
|