mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-08 01:39:36 +00:00
1
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include "bitmap.h"
|
||||
#include "vgui_internal.h"
|
||||
#include "filesystem.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include <tier0/dbg.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
// Input : *filename - image file to load
|
||||
//-----------------------------------------------------------------------------
|
||||
Bitmap::Bitmap(const char *filename, bool hardwareFiltered)
|
||||
{
|
||||
_filtered = hardwareFiltered;
|
||||
|
||||
int size = strlen(filename) + 1;
|
||||
_filename = (char *)malloc( size );
|
||||
Assert( _filename );
|
||||
|
||||
Q_snprintf( _filename, size, "%s", filename );
|
||||
|
||||
_bProcedural = false;
|
||||
|
||||
if ( Q_stristr( filename, ".pic" ) )
|
||||
{
|
||||
_bProcedural = true;
|
||||
}
|
||||
|
||||
_id = 0;
|
||||
_uploaded = false;
|
||||
_color = Color(255, 255, 255, 255);
|
||||
_pos[0] = _pos[1] = 0;
|
||||
_valid = true;
|
||||
_wide = 0;
|
||||
_tall = 0;
|
||||
nFrameCache = 0;
|
||||
_rotation = 0;
|
||||
|
||||
ForceUpload();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Bitmap::~Bitmap()
|
||||
{
|
||||
Evict();
|
||||
|
||||
if ( _filename )
|
||||
{
|
||||
free( _filename );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::GetSize(int &wide, int &tall)
|
||||
{
|
||||
wide = 0;
|
||||
tall = 0;
|
||||
|
||||
if ( !_valid )
|
||||
return;
|
||||
|
||||
// if a size has not been set, get it from the texture
|
||||
if ( 0 == _wide && 0 ==_tall )
|
||||
{
|
||||
g_pSurface->DrawGetTextureSize(_id, _wide, _tall);
|
||||
|
||||
}
|
||||
wide = _wide;
|
||||
tall = _tall;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::GetContentSize(int &wide, int &tall)
|
||||
{
|
||||
GetSize(wide, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ignored
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::SetSize(int x, int y)
|
||||
{
|
||||
// AssertMsg( _filtered, "Bitmap::SetSize called on non-hardware filtered texture. Bitmap can't be scaled; you don't want to be calling this." );
|
||||
_wide = x;
|
||||
_tall = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::SetPos(int x, int y)
|
||||
{
|
||||
_pos[0] = x;
|
||||
_pos[1] = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::SetColor(Color col)
|
||||
{
|
||||
_color = col;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the file name of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *Bitmap::GetName()
|
||||
{
|
||||
return _filename;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Renders the loaded image, uploading it if necessary
|
||||
// Assumes a valid image is always returned from uploading
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::Paint()
|
||||
{
|
||||
if ( !_valid )
|
||||
return;
|
||||
|
||||
// if we don't have an _id then lets make one
|
||||
if ( !_id )
|
||||
{
|
||||
_id = g_pSurface->CreateNewTextureID();
|
||||
}
|
||||
|
||||
// if we have not uploaded yet, lets go ahead and do so
|
||||
if ( !_uploaded )
|
||||
{
|
||||
ForceUpload();
|
||||
}
|
||||
|
||||
// set the texture current, set the color, and draw the biatch
|
||||
g_pSurface->DrawSetColor( _color[0], _color[1], _color[2], _color[3] );
|
||||
g_pSurface->DrawSetTexture( _id );
|
||||
|
||||
if ( _wide == 0 )
|
||||
{
|
||||
GetSize( _wide, _tall);
|
||||
}
|
||||
|
||||
if ( _rotation == ROTATED_UNROTATED )
|
||||
{
|
||||
g_pSurface->DrawTexturedRect(_pos[0], _pos[1], _pos[0] + _wide, _pos[1] + _tall);
|
||||
}
|
||||
else
|
||||
{
|
||||
vgui::Vertex_t verts[4];
|
||||
verts[0].m_Position.Init( 0, 0 );
|
||||
verts[1].m_Position.Init( _wide, 0 );
|
||||
verts[2].m_Position.Init( _wide, _tall );
|
||||
verts[3].m_Position.Init( 0, _tall );
|
||||
|
||||
switch ( _rotation )
|
||||
{
|
||||
case ROTATED_CLOCKWISE_90:
|
||||
verts[0].m_TexCoord.Init( 1, 0 );
|
||||
verts[1].m_TexCoord.Init( 1, 1 );
|
||||
verts[2].m_TexCoord.Init( 0, 1 );
|
||||
verts[3].m_TexCoord.Init( 0, 0 );
|
||||
break;
|
||||
|
||||
case ROTATED_ANTICLOCKWISE_90:
|
||||
verts[0].m_TexCoord.Init( 0, 1 );
|
||||
verts[1].m_TexCoord.Init( 0, 0 );
|
||||
verts[2].m_TexCoord.Init( 1, 0 );
|
||||
verts[3].m_TexCoord.Init( 1, 1 );
|
||||
break;
|
||||
|
||||
case ROTATED_FLIPPED:
|
||||
verts[0].m_TexCoord.Init( 1, 1 );
|
||||
verts[1].m_TexCoord.Init( 0, 1 );
|
||||
verts[2].m_TexCoord.Init( 0, 0 );
|
||||
verts[3].m_TexCoord.Init( 1, 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
case ROTATED_UNROTATED:
|
||||
break;
|
||||
}
|
||||
|
||||
g_pSurface->DrawTexturedPolygon( 4, verts );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ensures the bitmap has been uploaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void Bitmap::ForceUpload()
|
||||
{
|
||||
if ( !_valid || _uploaded )
|
||||
return;
|
||||
|
||||
if ( !_id )
|
||||
{
|
||||
_id = g_pSurface->CreateNewTextureID( _bProcedural );
|
||||
}
|
||||
|
||||
if ( !_bProcedural )
|
||||
{
|
||||
g_pSurface->DrawSetTextureFile( _id, _filename, _filtered, false );
|
||||
}
|
||||
|
||||
_uploaded = true;
|
||||
_valid = g_pSurface->IsTextureIDValid( _id );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
HTexture Bitmap::GetID()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
bool Bitmap::Evict()
|
||||
{
|
||||
if ( _id != 0 )
|
||||
{
|
||||
g_pSurface->DestroyTextureID( _id );
|
||||
// purposely not resetting _valid to match existing silly logic
|
||||
// either a Paint() or ForceUpload() will re-establish
|
||||
_id = 0;
|
||||
_uploaded = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int Bitmap::GetNumFrames()
|
||||
{
|
||||
if ( !_valid )
|
||||
return 0;
|
||||
|
||||
return g_pSurface->GetTextureNumFrames( _id );
|
||||
}
|
||||
|
||||
void Bitmap::SetFrame( int nFrame )
|
||||
{
|
||||
if ( !_valid )
|
||||
return;
|
||||
|
||||
// the frame cache is critical to cheapen the cost of this call
|
||||
g_pSurface->DrawSetTextureFrame( _id, nFrame, &nFrameCache );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vgui/IPanel.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include "VGUI_Border.h"
|
||||
#include "vgui_internal.h"
|
||||
#include "VPanel.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Border::Border()
|
||||
{
|
||||
_inset[0]=0;
|
||||
_inset[1]=0;
|
||||
_inset[2]=0;
|
||||
_inset[3]=0;
|
||||
_name = NULL;
|
||||
m_eBackgroundType = IBorder::BACKGROUND_FILLED;
|
||||
|
||||
memset(_sides, 0, sizeof(_sides));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
Border::~Border()
|
||||
{
|
||||
delete [] _name;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
delete [] _sides[i].lines;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::SetInset(int left,int top,int right,int bottom)
|
||||
{
|
||||
_inset[SIDE_LEFT] = left;
|
||||
_inset[SIDE_TOP] = top;
|
||||
_inset[SIDE_RIGHT] = right;
|
||||
_inset[SIDE_BOTTOM] = bottom;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::GetInset(int& left,int& top,int& right,int& bottom)
|
||||
{
|
||||
left = _inset[SIDE_LEFT];
|
||||
top = _inset[SIDE_TOP];
|
||||
right = _inset[SIDE_RIGHT];
|
||||
bottom = _inset[SIDE_BOTTOM];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::Paint(int x, int y, int wide, int tall)
|
||||
{
|
||||
Paint(x, y, wide, tall, -1, 0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draws the border with the specified size
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::Paint(int x, int y, int wide, int tall, int breakSide, int breakStart, int breakEnd)
|
||||
{
|
||||
// iterate through and draw all lines
|
||||
// draw left
|
||||
int i;
|
||||
for (i = 0; i < _sides[SIDE_LEFT].count; i++)
|
||||
{
|
||||
line_t *line = &(_sides[SIDE_LEFT].lines[i]);
|
||||
g_pSurface->DrawSetColor(line->col[0], line->col[1], line->col[2], line->col[3]);
|
||||
|
||||
if (breakSide == SIDE_LEFT)
|
||||
{
|
||||
// split into two section
|
||||
if (breakStart > 0)
|
||||
{
|
||||
// draw before the break Start
|
||||
g_pSurface->DrawFilledRect(x + i, y + line->startOffset, x + i + 1, y + breakStart);
|
||||
}
|
||||
|
||||
if (breakEnd < (tall - line->endOffset))
|
||||
{
|
||||
// draw after break end
|
||||
g_pSurface->DrawFilledRect(x + i, y + breakEnd + 1, x + i + 1, tall - line->endOffset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pSurface->DrawFilledRect(x + i, y + line->startOffset, x + i + 1, tall - line->endOffset);
|
||||
}
|
||||
}
|
||||
|
||||
// draw top
|
||||
for (i = 0; i < _sides[SIDE_TOP].count; i++)
|
||||
{
|
||||
line_t *line = &(_sides[SIDE_TOP].lines[i]);
|
||||
g_pSurface->DrawSetColor(line->col[0], line->col[1], line->col[2], line->col[3]);
|
||||
|
||||
if (breakSide == SIDE_TOP)
|
||||
{
|
||||
// split into two section
|
||||
if (breakStart > 0)
|
||||
{
|
||||
// draw before the break Start
|
||||
g_pSurface->DrawFilledRect(x + line->startOffset, y + i, x + breakStart, y + i + 1);
|
||||
}
|
||||
|
||||
if (breakEnd < (wide - line->endOffset))
|
||||
{
|
||||
// draw after break end
|
||||
g_pSurface->DrawFilledRect(x + breakEnd + 1, y + i, wide - line->endOffset, y + i + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pSurface->DrawFilledRect(x + line->startOffset, y + i, wide - line->endOffset, y + i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// draw right
|
||||
for (i = 0; i < _sides[SIDE_RIGHT].count; i++)
|
||||
{
|
||||
line_t *line = &(_sides[SIDE_RIGHT].lines[i]);
|
||||
g_pSurface->DrawSetColor(line->col[0], line->col[1], line->col[2], line->col[3]);
|
||||
g_pSurface->DrawFilledRect(wide - (i+1), y + line->startOffset, (wide - (i+1)) + 1, tall - line->endOffset);
|
||||
}
|
||||
|
||||
// draw bottom
|
||||
for (i = 0; i < _sides[SIDE_BOTTOM].count; i++)
|
||||
{
|
||||
line_t *line = &(_sides[SIDE_BOTTOM].lines[i]);
|
||||
g_pSurface->DrawSetColor(line->col[0], line->col[1], line->col[2], line->col[3]);
|
||||
g_pSurface->DrawFilledRect(x + line->startOffset, tall - (i+1), wide - line->endOffset, (tall - (i+1)) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::Paint(VPANEL panel)
|
||||
{
|
||||
// get panel size
|
||||
int wide, tall;
|
||||
((VPanel *)panel)->GetSize(wide, tall);
|
||||
Paint(0, 0, wide, tall, -1, 0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::ApplySchemeSettings(IScheme *pScheme, KeyValues *inResourceData)
|
||||
{
|
||||
// load inset information
|
||||
const char *insetString = inResourceData->GetString("inset", "0 0 0 0");
|
||||
|
||||
int left, top, right, bottom;
|
||||
GetInset(left, top, right, bottom);
|
||||
sscanf(insetString, "%d %d %d %d", &left, &top, &right, &bottom);
|
||||
SetInset(left, top, right, bottom);
|
||||
|
||||
// get the border information from the scheme
|
||||
ParseSideSettings(SIDE_LEFT, inResourceData->FindKey("Left"),pScheme);
|
||||
ParseSideSettings(SIDE_TOP, inResourceData->FindKey("Top"),pScheme);
|
||||
ParseSideSettings(SIDE_RIGHT, inResourceData->FindKey("Right"),pScheme);
|
||||
ParseSideSettings(SIDE_BOTTOM, inResourceData->FindKey("Bottom"),pScheme);
|
||||
|
||||
m_eBackgroundType = (backgroundtype_e)inResourceData->GetInt("backgroundtype");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: parses scheme data
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::ParseSideSettings(int side_index, KeyValues *inResourceData, IScheme *pScheme)
|
||||
{
|
||||
if (!inResourceData)
|
||||
return;
|
||||
|
||||
// count the numeber of lines in the side
|
||||
int count = 0;
|
||||
KeyValues *kv;
|
||||
for (kv = inResourceData->GetFirstSubKey(); kv != NULL; kv = kv->GetNextKey())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
// allocate memory
|
||||
_sides[side_index].count = count;
|
||||
_sides[side_index].lines = new line_t[count];
|
||||
|
||||
// iterate through the keys
|
||||
//!! this loads in order, ignoring key names
|
||||
int index = 0;
|
||||
for (kv = inResourceData->GetFirstSubKey(); kv != NULL; kv = kv->GetNextKey())
|
||||
{
|
||||
line_t *line = &(_sides[side_index].lines[index]);
|
||||
|
||||
// this is the color name, get that from the color table
|
||||
const char *col = kv->GetString("color", NULL);
|
||||
line->col = pScheme->GetColor(col, Color(0, 0, 0, 0));
|
||||
|
||||
col = kv->GetString("offset", NULL);
|
||||
int Start = 0, end = 0;
|
||||
if (col)
|
||||
{
|
||||
sscanf(col, "%d %d", &Start, &end);
|
||||
}
|
||||
line->startOffset = Start;
|
||||
line->endOffset = end;
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *Border::GetName()
|
||||
{
|
||||
if (_name)
|
||||
return _name;
|
||||
return "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void Border::SetName(const char *name)
|
||||
{
|
||||
if (_name)
|
||||
{
|
||||
delete [] _name;
|
||||
}
|
||||
|
||||
int len = Q_strlen(name) + 1;
|
||||
_name = new char[ len ];
|
||||
Q_strncpy( _name, name, len );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder::backgroundtype_e Border::GetBackgroundType()
|
||||
{
|
||||
return m_eBackgroundType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IMESSAGELISTENER_H
|
||||
#define IMESSAGELISTENER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
|
||||
class KeyValues;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
enum MessageSendType_t
|
||||
{
|
||||
MESSAGE_SENT = 0,
|
||||
MESSAGE_POSTED,
|
||||
MESSAGE_RECEIVED
|
||||
};
|
||||
|
||||
class VPanel;
|
||||
|
||||
|
||||
class IMessageListener
|
||||
{
|
||||
public:
|
||||
virtual void Message( VPanel* pSender, VPanel* pReceiver,
|
||||
KeyValues* pKeyValues, MessageSendType_t type ) = 0;
|
||||
};
|
||||
|
||||
IMessageListener* MessageListener();
|
||||
|
||||
}
|
||||
|
||||
#endif // IMESSAGELISTENER_H
|
||||
@@ -0,0 +1,223 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vgui_controls/Panel.h>
|
||||
#include "vgui/IPanel.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include "vgui_internal.h"
|
||||
#include "ImageBorder.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageBorder::ImageBorder()
|
||||
{
|
||||
_name = NULL;
|
||||
m_eBackgroundType = IBorder::BACKGROUND_TEXTURED;
|
||||
|
||||
m_pszImageName = NULL;
|
||||
m_iTextureID = g_pSurface->CreateNewTextureID();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageBorder::~ImageBorder()
|
||||
{
|
||||
if ( vgui::surface() && m_iTextureID != -1 )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_iTextureID );
|
||||
m_iTextureID = -1;
|
||||
}
|
||||
|
||||
delete [] _name;
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::SetImage(const char *imageName)
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
if (*imageName)
|
||||
{
|
||||
int len = Q_strlen(imageName) + 1 + 5; // 5 for "vgui/"
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_snprintf( m_pszImageName, len, "vgui/%s", imageName );
|
||||
|
||||
g_pSurface->DrawSetTextureFile( m_iTextureID, m_pszImageName, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::SetInset(int left,int top,int right,int bottom)
|
||||
{
|
||||
_inset[SIDE_LEFT] = left;
|
||||
_inset[SIDE_TOP] = top;
|
||||
_inset[SIDE_RIGHT] = right;
|
||||
_inset[SIDE_BOTTOM] = bottom;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::GetInset(int& left,int& top,int& right,int& bottom)
|
||||
{
|
||||
left = _inset[SIDE_LEFT];
|
||||
top = _inset[SIDE_TOP];
|
||||
right = _inset[SIDE_RIGHT];
|
||||
bottom = _inset[SIDE_BOTTOM];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::Paint(int x, int y, int wide, int tall)
|
||||
{
|
||||
Paint(x, y, wide, tall, -1, 0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draws the border with the specified size
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::Paint(int x, int y, int wide, int tall, int breakSide, int breakStart, int breakEnd)
|
||||
{
|
||||
if ( !m_pszImageName || !m_pszImageName[0] )
|
||||
return;
|
||||
|
||||
g_pSurface->DrawSetColor( 255, 255, 255, 255 );
|
||||
g_pSurface->DrawSetTexture( m_iTextureID );
|
||||
|
||||
float uvx = 0;
|
||||
float uvy = 0;
|
||||
float uvw = 1.0;
|
||||
float uvh = 1.0;
|
||||
Vector2D uv11( uvx, uvy );
|
||||
Vector2D uv21( uvx+uvw, uvy );
|
||||
Vector2D uv22( uvx+uvw, uvy+uvh );
|
||||
Vector2D uv12( uvx, uvy+uvh );
|
||||
|
||||
if ( m_bTiled )
|
||||
{
|
||||
int imageWide, imageTall;
|
||||
g_pSurface->DrawGetTextureSize( m_iTextureID, imageWide, imageTall );
|
||||
|
||||
int y = 0;
|
||||
while ( y < tall )
|
||||
{
|
||||
int x = 0;
|
||||
while (x < wide)
|
||||
{
|
||||
vgui::Vertex_t verts[4];
|
||||
verts[0].Init( Vector2D( x, y ), uv11 );
|
||||
verts[1].Init( Vector2D( x+imageWide, y ), uv21 );
|
||||
verts[2].Init( Vector2D( x+imageWide, y+imageTall ), uv22 );
|
||||
verts[3].Init( Vector2D( x, y+imageTall ), uv12 );
|
||||
|
||||
g_pSurface->DrawTexturedPolygon( 4, verts );
|
||||
|
||||
x += imageWide;
|
||||
}
|
||||
|
||||
y += imageTall;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vgui::Vertex_t verts[4];
|
||||
verts[0].Init( Vector2D( x, y ), uv11 );
|
||||
verts[1].Init( Vector2D( x+wide, y ), uv21 );
|
||||
verts[2].Init( Vector2D( x+wide, y+tall ), uv22 );
|
||||
verts[3].Init( Vector2D( x, y+tall ), uv12 );
|
||||
|
||||
g_pSurface->DrawTexturedPolygon( 4, verts );
|
||||
}
|
||||
|
||||
g_pSurface->DrawSetTexture(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::Paint(VPANEL panel)
|
||||
{
|
||||
// get panel size
|
||||
int wide, tall;
|
||||
ipanel()->GetSize( panel, wide, tall );
|
||||
Paint(0, 0, wide, tall, -1, 0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::ApplySchemeSettings(IScheme *pScheme, KeyValues *inResourceData)
|
||||
{
|
||||
m_eBackgroundType = (backgroundtype_e)inResourceData->GetInt("backgroundtype");
|
||||
m_bTiled = inResourceData->GetInt( "tiled" );
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
SetImage( imageName );
|
||||
|
||||
m_bPaintFirst = inResourceData->GetInt("paintfirst", true );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ImageBorder::GetName()
|
||||
{
|
||||
if (_name)
|
||||
return _name;
|
||||
return "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ImageBorder::SetName(const char *name)
|
||||
{
|
||||
if (_name)
|
||||
{
|
||||
delete [] _name;
|
||||
}
|
||||
|
||||
int len = Q_strlen(name) + 1;
|
||||
_name = new char[ len ];
|
||||
Q_strncpy( _name, name, len );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder::backgroundtype_e ImageBorder::GetBackgroundType()
|
||||
{
|
||||
return m_eBackgroundType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core implementation of vgui
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IMAGE_BORDER_H
|
||||
#define IMAGE_BORDER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <Color.h>
|
||||
|
||||
class KeyValues;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Custom border that renders itself with images
|
||||
//-----------------------------------------------------------------------------
|
||||
class ImageBorder : public vgui::IBorder
|
||||
{
|
||||
public:
|
||||
ImageBorder();
|
||||
~ImageBorder();
|
||||
|
||||
virtual void Paint(vgui::VPANEL panel);
|
||||
virtual void Paint(int x0, int y0, int x1, int y1);
|
||||
virtual void Paint(int x0, int y0, int x1, int y1, int breakSide, int breakStart, int breakStop);
|
||||
virtual void SetInset(int left, int top, int right, int bottom);
|
||||
virtual void GetInset(int &left, int &top, int &right, int &bottom);
|
||||
|
||||
virtual void ApplySchemeSettings(vgui::IScheme *pScheme, KeyValues *inResourceData);
|
||||
|
||||
virtual const char *GetName();
|
||||
virtual void SetName(const char *name);
|
||||
virtual backgroundtype_e GetBackgroundType();
|
||||
|
||||
virtual bool PaintFirst( void ) { return m_bPaintFirst; }
|
||||
|
||||
protected:
|
||||
void SetImage(const char *imageName);
|
||||
|
||||
protected:
|
||||
int _inset[4];
|
||||
|
||||
private:
|
||||
// protected copy constructor to prevent use
|
||||
ImageBorder(ImageBorder&);
|
||||
|
||||
char *_name;
|
||||
|
||||
backgroundtype_e m_eBackgroundType;
|
||||
|
||||
friend class VPanel;
|
||||
|
||||
int m_iTextureID;
|
||||
bool m_bTiled;
|
||||
|
||||
char *m_pszImageName;
|
||||
bool m_bPaintFirst;
|
||||
};
|
||||
|
||||
#endif // IMAGE_BORDER_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,174 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
|
||||
#if !defined(_STATIC_LINKED) || defined(_VGUI_DLL)
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
|
||||
#include "Memorybitmap.h"
|
||||
#include "vgui_internal.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
// Input : *filename - image file to load
|
||||
//-----------------------------------------------------------------------------
|
||||
MemoryBitmap::MemoryBitmap(unsigned char *texture,int wide, int tall)
|
||||
{
|
||||
_texture=texture;
|
||||
_id = 0;
|
||||
_uploaded = false;
|
||||
_color = Color(255, 255, 255, 255);
|
||||
_pos[0] = _pos[1] = 0;
|
||||
_valid = true;
|
||||
_w = wide;
|
||||
_h = tall;
|
||||
ForceUpload(texture,wide,tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
MemoryBitmap::~MemoryBitmap()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::GetSize(int &wide, int &tall)
|
||||
{
|
||||
wide = 0;
|
||||
tall = 0;
|
||||
|
||||
if (!_valid)
|
||||
return;
|
||||
|
||||
g_pSurface->DrawGetTextureSize(_id, wide, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: size of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::GetContentSize(int &wide, int &tall)
|
||||
{
|
||||
GetSize(wide, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ignored
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::SetSize(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::SetPos(int x, int y)
|
||||
{
|
||||
_pos[0] = x;
|
||||
_pos[1] = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::SetColor(Color col)
|
||||
{
|
||||
_color = col;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the file name of the bitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *MemoryBitmap::GetName()
|
||||
{
|
||||
return "MemoryBitmap";
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Renders the loaded image, uploading it if necessary
|
||||
// Assumes a valid image is always returned from uploading
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::Paint()
|
||||
{
|
||||
if (!_valid)
|
||||
return;
|
||||
|
||||
// if we don't have an _id then lets make one
|
||||
if (!_id)
|
||||
{
|
||||
_id = g_pSurface->CreateNewTextureID( true );
|
||||
}
|
||||
|
||||
// if we have not uploaded yet, lets go ahead and do so
|
||||
if (!_uploaded)
|
||||
{
|
||||
ForceUpload(_texture,_w,_h);
|
||||
}
|
||||
|
||||
//set the texture current, set the color, and draw the biatch
|
||||
g_pSurface->DrawSetTexture(_id);
|
||||
g_pSurface->DrawSetColor(_color[0], _color[1], _color[2], _color[3]);
|
||||
|
||||
int wide, tall;
|
||||
GetSize(wide, tall);
|
||||
g_pSurface->DrawTexturedRect(_pos[0], _pos[1], _pos[0] + wide, _pos[1] + tall);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: ensures the bitmap has been uploaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void MemoryBitmap::ForceUpload(unsigned char *texture,int wide, int tall)
|
||||
{
|
||||
_texture=texture;
|
||||
_w = wide;
|
||||
_h = tall;
|
||||
|
||||
if (!_valid)
|
||||
return;
|
||||
|
||||
// if (_uploaded)
|
||||
// return;
|
||||
|
||||
if(_w==0 || _h==0)
|
||||
return;
|
||||
|
||||
if (!_id)
|
||||
{
|
||||
_id = g_pSurface->CreateNewTextureID( true );
|
||||
}
|
||||
/* drawSetTextureRGBA(IE->textureID,static_cast<const char *>(lpvBits), w, h);
|
||||
*/
|
||||
g_pSurface->DrawSetTextureRGBA(_id, _texture, _w, _h, false, true);
|
||||
_uploaded = true;
|
||||
|
||||
_valid = g_pSurface->IsTextureIDValid(_id);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
HTexture MemoryBitmap::GetID()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
#endif // _STATIC_LINKED && _VGUI_DLL
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef MEMORYBITMAP_H
|
||||
#define MEMORYBITMAP_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <vgui/IImage.h>
|
||||
#include <Color.h>
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
typedef unsigned long HTexture;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Holds a single image created from a chunk of memory, internal to vgui only
|
||||
//-----------------------------------------------------------------------------
|
||||
class MemoryBitmap: public IImage
|
||||
{
|
||||
public:
|
||||
MemoryBitmap(unsigned char *texture,int wide, int tall);
|
||||
~MemoryBitmap();
|
||||
|
||||
// IImage implementation
|
||||
virtual void Paint();
|
||||
virtual void GetSize(int &wide, int &tall);
|
||||
virtual void GetContentSize(int &wide, int &tall);
|
||||
virtual void SetPos(int x, int y);
|
||||
virtual void SetSize(int x, int y);
|
||||
virtual void SetColor(Color col);
|
||||
|
||||
virtual bool Evict() { return false; }
|
||||
virtual int GetNumFrames() { return 0; }
|
||||
virtual void SetFrame( int nFrame ) {}
|
||||
virtual HTexture GetID(); // returns the texture id
|
||||
virtual void SetRotation( int iRotation ) { return; };
|
||||
|
||||
// methods
|
||||
void ForceUpload(unsigned char *texture,int wide, int tall); // ensures the bitmap has been uploaded
|
||||
const char *GetName();
|
||||
bool IsValid()
|
||||
{
|
||||
return _valid;
|
||||
}
|
||||
|
||||
private:
|
||||
HTexture _id;
|
||||
bool _uploaded;
|
||||
bool _valid;
|
||||
unsigned char *_texture;
|
||||
int _pos[2];
|
||||
Color _color;
|
||||
int _w,_h; // size of the texture
|
||||
};
|
||||
|
||||
} // namespace vgui
|
||||
|
||||
#endif // MEMORYBITMAP_H
|
||||
@@ -0,0 +1,112 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "IMessageListener.h"
|
||||
#include "VPanel.h"
|
||||
#include "vgui_internal.h"
|
||||
|
||||
#include <KeyValues.h>
|
||||
#include "vgui/IClientPanel.h"
|
||||
#include "vgui/IVGui.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation of the message listener
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMessageListener : public IMessageListener
|
||||
{
|
||||
public:
|
||||
virtual void Message( VPanel* pSender, VPanel* pReceiver, KeyValues* pKeyValues, MessageSendType_t type );
|
||||
};
|
||||
|
||||
void CMessageListener::Message( VPanel* pSender, VPanel* pReceiver, KeyValues* pKeyValues, MessageSendType_t type )
|
||||
{
|
||||
char const *pSenderName = "NULL";
|
||||
if (pSender)
|
||||
pSenderName = pSender->Client()->GetName();
|
||||
|
||||
char const *pSenderClass = "NULL";
|
||||
if (pSender)
|
||||
pSenderClass = pSender->Client()->GetClassName();
|
||||
|
||||
char const *pReceiverName = "unknown name";
|
||||
if (pReceiver)
|
||||
pReceiverName = pReceiver->Client()->GetName();
|
||||
|
||||
char const *pReceiverClass = "unknown class";
|
||||
if (pReceiver)
|
||||
pReceiverClass = pReceiver->Client()->GetClassName();
|
||||
|
||||
// FIXME: Make a bunch of filters here
|
||||
|
||||
// filter out key focus messages
|
||||
if (!strcmp (pKeyValues->GetName(), "KeyFocusTicked"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out mousefocus messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "MouseFocusTicked"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out cursor movement messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "CursorMoved"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out cursor entered messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "CursorEntered"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out cursor exited messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "CursorExited"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out MouseCaptureLost messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "MouseCaptureLost"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out MousePressed messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "MousePressed"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out MouseReleased messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "MouseReleased"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// filter out Tick messages
|
||||
else if (!strcmp (pKeyValues->GetName(), "Tick"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Msg( "%s : (%s (%s) - > %s (%s)) )\n",
|
||||
pKeyValues->GetName(), pSenderClass, pSenderName, pReceiverClass, pReceiverName );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton instance
|
||||
//-----------------------------------------------------------------------------
|
||||
static CMessageListener s_MessageListener;
|
||||
IMessageListener *MessageListener()
|
||||
{
|
||||
return &s_MessageListener;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vgui_controls/Panel.h>
|
||||
#include "vgui/IPanel.h"
|
||||
#include "vgui/IScheme.h"
|
||||
#include "vgui/ISurface.h"
|
||||
|
||||
#include "vgui_internal.h"
|
||||
#include "ScalableImageBorder.h"
|
||||
#include "KeyValues.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ScalableImageBorder::ScalableImageBorder()
|
||||
{
|
||||
_inset[0]=0;
|
||||
_inset[1]=0;
|
||||
_inset[2]=0;
|
||||
_inset[3]=0;
|
||||
_name = NULL;
|
||||
m_eBackgroundType = IBorder::BACKGROUND_TEXTURED;
|
||||
|
||||
m_iSrcCornerHeight = 0;
|
||||
m_iSrcCornerWidth = 0;
|
||||
m_iCornerHeight = 0;
|
||||
m_iCornerWidth = 0;
|
||||
m_pszImageName = NULL;
|
||||
m_iTextureID = g_pSurface->CreateNewTextureID();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
ScalableImageBorder::~ScalableImageBorder()
|
||||
{
|
||||
if ( vgui::surface() && m_iTextureID != -1 )
|
||||
{
|
||||
vgui::surface()->DestroyTextureID( m_iTextureID );
|
||||
m_iTextureID = -1;
|
||||
}
|
||||
|
||||
delete [] _name;
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::SetImage(const char *imageName)
|
||||
{
|
||||
if ( m_pszImageName )
|
||||
{
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = NULL;
|
||||
}
|
||||
|
||||
if (*imageName)
|
||||
{
|
||||
int len = Q_strlen(imageName) + 1 + 5; // 5 for "vgui/"
|
||||
delete [] m_pszImageName;
|
||||
m_pszImageName = new char[ len ];
|
||||
Q_snprintf( m_pszImageName, len, "vgui/%s", imageName );
|
||||
|
||||
g_pSurface->DrawSetTextureFile( m_iTextureID, m_pszImageName, true, false);
|
||||
|
||||
// get image dimensions, compare to m_iSrcCornerHeight, m_iSrcCornerWidth
|
||||
int wide,tall;
|
||||
g_pSurface->DrawGetTextureSize( m_iTextureID, wide, tall );
|
||||
|
||||
m_flCornerWidthPercent = ( wide > 0 ) ? ( (float)m_iSrcCornerWidth / (float)wide ) : 0;
|
||||
m_flCornerHeightPercent = ( tall > 0 ) ? ( (float)m_iSrcCornerHeight / (float)tall ) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::SetInset(int left,int top,int right,int bottom)
|
||||
{
|
||||
_inset[SIDE_LEFT] = left;
|
||||
_inset[SIDE_TOP] = top;
|
||||
_inset[SIDE_RIGHT] = right;
|
||||
_inset[SIDE_BOTTOM] = bottom;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::GetInset(int& left,int& top,int& right,int& bottom)
|
||||
{
|
||||
left = _inset[SIDE_LEFT];
|
||||
top = _inset[SIDE_TOP];
|
||||
right = _inset[SIDE_RIGHT];
|
||||
bottom = _inset[SIDE_BOTTOM];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::Paint(int x, int y, int wide, int tall)
|
||||
{
|
||||
Paint(x, y, wide, tall, -1, 0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Draws the border with the specified size
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::Paint(int x, int y, int wide, int tall, int breakSide, int breakStart, int breakEnd)
|
||||
{
|
||||
if ( !m_pszImageName || !m_pszImageName[0] )
|
||||
return;
|
||||
|
||||
g_pSurface->DrawSetColor( m_Color );
|
||||
g_pSurface->DrawSetTexture( m_iTextureID );
|
||||
|
||||
float uvx = 0;
|
||||
float uvy = 0;
|
||||
float uvw, uvh;
|
||||
|
||||
float drawW, drawH;
|
||||
|
||||
int row, col;
|
||||
for ( row=0;row<3;row++ )
|
||||
{
|
||||
x = 0;
|
||||
uvx = 0;
|
||||
|
||||
if ( row == 0 || row == 2 )
|
||||
{
|
||||
//uvh - row 0 or 2, is src_corner_height
|
||||
uvh = m_flCornerHeightPercent;
|
||||
drawH = m_iCornerHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
//uvh - row 1, is tall - ( 2 * src_corner_height ) ( min 0 )
|
||||
uvh = max( 1.f - 2.f * m_flCornerHeightPercent, 0.0f );
|
||||
drawH = max( 0, ( tall - 2 * m_iCornerHeight ) );
|
||||
}
|
||||
|
||||
for ( col=0;col<3;col++ )
|
||||
{
|
||||
if ( col == 0 || col == 2 )
|
||||
{
|
||||
//uvw - col 0 or 2, is src_corner_width
|
||||
uvw = m_flCornerWidthPercent;
|
||||
drawW = m_iCornerWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
//uvw - col 1, is wide - ( 2 * src_corner_width ) ( min 0 )
|
||||
uvw = max( 1.f - 2.f * m_flCornerWidthPercent, 0.0f );
|
||||
drawW = max( 0, ( wide - 2 * m_iCornerWidth ) );
|
||||
}
|
||||
|
||||
Vector2D uv11( uvx, uvy );
|
||||
Vector2D uv21( uvx+uvw, uvy );
|
||||
Vector2D uv22( uvx+uvw, uvy+uvh );
|
||||
Vector2D uv12( uvx, uvy+uvh );
|
||||
|
||||
vgui::Vertex_t verts[4];
|
||||
verts[0].Init( Vector2D( x, y ), uv11 );
|
||||
verts[1].Init( Vector2D( x+drawW, y ), uv21 );
|
||||
verts[2].Init( Vector2D( x+drawW, y+drawH ), uv22 );
|
||||
verts[3].Init( Vector2D( x, y+drawH ), uv12 );
|
||||
|
||||
g_pSurface->DrawTexturedPolygon( 4, verts );
|
||||
|
||||
x += drawW;
|
||||
uvx += uvw;
|
||||
}
|
||||
|
||||
y += drawH;
|
||||
uvy += uvh;
|
||||
}
|
||||
|
||||
g_pSurface->DrawSetTexture(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::Paint(VPANEL panel)
|
||||
{
|
||||
// get panel size
|
||||
int wide, tall;
|
||||
ipanel()->GetSize( panel, wide, tall );
|
||||
Paint(0, 0, wide, tall, -1, 0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::ApplySchemeSettings(IScheme *pScheme, KeyValues *inResourceData)
|
||||
{
|
||||
m_eBackgroundType = (backgroundtype_e)inResourceData->GetInt("backgroundtype");
|
||||
|
||||
m_iSrcCornerHeight = inResourceData->GetInt( "src_corner_height" );
|
||||
m_iSrcCornerWidth = inResourceData->GetInt( "src_corner_width" );
|
||||
m_iCornerHeight = inResourceData->GetInt( "draw_corner_height" );
|
||||
m_iCornerWidth = inResourceData->GetInt( "draw_corner_width" );
|
||||
|
||||
// scale the x and y up to our screen co-ords
|
||||
m_iCornerHeight = scheme()->GetProportionalScaledValue( m_iCornerHeight);
|
||||
m_iCornerWidth = scheme()->GetProportionalScaledValue(m_iCornerWidth);
|
||||
|
||||
const char *imageName = inResourceData->GetString("image", "");
|
||||
SetImage( imageName );
|
||||
|
||||
m_bPaintFirst = inResourceData->GetInt("paintfirst", true );
|
||||
|
||||
const char *col = inResourceData->GetString("color", NULL);
|
||||
if ( col && col[0] )
|
||||
{
|
||||
m_Color = pScheme->GetColor(col, Color(255, 255, 255, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Color = Color(255, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *ScalableImageBorder::GetName()
|
||||
{
|
||||
if (_name)
|
||||
return _name;
|
||||
return "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: data accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
void ScalableImageBorder::SetName(const char *name)
|
||||
{
|
||||
if (_name)
|
||||
{
|
||||
delete [] _name;
|
||||
}
|
||||
|
||||
int len = Q_strlen(name) + 1;
|
||||
_name = new char[ len ];
|
||||
Q_strncpy( _name, name, len );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
IBorder::backgroundtype_e ScalableImageBorder::GetBackgroundType()
|
||||
{
|
||||
return m_eBackgroundType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core implementation of vgui
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SCALABLE_IMAGE_BORDER_H
|
||||
#define SCALABLE_IMAGE_BORDER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <Color.h>
|
||||
|
||||
class KeyValues;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Custom border that renders itself with images
|
||||
//-----------------------------------------------------------------------------
|
||||
class ScalableImageBorder : public vgui::IBorder
|
||||
{
|
||||
public:
|
||||
ScalableImageBorder();
|
||||
~ScalableImageBorder();
|
||||
|
||||
virtual void Paint(vgui::VPANEL panel);
|
||||
virtual void Paint(int x0, int y0, int x1, int y1);
|
||||
virtual void Paint(int x0, int y0, int x1, int y1, int breakSide, int breakStart, int breakStop);
|
||||
virtual void SetInset(int left, int top, int right, int bottom);
|
||||
virtual void GetInset(int &left, int &top, int &right, int &bottom);
|
||||
|
||||
virtual void ApplySchemeSettings(vgui::IScheme *pScheme, KeyValues *inResourceData);
|
||||
|
||||
virtual const char *GetName();
|
||||
virtual void SetName(const char *name);
|
||||
virtual backgroundtype_e GetBackgroundType();
|
||||
|
||||
virtual bool PaintFirst( void ) { return m_bPaintFirst; }
|
||||
|
||||
protected:
|
||||
void SetImage(const char *imageName);
|
||||
|
||||
protected:
|
||||
int _inset[4];
|
||||
|
||||
private:
|
||||
// protected copy constructor to prevent use
|
||||
ScalableImageBorder(ScalableImageBorder&);
|
||||
|
||||
char *_name;
|
||||
|
||||
backgroundtype_e m_eBackgroundType;
|
||||
|
||||
friend class VPanel;
|
||||
|
||||
int m_iSrcCornerHeight; // in pixels, how tall is the corner inside the image
|
||||
int m_iSrcCornerWidth; // same for width
|
||||
int m_iCornerHeight; // output size of the corner height in pixels
|
||||
int m_iCornerWidth; // same for width
|
||||
|
||||
int m_iTextureID;
|
||||
|
||||
float m_flCornerWidthPercent; // corner width as percentage of image width
|
||||
float m_flCornerHeightPercent; // same for height
|
||||
|
||||
char *m_pszImageName;
|
||||
bool m_bPaintFirst;
|
||||
|
||||
Color m_Color;
|
||||
};
|
||||
|
||||
#endif // SCALABLE_IMAGE_BORDER_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,82 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core implementation of vgui
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VGUI_BORDER_H
|
||||
#define VGUI_BORDER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <vgui/IBorder.h>
|
||||
#include <vgui/IScheme.h>
|
||||
#include <Color.h>
|
||||
|
||||
class KeyValues;
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Interface to panel borders
|
||||
// Borders have a close relationship with panels
|
||||
//-----------------------------------------------------------------------------
|
||||
class Border : public IBorder
|
||||
{
|
||||
public:
|
||||
Border();
|
||||
~Border();
|
||||
|
||||
virtual void Paint(VPANEL panel);
|
||||
virtual void Paint(int x0, int y0, int x1, int y1);
|
||||
virtual void Paint(int x0, int y0, int x1, int y1, int breakSide, int breakStart, int breakStop);
|
||||
virtual void SetInset(int left, int top, int right, int bottom);
|
||||
virtual void GetInset(int &left, int &top, int &right, int &bottom);
|
||||
|
||||
virtual void ApplySchemeSettings(IScheme *pScheme, KeyValues *inResourceData);
|
||||
|
||||
virtual const char *GetName();
|
||||
virtual void SetName(const char *name);
|
||||
virtual backgroundtype_e GetBackgroundType();
|
||||
|
||||
virtual bool PaintFirst( void ) { return false; }
|
||||
|
||||
protected:
|
||||
int _inset[4];
|
||||
|
||||
private:
|
||||
// protected copy constructor to prevent use
|
||||
Border(Border&);
|
||||
|
||||
void ParseSideSettings(int side_index, KeyValues *inResourceData, IScheme *pScheme);
|
||||
|
||||
char *_name;
|
||||
|
||||
// border drawing description
|
||||
struct line_t
|
||||
{
|
||||
Color col;
|
||||
int startOffset;
|
||||
int endOffset;
|
||||
};
|
||||
|
||||
struct side_t
|
||||
{
|
||||
int count;
|
||||
line_t *lines;
|
||||
};
|
||||
|
||||
side_t _sides[4]; // left, top, right, bottom
|
||||
backgroundtype_e m_eBackgroundType;
|
||||
|
||||
friend class VPanel;
|
||||
};
|
||||
|
||||
} // namespace vgui
|
||||
|
||||
#endif // VGUI_BORDER_H
|
||||
@@ -0,0 +1,782 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/IClientPanel.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/IVGui.h>
|
||||
#include <vgui/Cursor.h>
|
||||
|
||||
#include "vgui_internal.h"
|
||||
#include "VPanel.h"
|
||||
|
||||
#include "tier0/minidump.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
|
||||
// Lame copy from Panel
|
||||
enum PinCorner_e
|
||||
{
|
||||
PIN_TOPLEFT = 0,
|
||||
PIN_TOPRIGHT,
|
||||
PIN_BOTTOMLEFT,
|
||||
PIN_BOTTOMRIGHT,
|
||||
|
||||
// For sibling pinning
|
||||
PIN_CENTER_TOP,
|
||||
PIN_CENTER_RIGHT,
|
||||
PIN_CENTER_BOTTOM,
|
||||
PIN_CENTER_LEFT,
|
||||
|
||||
NUM_PIN_POINTS,
|
||||
};
|
||||
|
||||
float PinDeltas[NUM_PIN_POINTS][2] =
|
||||
{
|
||||
{ 0, 0 }, // PIN_TOPLEFT,
|
||||
{ 1, 0 }, // PIN_TOPRIGHT,
|
||||
{ 0, 1 }, // PIN_BOTTOMLEFT,
|
||||
{ 1, 1 }, // PIN_BOTTOMRIGHT,
|
||||
{ 0.5, 0 }, // PIN_CENTER_TOP,
|
||||
{ 1, 0.5 }, // PIN_CENTER_RIGHT,
|
||||
{ 0.5, 1 }, // PIN_CENTER_BOTTOM,
|
||||
{ 0, 0.5 }, // PIN_CENTER_LEFT,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
VPanel::VPanel()
|
||||
{
|
||||
_pos[0] = _pos[1] = 0;
|
||||
_absPos[0] = _absPos[1] = 0;
|
||||
_size[0] = _size[1] = 0;
|
||||
|
||||
_minimumSize[0] = 0;
|
||||
_minimumSize[1] = 0;
|
||||
|
||||
_zpos = 0;
|
||||
|
||||
_inset[0] = _inset[1] = _inset[2] = _inset[3] = 0;
|
||||
_clipRect[0] = _clipRect[1] = _clipRect[2] = _clipRect[3] = 0;
|
||||
|
||||
_visible = true;
|
||||
_enabled = true;
|
||||
_clientPanel = NULL;
|
||||
_parent = NULL;
|
||||
_plat = NULL;
|
||||
_popup = false;
|
||||
_isTopmostPopup = false;
|
||||
_hPanel = INVALID_PANEL;
|
||||
|
||||
_mouseInput = true; // by default you want mouse and kb input to this panel
|
||||
_kbInput = true;
|
||||
|
||||
_pinsibling = NULL;
|
||||
_pinsibling_my_corner = PIN_TOPLEFT;
|
||||
_pinsibling_their_corner = PIN_TOPLEFT;
|
||||
|
||||
m_nThinkTraverseLevel = 0;
|
||||
_clientPanelHandle = vgui::INVALID_PANEL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
VPanel::~VPanel()
|
||||
{
|
||||
// Someone just deleted their parent Panel while it was being used in InternalSolveTraverse().
|
||||
// This will cause a difficult to debug crash, so we spew out the panel name here in hopes
|
||||
// it will help track down the offender.
|
||||
if ( m_nThinkTraverseLevel != 0 )
|
||||
{
|
||||
Warning( "Deleting in-use vpanel: %s/%s %p.\n", GetName(), GetClassName(), this );
|
||||
#ifdef STAGING_ONLY
|
||||
DebuggerBreak();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::TraverseLevel( int val )
|
||||
{
|
||||
// Bump up our traverse level.
|
||||
m_nThinkTraverseLevel += m_nThinkTraverseLevel;
|
||||
|
||||
// Bump up our client panel traverse level.
|
||||
if ( Client() )
|
||||
{
|
||||
VPANEL vp = g_pVGui->HandleToPanel( _clientPanelHandle );
|
||||
if ( vp == vgui::INVALID_PANEL )
|
||||
{
|
||||
// This is really bad - we have a Client() pointer that is invalid.
|
||||
Warning( "Panel '%s/%s' has invalid client: %p.\n", GetName(), GetClassName(), Client() );
|
||||
#ifdef STAGING_ONLY
|
||||
DebuggerBreak();
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( Client()->GetVPanel() )
|
||||
{
|
||||
VPanel *vpanel = (VPanel *)Client()->GetVPanel();
|
||||
vpanel->m_nThinkTraverseLevel += vpanel->m_nThinkTraverseLevel;
|
||||
}
|
||||
}
|
||||
|
||||
// This doesn't work. It appears we add all kinds of children to various panels in the
|
||||
// InternalThinkTraverse functions, and that means the refcount is 0 when added, and
|
||||
// then drops to -1 when we decrement the traverse level.
|
||||
#if 0
|
||||
// Bump up our children traverse levels.
|
||||
CUtlVector< VPanel * > &children = GetChildren();
|
||||
for ( int i = 0; i < children.Count(); ++i )
|
||||
{
|
||||
VPanel *child = children[ i ];
|
||||
if ( child )
|
||||
child->m_nThinkTraverseLevel = Max( child->m_nThinkTraverseLevel + val, 0 );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::Init(IClientPanel *attachedClientPanel)
|
||||
{
|
||||
_clientPanel = attachedClientPanel;
|
||||
_clientPanelHandle = g_pVGui->PanelToHandle( attachedClientPanel ? attachedClientPanel->GetVPanel() : 0 );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::Solve()
|
||||
{
|
||||
short basePos[2];
|
||||
basePos[0] = _pos[0];
|
||||
basePos[1] = _pos[1];
|
||||
|
||||
int baseSize[2];
|
||||
GetSize( baseSize[0], baseSize[1] );
|
||||
|
||||
VPanel *parent = GetParent();
|
||||
if (IsPopup())
|
||||
{
|
||||
// if we're a popup, draw at the highest level
|
||||
parent = (VPanel *)g_pSurface->GetEmbeddedPanel();
|
||||
}
|
||||
|
||||
int pabs[2];
|
||||
if ( parent )
|
||||
{
|
||||
parent->GetAbsPos(pabs[0], pabs[1]);
|
||||
}
|
||||
|
||||
if ( _pinsibling )
|
||||
{
|
||||
_pinsibling->Solve();
|
||||
|
||||
int sibPos[2];
|
||||
int sibSize[2];
|
||||
_pinsibling->GetInternalAbsPos( sibPos[0], sibPos[1] );
|
||||
_pinsibling->GetSize( sibSize[0], sibSize[1] );
|
||||
|
||||
for ( int i = 0; i < 2; i++ )
|
||||
{
|
||||
if ( parent )
|
||||
{
|
||||
sibPos[i] -= pabs[i];
|
||||
}
|
||||
|
||||
// Determine which direction positive values move in. For center pins, we use screen relative signs.
|
||||
int iSign = 1;
|
||||
if ( i == 0 && (_pinsibling_their_corner == PIN_CENTER_LEFT || _pinsibling_their_corner == PIN_TOPLEFT || _pinsibling_their_corner == PIN_BOTTOMLEFT) )
|
||||
{
|
||||
iSign = -1;
|
||||
}
|
||||
else if ( i == 1 && (_pinsibling_their_corner == PIN_CENTER_TOP || _pinsibling_their_corner == PIN_TOPLEFT || _pinsibling_their_corner == PIN_TOPRIGHT) )
|
||||
{
|
||||
iSign = -1;
|
||||
}
|
||||
|
||||
int iPos = sibPos[i] + (sibSize[i] * PinDeltas[_pinsibling_their_corner][i]);
|
||||
iPos -= (baseSize[i] * PinDeltas[_pinsibling_my_corner][i]);
|
||||
iPos += basePos[i] * iSign;
|
||||
|
||||
basePos[i] = iPos;
|
||||
}
|
||||
}
|
||||
|
||||
int absX = basePos[0];
|
||||
int absY = basePos[1];
|
||||
_absPos[0] = basePos[0];
|
||||
_absPos[1] = basePos[1];
|
||||
|
||||
// put into parent space
|
||||
int pinset[4] = {0, 0, 0, 0};
|
||||
if ( parent )
|
||||
{
|
||||
parent->GetInset( pinset[0], pinset[1], pinset[2], pinset[3] );
|
||||
|
||||
absX += pabs[0] + pinset[0];
|
||||
absY += pabs[1] + pinset[1];
|
||||
|
||||
_absPos[0] = clamp( absX, -32767, 32767 );
|
||||
_absPos[1] = clamp( absY, -32767, 32767 );
|
||||
}
|
||||
|
||||
// set initial bounds
|
||||
_clipRect[0] = _absPos[0];
|
||||
_clipRect[1] = _absPos[1];
|
||||
|
||||
int absX2 = absX + baseSize[0];
|
||||
int absY2 = absY + baseSize[1];
|
||||
_clipRect[2] = clamp( absX2, -32767, 32767 );
|
||||
_clipRect[3] = clamp( absY2, -32767, 32767 );
|
||||
|
||||
// clip to parent, if we're not a popup
|
||||
if ( parent && !IsPopup() )
|
||||
{
|
||||
int pclip[4];
|
||||
parent->GetClipRect(pclip[0], pclip[1], pclip[2], pclip[3]);
|
||||
|
||||
if (_clipRect[0] < pclip[0])
|
||||
{
|
||||
_clipRect[0] = pclip[0];
|
||||
}
|
||||
|
||||
if (_clipRect[1] < pclip[1])
|
||||
{
|
||||
_clipRect[1] = pclip[1];
|
||||
}
|
||||
|
||||
if(_clipRect[2] > pclip[2])
|
||||
{
|
||||
_clipRect[2] = pclip[2] - pinset[2];
|
||||
}
|
||||
|
||||
if(_clipRect[3] > pclip[3])
|
||||
{
|
||||
_clipRect[3] = pclip[3] - pinset[3];
|
||||
}
|
||||
|
||||
if ( _clipRect[0] > _clipRect[2] )
|
||||
{
|
||||
_clipRect[2] = _clipRect[0];
|
||||
}
|
||||
|
||||
if ( _clipRect[1] > _clipRect[3] )
|
||||
{
|
||||
_clipRect[3] = _clipRect[1];
|
||||
}
|
||||
}
|
||||
|
||||
Assert( _clipRect[0] <= _clipRect[2] );
|
||||
Assert( _clipRect[1] <= _clipRect[3] );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetPos(int x, int y)
|
||||
{
|
||||
_pos[0] = x;
|
||||
_pos[1] = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetPos(int &x, int &y)
|
||||
{
|
||||
x = _pos[0];
|
||||
y = _pos[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetSize(int wide,int tall)
|
||||
{
|
||||
if (wide<_minimumSize[0])
|
||||
{
|
||||
wide=_minimumSize[0];
|
||||
}
|
||||
if (tall<_minimumSize[1])
|
||||
{
|
||||
tall=_minimumSize[1];
|
||||
}
|
||||
|
||||
if (_size[0] == wide && _size[1] == tall)
|
||||
return;
|
||||
|
||||
_size[0]=wide;
|
||||
_size[1]=tall;
|
||||
|
||||
Client()->OnSizeChanged(wide, tall);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetSize(int& wide,int& tall)
|
||||
{
|
||||
wide=_size[0];
|
||||
tall=_size[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetMinimumSize(int wide,int tall)
|
||||
{
|
||||
_minimumSize[0]=wide;
|
||||
_minimumSize[1]=tall;
|
||||
|
||||
// check if we're currently smaller than the new minimum size
|
||||
int currentWidth = _size[0];
|
||||
if (currentWidth < wide)
|
||||
{
|
||||
currentWidth = wide;
|
||||
}
|
||||
int currentHeight = _size[1];
|
||||
if (currentHeight < tall)
|
||||
{
|
||||
currentHeight = tall;
|
||||
}
|
||||
|
||||
// resize to new minimum size if necessary
|
||||
if (currentWidth != _size[0] || currentHeight != _size[1])
|
||||
{
|
||||
SetSize(currentWidth, currentHeight);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetMinimumSize(int &wide, int &tall)
|
||||
{
|
||||
wide = _minimumSize[0];
|
||||
tall = _minimumSize[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetVisible(bool state)
|
||||
{
|
||||
if (_visible == state)
|
||||
return;
|
||||
|
||||
// need to tell the surface (in case special window processing needs to occur)
|
||||
g_pSurface->SetPanelVisible((VPANEL)this, state);
|
||||
|
||||
_visible = state;
|
||||
|
||||
if( IsPopup() )
|
||||
{
|
||||
vgui::g_pSurface->CalculateMouseVisible();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetEnabled(bool state)
|
||||
{
|
||||
_enabled = state;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VPanel::IsVisible()
|
||||
{
|
||||
return _visible;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VPanel::IsEnabled()
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetAbsPos(int &x, int &y)
|
||||
{
|
||||
x = _absPos[0];
|
||||
y = _absPos[1];
|
||||
|
||||
g_pSurface->OffsetAbsPos( x, y );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetInternalAbsPos(int &x, int &y)
|
||||
{
|
||||
x = _absPos[0];
|
||||
y = _absPos[1];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetClipRect(int &x0, int &y0, int &x1, int &y1)
|
||||
{
|
||||
x0 = _clipRect[0];
|
||||
y0 = _clipRect[1];
|
||||
x1 = _clipRect[2];
|
||||
y1 = _clipRect[3];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetInset(int left, int top, int right, int bottom)
|
||||
{
|
||||
_inset[0] = left;
|
||||
_inset[1] = top;
|
||||
_inset[2] = right;
|
||||
_inset[3] = bottom;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::GetInset(int &left, int &top, int &right, int &bottom)
|
||||
{
|
||||
left = _inset[0];
|
||||
top = _inset[1];
|
||||
right = _inset[2];
|
||||
bottom = _inset[3];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetParent(VPanel *newParent)
|
||||
{
|
||||
if (this == newParent)
|
||||
return;
|
||||
|
||||
if (_parent == newParent)
|
||||
return;
|
||||
|
||||
if (_parent != NULL)
|
||||
{
|
||||
_parent->_childDar.RemoveElement(this);
|
||||
_parent = null;
|
||||
}
|
||||
|
||||
if (newParent != NULL)
|
||||
{
|
||||
_parent = newParent;
|
||||
_parent->_childDar.PutElement(this);
|
||||
SetZPos(_zpos); // re-sort parent's panel order if necessary
|
||||
if (_parent->Client())
|
||||
{
|
||||
_parent->Client()->OnChildAdded((VPANEL)this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
int VPanel::GetChildCount()
|
||||
{
|
||||
return _childDar.GetCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
VPanel *VPanel::GetChild(int index)
|
||||
{
|
||||
return _childDar[index];
|
||||
}
|
||||
|
||||
CUtlVector< VPanel *> &VPanel::GetChildren()
|
||||
{
|
||||
return _childDar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
VPanel *VPanel::GetParent()
|
||||
{
|
||||
return _parent;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sets the Z position of a panel and reorders it appropriately
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetZPos(int z)
|
||||
{
|
||||
_zpos = z;
|
||||
|
||||
if (_parent)
|
||||
{
|
||||
// find the child in the list
|
||||
int childCount = _parent->GetChildCount();
|
||||
int i;
|
||||
for (i = 0; i < childCount; i++)
|
||||
{
|
||||
if (_parent->GetChild(i) == this)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == childCount)
|
||||
return;
|
||||
|
||||
while (1)
|
||||
{
|
||||
VPanel *prevChild = NULL, *nextChild = NULL;
|
||||
|
||||
if ( i > 0 )
|
||||
{
|
||||
prevChild = _parent->GetChild( i - 1 );
|
||||
}
|
||||
if ( i <(childCount - 1) )
|
||||
{
|
||||
nextChild = _parent->GetChild( i + 1 );
|
||||
}
|
||||
|
||||
// check either side of the child to see if it should move
|
||||
if ( i > 0 && prevChild && ( prevChild->_zpos > _zpos ) )
|
||||
{
|
||||
// swap with the lower
|
||||
_parent->_childDar.SetElementAt(prevChild, i);
|
||||
_parent->_childDar.SetElementAt(this, i - 1);
|
||||
i--;
|
||||
}
|
||||
else if (i < (childCount - 1) && nextChild && ( nextChild->_zpos < _zpos ) )
|
||||
{
|
||||
// swap with the higher
|
||||
_parent->_childDar.SetElementAt(nextChild, i);
|
||||
_parent->_childDar.SetElementAt(this, i + 1);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the z position of this panel
|
||||
//-----------------------------------------------------------------------------
|
||||
int VPanel::GetZPos()
|
||||
{
|
||||
return _zpos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Moves the panel to the front of the z-order
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::MoveToFront(void)
|
||||
{
|
||||
g_pSurface->MovePopupToFront((VPANEL)this);
|
||||
|
||||
if (_parent)
|
||||
{
|
||||
// move this panel to the end of it's parents list
|
||||
_parent->_childDar.MoveElementToEnd(this);
|
||||
|
||||
// Validate the Z order
|
||||
int i = _parent->_childDar.GetCount() - 2;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (_parent->_childDar[i]->_zpos > _zpos)
|
||||
{
|
||||
// we can't be in front of this; swap positions
|
||||
_parent->_childDar.SetElementAt(_parent->_childDar[i], i + 1);
|
||||
_parent->_childDar.SetElementAt(this, i);
|
||||
|
||||
// check the next value
|
||||
i--;
|
||||
}
|
||||
else
|
||||
{
|
||||
// order valid
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Moves the panel to the back of the z-order
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::MoveToBack()
|
||||
{
|
||||
if (_parent)
|
||||
{
|
||||
// move this panel to the end of it's parents list
|
||||
_parent->_childDar.RemoveElement(this);
|
||||
_parent->_childDar.InsertElementAt(this, 0);
|
||||
|
||||
// Validate the Z order
|
||||
int i = 1;
|
||||
while (i < _parent->_childDar.GetCount())
|
||||
{
|
||||
if (_parent->_childDar[i]->_zpos < _zpos)
|
||||
{
|
||||
// we can't be behind this; swap positions
|
||||
_parent->_childDar.SetElementAt(_parent->_childDar[i], i - 1);
|
||||
_parent->_childDar.SetElementAt(this, i);
|
||||
|
||||
// check the next value
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// order valid
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Iterates up the hierarchy looking to see if a panel has the specified ancestor
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VPanel::HasParent(VPanel *potentialParent)
|
||||
{
|
||||
if (this == potentialParent)
|
||||
return true;
|
||||
|
||||
if (_parent)
|
||||
{
|
||||
return _parent->HasParent(potentialParent);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SurfacePlat *VPanel::Plat()
|
||||
{
|
||||
return _plat;
|
||||
}
|
||||
|
||||
void VPanel::SetPlat(SurfacePlat *Plat)
|
||||
{
|
||||
_plat = Plat;
|
||||
}
|
||||
|
||||
bool VPanel::IsPopup()
|
||||
{
|
||||
return _popup;
|
||||
}
|
||||
|
||||
void VPanel::SetPopup(bool state)
|
||||
{
|
||||
_popup = state;
|
||||
}
|
||||
|
||||
bool VPanel::IsTopmostPopup() const
|
||||
{
|
||||
return _isTopmostPopup;
|
||||
}
|
||||
|
||||
void VPanel::SetTopmostPopup( bool bEnable )
|
||||
{
|
||||
_isTopmostPopup = bEnable;
|
||||
}
|
||||
|
||||
bool VPanel::IsFullyVisible()
|
||||
{
|
||||
// recursively check to see if the panel and all it's parents are visible
|
||||
VPanel *panel = this;
|
||||
while (panel)
|
||||
{
|
||||
if (!panel->_visible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
panel = panel->_parent;
|
||||
}
|
||||
|
||||
// we're visible all the way up the hierarchy
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *VPanel::GetName()
|
||||
{
|
||||
return Client()->GetName();
|
||||
}
|
||||
|
||||
const char *VPanel::GetClassName()
|
||||
{
|
||||
return Client()->GetClassName();
|
||||
}
|
||||
|
||||
HScheme VPanel::GetScheme()
|
||||
{
|
||||
return Client()->GetScheme();
|
||||
}
|
||||
|
||||
|
||||
void VPanel::SendMessage(KeyValues *params, VPANEL ifrompanel)
|
||||
{
|
||||
Client()->OnMessage(params, ifrompanel);
|
||||
}
|
||||
|
||||
|
||||
void VPanel::SetKeyBoardInputEnabled(bool state)
|
||||
{
|
||||
_kbInput = state;
|
||||
}
|
||||
|
||||
void VPanel::SetMouseInputEnabled(bool state)
|
||||
{
|
||||
_mouseInput = state;
|
||||
}
|
||||
|
||||
bool VPanel::IsKeyBoardInputEnabled()
|
||||
{
|
||||
return _kbInput;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VPanel::IsMouseInputEnabled()
|
||||
{
|
||||
return _mouseInput;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sibling pins
|
||||
//-----------------------------------------------------------------------------
|
||||
void VPanel::SetSiblingPin(VPanel *newSibling, byte iMyCornerToPin, byte iSiblingCornerToPinTo )
|
||||
{
|
||||
_pinsibling = newSibling;
|
||||
_pinsibling_my_corner = iMyCornerToPin;
|
||||
_pinsibling_their_corner = iSiblingCornerToPinTo;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VPANEL_H
|
||||
#define VPANEL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/Dar.h>
|
||||
#include <vgui/IPanel.h>
|
||||
|
||||
#ifdef GetClassName
|
||||
#undef GetClassName
|
||||
#endif
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
class SurfaceBase;
|
||||
class IClientPanel;
|
||||
struct SerialPanel_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: VGUI private implementation of panel
|
||||
//-----------------------------------------------------------------------------
|
||||
class VPanel
|
||||
{
|
||||
public:
|
||||
VPanel();
|
||||
virtual ~VPanel();
|
||||
|
||||
virtual void Init(IClientPanel *attachedClientPanel);
|
||||
|
||||
virtual SurfacePlat *Plat();
|
||||
virtual void SetPlat(SurfacePlat *pl);
|
||||
|
||||
virtual HPanel GetHPanel() { return _hPanel; } // safe pointer handling
|
||||
virtual void SetHPanel(HPanel hPanel) { _hPanel = hPanel; }
|
||||
|
||||
virtual bool IsPopup();
|
||||
virtual void SetPopup(bool state);
|
||||
virtual bool IsFullyVisible();
|
||||
|
||||
virtual void SetPos(int x, int y);
|
||||
virtual void GetPos(int &x, int &y);
|
||||
virtual void SetSize(int wide,int tall);
|
||||
virtual void GetSize(int& wide,int& tall);
|
||||
virtual void SetMinimumSize(int wide,int tall);
|
||||
virtual void GetMinimumSize(int& wide,int& tall);
|
||||
virtual void SetZPos(int z);
|
||||
virtual int GetZPos();
|
||||
|
||||
virtual void GetAbsPos(int &x, int &y);
|
||||
virtual void GetClipRect(int &x0, int &y0, int &x1, int &y1);
|
||||
virtual void SetInset(int left, int top, int right, int bottom);
|
||||
virtual void GetInset(int &left, int &top, int &right, int &bottom);
|
||||
|
||||
virtual void Solve();
|
||||
|
||||
virtual void SetVisible(bool state);
|
||||
virtual void SetEnabled(bool state);
|
||||
virtual bool IsVisible();
|
||||
virtual bool IsEnabled();
|
||||
virtual void SetParent(VPanel *newParent);
|
||||
virtual int GetChildCount();
|
||||
virtual VPanel *GetChild(int index);
|
||||
virtual VPanel *GetParent();
|
||||
virtual void MoveToFront();
|
||||
virtual void MoveToBack();
|
||||
virtual bool HasParent(VPanel *potentialParent);
|
||||
|
||||
virtual CUtlVector< VPanel * > &GetChildren();
|
||||
|
||||
// gets names of the object (for debugging purposes)
|
||||
virtual const char *GetName();
|
||||
virtual const char *GetClassName();
|
||||
|
||||
virtual HScheme GetScheme();
|
||||
|
||||
// handles a message
|
||||
virtual void SendMessage(KeyValues *params, VPANEL ifromPanel);
|
||||
|
||||
// wrapper to get Client panel interface
|
||||
virtual IClientPanel *Client() { return _clientPanel; }
|
||||
|
||||
// input interest
|
||||
virtual void SetKeyBoardInputEnabled(bool state);
|
||||
virtual void SetMouseInputEnabled(bool state);
|
||||
virtual bool IsKeyBoardInputEnabled();
|
||||
virtual bool IsMouseInputEnabled();
|
||||
|
||||
virtual bool IsTopmostPopup() const;
|
||||
virtual void SetTopmostPopup( bool bEnable );
|
||||
|
||||
// sibling pins
|
||||
virtual void SetSiblingPin(VPanel *newSibling, byte iMyCornerToPin = 0, byte iSiblingCornerToPinTo = 0 );
|
||||
|
||||
public:
|
||||
virtual void GetInternalAbsPos(int &x, int &y);
|
||||
virtual void TraverseLevel( int val );
|
||||
|
||||
private:
|
||||
Dar<VPanel*> _childDar;
|
||||
VPanel *_parent;
|
||||
SurfacePlat *_plat; // platform-specific data
|
||||
HPanel _hPanel;
|
||||
|
||||
// our companion Client panel
|
||||
IClientPanel *_clientPanel;
|
||||
|
||||
short _pos[2];
|
||||
short _size[2];
|
||||
short _minimumSize[2];
|
||||
|
||||
short _inset[4];
|
||||
short _clipRect[4];
|
||||
short _absPos[2];
|
||||
|
||||
short _zpos; // z-order position
|
||||
|
||||
bool _visible : 1;
|
||||
bool _enabled : 1;
|
||||
bool _popup : 1;
|
||||
bool _mouseInput : 1; // used for popups
|
||||
bool _kbInput : 1;
|
||||
bool _isTopmostPopup : 1;
|
||||
|
||||
VPanel *_pinsibling;
|
||||
byte _pinsibling_my_corner;
|
||||
byte _pinsibling_their_corner;
|
||||
|
||||
int m_nMessageContextId;
|
||||
int m_nThinkTraverseLevel;
|
||||
HPanel _clientPanelHandle; // Temp to check if _clientPanel is valid.
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // VPANEL_H
|
||||
@@ -0,0 +1,362 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "VPanel.h"
|
||||
#include "vgui_internal.h"
|
||||
|
||||
#include <vgui/IClientPanel.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include <vgui/ISurface.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Protects internal VPanel through the versionable interface IPanel
|
||||
//-----------------------------------------------------------------------------
|
||||
class VPanelWrapper : public vgui::IPanel
|
||||
{
|
||||
public:
|
||||
virtual void Init(VPANEL vguiPanel, IClientPanel *panel)
|
||||
{
|
||||
((VPanel *)vguiPanel)->Init(panel);
|
||||
}
|
||||
|
||||
// returns a pointer to the Client panel
|
||||
virtual IClientPanel *Client(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->Client();
|
||||
}
|
||||
|
||||
// methods
|
||||
virtual void SetPos(VPANEL vguiPanel, int x, int y)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetPos(x, y);
|
||||
}
|
||||
|
||||
virtual void GetPos(VPANEL vguiPanel, int &x, int &y)
|
||||
{
|
||||
((VPanel *)vguiPanel)->GetPos(x, y);
|
||||
}
|
||||
|
||||
virtual void SetSize(VPANEL vguiPanel, int wide,int tall)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetSize(wide, tall);
|
||||
}
|
||||
|
||||
virtual void GetSize(VPANEL vguiPanel, int &wide, int &tall)
|
||||
{
|
||||
((VPanel *)vguiPanel)->GetSize(wide, tall);
|
||||
}
|
||||
|
||||
virtual void SetMinimumSize(VPANEL vguiPanel, int wide, int tall)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetMinimumSize(wide, tall);
|
||||
}
|
||||
|
||||
virtual void GetMinimumSize(VPANEL vguiPanel, int &wide, int &tall)
|
||||
{
|
||||
((VPanel *)vguiPanel)->GetMinimumSize(wide, tall);
|
||||
}
|
||||
|
||||
virtual void SetZPos(VPANEL vguiPanel, int z)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetZPos(z);
|
||||
}
|
||||
|
||||
virtual int GetZPos(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->GetZPos();
|
||||
}
|
||||
|
||||
virtual void GetAbsPos(VPANEL vguiPanel, int &x, int &y)
|
||||
{
|
||||
((VPanel *)vguiPanel)->GetAbsPos(x, y);
|
||||
}
|
||||
|
||||
virtual void GetClipRect(VPANEL vguiPanel, int &x0, int &y0, int &x1, int &y1)
|
||||
{
|
||||
((VPanel *)vguiPanel)->GetClipRect(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
virtual void SetInset(VPANEL vguiPanel, int left, int top, int right, int bottom)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetInset(left, top, right, bottom);
|
||||
}
|
||||
|
||||
virtual void GetInset(VPANEL vguiPanel, int &left, int &top, int &right, int &bottom)
|
||||
{
|
||||
((VPanel *)vguiPanel)->GetInset(left, top, right, bottom);
|
||||
}
|
||||
|
||||
virtual void SetVisible(VPANEL vguiPanel, bool state)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetVisible(state);
|
||||
}
|
||||
|
||||
virtual void SetEnabled(VPANEL vguiPanel, bool state)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetEnabled(state);
|
||||
}
|
||||
|
||||
virtual bool IsVisible(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsVisible();
|
||||
}
|
||||
|
||||
virtual bool IsEnabled(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsEnabled();
|
||||
}
|
||||
|
||||
// Used by the drag/drop manager to always draw on top
|
||||
virtual bool IsTopmostPopup( VPANEL vguiPanel )
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsTopmostPopup();
|
||||
}
|
||||
|
||||
virtual void SetTopmostPopup( VPANEL vguiPanel, bool state )
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->SetTopmostPopup( state );
|
||||
}
|
||||
|
||||
virtual void SetParent(VPANEL vguiPanel, VPANEL newParent)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetParent((VPanel *)newParent);
|
||||
}
|
||||
|
||||
virtual int GetChildCount(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->GetChildCount();
|
||||
}
|
||||
|
||||
virtual VPANEL GetChild(VPANEL vguiPanel, int index)
|
||||
{
|
||||
return (VPANEL)((VPanel *)vguiPanel)->GetChild(index);
|
||||
}
|
||||
|
||||
virtual CUtlVector< VPANEL > &GetChildren( VPANEL vguiPanel )
|
||||
{
|
||||
return (CUtlVector< VPANEL > &)((VPanel *)vguiPanel)->GetChildren();
|
||||
}
|
||||
|
||||
virtual VPANEL GetParent(VPANEL vguiPanel)
|
||||
{
|
||||
return (VPANEL)((VPanel *)vguiPanel)->GetParent();
|
||||
}
|
||||
|
||||
virtual void MoveToFront(VPANEL vguiPanel)
|
||||
{
|
||||
((VPanel *)vguiPanel)->MoveToFront();
|
||||
}
|
||||
|
||||
virtual void MoveToBack(VPANEL vguiPanel)
|
||||
{
|
||||
((VPanel *)vguiPanel)->MoveToBack();
|
||||
}
|
||||
|
||||
virtual bool HasParent(VPANEL vguiPanel, VPANEL potentialParent)
|
||||
{
|
||||
if (!vguiPanel)
|
||||
return false;
|
||||
|
||||
return ((VPanel *)vguiPanel)->HasParent((VPanel *)potentialParent);
|
||||
}
|
||||
|
||||
virtual bool IsPopup(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsPopup();
|
||||
}
|
||||
|
||||
virtual void SetPopup(VPANEL vguiPanel, bool state)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetPopup(state);
|
||||
}
|
||||
|
||||
virtual bool IsFullyVisible( VPANEL vguiPanel )
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsFullyVisible();
|
||||
}
|
||||
|
||||
// calculates the panels current position within the hierarchy
|
||||
virtual void Solve(VPANEL vguiPanel)
|
||||
{
|
||||
((VPanel *)vguiPanel)->Solve();
|
||||
}
|
||||
|
||||
// used by ISurface to store platform-specific data
|
||||
virtual SurfacePlat *Plat(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->Plat();
|
||||
}
|
||||
|
||||
virtual void SetPlat(VPANEL vguiPanel, SurfacePlat *Plat)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetPlat(Plat);
|
||||
}
|
||||
|
||||
virtual const char *GetName(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->GetName();
|
||||
}
|
||||
|
||||
virtual const char *GetClassName(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->GetClassName();
|
||||
}
|
||||
|
||||
virtual HScheme GetScheme(VPANEL vguiPanel)
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->GetScheme();
|
||||
}
|
||||
|
||||
virtual bool IsProportional(VPANEL vguiPanel)
|
||||
{
|
||||
return Client(vguiPanel)->IsProportional();
|
||||
}
|
||||
|
||||
virtual bool IsAutoDeleteSet(VPANEL vguiPanel)
|
||||
{
|
||||
return Client(vguiPanel)->IsAutoDeleteSet();
|
||||
}
|
||||
|
||||
virtual void DeletePanel(VPANEL vguiPanel)
|
||||
{
|
||||
Client(vguiPanel)->DeletePanel();
|
||||
}
|
||||
|
||||
virtual void SendMessage(VPANEL vguiPanel, KeyValues *params, VPANEL ifrompanel)
|
||||
{
|
||||
((VPanel *)vguiPanel)->SendMessage(params, ifrompanel);
|
||||
}
|
||||
|
||||
virtual void Think(VPANEL vguiPanel)
|
||||
{
|
||||
Client(vguiPanel)->Think();
|
||||
}
|
||||
|
||||
virtual void PerformApplySchemeSettings(VPANEL vguiPanel)
|
||||
{
|
||||
Client(vguiPanel)->PerformApplySchemeSettings();
|
||||
}
|
||||
|
||||
virtual void PaintTraverse(VPANEL vguiPanel, bool forceRepaint, bool allowForce)
|
||||
{
|
||||
Client(vguiPanel)->PaintTraverse(forceRepaint, allowForce);
|
||||
}
|
||||
|
||||
virtual void Repaint(VPANEL vguiPanel)
|
||||
{
|
||||
Client(vguiPanel)->Repaint();
|
||||
}
|
||||
|
||||
virtual VPANEL IsWithinTraverse(VPANEL vguiPanel, int x, int y, bool traversePopups)
|
||||
{
|
||||
return Client(vguiPanel)->IsWithinTraverse(x, y, traversePopups);
|
||||
}
|
||||
|
||||
virtual void OnChildAdded(VPANEL vguiPanel, VPANEL child)
|
||||
{
|
||||
Client(vguiPanel)->OnChildAdded(child);
|
||||
}
|
||||
|
||||
virtual void OnSizeChanged(VPANEL vguiPanel, int newWide, int newTall)
|
||||
{
|
||||
Client(vguiPanel)->OnSizeChanged(newWide, newTall);
|
||||
}
|
||||
|
||||
virtual void InternalFocusChanged(VPANEL vguiPanel, bool lost)
|
||||
{
|
||||
Client(vguiPanel)->InternalFocusChanged(lost);
|
||||
}
|
||||
|
||||
virtual bool RequestInfo(VPANEL vguiPanel, KeyValues *outputData)
|
||||
{
|
||||
return Client(vguiPanel)->RequestInfo(outputData);
|
||||
}
|
||||
|
||||
virtual void RequestFocus(VPANEL vguiPanel, int direction = 0)
|
||||
{
|
||||
Client(vguiPanel)->RequestFocus(direction);
|
||||
}
|
||||
|
||||
virtual bool RequestFocusPrev(VPANEL vguiPanel, VPANEL existingPanel)
|
||||
{
|
||||
return Client(vguiPanel)->RequestFocusPrev(existingPanel);
|
||||
}
|
||||
|
||||
virtual bool RequestFocusNext(VPANEL vguiPanel, VPANEL existingPanel)
|
||||
{
|
||||
return Client(vguiPanel)->RequestFocusNext(existingPanel);
|
||||
}
|
||||
|
||||
virtual VPANEL GetCurrentKeyFocus(VPANEL vguiPanel)
|
||||
{
|
||||
return Client(vguiPanel)->GetCurrentKeyFocus();
|
||||
}
|
||||
|
||||
virtual int GetTabPosition(VPANEL vguiPanel)
|
||||
{
|
||||
return Client(vguiPanel)->GetTabPosition();
|
||||
}
|
||||
|
||||
virtual Panel *GetPanel(VPANEL vguiPanel, const char *moduleName)
|
||||
{
|
||||
if (!vguiPanel)
|
||||
return NULL;
|
||||
|
||||
if (vguiPanel == g_pSurface->GetEmbeddedPanel())
|
||||
return NULL;
|
||||
|
||||
// assert that the specified vpanel is from the same module as requesting the cast
|
||||
if ( !vguiPanel || V_stricmp(GetModuleName(vguiPanel), moduleName) )
|
||||
{
|
||||
// assert(!("GetPanel() used to retrieve a Panel * from a different dll than which which it was created. This is bad, you can't pass Panel * across dll boundaries else you'll break the versioning. Please only use a VPANEL."));
|
||||
// this is valid for now
|
||||
return NULL;
|
||||
}
|
||||
return Client(vguiPanel)->GetPanel();
|
||||
}
|
||||
|
||||
virtual const char *GetModuleName(VPANEL vguiPanel)
|
||||
{
|
||||
return Client(vguiPanel)->GetModuleName();
|
||||
}
|
||||
|
||||
virtual void SetKeyBoardInputEnabled( VPANEL vguiPanel, bool state )
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetKeyBoardInputEnabled(state);
|
||||
}
|
||||
|
||||
virtual void SetMouseInputEnabled( VPANEL vguiPanel, bool state )
|
||||
{
|
||||
((VPanel *)vguiPanel)->SetMouseInputEnabled(state);
|
||||
}
|
||||
|
||||
virtual bool IsMouseInputEnabled( VPANEL vguiPanel )
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsMouseInputEnabled();
|
||||
}
|
||||
|
||||
virtual bool IsKeyBoardInputEnabled( VPANEL vguiPanel )
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->IsKeyBoardInputEnabled();
|
||||
}
|
||||
|
||||
virtual void SetSiblingPin(VPANEL vguiPanel, VPANEL newSibling, byte iMyCornerToPin = 0, byte iSiblingCornerToPinTo = 0 )
|
||||
{
|
||||
return ((VPanel *)vguiPanel)->SetSiblingPin( (VPanel *)newSibling, iMyCornerToPin, iSiblingCornerToPinTo );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE(VPanelWrapper, IPanel, VGUI_PANEL_INTERFACE_VERSION);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef BITMAP_H
|
||||
#define BITMAP_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/IImage.h>
|
||||
#include <Color.h>
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Holds a single image, internal to vgui only
|
||||
//-----------------------------------------------------------------------------
|
||||
class Bitmap : public IImage
|
||||
{
|
||||
public:
|
||||
Bitmap( const char *filename, bool hardwareFiltered );
|
||||
~Bitmap();
|
||||
|
||||
// IImage implementation
|
||||
virtual void Paint();
|
||||
virtual void GetSize( int &wide, int &tall );
|
||||
virtual void GetContentSize( int &wide, int &tall );
|
||||
virtual void SetSize( int x, int y );
|
||||
virtual void SetPos( int x, int y );
|
||||
virtual void SetColor( Color col );
|
||||
virtual bool Evict();
|
||||
virtual int GetNumFrames();
|
||||
virtual void SetFrame( int nFrame );
|
||||
virtual HTexture GetID(); // returns the texture id
|
||||
virtual void SetRotation( int iRotation ) { _rotation = iRotation; }
|
||||
|
||||
// methods
|
||||
void ForceUpload(); // ensures the bitmap has been uploaded
|
||||
const char *GetName();
|
||||
bool IsValid() { return _valid; }
|
||||
|
||||
private:
|
||||
HTexture _id;
|
||||
bool _uploaded;
|
||||
bool _valid;
|
||||
char *_filename;
|
||||
int _pos[2];
|
||||
Color _color;
|
||||
bool _filtered;
|
||||
int _wide,_tall;
|
||||
bool _bProcedural;
|
||||
unsigned int nFrameCache;
|
||||
int _rotation;
|
||||
};
|
||||
|
||||
} // namespace vgui
|
||||
|
||||
#endif // BITMAP_H
|
||||
@@ -0,0 +1,211 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "fileimage.h"
|
||||
|
||||
#include "winlite.h"
|
||||
#include "vgui_internal.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
// TGA header.
|
||||
#pragma pack(1)
|
||||
class TGAFileHeader
|
||||
{
|
||||
public:
|
||||
unsigned char m_IDLength;
|
||||
unsigned char m_ColorMapType;
|
||||
unsigned char m_ImageType;
|
||||
unsigned short m_CMapStart;
|
||||
unsigned short m_CMapLength;
|
||||
unsigned char m_CMapDepth;
|
||||
unsigned short m_XOffset;
|
||||
unsigned short m_YOffset;
|
||||
unsigned short m_Width;
|
||||
unsigned short m_Height;
|
||||
unsigned char m_PixelDepth;
|
||||
unsigned char m_ImageDescriptor;
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------- //
|
||||
// FileImageStream_Memory.
|
||||
// ---------------------------------------------------------------------------------------- //
|
||||
FileImageStream_Memory::FileImageStream_Memory(void *pData, int dataLen)
|
||||
{
|
||||
m_pData = (unsigned char*)pData;
|
||||
m_DataLen = dataLen;
|
||||
m_CurPos = 0;
|
||||
m_bError = false;
|
||||
}
|
||||
|
||||
void FileImageStream_Memory::Read(void *pData, int len)
|
||||
{
|
||||
unsigned char *pOut;
|
||||
int i;
|
||||
|
||||
pOut = (unsigned char*)pData;
|
||||
for(i=0; i < len; i++)
|
||||
{
|
||||
if(m_CurPos < m_DataLen)
|
||||
{
|
||||
pOut[i] = m_pData[m_CurPos];
|
||||
++m_CurPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
pOut[i] = 0;
|
||||
m_bError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FileImageStream_Memory::ErrorStatus()
|
||||
{
|
||||
bool ret=m_bError;
|
||||
m_bError=false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------- //
|
||||
// Encode/decode functions.
|
||||
// ---------------------------------------------------------------------------------------- //
|
||||
static void WriteRun(unsigned char *pColor, FileHandle_t fp, int runLength)
|
||||
{
|
||||
unsigned char runCount;
|
||||
|
||||
runCount = runLength - 1;
|
||||
runCount |= (1 << 7);
|
||||
g_pFullFileSystem->Write( &runCount, 1, fp );
|
||||
g_pFullFileSystem->Write( pColor, 4, fp );
|
||||
}
|
||||
|
||||
|
||||
// Load in a 32-bit TGA file.
|
||||
bool Load32BitTGA(
|
||||
FileImageStream *fp,
|
||||
FileImage *pImage)
|
||||
{
|
||||
TGAFileHeader hdr;
|
||||
char dummyChar;
|
||||
int i, x, y;
|
||||
long color;
|
||||
int runLength, curOut;
|
||||
unsigned char *pLine;
|
||||
unsigned char packetHeader;
|
||||
|
||||
|
||||
pImage->Term();
|
||||
|
||||
// Read and verify the header.
|
||||
fp->Read(&hdr, sizeof(hdr));
|
||||
if(hdr.m_PixelDepth != 32 || hdr.m_ImageType != 10)
|
||||
return false;
|
||||
|
||||
// Skip the ID area..
|
||||
for(i=0; i < hdr.m_IDLength; i++)
|
||||
fp->Read(&dummyChar, 1);
|
||||
|
||||
pImage->m_Width = hdr.m_Width;
|
||||
pImage->m_Height = hdr.m_Height;
|
||||
pImage->m_pData = new unsigned char[hdr.m_Width * hdr.m_Height * 4];
|
||||
if(!pImage->m_pData)
|
||||
return false;
|
||||
|
||||
// Read in the data..
|
||||
for(y=pImage->m_Height-1; y >= 0; y--)
|
||||
{
|
||||
pLine = &pImage->m_pData[y*pImage->m_Width*4];
|
||||
|
||||
curOut = 0;
|
||||
while(curOut < pImage->m_Width)
|
||||
{
|
||||
fp->Read(&packetHeader, 1);
|
||||
|
||||
runLength = (int)(packetHeader & ~(1 << 7)) + 1;
|
||||
if(curOut + runLength > pImage->m_Width)
|
||||
return false;
|
||||
|
||||
if(packetHeader & (1 << 7))
|
||||
{
|
||||
fp->Read(&color, 4);
|
||||
for(x=0; x < runLength; x++)
|
||||
{
|
||||
*((long*)pLine) = color;
|
||||
pLine += 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(x=0; x < runLength; x++)
|
||||
{
|
||||
fp->Read(&color, 4);
|
||||
*((long*)pLine) = color;
|
||||
pLine += 4;
|
||||
}
|
||||
}
|
||||
|
||||
curOut += runLength;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Write a 32-bit TGA file.
|
||||
void Save32BitTGA(
|
||||
FileHandle_t fp,
|
||||
FileImage *pImage)
|
||||
{
|
||||
TGAFileHeader hdr;
|
||||
int y, runStart, x;
|
||||
unsigned char *pLine;
|
||||
|
||||
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
hdr.m_PixelDepth = 32;
|
||||
hdr.m_ImageType = 10; // Run-length encoded RGB.
|
||||
hdr.m_Width = pImage->m_Width;
|
||||
hdr.m_Height = pImage->m_Height;
|
||||
|
||||
g_pFullFileSystem->Write(&hdr, sizeof(hdr), fp );
|
||||
|
||||
// Lines are written bottom-up.
|
||||
for(y=pImage->m_Height-1; y >= 0; y--)
|
||||
{
|
||||
pLine = &pImage->m_pData[y*pImage->m_Width*4];
|
||||
|
||||
runStart = 0;
|
||||
for(x=0; x < pImage->m_Width; x++)
|
||||
{
|
||||
if((x - runStart) >= 128 ||
|
||||
*((long*)&pLine[runStart*4]) != *((long*)&pLine[x*4]))
|
||||
{
|
||||
// Encode this Run.
|
||||
WriteRun(&pLine[runStart*4], fp, x - runStart);
|
||||
runStart = x;
|
||||
}
|
||||
}
|
||||
|
||||
// Encode the last Run.
|
||||
if(x - runStart > 0)
|
||||
{
|
||||
WriteRun(&pLine[runStart*4], fp, x - runStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef __FILEIMAGE_H__
|
||||
#define __FILEIMAGE_H__
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef void *FileHandle_t;
|
||||
|
||||
class FileImageStream
|
||||
{
|
||||
public:
|
||||
virtual void Read(void *pOut, int len)=0;
|
||||
|
||||
// Returns true if there were any Read errors.
|
||||
// Clears error status.
|
||||
virtual bool ErrorStatus()=0;
|
||||
};
|
||||
|
||||
|
||||
// Use to read out of a memory buffer..
|
||||
class FileImageStream_Memory : public FileImageStream
|
||||
{
|
||||
public:
|
||||
FileImageStream_Memory(void *pData, int dataLen);
|
||||
|
||||
virtual void Read(void *pOut, int len);
|
||||
virtual bool ErrorStatus();
|
||||
|
||||
|
||||
private:
|
||||
unsigned char *m_pData;
|
||||
int m_DataLen;
|
||||
int m_CurPos;
|
||||
bool m_bError;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Generic image representation..
|
||||
class FileImage
|
||||
{
|
||||
public:
|
||||
FileImage()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
~FileImage()
|
||||
{
|
||||
Term();
|
||||
}
|
||||
|
||||
void Term()
|
||||
{
|
||||
if(m_pData)
|
||||
delete [] m_pData;
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
// Clear the structure without deallocating.
|
||||
void Clear()
|
||||
{
|
||||
m_Width = m_Height = 0;
|
||||
m_pData = NULL;
|
||||
}
|
||||
|
||||
int m_Width, m_Height;
|
||||
unsigned char *m_pData;
|
||||
};
|
||||
|
||||
|
||||
// Functions to load/save FileImages.
|
||||
bool Load32BitTGA(
|
||||
FileImageStream *fp,
|
||||
FileImage *pImage);
|
||||
|
||||
void Save32BitTGA(
|
||||
FileHandle_t fp,
|
||||
FileImage *pImage);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "inputsystem/InputEnums.h"
|
||||
|
||||
#include "vgui/KeyCode.h"
|
||||
#include "vgui/keyrepeat.h"
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//#define DEBUG_REPEATS
|
||||
|
||||
#ifdef DEBUG_REPEATS
|
||||
#define DbgRepeat(...) ConMsg( __VA_ARGS__ )
|
||||
#else
|
||||
#define DbgRepeat(...)
|
||||
#endif
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
vgui::KeyCode g_iCodesForAliases[FM_NUM_KEYREPEAT_ALIASES] =
|
||||
{
|
||||
KEY_XBUTTON_UP,
|
||||
KEY_XBUTTON_DOWN,
|
||||
KEY_XBUTTON_LEFT,
|
||||
KEY_XBUTTON_RIGHT
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Map joystick codes to our internal ones
|
||||
//-----------------------------------------------------------------------------
|
||||
static int GetIndexForCode( vgui::KeyCode code )
|
||||
{
|
||||
KeyCode localCode = GetBaseButtonCode( code );
|
||||
|
||||
switch ( localCode )
|
||||
{
|
||||
case KEY_XBUTTON_DOWN:
|
||||
case KEY_XSTICK1_DOWN:
|
||||
case KEY_XSTICK2_DOWN:
|
||||
return KR_ALIAS_DOWN; break;
|
||||
case KEY_XBUTTON_UP:
|
||||
case KEY_XSTICK1_UP:
|
||||
case KEY_XSTICK2_UP:
|
||||
return KR_ALIAS_UP; break;
|
||||
case KEY_XBUTTON_LEFT:
|
||||
case KEY_XSTICK1_LEFT:
|
||||
case KEY_XSTICK2_LEFT:
|
||||
return KR_ALIAS_LEFT; break;
|
||||
case KEY_XBUTTON_RIGHT:
|
||||
case KEY_XSTICK1_RIGHT:
|
||||
case KEY_XSTICK2_RIGHT:
|
||||
return KR_ALIAS_RIGHT; break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
CKeyRepeatHandler::CKeyRepeatHandler()
|
||||
{
|
||||
Reset();
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
m_flRepeatTimes[i] = 0.16;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Clear all state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::Reset()
|
||||
{
|
||||
DbgRepeat( "KeyRepeat: Reset\n" );
|
||||
|
||||
memset( m_bAliasDown, 0, sizeof( m_bAliasDown ) );
|
||||
m_bHaveKeyDown = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::KeyDown( vgui::KeyCode code )
|
||||
{
|
||||
int joyStick = GetJoystickForCode( code );
|
||||
int iIndex = GetIndexForCode(code);
|
||||
if ( iIndex == -1 )
|
||||
return;
|
||||
|
||||
if ( m_bAliasDown[ joyStick ][ iIndex ] )
|
||||
return;
|
||||
|
||||
DbgRepeat( "KeyRepeat: KeyDown %d(%d)\n", joyStick, iIndex );
|
||||
|
||||
Reset();
|
||||
m_bAliasDown[ joyStick ][ iIndex ] = true;
|
||||
m_flNextKeyRepeat[ joyStick ] = Plat_FloatTime() + 0.4;
|
||||
m_bHaveKeyDown = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::KeyUp( vgui::KeyCode code )
|
||||
{
|
||||
int joyStick = GetJoystickForCode( code );
|
||||
int iIndex = GetIndexForCode(code);
|
||||
if ( iIndex == -1 )
|
||||
return;
|
||||
|
||||
DbgRepeat( "KeyRepeat: KeyUp %d(%d)\n", joyStick, iIndex );
|
||||
|
||||
m_bAliasDown[ joyStick ][ iIndex ] = false;
|
||||
|
||||
m_bHaveKeyDown = false;
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
for ( int j = 0; j < MAX_JOYSTICKS; j++ )
|
||||
{
|
||||
if ( m_bAliasDown[ j ][ i ] )
|
||||
{
|
||||
m_bHaveKeyDown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
vgui::KeyCode CKeyRepeatHandler::KeyRepeated( void )
|
||||
{
|
||||
if ( IsPC() )
|
||||
return BUTTON_CODE_NONE;
|
||||
|
||||
if ( !m_bHaveKeyDown )
|
||||
return BUTTON_CODE_NONE;
|
||||
|
||||
float currentTime = Plat_FloatTime();
|
||||
|
||||
for ( int j = 0; j < MAX_JOYSTICKS; j++ )
|
||||
{
|
||||
if ( m_flNextKeyRepeat[ j ] < currentTime )
|
||||
{
|
||||
for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
|
||||
{
|
||||
if ( m_bAliasDown[ j ][ i ] )
|
||||
{
|
||||
m_flNextKeyRepeat[ j ] = currentTime + m_flRepeatTimes[i];
|
||||
DbgRepeat( "KeyRepeat: Repeat %d(%d)\n", j, i );
|
||||
|
||||
return ButtonCodeToJoystickButtonCode( g_iCodesForAliases[i], j );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BUTTON_CODE_NONE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CKeyRepeatHandler::SetKeyRepeatTime( vgui::KeyCode code, float flRepeat )
|
||||
{
|
||||
int iIndex = GetIndexForCode(code);
|
||||
Assert( iIndex != -1 );
|
||||
m_flRepeatTimes[ iIndex ] = flRepeat;
|
||||
}
|
||||
@@ -0,0 +1,809 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include <vgui/ISystem.h>
|
||||
#include <KeyValues.h>
|
||||
#include <vgui/IInputInternal.h>
|
||||
#include <vgui/ISurface.h>
|
||||
#include "tier0/vcrmode.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
#include "vgui_internal.h"
|
||||
#include "filesystem_helpers.h"
|
||||
#include "vgui_key_translation.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
#ifdef OSX
|
||||
#include <Carbon/Carbon.h>
|
||||
#elif defined(LINUX)
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL
|
||||
#include "SDL_clipboard.h"
|
||||
#include "SDL_error.h"
|
||||
#endif
|
||||
|
||||
#define PROTECTED_THINGS_DISABLE
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include <tier0/memdbgon.h>
|
||||
|
||||
using namespace vgui;
|
||||
|
||||
uint16 System_GetKeyState( int virtualKeyCode )
|
||||
{
|
||||
#ifndef _XBOX
|
||||
return g_pVCR->Hook_GetKeyState(virtualKeyCode);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
class CSystem : public ISystem
|
||||
{
|
||||
public:
|
||||
CSystem();
|
||||
~CSystem();
|
||||
|
||||
virtual void Shutdown();
|
||||
virtual void RunFrame();
|
||||
|
||||
virtual long GetTimeMillis();
|
||||
|
||||
// returns the time at the start of the frame
|
||||
virtual double GetFrameTime();
|
||||
|
||||
// returns the current time
|
||||
virtual double GetCurrentTime();
|
||||
|
||||
virtual void ShellExecute(const char *command, const char *file);
|
||||
|
||||
virtual int GetClipboardTextCount();
|
||||
virtual void SetClipboardText(const char *text, int textLen);
|
||||
virtual void SetClipboardText(const wchar_t *text, int textLen);
|
||||
virtual int GetClipboardText(int offset, char *buf, int bufLen);
|
||||
virtual int GetClipboardText(int offset, wchar_t *buf, int bufLen);
|
||||
|
||||
virtual void SetClipboardImage( void *pWnd, int x1, int y1, int x2, int y2 );
|
||||
|
||||
virtual bool SetRegistryString(const char *key, const char *value);
|
||||
virtual bool GetRegistryString(const char *key, char *value, int valueLen);
|
||||
virtual bool SetRegistryInteger(const char *key, int value);
|
||||
virtual bool GetRegistryInteger(const char *key, int &value);
|
||||
virtual bool DeleteRegistryKey(const char *keyName);
|
||||
|
||||
virtual bool SetWatchForComputerUse(bool state);
|
||||
virtual double GetTimeSinceLastUse();
|
||||
virtual int GetAvailableDrives(char *buf, int bufLen);
|
||||
virtual double GetFreeDiskSpace(const char *path);
|
||||
|
||||
virtual KeyValues *GetUserConfigFileData(const char *dialogName, int dialogID);
|
||||
virtual void SetUserConfigFile(const char *fileName, const char *pathName);
|
||||
virtual void SaveUserConfigFile();
|
||||
|
||||
virtual bool CommandLineParamExists(const char *commandName);
|
||||
virtual bool GetCommandLineParamValue(const char *paramName, char *value, int valueBufferSize);
|
||||
virtual const char *GetFullCommandLine();
|
||||
virtual bool GetCurrentTimeAndDate(int *year, int *month, int *dayOfWeek, int *day, int *hour, int *minute, int *second);
|
||||
|
||||
// shortcut (.lnk) modification functions
|
||||
virtual bool CreateShortcut(const char *linkFileName, const char *targetPath, const char *arguments, const char *workingDirectory, const char *iconFile);
|
||||
virtual bool GetShortcutTarget(const char *linkFileName, char *targetPath, char *arguments, int destBufferSizes);
|
||||
virtual bool ModifyShortcutTarget(const char *linkFileName, const char *targetPath, const char *arguments, const char *workingDirectory);
|
||||
|
||||
virtual KeyCode KeyCode_VirtualKeyToVGUI( int keyCode );
|
||||
virtual int KeyCode_VGUIToVirtualKey( KeyCode keyCode );
|
||||
// virtual MouseCode MouseCode_VirtualKeyToVGUI( int keyCode );
|
||||
// virtual int MouseCode_VGUIToVirtualKey( MouseCode keyCode );
|
||||
virtual const char *GetDesktopFolderPath();
|
||||
virtual const char *GetStartMenuFolderPath();
|
||||
virtual const char *GetAllUserDesktopFolderPath();
|
||||
virtual const char *GetAllUserStartMenuFolderPath();
|
||||
|
||||
virtual void ShellExecuteEx( const char *command, const char *file, const char *pParams );
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
virtual void Validate( CValidator &validator, char *pchName );
|
||||
#endif
|
||||
|
||||
private:
|
||||
void SaveRegistryToFile( bool bForce = false );
|
||||
bool m_bStaticWatchForComputerUse;
|
||||
double m_StaticLastComputerUseTime;
|
||||
int m_iStaticMouseOldX, m_iStaticMouseOldY;
|
||||
// timer data
|
||||
double m_flFrameTime;
|
||||
KeyValues *m_pUserConfigData;
|
||||
char m_szFileName[MAX_PATH];
|
||||
char m_szPathID[MAX_PATH];
|
||||
|
||||
KeyValues *m_pRegistry;
|
||||
double m_flRegistrySaveTime;
|
||||
bool m_bRegistryDirty;
|
||||
|
||||
char m_szRegistryPath[ MAX_PATH ];
|
||||
#ifdef OSX
|
||||
PasteboardRef m_PasteBoardRef;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
CSystem g_System;
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CSystem, ISystem, VGUI_SYSTEM_INTERFACE_VERSION, g_System);
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
vgui::ISystem *g_pSystem = &g_System;
|
||||
}
|
||||
|
||||
#define REGISTRY_NAME "cfg/registry.vdf"
|
||||
#define REGISTRY_SAVE_INTERVAL 30
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSystem::CSystem()
|
||||
{
|
||||
m_bStaticWatchForComputerUse = false;
|
||||
m_flFrameTime = 0.0;
|
||||
m_flRegistrySaveTime = 0.0;
|
||||
m_bRegistryDirty = false;
|
||||
m_pUserConfigData = NULL;
|
||||
#ifdef OSX
|
||||
PasteboardCreate( kPasteboardClipboard, &m_PasteBoardRef );
|
||||
#endif
|
||||
|
||||
Q_snprintf( m_szRegistryPath, sizeof(m_szRegistryPath), "%s", REGISTRY_NAME );
|
||||
|
||||
m_pRegistry = new KeyValues( "registry" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CSystem::~CSystem()
|
||||
{
|
||||
SaveRegistryToFile( true );
|
||||
#ifdef OSX
|
||||
CFRelease( m_PasteBoardRef );
|
||||
#endif
|
||||
}
|
||||
|
||||
void CSystem::SaveRegistryToFile( bool bForce )
|
||||
{
|
||||
/*if ( m_pRegistry && ( m_bRegistryDirty || bForce ) && g_pFullFileSystem )
|
||||
{
|
||||
m_pRegistry->SaveToFile( g_pFullFileSystem, m_szRegistryPath, "MOD" );
|
||||
}*/
|
||||
m_bRegistryDirty = false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSystem::Shutdown()
|
||||
{
|
||||
if (m_pUserConfigData)
|
||||
{
|
||||
m_pUserConfigData->deleteThis();
|
||||
}
|
||||
SaveRegistryToFile( true );
|
||||
if ( m_pRegistry )
|
||||
{
|
||||
m_pRegistry->deleteThis();
|
||||
}
|
||||
m_pRegistry = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Handles all the per frame actions
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSystem::RunFrame()
|
||||
{
|
||||
// record the current frame time
|
||||
m_flFrameTime = GetCurrentTime();
|
||||
|
||||
if (m_bStaticWatchForComputerUse)
|
||||
{
|
||||
// check for mouse movement
|
||||
int x, y;
|
||||
g_pInput->GetCursorPos(x, y);
|
||||
// allow a little slack for jittery mice, don't reset until it's moved more than fifty pixels
|
||||
if (abs((x + y) - (m_iStaticMouseOldX + m_iStaticMouseOldY)) > 50)
|
||||
{
|
||||
m_StaticLastComputerUseTime = Plat_MSTime();
|
||||
m_iStaticMouseOldX = x;
|
||||
m_iStaticMouseOldY = y;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_flFrameTime - m_flRegistrySaveTime > REGISTRY_SAVE_INTERVAL )
|
||||
{
|
||||
m_flRegistrySaveTime = m_flFrameTime;
|
||||
SaveRegistryToFile();
|
||||
// Registry_RunFrame();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the time at the start of the frame
|
||||
//-----------------------------------------------------------------------------
|
||||
double CSystem::GetFrameTime()
|
||||
{
|
||||
return m_flFrameTime;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the current time
|
||||
//-----------------------------------------------------------------------------
|
||||
double CSystem::GetCurrentTime()
|
||||
{
|
||||
return Plat_FloatTime();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the current time in milliseconds
|
||||
//-----------------------------------------------------------------------------
|
||||
long CSystem::GetTimeMillis()
|
||||
{
|
||||
return (long)(Plat_MSTime() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Legacy stub to allow ShellExecute( "open", "file" ) -- doesn't otherwise work
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSystem::ShellExecute(const char *command, const char *file)
|
||||
{
|
||||
if ( V_strcmp( command, "open" ) != 0 )
|
||||
{
|
||||
// Nope
|
||||
Assert( !"This legacy command is only supported in the form of open <foo>" );
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef OSX
|
||||
const char *szCommand = "open";
|
||||
#else
|
||||
const char *szCommand = "xdg-open";
|
||||
#endif
|
||||
|
||||
pid_t pid = fork();
|
||||
if ( pid == 0 )
|
||||
{
|
||||
// Child
|
||||
#ifdef LINUX
|
||||
// Escape steam runtime if necessary
|
||||
const char *szSteamRuntime = getenv( "STEAM_RUNTIME" );
|
||||
if ( szSteamRuntime )
|
||||
{
|
||||
unsetenv( "STEAM_RUNTIME" );
|
||||
|
||||
const char *szSystemLibraryPath = getenv( "SYSTEM_LD_LIBRARY_PATH" );
|
||||
const char *szSystemPath = getenv( "SYSTEM_PATH" );
|
||||
if ( szSystemLibraryPath )
|
||||
{
|
||||
setenv( "LD_LIBRARY_PATH", szSystemLibraryPath, 1 );
|
||||
}
|
||||
if ( szSystemPath )
|
||||
{
|
||||
setenv( "PATH", szSystemPath, 1 );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
execlp( szCommand, szCommand, file, (char *)0 );
|
||||
Assert( !"execlp failed" );
|
||||
}
|
||||
}
|
||||
|
||||
void CSystem::ShellExecuteEx( const char *command, const char *file, const char *pParams )
|
||||
{
|
||||
NOTE_UNUSED( pParams );
|
||||
ShellExecute( command, file );
|
||||
}
|
||||
|
||||
void CSystem::SetClipboardText(const char *text, int textLen)
|
||||
{
|
||||
#ifdef OSX
|
||||
PasteboardSynchronize( m_PasteBoardRef );
|
||||
PasteboardClear( m_PasteBoardRef );
|
||||
CFDataRef theData = CFDataCreate( kCFAllocatorDefault, (const UInt8*)text, textLen );
|
||||
PasteboardPutItemFlavor( m_PasteBoardRef, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), theData, 0 );
|
||||
CFRelease( theData );
|
||||
#elif defined( USE_SDL )
|
||||
if ( Q_strlen( text ) <= textLen )
|
||||
{
|
||||
if ( SDL_SetClipboardText( text ) )
|
||||
{
|
||||
Msg( "SDL_SetClipboardText failed: %s\n", SDL_GetError() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char *ClipText = ( char *)malloc( textLen + 1 );
|
||||
if ( ClipText )
|
||||
{
|
||||
Q_strncpy( ClipText, text, textLen + 1 );
|
||||
if ( SDL_SetClipboardText( ClipText ) )
|
||||
{
|
||||
Msg( "SDL_SetClipboardText failed: %s\n", SDL_GetError() );
|
||||
}
|
||||
free( ClipText );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CSystem::SetClipboardImage( void *pWnd, int x1, int y1, int x2, int y2 )
|
||||
{
|
||||
Assert( false );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Puts unicode text into the clipboard
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSystem::SetClipboardText(const wchar_t *text, int textLen)
|
||||
{
|
||||
char *charStr = (char *)malloc( textLen * 4 );
|
||||
|
||||
Q_UnicodeToUTF8( text, charStr, textLen*4 );
|
||||
|
||||
#ifdef OSX
|
||||
PasteboardSynchronize( m_PasteBoardRef );
|
||||
PasteboardClear( m_PasteBoardRef );
|
||||
|
||||
CFDataRef theData = CFDataCreate( kCFAllocatorDefault, (const UInt8*)charStr, Q_strlen(charStr) );
|
||||
PasteboardPutItemFlavor( m_PasteBoardRef, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), theData, 0 );
|
||||
CFRelease( theData );
|
||||
#elif defined( USE_SDL )
|
||||
SetClipboardText( charStr, Q_strlen( charStr ) );
|
||||
#endif
|
||||
|
||||
free( charStr );
|
||||
}
|
||||
|
||||
int CSystem::GetClipboardTextCount()
|
||||
{
|
||||
#ifdef OSX
|
||||
ItemCount count;
|
||||
PasteboardSynchronize( m_PasteBoardRef );
|
||||
|
||||
OSStatus err = PasteboardGetItemCount( m_PasteBoardRef, &count );
|
||||
if ( err != noErr )
|
||||
return 0;
|
||||
|
||||
if ( count <= 0 )
|
||||
return 0;
|
||||
|
||||
PasteboardItemID ItemID;
|
||||
// always use the last item on the clipboard for any cut and paste data
|
||||
err = PasteboardGetItemIdentifier( m_PasteBoardRef, count, &ItemID );
|
||||
if ( err != noErr )
|
||||
return 0;
|
||||
CFDataRef outData;
|
||||
err = PasteboardCopyItemFlavorData ( m_PasteBoardRef, ItemID, CFSTR ("public.utf8-plain-text"), &outData);
|
||||
if ( err != noErr )
|
||||
return 0;
|
||||
|
||||
int copyLen = CFDataGetLength( outData );
|
||||
CFRelease( outData );
|
||||
return (int)copyLen + 1;
|
||||
#elif defined( USE_SDL )
|
||||
int Count = 0;
|
||||
|
||||
if ( SDL_HasClipboardText() )
|
||||
{
|
||||
char *text = SDL_GetClipboardText();
|
||||
|
||||
if ( text )
|
||||
{
|
||||
Count = Q_strlen( text ) + 1;
|
||||
SDL_free( text );
|
||||
}
|
||||
}
|
||||
|
||||
return Count;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int CSystem::GetClipboardText(int offset, char *buf, int bufLen)
|
||||
{
|
||||
Assert( !offset );
|
||||
|
||||
#ifdef OSX
|
||||
ItemCount count;
|
||||
PasteboardSynchronize( m_PasteBoardRef );
|
||||
|
||||
OSStatus err = PasteboardGetItemCount( m_PasteBoardRef, &count );
|
||||
if ( err != noErr )
|
||||
return 0;
|
||||
|
||||
char *pchOutData;
|
||||
PasteboardItemID ItemID;
|
||||
// pull the last item from the clipboard
|
||||
err = PasteboardGetItemIdentifier( m_PasteBoardRef, count, &ItemID );
|
||||
if ( err != noErr )
|
||||
return 0;
|
||||
CFDataRef outData;
|
||||
err = PasteboardCopyItemFlavorData ( m_PasteBoardRef, ItemID, CFSTR ("public.utf8-plain-text"), &outData);
|
||||
if ( err != noErr )
|
||||
return 0;
|
||||
pchOutData = (char *)CFDataGetBytePtr(outData );
|
||||
int copyLen = MIN( CFDataGetLength( outData ), bufLen ) ;
|
||||
if ( pchOutData )
|
||||
memcpy( buf, pchOutData, copyLen );
|
||||
CFRelease( outData );
|
||||
return copyLen;
|
||||
#elif defined( USE_SDL )
|
||||
if( SDL_HasClipboardText() )
|
||||
{
|
||||
char *text = SDL_GetClipboardText();
|
||||
|
||||
if ( text )
|
||||
{
|
||||
Q_strncpy( buf, text, bufLen );
|
||||
SDL_free( text );
|
||||
return Q_strlen( buf );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Retrieves unicode text from the clipboard
|
||||
//-----------------------------------------------------------------------------
|
||||
int CSystem::GetClipboardText(int offset, wchar_t *buf, int bufLen)
|
||||
{
|
||||
Assert( !offset );
|
||||
|
||||
char *outputUTF8 = (char *)malloc( bufLen*4 );
|
||||
int ret = GetClipboardText( offset, outputUTF8, bufLen );
|
||||
|
||||
if ( ret )
|
||||
{
|
||||
Q_UTF8ToUnicode( outputUTF8, buf, bufLen );
|
||||
}
|
||||
else if( bufLen > 0 )
|
||||
{
|
||||
buf[ 0 ] = 0;
|
||||
}
|
||||
|
||||
free( outputUTF8 );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool CSystem::SetRegistryString(const char *key, const char *value)
|
||||
{
|
||||
m_bRegistryDirty = true;
|
||||
m_pRegistry->SetString( key, value );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSystem::GetRegistryString(const char *key, char *value, int valueLen)
|
||||
{
|
||||
const char *pchVal = m_pRegistry->GetString( key );
|
||||
if ( pchVal )
|
||||
Q_strncpy( value, pchVal, valueLen );
|
||||
return pchVal != NULL;
|
||||
}
|
||||
|
||||
bool CSystem::SetRegistryInteger(const char *key, int value)
|
||||
{
|
||||
m_bRegistryDirty = true;
|
||||
m_pRegistry->SetInt( key, value );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSystem::GetRegistryInteger(const char *key, int &value)
|
||||
{
|
||||
value = m_pRegistry->GetInt( key );
|
||||
return value != 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: recursively deletes a registry key and all it's subkeys
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::DeleteRegistryKey(const char *key)
|
||||
{
|
||||
Assert( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets whether or not the app watches for global computer use
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::SetWatchForComputerUse(bool state)
|
||||
{
|
||||
if (state == m_bStaticWatchForComputerUse)
|
||||
return true;
|
||||
|
||||
m_bStaticWatchForComputerUse = state;
|
||||
|
||||
if (m_bStaticWatchForComputerUse)
|
||||
{
|
||||
// enable watching
|
||||
}
|
||||
else
|
||||
{
|
||||
// disable watching
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the time, in seconds, since the last computer use.
|
||||
//-----------------------------------------------------------------------------
|
||||
double CSystem::GetTimeSinceLastUse()
|
||||
{
|
||||
if (m_bStaticWatchForComputerUse)
|
||||
{
|
||||
return ( Plat_MSTime() - m_StaticLastComputerUseTime ) / 1000.0f;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Get the drives a user has available on thier system
|
||||
//-----------------------------------------------------------------------------
|
||||
int CSystem::GetAvailableDrives(char *buf, int bufLen)
|
||||
{
|
||||
Assert( false );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the amount of available disk space, in bytes, on the specified path
|
||||
//-----------------------------------------------------------------------------
|
||||
double CSystem::GetFreeDiskSpace(const char *path)
|
||||
{
|
||||
struct statfs64 buf;
|
||||
int ret = statfs64( path, &buf );
|
||||
if ( ret < 0 )
|
||||
return 0.0;
|
||||
return (double) ( buf.f_bsize * buf.f_bfree );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: user config
|
||||
//-----------------------------------------------------------------------------
|
||||
KeyValues *CSystem::GetUserConfigFileData(const char *dialogName, int dialogID)
|
||||
{
|
||||
if (!m_pUserConfigData)
|
||||
return NULL;
|
||||
|
||||
Assert(dialogName && *dialogName);
|
||||
|
||||
if (dialogID)
|
||||
{
|
||||
char buf[256];
|
||||
Q_snprintf(buf, sizeof(buf), "%s_%d", dialogName, dialogID);
|
||||
dialogName = buf;
|
||||
}
|
||||
|
||||
return m_pUserConfigData->FindKey(dialogName, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the name of the config file to save/restore from. Settings are loaded immediately.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSystem::SetUserConfigFile(const char *fileName, const char *pathName)
|
||||
{
|
||||
//m_pRegistry->LoadFromFile( g_pFullFileSystem, m_szRegistryPath, NULL );
|
||||
|
||||
if (!m_pUserConfigData)
|
||||
{
|
||||
m_pUserConfigData = new KeyValues("UserConfigData");
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete all the existing keys so when we reload from the new file we don't
|
||||
// get duplicate entries in our key value
|
||||
m_pUserConfigData->Clear();
|
||||
}
|
||||
|
||||
Q_strncpy(m_szFileName, fileName, sizeof(m_szFileName));
|
||||
Q_strncpy(m_szPathID, pathName, sizeof(m_szPathID));
|
||||
|
||||
// open
|
||||
m_pUserConfigData->UsesEscapeSequences( true ); // VGUI may use this
|
||||
m_pUserConfigData->LoadFromFile(g_pFullFileSystem, m_szFileName, m_szPathID);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: saves all the current settings to the user config file
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSystem::SaveUserConfigFile()
|
||||
{
|
||||
if (m_pUserConfigData)
|
||||
{
|
||||
m_pUserConfigData->SaveToFile(g_pFullFileSystem, m_szFileName, m_szPathID);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns whether or not the parameter was on the command line
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::CommandLineParamExists(const char *paramName)
|
||||
{
|
||||
if ( Q_strstr( Plat_GetCommandLine(), paramName ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the string following a command line param
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::GetCommandLineParamValue(const char *paramName, char *value, int valueBufferSize)
|
||||
{
|
||||
Assert( false );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the name of the currently running exe
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSystem::GetFullCommandLine()
|
||||
{
|
||||
return VCRHook_GetCommandLine();
|
||||
}
|
||||
|
||||
|
||||
KeyCode CSystem::KeyCode_VirtualKeyToVGUI( int keyCode )
|
||||
{
|
||||
return ::KeyCode_VirtualKeyToVGUI( keyCode );
|
||||
}
|
||||
|
||||
int CSystem::KeyCode_VGUIToVirtualKey( KeyCode keyCode )
|
||||
{
|
||||
return ::KeyCode_VGUIToVirtualKey( keyCode );
|
||||
}
|
||||
|
||||
/*MouseCode CSystem::MouseCode_VirtualKeyToVGUI( int keyCode )
|
||||
{
|
||||
return ::MouseCode_VirtualKeyToVGUI( keyCode );
|
||||
}
|
||||
|
||||
int CSystem::MouseCode_VGUIToVirtualKey( MouseCode mouseCode )
|
||||
{
|
||||
return ::MouseCode_VGUIToVirtualKey( mouseCode );
|
||||
}*/
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the current local time and date
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::GetCurrentTimeAndDate(int *year, int *month, int *dayOfWeek, int *day, int *hour, int *minute, int *second)
|
||||
{
|
||||
time_t t = time( NULL );
|
||||
struct tm *now = localtime( &t );
|
||||
if ( now )
|
||||
{
|
||||
if ( year ) *year = now->tm_year + 1900;
|
||||
if ( month ) *month = now->tm_mon + 1;
|
||||
if ( dayOfWeek ) *dayOfWeek = now->tm_wday;
|
||||
if ( day ) *day = now->tm_mday;
|
||||
if ( hour ) *hour = now->tm_hour;
|
||||
if ( minute ) *minute = now->tm_min;
|
||||
if ( second ) *second = now->tm_sec;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates a shortcut file
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::CreateShortcut(const char *linkFileName, const char *targetPath, const char *arguments, const char *workingDirectory, const char *iconFile)
|
||||
{
|
||||
Assert( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: retrieves shortcut (.lnk) information
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::GetShortcutTarget(const char *linkFileName, char *targetPath, char *arguments, int destBufferSizes)
|
||||
{
|
||||
Assert( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets shortcut (.lnk) information
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CSystem::ModifyShortcutTarget(const char *linkFileName, const char *targetPath, const char *arguments, const char *workingDirectory)
|
||||
{
|
||||
Assert( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the full path of the current user's desktop folder
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSystem::GetDesktopFolderPath()
|
||||
{
|
||||
Assert( false );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the full path of the all user's desktop folder
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSystem::GetAllUserDesktopFolderPath()
|
||||
{
|
||||
Assert( false );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the full path of the current user's start->program files
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSystem::GetStartMenuFolderPath()
|
||||
{
|
||||
Assert( false );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the full path of the all user's start->program files
|
||||
//-----------------------------------------------------------------------------
|
||||
const char *CSystem::GetAllUserStartMenuFolderPath()
|
||||
{
|
||||
Assert( false );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Ensure that all of our internal structures are consistent, and
|
||||
// account for all memory that we've allocated.
|
||||
// Input: validator - Our global validator object
|
||||
// pchName - Our name (typically a member var in our container)
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef DBGFLAG_VALIDATE
|
||||
void CSystem::Validate( CValidator &validator, char *pchName )
|
||||
{
|
||||
VALIDATE_SCOPE();
|
||||
ValidatePtr( m_pUserConfigData );
|
||||
}
|
||||
|
||||
|
||||
void Validate_System( CValidator &validator )
|
||||
{
|
||||
ValidateObj( g_System );
|
||||
}
|
||||
#endif
|
||||
+1195
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,125 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// VGUI_DLL.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
|
||||
$Macro OUTBINNAME "vgui2"
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;..\include"
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\thirdparty"
|
||||
$PreprocessorDefinitions "$BASE;DONT_PROTECT_FILEIO_FUNCTIONS"
|
||||
// $TreatWchar_tAsBuiltinType "No"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$AdditionalDependencies "$BASE Imm32.lib Shlwapi.lib odbc32.lib odbccp32.lib winmm.lib" [$WIN32]
|
||||
$SystemLibraries "iconv" [$OSXALL] //||$LINUXALL]
|
||||
$SystemFrameworks "Carbon" [$OSXALL]
|
||||
}
|
||||
}
|
||||
|
||||
$Project "vgui2"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "Bitmap.cpp"
|
||||
$File "Border.cpp"
|
||||
$File "ScalableImageBorder.cpp"
|
||||
$File "ImageBorder.cpp"
|
||||
$File "fileimage.cpp"
|
||||
$File "$SRCDIR\public\filesystem_helpers.cpp"
|
||||
$File "$SRCDIR\public\filesystem_init.cpp"
|
||||
$File "InputWin32.cpp"
|
||||
$File "LocalizedStringTable.cpp"
|
||||
$File "MemoryBitmap.cpp"
|
||||
$File "Memorybitmap.h"
|
||||
$File "MessageListener.cpp"
|
||||
$File "Scheme.cpp"
|
||||
$File "Surface.cpp" [$WIN32]
|
||||
$File "System.cpp" [$WINDOWS||$X360]
|
||||
$File "system_posix.cpp" [$POSIX]
|
||||
$File "$SRCDIR\public\UnicodeFileHelpers.cpp"
|
||||
$File "vgui.cpp"
|
||||
$File "vgui_internal.cpp"
|
||||
$File "vgui_key_translation.cpp"
|
||||
$File "VPanel.cpp"
|
||||
$File "VPanelWrapper.cpp"
|
||||
$File "keyrepeat.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "bitmap.h"
|
||||
$File "fileimage.h"
|
||||
$File "IMessageListener.h"
|
||||
$File "vgui_internal.h"
|
||||
$File "vgui_key_translation.h"
|
||||
$File "VPanel.h"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\tier0\basetypes.h"
|
||||
$File "$SRCDIR\public\Color.h"
|
||||
$File "$SRCDIR\public\vgui\Cursor.h"
|
||||
$File "$SRCDIR\public\filesystem.h"
|
||||
$File "$SRCDIR\common\vgui_surfacelib\FontAmalgam.h"
|
||||
$File "$SRCDIR\common\vgui_surfacelib\FontManager.h"
|
||||
$File "$SRCDIR\public\tier1\interface.h"
|
||||
$File "$SRCDIR\public\vgui\KeyCode.h"
|
||||
$File "$SRCDIR\common\SteamBootStrapper.h"
|
||||
$File "$SRCDIR\public\tier1\strtools.h"
|
||||
$File "$SRCDIR\public\UnicodeFileHelpers.h"
|
||||
$File "$SRCDIR\public\tier1\utlbuffer.h"
|
||||
$File "$SRCDIR\public\tier1\utllinkedlist.h"
|
||||
$File "$SRCDIR\public\tier1\utlmemory.h"
|
||||
$File "$SRCDIR\public\tier1\utlpriorityqueue.h"
|
||||
$File "$SRCDIR\public\tier1\utlrbtree.h"
|
||||
$File "$SRCDIR\public\tier1\utlvector.h"
|
||||
$File "$SRCDIR\public\mathlib\vector2d.h"
|
||||
$File "$SRCDIR\public\vgui\VGUI.h"
|
||||
$File "$SRCDIR\public\vstdlib\vstdlib.h"
|
||||
$File "$SRCDIR\common\vgui_surfacelib\Win32Font.h"
|
||||
$File "$SRCDIR\public\vgui\KeyRepeat.h"
|
||||
}
|
||||
|
||||
$Folder "Interfaces"
|
||||
{
|
||||
$File "$SRCDIR\public\appframework\IAppSystem.h"
|
||||
$File "$SRCDIR\public\vgui\IBorder.h"
|
||||
$File "$SRCDIR\public\vgui\IClientPanel.h"
|
||||
$File "$SRCDIR\public\vgui\IHTML.h"
|
||||
$File "$SRCDIR\public\vgui\IImage.h"
|
||||
$File "$SRCDIR\public\vgui\IInput.h"
|
||||
$File "$SRCDIR\public\vgui\ILocalize.h"
|
||||
$File "$SRCDIR\public\vgui\IPanel.h"
|
||||
$File "$SRCDIR\public\vgui\IScheme.h"
|
||||
$File "$SRCDIR\public\vgui\ISurface.h"
|
||||
$File "$SRCDIR\public\vgui\ISystem.h"
|
||||
$File "$SRCDIR\public\vgui\IVGui.h"
|
||||
$File "$SRCDIR\public\vgui\IVguiMatInfo.h"
|
||||
$File "$SRCDIR\public\vgui\IVguiMatInfoVar.h"
|
||||
$File "VGUI_Border.h"
|
||||
$File "ScalableImageBorder.h"
|
||||
$File "ImageBorder.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib vgui_surfacelib
|
||||
$Lib tier2
|
||||
$Lib tier3
|
||||
$ImpLib SDL2 [$SDL]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Core implementation of vgui
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "vgui_internal.h"
|
||||
|
||||
#include <vgui/ISurface.h>
|
||||
#include <vgui/ILocalize.h>
|
||||
#include <vgui/IPanel.h>
|
||||
#include "filesystem.h"
|
||||
#include <vstdlib/IKeyValuesSystem.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
ISurface *g_pSurface = NULL;
|
||||
IPanel *g_pIPanel = NULL;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
static void *InitializeInterface( char const *interfaceName, CreateInterfaceFn *factoryList, int numFactories )
|
||||
{
|
||||
void *retval;
|
||||
|
||||
for ( int i = 0; i < numFactories; i++ )
|
||||
{
|
||||
CreateInterfaceFn factory = factoryList[ i ];
|
||||
if ( !factory )
|
||||
continue;
|
||||
|
||||
retval = factory( interfaceName, NULL );
|
||||
if ( retval )
|
||||
return retval;
|
||||
}
|
||||
|
||||
// No provider for requested interface!!!
|
||||
// assert( !"No provider for requested interface!!!" );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Output : Returns true on success, false on failure.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VGui_InternalLoadInterfaces( CreateInterfaceFn *factoryList, int numFactories )
|
||||
{
|
||||
// loads all the interfaces
|
||||
g_pSurface = (ISurface *)InitializeInterface(VGUI_SURFACE_INTERFACE_VERSION, factoryList, numFactories );
|
||||
// g_pKeyValues = (IKeyValues *)InitializeInterface(KEYVALUES_INTERFACE_VERSION, factoryList, numFactories );
|
||||
g_pIPanel = (IPanel *)InitializeInterface(VGUI_PANEL_INTERFACE_VERSION, factoryList, numFactories );
|
||||
|
||||
if (g_pSurface && /*g_pKeyValues &&*/ g_pIPanel)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace vgui
|
||||
@@ -0,0 +1,50 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Wraps pointers to basic vgui interfaces
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VGUI_INTERNAL_H
|
||||
#define VGUI_INTERNAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/VGUI.h>
|
||||
#include "interface.h"
|
||||
#include "tier3/tier3.h"
|
||||
#include "xbox/xboxstubs.h"
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
|
||||
bool VGui_InternalLoadInterfaces( CreateInterfaceFn *factoryList, int numFactories );
|
||||
|
||||
// <vgui/IInputInternal.h> header
|
||||
extern class IInputInternal *g_pInput;
|
||||
|
||||
// <vgui/IScheme.h> header
|
||||
extern class ISchemeManager *g_pScheme;
|
||||
|
||||
// <vgui/ISurface.h> header
|
||||
extern class ISurface *g_pSurface;
|
||||
|
||||
// <vgui/ISystem.h> header
|
||||
extern class ISystem *g_pSystem;
|
||||
|
||||
// <vgui/IVGui.h> header
|
||||
extern class IVGui *g_pIVgui;
|
||||
|
||||
// <vgui/IPanel.h> header
|
||||
extern class IPanel *g_pIPanel;
|
||||
|
||||
// methods
|
||||
void vgui_strcpy(char *dst, int dstLen, const char *src);
|
||||
} // namespace vgui
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // VGUI_INTERNAL_H
|
||||
@@ -0,0 +1,42 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#if defined( WIN32 ) && !defined( _X360 )
|
||||
#include <wtypes.h>
|
||||
#include <winuser.h>
|
||||
#include "xbox/xboxstubs.h"
|
||||
#endif
|
||||
#include "tier0/dbg.h"
|
||||
#include "vgui_key_translation.h"
|
||||
#if defined( _X360 )
|
||||
#include "xbox/xbox_win32stubs.h"
|
||||
#endif
|
||||
#ifdef POSIX
|
||||
#define VK_RETURN -1
|
||||
#endif
|
||||
|
||||
#include "tier2/tier2.h"
|
||||
#include "inputsystem/iinputsystem.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
vgui::KeyCode KeyCode_VirtualKeyToVGUI( int key )
|
||||
{
|
||||
// Some tools load vgui for localization and never use input
|
||||
if ( !g_pInputSystem )
|
||||
return KEY_NONE;
|
||||
return g_pInputSystem->VirtualKeyToButtonCode( key );
|
||||
}
|
||||
|
||||
int KeyCode_VGUIToVirtualKey( vgui::KeyCode code )
|
||||
{
|
||||
// Some tools load vgui for localization and never use input
|
||||
if ( !g_pInputSystem )
|
||||
return VK_RETURN;
|
||||
|
||||
return g_pInputSystem->ButtonCodeToVirtualKey( code );
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VGUI_KEY_TRANSLATION_H
|
||||
#define VGUI_KEY_TRANSLATION_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vgui/KeyCode.h>
|
||||
|
||||
// Convert from Windows scan codes to VGUI key codes.
|
||||
vgui::KeyCode KeyCode_VirtualKeyToVGUI( int key );
|
||||
int KeyCode_VGUIToVirtualKey( vgui::KeyCode keycode );
|
||||
|
||||
|
||||
#endif // VGUI_KEY_TRANSLATION_H
|
||||
@@ -0,0 +1,3 @@
|
||||
LIBRARY vgui2_360.dll
|
||||
EXPORTS
|
||||
CreateInterface @1
|
||||
Reference in New Issue
Block a user