ref: 0cfaa8fbd77ea39a6752e5df66dc6559a52585e4
parent: 3b83debfa8a7a5dc82c40d6500d35a9c98135cea
author: sirjofri <sirjofri@sirjofri.de>
date: Mon May 27 08:04:55 EDT 2024
puts game area in the center
--- a/plan9.c
+++ b/plan9.c
@@ -495,6 +495,7 @@
int resizenop;
Control *ctl;
Point newsize;
+ Point offset;
if (getwindow(display, Refnone) < 0) {
sysfatal("resize failed: %r");
@@ -513,8 +514,11 @@
return;
draw(screen, screen->r, fe->background, nil, ZP);
- fe->rect = rarea;
- fe->ZP = rarea.min;
+ /* calculate offset to place game area in the center */
+ offset = Pt(Dx(rarea), Dy(rarea)); // size of total game area
+ offset = subpt(divpt(addpt(offset, newsize), 2), newsize);
+ fe->rect = rectaddpt(rarea, offset);
+ fe->ZP = fe->rect.min;
chanprint(cs->ctl, "rowmain rect %R\nrowmain show", rmenu);
chanprint(cs->ctl, "l_status rect %R\nl_status show", sarea);
@@ -526,7 +530,7 @@
flushimage(display, 1);
break;
case SETTINGS:
- chanprint(cs->ctl, "c_settings rect %R\nc_settings reveal\nc_settings show", rarea);
+ chanprint(cs->ctl, "c_settings rect %R\nc_settings reveal\nc_settings show", fe->rect);
break;
}