added main menus, improved shading
This commit is contained in:
@@ -3,18 +3,23 @@
|
||||
#include "rendering.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "fgui/widget.h"
|
||||
#include <cctype>
|
||||
#include "ctype.h"
|
||||
|
||||
float fgui_fRectColor[4];
|
||||
float fgui_fTextColor[4];
|
||||
float fgui_fTextPosition[2];
|
||||
float fgui_fGlyphScale[2];
|
||||
CFont *fgui_pTextFont;
|
||||
|
||||
float fgui_fOffset[2];
|
||||
|
||||
IGraphicsPipeline *fgui_RectPipeline;
|
||||
IGraphicsPipeline *fgui_TextPipeline;
|
||||
IVertexBuffer *fgui_pRectangleBuffer;
|
||||
IVertexBuffer *fgui_pUVRectangleBuffer;
|
||||
|
||||
CUtlVector<CFGUI_Widget*> fgui_widgets;
|
||||
|
||||
void IFGUI::Init( void )
|
||||
{
|
||||
|
||||
@@ -22,14 +27,35 @@ void IFGUI::Init( void )
|
||||
|
||||
void IFGUI::Frame( void )
|
||||
{
|
||||
|
||||
for (auto &widget: fgui_widgets)
|
||||
{
|
||||
widget->Frame();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Sets offset of the drawn widget
|
||||
//----------------------------------------------------------------------------
|
||||
void IFGUI::AddOffset( float x, float y)
|
||||
{
|
||||
fgui_fOffset[0] += x;
|
||||
fgui_fOffset[1] += y;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Reset offset of the drawn widget
|
||||
//----------------------------------------------------------------------------
|
||||
void IFGUI::ResetOffset()
|
||||
{
|
||||
fgui_fOffset[0] = 0;
|
||||
fgui_fOffset[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Creates new widget in the world
|
||||
//----------------------------------------------------------------------------
|
||||
CUtlVector<CFGUI_Widget*> fgui_widgets;
|
||||
void IFGUI::AppendWidget( CFGUI_Widget *pWidget )
|
||||
{
|
||||
fgui_widgets.AppendTail(pWidget);
|
||||
@@ -81,8 +107,8 @@ void IFGUI::DrawRect( int32_t iPosX, int32_t iPosY, uint32_t uSizeX, uint32_t uS
|
||||
|
||||
constants.nResolution[0] = g_nWindowWidth;
|
||||
constants.nResolution[1] = g_nWindowHeight;
|
||||
constants.nPosition[0] = iPosX;
|
||||
constants.nPosition[1] = iPosY;
|
||||
constants.nPosition[0] = fgui_fOffset[0] + iPosX;
|
||||
constants.nPosition[1] = fgui_fOffset[1] + iPosY;
|
||||
constants.nSize[0] = uSizeX;
|
||||
constants.nSize[1] = uSizeY;
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
@@ -131,6 +157,11 @@ CFont *IFGUI::LoadFont( CUtlString szFontPath )
|
||||
pFont->nGlyphsPerColumn = nElementsHeight;
|
||||
return pFont;
|
||||
}
|
||||
void IFGUI::SetGlyphScale( float x, float y )
|
||||
{
|
||||
fgui_fGlyphScale[0] = x;
|
||||
fgui_fGlyphScale[1] = y;
|
||||
};
|
||||
|
||||
void IFGUI::SetTextFont( CFont *pFont )
|
||||
{
|
||||
@@ -159,7 +190,9 @@ void IFGUI::DrawText( CUtlString psz )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
IRenderer::BindPipeline(fgui_TextPipeline);
|
||||
|
||||
struct RectConstants_t
|
||||
{
|
||||
uint32_t nResolution[2];
|
||||
@@ -174,10 +207,10 @@ void IFGUI::DrawText( CUtlString psz )
|
||||
|
||||
constants.nResolution[0] = g_nWindowWidth;
|
||||
constants.nResolution[1] = g_nWindowHeight;
|
||||
constants.nPosition[0] = fgui_fTextPosition[0];
|
||||
constants.nPosition[1] = fgui_fTextPosition[1];
|
||||
constants.nSize[0] = fgui_pTextFont->glyphWidth;
|
||||
constants.nSize[1] = fgui_pTextFont->glyphHeight;
|
||||
constants.nPosition[0] = fgui_fOffset[0] + fgui_fTextPosition[0];
|
||||
constants.nPosition[1] = fgui_fOffset[1] + fgui_fTextPosition[1];
|
||||
constants.nSize[0] = fgui_pTextFont->glyphWidth * fgui_fGlyphScale[0];
|
||||
constants.nSize[1] = fgui_pTextFont->glyphHeight * fgui_fGlyphScale[1];
|
||||
constants.fGlyphSize[0] = 1.0 / fgui_pTextFont->nGlyphsPerRow;
|
||||
constants.fGlyphSize[1] = 1.0 / fgui_pTextFont->nGlyphsPerColumn;
|
||||
constants.nFont = ITextureManager::GetTextureID(fgui_pTextFont->pTexture);
|
||||
@@ -191,10 +224,9 @@ void IFGUI::DrawText( CUtlString psz )
|
||||
if (isprint(psz[i]) && !isspace(psz[i]))
|
||||
{
|
||||
IRenderer::SetConstants(sizeof(RectConstants_t), &constants);
|
||||
IRenderer::PushBindings();
|
||||
IRenderer::Draw(fgui_pUVRectangleBuffer, NULL);
|
||||
}
|
||||
constants.nPosition[0] += fgui_pTextFont->glyphWidth;
|
||||
constants.nPosition[0] += constants.nSize[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +250,7 @@ void CFGUI_Rendering::Init()
|
||||
48,
|
||||
8,
|
||||
{{0,0,VERTEX_FORMAT_X32Y32}},
|
||||
{IMAGE_FORMAT_R8G8B8A8},
|
||||
{IMAGE_FORMAT_WINDOW},
|
||||
true
|
||||
);
|
||||
fgui_TextPipeline = IRenderer::CreateGraphicsPipeline(
|
||||
@@ -267,13 +299,8 @@ void CFGUI_Rendering::Init()
|
||||
|
||||
void CFGUI_Rendering::Frame( float fDelta )
|
||||
{
|
||||
IRenderer::Barrier(BARRIER_STAGE_TOP, BARRIER_STAGE_COLOR_OUTPUT, {}, {
|
||||
{
|
||||
BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
IRenderer::GetOutputImage(),
|
||||
}
|
||||
});
|
||||
fgui_TextPipeline->PushBindings();
|
||||
|
||||
IRenderer::Begin(g_nWindowWidth, g_nWindowHeight, {
|
||||
{
|
||||
IRenderer::GetOutputImage(),
|
||||
@@ -286,16 +313,15 @@ void CFGUI_Rendering::Frame( float fDelta )
|
||||
IRenderer::SetDepthMode(DEPTH_MODE_LESS);
|
||||
for (auto &widget: fgui_widgets)
|
||||
{
|
||||
if (!widget->IsVisible())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IFGUI::ResetOffset();
|
||||
widget->ComputeOffset();
|
||||
widget->Draw();
|
||||
}
|
||||
IRenderer::End();
|
||||
IRenderer::Barrier(BARRIER_STAGE_COLOR_OUTPUT, BARRIER_STAGE_BOTTOM, {}, {
|
||||
{
|
||||
BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
IRenderer::GetOutputImage(),
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
void CFGUI_Rendering::Deinit()
|
||||
|
||||
Reference in New Issue
Block a user