Browse code

Only update viewport rect on resize

Devine Lu Linvega authored on 26/07/2023 15:37:58
Showing 1 changed files
... ...
@@ -48,27 +48,27 @@ WITH REGARD TO THIS SOFTWARE.
48 48
 static SDL_Window *emu_window;
49 49
 static SDL_Texture *emu_texture;
50 50
 static SDL_Renderer *emu_renderer;
51
+static SDL_Rect emu_viewport;
51 52
 static SDL_AudioDeviceID audio_id;
52 53
 static SDL_Thread *stdin_thread;
53 54
 
54
-Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
55
-Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
56
-
57 55
 /* devices */
58 56
 
57
+static int window_created = 0;
59 58
 static Uint32 stdin_event, audio0_event, zoom = 1;
60 59
 static Uint64 exec_deadline, deadline_interval, ms_interval;
60
+static char *rom_path;
61 61
 
62
-char *rom_path;
63
-int window_created = 0;
62
+Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
63
+Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
64 64
 
65 65
 static int
66 66
 clamp(int v, int min, int max)
67 67
 {
68
-
69 68
 	return v < min ? min : v > max ? max
70 69
 								   : v;
71 70
 }
71
+
72 72
 static Uint8
73 73
 audio_dei(int instance, Uint8 *d, Uint8 port)
74 74
 {
... ...
@@ -199,6 +199,10 @@ emu_resize(int width, int height)
199 199
 		return system_error("SDL_SetTextureBlendMode", SDL_GetError());
200 200
 	if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0)
201 201
 		return system_error("SDL_UpdateTexture", SDL_GetError());
202
+	emu_viewport.x = PAD;
203
+	emu_viewport.y = PAD;
204
+	emu_viewport.w = uxn_screen.width;
205
+	emu_viewport.h = uxn_screen.height;
202 206
 	set_window_size(emu_window, (width + PAD2) * zoom, (height + PAD2) * zoom);
203 207
 	return 1;
204 208
 }
... ...
@@ -206,16 +210,11 @@ emu_resize(int width, int height)
206 210
 static void
207 211
 emu_redraw(void)
208 212
 {
209
-	SDL_Rect r;
210
-	r.x = PAD;
211
-	r.y = PAD;
212
-	r.w = uxn_screen.width;
213
-	r.h = uxn_screen.height;
214 213
 	screen_redraw();
215 214
 	if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
216 215
 		system_error("SDL_UpdateTexture", SDL_GetError());
217 216
 	SDL_RenderClear(emu_renderer);
218
-	SDL_RenderCopy(emu_renderer, emu_texture, NULL, &r);
217
+	SDL_RenderCopy(emu_renderer, emu_texture, NULL, &emu_viewport);
219 218
 	SDL_RenderPresent(emu_renderer);
220 219
 }
221 220
 
... ...
@@ -374,7 +373,7 @@ handle_events(Uxn *u)
374 373
 			uxn_eval(u, PEEK2(&u->dev[0x30 + 0x10 * (event.type - audio0_event)]));
375 374
 		/* Mouse */
376 375
 		else if(event.type == SDL_MOUSEMOTION)
377
-			mouse_pos(u, &u->dev[0x90], clamp(event.motion.x - PAD, 0, uxn_screen.width), clamp(event.motion.y - PAD, 0, uxn_screen.height));
376
+			mouse_pos(u, &u->dev[0x90], clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
378 377
 		else if(event.type == SDL_MOUSEBUTTONUP)
379 378
 			mouse_up(u, &u->dev[0x90], SDL_BUTTON(event.button.button));
380 379
 		else if(event.type == SDL_MOUSEBUTTONDOWN)