Esempio n. 1
0
	void applyFontStyle(bool bold)
	{
		if (bold)
			TTF_SetFontStyle(font, TTF_STYLE_BOLD);
		else
			TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
	}
Esempio n. 2
0
void Typeface::setItalic(bool b) {
	int style = TTF_GetFontStyle(font);
	if (b != (style & TTF_STYLE_ITALIC)) { // avoid flushing the glyph cache
		if (b) {
			TTF_SetFontStyle(font, style | TTF_STYLE_ITALIC);
		} else {
			TTF_SetFontStyle(font, style & ~TTF_STYLE_ITALIC);
		}
	}
}
Esempio n. 3
0
void Typeface::setUnderline(bool b) {
	int style = TTF_GetFontStyle(font);
	if (b != (style & TTF_STYLE_UNDERLINE)) { // avoid flushing the glyph cache
		if (b) {
			TTF_SetFontStyle(font, style | TTF_STYLE_UNDERLINE);
		} else {
			TTF_SetFontStyle(font, style & ~TTF_STYLE_UNDERLINE);
		}
	}
}
Esempio n. 4
0
void Typeface::setStrikethrough(bool b) {
	int style = TTF_GetFontStyle(font);
	if (b != (style & TTF_STYLE_STRIKETHROUGH)) { // avoid flushing the glyph cache
		if (b) {
			TTF_SetFontStyle(font, style | TTF_STYLE_STRIKETHROUGH);
		} else {
			TTF_SetFontStyle(font, style & ~TTF_STYLE_STRIKETHROUGH);
		}
	}
}
Esempio n. 5
0
/**************************************************************************
  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;
}
Esempio n. 6
0
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);
	}
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
//==============================================================================
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;	
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
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;
}
	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;
		}
	}
//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;
	}
}
Esempio n. 13
0
//-----------------------------------------------------------------------------
// 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;
}
Esempio n. 14
0
/*
 * 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);
}
Esempio n. 15
0
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;*/
}
Esempio n. 16
0
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();
}
Esempio n. 17
0
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();
}
Esempio n. 18
0
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;
	}
}
Esempio n. 19
0
GFont fonts_get_system_font(const char *font_key) {
    int i;
    for (i=0; i<SYSTEM_FONT_COUNT; i++) {
        if (strcmp(font_key,systemFonts[i].key)==0) {
            if (systemFonts[i].font==0) {
                systemFonts[i].font=TTF_OpenFont (systemFonts[i].file,systemFonts[i].psize);
                if (systemFonts[i].font==0) {
                    printf ("[WARN] Didn't found system font: %s\n",systemFonts[i].file);
                } else {
                    switch (i) {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 9:
                        TTF_SetFontStyle(systemFonts[i].font, TTF_STYLE_BOLD);
                        break;
                    }
                }
            }
            return (GFont)systemFonts[i].font;
        }
    }
    printf ("[WARN] Invalid system font: %s\n",font_key);
    return 0;
}
void ONScripterLabel::drawGlyph( SDL_Surface *dst_surface, FontInfo *info, SDL_Color &color, char* text, int xy[2], bool shadow_flag, AnimationInfo *cache_info, SDL_Rect *clip, SDL_Rect &dst_rect )
{
    unsigned short unicode;
    if (IS_TWO_BYTE(text[0])){
        unsigned index = ((unsigned char*)text)[0];
        index = index << 8 | ((unsigned char*)text)[1];
        unicode = onsLocaleConv( index );
    }
    else{
        if ((text[0] & 0xe0) == 0xa0 || (text[0] & 0xe0) == 0xc0) unicode = ((unsigned char*)text)[0] - 0xa0 + 0xff60;
        else unicode = text[0];
    }

    int minx, maxx, miny, maxy, advanced;
#if 0
    if (TTF_GetFontStyle( (TTF_Font*)info->ttf_font ) !=
        (info->is_bold?TTF_STYLE_BOLD:TTF_STYLE_NORMAL) )
        TTF_SetFontStyle( (TTF_Font*)info->ttf_font, (info->is_bold?TTF_STYLE_BOLD:TTF_STYLE_NORMAL));
#endif    
    TTF_GlyphMetrics( (TTF_Font*)info->ttf_font, unicode,
                      &minx, &maxx, &miny, &maxy, &advanced );
    //printf("min %d %d %d %d %d %d\n", minx, maxx, miny, maxy, advanced,TTF_FontAscent((TTF_Font*)info->ttf_font)  );
    
    SDL_Surface *tmp_surface = renderGlyph( (TTF_Font*)info->ttf_font, unicode );

    bool rotate_flag = false;
    if ( info->getTateyokoMode() == FontInfo::TATE_MODE && IS_ROTATION_REQUIRED(text) ) rotate_flag = true;
    
    dst_rect.x = xy[0] + minx;
    dst_rect.y = xy[1] + TTF_FontAscent((TTF_Font*)info->ttf_font) - maxy;
    if ( rotate_flag ) dst_rect.x += miny - minx;
        
    if ( info->getTateyokoMode() == FontInfo::TATE_MODE && IS_TRANSLATION_REQUIRED(text) ){
        dst_rect.x += info->font_size_xy[0]/2;
        dst_rect.y -= info->font_size_xy[0]/2;
    }

    if ( shadow_flag ){
        dst_rect.x += shade_distance[0];
        dst_rect.y += shade_distance[1];
    }

    if ( tmp_surface ){
        if (rotate_flag){
            dst_rect.w = tmp_surface->h;
            dst_rect.h = tmp_surface->w;
        }
        else{
            dst_rect.w = tmp_surface->w;
            dst_rect.h = tmp_surface->h;
        }

        if (cache_info)
            cache_info->blendBySurface( tmp_surface, dst_rect.x, dst_rect.y, color, clip, rotate_flag );
        
        if (dst_surface)
            alphaBlend32( dst_surface, dst_rect, tmp_surface, color, clip, rotate_flag );
    }
}
Esempio n. 21
0
		int LOBJECT_METHOD(setFontStyle, TTF_Font * font){
			int style = TTF_STYLE_NORMAL;
			if (state.is_number(1)){
				style = state.to_integer(1);
			}
			TTF_SetFontStyle(font, style);
			return 0;
		}
Esempio n. 22
0
void pol_style(int style)
	{
	POINT p;
	p.x = -10; p.y = -10;
	aff_pol("",10,p,black); // Appel de aff_pol pour fixer la valeur de ___pol
	if ((style < 0x00) || (0x04 < style)) style = 0x00;
	TTF_SetFontStyle(___pol,style);
	}
Esempio n. 23
0
	void FontHandler::initialize(){
		
	font = TTF_OpenFont( "lazy.ttf", 28 );
    fontMenu = TTF_OpenFont( "lazy.ttf", 40);
	
    TTF_SetFontStyle(fontMenu, TTF_STYLE_BOLD);

	}
Esempio n. 24
0
static mrb_value
mrb_sdl2_ttf_font_set_style(mrb_state *mrb, mrb_value self)
{
  mrb_int style;
  mrb_get_args(mrb, "i", &style);
  TTF_SetFontStyle(mrb_sdl2_font_get_ptr(mrb, self), style);
  return mrb_nil_value();
}
Esempio n. 25
0
//Basic Init, create the font, backbuffer, etc
WINDOW *initscr(void)
{
    lastchar=-1;
    inputdelay=-1;

    std::string typeface = "";
	std::ifstream fin;
    int fontsize = 0; //actuall size
	fin.open("data/FONTDATA");
	if (!fin.is_open()){
        fontheight=16;
        fontwidth=8;
	} else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        if ((fontwidth <= 4) || (fontheight <=4)){
            fontheight=16;
            fontwidth=8;
		}
		fin.close();
	}

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS[OPT_VIEWPORT_X] * 2 + 1)) * fontwidth;
    WindowHeight= (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1) *fontheight;
    if(!WinCreate()) {}// do something here
    
    //make fontdata compatible with wincurse
    if(!fexists(typeface.c_str()))
        typeface = "data/font/" + typeface + ".ttf";

    //different default font with wincurse
    if(!fexists(typeface.c_str()))
        typeface = "data/font/fixedsys.ttf";

    if(fontsize<=0) fontsize=fontheight-1;
	font = TTF_OpenFont(typeface.c_str(), fontsize);

    //if(!font) something went wrong

	TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
	//TTF_SetFontOutline(font, 0);
	//TTF_SetFontKerning(font, 0);
	//TTF_SetFontHinting(font, TTF_HINTING_MONO);

	// glyph height hack by utunnels 
	// SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics
	// this causes baseline problems for certain fonts 
	// I can only guess by check a certain tall character...
    cache_glyphs();


    mainwin = newwin((OPTIONS[OPT_VIEWPORT_Y] * 2 + 1),(55 + (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Esempio n. 26
0
int
render_glyph(Glyph *g, SDL_Surface **ret) {
	SDL_Color color = {0,0,0}, bgcolor={0xff,0xff,0xff};
	int bold, italic, underline, strikethrough, sup, sub, supsub;
	int font;
	int baseline;
	char *byte;
	TTF_Font **fs;
	
	byte = g->bytes;
	if (format_byte(*byte, &bold, &italic, &underline, &strikethrough, &sup, &sub, &supsub))
		byte++;
	
	if (sup || sub || supsub)
		fs = su_fonts;
	else
		fs = fonts;
		
	baseline = 0;
	if (sub)
		baseline = 9;
	else if(supsub)
		baseline = 3;
	
	if (bold && italic)
		font = FONT_BOLD_ITALIC;
	else if (bold)
		font = FONT_BOLD;
	else if (italic)
		font = FONT_ITALIC;
	else
		font = FONT_NORMAL;
		
	if (underline && strikethrough)
		TTF_SetFontStyle(fs[font], TTF_STYLE_UNDERLINE | TTF_STYLE_STRIKETHROUGH);
	else if (underline)
		TTF_SetFontStyle(fs[font], TTF_STYLE_UNDERLINE);
	else if (strikethrough)
		TTF_SetFontStyle(fs[font], TTF_STYLE_STRIKETHROUGH);
	
	*ret = TTF_RenderUTF8_Shaded(fs[font], byte, color, bgcolor);
	TTF_SetFontStyle(fs[font], TTF_STYLE_NORMAL);
	
	return baseline;
}
Esempio n. 27
0
File: Fonts.cpp Progetto: qdii/vcmi
CTrueTypeFont::CTrueTypeFont(const JsonNode & fontConfig):
    data(loadData(fontConfig)),
    font(loadFont(fontConfig), TTF_CloseFont),
    blended(fontConfig["blend"].Bool())
{
    assert(font);

    TTF_SetFontStyle(font.get(), getFontStyle(fontConfig));
}
Esempio n. 28
0
void Font::ApplyFontStyle()
{
	if ( prevMask == mask )
		return;

	TTF_SetFontStyle( font, mask );

	prevMask = mask;
}
Esempio n. 29
0
static KW_Texture * KWSDL_renderText(KW_RenderDriver * driver, KW_Font * font, const char * text, KW_Color color, KW_RenderDriver_TextStyle style) {
  KWSDL * kwsdl = (KWSDL *) driver->priv;
  int previousstyle;
  SDL_Color sdlcolor;
  SDL_Surface * textsurface;
  SDL_Texture * ret;

  sdlcolor.r = color.r, sdlcolor.g = color.g, sdlcolor.b = color.b, sdlcolor.a = color.a;
  if (font == NULL || text == NULL)
    return NULL;

  previousstyle = TTF_GetFontStyle(font);
  TTF_SetFontStyle(font, style);
  textsurface = TTF_RenderUTF8_Blended(font, text, sdlcolor);
  ret = SDL_CreateTextureFromSurface(kwsdl->renderer, textsurface);
  SDL_FreeSurface(textsurface);
  TTF_SetFontStyle(font, previousstyle);
  return ret;
}
Esempio n. 30
0
void font::set_font_style(font_style style) {
    int s=0;
    if(style.bold)
        s=s|TTF_STYLE_BOLD;
    if(style.italic)
        s=s|TTF_STYLE_ITALIC;
    if(style.underline)
        s=s|TTF_STYLE_UNDERLINE;
    TTF_SetFontStyle(get_low(),s);
}