commit 55178e8

Devine Lu Linvega  ·  2023-04-30 18:32:11 +0000 UTC
parent 855b63b
Added ZOOM support
3 files changed,  +13, -8
+7, -4
 1@@ -75,7 +75,7 @@ screen_resize(UxnScreen *p, Uint16 width, Uint16 height)
 2 		return;
 3 	bg = realloc(p->bg.pixels, width * height),
 4 	fg = realloc(p->fg.pixels, width * height);
 5-	pixels = realloc(p->pixels, width * height * sizeof(Uint32));
 6+	pixels = realloc(p->pixels, width * height * sizeof(Uint32) * ZOOM * ZOOM);
 7 	if(!bg || !fg || !pixels)
 8 		return;
 9 	p->bg.pixels = bg;
10@@ -90,12 +90,15 @@ screen_resize(UxnScreen *p, Uint16 width, Uint16 height)
11 void
12 screen_redraw(UxnScreen *p)
13 {
14-	Uint32 i, size = p->width * p->height, palette[16], *pixels = p->pixels;
15 	Uint8 *fg = p->fg.pixels, *bg = p->bg.pixels;
16+	Uint32 i, j, x, y, w = p->width * ZOOM, h = p->height * ZOOM, palette[16], *pixels = p->pixels;
17 	for(i = 0; i < 16; i++)
18 		palette[i] = p->palette[(i >> 2) ? (i >> 2) : (i & 3)];
19-	for(i = 0; i < size; i++)
20-		pixels[i] = palette[fg[i] << 2 | bg[i]];
21+	for(y = 0; y < h; y++)
22+		for(x = 0; x < w; x++) {
23+			j = ((x / ZOOM) + (y / ZOOM) * p->width);
24+			pixels[x + y * w] = palette[fg[j] << 2 | bg[j]];
25+		}
26 	p->fg.changed = p->bg.changed = 0;
27 }
28 
+2, -0
1@@ -10,6 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2 WITH REGARD TO THIS SOFTWARE.
3 */
4 
5+#define ZOOM 2
6+
7 typedef struct Layer {
8 	Uint8 *pixels, changed;
9 } Layer;
+4, -4
 1@@ -72,7 +72,7 @@ static void
 2 emu_draw(void)
 3 {
 4 	screen_redraw(&uxn_screen);
 5-	XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width, uxn_screen.height);
 6+	XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width * ZOOM, uxn_screen.height * ZOOM);
 7 }
 8 
 9 static int
10@@ -166,7 +166,7 @@ emu_event(Uxn *u)
11 	} break;
12 	case MotionNotify: {
13 		XMotionEvent *e = (XMotionEvent *)&ev;
14-		mouse_pos(u, &u->dev[0x90], e->x - PAD, e->y - PAD);
15+		mouse_pos(u, &u->dev[0x90], (e->x - PAD) / ZOOM, (e->y - PAD) / ZOOM);
16 	} break;
17 	}
18 }
19@@ -177,7 +177,7 @@ display_start(char *title)
20 	Atom wmDelete;
21 	display = XOpenDisplay(NULL);
22 	visual = DefaultVisual(display, 0);
23-	window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2, 1, 0, 0);
24+	window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * ZOOM + PAD * 2, uxn_screen.height * ZOOM + PAD * 2, 1, 0, 0);
25 	if(visual->class != TrueColor)
26 		return system_error("init", "True-color visual failed");
27 	XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
28@@ -185,7 +185,7 @@ display_start(char *title)
29 	XSetWMProtocols(display, window, &wmDelete, 1);
30 	XStoreName(display, window, title);
31 	XMapWindow(display, window);
32-	ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width, uxn_screen.height, 32, 0);
33+	ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width * ZOOM, uxn_screen.height * ZOOM, 32, 0);
34 	hide_cursor();
35 	return 1;
36 }