本文整理汇总了C++中sf::String::toWideString方法的典型用法代码示例。如果您正苦于以下问题:C++ String::toWideString方法的具体用法?C++ String::toWideString怎么用?C++ String::toWideString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::String
的用法示例。
在下文中一共展示了String::toWideString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawText
void KText::drawText(sf::RenderWindow & window, int x, int y, sf::String str, sf::Color colour = sf::Color::Black)
{
sf::View view;
view.setSize(sf::Vector2f(SCREEN_WIDTH, SCREEN_HEIGHT));
view.setCenter(sf::Vector2f(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2));
window.setView(view);
int row = 0;
int col = 0;
int charWidth = FONT_SIZE;
for (int i = 0; i < str.toWideString().length(); i++)
{
bool draw = false;
wchar_t w = str[i];
sf::Sprite c;
charWidth = FONT_SIZE;
if (w != str.toWideString().size() - 1 && w == L'\\' && str[i + 1] == L'n') //If w is the enter key
{
//Go down a row and adjust all the way to the left side of the dialog box, also display the enter key with a width of zero
row++;
col = 0;
charWidth = 0;
i++;
continue;
}
else if (w != str.toWideString().size() - 1 && w == L'\\' && str[i + 1] == L't') //If w is the tab key
{
col += charWidth * 2;
i++;
continue;
}
else if ((32 <= w && w <= 126) || (161 <= w && w <= 255)) //basic latin
{
draw = true;
c = sf::Sprite(basic_latin, sf::IntRect((w % 16) * FONT_SIZE, ((w - (w % 16)) / 16) * FONT_SIZE, latinWidths[w], FONT_SIZE));
charWidth = latinWidths[w];
col += 4; //This is for space between each character, Japanese doesn't need this
}
else if (w == 8230) //...
{
draw = true;
//This character isn't actually in the Japanese section of unicode, but I decided to give a spot in the Japanese spritesheet
//because English users won't ever be typing in the single character form of the ellipses, also putting a character in a blank
//spot goes againsts the unicode policy, but hey, it keeps me from having to create a hundred new characters
c = sf::Sprite(japanese, sf::IntRect(0, 16 * FONT_SIZE, FONT_SIZE, FONT_SIZE));
}
else if (12288 <= w && w <= 12543) //1st japanese section of unicode stuff
{
draw = true;
c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 768) * FONT_SIZE, FONT_SIZE, FONT_SIZE));
}
else if (65281 <= w && w <= 65376) //2nd part of japanese stuff in unicode
{
draw = true;
c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 4064) * FONT_SIZE, FONT_SIZE, FONT_SIZE));
}
else if (65377 <= w && w <= 65439) //2nd part of japanese stuff in unicode, but halfwidth stuff
{
draw = true;
c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 4064) * FONT_SIZE, FONT_SIZE * .5, FONT_SIZE));
charWidth = .5 * FONT_SIZE;\
}
else if (65440 <= w && w <= 65519) //2nd part of japanese stuff in unicode, but back to full width characters
{
draw = true;
c = sf::Sprite(japanese, sf::IntRect((w % 16) * FONT_SIZE, (((w - (w % 16)) / 16) - 4064) * FONT_SIZE, FONT_SIZE, FONT_SIZE));
}
if (draw)
{
c.setPosition(sf::Vector2f(x + col, y + (row * FONT_SIZE)));
col += charWidth;
//Set the x value of the next character to += the width of the last character
}
c.setColor(colour);
window.draw(c);
}
}
示例2: load
int Game::load(sf::String path, SFG::SplashScreen* ss)
{
if(m_game_console.init() != 0)
SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__,
"Failed to init console"
);
if(!m_timing_font.loadFromFile("Fonts/arial.ttf"))
SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__,
"Failed to load font"
);
printf("Setting font... ");
m_timing_display.setFont(m_timing_font);
printf("Done.\n");
m_timing_display.setString("Asd");
XMLReader reader;
sf::String out;
if (basicLoadFile(path.toWideString(), out) != 0)
{
printf("[Error] Failed to load file %s in %s:%d\n", path.toAnsiString().c_str(), __FILE__, __LINE__);
return -1;
}
reader.setSource(out);
//Start parsing
if (reader.parse() != 0)
{
//Errors happening
}
//For now, we only need to load the gamestates up...
//Get the loading gamestate (with fancy animations and stuff)
int ret = 0;
auto sugs = SFG::Pointer<GameState>(new StartupGameState());
if ((ret = loadGamestate(reader, L"Startup", sugs)) < 0)
{
printf("[Error] Failed to load Startup Gamestate in %s:%d from file \"%s\" with Code %d.\n", __FILE__, __LINE__, path.toAnsiString().c_str(), ret);
}
//The first gamestate always needs to be inited
this->g_gamestates[0]->init(this->window);
//Get the menu gamestate
SFG::Pointer<GameState> menu(new MenuGameState());
if ((ret = loadGamestate(reader, L"Menu", menu)) < 0)
{
printf("[Error] Failed to load Menu Gamestate in %s:%d from file \"%s\" with Code %d.\n", __FILE__, __LINE__, path.toAnsiString().c_str(), ret);
}
//Get all other gamestates
for (size_t i = 2; ; i++)
{
sf::String path = L"xml/gamestate#" + std::to_wstring(i) + L"/";
sf::String ret = reader.getValue(path);
if (ret == L"__xml_failure")
{
break;
}
else
{
//#TODO: Add custom gamestate
//STILL_TO_DO(__FILE__, __LINE__);
int res = loadGamestate(reader, reader.getValue(path + "name."), SFG::Pointer<GameState>(nullptr));
if (res != 0)
{
std::string tmp = reader.getValue(path + "name.").toAnsiString();
SFG::Util::printLog(SFG::Util::LogMessageType::Error, __FILE__, __LINE__, "Failed to load custom gamestate named \"%s\"", tmp.c_str());
}
}
}
//Reading done
if (ss != nullptr)
{
//Tell the SplashScreen to disappear
ss->notify(SFG::SplashScreen::SplashScreenMessages::LoadingDone);
}
return 0;
}