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


C++ TTF_SizeText函数代码示例

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


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

示例1: menu_options

 uint8_t menu_options(uint8_t selected_option, int16_t width, SDL_Surface *buffer, TTF_Font *ttf_font)
{
  SDL_Rect target;
  SDL_Surface *text;
  SDL_Color text_color     = {200, 200, 200};
  SDL_Color selected_color = {50, 150, 250};
  SDL_Color current_color  = {128, 128, 128};
  int w, h, i, y;
  char *title = GNAME;
  char menu_options[3][25] = {
      "JUGAR",
      "CREDITOS",
      "SALIR"
  };

    y = TILE_HALF * 5;

    SDL_FillRect(buffer, NULL, 0x000000);
    TTF_SizeText(font, title, &w, &h);
    target.x = (width + (TILE_SIZE << 1) - w) >> 1;
    target.y = TILE_SIZE;
    target.w = w;
    target.h = h;

    text = TTF_RenderText_Blended(font, title, current_color);
    SDL_BlitSurface(text, NULL, buffer, &target);
    SDL_FreeSurface(text);

    current_color = text_color;

    for (i = 0; i < 3; i ++) {
        current_color = (selected_option == i) ? selected_color : text_color;

        TTF_SizeText(ttf_font, menu_options[i], &w, &h);
        target.x = (width + (TILE_SIZE << 1) - w) >> 1;
        target.y = y + i * h;
        target.w = w;
        target.h = h;

        text = TTF_RenderText_Blended(ttf_font, menu_options[i], current_color);
        SDL_BlitSurface(text, NULL, buffer, &target);
        SDL_FreeSurface(text);
    }

    return i - 1;
}
开发者ID:amfo,项目名称:rockpush,代码行数:46,代码来源:rockpush.c

示例2: Java_sdljava_x_swig_SWIG_1SDLTTFJNI_TTF_1SizeText

JNIEXPORT jint JNICALL Java_sdljava_x_swig_SWIG_1SDLTTFJNI_TTF_1SizeText(JNIEnv *jenv, jclass jcls, jlong jarg1, jstring jarg2, jintArray jarg3, jintArray jarg4) {
    jint jresult = 0 ;
    TTF_Font *arg1 = (TTF_Font *) 0 ;
    char *arg2 ;
    int *arg3 = (int *) 0 ;
    int *arg4 = (int *) 0 ;
    int result;
    int temp3 ;
    int temp4 ;
    
    (void)jenv;
    (void)jcls;
    arg1 = *(TTF_Font **)&jarg1; 
    {
        arg2 = 0;
        if (jarg2) {
            arg2 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg2, 0);
            if (!arg2) return 0;
        }
    }
    {
        if (!jarg3) {
            SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
            return 0;
        }
        if ((*jenv)->GetArrayLength(jenv, jarg3) == 0) {
            SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
            return 0;
        }
        arg3 = &temp3; 
    }
    {
        if (!jarg4) {
            SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
            return 0;
        }
        if ((*jenv)->GetArrayLength(jenv, jarg4) == 0) {
            SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
            return 0;
        }
        arg4 = &temp4; 
    }
    result = (int)TTF_SizeText(arg1,(char const *)arg2,arg3,arg4);
    
    jresult = (jint)result; 
    {
        jint jvalue = (jint)temp3;
        (*jenv)->SetIntArrayRegion(jenv, jarg3, 0, 1, &jvalue);
    }
    {
        jint jvalue = (jint)temp4;
        (*jenv)->SetIntArrayRegion(jenv, jarg4, 0, 1, &jvalue);
    }
    {
        if (arg2) (*jenv)->ReleaseStringUTFChars(jenv, jarg2, arg2); 
    }
    return jresult;
}
开发者ID:Deeptiman,项目名称:midpath4dingoo,代码行数:58,代码来源:SDLTTF_wrap.c

示例3: uiTextInput_Setup

void uiTextInput_Setup(Ui_TextInput *textInput, int x, int y, int layer, char *text, TTF_Font *font, int maxLength, int outputType, void *outputVar, Control_Event *cActivate, Ui_Pointer *pnt, Timer *srcTimer)
{
    int i = 0;
    int buttonWidth = 0;
    int buttonHeight = 0;
    Sprite *buttonSprite = NULL;
    Ui_TextBox *textBox = NULL;

    /*Setup the input buffer*/
    textInput->textLength = maxLength;

    textInput->inputText = (char *)mem_Malloc((maxLength + 1) * sizeof(char), __LINE__, __FILE__);
    for(i = 0; i < maxLength + 1; i++)
        textInput->inputText[i] = '\0';

    /*Setup output variable*/
    textInput->outputType = outputType;
    textInput->outputVar = outputVar;

    /*Setup the letter marking graphic*/
    sprite_Setup(&textInput->sMarker, 0, layer, srcTimer, 1,
                 frame_CreateBasic(0, surf_SimpleBox(2, 2, &colourBlack, &colourBlack, 1), A_FREE));


    /*Create the text box that is to be linked to the button*/
    textBox = uiTextBox_CreateBase(0, 0, layer, 0, NULL, font, tColourBlack, srcTimer);
    uiTextBox_AddText(textBox,
                     0, 0, text, NULL);

    /*Make sure the text starts to the left of the button*/
    uiTextBox_SetPos(textBox, -(int)sprite_Width(textBox->graphic) - 5, 0);

    buttonSprite = sprite_Setup(sprite_Create(),  1, layer, srcTimer, 1,
                              frame_CreateBasic(0, NULL, M_FREE)
    );

    /*Approximate the needed button width by using the '0' character width then
    multiplying it by the maximum text length*/
    TTF_SizeText(font,"0", &buttonWidth, &buttonHeight);
    buttonWidth *= maxLength;

    uiRect_SetDim(&textInput->rect, buttonWidth, buttonHeight);

    uiButton_Setup(&textInput->button, x, y, buttonWidth, buttonHeight, BFA_EnterPoll, BFA_Hover, dataStruct_Create(2, textInput, pnt), buttonSprite, 0, 250, srcTimer);

    uiButton_AddText(&textInput->button, textBox);

    uiButton_CopyControl(&textInput->button, cActivate, BC_POINTER);
    uiButton_CopyControl(&textInput->button, cActivate, BC_KEY);

    uiTextInput_SetPos(textInput, x, y);
    uiTextInput_SetState(textInput, pnt, UI_TEXTINPUT_BASE);
    uiTextInput_AssignInput(textInput);

    depWatcher_Setup(&textInput->dW, textInput);

    return;
}
开发者ID:sigt44,项目名称:ventifact,代码行数:58,代码来源:TextInput.c

示例4: textSize

void textSize(char *text, int size, int *w, int *h)
{
	if (!font[size])
	{
		loadFont(size);
	}
	
	TTF_SizeText(font[size], text, w, h);
}
开发者ID:nnesse,项目名称:tbftss,代码行数:9,代码来源:text.c

示例5: TTF_SizeText

int Renderer::getFontSize()
{
	if(sFontSize == 0)
	{
		TTF_SizeText(sFont, "TEST", NULL, &sFontSize);
	}

	return sFontSize;
}
开发者ID:Aloshi,项目名称:ES-config,代码行数:9,代码来源:Renderer.cpp

示例6: hauteur_texte

int hauteur_texte(char *texte, int taille)
	{
	int w,h;
	POINT p;
	p.x = -10; p.y = -10;
	aff_pol("",taille,p,black); // Appel de aff_pol pour fixer la valeur de ___pol
	TTF_SizeText(___pol,texte,&w,&h);
	return h;
	}
开发者ID:Protosspaspris,项目名称:IN301,代码行数:9,代码来源:graphics.c

示例7: while

void * TextInputBox::changeState(int x, int y, int click, void * package){
  currentState = Interactive::clickDown;
  int height;
  int width;
  if(package != NULL){
    SDL_Event * input = static_cast<SDL_Event*>(package);
    if(input->type == SDL_KEYDOWN){
      char nextLetter = input->key.keysym.unicode;
      if(nextLetter == 8){
	full = false;
	//case 1: we're just in a line and no newline before us
	//case 2: we're at the beginning of a line and the previous line is full
	//case 3: we're at the beginning of a line and the previous line is not full
	if(currentLine <= maxChars){
	  if(text->getText()[text->getText().length() - 1] == '\n')
	    text->setText(text->getText().substr(0, text->getText().length() - 1));
	  text->setText(text->getText().substr(0, text->getText().length() - 1));
	  int i = text->getText().length() - 1;
	  currentLine = 0;
	  while(text->getText()[i] != '\n' && i >= 0){
	    currentLine++;
	    i--;
	  }
	}
      }
      else if(nextLetter == '.' || nextLetter == ' '
	      || nextLetter == '?' || nextLetter == '!'
	      || nextLetter == ',' || nextLetter == '\''
	      || (nextLetter >= '0' && nextLetter <= '9')
	      || (nextLetter >= 'a' && nextLetter <= 'z')
	      || (nextLetter >= 'A' && nextLetter <= 'Z')){
	TTF_SizeText(text->font, (text->getText() + nextLetter).c_str(), &width, &height);
	if(maxChars == 999999){
	  if(width > box->position.w)
	    maxChars = text->getText().length() - 2;
	}
	if(currentLine < maxChars && !full){
	  currentLine++;
	  text->setText(text->getText() + nextLetter);
	}
	else{
	  if((text->getLines() + 1) * (height + 1) > box->position.h)
	    full = true;
	  if(!full){
	    currentLine = 0;
	    text->setText(text->getText() + '\n' + nextLetter);
	  }
	}
      }
      else if(input->key.keysym.sym == SDLK_RETURN){
	currentLine = 0;
	text->setText(text->getText() + '\n');
      }
    }
  }
  return NULL;
}
开发者ID:BastionFennell,项目名称:BWI-GUI,代码行数:57,代码来源:TextInputBox.cpp

示例8: text_height

int GW_PlatformSDL::text_height(const string &text)
{
#ifndef GW_NO_SDL_TTF
    int s;
    if (TTF_SizeText(font_, text.c_str(), NULL, &s) == 0)
        return s;
#endif
    return -1;
}
开发者ID:zskulcsar,项目名称:gamewatch,代码行数:9,代码来源:plat_sdl.cpp

示例9: TTF_SizeText

Label::Label(int x, int y, Clamp clamp, std::string text) {
    this->text = text;
    loc.x = x;
    loc.y = y;
    int w, h;
    TTF_SizeText(RenderEngine::getFont(), text.c_str(), &w, &h);
    size.x = w;
    size.y = h;
    this->clamp = clamp;
}
开发者ID:TheArni,项目名称:SGI-Engine,代码行数:10,代码来源:Label.cpp

示例10: TTF_SizeText

void DatapathGElementOutput::compute(const int x, const int y,const int xoffset_, const int yoffset_,TTF_Font *font){
	int text_w,text_h;
	TTF_SizeText(font,name,&text_w, &text_h);
	pos.p.x = x;
	pos.p.y = y;
	pos.textp.x = x - (text_w/2);
	pos.textp.y=  y - (text_h);
	yoffset = yoffset_;
	xoffset = xoffset_;
}
开发者ID:JinxinS,项目名称:xml2graph,代码行数:10,代码来源:DatapathGElementOutput.cpp

示例11: x

ScrollPane<T>::ScrollPane(int x, int y, int width, int height, const std::vector<T> &e, const TextParams *font)
	: x(x), y(y), width(width), height(height), scrollPos(0), font(font)
{
	selection = -1;
	TTF_SizeText(font->font, "Test", NULL, &lineHeight);
	lines = height/lineHeight;
	setElements(e);
	lastClickTime = 0;
	lastClickIndex = -1;
}
开发者ID:yixu34,项目名称:RefuseRobots,代码行数:10,代码来源:scrollpane.hpp

示例12: TTF_SizeUTF8

void TFont_ttf::dimensions(const char *s,int *w, int *h) {
  if (ttf) {
      if (is_utf)
	  TTF_SizeUTF8(ttf,s,w,h);
      else
	  TTF_SizeText(ttf,s,w,h);
  } else {
    TFont::dimensions(s,w,h);
  }
}
开发者ID:albinoz,项目名称:raine,代码行数:10,代码来源:tfont.cpp

示例13: fgui_char_width

int fgui_char_width(const int c)
{
  int x, y;
  if (c <= 0)
    ctest[0] = 0;
  else
    ctest[0] = 'M';
  TTF_SizeText(font, ctest, &x, &y);
  return x;
}
开发者ID:deeice,项目名称:fgui,代码行数:10,代码来源:fgui_font.c

示例14: TTF_SizeText

TextSize SDLFont::calculateTextSize(stringType text) {
    TextSize textSize;
    int w, h;
    int error = TTF_SizeText(this->fontContext, text.c_str(),
			     &w, &h);
    textSize.w = w;
    textSize.h = h;

    return textSize;
}
开发者ID:benzap,项目名称:Kampf,代码行数:10,代码来源:SDLFont.cpp

示例15: while

int Chat::CalculateAmount(const std::string& str, int pos)
{
    int copy_size = std::min(str.size() - pos, MAX_LINE_SIZE);
    for (int i = 0; i < copy_size; ++i)
        text_[i] = str[pos + i];

    text_[copy_size] = '\0';
    int w;
    if (int err = TTF_SizeText(deja_, text_, &w, nullptr))
        std::cout << "Some ttf error " << err << std::endl;
    while (w > (to_x_ - from_x_ - SCROLL_SIZE))
    {
        --copy_size;
        text_[copy_size] = '\0';
        if (int err = TTF_SizeText(deja_, text_, &w, nullptr))
            std::cout << "Some ttf error " << err << std::endl;
    }
    return copy_size;
}
开发者ID:Disasm,项目名称:karya-valya,代码行数:19,代码来源:Chat.cpp


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