1
0
Fork 0
forked from fte/fteqw

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; *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 SCR_CenterPrint

View file

@ -1008,6 +1008,8 @@ void Editor_Draw(void);
void Editor_Init(void); void Editor_Init(void);
#endif #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); void CL_AddVWeapModel(entity_t *player, int model);

View file

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

View file

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

View file

@ -416,25 +416,14 @@ palremap_t *D_GetPaletteRemap(int red, int green, int blue, qboolean desaturate,
palremap_t *RebuildMenuTint(void) palremap_t *RebuildMenuTint(void)
{ {
char *t; char *t;
int r, g, b; vec3_t rgb;
r = 255*r_menutint.value; if (r_menutint.string[0])
g = 0; SCR_StringToRGB(r_menutint.string, rgb, 1);
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;
}
else else
return NULL; 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) void D_DereferenceRemap(palremap_t *palremap)

View file

@ -921,32 +921,7 @@ void SWDraw_Crosshair(void)
if (crosshaircolor.modified) if (crosshaircolor.modified)
{ // redo color every modification to crosshaircolor { // redo color every modification to crosshaircolor
char *t; sw_crosshaircolor = SCR_StringToPalIndex(crosshaircolor.string, 255);
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);
}
crosshaircolor.modified = false; crosshaircolor.modified = false;
} }