font.cpp

来自「SDL_Draw chinese test」· C++ 代码 · 共 62 行

CPP
62
字号
#include "font.h"

SDL_Surface* myTTF_RenderString_Blended(TTF_Font* font, const std::string& str, SDL_Color fg)
{
	SDL_Surface* textbuf;
	//Get Unicode
	std::vector<Uint16> unicodeUnit = getUnicode(str);
	int arraySize = unicodeUnit.size();
	Uint16* perOne = new Uint16[arraySize+1];
	for ( int i = 0; i < arraySize; i++ )
		perOne[i] = unicodeUnit[i];
	perOne[arraySize] = 0;

	
	//Render the new text
	textbuf = TTF_RenderUNICODE_Blended(font, perOne, fg);

	//Free the text buffer and return
	delete [] perOne;
	return textbuf;
}

SDL_Surface* myTTF_RenderString_Solid(TTF_Font* font, const std::string& str, SDL_Color fg)
{
	SDL_Surface* textbuf;
	//Get Unicode
	std::vector<Uint16> unicodeUnit = getUnicode(str);
	int arraySize = unicodeUnit.size();
	Uint16* perOne = new Uint16[arraySize+1];
	for ( int i = 0; i < arraySize; i++ )
		perOne[i] = unicodeUnit[i];
	perOne[arraySize] = 0;

	
	//Render the new text
	textbuf = TTF_RenderUNICODE_Solid(font, perOne, fg);

	//Free the text buffer and return
	delete [] perOne;
	return textbuf;
}

SDL_Surface* myTTF_RenderString_Shaded(TTF_Font* font, const std::string& str, SDL_Color fg, SDL_Color bg)
{
	SDL_Surface* textbuf;
	//Get Unicode
	std::vector<Uint16> unicodeUnit = getUnicode(str);
	int arraySize = unicodeUnit.size();
	Uint16* perOne = new Uint16[arraySize+1];
	for ( int i = 0; i < arraySize; i++ )
		perOne[i] = unicodeUnit[i];
	perOne[arraySize] = 0;

	
	//Render the new text
	textbuf = TTF_RenderUNICODE_Shaded(font, perOne, fg, bg);

	//Free the text buffer and return
	delete [] perOne;
	return textbuf;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?