void AddHelpText(sf::RenderWindow &App, sf::Font &f, GroupManager &gm) { sf::View v = App.GetView(); sf::Vector2f center = v.GetCenter(), half = v.GetHalfSize(); string s; s = "Operations available:\n"; s += "Move: Left, Right, Up, Down\n"; s += "Speed: s (decrease), d (increase)\n"; s += "Step size: w (decrease), e (increase)\n"; s += "Zoom: z (in), x (out)\n"; s += "Steps mode: a (switch between modes)\n"; s += "Quit: Esc\n"; sf::String text(s, f, 12); text.SetColor(sf::Color(128, 200, 40)); text.Move(center.x - half.x + half.x/20, center.y - half.y + half.y/20); App.Draw(text); ostringstream step_per_second_str; step_per_second_str << "~" << step_per_second << "\n"; ostringstream step_time_str; step_time_str << "~" << step_time << "\n"; ostringstream framerate_str; framerate_str << 1.0/App.GetFrameTime() << "\n"; ostringstream step_size_str; step_size_str << gm.GetStepSize() << "\n"; s = "Steps per second: "; s += step_per_second_str.str() ; s += "Step time: "; s += step_time_str.str(); s += "Framerate: "; s += framerate_str.str(); s += "Step size: "; s += step_size_str.str(); s += "Steps mode: "; switch (step_mode) { case SM_HARD_STEPS_CNT: s += "SM_HARD_STEPS_CNT\n"; break; case SM_FREE_STEPS_CNT: s += "SM_FREE_STEPS_CNT\n"; break; default: break; } sf::String inf(s.c_str(), f, 20); inf.SetColor(sf::Color(230, 200, 180)); inf.Move(center.x - half.x + half.x/20, center.y + half.y - half.y/2); App.Draw(inf); }
void ProcessAppEvents(sf::RenderWindow &App, sf::View &v, GroupManager &gm) { sf::Event Event; while (App.GetEvent(Event)) { switch (Event.Type) { case sf::Event::Closed: App.Close(); break; case sf::Event::KeyPressed: { switch (Event.Key.Code) { case sf::Key::Escape: App.Close(); break; case sf::Key::Right: case sf::Key::Left: case sf::Key::Up: case sf::Key::Down: { const int step = 5; v = App.GetView(); int hor = 0, ver = 0; if (Event.Key.Code == sf::Key::Left) hor+=step; if (Event.Key.Code == sf::Key::Right) hor-=step; if (Event.Key.Code == sf::Key::Up) ver+=step; if (Event.Key.Code == sf::Key::Down) ver-=step; v.Move(hor, ver); App.SetView(v); break; } case sf::Key::S: case sf::Key::D: { //if (Event.Key.Code == sf::Key::S) // wanna_step_per_second-= wanna_step_per_second/10 - 1; //if (Event.Key.Code == sf::Key::D) // wanna_step_per_second+= wanna_step_per_second/10 + 1; //if (wanna_step_per_second <= 0) // step_per_second = 1; //if (wanna_step_per_second >= 250) // step_per_second = 250; //step_time = 1.0/wanna_step_per_second; break; } case sf::Key::W: case sf::Key::E: { if (Event.Key.Code == sf::Key::E) gm.SetStepSize(gm.GetStepSize() + 0.005); if (Event.Key.Code == sf::Key::W) gm.SetStepSize(gm.GetStepSize() - 0.005); break; } case sf::Key::Z: case sf::Key::X: { if (Event.Key.Code == sf::Key::Z) v.Zoom(1.01); if (Event.Key.Code == sf::Key::X) v.Zoom(1.0/1.01); break; } case sf::Key::A: { step_mode = (STEP_MODE) ((int)SM_HARD_STEPS_CNT + (int)SM_FREE_STEPS_CNT - step_mode); break; } default: break; } break; } case sf::Event::Resized: { int h = Event.Size.Height; int w = Event.Size.Width; v.SetHalfSize(w/2, h/2); break; } default: break; } } }