Exemple #1
0
void HighScoreDisplayDraw(HighScoreDisplay *h)
{
	char buf[2048];
	strcpy(buf, "High Scores\n\n");
	const bool countHeight = h->h == 0;
	if (countHeight) h->h += TTF_FontHeight(hsFont) * 2;
	for (int i = 0; i < (int)HighScores.size; i++)
	{
		const HighScore *hs = CArrayGet(&HighScores, i);
		char lbuf[256];
		struct tm *ptm = gmtime(&hs->Time);
		char tbuf[256];
		strftime(tbuf, sizeof tbuf, "%Y-%m-%d", ptm);
		sprintf(lbuf, "#%d        %d (%s)\n", i + 1, hs->Score, tbuf);
		strcat(buf, lbuf);
		if (countHeight)
		{
			h->h += TTF_FontHeight(hsFont);
		}
	}
	// Pulsate
	const float scalar =
		h->textCounter > 0.5f ? 1.0f - h->textCounter : h->textCounter;
	SDL_Color c;
	c.b = TEXT_BLUE_LOW + (Uint8)((TEXT_BLUE_HIGH - TEXT_BLUE_LOW) * scalar);
	c.r = c.g = c.b / 2;
	TextRenderCentered(hsFont, buf, (int)h->y, c);
}
Exemple #2
0
/**
 * Renders given text on the surface.
 * NOTE: Avoid calling in a loop. Blended rendering is slow
 * 
 * @param text The text to render
 * @param color Color to render text in
 * @param font Choose from RT_LARGE_FONT, RT_MEDIUM_FONT and RT_SMALL_FONT
 * @param dest The destination surface to blit to
 * @param x The x coordinate of destination where text will be blitted
 * @param y The y coordinate of destination where text will be blitted
 * @param align How to align the text. Valid values are rtTextUtil::ALIGN_LEFT (default), rtTextUtil::ALIGN_CENTER, rtTextUtil::ALIGN_RIGHT. The x, y coordinates are relative to position.
 * @param bold Render bold text (Default false)
 * @param italic Render italic text (Default false)
 * @param yPadding The distance between two consecutive lines.
 */
void rtTextUtil::render(const char * text,
                       SDL_Color color,
                       TTF_Font * font,
                       SDL_Surface * dest,
                       int x,
                       int y,
                       int align,
                       bool bold,
                       bool italic,
                       int yPadding) {
                             
    //split by newlines and generate new surfaces for each
    std::string txt = text;
    std::string token;
    SDL_Surface *txtSurf;

    SDL_Rect r;
    r.y = y-TTF_FontHeight(font)/2;  

    while(!txt.empty()) {
        token = splitString(txt);
        if(token.empty()) {
            r.y += TTF_FontHeight(font) + yPadding;
            continue;
        }
        txtSurf = render(token.c_str(), color, font, bold, italic);

        if(txtSurf == NULL) {
            std::cerr<<"Error rendering text: "<<TTF_GetError()<<std::endl;
            return;
        }

        switch(align) {
            case ALIGN_LEFT:
                r.x = x;
                break;
            case ALIGN_RIGHT:
                r.x = x - txtSurf->w;
                break;
            case ALIGN_CENTER:
                r.x = x - txtSurf->w/2;
                break;
        }
        SDL_BlitSurface(txtSurf, NULL, dest, &r);
        SDL_FreeSurface(txtSurf);

        r.y += TTF_FontHeight(font) + yPadding;
    }
}
ScoreScrollNode::ScoreScrollNode(Screen *screen): Node(screen)
{
	_image = NULL;

	_pos.x = 175;
	_pos.y = 30;
	_pos.w = 160;
	_pos.h = 135;

	_name_color.r = _name_color.g = _name_color.b = 0xFF;
	_score_color.r = 0xF1;
	_score_color.g = 0x72;
	_score_color.b = 0xB7;

	_font = load_font(16);

	_scroll_rect.x = 0;
	_scroll_rect.y = 0;
	_scroll_rect.w = _pos.w;
	_scroll_rect.h = _pos.h;

	_bg_color.r = _bg_color.b = 0;
	_bg_color.g = 0;

	_font_height = TTF_FontHeight(_font);
}
Exemple #4
0
bool TextSupervisor::LoadFont(const std::string &filename, const std::string &font_name, uint32 size)
{
    // Make sure that the font name is not already taken
    if(IsFontValid(font_name) == true) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "a font with the desired reference name already existed: " << font_name << std::endl;
        return false;
    }

    if(size == 0) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "attempted to load a font of point size zero" << font_name << std::endl;
        return false;
    }

    // Attempt to load the font
    TTF_Font *font = TTF_OpenFont(filename.c_str(), size);
    if(font == NULL) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "call to TTF_OpenFont() failed to load the font file: " << filename << std::endl;
        return false;
    }

    // Create a new FontProperties object for this font and set all of the properties according to SDL_ttf
    FontProperties *fp = new FontProperties;
    fp->ttf_font = font;
    fp->height = TTF_FontHeight(font);
    fp->line_skip = TTF_FontLineSkip(font);
    fp->ascent = TTF_FontAscent(font);
    fp->descent = TTF_FontDescent(font);

    // Create the glyph cache for the font and add it to the font map
    fp->glyph_cache = new std::vector<FontGlyph *>;
    _font_map[font_name] = fp;
    return true;
} // bool TextSupervisor::LoadFont(...)
int DisplayCursor(TextEdition te)
{
    int c,l;
    SDL_Rect pos, rect = te.pos;
    SDL_Surface *surf;

    if (!te.focus)
        return 0;

    rect.x = 0;
    rect.y = 0;
    rect.w -= VSBWidth(te);
    rect.h -= HSBHeight(te);
    GetPositionInEdition(te, te.cursorPos, &l, &c);

    pos.x = te.tab[l][c].x + te.offsetX;
    pos.y = te.tab[l][c].y + te.offsetY;
    pos.w = 1;
    pos.h = te.fontHeight;

    if (IsRectInRect(pos, rect))
    {
        surf = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, TTF_FontHeight(te.font), 32, 0,0,0,0);
        SDL_FillRect(surf, 0, SDL_MapRGB(surf->format, te.colorFG.r, te.colorFG.g, te.colorFG.b));
        SDL_BlitSurface(surf, NULL, te.tmpSurf, &pos);
        SDL_FreeSurface(surf);

        return 1;
    }
    else return 0;
}
Exemple #6
0
void GUI::Checkbox::Draw() {
	SDL_Rect rect = {x+1,y+1,w-2,h-2};

	SDL_Colour black = ImgStuff::Colour(0,0,0);
	SDL_Colour white = ImgStuff::Colour(255,255,255);

	SDL_Colour bc = has_focus() ? ImgStuff::Colour(255,255,0) : white;
	SDL_Rect bt = {x,y,w,1}, bb = {x,y+h,w,1}, bl = {x,y,1,h}, br = {x+w,y,1,h};

	ImgStuff::draw_rect(bt, bc, 255);
	ImgStuff::draw_rect(bb, bc, 255);
	ImgStuff::draw_rect(bl, bc, 255);
	ImgStuff::draw_rect(br, bc, 255);

	ImgStuff::draw_rect(rect, black, 178);

	if(state) {
		TTF_Font *font = FontStuff::LoadFont("fonts/DejaVuSansMono.ttf", 18);
		int fh = TTF_FontHeight(font);
		int fw = FontStuff::TextWidth(font, "X");

		rect.x = x + (w - fw) / 2;
		rect.y = y + (h - fh) / 2;

		FontStuff::BlitText(screen, rect, font, white, "X");
	}
}
Exemple #7
0
/******************************************************************************\
 Loads the font, properly scaled and generates an error message if something
 goes wrong. For some reason, SDL_ttf returns a line skip that is one pixel shy
 of the image height returned by TTF_RenderUTF8_Blended() so we account for
 that here.
\******************************************************************************/
static void load_font(r_font_t font, c_var_t *var, int size)
{
        int points;

        points = (int)ceilf(size * r_scale_2d);
        if (points < FONT_SIZE_MIN)
                points = FONT_SIZE_MIN;
        C_zero(fonts + font);
        fonts[font].ttf_font = TTF_OpenFont(var->value.s, points);
        if (!fonts[font].ttf_font) {
                C_warning("Failed to load font '%s' (%d -> %d pt)",
                          var->value.s, size, points);

                /* Fallback to the stock font file */
                fonts[font].ttf_font = TTF_OpenFont(var->stock.s, points);
                if (!fonts[font].ttf_font)
                        C_error("Failed to load font '%s' (%d -> %d pt) and "
                                "stock font '%s'", var->value.s, size, points,
                                var->stock.s);
        }
        fonts[font].height = TTF_FontHeight(fonts[font].ttf_font);
        fonts[font].line_skip = TTF_FontLineSkip(fonts[font].ttf_font) + 1;

        /* SDL_ttf won't tell us the width of the widest glyph directly so we
           assume it is the width of 'W' */
        fonts[font].width = (int)R_font_size(font, "W").x;
}
Exemple #8
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;
	}
}
    void TtFontAsset::RenderText( SurfacePtr dest, int& x, int& y, const char* text, const pei::Color& color /*= pei::XColor(255,255,255)*/ )
    {
        //     assert ( pFont );
        if (!m_TtFont || dest.get() == NULL ) {
            return;
        }
#ifdef _HAS_SDL_TTF_
        SDL_Surface *text_surface = NULL;
        // this is a hack! We swap r & g and correct the color format manually
        // SDL_ttf renders ARGB, but we need ABGR (or LE RGBA) to match RGBA texture format - performace reasons!
        SDL_Color c = { color.b, color.g, color.r, color.a };
        if ( (text_surface = TTF_RenderText_Blended( (TTF_Font*)m_TtFont->GetFontHandle(), text, c )) != NULL )
        {
            // swap r&g in the format description
            text_surface->format->Rmask = 0x000000ff; text_surface->format->Rshift = 0;
            text_surface->format->Bmask = 0x00ff0000; text_surface->format->Bshift = 16;

        	pei::SurfacePtr txt( new pei::SDL::SurfaceWrapper(text_surface));
            pei::Blitter blitter(pei::PixOpPtr(new PixOpAlphaBlitSrcAlpha(txt->GetFormat(),dest->GetFormat()) ) );
            blitter.Blit( txt, dest, x, y, txt->GetWidth(), txt->GetHeight(), 0, 0 );

            int tw, th;
            TTF_SizeText( (TTF_Font*)m_TtFont->GetFontHandle(), text, &tw, &th);

            Uint32 font_height = TTF_FontHeight((TTF_Font*)m_TtFont->GetFontHandle()); // - a - 2*d;
            y += font_height;
            x += tw;
        }
#endif
    }
Exemple #10
0
void GUI::TextBox::Draw() {
	SDL_Rect rect = {x, y, w, h};

	ensure_SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0));

	rect.x += 1;
	rect.y += 1;
	rect.w -= 1;
	rect.h -= 1;

	ensure_SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 255, 255, 255));

	TTF_Font *font = FontStuff::LoadFont("fonts/DejaVuSansMono.ttf", 14);
	int fh = TTF_FontHeight(font);

	rect.x = x + (h - fh) / 2;
	rect.y = y + (h - fh) / 2;

	FontStuff::BlitText(screen, rect, font, ImgStuff::Colour(0,0,0), text);

	if(has_focus()) {
		rect.x += FontStuff::TextWidth(font, text.substr(0, insert_offset));
		rect.w = FontStuff::TextWidth(font, insert_offset < text.length() ? text.substr(insert_offset, 1) : "A");
		rect.h = fh;

		ensure_SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0));

		if(insert_offset < text.length()) {
			FontStuff::BlitText(screen, rect, font, ImgStuff::Colour(255,255,255), text.substr(insert_offset, 1));
		}
	}
}
// bitmap font font size test
// return face index that has this size or below
static int test_face_size(std::string f, int size, int faceIndex)
{
    TTF_Font* fnt = TTF_OpenFontIndex(f.c_str(), size, faceIndex);
    if(fnt)
    {
        char* style = TTF_FontFaceStyleName(fnt);
        if(style != NULL)
        {
            int faces = TTF_FontFaces(fnt);
            bool found = false;
            for(int i = faces - 1; i >= 0 && !found; i--)
            {
                TTF_Font* tf = TTF_OpenFontIndex(f.c_str(), size, i);
                char* ts = NULL;
                if(NULL != tf && NULL != (ts = TTF_FontFaceStyleName(tf)))
                {
                    if(0 == strcasecmp(ts, style) && TTF_FontHeight(tf) <= size)
                    {
                        faceIndex = i;
                        found = true;
                    }
                }
                TTF_CloseFont(tf);
            }
        }
        TTF_CloseFont(fnt);
    }

    return faceIndex;
}
Exemple #12
0
void Menu::setFont(const char* font_name)
{
    this->font = TTF_OpenFont(font_name, 48);
    this->inbetween = TTF_FontHeight(this->font);
    if(!this->font)
        handleError(TTF_GetError());
}
Exemple #13
0
void Font::InitFont( void )
{
	Initialized = false;
	
	if( TTFont )
		TTF_CloseFont( TTFont );
	
	TTFont = TTF_OpenFont( Name.c_str(), PointSize );
	if( ! TTFont )
	{
		// FIXME: Use TTF_Error output?
		fprintf( stderr, "Can't open font file: %s\n", Name.c_str() );
		return;
	}
	
	Height = TTF_FontHeight( TTFont );
	Ascent = TTF_FontAscent( TTFont );
	Descent = TTF_FontDescent( TTFont );
	LineSkip = TTF_FontLineSkip( TTFont );
	
	for( int i = 0; i < 256; i ++ )
	{
		Glyphs[ i ].Pic = NULL;
		Glyphs[ i ].Tex = 0;
	}
	
	LoadedTime.Reset();
	
	Initialized = true;
}
	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;
		}
	}
Exemple #15
0
extern SCROLLTEXT* newScroll(char *text)
{
   SCROLLTEXT *newScroll;
   SDL_Surface *screen;
   int i=0;
   
   newScroll = malloc(sizeof(SCROLLTEXT));
   
   screen = SDL_GetVideoSurface();
   
   if (!TTF_WasInit())
   {
      if (TTF_Init()==-1)
      {
         fprintf(stderr, "No text for you...\n");
         return NULL;
      }
   }
   
   newScroll->font = TTF_OpenFont("scrollFont.ttf", 25);
   
   newScroll->background = SDL_CreateRGBSurface(
      SDL_HWSURFACE|SDL_SRCALPHA,
      screen->w,
      TTF_FontHeight(newScroll->font) + 2,
      32, screen->format->Rmask,
      screen->format->Gmask,
      screen->format->Bmask,
      screen->format->Amask);
      
   newScroll->screenLocal.x = 0;
   newScroll->screenLocal.y = 0;
   newScroll->screenLocal.w = screen->w;
   newScroll->screenLocal.h = 1;
   
   for (i = 50; i <= 200; i += (150 / newScroll->background->h))
   {
      SDL_FillRect(newScroll->background, &newScroll->screenLocal,
         SDL_MapRGBA(screen->format, 0, i, 0, i));
      ++newScroll->screenLocal.y;
   }
   
   newScroll->textClip.x = 0;
   newScroll->textClip.y = 0;
   newScroll->textClip.w = screen->w;
   newScroll->textClip.h = newScroll->background->h;
   
   newScroll->text = text;
   
   newScroll->textColor.r = 255;
   newScroll->textColor.g = 255;
   newScroll->textColor.b = 255;
   
   newScroll->renderedText = TTF_RenderText_Blended(
      newScroll->font,
      newScroll->text,
      newScroll->textColor);
      
   return newScroll;
}
Exemple #16
0
  gcc_pure
  unsigned text_height(const TCHAR *text) const {
#ifdef ANDROID
    return font != NULL ? font->get_height() : 0;
#else
    return font != NULL ? TTF_FontHeight(font) : 0;
#endif
  }
Exemple #17
0
 void text_matrix(int x, int y, double m[]) {
     int i, j;
     for (i = 0; i < 4; i++) {
         for (j = 0; j < 4; j++) {
             text(x + 75 * i, y + TTF_FontHeight(sdl_font) * j, sdl_font, "%8.2f", m[4*i+j]);
         }
     }
 }
Exemple #18
0
int get_max_height(int size)
{
	// Only returns the maximal size of the first font
	TTF_Font* const font = get_font(font_id(0, size));
	if(font == NULL)
		return 0;
	return TTF_FontHeight(font);
}
violet::TextManager::TextManager(boost::filesystem::path fontPath, int fontSize) {
	m_font = TTF_OpenFont(fontPath.string().c_str(), fontSize);
	if (!m_font) {
		std::cerr << "Couldn't initialize font: " << TTF_GetError() << std::endl;
		exit(5);
	}
	m_height = TTF_FontHeight(m_font);
	m_ident = (int) (m_height * 0.5);
}
Exemple #20
0
void load_font(char *fname, int size)
{
    char *p;

    free_font();
    font=TTF_OpenFont(fname, size);
    if(!font)
    {
        printf("TTF_OpenFont: %s\n", TTF_GetError());
        exit(3);
    }

    /* print some metrics and attributes */
    printf("size                    : %d\n",size);
    printf("TTF_FontHeight          : %d\n",TTF_FontHeight(font));
    printf("TTF_FontAscent          : %d\n",TTF_FontAscent(font));
    printf("TTF_FontDescent         : %d\n",TTF_FontDescent(font));
    printf("TTF_FontLineSkip        : %d\n",TTF_FontLineSkip(font));
    printf("TTF_FontFaceIsFixedWidth: %d\n",TTF_FontFaceIsFixedWidth(font));
    {
        char *str=TTF_FontFaceFamilyName(font);
        if(!str)
            str="(null)";
        printf("TTF_FontFaceFamilyName  : \"%s\"\n",str);
    }
    {
        char *str=TTF_FontFaceStyleName(font);
        if(!str)
            str="(null)";
        printf("TTF_FontFaceStyleName   : \"%s\"\n",str);
    }
    if(TTF_GlyphIsProvided(font,'g'))
    {
        int minx, maxx, miny, maxy, advance;
        TTF_GlyphMetrics(font,'g', &minx, &maxx, &miny, &maxy, &advance);
        printf("TTF_GlyphMetrics('g'):\n\tminx=%d\n\tmaxx=%d\n\tminy=%d\n\tmaxy=%d\n\tadvance=%d\n",
            minx, maxx, miny, maxy, advance);
    }
    else
        printf("TTF_GlyphMetrics('g'): unavailable in font!\n");

    /* set window title and icon name, using filename and stuff */
    p=strrchr(fname,'/');
    if(!p)
        p=strrchr(fname,'\\');
    if(!p)
        p=strrchr(fname,':');
    if(!p)
        p=fname;
    else
        p++;

    /* cache new glyphs */
    cache_glyphs();
}
Exemple #21
0
void
Font::CalculateHeights()
{
  height = TTF_FontHeight(font);
  ascent_height = TTF_FontAscent(font);

  int miny, maxy;
  TTF_GlyphMetrics(font, 'M', NULL, NULL, &miny, &maxy, NULL);

  capital_height = maxy - miny + 1;
}
Exemple #22
0
static void RenderUpdate () {
  SDL_Rect r;
  int winW, winH, texW, texH, dist;

  if (!sdlWindow || !sdlRenderer) return;

  SDL_GetRendererOutputSize (sdlRenderer, &winW, &winH);

  SDL_SetRenderDrawColor (sdlRenderer, 0, 0, 0, 255);
  SDL_RenderClear (sdlRenderer);

  if (texVideoRemote) {
    SDL_QueryTexture (texVideoRemote, NULL, NULL, &texW, &texH);
    if (winW * texH < texW * winH) {
      // Texture is wider than window => fit to width...
      r.w = winW;
      r.h = texH * winW / texW;
      r.x = 0;
      r.y = (winH - r.h) / 2;
    }
    else {
      // Window is wider than texture => fit to height...
      r.w = texW * winH / texH;
      r.h = winH;
      r.x = (winW - r.w) / 2;
      r.y = 0;
    }
    SDL_RenderCopy (sdlRenderer, texVideoRemote, NULL, &r);
  }
  if (texVideoLocal) {
    SDL_QueryTexture (texVideoLocal, NULL, NULL, &texW, &texH);
    // Select 1/4 of the total height and keep aspect ratio...
    r.h = winH / 4;
    r.w = r.h * texW / texH;
    r.x = winW - r.w;
    r.y = winH - r.h;
    SDL_RenderCopy (sdlRenderer, texVideoLocal, NULL, &r);
  }
  if (texMessage) {
    SDL_QueryTexture (texMessage, NULL, NULL, &texW, &texH);
    r.w = texW;
    r.h = texH;
    /*
    // Center message text...
    r.x = (winW - texW) / 2;
    r.y = (winH - texH) / 2;
    */
    dist = TTF_FontHeight (sdlFont) / 2;
    r.x = dist;
    r.y = winH - texH - dist;
    SDL_RenderCopy (sdlRenderer, texMessage, NULL, &r);
  }
  SDL_RenderPresent (sdlRenderer);
}
Exemple #23
0
float CText::GetHeight(FontType font, float size)
{
    assert(font != FONT_BUTTON);

    CachedFont* cf = GetOrOpenFont(font, size);
    assert(cf != nullptr);
    Math::IntPoint wndSize;
    wndSize.y = TTF_FontHeight(cf->font);
    Math::Point ifSize = m_engine->WindowToInterfaceSize(wndSize);
    return ifSize.y;
}
Exemple #24
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;
}
JNIEXPORT jint JNICALL Java_sdljava_x_swig_SWIG_1SDLTTFJNI_TTF_1FontHeight(JNIEnv *jenv, jclass jcls, jlong jarg1) {
    jint jresult = 0 ;
    TTF_Font *arg1 = (TTF_Font *) 0 ;
    int result;
    
    (void)jenv;
    (void)jcls;
    arg1 = *(TTF_Font **)&jarg1; 
    result = (int)TTF_FontHeight(arg1);
    
    jresult = (jint)result; 
    return jresult;
}
Exemple #26
0
/**
 * Initializes the required font metrics.
 */
static Code initialize_font_metrics(void) {
  int width;
  int height;
  Font *font = global_monospaced_font;
  if (TTF_GlyphMetrics(font, 'A', NULL, NULL, NULL, NULL, &width)) {
    log_message("Could not assess the width of a font.");
    return CODE_ERROR;
  }
  height = TTF_FontHeight(font);
  global_monospaced_font_width = width;
  global_monospaced_font_height = height;
  return CODE_OK;
}
Exemple #27
0
int get_text_height(FontDesc *font)
{
	if (font == NULL) return 0;
#ifdef USE_TTF
	if (font->fonthandle == NULL)
		font->fonthandle = TTF_OpenFont(font->filename, FONT_SIZE);
	if (font->fonthandle)
		return TTF_FontHeight((TTF_Font *)font->fonthandle);
	else
		return 0;
#else
	return 24;
#endif
}
Exemple #28
0
void GUI_Input::DrawText() {
	int h;
	int x,y;

	x = 3;
	h = TTF_FontHeight(GetFont());
	y = (my_height - h)/2;

	// draw text
	char DrawText[10];
	strcpy(DrawText, GetDrawText());
	my_strupr(DrawText);

	if(DrawText[0] != 0){
		PG_DrawObject::DrawText(x+offset_x,y+2, DrawText, textcolor, GetFont());
	}		
}
Exemple #29
0
bool Fonte::carregarTrueType(const string& arquivo, int tamanho, int estilo, Uint16 primeiro_glifo, Uint16 ultimo_glifo, EnumQualidadeEscala qualidade_escala)
{
	if (!uniEstaInicializada())
	{
		gDebug.erro("Sem uniInicializar() antes de tentar carregar: '" + arquivo + "'.");
		return false;
	}

	if (estaCarregada())
	{
		gDebug.erro("Arquivo '" + arquivo + "' nao pode ser carregado, pois Fonte ja carregou o arquivo " + tex.getCaminhoDoArquivo() + ".");
		return false;
	}

	TTF_Font* ttf_font = TTF_OpenFont(arquivo.c_str(), tamanho);
	if (!ttf_font)
	{
		gDebug.erro("Erro ao carregar arquivo: '" + arquivo + "' - " + SDL_GetError() + ".");
		return false;
	}

	TTF_SetFontStyle(ttf_font, estilo);

	if (!criarTexturaTrueType(ttf_font, tamanho, primeiro_glifo, ultimo_glifo, qualidade_escala))
	{
		glifos.clear();
		gDebug.erro("Erro ao criar textura para fonte ttf, usando arquivo: '" + arquivo + "' - " + SDL_GetError() + ".");
		return false;
	}
	glifoNulo.quad.x = 0;
	glifoNulo.quad.y = 0;
	glifoNulo.quad.larg = 0;
	glifoNulo.quad.alt = 0;
	glifoNulo.alturaAcimaDaBase = 0;
	glifoNulo.avanco = tamanho;
	glifoNulo.caractere = 0;

	this->estilo = estilo;
	monoespacada = TTF_FontFaceIsFixedWidth(ttf_font) > 0;

	larguraGlifos = tamanho;
	alturaGlifos = TTF_FontHeight(ttf_font);

	ttf = true;
	return true;
}
Exemple #30
0
FontEngine::FontEngine() {
	font_pt = 10;

	// Initiate SDL_ttf
	if(!TTF_WasInit() && TTF_Init()==-1) {
		printf("TTF_Init: %s\n", TTF_GetError());
		exit(2);
	}

	// load the font
	string font_path;
	FileParser infile;
	if (infile.open(PATH_DATA + "engine/font_settings.txt")) {
		while (infile.next()) {
			if (infile.key == "font_regular"){
				font_path = infile.val;
			}
			if (infile.key == "ptsize"){
				font_pt = atoi(infile.val.c_str());
			}
		}
	}
	font_path = PATH_DATA + "fonts/" + font_path;
	font = TTF_OpenFont(font_path.c_str(), font_pt);
	if(!font) printf("TTF_OpenFont: %s\n", TTF_GetError());

	// calculate the optimal line height
	line_height = TTF_FontLineSkip(font);
	font_height = TTF_FontHeight(font); 

	// set the font colors
	SDL_Color white = {255,255,255};
	SDL_Color red = {255,0,0};
	SDL_Color green = {0,255,0};
	SDL_Color blue = {0,0,255};
	SDL_Color grey = {128,128,128};
	SDL_Color black = {0,0,0};

	colors[FONT_WHITE] = white;
	colors[FONT_RED] = red;
	colors[FONT_GREEN] = green;
	colors[FONT_BLUE] = blue;
	colors[FONT_GREY] = grey;
	colors[FONT_BLACK] = black;
}