added main menus, improved shading
This commit is contained in:
0
fgui/button.cpp
Normal file
0
fgui/button.cpp
Normal file
@@ -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()
|
||||
|
||||
0
fgui/input_field.cpp
Normal file
0
fgui/input_field.cpp
Normal file
@@ -16,23 +16,32 @@ void CFGUI_Label::SetLabel( CUtlString text )
|
||||
m_szText = text;
|
||||
}
|
||||
|
||||
void CFGUI_Label::SetLabelSize( uint32_t nSize )
|
||||
void CFGUI_Label::SetGlyphSize( uint32_t nSize )
|
||||
{
|
||||
|
||||
if (!m_pFont)
|
||||
return;
|
||||
m_fGlyphScale[1] = (float)nSize/m_pFont->glyphHeight;
|
||||
m_fGlyphScale[0] = m_fGlyphScale[1];
|
||||
}
|
||||
|
||||
void CFGUI_Label::Event( FGUI_Event_t event )
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CFGUI_Label::Draw()
|
||||
{
|
||||
IFGUI::SetTextFont(m_pFont);
|
||||
IFGUI::SetTextColor(1, 1, 1, 1);
|
||||
IFGUI::SetGlyphScale(m_fGlyphScale[0], m_fGlyphScale[1]);
|
||||
IFGUI::SetTextPos(m_iPosition[0], m_iPosition[1]);
|
||||
IFGUI::DrawText(m_szText);
|
||||
}
|
||||
|
||||
void CFGUI_Label::Frame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CFGUI_Label::~CFGUI_Label()
|
||||
{
|
||||
|
||||
@@ -19,3 +19,7 @@ void CFGUI_Rect::Draw()
|
||||
IFGUI::DrawRect(m_iPosition[0],m_iPosition[1],m_iSize[0],m_iSize[1]);
|
||||
}
|
||||
|
||||
void CFGUI_Rect::Frame()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@@ -25,6 +25,31 @@ void CFGUI_Widget::SetSize( uint32_t nX, uint32_t nY )
|
||||
|
||||
void CFGUI_Widget::SetParent( CFGUI_Widget *pParent )
|
||||
{
|
||||
|
||||
m_pParent = pParent;
|
||||
}
|
||||
|
||||
void CFGUI_Widget::ComputeOffset( void )
|
||||
{
|
||||
CFGUI_Widget *pParent = m_pParent;
|
||||
while (pParent)
|
||||
{
|
||||
IFGUI::AddOffset(pParent->m_iPosition[0], pParent->m_iPosition[1]);
|
||||
pParent = pParent->m_pParent;
|
||||
};
|
||||
}
|
||||
bool CFGUI_Widget::IsVisible( )
|
||||
{
|
||||
CFGUI_Widget *pWidget = this;
|
||||
while (pWidget)
|
||||
{
|
||||
if (!pWidget->m_bIsVisible)
|
||||
return false;
|
||||
pWidget = pWidget->m_pParent;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
void CFGUI_Widget::SetVisibility( bool bValue )
|
||||
{
|
||||
m_bIsVisible = bValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user