Sometime crashes, sometimes blank text, and sometimes works.
I'm passing (I hope) a reference to TextDisplay::update() so It can draw all the text in keyBindMenu
which is a vector of std::strings. I'm not sure if I'm handling this correctly. My understanding of this is very weak, but I think I did it correctly (passing the ref)
int main(int argc, char** argv) {
bool displayMenu = false;
std::vector<std::string> keyBindMenu;
keyBindMenu.push_back("Escape toggle this menu");
keyBindMenu.push_back("W,A,S,D map view scroll");
keyBindMenu.push_back("Up,Down,Left,Right keys select tile");
keyBindMenu.push_back("+,- map zoom");
keyBindMenu.push_back("Left Mouse button to place tile");
sf::RenderWindow *pWindow;
sf::RenderWindow displayWindow(sf::VideoMode(DWIN_WIDTH, DWIN_HEIGHT),
"Map Editor");
TextDisplay mainMenu(100, 100, 600, keyBindMenu.size()*45, displayWindow.getSize());
....
case sf::Keyboard::Escape:
if (displayMenu) displayMenu = false;
else displayMenu = true;
break;
....
if (displayMenu) {
mainMenu.update(pWindow, keyBindMenu);
}
// ****** code from TextDisplay class
void TextDisplay::update(sf::RenderWindow *window, std::vector<std::string> &menuText) {
// display a rect area that text will display
window->draw(*pTextArea);
for (int i = 0; i <= menuText.size(); i++) {
text.setString(menuText[i]);
text.setPosition(sf::Vector2f(textBox.left + 40, (textBox.top + 7)+
(i * (font.getLineSpacing(MENU_TEXT_SIZE)))));
window->draw(text);
}
//std::cout << "updating menu" << std::endl;
}