コード例 #1
0
void AvHSpriteDrawTiles(int spriteHandle, int numXFrames, int numYFrames, float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2)
{
    
    float dx = x2 - x1;
    float dy = y2 - y1;

    float oldDepth = gDepth;

    for (int frameY = 0; frameY < numYFrames; ++frameY)
    {
        for (int frameX = 0; frameX < numXFrames; ++frameX)
        {

            int frame = frameX + frameY * numXFrames;

            float pw = SPR_Width(spriteHandle, frame);
            float ph = SPR_Height(spriteHandle, frame);
            
            float fx1 = ((float)(frameX)) / numXFrames;
            float fy1 = ((float)(frameY)) / numYFrames;
            
            float fx2 = ((float)(frameX + 1)) / numXFrames;
            float fy2 = ((float)(frameY + 1)) / numYFrames;

            gDepth = oldDepth;

            AvHSpriteDraw(spriteHandle, frame,
                 x1 + dx * fx1, y1 + dy * fy1, x1 + dx * fx2, y1 + dy * fy2,
                 0, 0, 1, 1);

        }
    }

}
コード例 #2
0
ファイル: cdll_int.cpp プロジェクト: Arkshine/NS
void UIDrawVariableBarSpriteHoles(int inSprite, int inX, int inY, float inPercentage)
{
	// Assumes that frame 0 is the empty sprite, frame 1 is full sprite
	const int kEmptyFrame = 0;
	const int kFullFrame = 1;
	
	int theSpriteWidth = SPR_Width(inSprite, kFullFrame);
	int theSpriteHeight = SPR_Height(inSprite, kFullFrame);
	
	int theColorComponent = 255;
	
	// Draw empty sprite
	SPR_Set(inSprite, theColorComponent, theColorComponent, theColorComponent);
	SPR_DrawHoles(kEmptyFrame, inX, inY, NULL);
	
	// Draw secondary level if specified, at half brightness
	int theFilledHeight = theSpriteHeight*inPercentage;
	theFilledHeight = theSpriteHeight*inPercentage;
	
	// Draw partially full sprite.  Enable scissor so it's not all drawn.
	SPR_EnableScissor(inX, inY + (theSpriteHeight - theFilledHeight), theSpriteWidth, theFilledHeight);
	
	SPR_Set(inSprite, theColorComponent, theColorComponent, theColorComponent);
	SPR_DrawHoles(kFullFrame, inX, inY, NULL);
	
	SPR_DisableScissor();
}
コード例 #3
0
ファイル: hud_redraw.cpp プロジェクト: 6779660/halflife
// Redraw
// step through the local data,  placing the appropriate graphics & text as appropriate
// returns 1 if they've changed, 0 otherwise
int CHud :: Redraw( float flTime, int intermission )
{
	m_fOldTime = m_flTime;	// save time of previous redraw
	m_flTime = flTime;
	m_flTimeDelta = (double)m_flTime - m_fOldTime;
	
	// Clock was reset, reset delta
	if ( m_flTimeDelta < 0 )
		m_flTimeDelta = 0;

	m_iIntermission = intermission;

	// if no redrawing is necessary
	// return 0;
	
	HUDLIST *pList = m_pHudList;

	while (pList)
	{
		if ( !intermission )
		{
			if ((pList->p->m_iFlags & HUD_ACTIVE) && !(m_iHideHUDDisplay & HIDEHUD_ALL))
				pList->p->Draw(flTime);
		}
		else
		{  // it's an intermission,  so only draw hud elements that are set to draw during intermissions
			if ( pList->p->m_iFlags & HUD_INTERMISSION )
				pList->p->Draw( flTime );
		}

		pList = pList->pNext;
	}

	// are we in demo mode? do we need to draw the logo in the top corner?
	if (m_iLogo)
	{
		int x, y, i;

		if (m_hsprLogo == 0)
			m_hsprLogo = LoadSprite("sprites/%d_logo.spr");

		SPR_Set(m_hsprLogo, 250, 250, 250 );
		
		x = SPR_Width(m_hsprLogo, 0);
		x = ScreenWidth - x;
		y = SPR_Height(m_hsprLogo, 0)/2;

		// Draw the logo at 20 fps
		int iFrame = (int)(flTime * 20) % MAX_LOGO_FRAMES;
		i = grgLogoFrame[iFrame] - 1;

		SPR_DrawAdditive(i, x, y, NULL);
	}

	return 1;
}
コード例 #4
0
ファイル: AvHFont.cpp プロジェクト: Arkshine/NS
bool AvHFont::Load(const char* inFileName)
{
    
    std::string theSpriteFileName;
    theSpriteFileName  = inFileName;
    theSpriteFileName += ".spr";

    std::string theWidthFileName;
    theWidthFileName  = getModDirectory();
    theWidthFileName += "/";
    theWidthFileName += inFileName;
    theWidthFileName += ".dat";
    
    FILE* file = fopen(theWidthFileName.c_str(), "rb");

    if (file != NULL)
    {

        struct LABC
        {
            long a;
            long b;
            long c;
        };

        LABC labc[256];
        fread(labc, sizeof(LABC), 256, file);

        for (int i = 0; i < 256; ++i)
        {
            mCharWidth[i].a = labc[i].a;
            mCharWidth[i].b = labc[i].b;
            mCharWidth[i].c = labc[i].c;
        }
        
        fclose(file);
    }
    else
    {
        return false;
    }

    mSprite = Safe_SPR_Load(theSpriteFileName.c_str());

    if (mSprite != 0)
    {
        mSpriteWidth  = SPR_Width(mSprite, 0);
        mSpriteHeight = SPR_Height(mSprite, 0);
    }
    
    return mSprite != 0;

}
コード例 #5
0
ファイル: train.cpp プロジェクト: FWGS/XashXT
int CHudTrain::Draw( float fTime )
{
	if( !m_hSprite )
		m_hSprite = LoadSprite( "sprites/640_train.spr" );

	if( m_iPos )
	{
		int r, g, b, x, y;

		UnpackRGB( r, g, b, gHUD.m_iHUDColor );
		SPR_Set( m_hSprite, r, g, b );

		// This should show up to the right and part way up the armor number
		y = ScreenHeight - SPR_Height( m_hSprite, 0 ) - gHUD.m_iFontHeight;
		x = ScreenWidth / 3 + SPR_Width( m_hSprite, 0 ) / 4;

		SPR_DrawAdditive( m_iPos - 1,  x, y, NULL );
	}
	return 1;
}
コード例 #6
0
ファイル: cdll_int.cpp プロジェクト: Arkshine/NS
// Demonstrates black lines around the edge of sprites (both using tri API and SPR_* calls)
// Demonstrates scissor not working properly
void Direct3DTest()
{
	static int theSprite = 0;
	
	if(!theSprite)
	{
		theSprite = Safe_SPR_Load("sprites/640a-energy.spr");
	}

	// Draw alien energy
	if(theSprite)
	{
		int theFrame = 0;
		
		int theX = ScreenWidth() - SPR_Width(theSprite, theFrame);
		int theY = ScreenHeight() - SPR_Height(theSprite, theFrame);

		// 0-1, depending how much to draw
		float theFactor = .5f;
		UIDrawVariableBarSpriteHoles(theSprite, theX, theY, theFactor);
	}
}
コード例 #7
0
void FadingImageLabel::DoPaint()
{
	//const float thePercentToChopOffXEdge = .1f;
	//const float thePercentToChopOffYEdge = 0.0f;

	int theX, theY;
	this->getPos(theX, theY);

	//if(!IEngineStudio.IsHardware())
	//{
	//	theX += ScreenWidth/2;
	//	theY += ScreenHeight/2;
	//}
	
	int theWidth, theHeight;
	this->getSize(theWidth, theHeight);

	//ASSERT(this->mVisibleWidth <= theWidth);
	//ASSERT(this->mVisibleHeight <= theHeight);

	if((this->mVisibleWidth <= theWidth) && (this->mVisibleHeight <= theHeight))
	{
		int r, g, b, a;
		this->getBgColor(r, g, b, a);

		float theGammaSlope = gHUD.GetGammaSlope();
		r = r/theGammaSlope;
		g = g/theGammaSlope;
		b = b/theGammaSlope;
		
		// Don't take gamma slope into account for alpha
		a = 255 - a;

		////int theXBorder = thePercentToChopOffXEdge*ScreenWidth;
		////int theYBorder = thePercentToChopOffYEdge*ScreenHeight;
		int theXBorder = (theWidth - this->mVisibleWidth)/2;
		int theYBorder = (theHeight - this->mVisibleHeight)/2;

		//vguiSimpleBox(theXBorder, theYBorder, theWidth - theXBorder*2 + theXBorder, theHeight - theYBorder*2 + theYBorder, r, g, b, a);
		
		if(!this->mImageMode)
		{
			//FillRGBA(theXBorder, theYBorder, theWidth - theXBorder*2, theHeight - theYBorder*2, r, g, b, a);

			//int theSprite = Safe_SPR_Load("sprites/marinenode.spr");
			//DrawScaledHUDSprite(theSprite, kRenderTransAdd, 1, theX, theY, theWidth, theHeight, 0);
			
			gEngfuncs.pTriAPI->RenderMode(kRenderTransAlpha);
			gEngfuncs.pTriAPI->CullFace(TRI_NONE);
			//gEngfuncs.pTriAPI->Brightness(1);
			theX = theXBorder;
			theY = theYBorder;
			theWidth = theWidth - theXBorder*2;
			theHeight = theHeight - theYBorder*2;

			// 0 = selectable, valid
			// 1 = selectable, valid, current
			// 2 = selectable, invalid
			// 3 = selectable, invalid, current
			int theFrame = 0;

			if(this->GetEnabled() && this->GetDrawHighlighted())
			{
				theFrame = 1;
			}
			else if(!this->GetEnabled())
			{
				theFrame = this->GetFadeState() ? 3 : 2;
			}

			//char theFrameNumber[64];
			//sprintf(theFrameNumber, "Frame %d", theFrame);
			//this->mTextImage.setText(theFrameNumber);

			if(!this->mSprite)
			{
				this->mSprite = Safe_SPR_Load(this->mImageName.c_str());
				this->mSpriteWidth = SPR_Width(this->mSprite, this->mSpriteFrame);
				this->mSpriteHeight = SPR_Height(this->mSprite, this->mSpriteFrame);
				ASSERT(this->mSprite > 0);
			}
			
			if(this->mSprite && gEngfuncs.pTriAPI->SpriteTexture((struct model_s*)gEngfuncs.GetSpritePointer(this->mSprite), theFrame))
			{
				gEngfuncs.pTriAPI->Begin(TRI_TRIANGLE_STRIP);
			
				vec3_t theVertex;
			
				gEngfuncs.pTriAPI->TexCoord2f(0, 1);
				theVertex.x = theX;
				theVertex.y = theY + theHeight;
				theVertex.z = 0;
				//gEngfuncs.pTriAPI->Color4ub(255, 255, 255, a);
				gEngfuncs.pTriAPI->Vertex3fv((float*)&theVertex);
			
				gEngfuncs.pTriAPI->TexCoord2f(0, 0);
				theVertex.x = theX;
				theVertex.y = theY;
				//gEngfuncs.pTriAPI->Color4ub(255, 255, 255, a);
				gEngfuncs.pTriAPI->Vertex3fv((float*)&theVertex);
			
				gEngfuncs.pTriAPI->TexCoord2f(1, 1);
				theVertex.x = theX + theWidth;
				theVertex.y = theY + theHeight;
				//gEngfuncs.pTriAPI->Color4ub(255, 255, 255, a);
				gEngfuncs.pTriAPI->Vertex3fv((float*)&theVertex);
			
				gEngfuncs.pTriAPI->TexCoord2f(1, 0);
				theVertex.x = theX + theWidth;
				theVertex.y = theY;
				//gEngfuncs.pTriAPI->Color4ub(255, 255, 255, a);
				gEngfuncs.pTriAPI->Vertex3fv((float*)&theVertex);
			
				gEngfuncs.pTriAPI->End();
			}

			gEngfuncs.pTriAPI->RenderMode(kRenderNormal);
		}	
		else
		{
			SPR_Set(this->mSprite, a, a, a);
			
			int theSpriteWidth = SPR_Width(this->mSprite, this->mSpriteFrame);
			int theSpriteHeight = SPR_Height(this->mSprite, this->mSpriteFrame);
			
			//SPR_DrawAdditive(theFrame, (theWidth - theSpriteWidth)/2, (theHeight - theSpriteHeight)/2, NULL);
			SPR_DrawHoles(this->mSpriteFrame, (theWidth - theSpriteWidth)/2, (theHeight - theSpriteHeight)/2, NULL);
		}
	}
}
コード例 #8
0
ファイル: hud_redraw.cpp プロジェクト: ET-NiK/amxxgroup
// Redraw
// step through the local data,  placing the appropriate graphics & text as appropriate
// returns 1 if they've changed, 0 otherwise
int CHud :: Redraw( float flTime, int intermission )
{
	m_fOldTime = m_flTime;	// save time of previous redraw
	m_flTime = flTime;
	m_flTimeDelta = (double)m_flTime - m_fOldTime;
	static m_flShotTime = 0;
	
	// Clock was reset, reset delta
	if ( m_flTimeDelta < 0 )
		m_flTimeDelta = 0;

	// Bring up the scoreboard during intermission
	if (gViewPort)
	{
		if ( m_iIntermission && !intermission )
		{
			// Have to do this here so the scoreboard goes away
			m_iIntermission = intermission;
			gViewPort->HideCommandMenu();
			gViewPort->HideScoreBoard();
			gViewPort->UpdateSpectatorPanel();
		}
		else if ( !m_iIntermission && intermission )
		{
			m_iIntermission = intermission;
			gViewPort->HideCommandMenu();
			gViewPort->HideVGUIMenu();
			gViewPort->ShowScoreBoard();
			gViewPort->UpdateSpectatorPanel();

			// Take a screenshot if the client's got the cvar set
			if ( CVAR_GET_FLOAT( "hud_takesshots" ) != 0 )
				m_flShotTime = flTime + 1.0;	// Take a screenshot in a second
		}
	}

	if (m_flShotTime && m_flShotTime < flTime)
	{
		gEngfuncs.pfnClientCmd("snapshot\n");
		m_flShotTime = 0;
	}
	// if no redrawing is necessary
	// return 0;
	
	// draw all registered HUD elements
	if ( m_pCvarDraw->value )
	{
		HUDLIST *pList = m_pHudList;

		while (pList)
		{
			if ( !intermission )
			{
				if ((pList->p->m_iFlags & HUD_ACTIVE) && !(m_iHideHUDDisplay & HIDEHUD_ALL))
					pList->p->Draw(flTime);
			}
			else
			{  // it's an intermission,  so only draw hud elements that are set to draw during intermissions
				if ( pList->p->m_iFlags & HUD_INTERMISSION )
					pList->p->Draw( flTime );
			}

			pList = pList->pNext;
		}
	}

	// are we in demo mode? do we need to draw the logo in the top corner?
	if (m_iLogo)
	{
		int x, y, i;

		if (m_hsprLogo == 0)
			m_hsprLogo = LoadSprite("sprites/%d_logo.spr");

		SPR_Set(m_hsprLogo, 250, 250, 250 );
		
		x = SPR_Width(m_hsprLogo, 0);
		x = ScreenWidth - x;
		y = SPR_Height(m_hsprLogo, 0)/2;

		// Draw the logo at 20 fps
		int iFrame = (int)(flTime * 20) % MAX_LOGO_FRAMES;
		i = grgLogoFrame[iFrame] - 1;

		SPR_DrawAdditive(i, x, y, NULL);
	}
	

	return 1;
}
コード例 #9
0
// Draw node lines
void PieNode::paintBackground()
{
    // For each child
    for(int i = 0; i < kNumNodes; i++)
    {
        PieNode* theCurrentPieNode = this->mArray[i];
        if(theCurrentPieNode)
        {
            // Draw line from us to them indicating pie node in that direction
            if(theCurrentPieNode->GetValveAlpha() < 255)
            {
                // If node above us isn't highlighted, don't draw line to us
                //if(theCurrentPieNode->HasSelectedNodeAbove() || theCurrentPieNode->HasSelectedNodeBelow())
				
				// All those lines are getting confusing.  Only draw the lines around this pie node that
				// connect to a selected parent or selected child
                if(theCurrentPieNode->HasSelectedNodeBelow() || this->GetDrawSelected())
                {
                    // Find correct line to draw from center of edge of source pie node to center
                    // of edge of dest pie node
                    int theRelativeLineX0, theRelativeLineY0, theRelativeLineX1, theRelativeLineY1;
                    if(this->ComputeRelativeConnectorCoordinates(theCurrentPieNode, theRelativeLineX0, theRelativeLineY0, theRelativeLineX1, theRelativeLineY1))
                    {
                        // What color to draw the line in?
                        //vgui::Color theCurrentColor = this->GetColor();
                        vgui::Color theCurrentColor;
						//theCurrentPieNode->getBgColor(theCurrentColor);
						
						if(this->mEnabled)
						{
							theCurrentPieNode->getFgColor(theCurrentColor);
						}
						else
						{
							theCurrentPieNode->getBgColor(theCurrentColor);
						}
						
                        int r, g, b, a;
                        theCurrentColor.getColor(r, g, b, a);

						// Take gamma into account
						//r *= this->mColorBias;
						//g *= this->mColorBias;
						//b *= this->mColorBias;
						a = this->GetValveAlpha();

//						//if(theCurrentPieNode->GetEnabled())
//						//{
//						g = (theCurrentPieNode->HasSelectedNodeBelow() ? 255 : kDarkGreenColor);
//						//g = (theCurrentPieNode->HasSelectedNodeAbove() ? 255 : kDarkGreenColor);
//						//}
//						// ...else this will draw lines in disabled color too, using current fade alpha
                        
                        // Stupid Valve-alpha, vguiSimpleLine wants normal alpha of course
						a = 255 - a;
						a *= this->mColorBias;
						
						// Only draw if child isn't invisible.  Draw line
						// relative from current node.

						if(this->mConnectorSprite == 0 && (this->mConnectorSpriteName != ""))
						{
							this->mConnectorSprite = Safe_SPR_Load(this->mConnectorSpriteName.c_str());
						}

						if(this->mConnectorSprite > 0)
						{
							// Approximate alpha
							float theAlpha = a/255.0f;
							int theSpriteRed = theAlpha*r;
							int theSpriteGreen = theAlpha*g;
							int theSpriteBlue = theAlpha*b;
							
							SPR_Set(this->mConnectorSprite, theSpriteRed, theSpriteGreen, theSpriteBlue);
							int theLineWidth = abs(theRelativeLineX1 - theRelativeLineX0);
							int theLineHeight = abs(theRelativeLineY1 - theRelativeLineY0);
							
							// Use second frame if vertical
							int theConnectorFrame = 0;
							if(theLineHeight > 0)							
							{
								theConnectorFrame = 1;
							}
							
							int theConnectorSpriteWidth = SPR_Width(this->mConnectorSprite, theConnectorFrame);
							int theConnectorSpriteHeight = SPR_Height(this->mConnectorSprite, theConnectorFrame);

							int thePieNodeWidth, thePieNodeHeight;
							this->getContentSize(thePieNodeWidth, thePieNodeHeight);
							
							int thePieNodeX, thePieNodeY;
							this->getPos(thePieNodeX, thePieNodeY);
							
							int theStartX = 0;
							int theStartY = 0;

							if(theConnectorFrame == 0)
							{
								int theXOffset = (theLineWidth - theConnectorSpriteWidth)/2;
								//if(theXOffset < 0)
								//	theXOffset = 0;
								
								theStartX = min(theRelativeLineX0, theRelativeLineX1) + theXOffset;
								theStartY = min(theRelativeLineY0, theRelativeLineY1) - theConnectorSpriteHeight/2;

//								int theScissorStartX = thePieNodeX + min(theRelativeLineX0, theRelativeLineX1) + thePieNodeWidth/2;
//								int theScissorStartY = thePieNodeY + theStartY;
//								int theScissorEndX = theScissorStartX + theLineWidth - thePieNodeWidth/2;
//								int theScissorEndY = theScissorStartY + theConnectorSpriteHeight;
								
								//vguiSimpleBox(theScissorStartX - thePieNodeX, theScissorStartY - thePieNodeY, theScissorEndX - thePieNodeX, theScissorEndY - thePieNodeY, 255, 255, 0, 128);

//								SPR_EnableScissor(theScissorStartX, theScissorStartY, theLineWidth, theConnectorSpriteHeight);
							}
							else
							{
								int theYOffset = (theLineHeight - theConnectorSpriteHeight)/2;
								//if(theYOffset < 0)
								//	theYOffset = 0;

								theStartX = min(theRelativeLineX0, theRelativeLineX1) - theConnectorSpriteWidth/2;
								theStartY = min(theRelativeLineY0, theRelativeLineY1) + theYOffset;

//								int theScissorStartX = thePieNodeX + theStartX;
//								int theScissorStartY = thePieNodeY + min(theRelativeLineY0, theRelativeLineY1);
//								int theScissorEndX = theScissorStartX + theConnectorSpriteWidth;
//								int theScissorEndY = theScissorStartY + theLineHeight - thePieNodeHeight;
								
								//vguiSimpleBox(theScissorStartX - thePieNodeX, theScissorStartY - thePieNodeY, theScissorEndX - thePieNodeX, theScissorEndY - thePieNodeY, 255, 255, 0, 128);

//								SPR_EnableScissor(theScissorStartX, theScissorStartY, theConnectorSpriteWidth, theLineHeight);
							}

							// Take into account our position, including our parent(s), when drawing
//							Panel* theParent = this->getParent();
//							while(theParent)
//							{
//								int theX, theY;
//								theParent->getPos(theX, theY);
//								theStartX += theX;
//								theStartY += theY;
//								theParent = theParent->getParent();
//							}

							// Draw it
							//SPR_DrawAdditive(theConnectorFrame, theStartX, theStartY, NULL);
							SPR_DrawHoles(theConnectorFrame, theStartX, theStartY, NULL);
//							gEngfuncs.pfnSPR_DisableScissor();
							
						}
						else
						{
							vguiSimpleLine(theRelativeLineX0, theRelativeLineY0, theRelativeLineX1, theRelativeLineY1, r, g, b, a);
						}

						vguiSimpleBox(theRelativeLineX0, theRelativeLineY0, theRelativeLineX1, theRelativeLineY1, 255, 255, 0, 128);
					}
				}
			}
		}
	}
}
コード例 #10
0
ファイル: HudHealth.cpp プロジェクト: Sh1ft0x0EF/HLSDKRevamp
int CHudHealth::DrawPain(float flTime)
{
	if(!(m_fAttackFront || m_fAttackRear || m_fAttackLeft || m_fAttackRight))
		return 1;

	int r, g, b;
	int x, y, a, shade;

	// TODO:  get the shift value of the health
	a = 255; // max brightness until then

	float fFade = gHUD.m_flTimeDelta * 2;

	// SPR_Draw top
	if(m_fAttackFront > 0.4)
	{
		GetPainColor(r, g, b);
		shade = a * max(m_fAttackFront, 0.5);
		ScaleColors(r, g, b, shade);
		SPR_Set(m_hSprite, r, g, b);

		x = ScreenWidth / 2 - SPR_Width(m_hSprite, 0) / 2;
		y = ScreenHeight / 2 - SPR_Height(m_hSprite, 0) * 3;
		SPR_DrawAdditive(0, x, y, NULL);
		m_fAttackFront = max(0, m_fAttackFront - fFade);
	}
	else
		m_fAttackFront = 0;

	if(m_fAttackRight > 0.4)
	{
		GetPainColor(r, g, b);
		shade = a * max(m_fAttackRight, 0.5);
		ScaleColors(r, g, b, shade);
		SPR_Set(m_hSprite, r, g, b);

		x = ScreenWidth / 2 + SPR_Width(m_hSprite, 1) * 2;
		y = ScreenHeight / 2 - SPR_Height(m_hSprite, 1) / 2;
		SPR_DrawAdditive(1, x, y, NULL);
		m_fAttackRight = max(0, m_fAttackRight - fFade);
	}
	else
		m_fAttackRight = 0;

	if(m_fAttackRear > 0.4)
	{
		GetPainColor(r, g, b);
		shade = a * max(m_fAttackRear, 0.5);
		ScaleColors(r, g, b, shade);
		SPR_Set(m_hSprite, r, g, b);

		x = ScreenWidth / 2 - SPR_Width(m_hSprite, 2) / 2;
		y = ScreenHeight / 2 + SPR_Height(m_hSprite, 2) * 2;
		SPR_DrawAdditive(2, x, y, NULL);
		m_fAttackRear = max(0, m_fAttackRear - fFade);
	}
	else
		m_fAttackRear = 0;

	if(m_fAttackLeft > 0.4)
	{
		GetPainColor(r, g, b);
		shade = a * max(m_fAttackLeft, 0.5);
		ScaleColors(r, g, b, shade);
		SPR_Set(m_hSprite, r, g, b);

		x = ScreenWidth / 2 - SPR_Width(m_hSprite, 3) * 3;
		y = ScreenHeight / 2 - SPR_Height(m_hSprite, 3) / 2;
		SPR_DrawAdditive(3, x, y, NULL);

		m_fAttackLeft = max(0, m_fAttackLeft - fFade);
	}
	else
		m_fAttackLeft = 0;

	return 1;
}
コード例 #11
0
// Redraw
// step through the local data,  placing the appropriate graphics & text as appropriate
// returns 1 if they've changed, 0 otherwise
int CHud :: Redraw( float flTime, int intermission )
{
	m_fOldTime = m_flTime;	// save time of previous redraw
	m_flTime = flTime;
	m_flTimeDelta = (double)m_flTime - m_fOldTime;
	static float m_flShotTime = 0;
	
	// Clock was reset, reset delta
	if ( m_flTimeDelta < 0 )
		m_flTimeDelta = 0;


	if (m_flShotTime && m_flShotTime < flTime)
	{
		gEngfuncs.pfnClientCmd("snapshot\n");
		m_flShotTime = 0;
	}

	m_iIntermission = intermission;

	// if no redrawing is necessary
	// return 0;
	
	if ( m_pCvarDraw->value )
	{
		HUDLIST *pList = m_pHudList;

		while (pList)
		{
			if ( !intermission )
			{
				if ( (pList->p->m_iFlags & HUD_ACTIVE) && !(m_iHideHUDDisplay & HIDEHUD_ALL) )
					pList->p->Draw(flTime);
			}
			else
			{  // it's an intermission,  so only draw hud elements that are set to draw during intermissions
				if ( pList->p->m_iFlags & HUD_INTERMISSION )
					pList->p->Draw( flTime );
			}

			pList = pList->pNext;
		}
	}

	// are we in demo mode? do we need to draw the logo in the top corner?
	if (m_iLogo)
	{
		int x, y, i;

		if (m_hsprLogo == 0)
			m_hsprLogo = LoadSprite("sprites/%d_logo.spr");

		SPR_Set(m_hsprLogo, 250, 250, 250 );
		
		x = SPR_Width(m_hsprLogo, 0);
		x = ScreenWidth - x;
		y = SPR_Height(m_hsprLogo, 0)/2;

		// Draw the logo at 20 fps
		int iFrame = (int)(flTime * 20) % MAX_LOGO_FRAMES;
		i = grgLogoFrame[iFrame] - 1;

		SPR_DrawAdditive(i, x, y, NULL);
	}

	/*
	if ( g_iVisibleMouse )
	{
		void IN_GetMousePos( int *mx, int *my );
		int mx, my;

		IN_GetMousePos( &mx, &my );
		
		if (m_hsprCursor == 0)
		{
			char sz[256];
			sprintf( sz, "sprites/cursor.spr" );
			m_hsprCursor = SPR_Load( sz );
		}

		SPR_Set(m_hsprCursor, 250, 250, 250 );
		
		// Draw the logo at 20 fps
		SPR_DrawAdditive( 0, mx, my, NULL );
	}
	*/

	return 1;
}
コード例 #12
0
ファイル: hud_redraw.cpp プロジェクト: mittorn/SoHL-1.2
// Redraw
// step through the local data,  placing the appropriate graphics & text as appropriate
// returns 1 if they've changed, 0 otherwise
int CHud :: Redraw( float flTime, int intermission )
{
	m_fOldTime = m_flTime;	// save time of previous redraw
	m_flTime = flTime;
	m_flTimeDelta = (double)m_flTime - m_fOldTime;
	static int m_flShotTime = 0;

	//LRC - handle fog fading effects. (is this the right place for it?)
	if (g_fFadeDuration)
	{
		// Nicer might be to use some kind of logarithmic fade-in?
		double fFraction = m_flTimeDelta/g_fFadeDuration;
//		g_fStartDist -= (FOG_LIMIT - g_iFinalStartDist)*fFraction;
		g_fEndDist -= (FOG_LIMIT - g_iFinalEndDist)*fFraction;

//		CONPRINT("FogFading: %f - %f, frac %f, time %f, final %d\n", g_fStartDist, g_fEndDist, fFraction, flTime, g_iFinalEndDist);

		// cap it
//		if (g_fStartDist > FOG_LIMIT)				g_fStartDist = FOG_LIMIT;
		if (g_fEndDist   > FOG_LIMIT)				g_fEndDist = FOG_LIMIT;
//		if (g_fStartDist < g_iFinalStartDist)	g_fStartDist = g_iFinalStartDist;
		if (g_fEndDist   < g_iFinalEndDist)		g_fEndDist   = g_iFinalEndDist;
	}
	
	// Clock was reset, reset delta
	if ( m_flTimeDelta < 0 )
		m_flTimeDelta = 0;

	// Bring up the scoreboard during intermission
	/*if (gViewPort)
	{
		if ( m_iIntermission && !intermission )
		{
			// Have to do this here so the scoreboard goes away
			m_iIntermission = intermission;
			gViewPort->HideCommandMenu();
			gViewPort->HideScoreBoard();
			gViewPort->UpdateSpectatorPanel();
		}
		else if ( !m_iIntermission && intermission )
		{
			m_iIntermission = intermission;
			gViewPort->HideCommandMenu();
			gViewPort->HideVGUIMenu();
			gViewPort->ShowScoreBoard();
			gViewPort->UpdateSpectatorPanel();

			// Take a screenshot if the client's got the cvar set
			if ( CVAR_GET_FLOAT( "hud_takesshots" ) != 0 )
				m_flShotTime = flTime + 1.0;	// Take a screenshot in a second
		}
	}*/

	if (m_flShotTime && m_flShotTime < flTime)
	{
		gEngfuncs.pfnClientCmd("snapshot\n");
		m_flShotTime = 0;
	}

	m_iIntermission = intermission;

	// if no redrawing is necessary
	// return 0;
	
	if ( m_pCvarDraw->value )
	{
		HUDLIST *pList = m_pHudList;

		while (pList)
		{
			if ( !intermission )
			{
				if ( (pList->p->m_iFlags & HUD_ACTIVE) && !(m_iHideHUDDisplay & HIDEHUD_ALL) )
					pList->p->Draw(flTime);
			}
			else
			{  // it's an intermission,  so only draw hud elements that are set to draw during intermissions
				if ( pList->p->m_iFlags & HUD_INTERMISSION )
					pList->p->Draw( flTime );
			}

			pList = pList->pNext;
		}
	}

	// are we in demo mode? do we need to draw the logo in the top corner?
	if (m_iLogo)
	{
		int x, y, i;

		if (m_hsprLogo == 0)
			m_hsprLogo = LoadSprite("sprites/%d_logo.spr");

		SPR_Set(m_hsprLogo, 250, 250, 250 );
		
		x = SPR_Width(m_hsprLogo, 0);
		x = ScreenWidth - x;
		y = SPR_Height(m_hsprLogo, 0)/2;

		// Draw the logo at 20 fps
		int iFrame = (int)(flTime * 20) % MAX_LOGO_FRAMES;
		i = grgLogoFrame[iFrame] - 1;

		SPR_DrawAdditive(i, x, y, NULL);
	}

	/*
	if ( g_iVisibleMouse )
	{
		void IN_GetMousePos( int *mx, int *my );
		int mx, my;

		IN_GetMousePos( &mx, &my );
		
		if (m_hsprCursor == 0)
		{
			char sz[256];
			sprintf( sz, "sprites/cursor.spr" );
			m_hsprCursor = SPR_Load( sz );
		}

		SPR_Set(m_hsprCursor, 250, 250, 250 );
		
		// Draw the logo at 20 fps
		SPR_DrawAdditive( 0, mx, my, NULL );
	}
	*/

	return 1;
}
コード例 #13
0
void AvHSpriteDraw(int spriteHandle, int frame, float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2)
{

    gEngfuncs.pTriAPI->RenderMode(gRenderMode);
    gEngfuncs.pTriAPI->CullFace(TRI_NONE);
    
    struct model_s* spritePtr = (struct model_s*)(gEngfuncs.GetSpritePointer(spriteHandle));
    ASSERT(spritePtr);

    if (!gEngfuncs.pTriAPI->SpriteTexture(spritePtr, frame))
    {
        return;
    }

    Vertex vertex[8];

    vertex[0].x = x1;
    vertex[0].y = y1;
    vertex[0].u = u1;
    vertex[0].v = v1;

    vertex[1].x = x2;
    vertex[1].y = y1;
    vertex[1].u = u2;
    vertex[1].v = v1;

    vertex[2].x = x2;
    vertex[2].y = y2;
    vertex[2].u = u2;
    vertex[2].v = v2;

    vertex[3].x = x1;
    vertex[3].y = y2;
    vertex[3].u = u1;
    vertex[3].v = v2;

    int numVertices = 4;

    float pw = SPR_Width(spriteHandle, frame);
    float ph = SPR_Height(spriteHandle, frame);

    float uOffset = 0;
    float vOffset = 0;

    if (IEngineStudio.IsHardware() == 2)
    {

        // Direct3D addresses textures differently than OpenGL so compensate
        // for that here.

        uOffset = 0.5 / pw;
        vOffset = 0.5 / ph;
  
    }

    // Apply the transformation to the vertices.
    
    for (int i = 0; i < numVertices; ++i)
    {

        if (vertex[i].u < 0.25 / pw)
        {
            vertex[i].u = 0.25 / pw;
        }

        if (vertex[i].v < 0.25 / ph)
        {
            vertex[i].v = 0.25 / ph;
        }

        if (vertex[i].u > 1 - 0.25 / pw)
        {
            vertex[i].u = 1 - 0.25 / pw;
        }

        if (vertex[i].v > 1 - 0.25 / ph)
        {
            vertex[i].v = 1 - 0.25 / ph;
        }

        vertex[i].u += uOffset;
        vertex[i].v += vOffset;
        
        float x = vertex[i].x;
        float y = vertex[i].y;
        
        vertex[i].x = x * gTransform[0][0] + y * gTransform[0][1] + gTransform[0][2];
        vertex[i].y = x * gTransform[1][0] + y * gTransform[1][1] + gTransform[1][2];

    }

    if (gClippingEnabled)
    {
    
        // Clip the polygon to each side of the clipping rectangle. This isn't the
        // fastest way to clip a polygon against a rectangle, but it's probably the
        // simplest.

        ClipPolygon(vertex, numVertices,  1,  0, -gClipRectX1);
        ClipPolygon(vertex, numVertices, -1,  0,  gClipRectX2);
        ClipPolygon(vertex, numVertices,  0,  1, -gClipRectY1);
        ClipPolygon(vertex, numVertices,  0, -1,  gClipRectY2);

    }

    // Compensate for the overbrightening effect.

	float gammaScale = 1.0f / gHUD.GetGammaSlope();
	gEngfuncs.pTriAPI->Color4f(gammaScale * gColor[0], gammaScale * gColor[1], gammaScale * gColor[2], gColor[3]);

    // Output the vertices.

    if (gDrawMode == kSpriteDrawModeFilled)
    {
        gEngfuncs.pTriAPI->Begin(TRI_TRIANGLE_FAN);

        for (int j = 0; j < numVertices; ++j)
        {

            Vector worldPoint;
            
            if (gVGUIEnabled)
            {
                worldPoint.x = (vertex[j].x - gVGUIOffsetX) * gViewportXScale + gViewportXOffset;
                worldPoint.y = (vertex[j].y - gVGUIOffsetY) * gViewportYScale + gViewportYOffset;
                worldPoint.z = 1;
            }
            else
            {
                worldPoint = gViewOrigin +
                    gViewXAxis * vertex[j].x +
                    gViewYAxis * vertex[j].y +
                    gViewZAxis * (gDepth + gDepthOffset);
            }

            gEngfuncs.pTriAPI->TexCoord2f(vertex[j].u, vertex[j].v);
            gEngfuncs.pTriAPI->Vertex3fv((float*)&worldPoint);

        }
    
        gEngfuncs.pTriAPI->End();

    }
    else if (gDrawMode == kSpriteDrawModeBorder)
    {

        gEngfuncs.pTriAPI->Begin(TRI_LINES);

        for (int j = 0; j < numVertices; ++j)
        {

            int k = (j + 1) % numVertices;

            Vector worldPoint1;
            Vector worldPoint2;
            
            if (gVGUIEnabled)
            {

                worldPoint1.x = vertex[j].x - gVGUIOffsetX;
                worldPoint1.y = vertex[j].y - gVGUIOffsetY;
                worldPoint1.z = 1;

                worldPoint2.x = vertex[k].x - gVGUIOffsetX;
                worldPoint2.y = vertex[k].y - gVGUIOffsetY;
                worldPoint2.z = 1;
            
            }
            else
            {
                
                worldPoint1 = gViewOrigin +
                    gViewXAxis * vertex[j].x +
                    gViewYAxis * vertex[j].y +
                    gViewZAxis * (gDepth + gDepthOffset);

                worldPoint2 = gViewOrigin +
                    gViewXAxis * vertex[k].x +
                    gViewYAxis * vertex[k].y +
                    gViewZAxis * (gDepth + gDepthOffset);
            
            }

            gEngfuncs.pTriAPI->TexCoord2f(vertex[j].u, vertex[j].v);
            gEngfuncs.pTriAPI->Vertex3fv((float*)&worldPoint1);

            gEngfuncs.pTriAPI->TexCoord2f(vertex[k].u, vertex[k].v);
            gEngfuncs.pTriAPI->Vertex3fv((float*)&worldPoint2);
        
        }

        gEngfuncs.pTriAPI->End();

    }

    gDepth += kDepthIncrement; 

}