diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /hammer/RenderUtils.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'hammer/RenderUtils.cpp')
| -rw-r--r-- | hammer/RenderUtils.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/hammer/RenderUtils.cpp b/hammer/RenderUtils.cpp new file mode 100644 index 0000000..56fb1a2 --- /dev/null +++ b/hammer/RenderUtils.cpp @@ -0,0 +1,95 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "stdafx.h" +#include "Render2D.h" +#include "RenderUtils.h" +#include "mapview2d.h" +#include "toolinterface.h" + +//----------------------------------------------------------------------------- +// Purpose: Draws the measurements of a brush in the 2D view. +// Input : pRender - +// Mins - +// Maxs - +// nFlags - +//----------------------------------------------------------------------------- +void DrawBoundsText(CRender2D *pRender, const Vector &Mins, const Vector &Maxs, int nFlags) +{ + CMapView2D *pView = (CMapView2D*) pRender->GetView(); + + // Calculate the solid's extents along our 2D view axes. + Vector Extents = Maxs - Mins; + Vector Center = (Mins + Maxs ) * 0.5f; + + for ( int i=0; i<3;i++ ) + Extents[i] = fabs(Extents[i]); + + // Transform the solids mins and maxs to 2D view space. These are used + // for placing the text in the view. + Vector2D projMins, projMaxs, projCenter; + pRender->TransformPoint( projMins, Mins ); + pRender->TransformPoint( projMaxs, Maxs ); + pRender->TransformPoint( projCenter, Center ); + + if( projMins.x > projMaxs.x ) + { + V_swap( projMins.x, projMaxs.x ); + } + + if( projMins.y > projMaxs.y ) + { + V_swap( projMins.y, projMaxs.y ); + } + + // + // display the extents of this brush + // + char extentText[30]; + int nTextX, nTextY; + int nTextFlags; + + pRender->SetTextColor( 255, 255, 255 ); + + // horz + sprintf( extentText, "%.1f", Extents[pView->axHorz] ); + nTextFlags = CRender2D::TEXT_JUSTIFY_HORZ_CENTER; + nTextX = projCenter.x; + + if ( nFlags & DBT_TOP ) + { + nTextY = projMins.y - (HANDLE_RADIUS*3); + nTextFlags |= CRender2D::TEXT_JUSTIFY_TOP; + } + else + { + nTextY = projMaxs.y + (HANDLE_RADIUS*3); + nTextFlags |= CRender2D::TEXT_JUSTIFY_BOTTOM; + } + + pRender->DrawText( extentText, nTextX, nTextY, nTextFlags ); + + // vert + sprintf( extentText, "%.1f", Extents[pView->axVert] ); + nTextFlags = CRender2D::TEXT_JUSTIFY_VERT_CENTER; + nTextY = projCenter.y; + + if ( nFlags & DBT_LEFT ) + { + nTextX = projMins.x - (HANDLE_RADIUS*3); + nTextFlags |= CRender2D::TEXT_JUSTIFY_LEFT; + } + else + { + nTextX = projMaxs.x + (HANDLE_RADIUS*3); + nTextFlags |= CRender2D::TEXT_JUSTIFY_RIGHT; + } + + pRender->DrawText( extentText, nTextX, nTextY, nTextFlags ); +} + + |