mirror of
https://github.com/celisej567/source-engine.git
synced 2025-12-31 21:48:22 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f5ebfbde3 | ||
|
|
4ace9f8030 | ||
|
|
9c4ace30c3 |
@@ -410,6 +410,10 @@ void CTouchControls::Init()
|
||||
ResetToDefaults();
|
||||
|
||||
CTouchTexture *texture = new CTouchTexture;
|
||||
texture->isInAtlas = false;
|
||||
texture->textureID = 0;
|
||||
texture->X0 = 0; texture->X1 = 0; texture->Y0 = 0; texture->Y1 = 0;
|
||||
|
||||
Q_strncpy( texture->szName, "vgui/touch/back", sizeof(texture->szName) );
|
||||
textureList.AddToTail(texture);
|
||||
|
||||
@@ -441,6 +445,8 @@ void CTouchControls::CreateAtlasTexture()
|
||||
if( touchTextureID )
|
||||
vgui::surface()->DeleteTextureByID( touchTextureID );
|
||||
|
||||
int rectCount = 0;
|
||||
|
||||
for( int i = 0; i < textureList.Count(); i++ )
|
||||
{
|
||||
CTouchTexture *t = textureList[i];
|
||||
@@ -448,7 +454,12 @@ void CTouchControls::CreateAtlasTexture()
|
||||
|
||||
FileHandle_t fp;
|
||||
fp = ::filesystem->Open( fullFileName, "rb" );
|
||||
if( !fp ) return;
|
||||
if( !fp )
|
||||
{
|
||||
t->textureID = vgui::surface()->CreateNewTextureID();
|
||||
vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false );
|
||||
continue;
|
||||
}
|
||||
|
||||
::filesystem->Seek( fp, 0, FILESYSTEM_SEEK_TAIL );
|
||||
int srcVTFLength = ::filesystem->Tell( fp );
|
||||
@@ -467,22 +478,31 @@ void CTouchControls::CreateAtlasTexture()
|
||||
{
|
||||
if( t->vtf->Format() != IMAGE_FORMAT_RGBA8888 && t->vtf->Format() != IMAGE_FORMAT_BGRA8888 )
|
||||
{
|
||||
Msg("Format=%d\n", t->vtf->Format());
|
||||
Error("Use RGBA8888/BGRA88888 for touch buttons!\n");
|
||||
t->textureID = vgui::surface()->CreateNewTextureID();
|
||||
vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false);
|
||||
DestroyVTFTexture(t->vtf);
|
||||
continue;
|
||||
}
|
||||
if( t->vtf->Height() != t->vtf->Width() || (t->vtf->Height() & (t->vtf->Height() - 1)) != 0 )
|
||||
Error("Touch texture is wrong! Don't use npot textures for touch.");
|
||||
Error("%s texture is wrong! Don't use npot textures for touch.");
|
||||
|
||||
t->height = t->vtf->Height();
|
||||
t->width = t->vtf->Width();
|
||||
t->isInAtlas = true;
|
||||
|
||||
atlasSize += t->width*t->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyVTFTexture(t->vtf);
|
||||
t->textureID = vgui::surface()->CreateNewTextureID();
|
||||
vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
buf.Clear();
|
||||
|
||||
rects[i].h = t->height;
|
||||
rects[i].w = t->width;
|
||||
rects[rectCount].h = t->height;
|
||||
rects[rectCount].w = t->width;
|
||||
rectCount++;
|
||||
}
|
||||
|
||||
if( !textureList.Count() )
|
||||
@@ -499,33 +519,36 @@ void CTouchControls::CreateAtlasTexture()
|
||||
|
||||
stbrp_context context;
|
||||
stbrp_init_target( &context, atlasHeight, atlasHeight, nodes, nodesCount );
|
||||
stbrp_pack_rects(&context, rects, textureList.Count());
|
||||
stbrp_pack_rects(&context, rects, rectCount);
|
||||
|
||||
rectCount = 0;
|
||||
for( int i = 0; i < textureList.Count(); i++ )
|
||||
{
|
||||
CTouchTexture *t = textureList[i];
|
||||
t->X0 = rects[i].x / (float)atlasHeight;
|
||||
t->Y0 = rects[i].y / (float)atlasHeight;
|
||||
if( t->textureID )
|
||||
continue;
|
||||
|
||||
t->X0 = rects[rectCount].x / (float)atlasHeight;
|
||||
t->Y0 = rects[rectCount].y / (float)atlasHeight;
|
||||
t->X1 = t->X0 + t->width / (float)atlasHeight;
|
||||
t->Y1 = t->Y0 + t->height / (float)atlasHeight;
|
||||
|
||||
unsigned char *src = t->vtf->ImageData(0, 0, 0);
|
||||
for( int row = 0; row < t->height; row++)
|
||||
{
|
||||
unsigned char *row_dest = dest+(row+rects[i].y)*atlasHeight*4+rects[i].x*4;
|
||||
unsigned char *row_dest = dest+(row+rects[rectCount].y)*atlasHeight*4+rects[rectCount].x*4;
|
||||
unsigned char *row_src = src+row*t->height*4;
|
||||
|
||||
memcpy(row_dest, row_src, t->height*4);
|
||||
}
|
||||
rectCount++;
|
||||
|
||||
DestroyVTFTexture(t->vtf);
|
||||
t->isInAtlas = true;
|
||||
}
|
||||
|
||||
touchTextureID = vgui::surface()->CreateNewTextureID( true );
|
||||
vgui::surface()->DrawSetTextureRGBA( touchTextureID, dest, atlasHeight, atlasHeight, 1, true );
|
||||
|
||||
|
||||
free(nodes);
|
||||
free(rects);
|
||||
delete[] dest;
|
||||
@@ -603,7 +626,6 @@ void CTouchControls::Paint( )
|
||||
return;
|
||||
|
||||
CUtlLinkedList<CTouchButton*>::iterator it;
|
||||
|
||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||
|
||||
if( state == state_edit )
|
||||
@@ -638,7 +660,6 @@ void CTouchControls::Paint( )
|
||||
}
|
||||
}
|
||||
|
||||
pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(touchTextureID) );
|
||||
m_pMesh = pRenderContext->GetDynamicMesh();
|
||||
|
||||
int meshCount = 0;
|
||||
@@ -648,20 +669,53 @@ void CTouchControls::Paint( )
|
||||
|
||||
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) )
|
||||
{
|
||||
if( !btn->texture->isInAtlas )
|
||||
CTouchTexture *t = btn->texture;
|
||||
|
||||
if( t->textureID )
|
||||
{
|
||||
pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(t->textureID) );
|
||||
meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount );
|
||||
|
||||
rgba_t color(btn->color.r, btn->color.g, btn->color.b, btn->color.a);
|
||||
meshBuilder.Position3f( btn->x1*screen_w, btn->y1*screen_h, 0 );
|
||||
meshBuilder.Color4ubv( color );
|
||||
meshBuilder.TexCoord2f( 0, 0, 0 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||
|
||||
meshBuilder.Position3f( btn->x2*screen_w, btn->y1*screen_h, 0 );
|
||||
meshBuilder.Color4ubv( color );
|
||||
meshBuilder.TexCoord2f( 0, 1, 0 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||
|
||||
meshBuilder.Position3f( btn->x2*screen_w, btn->y2*screen_h, 0 );
|
||||
meshBuilder.Color4ubv( color );
|
||||
meshBuilder.TexCoord2f( 0, 1, 1 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||
|
||||
meshBuilder.Position3f( btn->x1*screen_w, btn->y2*screen_h, 0 );
|
||||
meshBuilder.Color4ubv( color );
|
||||
meshBuilder.TexCoord2f( 0, 0, 1 );
|
||||
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||
|
||||
meshBuilder.End();
|
||||
m_pMesh->Draw();
|
||||
}
|
||||
else if( !btn->texture->isInAtlas )
|
||||
CreateAtlasTexture();
|
||||
|
||||
meshCount++;
|
||||
if( !t->textureID )
|
||||
meshCount++;
|
||||
}
|
||||
}
|
||||
|
||||
pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(touchTextureID) );
|
||||
meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount );
|
||||
|
||||
for( it = btns.begin(); it != btns.end(); it++ )
|
||||
{
|
||||
CTouchButton *btn = *it;
|
||||
|
||||
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) )
|
||||
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) && !btn->texture->textureID )
|
||||
{
|
||||
CTouchTexture *t = btn->texture;
|
||||
|
||||
@@ -744,6 +798,7 @@ void CTouchControls::AddButton( const char *name, const char *texturefile, const
|
||||
CTouchTexture *texture = new CTouchTexture;
|
||||
btn->texture = texture;
|
||||
texture->isInAtlas = false;
|
||||
texture->textureID = 0;
|
||||
texture->X0 = 0; texture->X1 = 0; texture->Y0 = 0; texture->Y1 = 0;
|
||||
Q_strncpy( texture->szName, btn->texturefile, sizeof(btn->texturefile) );
|
||||
textureList.AddToTail(texture);
|
||||
|
||||
@@ -83,6 +83,7 @@ struct CTouchTexture
|
||||
|
||||
float X0, Y0, X1, Y1; // position in atlas texture
|
||||
int height, width;
|
||||
int textureID;
|
||||
bool isInAtlas;
|
||||
char szName[1024];
|
||||
};
|
||||
@@ -164,7 +165,7 @@ public:
|
||||
|
||||
void Paint( );
|
||||
void Frame( );
|
||||
|
||||
|
||||
void AddButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, rgba_t color = rgba_t(255, 255, 255, 255), int round = 2, float aspect = 1.f, int flags = 0 );
|
||||
void RemoveButton( const char *name );
|
||||
void ResetToDefaults();
|
||||
@@ -172,7 +173,7 @@ public:
|
||||
void ShowButton( const char *name );
|
||||
void ListButtons();
|
||||
void RemoveButtons();
|
||||
|
||||
|
||||
CTouchButton *FindButton( const char *name );
|
||||
// bool FindNextButton( const char *name, CTouchButton &button );
|
||||
void SetTexture( const char *name, const char *file );
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <new>
|
||||
#endif
|
||||
|
||||
|
||||
struct GeneratePolyhedronFromPlanes_Point;
|
||||
struct GeneratePolyhedronFromPlanes_PointLL;
|
||||
struct GeneratePolyhedronFromPlanes_Line;
|
||||
@@ -73,18 +72,18 @@ void CreateDumpDirectory( const char *szDirectoryName )
|
||||
|
||||
void CPolyhedron_AllocByNew::Release( void )
|
||||
{
|
||||
free(this);
|
||||
delete this;
|
||||
}
|
||||
|
||||
CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation
|
||||
{
|
||||
void *pMemory = malloc(sizeof( CPolyhedron_AllocByNew ) +
|
||||
void *pMemory = new unsigned char [ sizeof( CPolyhedron_AllocByNew ) +
|
||||
(iVertices * sizeof(Vector)) +
|
||||
(iLines * sizeof(Polyhedron_IndexedLine_t)) +
|
||||
(iIndices * sizeof( Polyhedron_IndexedLineReference_t )) +
|
||||
(iPolygons * sizeof( Polyhedron_IndexedPolygon_t )));
|
||||
(iPolygons * sizeof( Polyhedron_IndexedPolygon_t ))];
|
||||
|
||||
#include "tier0/memdbgoff.h"
|
||||
#include "tier0/memdbgoff.h" //the following placement new doesn't compile with memory debugging
|
||||
CPolyhedron_AllocByNew *pAllocated = new ( pMemory ) CPolyhedron_AllocByNew;
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
@@ -108,7 +107,7 @@ public:
|
||||
int iReferenceCount;
|
||||
#endif
|
||||
|
||||
void Release( void ) override
|
||||
virtual void Release( void )
|
||||
{
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
--iReferenceCount;
|
||||
|
||||
@@ -405,20 +405,62 @@ bool CLinuxFont::CreateFromMemory(const char *windowsFontName, void *data, int d
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "tier1/convar.h"
|
||||
ConVar cl_language( "cl_language", "english", FCVAR_USERINFO, "Language (from HKCU\\Software\\Valve\\Steam\\Language)" );
|
||||
|
||||
#if !HAVE_FC
|
||||
char *TryFindFont(const char *winFontName, bool bBold, int italic)
|
||||
{
|
||||
static char fontFile[MAX_PATH];
|
||||
|
||||
const char *fontName, *fontNamePost;
|
||||
const char *fontName, *fontNamePost = NULL;
|
||||
|
||||
#ifdef ANDROID
|
||||
if( strcmp( winFontName, "Courier New") == 0 )
|
||||
fontName = "LiberationMono-Regular.ttf";
|
||||
else
|
||||
fontName = "DroidSansFallback.ttf"; // for chinese/japanese/korean
|
||||
const char *lang = cl_language.GetString();
|
||||
|
||||
snprintf( fontFile, sizeof fontFile, "%s/files/%s", getenv("APP_DATA_PATH"), fontName);
|
||||
if( strcmp( winFontName, "Courier New") == 0 )
|
||||
{
|
||||
fontName = "LiberationMono-Regular.ttf";
|
||||
snprintf( fontFile, sizeof fontFile, "%s/files/%s", getenv("APP_DATA_PATH"), fontName);
|
||||
return fontFile;
|
||||
}
|
||||
|
||||
if( strcmp(lang, "japanese") == 0 ||
|
||||
strcmp(lang, "koreana") == 0 ||
|
||||
strcmp(lang, "korean") == 0 ||
|
||||
strcmp(lang, "tchinese") == 0 ||
|
||||
strcmp(lang, "schinese") == 0 )
|
||||
{
|
||||
fontName = "DroidSansFallback.ttf"; // for chinese/japanese/korean
|
||||
snprintf( fontFile, sizeof fontFile, "%s/files/%s", getenv("APP_DATA_PATH"), fontName);
|
||||
return fontFile;
|
||||
}
|
||||
else if( strcmp(lang, "thai") == 0 )
|
||||
{
|
||||
fontName = "Itim-Regular.otf";
|
||||
snprintf( fontFile, sizeof fontFile, "%s/files/%s", getenv("APP_DATA_PATH"), fontName);
|
||||
return fontFile;
|
||||
}
|
||||
|
||||
fontName = "dejavusans";
|
||||
|
||||
if( bBold )
|
||||
{
|
||||
if( italic )
|
||||
fontNamePost = "boldoblique";
|
||||
else
|
||||
fontNamePost = "bold";
|
||||
}
|
||||
else if( italic )
|
||||
fontNamePost = "oblique";
|
||||
|
||||
if( fontNamePost )
|
||||
snprintf(fontFile, sizeof fontFile, "%s/files/%s-%s.ttf", getenv("APP_DATA_PATH"), fontName, fontNamePost);
|
||||
else
|
||||
snprintf(fontFile, sizeof fontFile, "%s/files/%s.ttf", getenv("APP_DATA_PATH"), fontName);
|
||||
|
||||
|
||||
return fontFile;
|
||||
#else
|
||||
// "platform/resource/linux_fonts/";
|
||||
|
||||
@@ -438,50 +480,7 @@ char *TryFindFont(const char *winFontName, bool bBold, int italic)
|
||||
fontNamePost = "regular";
|
||||
|
||||
snprintf(fontFile, sizeof fontFile, "platform/resource/linux_fonts/%s-%s.ttf", fontName, fontNamePost);
|
||||
#endif
|
||||
return fontFile;
|
||||
|
||||
#if 0 // Old detect
|
||||
const char *fontFileName, *fontFileNamePost = NULL;
|
||||
|
||||
fontFileName = "Roboto";
|
||||
|
||||
if( bBold )
|
||||
{
|
||||
if( italic )
|
||||
fontFileNamePost = "BoldItalic";
|
||||
else
|
||||
fontFileNamePost = "Bold";
|
||||
}
|
||||
else if( italic )
|
||||
fontFileNamePost = "Italic";
|
||||
else
|
||||
fontFileNamePost = "Regular";
|
||||
|
||||
static char dataFile[MAX_PATH];
|
||||
|
||||
if( fontFileNamePost )
|
||||
snprintf( dataFile, sizeof dataFile, "/system/fonts/%s-%s.ttf", fontFileName, fontFileNamePost );
|
||||
else
|
||||
snprintf( dataFile, sizeof dataFile, "/system/fonts/%s.ttf", fontFileName );
|
||||
|
||||
if( access( dataFile, R_OK ) != 0 )
|
||||
{
|
||||
fontFileNamePost = NULL;
|
||||
fontFileName = "DroidSans";
|
||||
if( bBold )
|
||||
fontFileNamePost = "Bold";
|
||||
|
||||
if( fontFileNamePost )
|
||||
snprintf( dataFile, sizeof dataFile, "/system/fonts/%s-%s.ttf", fontFileName, fontFileNamePost );
|
||||
else
|
||||
snprintf( dataFile, sizeof dataFile, "/system/fonts/%s.ttf", fontFileName );
|
||||
|
||||
if( access( dataFile, R_OK ) != 0 )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dataFile;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user