[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Patch to make Jigzo work with any resolution and any screen ratio



Hi,

I've made a patch to make Jigzo work properly with any resolution and
any screen ratio
It also modifies the code to start in 800x600 windowed mode.
Resolution can be selected now through command line options

http://www.resorama.com/jigzo/
http://www.iua.upf.es/~mdeboer/resorama/jigzo/

Greetings,
Miry
Patch to make Jigzo work properly with any resolution and any screen ratio
It also modifies the code to start in 800x600 windowed mode
Resolution can be selected now through command line options

Copyright (C) 2008, Miriam Ruiz <little_miry@yahoo.es>

This patch is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

diff -ruN jigzo-0.6.1.old/src/main.cxx jigzo-0.6.1/src/main.cxx
--- jigzo-0.6.1.old/src/main.cxx	2008-05-09 00:39:02.000000000 +0200
+++ jigzo-0.6.1/src/main.cxx	2008-12-12 02:04:19.000000000 +0100
@@ -33,6 +33,11 @@
 float BG_G = float(0x00)/255.;
 float BG_B = float(0x00)/255.;
 
+int screen_width = 800;
+int screen_height = 600;
+int glw = 0;
+int glh = 0;
+
 bool rotateEnabled = false;
 bool soundEnabled = false;
 bool soundFailed = false;
@@ -161,7 +166,7 @@
 
 Sprite *chars[128];
 
-int mouseX = 0,mouseY = 0;
+int mouseX = 0, mouseY = 0;
 
 class PuzzlePieceSprite **grid = 0;
 int ncolumns = 0;
@@ -572,7 +577,7 @@
 											rgba.Height()-offsetY-leaveRGBA.Height(),
 											leaveRGBA.Width(),
 											leaveRGBA.Height()));
-		leave->Move(Point(1024-4-leave->GetRect().w,768-leave->GetRect().h));
+		leave->Move(Point(glw-4-leave->GetRect().w,glh-leave->GetRect().h));
 		offsetX += leaveRGBA.Width();
 	}
 	if (nFolders)
@@ -718,10 +723,10 @@
 		jpgLoader.Load(puzzlefile.ThumbJpg(),rgba,x,y);
 		preview->CreateTextureMap(texture, Rect(x,y,jpgLoader.width,jpgLoader.height));
 		preview->pos = Point(
-								x+(256-preview->GetRect().w)/2,
-								y+(240-preview->GetRect().h)/2);
+			x + (256-preview->GetRect().w)/2 + glw/2 - 512,
+			y + (240-preview->GetRect().h)/2 + glh/2 - 384);
 		x += 256;
-		if (x==1024)
+		if (x>=1024)
 		{
 			x = 0;
 			y += 240;
@@ -969,13 +974,23 @@
 	nextGroup = 0;
 	for (int i = 0; i < n; i++)
 		v[i] = i;
+	float cx = 0.f;
+	float cy = 0.f;
+	int cn = 0;
 	for (it = puzzlePieces.begin(); it != puzzlePieces.end(); it++) {
 		int r = rand() % n;
 		int i = v[r];
 		v[r] = v[--n];
-		(*it)->pos = Point(4 + grid[i]->tx + grid[i]->tx / 5,
-								 4 + grid[i]->ty + grid[i]->ty / 5);
+		(*it)->pos = Point(4 + grid[i]->tx + grid[i]->tx / 5 ,
+			4 + grid[i]->ty + grid[i]->ty / 5);
 		(*it)->group = NextGroup();
+		Rect cr = (*it)->GetRect();
+		cx += cr.x + cr.w / 2;
+		cy += cr.y + cr.h / 2;
+		cn ++;
+	}
+	for (it = puzzlePieces.begin(); it != puzzlePieces.end(); it++) {
+		(*it)->pos += Point( glw/2 - cx/cn, glh/2 - cy/cn );
 	}
 
 	drawFoto = 0;
@@ -1004,7 +1019,7 @@
 	}
 	glDisable(GL_TEXTURE_2D);
 	glColor4f(BG_R,BG_G,BG_B,fade);
-	glRectf(0,0,1024,768);
+	glRectf(0,0,glw,glh);
 }
 
 void Display2(void)
@@ -1093,7 +1108,7 @@
 				ff = ff*ff;
 				glColor4f(1,1,1,ff);
 				PuzzlePieceSprite *pp = *it;
-				pp->Move(Point(1024 / 2 + pp->tx - INTROIMGW/3,
+				pp->Move(Point(glw / 2 + pp->tx - INTROIMGW/3,
 									80 + pp->ty 
 				));
 				(*it)->Draw();
@@ -1118,17 +1133,17 @@
 		}
 
 		glColor3f(0.9, 1, 1);
-		DrawString(1024 / 2, 360, "Version 0.6.1", 80.f/256.f);
+		DrawString(glw / 2, 360, "Version 0.6.1", 80.f/256.f);
 		glColor3f(1, 0.8, 0.2);
-		DrawString(1024 / 2, 398, "http://www.resorama.com/jigzo/";, 80.f/256.f);
+		DrawString(glw / 2, 398, "http://www.resorama.com/jigzo/";, 80.f/256.f);
 		glColor3f(0.9, 1, 1);
-		DrawString(1024 / 2, 450, "Options:", 92.f/256.f);
+		DrawString(glw / 2, 450, "Options:", 92.f/256.f);
 		char tmp[256];
 		glColor3f(0.5, 0.5, 1);
 		sprintf(tmp,"Rotating pieces: %s",rotateEnabled ? " ON" : "OFF");
-		rotateOptionRect = DrawString(1024 / 2, 489, tmp, 80.f/256.f);
+		rotateOptionRect = DrawString(glw / 2, 489, tmp, 80.f/256.f);
 		glColor3f(0.7, 0.7, 0.8);
-		DrawString(1024 / 2, 528, "(Hold Ctrl to rotate)", 80.f/256.f);
+		DrawString(glw / 2, 528, "(Hold Ctrl to rotate)", 80.f/256.f);
 		glColor3f(0.5, 0.5, 1);
 #ifdef ENABLE_SOUND
 		if (soundFailed)
@@ -1140,16 +1155,16 @@
 #else
 		sprintf(tmp,"Sound support not available");
 #endif
-		soundOptionRect = DrawString(1024 / 2, 570, tmp, 80.f/256.f);
+		soundOptionRect = DrawString(glw / 2, 570, tmp, 80.f/256.f);
 		sprintf(tmp,"Connection tolerance: %s",
 				toleranceString[tolerance]);
-		toleranceOptionRect = DrawString(1024 / 2, 613, tmp, 80.f/256.f);
+		toleranceOptionRect = DrawString(glw / 2, 613, tmp, 80.f/256.f);
 		glColor3f(1, 0.8, 0.2);
-		DrawString(1024 / 2, 680, "Press 'Esc' to quit", 92.f/256.f);
+		DrawString(glw / 2, 680, "Press 'Esc' to quit", 92.f/256.f);
 		glColor3f(0.9, 1, 1);
-		DrawString(1024 / 2, 720, "SPACE brings bottom-piece to front",80.f/256.f);
+		DrawString(glw / 2, 720, "SPACE brings bottom-piece to front",80.f/256.f);
 		glColor3f(1, 0.8, 0.2);
-		DrawString(1024 / 2, 770, "Click or press key to continue", 92.f/256.f);
+		DrawString(glw / 2, 770, "Click or press key to continue", 92.f/256.f);
 		glColor3f(1, 1, 1);
 		leave->Draw();
 		arrow->Draw();
@@ -1231,8 +1246,8 @@
 
 void MouseMove(int x, int y, bool modifier)
 {
-	mouseX = x;
-	mouseY = y;
+	mouseX = x * glw / screen_width;
+	mouseY = y * glh / screen_height;
 	if (arrow)
 		arrow->Move(Point(mouseX, mouseY));
 	if (mode == intro) {
@@ -1463,12 +1478,14 @@
 	printf("http://www.resorama.com/jigzo/\n\n";);
 	printf
 	("Copyright (C) 2005-2008   Maarten de Boer <maarten@resorama.com>\n\n");
-	printf("Usage: jigzo [-h | -w]\n\n");
-	printf("  -h   show this usage info\n");
-	printf("  -w   window mode (default is fullscreen)\n");
+	printf("Usage: jigzo [options]\n\n");
+	printf("  -h                   show this usage info\n");
+	printf("  -f                   fullscreen mode\n");
+	printf("  -w                   window mode (default)\n");
+	printf("  -s <width>x<height>  screen size (default: 800x600)\n");
 	printf("\n");
 	printf
-	("jigzo requires a OpenGL hardware accelaration and runs at 1024x768 only\n\n");
+	("jigzo requires a OpenGL hardware accelaration\n\n");
 #ifndef ENABLE_SOUND
 	printf("Sound support disabled at compilation\n\n");
 #endif
@@ -1482,7 +1499,7 @@
 	time(&t);
 	srand(t);
 	try {
-		bool fullscreen = true;
+		bool fullscreen = false;
 		mode = start_intro;
 
 		string argv0(argv[0]);
@@ -1501,23 +1518,51 @@
 
 
 		if (argc > 1) {
-			if (argc > 2)
-				usage();
-			if (string(argv[1]) == "-h")
-				usage();
-			if (string(argv[1]) == "-w")
-				fullscreen = false;
+			for (int i = 1; i < argc ; i++) {
+				if (string(argv[i]) == "-h") {
+					usage();
+				}
+				if (string(argv[i]) == "-f") {
+					fullscreen = true;
+					continue;
+				}
+				if (string(argv[i]) == "-w") {
+					fullscreen = false;
+					continue;
+				}
+				if (string(argv[i]) == "-s") {
+					i++;
+					if (i >= argc)
+						usage();
+					if (sscanf(argv[i], "%dx%d", &screen_width, &screen_height) != 2)
+						usage();
+					if (screen_width < 100 || screen_height < 80)
+						usage();
+					continue;
+				}
+			}
 		}
 
+		int gl_width = 1024;
+		int gl_height = 768;
+
 		// todo: for non 4/3 resolution, the contents should be
 		// repositioned
-		int w = 1024;
-		int h = 768;
+		int w = screen_width;
+		int h = screen_height;
 		float ar = float(w)/float(h);
-		float glhf = sqrt(1024.f*768.f/ar);
+		float glhf = sqrt(float(gl_width)*float(gl_height)/ar);
 		float glwf = glhf*ar;
-		int glw = int(glwf+0.5f);
-		int glh = int(glhf+0.5f);
+		if (float(gl_width) > float(gl_height)/ar)
+		{
+			glhf = float(gl_height);
+			glwf = glhf*ar;
+		} else {
+			glwf = float(gl_width);
+			glhf = glhf/ar;
+		}
+		glw = int(glwf+0.5f);
+		glh = int(glhf+0.5f);
 		INTERPOLATION = GL_LINEAR;
 		//if (w==glw && h==glh) INTERPOLATION = GL_NEAREST;
 		//else INTERPOLATION = GL_LINEAR;

Reply to: