Création du menu et de AnimatedMain
This commit is contained in:
parent
c20c5e3ac2
commit
1c0ed7daad
BIN
Code/data/font/arial.ttf
Normal file
BIN
Code/data/font/arial.ttf
Normal file
Binary file not shown.
26
Code/include/Animation/Menu.hpp
Normal file
26
Code/include/Animation/Menu.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef MENU_HPP
|
||||||
|
#define MENU_HPP
|
||||||
|
|
||||||
|
#include <SFML/Window.hpp>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
class Menu : public sf::Drawable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Menu(unsigned int nbPatellas = 3, std::string const& path = "data/font/arial.ttf", float rotationSpped = 1.0f, unsigned int fontSize = 20);
|
||||||
|
|
||||||
|
bool manageEvent(sf::Event const& event);
|
||||||
|
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||||
|
|
||||||
|
std::vector<std::vector<sf::Text>> textsMenu;
|
||||||
|
unsigned int patellaIndex;
|
||||||
|
unsigned int nbPatellas;
|
||||||
|
unsigned int angleIndex;
|
||||||
|
|
||||||
|
std::vector<std::vector<float>> angles;
|
||||||
|
float rotationSpeed;
|
||||||
|
sf::Font font;
|
||||||
|
unsigned int fontSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MENU_HPP
|
@ -14,6 +14,7 @@
|
|||||||
#include "Geometry/Point.hpp"
|
#include "Geometry/Point.hpp"
|
||||||
#include "Spline/Skeleton3D.hpp"
|
#include "Spline/Skeleton3D.hpp"
|
||||||
#include "Animation/AnimatedMesh.hpp"
|
#include "Animation/AnimatedMesh.hpp"
|
||||||
|
#include "Animation/Menu.hpp"
|
||||||
|
|
||||||
// Full hd : 1920x1080
|
// Full hd : 1920x1080
|
||||||
constexpr auto WIDTH = 1920;
|
constexpr auto WIDTH = 1920;
|
||||||
@ -46,6 +47,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
auto mesh = pae::AnimatedMesh{skeleton};
|
auto mesh = pae::AnimatedMesh{skeleton};
|
||||||
|
|
||||||
|
auto menu = Menu{};
|
||||||
|
|
||||||
// Création de la fenêtre
|
// Création de la fenêtre
|
||||||
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT),
|
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT),
|
||||||
"pae",
|
"pae",
|
||||||
@ -78,18 +81,21 @@ int main(int argc, char *argv[])
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
auto camera = sft::FreeFlyCamera{};
|
auto camera = sft::FreeFlyCamera{};
|
||||||
|
|
||||||
// la boucle principale
|
// la boucle principale
|
||||||
auto running = true;
|
auto running = true;
|
||||||
auto captureRequired = false;
|
auto captureRequired = false;
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
// gestion des évènements
|
// gestion des évènements
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
{
|
{
|
||||||
|
menu.manageEvent(event);
|
||||||
|
|
||||||
if (event.type == sf::Event::Closed)
|
if (event.type == sf::Event::Closed)
|
||||||
{
|
{
|
||||||
// on stoppe le programme
|
// on stoppe le programme
|
||||||
@ -131,6 +137,9 @@ int main(int argc, char *argv[])
|
|||||||
captureRequired = false;
|
captureRequired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the texts
|
||||||
|
window.draw(menu);
|
||||||
|
|
||||||
// termine la trame courante (en interne, échange les deux tampons de rendu)
|
// termine la trame courante (en interne, échange les deux tampons de rendu)
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
add_executable(AnimatedMain AnimatedMain.cpp AnimatedMesh.cpp ../Spline/Click.cpp)
|
add_executable(AnimatedMain AnimatedMain.cpp AnimatedMesh.cpp ../Spline/Click.cpp Menu.cpp)
|
||||||
target_link_libraries(AnimatedMain Geometry SFMLTools ${SFML_LIBRARIES} ${OPENGL_LIBRARIES})
|
target_link_libraries(AnimatedMain Geometry SFMLTools ${SFML_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||||
|
131
Code/src/Animation/Menu.cpp
Normal file
131
Code/src/Animation/Menu.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include <Animation/Menu.hpp>
|
||||||
|
|
||||||
|
Menu::Menu(unsigned int nbPatellas, std::string const& path, float rotationSpeed, unsigned int fontSize) :
|
||||||
|
textsMenu{},
|
||||||
|
patellaIndex{0},
|
||||||
|
nbPatellas{nbPatellas},
|
||||||
|
angleIndex{0},
|
||||||
|
rotationSpeed{rotationSpeed},
|
||||||
|
fontSize{fontSize}
|
||||||
|
|
||||||
|
{
|
||||||
|
if (!font.loadFromFile(path))
|
||||||
|
std::cerr << "Error when loading the font" << std::endl;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < nbPatellas; i++)
|
||||||
|
{
|
||||||
|
angles.push_back({});
|
||||||
|
|
||||||
|
for (unsigned int j = 0; j < 3; j++)
|
||||||
|
angles[i].push_back(0.0f);
|
||||||
|
|
||||||
|
textsMenu.push_back({});
|
||||||
|
textsMenu[i].push_back(sf::Text{std::to_string(i+1)+")", font, 20});
|
||||||
|
textsMenu[i][0].setPosition(fontSize, (fontSize+10)*(1+i));
|
||||||
|
textsMenu[i].push_back(sf::Text{L"θ =", font, 20});
|
||||||
|
textsMenu[i][1].setPosition(fontSize*3, (fontSize+10)*(1+i));
|
||||||
|
textsMenu[i].push_back(sf::Text{boost::lexical_cast<std::string>(angles[i][0]), font, 20});
|
||||||
|
textsMenu[i][2].setPosition(fontSize*5, (fontSize+10)*(1+i));
|
||||||
|
textsMenu[i].push_back(sf::Text{L"φ =", font, 20});
|
||||||
|
textsMenu[i][3].setPosition(fontSize*7, (fontSize+10)*(1+i));
|
||||||
|
textsMenu[i].push_back(sf::Text{boost::lexical_cast<std::string>(angles[i][1]), font, 20});
|
||||||
|
textsMenu[i][4].setPosition(fontSize*9, (fontSize+10)*(1+i));
|
||||||
|
textsMenu[i].push_back(sf::Text{L"ψ =", font, 20});
|
||||||
|
textsMenu[i][5].setPosition(fontSize*11, (fontSize+10)*(1+i));
|
||||||
|
textsMenu[i].push_back(sf::Text{boost::lexical_cast<std::string>(angles[i][2]), font, 20});
|
||||||
|
textsMenu[i][6].setPosition(fontSize*13, (fontSize+10)*(1+i));
|
||||||
|
angles.push_back({});
|
||||||
|
|
||||||
|
for (unsigned int k = 0; k < 7; k++)
|
||||||
|
textsMenu[i][k].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
|
||||||
|
textsMenu[0][0].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[0][1].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[0][2].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Menu::manageEvent(sf::Event const& event)
|
||||||
|
{
|
||||||
|
if (event.type == sf::Event::KeyPressed)
|
||||||
|
{
|
||||||
|
switch (event.key.code)
|
||||||
|
{
|
||||||
|
case sf::Keyboard::Right:
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
angleIndex = (angleIndex+1)%3;
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sf::Keyboard::Up:
|
||||||
|
textsMenu[patellaIndex][0].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
patellaIndex = (patellaIndex+nbPatellas-1)%nbPatellas;
|
||||||
|
textsMenu[patellaIndex][0].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sf::Keyboard::Left:
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
angleIndex = (angleIndex+2)%3;
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sf::Keyboard::Down:
|
||||||
|
textsMenu[patellaIndex][0].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
patellaIndex = (patellaIndex+1)%nbPatellas;
|
||||||
|
textsMenu[patellaIndex][0].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[patellaIndex][1+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sf::Keyboard::Add:
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
angles[patellaIndex][angleIndex] = std::fmod((angles[patellaIndex][angleIndex]+rotationSpeed),360);
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setString(boost::lexical_cast<std::string>(angles[patellaIndex][angleIndex]));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sf::Keyboard::Subtract:
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(50, 50, 50, 170));
|
||||||
|
angles[patellaIndex][angleIndex] = std::fmod((angles[patellaIndex][angleIndex]+360-rotationSpeed),360);
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setString(boost::lexical_cast<std::string>(angles[patellaIndex][angleIndex]));
|
||||||
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
|
{
|
||||||
|
target.pushGLStates();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < textsMenu.size(); i++)
|
||||||
|
{
|
||||||
|
for (unsigned int j = 0; j < textsMenu[i].size(); j++)
|
||||||
|
{
|
||||||
|
target.draw(textsMenu[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.popGLStates();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user