[client] added support for alert text

This commit is contained in:
Geoffrey McRae 2018-05-29 11:06:42 +10:00
parent 86207993b8
commit b26a535451
2 changed files with 46 additions and 39 deletions

View File

@ -60,6 +60,7 @@ typedef LG_RendererOpt * LG_RendererOptions;
typedef struct LG_RendererParams typedef struct LG_RendererParams
{ {
TTF_Font * font; TTF_Font * font;
TTF_Font * alertFont;
bool showFPS; bool showFPS;
} }
LG_RendererParams; LG_RendererParams;

View File

@ -52,6 +52,7 @@ struct AppState
bool keyDown[SDL_NUM_SCANCODES]; bool keyDown[SDL_NUM_SCANCODES];
TTF_Font * font; TTF_Font * font;
TTF_Font * alertFont;
SDL_Point srcSize; SDL_Point srcSize;
LG_RendererRect dstRect; LG_RendererRect dstRect;
SDL_Point cursor; SDL_Point cursor;
@ -529,7 +530,7 @@ int eventFilter(void * userdata, SDL_Event * event)
if (state.lgr) if (state.lgr)
state.lgr->on_alert( state.lgr->on_alert(
state.lgrData, state.lgrData,
LG_ALERT_INFO, serverMode ? LG_ALERT_SUCCESS : LG_ALERT_WARNING,
serverMode ? "Capture Enabled" : "Capture Disabled" serverMode ? "Capture Enabled" : "Capture Disabled"
); );
@ -716,48 +717,53 @@ int run()
// SIGINT and the user sending a close event, such as ALT+F4 // SIGINT and the user sending a close event, such as ALT+F4
signal(SIGINT, intHandler); signal(SIGINT, intHandler);
if (params.showFPS) if (TTF_Init() < 0)
{ {
if (TTF_Init() < 0) DEBUG_ERROR("TTL_Init Failed");
{ return -1;
DEBUG_ERROR("TTL_Init Failed");
return -1;
}
FcConfig * config = FcInitLoadConfigAndFonts();
if (!config)
{
DEBUG_ERROR("FcInitLoadConfigAndFonts Failed");
return -1;
}
FcPattern * pat = FcNameParse((const FcChar8*)"FreeMono");
FcConfigSubstitute (config, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcResult result;
FcChar8 * file = NULL;
FcPattern * font = FcFontMatch(config, pat, &result);
if (font && (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch))
{
state.font = TTF_OpenFont((char *)file, 14);
if (!state.font)
{
DEBUG_ERROR("TTL_OpenFont Failed");
return -1;
}
}
else
{
DEBUG_ERROR("Failed to locate a font for FPS display");
return -1;
}
FcPatternDestroy(pat);
} }
FcConfig * config = FcInitLoadConfigAndFonts();
if (!config)
{
DEBUG_ERROR("FcInitLoadConfigAndFonts Failed");
return -1;
}
FcPattern * pat = FcNameParse((const FcChar8*)"FreeMono");
FcConfigSubstitute (config, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcResult result;
FcChar8 * file = NULL;
FcPattern * font = FcFontMatch(config, pat, &result);
if (font && (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch))
{
state.font = TTF_OpenFont((char *)file, 14);
if (!state.font)
{
DEBUG_ERROR("TTL_OpenFont Failed");
return -1;
}
state.alertFont = TTF_OpenFont((char *)file, 18);
if (!state.alertFont)
{
DEBUG_ERROR("TTL_OpenFont Failed");
return -1;
}
}
else
{
DEBUG_ERROR("Failed to locate a font for text display");
return -1;
}
FcPatternDestroy(pat);
LG_RendererParams lgrParams; LG_RendererParams lgrParams;
lgrParams.font = state.font; lgrParams.font = state.font;
lgrParams.showFPS = params.showFPS; lgrParams.alertFont = state.alertFont;
lgrParams.showFPS = params.showFPS;
Uint32 sdlFlags; Uint32 sdlFlags;
if (params.forceRenderer) if (params.forceRenderer)