changeset 1074:936da0056ed3

Save/restore system palette when application topped/untopped
author Patrice Mandin <patmandin@gmail.com>
date Tue, 07 Jun 2005 11:52:46 +0000
parents 6d3c1134cd19
children 1f5ef94e8bef
files src/video/gem/SDL_gemevents.c src/video/gem/SDL_gemvideo.c src/video/gem/SDL_gemvideo.h
diffstat 3 files changed, 35 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/gem/SDL_gemevents.c	Mon Jun 06 21:50:26 2005 +0000
+++ b/src/video/gem/SDL_gemevents.c	Tue Jun 07 11:52:46 2005 +0000
@@ -245,6 +245,9 @@
 		case WM_TOPPED:
 			wind_set(message[3],WF_TOP,message[4],0,0,0);
 			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
+			if (VDI_setpalette) {
+				VDI_setpalette(this, VDI_curpalette);
+			}
 			break;
 		case WM_REDRAW:
 			if (!GEM_lock_redraw) {
@@ -307,6 +310,9 @@
 		case WM_BOTTOMED:
 		case WM_UNTOPPED:
 			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
+			if (VDI_setpalette) {
+				VDI_setpalette(this, VDI_oldpalette);
+			}
 			break;
 	}
 	
--- a/src/video/gem/SDL_gemvideo.c	Mon Jun 06 21:50:26 2005 +0000
+++ b/src/video/gem/SDL_gemvideo.c	Tue Jun 07 11:52:46 2005 +0000
@@ -106,6 +106,7 @@
 static void GEM_FreeBuffers(_THIS);
 static void GEM_ClearScreen(_THIS);
 static void GEM_ClearRect(_THIS, short *rect);
+static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]);
 static void GEM_LockScreen(_THIS);
 static void GEM_UnlockScreen(_THIS);
 static void refresh_window(_THIS, int winhandle, short *rect);
@@ -396,6 +397,8 @@
 		VDI_oldpalette[i][1] = rgb[1];
 		VDI_oldpalette[i][2] = rgb[2];
 	}
+	VDI_setpalette = GEM_SetNewPalette;
+	memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette));
 
 	/* Setup screen info */
 	GEM_title_name = empty_name;
@@ -520,6 +523,23 @@
 	v_show_c(VDI_handle, 1);
 }
 
+static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3])
+{
+	int i;
+	short rgb[3];
+
+	if (VDI_oldnumcolors==0)
+		return;
+
+	for(i = 0; i < VDI_oldnumcolors; i++) {
+		rgb[0] = newpal[i][0];
+		rgb[1] = newpal[i][1];
+		rgb[2] = newpal[i][2];
+
+		vs_color(VDI_handle, i, rgb);
+	}
+}
+
 static void GEM_LockScreen(_THIS)
 {
 	if (!GEM_locked) {
@@ -1048,9 +1068,9 @@
 		g = colors[i].g;
 		b = colors[i].b;
 
-		rgb[0] = (1000 * r) / 255;
-		rgb[1] = (1000 * g) / 255;
-		rgb[2] = (1000 * b) / 255;
+		rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255;
+		rgb[1] = VDI_curpalette[i][1] =(1000 * g) / 255;
+		rgb[2] = VDI_curpalette[i][2] =(1000 * b) / 255;
 
 		vs_color(VDI_handle, vdi_index[firstcolor+i], rgb);
 	}
@@ -1101,20 +1121,7 @@
 
 	appl_exit();
 
-	/* Restore palette */
-	if (VDI_oldnumcolors) {
-		int i;
-
-		for(i = 0; i < VDI_oldnumcolors; i++) {
-			short	rgb[3];
-
-			rgb[0] = VDI_oldpalette[i][0];
-			rgb[1] = VDI_oldpalette[i][1];
-			rgb[2] = VDI_oldpalette[i][2];
-
-			vs_color(VDI_handle, i, rgb);
-		}
-	}
+	GEM_SetNewPalette(this, VDI_oldpalette);
 
 	/* Close VDI workstation */
 	if (VDI_handle) {
--- a/src/video/gem/SDL_gemvideo.h	Mon Jun 06 21:50:26 2005 +0000
+++ b/src/video/gem/SDL_gemvideo.h	Tue Jun 07 11:52:46 2005 +0000
@@ -65,6 +65,9 @@
 	short	blit_coords[8];		/* Coordinates for bitblt */
 	MFDB	src_mfdb, dst_mfdb;	/* VDI MFDB for bitblt */
 	Uint16 old_palette[256][3];	/* Saved current palette */
+	Uint16 cur_palette[256][3];	/* SDL application palette */
+								/* Function to set/restore palette */
+	void (*setpalette)(_THIS, Uint16 newpal[256][3]);
 
 	/* GEM infos */
 	short desk_x, desk_y;		/* Desktop properties */
@@ -96,6 +99,8 @@
 #define VDI_pixelsize		(this->hidden->pixelsize)
 #define VDI_oldnumcolors	(this->hidden->old_numcolors)
 #define VDI_oldpalette		(this->hidden->old_palette)
+#define VDI_curpalette		(this->hidden->cur_palette)
+#define VDI_setpalette		(this->hidden->setpalette)
 #define VDI_pitch			(this->hidden->pitch)
 #define VDI_format			(this->hidden->format)
 #define VDI_screen			(this->hidden->screen)