当前位置: 首页>>代码示例>>C++>>正文


C++ TTF_FontHeight函数代码示例

本文整理汇总了C++中TTF_FontHeight函数的典型用法代码示例。如果您正苦于以下问题:C++ TTF_FontHeight函数的具体用法?C++ TTF_FontHeight怎么用?C++ TTF_FontHeight使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TTF_FontHeight函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HighScoreDisplayDraw

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);
}
开发者ID:AMDmi3,项目名称:FallingTime,代码行数:28,代码来源:high_score.c

示例2: while

/**
 * 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;
    }
}
开发者ID:nikhilm,项目名称:ricochet,代码行数:64,代码来源:textutil.cpp

示例3: Node

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);
}
开发者ID:davehorner,项目名称:KM-Bubble-Shooter,代码行数:26,代码来源:scorescrollnode.cpp

示例4: IF_PRINT_WARNING

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(...)
开发者ID:AMDmi3,项目名称:ValyriaTear,代码行数:33,代码来源:text.cpp

示例5: DisplayCursor

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;
}
开发者ID:CokieForever,项目名称:pacman-caml,代码行数:31,代码来源:textedition.c

示例6: has_focus

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");
	}
}
开发者ID:froggey,项目名称:hexradius,代码行数:27,代码来源:gui.cpp

示例7: TTF_RenderUTF8_Blended

/******************************************************************************\
 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;
}
开发者ID:sivarajankumar,项目名称:plutocracy,代码行数:33,代码来源:r_assets.c

示例8: 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;
	}
}
开发者ID:codespear,项目名称:GameEx,代码行数:31,代码来源:font.cpp

示例9: txt

    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
    }
开发者ID:juergen0815,项目名称:PEngIneLite,代码行数:30,代码来源:tt_font_asset.cpp

示例10: ensure_SDL_FillRect

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));
		}
	}
}
开发者ID:froggey,项目名称:hexradius,代码行数:32,代码来源:gui.cpp

示例11: test_face_size

// 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;
}
开发者ID:narcoticgoldfish,项目名称:Cataclysm-DDA,代码行数:32,代码来源:sdlcurse.cpp

示例12: TTF_OpenFont

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());
}
开发者ID:Shaptic,项目名称:NPong,代码行数:7,代码来源:MenuCreation.cpp

示例13: 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;
		}
	}
开发者ID:jasonwnorris,项目名称:HybridGameEngineAntiquated,代码行数:29,代码来源:GlyphFont.cpp

示例14: newScroll

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;
}
开发者ID:quizno50,项目名称:BoingDemo,代码行数:60,代码来源:scrollText.c

示例15: text_height

  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
  }
开发者ID:Mrdini,项目名称:XCSoar,代码行数:8,代码来源:Canvas.hpp


注:本文中的TTF_FontHeight函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。