From 7272b080db41ef9033b83a991ee44e7a24176b62 Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 24 Feb 2020 00:49:21 -0600 Subject: made the camera control with the secondary mouse button work in a way that is easier to use --- src/graphics_c3.h | 2 ++ src/mouse_x11.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/graphics_c3.h b/src/graphics_c3.h index 691b650..b609721 100644 --- a/src/graphics_c3.h +++ b/src/graphics_c3.h @@ -23,6 +23,8 @@ struct gra_global { int mapxoff; int mapyoff; int mousemap[10];//you're only going to have 10 buttons on your mouse... right? + c2_t dragstart[10];//mouse coordinates where a drag was started + c3_rot_t oldcamera; int maxshapes; }; diff --git a/src/mouse_x11.c b/src/mouse_x11.c index 23ec5ab..16c577c 100644 --- a/src/mouse_x11.c +++ b/src/mouse_x11.c @@ -38,12 +38,14 @@ int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for bu printf("# gra_global.input_mode == %d\n",gra_global.input_mode); } printf("# button press %d\n",butt); + gra_global.dragstart[butt]=gra_global.mouse; gra_global.mousemap[butt]=1; redrawplzkthx=1; break; case ButtonRelease: printf("# button release %d\n",e.xbutton.button-1); gra_global.mousemap[e.xbutton.button-1]=-1;//we can trigger on -1 or on 1 then set back to 0 to prevent double-trigger + gra_global.oldcamera=global.camera.r; redrawplzkthx=1; break; case MotionNotify: @@ -68,8 +70,8 @@ int mouse_event_handler() {//this returns HVM_ key + for buttondown and - for bu //global.camera.r.x.d=(gra_global.height - gra_global.mouse.y);//up and down camera controls backwards //fprintf(stderr,"# mouse.x: %f mouse.y: %f\n# width: %u height: %u\n",gra_global.mouse.x,gra_global.mouse.y,gra_global.width,gra_global.height); if(gra_global.mousemap[2] == 1) {//if "right" click is held down - global.camera.r.x.d=(gra_global.mouse.y); - global.camera.r.y.d=(gra_global.mouse.x); + global.camera.r.x.d=gra_global.oldcamera.x.d + (gra_global.mouse.y - gra_global.dragstart[2].y); + global.camera.r.y.d=gra_global.oldcamera.y.d + (gra_global.mouse.x - gra_global.dragstart[2].x); } } if(redrawplzkthx) { -- cgit v1.2.3