ref: 322545c522db8bcf396d98e437f84b033125a721
parent: b573b863e1ea1a84bb43d44368565280c8379451
author: sirjofri <sirjofri@sirjofri.de>
date: Mon Feb 16 16:02:23 EST 2026
improves mouse hit handling
--- a/main.c
+++ b/main.c
@@ -22,6 +22,8 @@
}
Point carddim;
+Rectangle roomrects[4];
+Rectangle weaponrect;
static void
drawroom(int *cards)
@@ -39,7 +41,8 @@
p.x = i * Dx(img->r);
p.y = 0;
p = addpt(p, screen->r.min);
- draw(screen, rectaddpt(img->r, p), img, nil, ZP);
+ roomrects[i] = rectaddpt(img->r, p);
+ draw(screen, roomrects[i], img, nil, ZP);
}
}
@@ -61,7 +64,8 @@
p.x = 0;
p.y = Dy(img->r);
p = addpt(p, screen->r.min);
- draw(screen, rectaddpt(img->r, p), img, nil, ZP);
+ weaponrect = rectaddpt(img->r, p);
+ draw(screen, weaponrect, img, nil, ZP);
if (useweapon) {p.x = Dx(img->r)+10;
@@ -195,23 +199,22 @@
if (m.buttons != 1)
return;
- m.xy.x -= screen->r.min.x;
- m.xy.y -= screen->r.min.y;
-
- if (m.xy.y < carddim.y) {- /* first row: room cards */
- i = m.xy.x / carddim.x;
- if (roomaction(i, useweapon)) redraw();
- return;
- }
- if (m.xy.y < carddim.y*2) {- if (m.xy.x < carddim.x) {- /* weapon card pressed */
- useweapon = !useweapon;
- redraw();
+ for (i = 0; i < 4; i++) {+ /* room cards */
+ if (ptinrect(m.xy, roomrects[i])) {+ if (roomaction(i, useweapon))
+ redraw();
return;
}
}
+
+ if (ptinrect(m.xy, weaponrect)) {+ /* weapon card */
+ useweapon = !useweapon;
+ redraw();
+ return;
+ }
+ return;
}
void
--
⑨