Exemplo n.º 1
0
SEXP do_hsv(SEXP call, SEXP op, SEXP args, SEXP env)
{
    SEXP c, h, s, v, gm, a;
    double hh, ss, vv, gg, aa, r, g, b;
    int i, max, nh, ns, nv, ng, na;

    checkArity(op, args);

    PROTECT(h = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(s = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(v = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(gm = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(a = coerceVector(CAR(args),REALSXP)); args = CDR(args);

    nh = LENGTH(h);
    ns = LENGTH(s);
    nv = LENGTH(v);
    ng = LENGTH(gm);
    na = LENGTH(a);
    if (nh <= 0 || ns <= 0 || nv <= 0 || ng <= 0 || na <= 0) {
	UNPROTECT(5);
	return(allocVector(STRSXP, 0));
    }
    max = nh;
    if (max < ns) max = ns;
    if (max < nv) max = nv;
    if (max < ng) max = ng;
    if (max < na) max = na;
    PROTECT(c = allocVector(STRSXP, max));
    if(max == 0) return(c);

    for (i = 0; i < max; i++) {
	hh = REAL(h)[i % nh];
	ss = REAL(s)[i % ns];
	vv = REAL(v)[i % nv];
	gg = REAL(gm)[i % ng];
	aa = REAL(a)[i % na];
	if (hh < 0 || hh > 1 || ss < 0 || ss > 1 || vv < 0 || vv > 1 ||
	    aa < 0 || aa > 1)
	    errorcall(call, _("invalid HSV color"));
	hsv2rgb(hh, ss, vv, &r, &g, &b);
	r = pow(r, gg);
	g = pow(g, gg);
	b = pow(b, gg);
	SET_STRING_ELT(c, i, mkChar(RGBA2rgb(ScaleColor(r),
					     ScaleColor(g),
					     ScaleColor(b),
					     ScaleAlpha(aa))));
    }
    UNPROTECT(6);
    return c;
}
Exemplo n.º 2
0
/**
 * Applies the fixed point multiplier 'mult' to all colors in
 * 'pOrig' to produce 'pNew'. Each color in the palette will be
 * multiplied by 'mult'.
 * @param pNew				Pointer to new palette
 * @param pOrig				Pointer to original palette
 * @param numColors		Number of colors in the above palettes
 * @param mult				Fixed point multiplier
 */
static void FadePalette(COLORREF *pNew, COLORREF *pOrig, int numColors, uint32 mult) {
	for (int i = 0; i < numColors; i++, pNew++, pOrig++) {
		if (!TinselV2)
			// apply multiplier to RGB components
			*pNew = ScaleColor(*pOrig, mult);
		else if (i == (TalkColor() - 1)) {
			*pNew = GetTalkColorRef();
			*pNew = ScaleColor(*pNew, mult);
		} else if (SysVar(SV_TAGCOLOR) && i == (SysVar(SV_TAGCOLOR) - 1)) {
			*pNew = GetTagColorRef();
			*pNew = ScaleColor(*pNew, mult);
		} else {
			*pNew = ScaleColor(*pOrig, mult);
		}
	}
}
Exemplo n.º 3
0
SEXP attribute_hidden do_hsv(SEXP call, SEXP op, SEXP args, SEXP env)
{
    SEXP c, h, s, v, a;
    double hh, ss, vv, aa, r=0., g=0., b=0.; /* -Wall */
    int i, max, nh, ns, nv, na;

    checkArity(op, args);

    PROTECT(h = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(s = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(v = coerceVector(CAR(args),REALSXP)); args = CDR(args);
    PROTECT(a = coerceVector(CAR(args),REALSXP)); args = CDR(args);

    nh = LENGTH(h);
    ns = LENGTH(s);
    nv = LENGTH(v);
    na = LENGTH(a);
    if (nh <= 0 || ns <= 0 || nv <= 0 || na <= 0) {
	UNPROTECT(4);
	return(allocVector(STRSXP, 0));
    }
    max = nh;
    if (max < ns) max = ns;
    if (max < nv) max = nv;
    if (max < na) max = na;
    PROTECT(c = allocVector(STRSXP, max));
    if(max == 0) return(c);

    for (i = 0; i < max; i++) {
	hh = REAL(h)[i % nh];
	ss = REAL(s)[i % ns];
	vv = REAL(v)[i % nv];
	aa = REAL(a)[i % na];
	if (hh < 0 || hh > 1 || ss < 0 || ss > 1 || vv < 0 || vv > 1 ||
	    aa < 0 || aa > 1)
	    error(_("invalid hsv color"));
	hsv2rgb(hh, ss, vv, &r, &g, &b);
	SET_STRING_ELT(c, i, mkChar(RGBA2rgb(ScaleColor(r),
					     ScaleColor(g),
					     ScaleColor(b),
					     ScaleAlpha(aa))));
    }
    UNPROTECT(5);
    return c;
}
Exemplo n.º 4
0
void CMiniMap::RebuildTerrainTexture()
{
	u32 x = 0;
	u32 y = 0;
	u32 w = m_MapSize - 1;
	u32 h = m_MapSize - 1;
	float waterHeight = g_Renderer.GetWaterManager()->m_WaterHeight;

	m_TerrainDirty = false;

	for(u32 j = 0; j < h; j++)
	{
		u32 *dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
		for(u32 i = 0; i < w; i++)
		{
			float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j)
					+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j)
					+ m_Terrain->GetVertexGroundLevel((int)i, (int)j+1)
					+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j+1)
				) / 4.0f;

			if(avgHeight < waterHeight)
			{
				*dataPtr++ = 0xff304080;		// TODO: perhaps use the renderer's water color?
			}
			else
			{
				int hmap = ((int)m_Terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8;
				int val = (hmap / 3) + 170;

				u32 color = 0xFFFFFFFF;

				CMiniPatch *mp = m_Terrain->GetTile(x + i, y + j);
				if(mp)
				{
					CTerrainTextureEntry *tex = mp->GetTextureEntry();
					if(tex)
					{
						// If the texture can't be loaded yet, set the dirty flags
						// so we'll try regenerating the terrain texture again soon
						if(!tex->GetTexture()->TryLoad())
							m_TerrainDirty = true;

						color = tex->GetBaseColor();
					}
				}

				*dataPtr++ = ScaleColor(color, float(val) / 255.0f);
			}
		}
	}

	// Upload the texture
	g_Renderer.BindTexture(0, m_TerrainTexture);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, m_TerrainData);
}
Exemplo n.º 5
0
/*inline*/
void SetTMapColor (tUVL *uvlList, int i, CBitmap *bmP, int bResetColor, tFaceColor *vertColor)
{
	float l = (bmP->Flags () & BM_FLAG_NO_LIGHTING) ? 1.0f : X2F (uvlList->l);
	float s = 1.0f;

#if SHADOWS
if (gameStates.ogl.bScaleLight)
	s *= gameStates.render.bHeadlightOn ? 0.4f : 0.3f;
#endif
if (gameStates.app.bEndLevelSequence >= EL_OUTSIDE)
	OglColor4sf (l, l, l, s);
else if (vertColor) {
	if (tMapColor.index) {
		ScaleColor (&tMapColor, l);
		vertColor->color = tMapColor.color;
		if (l >= 0)
			tMapColor.color.red =
			tMapColor.color.green =
			tMapColor.color.blue = 1.0;
		}
	else if (i >= (int) (sizeof (vertColors) / sizeof (tFaceColor)))
		return;
	else if (vertColors [i].index) {
			tFaceColor *pvc = vertColors + i;

		vertColor->color = vertColors [i].color;
		if (bResetColor) {
			pvc->color.red =
			pvc->color.green =
			pvc->color.blue = 1.0;
			pvc->index = 0;
			}
		}
	else {
		vertColor->color.red =
		vertColor->color.green =
		vertColor->color.blue = l;
		}
	vertColor->color.alpha = s;
	}
else {
	if (tMapColor.index) {
		ScaleColor (&tMapColor, l);
		OglColor4sf (tMapColor.color.red, tMapColor.color.green, tMapColor.color.blue, s);
		if (l >= 0)
			tMapColor.color.red =
			tMapColor.color.green =
			tMapColor.color.blue = 1.0;
		}
	else if (i >= (int) (sizeof (vertColors) / sizeof (tFaceColor)))
		return;
	else if (vertColors [i].index) {
			tFaceColor *pvc = vertColors + i;

		OglColor4sf (pvc->color.red, pvc->color.green, pvc->color.blue, s);
		if (bResetColor) {
			pvc->color.red =
			pvc->color.green =
			pvc->color.blue = 1.0;
			pvc->index = 0;
			}
		}
	else {
		OglColor4sf (l, l, l, s);
		}
	}
}
Exemplo n.º 6
0
fix SetVertexLight (int nSegment, int nSide, int nVertex, tFaceColor *colorP, fix light)
{
	tRgbColorf	*pdc;
	fix			dynLight;
	float			fl, dl, hl;

//the tUVL struct has static light already in it
//scale static light for destruction effect
if (EGI_FLAG (bDarkness, 0, 0, 0))
	light = 0;
else {
#if LMAP_LIGHTADJUST
	if (USE_LIGHTMAPS) {
		else {
			light = I2X (1) / 2 + gameData.render.lights.segDeltas [nSegment * 6 + nSide];
			if (light < 0)
				light = 0;
			}
		}
#endif
	if (gameData.reactor.bDestroyed || gameStates.gameplay.seismic.nMagnitude)	//make lights flash
		light = FixMul (gameStates.render.nFlashScale, light);
	}
//add in dynamic light (from explosions, etc.)
dynLight = gameData.render.lights.dynamicLight [nVertex];
fl = X2F (light);
dl = X2F (dynLight);
light += dynLight;
#if DBG
if (nVertex == nDbgVertex)
	nVertex = nVertex;
#endif
if (gameStates.app.bHaveExtraGameInfo [IsMultiGame]) {
	if (gameData.render.lights.bGotDynColor [nVertex]) {
		pdc = gameData.render.lights.dynamicColor + nVertex;
		if (gameOpts->render.color.bMix) {
			if (gameOpts->render.color.bGunLight) {
				if (gameStates.render.bAmbientColor) {
					if ((fl != 0) && gameData.render.color.vertBright [nVertex]) {
						hl = fl / gameData.render.color.vertBright [nVertex];
						colorP->color.red = colorP->color.red * hl + pdc->red * dl;
						colorP->color.green = colorP->color.green * hl + pdc->green * dl;
						colorP->color.blue = colorP->color.blue * hl + pdc->blue * dl;
						ScaleColor (colorP, fl + dl);
						}
					else {
						colorP->color.red = pdc->red * dl;
						colorP->color.green = pdc->green * dl;
						colorP->color.blue = pdc->blue * dl;
						ScaleColor (colorP, dl);
						}
					}
				else {
					colorP->color.red = fl + pdc->red * dl;
					colorP->color.green = fl + pdc->green * dl;
					colorP->color.blue = fl + pdc->blue * dl;
					ScaleColor (colorP, fl + dl);
					}
				}
			else {
				colorP->color.red =
				colorP->color.green =
				colorP->color.blue = fl + dl;
				}
			if (gameOpts->render.color.bCap) {
				if (colorP->color.red > 1.0)
					colorP->color.red = 1.0;
				if (colorP->color.green > 1.0)
					colorP->color.green = 1.0;
				if (colorP->color.blue > 1.0)
					colorP->color.blue = 1.0;
				}
			}
		else {
			float dl = X2F (light);
			dl = (float) pow (dl, 1.0f / 3.0f);
			colorP->color.red = pdc->red * dl;
			colorP->color.green = pdc->green * dl;
			colorP->color.blue = pdc->blue * dl;
			}
		}
	else {
		ScaleColor (colorP, fl + dl);
		}
	}
else {
	ScaleColor (colorP, fl + dl);
	}
//saturate at max value
if (light > MAX_LIGHT)
	light = MAX_LIGHT;
return light;
}
Exemplo n.º 7
0
SEXP do_rgb(SEXP call, SEXP op, SEXP args, SEXP env)
{
    SEXP c, r, g, b, a, nam;
    int OP, i, l_max, nr, ng, nb, na;
    Rboolean max_1 = FALSE;
    double mV = 0.0; /* -Wall */

    checkArity(op, args);
    OP = PRIMVAL(op);
    if(OP) {/* op == 1:  rgb256() :*/
	PROTECT(r = coerceVector(CAR(args), INTSXP)); args = CDR(args);
	PROTECT(g = coerceVector(CAR(args), INTSXP)); args = CDR(args);
	PROTECT(b = coerceVector(CAR(args), INTSXP)); args = CDR(args);
	PROTECT(a = coerceVector(CAR(args), INTSXP)); args = CDR(args);
    }
    else {
	PROTECT(r = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	PROTECT(g = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	PROTECT(b = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	PROTECT(a = coerceVector(CAR(args), REALSXP)); args = CDR(args);
	mV = asReal(CAR(args));			       args = CDR(args);
	max_1 = (mV == 1.);
    }

    nr = LENGTH(r); ng = LENGTH(g); nb = LENGTH(b); na = LENGTH(a);
    if (nr <= 0 || ng <= 0 || nb <= 0 || na <= 0) {
	UNPROTECT(4);
	return(allocVector(STRSXP, 0));
    }
    l_max = nr;
    if (l_max < ng) l_max = ng;
    if (l_max < nb) l_max = nb;
    if (l_max < na) l_max = na;

    PROTECT(nam = coerceVector(CAR(args), STRSXP)); args = CDR(args);
    if (length(nam) != 0 && length(nam) != l_max)
	errorcall(call, _("invalid names vector"));
    PROTECT(c = allocVector(STRSXP, l_max));

#define _R_set_c_RGBA(_R,_G,_B,_A)				\
    for (i = 0; i < l_max; i++)				\
	SET_STRING_ELT(c, i, mkChar(RGBA2rgb(_R,_G,_B,_A)))

    if(OP) { /* OP == 1:  rgb256() :*/
	_R_set_c_RGBA(CheckColor(INTEGER(r)[i%nr]),
		      CheckColor(INTEGER(g)[i%ng]),
		      CheckColor(INTEGER(b)[i%nb]),
		      CheckAlpha(INTEGER(a)[i%na]));
    }
    else if(max_1) {
	_R_set_c_RGBA(ScaleColor(REAL(r)[i%nr]),
		      ScaleColor(REAL(g)[i%ng]),
		      ScaleColor(REAL(b)[i%nb]),
		      ScaleAlpha(REAL(a)[i%na]));
    }
    else { /* maxColorVal not in {1, 255} */
	_R_set_c_RGBA(ScaleColor(REAL(r)[i%nr] / mV),
		      ScaleColor(REAL(g)[i%ng] / mV),
		      ScaleColor(REAL(b)[i%nb] / mV),
		      ScaleAlpha(REAL(a)[i%na] / mV));
    }
    if (length(nam) != 0)
	setAttrib(c, R_NamesSymbol, nam);
    UNPROTECT(6);
    return c;
}
Exemplo n.º 8
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : int - 
//-----------------------------------------------------------------------------
int	C_GunshipFX::DrawModel( int )
{
	static color32 white = {255,255,255,255};
	Vector params[GUNSHIPFX_PARAMETERS];
	bool hasParam[GUNSHIPFX_PARAMETERS];

	if ( !m_active )
		return 1;

	C_BaseEntity *ent = cl_entitylist->GetEnt( m_entityIndex );
	if ( ent )
	{
		QAngle angles;
		ent->GetAttachment( m_attachment, m_worldPosition, angles );
	}

	Vector test;
	m_t += gpGlobals->frametime;
	if ( m_tMax > 0 )
	{
		m_t = clamp( m_t, 0, m_tMax );
		m_beamEndPosition = m_worldPosition;
	}
	float t = m_t;

	bool hasAny = false;
	memset( hasParam, 0, sizeof(hasParam) );
	for ( int i = 0; i < GUNSHIPFX_PARAMETERS; i++ )
	{
		hasParam[i] = g_GunshipCannonEnvelope.m_parameters[i].Interp( params[i], t );
		hasAny = hasAny || hasParam[i];
	}

	// draw the narrow beam
	if ( hasParam[GUNSHIPFX_NARROW_BEAM_COLOR] && hasParam[GUNSHIPFX_NARROW_BEAM_SIZE] )
	{
		IMaterial *pMat = materials->FindMaterial( "sprites/bluelaser1", TEXTURE_GROUP_CLIENT_EFFECTS );
		float width = NARROW_BEAM_WIDTH * params[GUNSHIPFX_NARROW_BEAM_SIZE].x;
		color32 color;
		float bright = params[GUNSHIPFX_NARROW_BEAM_COLOR].x;
		ScaleColor( color, white, bright );

		//Gunship_DrawLine( m_beamEndPosition, m_targetPosition, width, pMat, color );
		FX_DrawLine( m_beamEndPosition, m_targetPosition, width, pMat, color );
	}

	// glowy blue flare sprite
	if ( hasParam[GUNSHIPFX_FLARE_COLOR] && hasParam[GUNSHIPFX_FLARE_SIZE] )
	{
		IMaterial *pMat = materials->FindMaterial( "effects/blueblackflash", TEXTURE_GROUP_CLIENT_EFFECTS );
		float size = FLARE_SIZE * params[GUNSHIPFX_FLARE_SIZE].x;
		color32 color;
		float bright = params[GUNSHIPFX_FLARE_COLOR].x;
		ScaleColor( color, white, bright );
		color.a = (int)(255 * params[GUNSHIPFX_DARKNESS].x);
		materials->Bind( pMat, (IClientRenderable*)this );
		Gunship_DrawSprite( m_worldPosition, size, color, true );
	}

	if ( hasParam[GUNSHIPFX_AFTERGLOW_COLOR] )
	{
		// Muzzle effect
		dlight_t *dl = effects->CL_AllocDlight( m_entityIndex );
		dl->origin = m_worldPosition;
		dl->color.r = 40*params[GUNSHIPFX_AFTERGLOW_COLOR].x;
		dl->color.g = 60*params[GUNSHIPFX_AFTERGLOW_COLOR].x;
		dl->color.b = 255*params[GUNSHIPFX_AFTERGLOW_COLOR].x;
		dl->color.exponent = 5;
		dl->radius = 128.0f;
		dl->die = gpGlobals->curtime + 0.001;
	}

	if ( m_t >= 4.0 && !hasAny )
	{
		EffectShutdown();
	}

	return 1;
}
Exemplo n.º 9
0
int	C_StriderFX::DrawModel( int )
{
	static color32 white = {255,255,255,255};
	Vector params[STRIDERFX_PARAMETERS];
	bool hasParam[STRIDERFX_PARAMETERS];

	if ( !m_active )
		return 1;

	C_BaseEntity *ent = cl_entitylist->GetEnt( m_entityIndex );
	if ( ent )
	{
		QAngle angles;
		ent->GetAttachment( m_attachment, m_worldPosition, angles );
	}

	// This forces time to drive from the main clock instead of being integrated per-draw below
	// that way the effect moves on even when culled for visibility
	if ( m_limitHitTime > 0 && m_tMax > 0 )
	{
		float dt = m_limitHitTime - gpGlobals->curtime;
		if ( dt < 0 )
		{
			dt = 0;
		}
		// if the clock needs to move, update it.
		if ( m_tMax - dt > m_t )
		{
			m_t = m_tMax - dt;
			m_beamEndPosition = m_worldPosition;
		}
	}
	else
	{
		// don't have enough info to derive the time, integrate current frame time
		m_t += gpGlobals->frametime;
		if ( m_tMax > 0 )
		{
			m_t = clamp( m_t, 0, m_tMax );
			m_beamEndPosition = m_worldPosition;
		}
	}
	float t = m_t;

	bool hasAny = false;
	memset( hasParam, 0, sizeof(hasParam) );
	for ( int i = 0; i < STRIDERFX_PARAMETERS; i++ )
	{
		hasParam[i] = g_StriderCannonEnvelope.m_parameters[i].Interp( params[i], t );
		hasAny = hasAny || hasParam[i];
	}

	pixelvis_queryparams_t gunParams;
	gunParams.Init(m_worldPosition, 4.0f);
	float gunFractionVisible = PixelVisibility_FractionVisible( gunParams, &m_queryHandleGun );
	bool gunVisible = gunFractionVisible > 0.0f ? true : false;

	// draw the narrow beam
	if ( hasParam[STRIDERFX_NARROW_BEAM_COLOR] && hasParam[STRIDERFX_NARROW_BEAM_SIZE] )
	{
		IMaterial *pMat = materials->FindMaterial( "sprites/bluelaser1", TEXTURE_GROUP_CLIENT_EFFECTS );
		float width = NARROW_BEAM_WIDTH * params[STRIDERFX_NARROW_BEAM_SIZE].x;
		color32 color;
		float bright = params[STRIDERFX_NARROW_BEAM_COLOR].x;
		ScaleColor( color, white, bright );

		Strider_DrawLine( m_beamEndPosition, m_targetPosition, width, pMat, color );
	}

	// draw the wide beam
	if ( hasParam[STRIDERFX_WIDE_BEAM_COLOR] && hasParam[STRIDERFX_WIDE_BEAM_SIZE] )
	{
		IMaterial *pMat = materials->FindMaterial( "effects/blueblacklargebeam", TEXTURE_GROUP_CLIENT_EFFECTS );
		float width = WIDE_BEAM_WIDTH * params[STRIDERFX_WIDE_BEAM_SIZE].x;
		color32 color;
		float bright = params[STRIDERFX_WIDE_BEAM_COLOR].x;
		ScaleColor( color, white, bright );
		Vector wideBeamEnd = m_beamEndPosition;
		if ( hasParam[STRIDERFX_WIDE_BEAM_LENGTH] )
		{
			float amt = params[STRIDERFX_WIDE_BEAM_LENGTH].x;
			wideBeamEnd = m_beamEndPosition * amt + m_targetPosition * (1-amt);
		}

		Strider_DrawLine( wideBeamEnd, m_targetPosition, width, pMat, color );
	}

// after glow sprite
	bool updated = false;
	CMatRenderContextPtr pRenderContext( materials );
// warpy sprite bit
	if ( hasParam[STRIDERFX_WARP_SCALE] && !hasParam[STRIDERFX_BUBBLE_SIZE] && gunVisible )
	{
		if ( !updated )
		{
			updated = true;
			pRenderContext->Flush();
			UpdateRefractTexture();
		}

		IMaterial *pMat = materials->FindMaterial( "effects/strider_pinch_dudv", TEXTURE_GROUP_CLIENT_EFFECTS );
		float size = WARP_SIZE;
		float refract = params[STRIDERFX_WARP_SCALE].x * WARP_REFRACT * gunFractionVisible;

		pRenderContext->Bind( pMat, (IClientRenderable*)this );
		IMaterialVar *pVar = pMat->FindVar( "$refractamount", NULL );
		pVar->SetFloatValue( refract );
		Strider_DrawSprite( m_worldPosition, size, white );
	}
// darkening sprite
// glowy blue flare sprite
	if ( hasParam[STRIDERFX_FLARE_COLOR] && hasParam[STRIDERFX_FLARE_SIZE] && hasParam[STRIDERFX_DARKNESS] && gunVisible )
	{
		IMaterial *pMat = materials->FindMaterial( "effects/blueblackflash", TEXTURE_GROUP_CLIENT_EFFECTS );
		float size = FLARE_SIZE * params[STRIDERFX_FLARE_SIZE].x;
		color32 color;
		float bright = params[STRIDERFX_FLARE_COLOR].x * gunFractionVisible;
		ScaleColor( color, white, bright );
		color.a = (int)(255 * params[STRIDERFX_DARKNESS].x);
		pRenderContext->Bind( pMat, (IClientRenderable*)this );
		Strider_DrawSprite( m_worldPosition, size, color );
	}
// bubble warpy sprite
	if ( hasParam[STRIDERFX_BUBBLE_SIZE] )
	{
		Vector wideBeamEnd = m_beamEndPosition;
		if ( hasParam[STRIDERFX_WIDE_BEAM_LENGTH] )
		{
			float amt = params[STRIDERFX_WIDE_BEAM_LENGTH].x;
			wideBeamEnd = m_beamEndPosition * amt + m_targetPosition * (1-amt);
		}
		pixelvis_queryparams_t endParams;
		endParams.Init(wideBeamEnd, 4.0f, 0.001f);
		float endFractionVisible = PixelVisibility_FractionVisible( endParams, &m_queryHandleBeamEnd );
		bool endVisible = endFractionVisible > 0.0f ? true : false;

		if ( endVisible )
		{
			if ( !updated )
			{
				updated = true;
				pRenderContext->Flush();
				UpdateRefractTexture();
			}
			IMaterial *pMat = materials->FindMaterial( "effects/strider_bulge_dudv", TEXTURE_GROUP_CLIENT_EFFECTS );
			float refract = endFractionVisible * WARP_BUBBLE_REFRACT * params[STRIDERFX_BUBBLE_REFRACT].x;
			float size = WARP_BUBBLE_SIZE * params[STRIDERFX_BUBBLE_SIZE].x;
			IMaterialVar *pVar = pMat->FindVar( "$refractamount", NULL );
			pVar->SetFloatValue( refract );

			pRenderContext->Bind( pMat, (IClientRenderable*)this );
			Strider_DrawSprite( wideBeamEnd, size, white );
		}
	}
	else
	{
		// call this to have the check ready on the first frame
		pixelvis_queryparams_t endParams;
		endParams.Init(m_beamEndPosition, 4.0f, 0.001f);
		PixelVisibility_FractionVisible( endParams, &m_queryHandleBeamEnd );
	}
	if ( hasParam[STRIDERFX_AFTERGLOW_COLOR] && gunVisible )
	{
		IMaterial *pMat = materials->FindMaterial( "effects/blueblackflash", TEXTURE_GROUP_CLIENT_EFFECTS );
		float size = AFTERGLOW_SIZE;// * params[STRIDERFX_FLARE_SIZE].x;
		color32 color;
		float bright = params[STRIDERFX_AFTERGLOW_COLOR].x * gunFractionVisible;
		ScaleColor( color, white, bright );

		pRenderContext->Bind( pMat, (IClientRenderable*)this );
		Strider_DrawSprite( m_worldPosition, size, color );

		dlight_t *dl = effects->CL_AllocDlight( m_entityIndex );
		dl->origin = m_worldPosition;
		dl->color.r = 40;
		dl->color.g = 60;
		dl->color.b = 255;
		dl->color.exponent = 5;
		dl->radius = bright * 128;
		dl->die = gpGlobals->curtime + 0.001;
	}

	if ( m_t >= STRIDERFX_END_ALL_TIME && !hasAny )
	{
		EffectShutdown();
	}
	return 1;
}
Exemplo n.º 10
0
void CMiniMap::RebuildTerrainTexture()
{
	u32 x = 0;
	u32 y = 0;
	u32 w = m_MapSize - 1;
	u32 h = m_MapSize - 1;
	float waterHeight = g_Renderer.GetWaterManager()->m_WaterHeight;

	m_TerrainDirty = false;

	for (u32 j = 0; j < h; ++j)
	{
		u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
		for (u32 i = 0; i < w; ++i)
		{
			float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j)
					+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j)
					+ m_Terrain->GetVertexGroundLevel((int)i, (int)j+1)
					+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j+1)
				) / 4.0f;

			if (avgHeight < waterHeight && avgHeight > waterHeight - m_ShallowPassageHeight)
			{
				// shallow water
				*dataPtr++ = 0xffc09870;
			}
			else if (avgHeight < waterHeight)
			{
				// Set water as constant color for consistency on different maps
				*dataPtr++ = 0xffa07850;
			}
			else
			{
				int hmap = ((int)m_Terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8;
				int val = (hmap / 3) + 170;

				u32 color = 0xFFFFFFFF;

				CMiniPatch* mp = m_Terrain->GetTile(x + i, y + j);
				if (mp)
				{
					CTerrainTextureEntry* tex = mp->GetTextureEntry();
					if (tex)
					{
						// If the texture can't be loaded yet, set the dirty flags
						// so we'll try regenerating the terrain texture again soon
						if(!tex->GetTexture()->TryLoad())
							m_TerrainDirty = true;

						color = tex->GetBaseColor();
					}
				}

				*dataPtr++ = ScaleColor(color, float(val) / 255.0f);
			}
		}
	}

	// Upload the texture
	g_Renderer.BindTexture(0, m_TerrainTexture);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_RGBA, GL_UNSIGNED_BYTE, m_TerrainData);
}
Exemplo n.º 11
0
BOOL CWinMenu::DrawMenuItems(HDC hDC, LPRECT pRect)
{
	if ( hDC == NULL || pRect == NULL ) return FALSE;

	BOOL bFirst = m_bFirstDraw;
	m_bFirstDraw = FALSE;

	CText		text;
	long		x = pRect->left + 4;
	long		y = pRect->top + 4;
	long		w = pRect->right - pRect->left - 8;

	long		bx = x;
	long		by = y;

	// Set colors
	COLORREF rgbMenu, rgbMenuText, rgbSel, rgbSelText;

	if ( m_bSystemColors )
	{	rgbMenu = GetSysColor( COLOR_MENU );
		rgbMenuText = GetSysColor( COLOR_MENUTEXT );
		rgbSel = GetSysColor( COLOR_HIGHLIGHT );
		rgbSelText = GetSysColor( COLOR_HIGHLIGHTTEXT );
	} // end if
	else
	{	rgbMenu = m_rgbMenu;
		rgbMenuText = m_rgbMenuText;
		rgbSel = m_rgbSel;
		rgbSelText = m_rgbSelText;
	} // end else


	COLORREF	rgbLightPen = ScaleColor( rgbMenu, 100 );
	COLORREF	rgbDarkPen = ScaleColor( rgbMenu, -150 );

	COLORREF	rgbBck = rgbMenu;
	COLORREF	rgbBckLt = ScaleColor( rgbBck, 40 );
	COLORREF	rgbBckDk = ScaleColor( rgbBck, -40 );
	COLORREF	rgbSelLt = ScaleColor( rgbSel, 80 );
	COLORREF	rgbSelDk = ScaleColor( rgbSel, -120 );
	COLORREF	rgbSelTextLt = ScaleColor( rgbSelText, 80 );
	COLORREF	rgbSelTextDk = ScaleColor( rgbSelText, -150 );
	COLORREF	rgbBumpLt = ScaleColor( rgbBck, 120 );
	COLORREF	rgbBumpDk = ScaleColor( rgbBck, -120 );

	COLORREF	rgbText = rgbMenuText;
	COLORREF	rgbTextLt = ScaleColor( rgbBck, 100 );
	COLORREF	rgbTextDk = ScaleColor( rgbBck, -100 );

	if ( GetColorAvg( rgbSel ) > 128 )
	{	COLORREF swap = rgbSelTextLt;
		rgbSelTextLt = rgbSelTextDk; rgbSelTextDk = swap;
	} // end if


	// What font does the user want for menu's?
	NONCLIENTMETRICS info;
	info.cbSize = sizeof(info);			
	SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( info ), &info, 0 );

	// Check for empty menu	
	if ( m_mitems.Size() == 0 )
	{
		COLORREF rgbEmptyLt = ScaleColor( rgbBck, 120 );
		COLORREF rgbEmptyDk = ScaleColor( rgbBck, -120 );

		if ( GetColorAvg( rgbBck ) < 128 ) 
		{	COLORREF swap = rgbEmptyLt;
			rgbEmptyLt = rgbEmptyDk; rgbEmptyDk = swap;
		} // end if

		RECT t;
		CopyRect( &t, pRect );

		text.SetWeight( FW_BOLD );
		text.SetFont( &info.lfMenuFont );
		text.SetFlags( DT_SINGLELINE | DT_CENTER | DT_VCENTER );

		// Make text look recessed
		OffsetRect( &t, -1, -1 );
		text.SetColor( rgbEmptyDk );
		text.DrawText( hDC, EMPTY_STR, &t );

		OffsetRect( &t, 1, 1 );
		text.SetColor( rgbEmptyLt );
		text.DrawText( hDC, EMPTY_STR, &t );

	} // end if
	
	
	// This kinda bites, but we need to know how far to offset the text
	BOOL islots = 0;
	LPMITEMINFO	pmi = NULL;
	while(	islots < 2 && ( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL )
	{
		// Do we need both icon slots?
		if ( pmi->icon != NULL && pmi->b != NULL ) islots = 2;

		// Do we have one islot already?
		else if ( islots < 1 )
		{
			if ( pmi->icon != NULL ) islots = 1;
			
			else if ( pmi->b != NULL && m_hCheck == NULL && m_hUncheck == NULL )
				islots = 1;
		} // end else if

	} // end while

	
	// The icon size
	long iconsize = m_th - 4;

	// Draw each item
	pmi = NULL;
	while(	( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL &&
			x < pRect->right && y < pRect->bottom )
	{
		// Set base coords
		bx = x; by = y;

		if ( *pmi->name != NULL )
		{
			POINT	pt;
			GetCursorPos( &pt );
			ScreenToClient( &pt );

			// Is this item being selected?
			BOOL bSelected = FALSE;
			RECT hl;
			hl.left = pRect->left + 3;
			hl.right = pRect->right - 4;
			hl.top = by;
			hl.bottom = by + m_th;
//			if (	pt.x > hl.left && pt.x < hl.right &&
//					pt.y > hl.top && pt.y < hl.bottom )

			// Add for toolbar
			if ( pmi->toolbar != NULL && pmi->toolbar->GetNumButtons() )
				hl.left += pmi->toolbar->GetWidth();


			if ( pmi == m_itemover )
			{
				bSelected = TRUE;
//				HPEN whitepen = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) );
//				HPEN dkgraypen = CreatePen( PS_SOLID, 1, RGB( 50, 50, 50 ) );
				HPEN whitepen = CreatePen( PS_SOLID, 1, rgbLightPen );
				HPEN dkgraypen = CreatePen( PS_SOLID, 1, rgbDarkPen );
				HPEN oldpen = (HPEN)SelectObject( hDC, whitepen );

				// Draw white line
				MoveToEx( hDC, hl.right, hl.top, NULL );
				LineTo( hDC, hl.right, hl.bottom  );
				LineTo( hDC, hl.left, hl.bottom  );

				// Draw dark gray line
				SelectObject( hDC, dkgraypen );
				MoveToEx( hDC, hl.right, hl.top, NULL );
				LineTo( hDC, hl.left, hl.top  );
				LineTo( hDC, hl.left, hl.bottom  );

				SelectObject( hDC, oldpen );
				DeleteObject( whitepen );
				DeleteObject( dkgraypen );

//				InflateRect( &hl, -1, -1 );
				hl.left += 1;
				hl.top += 1;

//				GradientFill( hDC, &hl, RGB( 170, 170, 190 ), RGB( 110, 110, 110 ) );
				CGrDC::VertGradientFill( hDC, &hl, rgbSelLt, rgbSelDk );
/*				HBRUSH brush = CreateSolidBrush( RGB( 120, 120, 120 ) );
				FillRect( hDC, &hl, brush );
				DeleteObject( brush );
*/

			} // end if

			// Draw toolbar
			if ( pmi->toolbar != NULL && pmi->toolbar->GetNumButtons() )
			{	pmi->toolbar->SetHeight( m_th );

				RECT tbar;
				SetRect( &tbar, bx, by, bx + pmi->toolbar->GetWidth(), 
									by + pmi->toolbar->GetHeight() );

				if ( bFirst ) pmi->toolbar->CreateToolTips( GetSafeHwnd(), &tbar );
				pmi->toolbar->SetMessageTarget( GetSafeHwnd(), WM_MENUCMD );
				pmi->toolbar->Draw( GetSafeHwnd(), hDC, &tbar );
			
				bx += pmi->toolbar->GetWidth();
			} // end if

			RECT t;

			// Calc text box
			t.left = bx + 4;
			t.left += islots * iconsize;
			t.right = pRect->right;
			t.top = by;
			t.bottom = by + m_th;

			// Draw Check
			if ( pmi->b != NULL )
			{
				RECT icon;
				SetRect( &icon, bx + 2, by + 2, bx + 2 + iconsize, by + 2 + iconsize );

				if ( *pmi->b != FALSE )
				{
					if ( bSelected && m_hHotCheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hHotCheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hHotCheck, iconsize, iconsize, 0, 0, DI_NORMAL );

					else if ( m_hCheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hCheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hCheck, iconsize, iconsize, 0, 0, DI_NORMAL );
				} // end if
				else 
				{
					if ( bSelected && m_hHotUncheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hHotUncheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hHotUncheck, iconsize, iconsize, 0, 0, DI_NORMAL );

					else if ( m_hUncheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hUncheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hUncheck, iconsize, iconsize, 0, 0, DI_NORMAL );
				} // end else
			} // end if

			// Draw icon
			if ( pmi->icon != NULL ) 
			{
				long xoff = 2;
				xoff += iconsize * ( islots - 1 ) + 1;


//				DrawIconEx( hDC, x + xoff, y + 2, pmi->icon,
//							16, 16, 0, 0, DI_NORMAL );

				DrawIconEx( hDC, bx + xoff, by + 2, pmi->icon,
							iconsize, iconsize, 0, 0, DI_NORMAL );



			} // end if

			// Setup the text object
			text.SetFlags( DT_SINGLELINE | DT_VCENTER );

			if ( bSelected )
			{
				text.SetWeight( FW_BOLD );
				text.SetFont( &info.lfMenuFont );
	
				// Make text look recessed
				OffsetRect( &t, -1, -1 );
//				text.SetColor( RGB( 0, 0, 0 ) );
				text.SetColor( rgbSelTextDk );
				text.DrawText( hDC, pmi->name, &t );

				OffsetRect( &t, 1, 1 );
				text.SetColor( rgbSelTextLt );
			} // end if
			else
			{
//				text.SetItalic( FALSE );
				text.SetWeight( FW_BOLD );
				text.SetFont( &info.lfMenuFont );
//				text.SetFont( TFONTSIZE, TFONTTYPE );
//				text.SetColor( RGB( 0, 50, 128 ) );
				text.SetColor( rgbText );
			} // end else
//			else text.SetColor( rgbText );
//			text.SetColor( RGB( 0, 50, 128 ) );
			text.DrawText( hDC, pmi->name, &t );

			// Draw sub menu indicator
			if ( pmi->submenu != NULL )
			{
				// Do we have a tick mark icon?
				if ( m_hTick != NULL )
				{
					RECT ic;
					SetRect( &ic, t.right - 18, t.top + 5, t.right - 8, t.bottom - 7 );

					// Colorize tick icon
					HICON hMono = NULL;
					if ( !pmi->submenu->IsEmpty() ) 
						hMono = CGrDC::CreateMonoChromeIcon( m_hTick, GetSysColor( COLOR_ACTIVECAPTION ) );
					else hMono = CGrDC::CreateMonoChromeIcon( m_hTick, GetSysColor( COLOR_INACTIVECAPTION ) );
//						hMono = CGrDC::CreateMonoChromeIcon( m_hTick, rgbSel );
//					else hMono = CGrDC::CreateMonoChromeIcon( m_hTick, rgbBck );

					// Draw the icon
					if ( hMono != NULL )
					{	
						CGrDC::DrawIcon( hDC, &ic, hMono );
						DestroyIcon( hMono );
					} // end if

				} // end if
				else
				{
					HPEN whitepen = CreatePen( PS_SOLID, 1, rgbLightPen );
					HPEN dkgraypen = CreatePen( PS_SOLID, 1, ScaleColor( rgbBck, -10 ) );
					HPEN blackpen = CreatePen( PS_SOLID, 1, ScaleColor( rgbBck, -40 ) );
					HPEN oldpen = (HPEN)SelectObject( hDC, whitepen );				
					HBRUSH mbrush;
					if ( !pmi->submenu->IsEmpty() ) mbrush = CreateSolidBrush( rgbBck );
					else mbrush = CreateSolidBrush( ScaleColor( rgbBck, -80 ) );
					HBRUSH oldbrush = (HBRUSH)SelectObject( hDC, mbrush );

					POINT	pts[ 3 ];

					pts[ 0 ].x = t.right - 14;
					pts[ 0 ].y = t.top + 5;
					pts[ 1 ].x = t.right - 14;
					pts[ 1 ].y = t.bottom - 7;
					pts[ 2 ].x = t.right - 8;
					pts[ 2 ].y = t.top + ( ( t.bottom - t.top ) / 2 );

					// Draw the shape
					Polygon( hDC, pts, sizeof( pts ) / sizeof( POINT ) );

					// Draw border
					MoveToEx( hDC, pts[ 0 ].x, pts[ 0 ].y, NULL );
					LineTo( hDC, pts[ 1 ].x, pts[ 1 ].y );
					SelectObject( hDC, blackpen );
					LineTo( hDC, pts[ 2 ].x, pts[ 2 ].y );
					SelectObject( hDC, dkgraypen );
					LineTo( hDC, pts[ 0 ].x, pts[ 0 ].y ); 


					// Release drawing objects
					SelectObject( hDC, oldpen );
					DeleteObject( whitepen );
					DeleteObject( dkgraypen );
					DeleteObject( blackpen );
					SelectObject( hDC, oldbrush );
					DeleteObject( mbrush );

				} // end if

			} // end if

			// Next menu item position
			y += m_th;
		} // end if

		else // separator
		{
//			HPEN whitepen = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) );
//			HPEN dkgraypen = CreatePen( PS_SOLID, 1, RGB( 50, 50, 50 ) );
			HPEN whitepen = CreatePen( PS_SOLID, 1, rgbBumpLt );
			HPEN dkgraypen = CreatePen( PS_SOLID, 1, rgbBumpDk );
			HPEN oldpen = (HPEN)SelectObject( hDC, whitepen );

			// Draw white line
			MoveToEx( hDC, bx + 2, by + 2, NULL );
			LineTo( hDC, ( pRect->right - pRect->left ) - 2, by + 2 );

			// Draw dark gray line
			SelectObject( hDC, dkgraypen );
			MoveToEx( hDC, bx + 2, by + 3, NULL );
			LineTo( hDC, ( pRect->right - pRect->left ) - 2, by + 3 );

			SelectObject( hDC, oldpen );
			DeleteObject( whitepen );
			DeleteObject( dkgraypen );

			y += 6;

		} // end else

	} // end while

	return TRUE;
}
Exemplo n.º 12
0
void CWinMenu::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	RECT rect;
	HDC hDC = dc.GetSafeHdc();
	GetClientRect( &rect );

	// Where will we draw?
	HDC hDraw = hDC;
	if ( m_offscreen.Create( hDC, &rect ) ) 
		hDraw = m_offscreen.GetSafeHdc();

	// Fill in menu window
	COLORREF rgbBck = m_rgbMenu;
	if ( m_bSystemColors ) rgbBck = GetSysColor( COLOR_MENU );
	
	COLORREF	rgbBckLt = ScaleColor( rgbBck, 40 );
	COLORREF	rgbBckDk = ScaleColor( rgbBck, -40 );

//	CGrDC::GradientFill( hDraw, &rect,	RGB( 255, 0, 0 ), RGB( 0, 255, 0 ),
//										RGB( 255, 0, 255 ), RGB( 0, 255, 255 ) );

	if (	m_bck.GetSafeHdc() == NULL || 
			RW( rect ) != m_bck.GetWidth() ||
			RH( rect ) != m_bck.GetHeight() )
	{
		// Create the background
		m_bck.Create( NULL, &rect );

		if ( m_dwShading == 0 )
			CGrDC::FillSolidRect( hDraw, &rect, rgbBck );
		else if ( m_dwShading == 1 )
			CGrDC::VertGradientFill( hDraw, &rect,	rgbBckLt, rgbBckDk );
		else if ( m_dwShading == 3 )
		{
			CGrDC::VertGradientFill(	m_bck, m_bck, 
										CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), 50 ),
										CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), -50 ) );
			m_bck.Aluminize( 2 );

		} // end else if
		else if ( m_dwShading == 4 )
		{
			CGrDC::VertGradientFill(	m_bck, m_bck, 
										CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), 50 ),
										CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), -50 ) );
			m_bck.Texturize( 5 );

		} // end else if
		else
		{	// Gradient fill
			COLORREF rgbCorner = m_rgbSel;
			if ( m_bSystemColors ) rgbCorner = GetSysColor( COLOR_ACTIVECAPTION );
			CGrDC::GradientFill( m_bck, &rect,	rgbBckLt, rgbBckDk, 
												rgbBckLt, rgbCorner );
		} // end else

		RECT brect;
		CopyRect( &brect, m_bck );

		HPEN whitepen = CreatePen( PS_SOLID, 3, ScaleColor( rgbBck, 120 ) );
		HPEN dkgraypen = CreatePen( PS_SOLID, 3, ScaleColor( rgbBck, -120 ) );
		HPEN oldpen = (HPEN)SelectObject( m_bck, whitepen );

		// Draw white line
		MoveToEx( m_bck, brect.right, brect.top, NULL );
		LineTo( m_bck, brect.left, brect.top );
		LineTo( m_bck, brect.left, brect.bottom );

		// Draw dark gray line
		SelectObject( m_bck, dkgraypen );
		MoveToEx( m_bck, brect.left, brect.bottom, NULL );
		LineTo( m_bck, brect.right, brect.bottom );
		LineTo( m_bck, brect.right, brect.top );

		SelectObject( m_bck, oldpen );
		DeleteObject( whitepen );
		DeleteObject( dkgraypen );

	} // end if

	// Draw background
	m_bck.Draw( hDraw, &rect );

	// Draw the menu items
	DrawMenuItems( hDraw, &rect );

	// Copy from offscreen
	if ( m_offscreen.GetSafeHdc() ) m_offscreen.Draw( hDC, &rect );
}