【问题标题】:Sdl_ttf Text Wrappingsdl_ttf 文本换行
【发布时间】:2014-04-12 02:58:13
【问题描述】:

当一串文本过去时说,300 的长度,我希望它掉到一个新行并继续。我读到这就是你的做法,但它不起作用 - 它只是延长了文本。

如何做到这一点?

const char* message = "example text to test that it drops to a new line."; 
std::string fontFile = "Font/font.ttf";
int fontSize = 16;

TTF_Font *font = nullptr;
    font = TTF_OpenFont(fontFile.c_str(), fontSize);

SDL_Color textColor = { 0, 300, 200 };
SDL_Surface *surf = TTF_RenderText_Blended_Wrapped(font, message, textColor, 300);
    texture = SDL_CreateTextureFromSurface(m_p_Renderer, surf);

int w,h;
TTF_SizeText(font,message,&w,&h);

srcRect.x = 0;
srcRect.y = 0;
destRect.x = 0;
destRect.y = 0;

srcRect.w =w;
srcRect.h = h;

destRect.w =w;
destRect.h = h;

【问题讨论】:

    标签: c++ newline sdl-2 sdl-ttf


    【解决方案1】:

    A 认为错误在于TTF_SizeText(...) 调用。它不知道您设置的边界,也可能忽略端线。尝试删除该行并将其改为:

    int w, h;
    w = surf->w;
    h = surf->h;
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 2011-02-19
      相关资源
      最近更新 更多