shithub: npe

Download patch

ref: a9006b7d8db146f51c4adc2f356d80dc0211ad81
parent: 2eb9412c338b44fcefaf28aa438a3965071f0ba4
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Oct 28 20:14:51 EDT 2021

sdl2: scale mouse movements according to zoom

--- a/libnpe_sdl2/_sdl.h
+++ b/libnpe_sdl2/_sdl.h
@@ -17,6 +17,7 @@
 	int mredraw;
 	int fullredraw;
 	int textinput;
+	float scale;
 };
 
 enum {
--- a/libnpe_sdl2/events.c
+++ b/libnpe_sdl2/events.c
@@ -107,8 +107,8 @@
 
 	case Cmouse:
 		memset(e, 0, sizeof(*e));
-		e->motion.x = npe_sdl.m.xy.x - screen->r.min.x;
-		e->motion.y = npe_sdl.m.xy.y - screen->r.min.y;
+		e->motion.x = (npe_sdl.m.xy.x - screen->r.min.x) * npe_sdl.scale;
+		e->motion.y = (npe_sdl.m.xy.y - screen->r.min.y) * npe_sdl.scale;
 		if(!eqpt(npe_sdl.m.xy, npe_sdl.om.xy)){
 			npe_sdl.mredraw = 1;
 			if(npe_sdl.m.buttons == npe_sdl.om.buttons){
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -70,6 +70,7 @@
 		goto err;
 	if(npe_sdl_init_input() != 0)
 		goto err;
+	npe_sdl.scale = 1;
 
 	return 0;
 err:
@@ -629,6 +630,8 @@
 		logiw = physw;
 		logih = physh;
 	}
+
+	npe_sdl.scale = (float)logiw / (float)physw;
 
 	if(!npe_sdl.fullredraw && (npe_sdl.fullredraw = memcmp(backcopy, byteaddr(back, ZP), logiw*logih*4)) == 0 && !npe_sdl.mredraw)
 		return;