tetris: add vertical separator between playfield and side panel; enlarge next-piece preview

Draw a bright vertical divider in the gap between the playfield and the side
panel so the two areas are clearly separated, and render the NEXT piece larger
(pcell 6 -> 11) centered inside a framed preview box.
This commit is contained in:
Luxferre
2026-10-23 19:18:32 +03:00
parent 70ef9860be
commit 36757c3f46
3 changed files with 18 additions and 5 deletions
Binary file not shown.
Binary file not shown.
+18 -5
View File
@@ -279,27 +279,40 @@ static void render() {
}
}
// vertical separator line between the playfield and the side panel
int sepX = px0 + PCOLS * CELL + 6;
XSetForeground(dpy, gc, C_FG);
XDrawLine(dpy, back, gc, sepX, py0, sepX, py0 + PROWS * CELL);
// side panel
int sx = px0 + PCOLS * CELL + 12;
draw_text(sx, py0, 1, C_DIM, "NEXT");
// framed preview box for the next piece
int boxY = py0 + 10;
int boxH = 48;
XSetForeground(dpy, gc, C_DIM);
XDrawRectangle(dpy, back, gc, sx, boxY, winW - sx - 4, boxH);
int nc[4][2];
piece_cells(nextType, 0, nc);
int minx = 4, miny = 4, maxx = -1, maxy = -1;
for (int i = 0; i < 4; i++) {
minx = nc[i][0] < minx ? nc[i][0] : minx;
miny = nc[i][1] < miny ? nc[i][1] : miny;
miny = nc[i][1] < miny ? miny : miny;
maxx = nc[i][0] > maxx ? nc[i][0] : maxx;
maxy = nc[i][1] > maxy ? nc[i][1] : maxy;
maxy = nc[i][1] > maxy ? maxy : maxy;
}
int pcell = 6;
int nx0 = sx + 2, ny0 = py0 + 10;
int pcell = 11; // larger next-piece preview
int pcols = maxx - minx + 1;
int prows = maxy - miny + 1;
int nx0 = sx + ((winW - sx - 4) - pcols * pcell) / 2;
int ny0 = boxY + (boxH - prows * pcell) / 2;
XSetForeground(dpy, gc, C_HEAD);
for (int i = 0; i < 4; i++) {
int cx = nx0 + (nc[i][0] - minx) * pcell;
int cy = ny0 + (nc[i][1] - miny) * pcell;
XFillRectangle(dpy, back, gc, cx, cy, pcell, pcell);
}
int ty = py0 + 60;
int ty = boxY + boxH + 6;
char buf[32];
snprintf(buf, sizeof(buf), "SCORE %d", score); draw_text(sx, ty, 1, C_DIM, buf);
snprintf(buf, sizeof(buf), "LINES %d", lines); draw_text(sx, ty + 9, 1, C_DIM, buf);