169 lines
7.5 KiB
C++
169 lines
7.5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Paella
|
|
// Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX
|
|
// Authors :
|
|
// Thomas FORGIONE
|
|
// Emilie JALRAS
|
|
// Marion LENFANT
|
|
// Thierry MALON
|
|
// Amandine PAILLOUX
|
|
//
|
|
// This file is part of the project Paella
|
|
// This software is provided 'as-is', without any express or implied warranty.
|
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
//
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
// including commercial applications, and to alter it and redistribute it freely,
|
|
// subject to the following restrictions:
|
|
//
|
|
// 1. The origin of this software must not be misrepresented;
|
|
// you must not claim that you wrote the original software.
|
|
// If you use this software in a product, an acknowledgment
|
|
// in the product documentation would be appreciated but is not required.
|
|
//
|
|
// 2. Altered source versions must be plainly marked as such,
|
|
// and must not be misrepresented as being the original software.
|
|
//
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include <iostream>
|
|
#include <cmath>
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <Animation/Menu.hpp>
|
|
|
|
Menu::Menu(std::shared_ptr<pae::AnimatedMesh> const& mesh, unsigned int nbPatellas, std::string const& path, float rotationSpeed, unsigned int fontSize) :
|
|
mesh(mesh),
|
|
textsMenu{},
|
|
patellaIndex{0},
|
|
nbPatellas{static_cast<unsigned int>(mesh->rotations.size())},
|
|
angleIndex{0},
|
|
rotationSpeed{rotationSpeed},
|
|
fontSize{fontSize}
|
|
|
|
{
|
|
nbPatellas = mesh->rotations.size();
|
|
|
|
if (!font.loadFromFile(path))
|
|
std::cerr << "Error when loading the font" << std::endl;
|
|
|
|
for (unsigned int i = 0; i < nbPatellas; i++)
|
|
{
|
|
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>(
|
|
mesh->rotations.applyPath(mesh->paths[i]).node.theta
|
|
), 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>(
|
|
mesh->rotations.applyPath(mesh->paths[i]).node.phi
|
|
), 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>(
|
|
mesh->rotations.applyPath(mesh->paths[i]).node.psi
|
|
), font, 20});
|
|
|
|
textsMenu[i][6].setPosition(fontSize*13, (fontSize+10)*(1+i));
|
|
|
|
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));
|
|
}
|
|
|
|
}
|
|
|
|
void 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));
|
|
mesh->rotations.applyPath(mesh->paths[patellaIndex]).node[angleIndex] = std::fmod((mesh->rotations.applyPath(mesh->paths[patellaIndex]).node[angleIndex]+rotationSpeed),360);
|
|
textsMenu[patellaIndex][2+2*angleIndex].setString(boost::lexical_cast<std::string>(mesh->rotations.applyPath(mesh->paths[patellaIndex]).node[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));
|
|
mesh->rotations.applyPath(mesh->paths[patellaIndex]).node[angleIndex] = std::fmod((mesh->rotations.applyPath(mesh->paths[patellaIndex]).node[angleIndex]+360-rotationSpeed),360);
|
|
textsMenu[patellaIndex][2+2*angleIndex].setString(boost::lexical_cast<std::string>(mesh->rotations.applyPath(mesh->paths[patellaIndex]).node[angleIndex]));
|
|
textsMenu[patellaIndex][2+2*angleIndex].setColor(sf::Color(200, 200, 200, 170));
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|