Guest User

Menu::loadFont()

a guest
Dec 19th, 2015
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. void Menu::show()
  2. {
  3.     sf::Text title(Data::gameTitle,font,Data::sizeOfTitleFontInMenu);
  4.     title.setStyle(sf::Text::Bold);
  5.     title.setPosition(Data::windowWidth/2-title.getGlobalBounds().width/2,Data::titleTopMarginInMenu);
  6.  
  7.     sf::Text option[Data::numberOfOptionsInMenu];
  8.  
  9.     for(int i=1; i<=Data::numberOfOptionsInMenu; i++)
  10.     {
  11.         option[i].setFont(font);
  12.         option[i].setCharacterSize(Data::sizeOfOptionsFontInMenu);
  13.         option[i].setString(Data::OptionsInMenuContent[i]);
  14.         option[i].setPosition(Data::windowWidth/2-title.getGlobalBounds().width/2,Data::optionTopMarginInMenu*i);
  15.     }
  16.  
  17.     while(info->state == Info::MENU)
  18.     {
  19.         sf::Vector2f mouse(sf::Mouse::getPosition());
  20.         sf::Event event;
  21.  
  22.         while(window->pollEvent(event))
  23.         {
  24.             if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape || event.type == sf::Event::Closed){
  25.                 window->close();
  26.             }
  27.  
  28.             if(option[0].getGlobalBounds().contains(mouse) && event.type == sf::Event::MouseButtonReleased && event.key.code == sf::Mouse::Left){
  29.                 info->state = Info::GAME;
  30.             }
  31.  
  32.             if(option[1].getGlobalBounds().contains(mouse) && event.type == sf::Event::MouseButtonReleased && event.key.code == sf::Mouse::Left){
  33.                 window->close();
  34.             }
  35.         }
  36.  
  37.         for(int i=0; i<Data::numberOfOptionsInMenu; i++)
  38.         {
  39.              if(option[i].getGlobalBounds().contains(mouse)){
  40.                 option[i].setColor(Data::colorOfCheckOptionInMenu);
  41.             }
  42.             else {
  43.                 option[i].setColor(Data::colorOfOptionInMenu);
  44.             }
  45.         }
  46.  
  47.         window->clear(Data::colorOfBackgroundInMenu);
  48.         window->draw(title);
  49.  
  50.         for(int i=0; i<Data::numberOfOptionsInMenu; i++)
  51.         {
  52.             window->draw(option[i]);
  53.         }
  54.  
  55.         window->display();
  56.     }
  57. }
Add Comment
Please, Sign In to add comment