本文整理汇总了C++中TTF_SetFontStyle函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_SetFontStyle函数的具体用法?C++ TTF_SetFontStyle怎么用?C++ TTF_SetFontStyle使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TTF_SetFontStyle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyFontStyle
void applyFontStyle(bool bold)
{
if (bold)
TTF_SetFontStyle(font, TTF_STYLE_BOLD);
else
TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
}
示例2: TTF_SetFontStyle
/**************************************************************************
Create Text Surface from SDL_String16
**************************************************************************/
static SDL_Surface *create_str16_surf(SDL_String16 * pString)
{
SDL_Surface *pText = NULL; /* FIXME: possibly uninitialized */
if (!pString) {
return NULL;
}
if (!((pString->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(pString->font, (pString->style & 0x0F));
}
switch (pString->render) {
case 0:
pText = TTF_RenderUNICODE_Shaded(pString->font,
pString->text, pString->fgcol,
pString->bgcol);
break;
case 1:
{
SDL_Surface *pTmp = TTF_RenderUNICODE_Solid(pString->font,
pString->text, pString->fgcol);
if ((pText = SDL_DisplayFormat(pTmp)) == NULL) {
log_error("SDL_create_str16_surf: couldn't convert text "
"to display format: %s", SDL_GetError());
pText = pTmp;
} else {
FREESURFACE( pTmp );
}
}
break;
case 2:
pText = TTF_RenderUNICODE_Blended(pString->font,
pString->text, pString->fgcol);
break;
}
if (pText != NULL) {
log_debug("SDL_create_str16_surf: Font is generally %d big, and "
"string is %hd big", TTF_FontHeight(pString->font), pText->h);
log_debug("SDL_create_str16_surf: String is %d length", pText->w);
} else {
log_debug("SDL_create_str16_surf: pText NULL");
pText = create_surf_alpha(0, 0, SDL_SWSURFACE);
}
if (!((pString->style & 0x0F) & TTF_STYLE_NORMAL)) {
TTF_SetFontStyle(pString->font, TTF_STYLE_NORMAL);
}
return pText;
}
示例3: SDL_RenderCopy
void GameplayScreen::RenderGUI(SDL_Renderer* renderer)
{
// Display the lives left
for (int i = 0; i < livesRemaining - 1; i++)
{
livesLeftRect.x = Config::gridSize * i;
SDL_RenderCopy(renderer, livesTexture, NULL, &livesLeftRect);
}
// Display the score
if (arialFont != NULL)
{
std::string scoreString = "Score: " + std::to_string(score);
Utils::RenderText(renderer, arialFont, scoreString, SDL_Color{ 255, 255, 255 }, &scoreTextRect);
}
// Display the AI state
std::string aiStateString = Ghost::CurrentStateName();
SDL_Rect aiStateRect;
aiStateRect.x = Config::gridSize * 18;
aiStateRect.y = Config::gridSize * 32;
aiStateRect.w = Config::gridSize * 8;
aiStateRect.h = Config::gridSize * 2;
Utils::RenderText(renderer, arialFont, "AI State: " + aiStateString, SDL_Color{ 255, 255, 255 }, &aiStateRect);
if (isPaused)
{
SDL_Rect pauseRect;
pauseRect.w = Config::gridSize * 10;
pauseRect.h = Config::gridSize * 2;
pauseRect.x = Config::screenWidth / 2 - pauseRect.w / 2;
pauseRect.y = Config::screenHeight / 2 - pauseRect.h / 2;
SDL_RenderCopy(renderer, pauseTexture, NULL, &pauseRect);
}
if (isLevelOver)
{
const int VERT_OFFSET = 7;
SDL_Rect endGameRect;
endGameRect.w = Config::gridSize * 6;
endGameRect.h = Config::gridSize * 1.2;
endGameRect.x = Config::screenWidth / 2 - endGameRect.w / 2;
endGameRect.y = Config::screenHeight / 2 - endGameRect.h / 2 - VERT_OFFSET;
TTF_SetFontStyle(arialFont, TTF_STYLE_BOLD);
Utils::RenderText(renderer, arialFont, endGameMessage, SDL_Color{ 255, 255, 255 }, &endGameRect);
TTF_SetFontStyle(arialFont, TTF_STYLE_NORMAL);
}
}
示例4: KW_RenderTextLine
SDL_Texture * KW_RenderTextLine(TTF_Font * font, SDL_Renderer * renderer, const char * text, SDL_Color color, int styleflags) {
int previousstyle;
SDL_Surface * textsurface;
SDL_Texture * ret;
if (font == NULL || text == NULL)
return NULL;
previousstyle = TTF_GetFontStyle(font);
TTF_SetFontStyle(font, styleflags);
textsurface = TTF_RenderUTF8_Blended(font, text, color);
ret = SDL_CreateTextureFromSurface(renderer, textsurface);
SDL_FreeSurface(textsurface);
TTF_SetFontStyle(font, previousstyle);
return ret;
}
示例5: Init
//==============================================================================
int Init(int w, int h, int bits, int full){
//==============================================================================
if (SDL_Init(SDL_SUBSYSTEMS)==-1){
fprintf(stderr, "ERROR: Inicializacia VIDEO podpory SDL sa nepodarila: %s\n",
SDL_GetError());
return FAIL;
}
fprintf(stderr, "Inicializacia VIDEO podpory SDL [OK] \n");
screen = SDL_SetVideoMode(w, h, bits, WIN_FLAGS );
SDL_WM_SetCaption(WIN_TITLE, 0);
if (screen==NULL){
printf("Inicializacia videobufferu %ix%ix%i: %s\n", w, h, bits, SDL_GetError());
return FAIL;
}
if(TTF_Init() == -1){
printf("Nepodarilo se inicializovat SDL_ttf: %s\n", TTF_GetError());
return FAIL;
}
console_font = TTF_OpenFont(ROOT"data/console.ttf", FONT_SIZE);
if(!console_font){
printf("Unable to open font: %s\n", TTF_GetError());
return FAIL;
}
TTF_SetFontStyle(console_font, TTF_STYLE_NORMAL);
text_font = TTF_OpenFont(ROOT"data/normal.ttf", 20);
if(!text_font){
printf("Unable to open font: %s\n", TTF_GetError());
return FAIL;
}
TTF_SetFontStyle(text_font, TTF_STYLE_NORMAL);
SDL_ShowCursor(SDL_DISABLE);
if(F==1)SDL_WM_ToggleFullScreen(screen);
return OK;
}
示例6: MyTTF_Render_BlendedU
SDL_Surface * MyTTF_Render_BlendedU( SDL_Surface * render_text, \
Uint16 *text, int size, \
Uint8 style, SDL_Color color )
{
SDL_Surface * render_tmp;
char tmpstr[512];
TTF_Font *font;
SDLGuiTK_Theme * theme;
if( render_text!=NULL ) {
SDL_FreeSurface( render_text );
render_text = NULL;
}
theme = PROT__theme_get_and_lock();
font = TTF_OpenFont( theme->font_file, size );
if ( font==NULL ) {
sprintf( tmpstr, "Couldn't load %d pt font from %s: %s\n",
size, theme->font_file, SDL_GetError());
SDLGUITK_ERROR( tmpstr );
exit(2);
}
TTF_SetFontStyle( font, style );
render_tmp = TTF_RenderUNICODE_Blended( font, text, \
color );
//render_text = SDL_DisplayFormatAlpha( render_tmp );
render_text = render_tmp;
/* render_text = render_tmp; */
MySDL_FreeSurface( render_tmp );
PROT__theme_unlock( theme );
TTF_CloseFont(font);
return render_text;
}
示例7: TTF_OpenFont
int Display_SDL::MessageXY(int x, int y, const char * pcMessage) {
int ptsize = 24;
TTF_Font * font = NULL;
SDL_Color forecol = { 0xFF, 0xFF, 0xFF, 0 };
SDL_Color backcol = { 0x00, 0x00, 0x00, 0 };
SDL_Surface * text = NULL;
SDL_Rect dstrect;
font = TTF_OpenFont("seguibk.ttf", ptsize);
if (font == NULL) {
g_pErr->Report("couldn't open font file seguibk.ttf");
} else {}
TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
text = TTF_RenderText_Solid(font, pcMessage, forecol);
if (text == NULL) {
g_pErr->Report("error rendering font");
} else {
dstrect.x = (int) (x - (text->w / 2));
dstrect.y = (int) (y - (text->h / 2));
dstrect.w = text->w;
dstrect.h = text->h;
//SDL_FillRect(m_pScreen, NULL,
//SDL_MapRGB(m_pScreen->format, backcol.r, backcol.g, backcol.b));
SDL_BlitSurface(text, NULL, m_pScreen, &dstrect);
SDL_FreeSurface(text);
SDL_Flip(m_pScreen);
}
TTF_CloseFont(font);
return 0;
}
示例8: TTF_OpenFont
void GlyphFont::InitFont()
{
mTtfFont = TTF_OpenFont(mFilename, mPointSize);
if(mTtfFont == NULL)
printf("Can't open font file\n");
// 0 = TTF_STYLE_NORMAL
// 1 = TTF_STYLE_BOLD
// 2 = TTF_STYLE_ITALIC
// 4 = TTF_STYLE_UNDERLINE
// 8 = TTF_STYLE_STRIKETHROUGH
TTF_SetFontStyle(mTtfFont, mStyle);
mColor.r = (Uint8)(mRed * 255);
mColor.g = (Uint8)(mGreen * 255);
mColor.b = (Uint8)(mBlue * 255);
mHeight = TTF_FontHeight(mTtfFont);
mAscent = TTF_FontAscent(mTtfFont);
mDescent = TTF_FontDescent(mTtfFont);
mLineSkip = TTF_FontLineSkip(mTtfFont);
for(int i = sMinGlyph; i <= sMaxGlyph; i++)
{
mGlyphs[i].Surface = NULL;
mGlyphs[i].Texture = 0;
}
}
示例9: TTF_GetFontStyle
//Sets the font style of the font at the specified index
//param:fontIndex->The index of the font to modify
//param:style->The style to set it to. Use | to use multiple
//TTF_STYLE_BOLD: Sets the font to its bold version
//TTF_STYLE_ITALIC: Italicizes the font
//TTF_STYLE_NORMAL: Sets the font to its normal format
//TTF_STYLE_STRIKETHROUGH: Creates a line through the middle
//TTF_STYLE_UNDERLINE: Creates an underline
void SpriteFont::SetFontStyle(int fontIndex, int style)
{
//Try block to make sure index is valid
try
{
//Get the font to modify
TTF_Font* font = fontList.at(fontIndex);
//Check for null
if(font)
{
//Get the current style
int currentStyle = TTF_GetFontStyle(font);
//Save processing by not changing style if they are identical
if(currentStyle != style)
{
//Otherwise, set the style
TTF_SetFontStyle(font, style);
}
}
else
{
std::cout<<"SetFontStyle error: Provided index is NULL"<<std::endl;
return;
}
}
catch(std::out_of_range problem)
{
//display invalid index
std::cout<<"SetFontStyle error: font index invalid"<<std::endl;
return;
}
}
示例10: TTF_OpenFont
//-----------------------------------------------------------------------------
// Purpose: Creates a new font
//-----------------------------------------------------------------------------
HGAMEFONT CGameEngineGL::HCreateFont( int nHeight, int nFontWeight, bool bItalic, const char * pchFont )
{
// For this sample we include a single font
pchFont = "DejaVuSans.ttf";
TTF_Font *font = TTF_OpenFont( pchFont, nHeight );
if ( !font )
{
OutputDebugString( "Couldn't create font: " );
OutputDebugString( pchFont );
OutputDebugString( "\n" );
return 0;
}
HGAMEFONT hFont = m_nNextFontHandle;
++m_nNextFontHandle;
int nStyle = TTF_STYLE_NORMAL;
if ( nFontWeight & FW_BOLD )
{
nStyle |= TTF_STYLE_BOLD;
}
if ( bItalic )
{
nStyle |= TTF_STYLE_ITALIC;
}
TTF_SetFontStyle( font, nStyle );
m_MapGameFonts[ hFont ] = font;
return hFont;
}
示例11: DBG
/*
* Load a new font and create textures for each glyph
*/
font *ttf_new (const char *name, int32_t pointSize, int32_t style)
{
TTF_Font *ttf;
uint8_t c;
font *f;
f = (fontp)myzalloc(sizeof(*f), __FUNCTION__);
DBG("Load TTF: %s", name);
ttf = TTF_OpenFont(name, pointSize);
if (!ttf) {
DIE("cannot open font file %s", name);
}
f->foreground.r = 255;
f->foreground.g = 255;
f->foreground.b = 255;
f->background.r = 0;
f->background.g = 0;
f->background.b = 0;
TTF_SetFontStyle(ttf, style);
for (c = TTF_GLYPH_MIN; c < TTF_GLYPH_MAX; c++) {
ttf_create_tex_from_char(ttf, name, f, c);
}
TTF_CloseFont(ttf);
return (f);
}
示例12: Composants_Pour_FonctionPourJeu1
void Composants_Pour_FonctionPourJeu1(ComposantsFonctionPourJeu *Composants_Pour_FonctionPourJeu)
{
Composants_Pour_FonctionPourJeu->police = TTF_OpenFont("PRISTINA.TTF", 25);
TTF_SetFontStyle(Composants_Pour_FonctionPourJeu->police, TTF_STYLE_ITALIC);
SDL_Color couleurNoire = {"#f", 0, "#a"};
Composants_Pour_FonctionPourJeu->croix = SDL_LoadBMP("images/Croix.bmp");
Composants_Pour_FonctionPourJeu->rond = SDL_LoadBMP("images/Rond.bmp");
Composants_Pour_FonctionPourJeu->PointsCroix= SDL_LoadBMP( "images/petiteCroix.bmp");
Composants_Pour_FonctionPourJeu->PointsRond = SDL_LoadBMP( "images/PetitRond.bmp");
Composants_Pour_FonctionPourJeu->grille = SDL_LoadBMP ("images/PlateauVide.bmp");
Composants_Pour_FonctionPourJeu->TextePoints= SDL_LoadBMP("images/Points.bmp");
Composants_Pour_FonctionPourJeu->ImageMorpion[0]= SDL_LoadBMP( "images/morpionGrille.bmp" );
Composants_Pour_FonctionPourJeu->ImageMorpion[1]= SDL_LoadBMP( "images/morpionGrille2.bmp");
Composants_Pour_FonctionPourJeu->ImageMorpion[2]= SDL_LoadBMP( "images/morpionGrille3.bmp");
Composants_Pour_FonctionPourJeu->ImageMorpion[2]= SDL_LoadBMP( "images/morpionGrille3.bmp");
//Composants_Pour_FonctionPourJeu->img= SDL_LoadBMP( "images/play.bmp");
Composants_Pour_FonctionPourJeu->Quitter= TTF_RenderText_Blended(Composants_Pour_FonctionPourJeu->police, "Retour au menu Principal", couleurNoire);
Composants_Pour_FonctionPourJeu->positionImageMorpion.x = 900;
Composants_Pour_FonctionPourJeu->positionImageMorpion.y = 0;
Composants_Pour_FonctionPourJeu->positionImagePoints.x=30;
Composants_Pour_FonctionPourJeu->positionImagePoints.y=550;
Composants_Pour_FonctionPourJeu->position_Grille.x = 420;
Composants_Pour_FonctionPourJeu->position_Grille.y = 80;
Composants_Pour_FonctionPourJeu->positionPointsCroix.y=550;/*L'ordonnée des 2 images puisqu'on donne l'abcisse après!*/
Composants_Pour_FonctionPourJeu->positionPointsRond.y=615;
Composants_Pour_FonctionPourJeu->pos_Quitter.x=460;
Composants_Pour_FonctionPourJeu->pos_Quitter.y=650;
/* pos_img.x = 500;
pos_img.y = 260;*/
}
示例13: fixDirSeparators
void Font::loadFont(std::string filename,
const int size,
const int style)
{
if (fontCounter == 0 && TTF_Init() == -1)
{
logger->log("Unable to initialize SDL_ttf: " +
std::string(TTF_GetError()));
return;
}
fixDirSeparators(filename);
TTF_Font *const font = openFont(filename.c_str(), size);
if (!font)
{
logger->log("Font::Font: " +
std::string(TTF_GetError()));
return;
}
if (mFont)
TTF_CloseFont(mFont);
mFont = font;
TTF_SetFontStyle(mFont, style);
clear();
}
示例14: switch
void Font::AddFontStyle( FontStyle style )
{
switch ( style )
{
case FontStyle::Normal:
return;
case FontStyle::Bold:
mask |= TTF_STYLE_BOLD;
break;
case FontStyle::Italic:
mask |= TTF_STYLE_ITALIC;
break;
case FontStyle::Underline:
mask |= TTF_STYLE_UNDERLINE;
break;
case FontStyle::Strikethrough:
mask |= TTF_STYLE_STRIKETHROUGH;
break;
default :
break;
}
TTF_SetFontStyle( font, mask );
ApplyFontStyle();
}
示例15: height
Font::Font(const char *aaddress, int alength, int apointSize, int astyle,
float afgRed, float afgGreen, float afgBlue, float abgRed, float abgGreen,
float abgBlue) :
height(), ascent(), descent(), lineSkip(), address(
aaddress), length(alength), pointSize(apointSize), style(astyle), fgRed(
afgRed), fgGreen(afgGreen), fgBlue(afgBlue), bgRed(abgRed), bgGreen(
abgGreen), bgBlue(abgBlue), ttfFont(), foreground(), background() {
int i;
ttfFont = open_font(address, pointSize);
TTF_SetFontStyle(ttfFont, style);
foreground.r = (Uint8) (255 * fgRed);
foreground.g = (Uint8) (255 * fgGreen);
foreground.b = (Uint8) (255 * fgBlue);
background.r = (Uint8) (255 * bgRed);
background.g = (Uint8) (255 * bgGreen);
background.b = (Uint8) (255 * bgBlue);
height = TTF_FontHeight(ttfFont);
ascent = TTF_FontAscent(ttfFont);
descent = TTF_FontDescent(ttfFont);
lineSkip = TTF_FontLineSkip(ttfFont);
for (i = minGlyph; i <= maxGlyph; i++) {
glyphs[i].pic = NULL;
glyphs[i].tex = 0;
}
}