mirror of
https://github.com/nillerusr/source-engine.git
synced 2024-12-22 14:16:50 +00:00
game(client): fix touch drawing problems again, fix some fonts on android
This commit is contained in:
parent
9c4ace30c3
commit
4ace9f8030
@ -441,6 +441,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];
|
||||
@ -494,8 +496,9 @@ void CTouchControls::CreateAtlasTexture()
|
||||
continue;
|
||||
}
|
||||
|
||||
rects[i].h = t->height;
|
||||
rects[i].w = t->width;
|
||||
rects[rectCount].h = t->height;
|
||||
rects[rectCount].w = t->width;
|
||||
rectCount++;
|
||||
}
|
||||
|
||||
if( !textureList.Count() )
|
||||
@ -512,27 +515,29 @@ 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];
|
||||
if( t->textureID )
|
||||
continue;
|
||||
|
||||
t->X0 = rects[i].x / (float)atlasHeight;
|
||||
t->Y0 = rects[i].y / (float)atlasHeight;
|
||||
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user