mirror of
https://github.com/celisej567/cool-source-archive.git
synced 2026-01-04 14:11:16 +03:00
added VS2019 support
debug build requires a little bit of work
This commit is contained in:
@@ -1,292 +1,292 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/CircularProgressBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CircularProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::CircularProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
m_iProgressDirection = CircularProgressBar::PROGRESS_CCW;
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
m_nTextureId[i] = -1;
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
m_iStartSegment = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::~CircularProgressBar()
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( vgui::surface() && m_nTextureId[i] )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_nTextureId[i] );
|
||||
m_nTextureId[i] = -1;
|
||||
}
|
||||
|
||||
delete [] m_pszImageName[i];
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
delete [] m_pszImageName[i];
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("fg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetFgImage( imageName );
|
||||
}
|
||||
imageName = inResourceData->GetString("bg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetBgImage( imageName );
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("CircularProgressBar.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("CircularProgressBar.BgColor", pScheme));
|
||||
SetBorder(NULL);
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( m_pszImageName[i] && strlen( m_pszImageName[i] ) > 0 )
|
||||
{
|
||||
if ( m_nTextureId[i] == -1 )
|
||||
{
|
||||
m_nTextureId[i] = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( m_nTextureId[i], m_pszImageName[i], true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::SetImage(const char *imageName, progress_textures_t iPos)
|
||||
{
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
|
||||
if ( m_pszImageName[iPos] && ( m_lenImageName[iPos] < len ) )
|
||||
{
|
||||
// If we already have a buffer, but it is too short, then free the buffer
|
||||
delete [] m_pszImageName[iPos];
|
||||
m_pszImageName[iPos] = NULL;
|
||||
m_lenImageName[iPos] = 0;
|
||||
}
|
||||
|
||||
if ( !m_pszImageName[iPos] )
|
||||
{
|
||||
m_pszImageName[iPos] = new char[ len ];
|
||||
m_lenImageName[iPos] = len;
|
||||
}
|
||||
|
||||
Q_snprintf( m_pszImageName[iPos], len, "%s%s", pszDir, imageName );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::PaintBackground()
|
||||
{
|
||||
// If we don't have a Bg image, use the foreground
|
||||
int iTextureID = m_nTextureId[PROGRESS_TEXTURE_BG] != -1 ? m_nTextureId[PROGRESS_TEXTURE_BG] : m_nTextureId[PROGRESS_TEXTURE_FG];
|
||||
vgui::surface()->DrawSetTexture( iTextureID );
|
||||
vgui::surface()->DrawSetColor( GetBgColor() );
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
vgui::surface()->DrawTexturedRect( 0, 0, wide, tall );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::Paint()
|
||||
{
|
||||
float flProgress = GetProgress();
|
||||
float flEndAngle;
|
||||
|
||||
if ( m_iProgressDirection == PROGRESS_CW )
|
||||
{
|
||||
flEndAngle = flProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
flEndAngle = ( 1.0 - flProgress );
|
||||
}
|
||||
|
||||
DrawCircleSegment( GetFgColor(), flEndAngle, ( m_iProgressDirection == PROGRESS_CW ) );
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float minProgressRadians;
|
||||
|
||||
float vert1x;
|
||||
float vert1y;
|
||||
float vert2x;
|
||||
float vert2y;
|
||||
|
||||
int swipe_dir_x;
|
||||
int swipe_dir_y;
|
||||
} circular_progress_segment_t;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
// This defines the properties of the 8 circle segments
|
||||
// in the circular progress bar.
|
||||
circular_progress_segment_t Segments[8] =
|
||||
{
|
||||
{ 0.0, 0.5, 0.0, 1.0, 0.0, 1, 0 },
|
||||
{ M_PI * 0.25, 1.0, 0.0, 1.0, 0.5, 0, 1 },
|
||||
{ M_PI * 0.5, 1.0, 0.5, 1.0, 1.0, 0, 1 },
|
||||
{ M_PI * 0.75, 1.0, 1.0, 0.5, 1.0, -1, 0 },
|
||||
{ M_PI, 0.5, 1.0, 0.0, 1.0, -1, 0 },
|
||||
{ M_PI * 1.25, 0.0, 1.0, 0.0, 0.5, 0, -1 },
|
||||
{ M_PI * 1.5, 0.0, 0.5, 0.0, 0.0, 0, -1 },
|
||||
{ M_PI * 1.75, 0.0, 0.0, 0.5, 0.0, 1, 0 },
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#define SEGMENT_ANGLE ( M_PI / 4 )
|
||||
|
||||
// function to draw from A to B degrees, with a direction
|
||||
// we draw starting from the top ( 0 progress )
|
||||
void CircularProgressBar::DrawCircleSegment( Color c, float flEndProgress, bool bClockwise )
|
||||
{
|
||||
if ( m_nTextureId[PROGRESS_TEXTURE_FG] == -1 )
|
||||
return;
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
float flWide = (float)wide;
|
||||
float flTall = (float)tall;
|
||||
|
||||
float flHalfWide = (float)wide / 2;
|
||||
float flHalfTall = (float)tall / 2;
|
||||
|
||||
vgui::surface()->DrawSetTexture( m_nTextureId[PROGRESS_TEXTURE_FG] );
|
||||
vgui::surface()->DrawSetColor( c );
|
||||
|
||||
// TODO - if we want to progress CCW, reverse a few things
|
||||
|
||||
float flEndProgressRadians = flEndProgress * M_PI * 2;
|
||||
|
||||
int cur_wedge = m_iStartSegment;
|
||||
for ( int i=0;i<8;i++ )
|
||||
{
|
||||
if ( flEndProgressRadians > Segments[cur_wedge].minProgressRadians)
|
||||
{
|
||||
vgui::Vertex_t v[3];
|
||||
|
||||
// vert 0 is ( 0.5, 0.5 )
|
||||
v[0].m_Position.Init( flHalfWide, flHalfTall );
|
||||
v[0].m_TexCoord.Init( 0.5f, 0.5f );
|
||||
|
||||
float flInternalProgress = flEndProgressRadians - Segments[cur_wedge].minProgressRadians;
|
||||
|
||||
if ( flInternalProgress < SEGMENT_ANGLE )
|
||||
{
|
||||
// Calc how much of this slice we should be drawing
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flInternalProgress = SEGMENT_ANGLE - flInternalProgress;
|
||||
}
|
||||
|
||||
float flTan = tan(flInternalProgress);
|
||||
|
||||
float flDeltaX, flDeltaY;
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flDeltaX = ( flHalfWide - flHalfTall * flTan ) * Segments[i].swipe_dir_x;
|
||||
flDeltaY = ( flHalfTall - flHalfWide * flTan ) * Segments[i].swipe_dir_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
flDeltaX = flHalfTall * flTan * Segments[i].swipe_dir_x;
|
||||
flDeltaY = flHalfWide * flTan * Segments[i].swipe_dir_y;
|
||||
}
|
||||
|
||||
v[2].m_Position.Init( Segments[i].vert1x * flWide + flDeltaX, Segments[i].vert1y * flTall + flDeltaY );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert1x + ( flDeltaX / flHalfWide ) * 0.5, Segments[i].vert1y + ( flDeltaY / flHalfTall ) * 0.5 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// full segment, easy calculation
|
||||
v[2].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert2x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert2y - 0.5 ) );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert2x, Segments[i].vert2y );
|
||||
}
|
||||
|
||||
// vert 2 is ( Segments[i].vert1x, Segments[i].vert1y )
|
||||
v[1].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert1x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert1y - 0.5 ) );
|
||||
v[1].m_TexCoord.Init( Segments[i].vert1x, Segments[i].vert1y );
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 3, v );
|
||||
}
|
||||
|
||||
cur_wedge++;
|
||||
if ( cur_wedge >= 8)
|
||||
cur_wedge = 0;
|
||||
}
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui_controls/CircularProgressBar.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
//#include <vgui/ILocalize.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <KeyValues.h>
|
||||
|
||||
//#include "mathlib/mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
DECLARE_BUILD_FACTORY( CircularProgressBar );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::CircularProgressBar(Panel *parent, const char *panelName) : ProgressBar(parent, panelName)
|
||||
{
|
||||
m_iProgressDirection = CircularProgressBar::PROGRESS_CCW;
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
m_nTextureId[i] = -1;
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
m_iStartSegment = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CircularProgressBar::~CircularProgressBar()
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( vgui::surface() && m_nTextureId[i] )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_nTextureId[i] );
|
||||
m_nTextureId[i] = -1;
|
||||
}
|
||||
|
||||
delete [] m_pszImageName[i];
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySettings(KeyValues *inResourceData)
|
||||
{
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
delete [] m_pszImageName[i];
|
||||
m_pszImageName[i] = NULL;
|
||||
m_lenImageName[i] = 0;
|
||||
}
|
||||
|
||||
const char *imageName = inResourceData->GetString("fg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetFgImage( imageName );
|
||||
}
|
||||
imageName = inResourceData->GetString("bg_image", "");
|
||||
if (*imageName)
|
||||
{
|
||||
SetBgImage( imageName );
|
||||
}
|
||||
|
||||
BaseClass::ApplySettings( inResourceData );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
BaseClass::ApplySchemeSettings(pScheme);
|
||||
|
||||
SetFgColor(GetSchemeColor("CircularProgressBar.FgColor", pScheme));
|
||||
SetBgColor(GetSchemeColor("CircularProgressBar.BgColor", pScheme));
|
||||
SetBorder(NULL);
|
||||
|
||||
for ( int i = 0; i < NUM_PROGRESS_TEXTURES; i++ )
|
||||
{
|
||||
if ( m_pszImageName[i] && strlen( m_pszImageName[i] ) > 0 )
|
||||
{
|
||||
if ( m_nTextureId[i] == -1 )
|
||||
{
|
||||
m_nTextureId[i] = surface()->CreateNewTextureID();
|
||||
}
|
||||
|
||||
surface()->DrawSetTextureFile( m_nTextureId[i], m_pszImageName[i], true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets an image by file name
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::SetImage(const char *imageName, progress_textures_t iPos)
|
||||
{
|
||||
const char *pszDir = "vgui/";
|
||||
int len = Q_strlen(imageName) + 1;
|
||||
len += strlen(pszDir);
|
||||
|
||||
if ( m_pszImageName[iPos] && ( m_lenImageName[iPos] < len ) )
|
||||
{
|
||||
// If we already have a buffer, but it is too short, then free the buffer
|
||||
delete [] m_pszImageName[iPos];
|
||||
m_pszImageName[iPos] = NULL;
|
||||
m_lenImageName[iPos] = 0;
|
||||
}
|
||||
|
||||
if ( !m_pszImageName[iPos] )
|
||||
{
|
||||
m_pszImageName[iPos] = new char[ len ];
|
||||
m_lenImageName[iPos] = len;
|
||||
}
|
||||
|
||||
Q_snprintf( m_pszImageName[iPos], len, "%s%s", pszDir, imageName );
|
||||
InvalidateLayout(false, true); // force applyschemesettings to run
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::PaintBackground()
|
||||
{
|
||||
// If we don't have a Bg image, use the foreground
|
||||
int iTextureID = m_nTextureId[PROGRESS_TEXTURE_BG] != -1 ? m_nTextureId[PROGRESS_TEXTURE_BG] : m_nTextureId[PROGRESS_TEXTURE_FG];
|
||||
vgui::surface()->DrawSetTexture( iTextureID );
|
||||
vgui::surface()->DrawSetColor( GetBgColor() );
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
vgui::surface()->DrawTexturedRect( 0, 0, wide, tall );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CircularProgressBar::Paint()
|
||||
{
|
||||
float flProgress = GetProgress();
|
||||
float flEndAngle;
|
||||
|
||||
if ( m_iProgressDirection == PROGRESS_CW )
|
||||
{
|
||||
flEndAngle = flProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
flEndAngle = ( 1.0 - flProgress );
|
||||
}
|
||||
|
||||
DrawCircleSegment( GetFgColor(), flEndAngle, ( m_iProgressDirection == PROGRESS_CW ) );
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float minProgressRadians;
|
||||
|
||||
float vert1x;
|
||||
float vert1y;
|
||||
float vert2x;
|
||||
float vert2y;
|
||||
|
||||
int swipe_dir_x;
|
||||
int swipe_dir_y;
|
||||
} circular_progress_segment_t;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
// This defines the properties of the 8 circle segments
|
||||
// in the circular progress bar.
|
||||
circular_progress_segment_t Segments[8] =
|
||||
{
|
||||
{ 0.0, 0.5, 0.0, 1.0, 0.0, 1, 0 },
|
||||
{ M_PI * 0.25, 1.0, 0.0, 1.0, 0.5, 0, 1 },
|
||||
{ M_PI * 0.5, 1.0, 0.5, 1.0, 1.0, 0, 1 },
|
||||
{ M_PI * 0.75, 1.0, 1.0, 0.5, 1.0, -1, 0 },
|
||||
{ M_PI, 0.5, 1.0, 0.0, 1.0, -1, 0 },
|
||||
{ M_PI * 1.25, 0.0, 1.0, 0.0, 0.5, 0, -1 },
|
||||
{ M_PI * 1.5, 0.0, 0.5, 0.0, 0.0, 0, -1 },
|
||||
{ M_PI * 1.75, 0.0, 0.0, 0.5, 0.0, 1, 0 },
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#define SEGMENT_ANGLE ( M_PI / 4 )
|
||||
|
||||
// function to draw from A to B degrees, with a direction
|
||||
// we draw starting from the top ( 0 progress )
|
||||
void CircularProgressBar::DrawCircleSegment( Color c, float flEndProgress, bool bClockwise )
|
||||
{
|
||||
if ( m_nTextureId[PROGRESS_TEXTURE_FG] == -1 )
|
||||
return;
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
|
||||
float flWide = (float)wide;
|
||||
float flTall = (float)tall;
|
||||
|
||||
float flHalfWide = (float)wide / 2;
|
||||
float flHalfTall = (float)tall / 2;
|
||||
|
||||
vgui::surface()->DrawSetTexture( m_nTextureId[PROGRESS_TEXTURE_FG] );
|
||||
vgui::surface()->DrawSetColor( c );
|
||||
|
||||
// TODO - if we want to progress CCW, reverse a few things
|
||||
|
||||
float flEndProgressRadians = flEndProgress * M_PI * 2;
|
||||
|
||||
int cur_wedge = m_iStartSegment;
|
||||
for ( int i=0;i<8;i++ )
|
||||
{
|
||||
if ( flEndProgressRadians > Segments[cur_wedge].minProgressRadians)
|
||||
{
|
||||
vgui::Vertex_t v[3];
|
||||
|
||||
// vert 0 is ( 0.5, 0.5 )
|
||||
v[0].m_Position.Init( flHalfWide, flHalfTall );
|
||||
v[0].m_TexCoord.Init( 0.5f, 0.5f );
|
||||
|
||||
float flInternalProgress = flEndProgressRadians - Segments[cur_wedge].minProgressRadians;
|
||||
|
||||
if ( flInternalProgress < SEGMENT_ANGLE )
|
||||
{
|
||||
// Calc how much of this slice we should be drawing
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flInternalProgress = SEGMENT_ANGLE - flInternalProgress;
|
||||
}
|
||||
|
||||
float flTan = tan(flInternalProgress);
|
||||
|
||||
float flDeltaX, flDeltaY;
|
||||
|
||||
if ( i % 2 == 1 )
|
||||
{
|
||||
flDeltaX = ( flHalfWide - flHalfTall * flTan ) * Segments[i].swipe_dir_x;
|
||||
flDeltaY = ( flHalfTall - flHalfWide * flTan ) * Segments[i].swipe_dir_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
flDeltaX = flHalfTall * flTan * Segments[i].swipe_dir_x;
|
||||
flDeltaY = flHalfWide * flTan * Segments[i].swipe_dir_y;
|
||||
}
|
||||
|
||||
v[2].m_Position.Init( Segments[i].vert1x * flWide + flDeltaX, Segments[i].vert1y * flTall + flDeltaY );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert1x + ( flDeltaX / flHalfWide ) * 0.5, Segments[i].vert1y + ( flDeltaY / flHalfTall ) * 0.5 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// full segment, easy calculation
|
||||
v[2].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert2x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert2y - 0.5 ) );
|
||||
v[2].m_TexCoord.Init( Segments[i].vert2x, Segments[i].vert2y );
|
||||
}
|
||||
|
||||
// vert 2 is ( Segments[i].vert1x, Segments[i].vert1y )
|
||||
v[1].m_Position.Init( flHalfWide + flWide * ( Segments[i].vert1x - 0.5 ), flHalfTall + flTall * ( Segments[i].vert1y - 0.5 ) );
|
||||
v[1].m_TexCoord.Init( Segments[i].vert1x, Segments[i].vert1y );
|
||||
|
||||
vgui::surface()->DrawTexturedPolygon( 3, v );
|
||||
}
|
||||
|
||||
cur_wedge++;
|
||||
if ( cur_wedge >= 8)
|
||||
cur_wedge = 0;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,406 +1,406 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
// This class is a message box that has two buttons, ok and cancel instead of
|
||||
// just the ok button of a message box. We use a message box class for the ok button
|
||||
// and implement another button here.
|
||||
//=============================================================================//
|
||||
|
||||
#include <math.h>
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IPanel.h>
|
||||
|
||||
#include <vgui_controls/Tooltip.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
static vgui::DHANDLE< TextEntry > s_TooltipWindow;
|
||||
static int s_iTooltipWindowCount = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BaseTooltip::BaseTooltip(Panel *parent, const char *text)
|
||||
{
|
||||
SetText(text);
|
||||
|
||||
_displayOnOneLine = false;
|
||||
_makeVisible = false;
|
||||
_isDirty = false;
|
||||
_enabled = true;
|
||||
|
||||
_tooltipDelay = 500; // default delay for opening tooltips
|
||||
_delay = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reset the tooltip delay timer
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ResetDelay()
|
||||
{
|
||||
_isDirty = true;
|
||||
_delay = system()->GetTimeMillis() + _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipDelay( int tooltipDelay )
|
||||
{
|
||||
_tooltipDelay = tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
int BaseTooltip::GetTooltipDelay()
|
||||
{
|
||||
return _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on one line only
|
||||
// Default is multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToSingleLine()
|
||||
{
|
||||
_displayOnOneLine = true;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToMultiLine()
|
||||
{
|
||||
_displayOnOneLine = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
_makeVisible = true;
|
||||
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
void BaseTooltip::SetEnabled( bool bState )
|
||||
{
|
||||
_enabled = bState;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BaseTooltip::ShouldLayout( void )
|
||||
{
|
||||
if (!_makeVisible)
|
||||
return false;
|
||||
|
||||
if (_delay > system()->GetTimeMillis())
|
||||
return false;
|
||||
|
||||
// We only need to layout when we first become visible
|
||||
if ( !_isDirty )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::HideTooltip()
|
||||
{
|
||||
_makeVisible = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetText(const char *text)
|
||||
{
|
||||
_isDirty = true;
|
||||
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
|
||||
if (m_Text.Size() > 0)
|
||||
{
|
||||
m_Text.RemoveAll();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < strlen(text); i++)
|
||||
{
|
||||
m_Text.AddToTail(text[i]);
|
||||
}
|
||||
m_Text.AddToTail('\0');
|
||||
|
||||
if (s_TooltipWindow.Get() && m_pParent == s_TooltipWindow.Get()->GetParent())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *BaseTooltip::GetText()
|
||||
{
|
||||
return m_Text.Base();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Position the tool tip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::PositionWindow( Panel *pTipPanel )
|
||||
{
|
||||
int iTipW, iTipH;
|
||||
pTipPanel->GetSize( iTipW, iTipH );
|
||||
|
||||
int cursorX, cursorY;
|
||||
input()->GetCursorPos(cursorX, cursorY);
|
||||
|
||||
int wide, tall;
|
||||
surface()->GetScreenSize(wide, tall);
|
||||
|
||||
if (wide - iTipW > cursorX)
|
||||
{
|
||||
cursorY += 20;
|
||||
// menu hanging right
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX, cursorY - iTipH - 20);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging left
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY - iTipH - 20 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::TextTooltip(Panel *parent, const char *text) : BaseTooltip( parent, text )
|
||||
{
|
||||
if (!s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow = new TextEntry(NULL, "tooltip");
|
||||
|
||||
s_TooltipWindow->InvalidateLayout(false, true);
|
||||
|
||||
// this bit of hackery is necessary because tooltips don't get ApplySchemeSettings called from their parents
|
||||
IScheme *pScheme = scheme()->GetIScheme( s_TooltipWindow->GetScheme() );
|
||||
s_TooltipWindow->SetBgColor(s_TooltipWindow->GetSchemeColor("Tooltip.BgColor", s_TooltipWindow->GetBgColor(), pScheme));
|
||||
s_TooltipWindow->SetFgColor(s_TooltipWindow->GetSchemeColor("Tooltip.TextColor", s_TooltipWindow->GetFgColor(), pScheme));
|
||||
s_TooltipWindow->SetBorder(pScheme->GetBorder("ToolTipBorder"));
|
||||
s_TooltipWindow->SetFont( pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
s_iTooltipWindowCount++;
|
||||
|
||||
// this line prevents the main window from losing focus
|
||||
// when a tooltip pops up
|
||||
s_TooltipWindow->MakePopup(false, true);
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
SetText(text);
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
s_TooltipWindow->SetEditable(false);
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::~TextTooltip()
|
||||
{
|
||||
if (--s_iTooltipWindowCount < 1)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->MarkForDeletion();
|
||||
}
|
||||
s_TooltipWindow = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SetText(const char *text)
|
||||
{
|
||||
BaseTooltip::SetText( text );
|
||||
|
||||
if (s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the font from the scheme
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
if ( s_TooltipWindow )
|
||||
{
|
||||
s_TooltipWindow->SetFont(pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
int nLen = s_TooltipWindow->GetTextLength();
|
||||
|
||||
if ( nLen <= 0 )
|
||||
{
|
||||
// Empty tool tip, no need to show it
|
||||
_makeVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
char *pBuf = (char*)_alloca( nLen+1 );
|
||||
s_TooltipWindow->GetText( pBuf, nLen+1 );
|
||||
Panel *pCurrentParent = s_TooltipWindow->GetParent();
|
||||
|
||||
_isDirty = _isDirty || ( pCurrentParent != currentPanel );
|
||||
s_TooltipWindow->SetText( m_Text.Base() );
|
||||
s_TooltipWindow->SetParent(currentPanel);
|
||||
}
|
||||
BaseTooltip::ShowTooltip( currentPanel );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::PerformLayout()
|
||||
{
|
||||
if ( !ShouldLayout() )
|
||||
return;
|
||||
// we're ready, just make us visible
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
_isDirty = false;
|
||||
|
||||
s_TooltipWindow->SetVisible(true);
|
||||
s_TooltipWindow->MakePopup( false, true );
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
// relayout the textwindow immediately so that we know it's size
|
||||
//m_pTextEntry->InvalidateLayout(true);
|
||||
|
||||
SizeTextWindow();
|
||||
PositionWindow( s_TooltipWindow );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Size the text window so all the text fits inside it.
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SizeTextWindow()
|
||||
{
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
if (_displayOnOneLine)
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
int wide, tall;
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
double newWide = sqrt( (2.0/1) * wide * tall );
|
||||
double newTall = (1/2) * newWide;
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetSize((int)newWide, (int)newTall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
|
||||
if (( wide < 100 ) && ( s_TooltipWindow->GetNumLines() == 2) )
|
||||
{
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
while ( (float)wide/(float)tall < 2 )
|
||||
{
|
||||
s_TooltipWindow->SetSize( wide + 1, tall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
}
|
||||
}
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
// ivgui()->DPrintf("End Ratio: %f\n", (float)wide/(float)tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::HideTooltip()
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
BaseTooltip::HideTooltip();
|
||||
}
|
||||
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
// This class is a message box that has two buttons, ok and cancel instead of
|
||||
// just the ok button of a message box. We use a message box class for the ok button
|
||||
// and implement another button here.
|
||||
//=============================================================================//
|
||||
|
||||
//#include <math.h>
|
||||
//#define PROTECTED_THINGS_DISABLE
|
||||
|
||||
#include <vgui/IInput.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/IPanel.h>
|
||||
|
||||
#include <vgui_controls/Tooltip.h>
|
||||
#include <vgui_controls/TextEntry.h>
|
||||
#include <vgui_controls/Controls.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
static vgui::DHANDLE< TextEntry > s_TooltipWindow;
|
||||
static int s_iTooltipWindowCount = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
BaseTooltip::BaseTooltip(Panel *parent, const char *text)
|
||||
{
|
||||
SetText(text);
|
||||
|
||||
_displayOnOneLine = false;
|
||||
_makeVisible = false;
|
||||
_isDirty = false;
|
||||
_enabled = true;
|
||||
|
||||
_tooltipDelay = 500; // default delay for opening tooltips
|
||||
_delay = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reset the tooltip delay timer
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ResetDelay()
|
||||
{
|
||||
_isDirty = true;
|
||||
_delay = system()->GetTimeMillis() + _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipDelay( int tooltipDelay )
|
||||
{
|
||||
_tooltipDelay = tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip delay before a tooltip comes up.
|
||||
//-----------------------------------------------------------------------------
|
||||
int BaseTooltip::GetTooltipDelay()
|
||||
{
|
||||
return _tooltipDelay;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on one line only
|
||||
// Default is multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToSingleLine()
|
||||
{
|
||||
_displayOnOneLine = true;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tool tip to display on multiple lines.
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetTooltipFormatToMultiLine()
|
||||
{
|
||||
_displayOnOneLine = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
_makeVisible = true;
|
||||
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
void BaseTooltip::SetEnabled( bool bState )
|
||||
{
|
||||
_enabled = bState;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool BaseTooltip::ShouldLayout( void )
|
||||
{
|
||||
if (!_makeVisible)
|
||||
return false;
|
||||
|
||||
if (_delay > system()->GetTimeMillis())
|
||||
return false;
|
||||
|
||||
// We only need to layout when we first become visible
|
||||
if ( !_isDirty )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::HideTooltip()
|
||||
{
|
||||
_makeVisible = false;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::SetText(const char *text)
|
||||
{
|
||||
_isDirty = true;
|
||||
|
||||
if (!text)
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
|
||||
if (m_Text.Size() > 0)
|
||||
{
|
||||
m_Text.RemoveAll();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < strlen(text); i++)
|
||||
{
|
||||
m_Text.AddToTail(text[i]);
|
||||
}
|
||||
m_Text.AddToTail('\0');
|
||||
|
||||
if (s_TooltipWindow.Get() && m_pParent == s_TooltipWindow.Get()->GetParent())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *BaseTooltip::GetText()
|
||||
{
|
||||
return m_Text.Base();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Position the tool tip
|
||||
//-----------------------------------------------------------------------------
|
||||
void BaseTooltip::PositionWindow( Panel *pTipPanel )
|
||||
{
|
||||
int iTipW, iTipH;
|
||||
pTipPanel->GetSize( iTipW, iTipH );
|
||||
|
||||
int cursorX, cursorY;
|
||||
input()->GetCursorPos(cursorX, cursorY);
|
||||
|
||||
int wide, tall;
|
||||
surface()->GetScreenSize(wide, tall);
|
||||
|
||||
if (wide - iTipW > cursorX)
|
||||
{
|
||||
cursorY += 20;
|
||||
// menu hanging right
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX, cursorY - iTipH - 20);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging left
|
||||
if (tall - iTipH > cursorY)
|
||||
{
|
||||
// menu hanging down
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY);
|
||||
}
|
||||
else
|
||||
{
|
||||
// menu hanging up
|
||||
pTipPanel->SetPos(cursorX - iTipW, cursorY - iTipH - 20 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::TextTooltip(Panel *parent, const char *text) : BaseTooltip( parent, text )
|
||||
{
|
||||
if (!s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow = new TextEntry(NULL, "tooltip");
|
||||
|
||||
s_TooltipWindow->InvalidateLayout(false, true);
|
||||
|
||||
// this bit of hackery is necessary because tooltips don't get ApplySchemeSettings called from their parents
|
||||
IScheme *pScheme = scheme()->GetIScheme( s_TooltipWindow->GetScheme() );
|
||||
s_TooltipWindow->SetBgColor(s_TooltipWindow->GetSchemeColor("Tooltip.BgColor", s_TooltipWindow->GetBgColor(), pScheme));
|
||||
s_TooltipWindow->SetFgColor(s_TooltipWindow->GetSchemeColor("Tooltip.TextColor", s_TooltipWindow->GetFgColor(), pScheme));
|
||||
s_TooltipWindow->SetBorder(pScheme->GetBorder("ToolTipBorder"));
|
||||
s_TooltipWindow->SetFont( pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
s_iTooltipWindowCount++;
|
||||
|
||||
// this line prevents the main window from losing focus
|
||||
// when a tooltip pops up
|
||||
s_TooltipWindow->MakePopup(false, true);
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
SetText(text);
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
s_TooltipWindow->SetEditable(false);
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
TextTooltip::~TextTooltip()
|
||||
{
|
||||
if (--s_iTooltipWindowCount < 1)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->MarkForDeletion();
|
||||
}
|
||||
s_TooltipWindow = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Set the tooltip text
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SetText(const char *text)
|
||||
{
|
||||
BaseTooltip::SetText( text );
|
||||
|
||||
if (s_TooltipWindow.Get())
|
||||
{
|
||||
s_TooltipWindow->SetText(m_Text.Base());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the font from the scheme
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ApplySchemeSettings(IScheme *pScheme)
|
||||
{
|
||||
if ( s_TooltipWindow )
|
||||
{
|
||||
s_TooltipWindow->SetFont(pScheme->GetFont("DefaultSmall", s_TooltipWindow->IsProportional()));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::ShowTooltip(Panel *currentPanel)
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
int nLen = s_TooltipWindow->GetTextLength();
|
||||
|
||||
if ( nLen <= 0 )
|
||||
{
|
||||
// Empty tool tip, no need to show it
|
||||
_makeVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
char *pBuf = (char*)_alloca( nLen+1 );
|
||||
s_TooltipWindow->GetText( pBuf, nLen+1 );
|
||||
Panel *pCurrentParent = s_TooltipWindow->GetParent();
|
||||
|
||||
_isDirty = _isDirty || ( pCurrentParent != currentPanel );
|
||||
s_TooltipWindow->SetText( m_Text.Base() );
|
||||
s_TooltipWindow->SetParent(currentPanel);
|
||||
}
|
||||
BaseTooltip::ShowTooltip( currentPanel );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::PerformLayout()
|
||||
{
|
||||
if ( !ShouldLayout() )
|
||||
return;
|
||||
// we're ready, just make us visible
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
_isDirty = false;
|
||||
|
||||
s_TooltipWindow->SetVisible(true);
|
||||
s_TooltipWindow->MakePopup( false, true );
|
||||
s_TooltipWindow->SetKeyBoardInputEnabled( false );
|
||||
s_TooltipWindow->SetMouseInputEnabled( false );
|
||||
|
||||
// relayout the textwindow immediately so that we know it's size
|
||||
//m_pTextEntry->InvalidateLayout(true);
|
||||
|
||||
SizeTextWindow();
|
||||
PositionWindow( s_TooltipWindow );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Size the text window so all the text fits inside it.
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::SizeTextWindow()
|
||||
{
|
||||
if ( !s_TooltipWindow.Get() )
|
||||
return;
|
||||
|
||||
if (_displayOnOneLine)
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We want the tool tip to be one line
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
int wide, tall;
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
double newWide = sqrt( (2.0/1) * wide * tall );
|
||||
double newTall = (1/2) * newWide;
|
||||
s_TooltipWindow->SetMultiline(true);
|
||||
s_TooltipWindow->SetSize((int)newWide, (int)newTall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
|
||||
if (( wide < 100 ) && ( s_TooltipWindow->GetNumLines() == 2) )
|
||||
{
|
||||
s_TooltipWindow->SetMultiline(false);
|
||||
s_TooltipWindow->SetToFullWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
while ( (float)wide/(float)tall < 2 )
|
||||
{
|
||||
s_TooltipWindow->SetSize( wide + 1, tall );
|
||||
s_TooltipWindow->SetToFullHeight();
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
}
|
||||
}
|
||||
s_TooltipWindow->GetSize( wide, tall );
|
||||
// ivgui()->DPrintf("End Ratio: %f\n", (float)wide/(float)tall);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Display the tooltip
|
||||
//-----------------------------------------------------------------------------
|
||||
void TextTooltip::HideTooltip()
|
||||
{
|
||||
if ( s_TooltipWindow.Get() )
|
||||
{
|
||||
s_TooltipWindow->SetVisible(false);
|
||||
}
|
||||
|
||||
BaseTooltip::HideTooltip();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user