Maelstrom: Added some quick hacks to try out how the game feels at different resolutions.

https://github.com/libsdl-org/Maelstrom/commit/016c44e51d0f75efcbc5288a92fd8e547fef6650

From 016c44e51d0f75efcbc5288a92fd8e547fef6650 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 10 Nov 2011 02:15:54 -0500
Subject: [PATCH] Added some quick hacks to try out how the game feels at
 different resolutions.

---
 screenlib/SDL_FrameBuf.cpp | 13 ++++++--
 screenlib/SDL_FrameBuf.h   | 68 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index c922f608..0c008b46 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -46,6 +46,11 @@ FrameBuf:: Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
 {
 	int w, h;
 
+#ifdef HACK_RESOLUTION
+	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
+#endif
+	AdjustCoordinates(width, height);
+
 	window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags);
 	if (!window) {
 		SetError("Couldn't create %dx%d window: %s", 
@@ -75,8 +80,8 @@ FrameBuf:: Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
 	/* Set the blit clipping rectangle */
 	clip.x = 0;
 	clip.y = 0;
-	clip.w = width;
-	clip.h = height;
+	clip.w = AdjustCoordinateX(width, true);
+	clip.h = AdjustCoordinateY(height, true);
 
 	/* Copy the image colormap */
 	if ( colors ) {
@@ -175,6 +180,8 @@ FrameBuf:: QueueBlit(int dstx, int dsty, SDL_Texture *src,
 		srcrect.w = dstrect.w;
 		srcrect.h = dstrect.h;
 	}
+	AdjustCoordinates(dstrect.x, dstrect.y);
+	AdjustCoordinates(dstrect.w, dstrect.h);
 	SDL_RenderCopy(renderer, src, &srcrect, &dstrect);
 }
 
@@ -234,6 +241,8 @@ FrameBuf:: ScreenDump(const char *prefix, int x, int y, int w, int h)
 	if (!h) {
 		h = Height();
 	}
+	AdjustCoordinates(x, y);
+	AdjustCoordinates(w, h);
 	rect.x = x;
 	rect.y = y;
 	rect.w = w;
diff --git a/screenlib/SDL_FrameBuf.h b/screenlib/SDL_FrameBuf.h
index 6361736f..55f50609 100644
--- a/screenlib/SDL_FrameBuf.h
+++ b/screenlib/SDL_FrameBuf.h
@@ -31,6 +31,25 @@
 // Define this if you're rapidly iterating on UI screens
 //#define FAST_ITERATION
 
+// Define these if you want to try out the quick resolution hacks
+//#define HACK_1024x768
+//#define HACK_400x300
+
+#ifdef HACK_1024x768
+#define HACK_RESOLUTION
+#define HACK_RESOLUTION_X 1024
+#define HACK_RESOLUTION_Y 768
+#endif
+#ifdef HACK_400x300
+#define HACK_RESOLUTION
+#define HACK_RESOLUTION_X 400
+#define HACK_RESOLUTION_Y 300
+#endif
+#ifdef HACK_RESOLUTION
+#define ORIG_RESOLUTION_X 640
+#define ORIG_RESOLUTION_Y 480
+#endif
+
 #include <stdio.h>
 
 #include "SDL.h"
@@ -49,6 +68,31 @@ class FrameBuf : public ErrorBase {
 			SDL_Color *colors = NULL, SDL_Surface *icon = NULL);
 	virtual ~FrameBuf();
 
+	int AdjustCoordinateX(int &x, bool invert = false) const {
+#ifdef HACK_RESOLUTION
+		if (invert) {
+			x = (x*ORIG_RESOLUTION_X)/HACK_RESOLUTION_X;
+		} else {
+			x = (x*HACK_RESOLUTION_X)/ORIG_RESOLUTION_X;
+		}
+#endif
+		return x;
+	}
+	int AdjustCoordinateY(int &y, bool invert = false) const {
+#ifdef HACK_RESOLUTION
+		if (invert) {
+			y = (y*ORIG_RESOLUTION_Y)/HACK_RESOLUTION_Y;
+		} else {
+			y = (y*HACK_RESOLUTION_Y)/ORIG_RESOLUTION_Y;
+		}
+#endif
+		return y;
+	}
+	void AdjustCoordinates(int &x, int &y, bool invert = false) const {
+		AdjustCoordinateX(x, invert);
+		AdjustCoordinateY(y, invert);
+	}
+
 	/* Setup routines */
 	/* Set the image palette -- 256 entries */
 	void SetPalette(SDL_Color *colors);
@@ -86,11 +130,15 @@ class FrameBuf : public ErrorBase {
 			case SDL_MOUSEMOTION:
 				event->motion.x -= rect.x;
 				event->motion.y -= rect.y;
+				AdjustCoordinates(event->motion.x,
+						  event->motion.y, true);
 				break;
 			case SDL_MOUSEBUTTONDOWN:
 			case SDL_MOUSEBUTTONUP:
 				event->button.x -= rect.x;
 				event->button.y -= rect.y;
+				AdjustCoordinates(event->button.x,
+						  event->button.y, true);
 				break;
 		}
 	}
@@ -109,10 +157,12 @@ class FrameBuf : public ErrorBase {
 
 	/* Information routines */
 	int Width() const {
-		return rect.w;
+		int w = rect.w;
+		return AdjustCoordinateX(w, true);
 	}
 	int Height() const {
-		return rect.h;
+		int h = rect.h;
+		return AdjustCoordinateY(h, true);
 	}
 
 	/* Blit and update routines */
@@ -140,6 +190,9 @@ class FrameBuf : public ErrorBase {
 
 	/* Drawing routines */
 	void Clear(int x, int y, int w, int h) {
+		AdjustCoordinates(x, y);
+		AdjustCoordinates(w, h);
+
 		FillRect(x, y, w, h, 0);
 	}
 	void Clear(void) {
@@ -147,16 +200,24 @@ class FrameBuf : public ErrorBase {
 		SDL_RenderClear(renderer);
 	}
 	void DrawPoint(int x, int y, Uint32 color) {
+		AdjustCoordinates(x, y);
+
 		UpdateDrawColor(color);
 		SDL_RenderDrawPoint(renderer, x, y);
 	}
 	void DrawLine(int x1, int y1, int x2, int y2, Uint32 color) {
+		AdjustCoordinates(x1, y1);
+		AdjustCoordinates(x2, y2);
+
 		UpdateDrawColor(color);
 		SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
 	}
 	void DrawRect(int x1, int y1, int w, int h, Uint32 color) {
 		UpdateDrawColor(color);
 
+		AdjustCoordinates(x1, y1);
+		AdjustCoordinates(w, h);
+
 		SDL_Rect rect;
 		rect.x = x1;
 		rect.y = y1;
@@ -167,6 +228,9 @@ class FrameBuf : public ErrorBase {
 	void FillRect(int x1, int y1, int w, int h, Uint32 color) {
 		UpdateDrawColor(color);
 
+		AdjustCoordinates(x1, y1);
+		AdjustCoordinates(w, h);
+
 		SDL_Rect rect;
 		rect.x = x1;
 		rect.y = y1;