use stringtorgb and stringtoindex functions for crosshaircolor and r_menutint

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2077 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-03-11 00:35:56 +00:00
parent 3e6c4e4c34
commit 973d2830a0
6 changed files with 92 additions and 89 deletions

View File

@ -273,6 +273,79 @@ void CopyAndMarkup(conchar_t *dest, qbyte *src, int maxlength)
*dest = 0;
}
// SCR_StringToRGB: takes in "<index>" or "<r> <g> <b>" and converts to an RGB vector
void SCR_StringToRGB (char *rgbstring, float *rgb, float rgbinputscale)
{
char *t;
rgbinputscale = 1/rgbinputscale;
t = strstr(rgbstring, " ");
if (!t) // use standard coloring
{
qbyte *pal;
int i = atoi(rgbstring);
i = bound(0, i, 255);
pal = host_basepal + (i * 3);
// convert r8g8b8 to rgb floats
rgb[0] = (float)(pal[0]);
rgb[1] = (float)(pal[1]);
rgb[2] = (float)(pal[2]);
VectorScale(rgb, 1/255.0, rgb);
}
else // use RGB coloring
{
t++;
rgb[0] = atof(rgbstring);
rgb[1] = atof(t);
t = strstr(t, " "); // find last value
if (t)
rgb[2] = atof(t+1);
else
rgb[2] = 0.0;
VectorScale(rgb, rgbinputscale, rgb);
} // i contains the crosshair color
}
// SCR_StringToPalIndex: takes in "<index>" or "<r> <g> <b>" and converts to a
// Quake palette index
int SCR_StringToPalIndex (char *rgbstring, float rgbinputscale)
{
int i;
char *t;
rgbinputscale = 255/rgbinputscale;
t = strstr(rgbstring, " ");
if (t)
{
int r, g, b;
t++;
r = atof(rgbstring) * rgbinputscale;
g = atof(t) * rgbinputscale;
t = strstr(t, " ");
if (t)
b = atof(t) * rgbinputscale;
else
b = 0;
r = bound(0, r, 255);
g = bound(0, g, 255);
b = bound(0, b, 255);
i = GetPalette(r, g, b);
}
else
{
i = atoi(rgbstring);
i = bound(0, i, 255);
}
return i;
}
/*
==============
SCR_CenterPrint

View File

@ -1008,6 +1008,8 @@ void Editor_Draw(void);
void Editor_Init(void);
#endif
void SCR_StringToRGB (char *rgbstring, float *rgb, float rgbinputscale);
int SCR_StringToPalIndex (char *rgbstring, float rgbinputscale);
void CL_AddVWeapModel(entity_t *player, int model);

View File

@ -258,7 +258,6 @@ void COM_CleanUpPath(char *str);
char *VARGS va(char *format, ...);
// does a varargs printf into a temp buffer
//============================================================================
extern qboolean com_file_copyprotected;

View File

@ -1357,7 +1357,7 @@ void GLDraw_Crosshair(void)
float x1, x2, y1, y2;
float size, chc;
int c2, c, i, usecolor;
int c2, c, usecolor;
int chrebuild;
usecolor = 0;
@ -1381,39 +1381,18 @@ void GLDraw_Crosshair(void)
if (chrebuild)
{
char *t;
SCR_StringToRGB(crosshaircolor.string, chcolor, 255);
t = strstr(crosshaircolor.string, " ");
if (!t) // use standard coloring
{
c = d_8to24rgbtable[(qbyte) crosshaircolor.value];
// convert r8g8b8 to rgb floats
chcolor[0] = c & 0xff;
chcolor[1] = (c & 0xff00) << 8;
chcolor[2] = (c & 0xff0000) << 16;
}
else // use RGB coloring
{
t++;
// abusing the fact that atof considers whitespace to be a delimiter...
i = chcolor[0] = crosshaircolor.value;
i = bound(0, i, 255);
c = i; // red channel (first 8 bits)
i = chcolor[1] = atof(t);
i = bound(0, i, 255);
c |= (i << 8); // green channel
t = strstr(t, " "); // find last value
if (t)
{
i = chcolor[2] = atof(t+1);
i = bound(0, i, 255);
c |= (i << 16); // blue channel
}
c |= 0xff000000; // alpha channel (always full)
} // i contains the crosshair color
chcolor[0] = bound(0, chcolor[0], 1);
chcolor[1] = bound(0, chcolor[1], 1);
chcolor[2] = bound(0, chcolor[2], 1);
c = (int)(chcolor[0] * 255) | // red
((int)(chcolor[1] * 255) << 8) | // green
((int)(chcolor[2] * 255) << 16) | // blue
0xff000000; // alpha
c2 = c;
VectorScale(chcolor, 1/255.0, chcolor); // scale 0-255 to 0-1 range
chmodified = crosshaircolor.modified;
}
@ -2038,25 +2017,11 @@ void GLDraw_FadeScreen (void)
if (fademodified != r_menutint.modified)
{
char *t;
// parse r_menutint and clear defaults
fadecolor[0] = r_menutint.value;
fadecolor[1] = 0;
fadecolor[2] = 0;
faderender = GL_DST_COLOR;
t = strstr(r_menutint.string, " ");
if (t)
{
fadecolor[1] = atof(t+1);
t = strstr(t+1, " ");
if (t)
fadecolor[2] = atof(t+1);
else
faderender = 0;
}
if (r_menutint.string[0])
SCR_StringToRGB(r_menutint.string, fadecolor, 1);
else
faderender = 0;

View File

@ -416,25 +416,14 @@ palremap_t *D_GetPaletteRemap(int red, int green, int blue, qboolean desaturate,
palremap_t *RebuildMenuTint(void)
{
char *t;
int r, g, b;
vec3_t rgb;
r = 255*r_menutint.value;
g = 0;
b = 0;
t = strstr(r_menutint.string, " ");
if (t)
{
g = 255*atof(t+1);
t = strstr(t+1, " ");
if (t)
b = 255*atof(t+1);
else
return NULL;
}
if (r_menutint.string[0])
SCR_StringToRGB(r_menutint.string, rgb, 1);
else
return NULL;
return D_GetPaletteRemap(r, g, b, true, true, TOP_DEFAULT, BOTTOM_DEFAULT);
return D_GetPaletteRemap(rgb[0]*255, rgb[1]*255, rgb[2]*255, true, true, TOP_DEFAULT, BOTTOM_DEFAULT);
}
void D_DereferenceRemap(palremap_t *palremap)

View File

@ -921,32 +921,7 @@ void SWDraw_Crosshair(void)
if (crosshaircolor.modified)
{ // redo color every modification to crosshaircolor
char *t;
t = strstr(crosshaircolor.string, " ");
if (!t) // use standard coloring
sw_crosshaircolor = (qbyte) crosshaircolor.value;
else // use RGB coloring
{
int rc,gc,bc;
t++;
// abusing the fact that atof considers whitespace to be a delimiter...
rc = (int)crosshaircolor.value;
rc = bound(0, rc, 255);
gc = atoi(t);
gc = bound(0, gc, 255);
t = strstr(t, " "); // find last value
if (t)
{
bc = atoi(t+1);
bc = bound(0, bc, 255);
}
else
bc = 0;
sw_crosshaircolor = GetPalette(rc,gc,bc);
}
sw_crosshaircolor = SCR_StringToPalIndex(crosshaircolor.string, 255);
crosshaircolor.modified = false;
}