> Can you do this by shifting instead, since that is what we really do.
> We just removes the lower 8 bits.
> 
>                 col.r = xcol.red >> 8;

Never, ever use shift on portable code without thinking REALLY hard about 
what you're doing. What about big/little endian machines?

Anyway, the two approaches achieve the same goal and my way will work 
on all machines.

> btw. I think you still need the static cast to avoid warnings.
> 
>                 col.r = static_cast<unsigned char>(xcol.red >> 8);

Fair enough. How about:

col.r = static_cast<unsigned char>(xcol.red / 256);

Patch attached.
Angus
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.6
diff -u -r1.6 ChangeLog
--- src/frontends/xforms/ChangeLog	2001/01/21 21:41:35	1.6
+++ src/frontends/xforms/ChangeLog	2001/01/23 13:11:41
@@ -1,3 +1,8 @@
+2001-01-23  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* FormPreferences.C (LoadBrowserLyX): convert unsigned short to
+	unsigned char correctly and so fix 2 bugs loading/changing colors.
+
 2001-01-21  Dekel Tsur  <[EMAIL PROTECTED]>
 
 	* FormRef.C (update): Do not update dialog_->{ref,name,type}
Index: src/frontends/xforms/FormPreferences.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormPreferences.C,v
retrieving revision 1.50
diff -u -r1.50 FormPreferences.C
--- src/frontends/xforms/FormPreferences.C	2001/01/03 17:43:28	1.50
+++ src/frontends/xforms/FormPreferences.C	2001/01/23 13:11:42
@@ -806,9 +806,9 @@
 		// Note that X stores the RGB values in the range 0 - 65535
 		// whilst we require them in the range 0 - 255.
 		RGBColor col;
-		col.r = static_cast<unsigned char>(xcol.red);
-		col.g = static_cast<unsigned char>(xcol.green);
-		col.b = static_cast<unsigned char>(xcol.blue);
+		col.r = static_cast<unsigned char>(xcol.red   / 256);
+		col.g = static_cast<unsigned char>(xcol.green / 256);
+		col.b = static_cast<unsigned char>(xcol.blue  / 256);
 
 		// Create a valid X11 name of the form "#rrggbb" and change the
 		// LColor X11name to this. Don't want to trigger a redraw,

Reply via email to