Созданные ответы форума
Просмотр 4 сообщений - с 1 по 4 (из 4 всего)
-
АвторСообщения
-
Я удалил репозиторий и видео с youtube (на это есть свои причины). Если кому-то это нужно, напишите, что-нибудь придумаем.
Или если у кого-то остался исходник, киньте ссылку.
А не лучше ли использовать ini файл? Вот готовое решение.
Я проблему с русским текстом решил так:
Весь текст держу как wchar_t и всё норм.
C++12345678wchar_t* TextTitle = L"Русские буквы";// Из wchar_t* в sf:String переводится так:sf::String sfStr = sf::String(TextTitle);sf::Text text;text.setString(sf::String(TextTitle));// Для других случаев у меня есть StringHelper:std::string stdStr = StringHelper::WideStringToAnsi(TextTitle);text.setString(StringHelper::WideStringToAnsi(TextTitle) + " - v0.1");Сам StringHelper выглядит так:
C++123456789101112131415161718192021222324252627282930313233343536373839404142class StringHelper{public:static wchar_t* ToWCHAR(const char *c, UINT CodePage = CP_ACP){static wchar_t* result;int nChars = MultiByteToWideChar(CodePage, 0, c, -1, NULL, 0);result = new WCHAR[nChars];MultiByteToWideChar(CodePage, 0, c, -1, (LPWSTR)result, nChars);return result;}static const char* ToCHAR(wchar_t *c, UINT CodePage = CP_ACP){static char* result;int nChars = WideCharToMultiByte(CodePage, 0, c, -1, NULL, 0, NULL, NULL);result = new CHAR[nChars];WideCharToMultiByte(CodePage, 0, c, -1, (LPSTR)result, nChars, NULL, NULL);return result;}static std::wstring AnsiStringToWide(std::string const &Str, UINT CodePage = CP_ACP){DWORD const BuffSize = MultiByteToWideChar(CodePage, 0, Str.c_str(), -1, NULL, 0);if (!BuffSize) return NULL;std::vector<wchar_t> Buffer;Buffer.resize(BuffSize);if (!MultiByteToWideChar(CodePage, 0, Str.c_str(), -1, &Buffer[0], BuffSize)) return NULL;return (&Buffer[0]);}static std::string WideStringToAnsi(std::wstring const &Str, UINT CodePage = CP_ACP){DWORD const BuffSize = WideCharToMultiByte(CodePage, 0, Str.c_str(), -1, NULL, 0, NULL, NULL);if (!BuffSize) return NULL;std::vector<char> Buffer;Buffer.resize(BuffSize);if (!WideCharToMultiByte(CodePage, 0, Str.c_str(), -1, &Buffer[0], BuffSize, NULL, NULL)) return NULL;return (&Buffer[0]);}};08.01.2018 в 21:56 в ответ на: Трансформация изображения (а так же его адаптивность под разные разрешения) #4957Всем спасибо! Очень помогли.
Используя примеры, сделал так:
C++1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253int main(){sf::Texture backgroundTexture;if (!backgroundTexture.loadFromFile("Data/RedBackground.jpg")) // RedBackground.jpg 800x600return EXIT_FAILURE;sf::Sprite background(backgroundTexture);sf::RenderWindow window(sf::VideoMode(1024, 650), "Test Background Size", sf::Style::Close | sf::Style::Resize);window.setVerticalSyncEnabled(true);Vector2u size = backgroundTexture.getSize();float xsize = (static_cast<float>(window.getSize().x) / size.x);float ysize = (static_cast<float>(window.getSize().y) / size.y);float sScale;if (xsize > ysize){sScale = ysize;}else{sScale = xsize;}background.setScale(sScale, sScale);FloatRect fRect = background.getGlobalBounds();int px = (window.getSize().x - fRect.width) / 2;int py = (window.getSize().y - fRect.height) / 2;background.setPosition(px, py);while (window.isOpen()){sf::Event event;while (window.pollEvent(event)){if (event.type == sf::Event::Closed){window.close();}else if (event.type == sf::Event::Resized){// Тут ещё нужно подумать}}window.clear();window.draw(background);window.display();}return EXIT_SUCCESS;} -
АвторСообщения
Просмотр 4 сообщений - с 1 по 4 (из 4 всего)