1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
| #define SUIVI
#include <SFML/Graphics.hpp>
#include <windows.h>
#include <string.h>
#include <cstdlib>
#ifdef SUIVI
#include <iostream>
#endif
#include "MenuColonneCentree.h"
using namespace std;
using namespace sf;
// Implémentation des méthodes de la classe
MenuColonneCentree::MenuColonneCentree(RenderWindow & argWINDOW):
window(argWINDOW) // Liste d'initialisation
{ Font fonte; // Fonte pour le texte des menus
fonte.loadFromFile("Fontes/FonteGVSC.ttf"); // Chargement d'un fichier font
Color couleur; // Couleur pour le texte des menus
couleur.r=255; couleur.g=100; couleur.b=0; couleur.a=255; // Création d'une couleur (rouge-orangé opaque)
width=VideoMode::getDesktopMode().width; // Récupérer résolution horizontale de l'écran
height=VideoMode::getDesktopMode().height; // Récupérer résolution verticale de l'écran
hauteurTextePrincipal=height/13;
hauteurTexteSecondaire=2*height/39;
// Présélection par-défaut de l'animation zéro
animation=4;
etape=0;
#ifdef SUIVI
cout << "MenuColonneCentree, MenuColonneCentree OK" << endl;
#endif
}
void MenuColonneCentree::SetContenu(vector<vector<string> > argCONTENU)
{
#ifdef SUIVI
cout << "MenuColonneCentree, SetContenu lance" << endl;
#endif
options=(argCONTENU.size());
// Redimensionner les vecteurs
texte.resize(options);
posX.resize(options);
posY.resize(options);
for (int index(0); index < options; index++)
{ texte[index].resize(2);
posX[index].resize(2);
posY[index].resize(2);
}
ligneSelectionnee=0; // Présélection de la première ligne
for (int index(0); index < options; index++)
{ texte[index][0].setString(argCONTENU[index][0]);
texte[index][1].setString(argCONTENU[index][1]);
texte[index][0].setFont(fonte);
texte[index][1].setFont(fonte);
texte[index][0].setColor(couleur);
texte[index][1].setColor(couleur);
texte[index][0].setStyle(0);
texte[index][1].setStyle(0);
posX[index][0]=width/2;
posX[index][1]=2*width/3;
posY[index][0]=(7-options+2*index)*hauteurTextePrincipal;
posY[index][1]=(8-options+2*index)*hauteurTextePrincipal;
}
etatExistence=true;
#ifdef SUIVI
cout << "MenuColonneCentree, SetContenu OK" << endl;
#endif
}
void MenuColonneCentree::ChoixAnimation(int argNUMERO)
{ animation=argNUMERO;
switch (animation)
{ case 0: // Animation standard
etatAnimation=true;
longueurAnimation=15;
break;
case 1: // Entrée en glissant pas la droite
etatAnimation=false;
longueurAnimation=15;
break;
case 2: // Sortie en glissant pas la gauche
etatAnimation=false;
longueurAnimation=15;
break;
case 3: // Sortie en glissant pas la droite
etatAnimation=false;
longueurAnimation=15;
break;
case 4: // Animation zéro (ne rien faire)
etatAnimation=true;
break;
}
for (int index(0); index < options; index++)
{ texte[index][0].setCharacterSize(hauteurTextePrincipal);
texte[index][0].setOrigin(texte[index][0].getGlobalBounds().width/2, hauteurTextePrincipal/2);
texte[index][1].setCharacterSize(hauteurTexteSecondaire);
texte[index][1].setOrigin(texte[index][1].getGlobalBounds().width/2, hauteurTextePrincipal/2);
texte[index][0].setPosition(posX[index][0], posY[index][0]);
texte[index][1].setPosition(posX[index][1], posY[index][1]);
}
etape=0; // Réinitialiser iTexte
#ifdef SUIVI
cout << "MenuColonneCentree, ChoixAnimation OK" << endl;
#endif
}
void MenuColonneCentree::MouvementPreselection(int argMOUVEMENT)
{ // argMOUVEMENT : mouvement à effectuer (+ = descendre ; 0 = rester ; - = monter)
ligneSelectionnee+=argMOUVEMENT;
if (ligneSelectionnee > options) {ligneSelectionnee=0;}
else if (ligneSelectionnee < 0) {ligneSelectionnee=options;}
#ifdef SUIVI
cout << "MenuColonneCentree, MouvementPreselection OK" << endl;
#endif
}
void MenuColonneCentree::Animation(int argSTEP)
{ // argSTEP : nombre d'étapes à passer dans l'animation
etape+=argSTEP; // Incrémenter l'index d'animation
switch (animation)
{ case 0: // Animation standard de la ligne sélectionnée
if (etape >= longueurAnimation-1) {etape-=longueurAnimation;} // Ne pas dépasser longueurAnimation-1
j=1+DecoupageQuadratiqueMiroir(etape, longueurAnimation); // Prendre le facteur
texte[ligneSelectionnee][0].setCharacterSize(j*hauteurTextePrincipal);
texte[ligneSelectionnee][1].setCharacterSize(j*hauteurTexteSecondaire);
texte[ligneSelectionnee][0].setOrigin(texte[ligneSelectionnee][0].getGlobalBounds().width/2, j*hauteurTextePrincipal/2);
texte[ligneSelectionnee][1].setOrigin(texte[ligneSelectionnee][1].getGlobalBounds().width/2, j*hauteurTexteSecondaire/2);
for (int index(0); index < options; index++)
{ window.draw(texte[index][0]);
window.draw(texte[index][1]);
}
break;
case 1: // Entrée en glissant par la droite
if (etape >= longueurAnimation-1) // Ne pas dépasser longueurAnimation-1
{ etape=longueurAnimation-1;
etatAnimation=true;
}
X=width*DecoupageQuadratiqueMiroir(etape, longueurAnimation); // Prendre le facteur
for (int index(0); index < options; index++)
{ texte[index][0].setPosition(posX[index][0]+X, posY[index][0]);
texte[index][1].setPosition(posX[index][1]+X, posY[index][1]);
window.draw(texte[index][0]);
window.draw(texte[index][1]);
}
break;
case 2: // Sortie en glissant par la gauche
if (etape >= longueurAnimation-1) // Ne pas dépasser longueurAnimation-1
{ etape=longueurAnimation-1;
etatAnimation=true;
etatExistence=false;
}
X=width*DecoupageQuadratiqueMiroir(longueurAnimation-1-etape, longueurAnimation); // Prendre le facteur
for (int index(0); index < options; index++)
{ texte[index][0].setPosition(posX[index][0]+X, posY[index][0]);
texte[index][1].setPosition(posX[index][1]+X, posY[index][1]);
window.draw(texte[index][0]);
window.draw(texte[index][1]);
}
break;
case 3: // Sortie en glissant par la droite
if (etape >= longueurAnimation-1) // Ne pas dépasser longueurAnimation-1
{ etape=longueurAnimation-1;
etatAnimation=true;
etatExistence=false;
}
X=-width*DecoupageQuadratiqueMiroir(longueurAnimation-1-etape, longueurAnimation); // Prendre le facteur
for (int index(0); index < options; index++)
{ texte[index][0].setPosition(posX[index][0]+X, posY[index][0]);
texte[index][1].setPosition(posX[index][1]+X, posY[index][1]);
window.draw(texte[index][0]);
window.draw(texte[index][1]);
}
break;
case 4: // Animation zéro (ne rien faire)
for (int index(0); index < options; index++)
{ window.draw(texte[index][0]);
window.draw(texte[index][1]);
}
break;
}
} |
Partager