Sdl_ttf文本换行
Sdl_ttf Text Wrapping
当一串文本超过长度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;
A 认为错误出在TTF_SizeText(...)
调用上。它不知道您设置的边界,也可能忽略端点。尝试删除该行并放置这些:
int w, h;
w = surf->w;
h = surf->h;
我希望它有所帮助。
相关文章:
- 在 Stream C++ 文本之前有一个额外的换行符
- 正则表达式 获取两个换行符之间的文本
- 从文本文件中读取数据并删除所有换行符空格,并在 C++ 控制台中显示
- C++是否可以将带有换行符的文本传递给C++程序
- Sdl_ttf文本换行
- 读取整数对,直到文本输入文件中的换行符
- 正在读取由换行符分隔的文本文件.unix上的C++
- 如何在不添加换行符的情况下将文本附加到QPlainTextEdit,并保持滚动在底部
- 输出到文本文件时C++换行符
- C++交叉编译不处理换行输入文本文件
- QListWidget,插入换行符以获得较长的文本
- 检测富编辑文本控件中的换行符
- Cocos2d-x 中的文本换行
- 使用 getline 仅读取换行符或文本
- 如何在 XML 文本(在标记内)中搜索换行符
- 如何做一个换行的文本查找器
- 使用 WinAPI 使用可变字体/格式的文本自动换行块
- 使用 fopen 读取C++文本文件,无需换行转换
- 为什么 fstream::tellg() 返回值会因输入文本文件中的换行符数而增大,当文件针对 Windows (r
- 如何在写入文本文件时向一行添加换行符