shithub: pain

Download patch

ref: c8dfc9e70b9e9df578e0c1213b04ae31d5c28c08
parent: ba2794f02b1f69c0b7c2310f967c308d17471c78
author: jmq <jmq@jmq.sh>
date: Tue Dec 10 00:54:22 EST 2024

fixed +pos bug

--- a/fns.h
+++ b/fns.h
@@ -26,6 +26,7 @@
 void ntfprint(char *, ...);
 void setcurrentlayer(Layer *);
 Point mulptf(Point, float);
+int rectcut(Rectangle *, Rectangle);
 
 Point globaltoscreenpt(Point p);
 Point globaltoscreenatcanvaspt(Point p);
--- a/main.c
+++ b/main.c
@@ -43,7 +43,7 @@
 int DrawAllLayers = 0;
 float Zoom = 1;
 float TargetZoom = 1;
-float ZoomSensitivity = 0.1;
+float ZoomSensitivity = 0.025;
 Mouse CurrentMouse = {0};
 Mouse PastMouse = {0};
 Point MousePosition = {0};
@@ -143,7 +143,8 @@
 void
 drawcanvas(void)
 {
-	int sr;
+	int sr, i;
+	Point p;
 	Rectangle vr;
 
 	sr = 0;
@@ -173,8 +174,14 @@
 		setbackground(BACKGROUNDCOLOR);
 
 	vr = rectaddpt(ZoomedSize, CanvasAt);
-	if (rectclip(&vr, Rect(0, 0, Dx(screen->r), Dy(screen->r))) && ((CanvasMoved && Ar(vr) != Ar(ZoomedSize)) || sr)) {
-		vr = rectsubpt(vr, CanvasAt);
+	i = rectclip(&vr,Rect(0, 0, Dx(screen->r), Dy(screen->r)));
+	if (i && ((CanvasMoved && Ar(vr) != Ar(ZoomedSize)) || sr)) {
+		p = CanvasAt;
+		if (p.x < 0)
+			p.x = 0;
+		if (p.y < 0)
+			p.y = 0;
+		vr = rectsubpt(vr, p);
 		if (resizeimage(ZoomedImage, vr, Zoom, ViewImage, ZP) < 0)
 			sysfatal("resizeimage: %r");
 	}
@@ -252,11 +259,11 @@
 	osx = Dx(ZoomedSize);
 	osy = Dy(ZoomedSize);
 
-	zs->min = mulptf(CanvasSize.min, z);
+	zs->min = ZP;
 	zs->max = mulptf(CanvasSize.max, z);
 
 	*ca = addpt(
-		Pt(Dx(ZoomedSize)*c.x/osx, Dy(ZoomedSize)*c.y/osy), 
+		Pt(Dx(*zs)*c.x/osx, Dy(*zs)*c.y/osy), 
 		MousePosition
 	);
 }
--- a/resize.c
+++ b/resize.c
@@ -14,7 +14,7 @@
 	float d, f;
 	Point p;
 	Rectangle r, tr;
-	int sh, i;
+	int i;
 	Image * t, * ci;
 
 	if (scale < 0) {
@@ -24,8 +24,7 @@
 		draw(di, dr, si, nil, addpt(sp, dr.min));
 		return 1;
 	}
-	
-	sh = Dy(si->r);
+
 	// Allocate temporary image with the size of the dimensions
 	// we are supposed to write on
 	tr = dr;
@@ -60,9 +59,7 @@
 	r.max.y = tr.max.y;
 	r.max.x = r.min.x + MAX(1.0, scale);	// It wouldn't make much sense to have
 											// a horizontal width of less than 1
-	// print("t->r = %R\n", t->r);
-	// print("ci->r = %R\n", ci->r);
-	// print("dr = %R\n", dr);
+
 	i = r.max.x - r.min.x;
 	d = p.x;
 	f = r.min.x;
@@ -75,7 +72,6 @@
 		// image, for every line on the target image will we will skip over multiple
 		// lines on the source image.
 		
-		// print("f = %f, p = %P, r = %R\n", scale, p, r);
 		// Move the ci one 1/scale space to the right
 		draw(ci, ci->r, si, nil, p);
 		d += MAX(1/scale, 1);
--