Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/Audio.hpp>
  3.  
  4. #define LARGEUR_FENETRE_MENUUN 1360
  5. #define HAUTEUR_FENETRE_MENUUN 800
  6.  
  7. using namespace sf;
  8.  
  9. typedef struct
  10. {
  11. int x, y ;
  12. } Point ;
  13. typedef struct
  14. {
  15. int l, h ;
  16. } Size ;
  17. typedef struct
  18. {
  19. int r, g, b ;
  20. } CodeRGB ;
  21. typedef struct
  22. {
  23. char name[20] ;
  24. Size t /* t = taille */;
  25. Point p /* p = position */;
  26. CodeRGB couleur ;
  27. } Button ;
  28.  
  29. void DrawButton ( RenderWindow * fenetre, Button b[], int nbBouton ) ;
  30. void Drawfenetre( RenderWindow * fenetre) ;
  31. void ChoixLevel();
  32. void hoverButton(Event * evenement, Button b[4]);
  33. void colorButton ( Button * b, CodeRGB c);
  34.  
  35. int main()
  36. {
  37. int i, nbBouton = 4, sdf;
  38. RenderWindow fenetre (VideoMode(LARGEUR_FENETRE_MENUUN, HAUTEUR_FENETRE_MENUUN), "SFML window");
  39.  
  40. /*Création des boutons du menu*/
  41. Button menu[nbBouton] ;
  42. sprintf( menu[0].name, "LEVELS" ) ;
  43. sprintf( menu[1].name, "SETTINGS" ) ;
  44. sprintf( menu[2].name, "CREDITS" ) ;
  45. sprintf( menu[3].name, "EXIT" ) ;
  46. for ( i=0 ; i<nbBouton ; i++)
  47. {
  48. menu[i].couleur.r = 150 ;
  49. menu[i].couleur.g = 150 ;
  50. menu[i].couleur.b = 150 ;
  51. menu[i].p.x = LARGEUR_FENETRE_MENUUN/2 ;
  52. menu[i].p.y = HAUTEUR_FENETRE_MENUUN/3 + 150 * (i-1) ;
  53. menu[i].t.l = 300 ;
  54. menu[i].t.h = 100 ;
  55. }
  56.  
  57. while (fenetre.isOpen())
  58. {
  59. Event evenement;
  60. while (fenetre.pollEvent(evenement))
  61. {
  62. switch (evenement.type)
  63. {
  64. case Event::Closed :
  65. fenetre.close();
  66. break;
  67. case Event::MouseMoved :
  68. hoverButton(&evenement, menu);
  69. break;
  70. case Event::MouseButtonPressed:
  71.  
  72. break;
  73. }
  74.  
  75. }
  76.  
  77. fenetre.clear();
  78. Drawfenetre(&fenetre);
  79. DrawButton(&fenetre, menu, nbBouton);
  80. fenetre.display();
  81.  
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88. return 0;
  89. }
  90.  
  91.  
  92. void DrawButton ( RenderWindow * fenetre, Button b[], int nbBouton )
  93. {
  94. int i ;
  95. Font font;
  96. font.loadFromFile("arial.ttf");
  97.  
  98. for ( i=0 ; i<nbBouton ; i++ )
  99. {
  100. RectangleShape buton ( Vector2f ( b[i].t.l, b[i].t.h ) ) ;
  101. buton.setFillColor ( Color ( b[i].couleur.r, b[i].couleur.g, b[i].couleur.b ) ) ;
  102. buton.setOrigin ( (b[i].t.l)/2, (b[i].t.h)/2 ) ;
  103. buton.setPosition ( (b[i].p.x), (b[i].p.y) ) ;
  104. Text text;
  105. text.setFont(font);
  106. text.setString(b[i].name);
  107. text.setColor(Color::Red);
  108. text.setOrigin(( text.getGlobalBounds().width)/2, (text.getGlobalBounds().height) );
  109. text.setPosition( (b[i].p.x), (b[i].p.y) );
  110. fenetre->draw(buton) ;
  111. fenetre->draw(text);
  112. }
  113. }
  114.  
  115. void Drawfenetre( RenderWindow * fenetre)
  116. {
  117. Texture texture;
  118. texture.loadFromFile("Fond-menu-1.png");
  119. Sprite sprite(texture);
  120. fenetre->draw(sprite);
  121. }
  122. void ChoixLevel()
  123. {
  124. RenderWindow level (VideoMode(LARGEUR_FENETRE_MENUUN, HAUTEUR_FENETRE_MENUUN), "Choix de niveaux");
  125. Texture fond1;
  126. fond1.loadFromFile("Fond-menu-1.png");
  127. Sprite fond;
  128. fond.setTexture(fond1);
  129. level.draw(fond);
  130. level.display();
  131. }
  132. void hoverButton(Event * evenement, Button b[4])
  133. {
  134. int i, res=0;
  135. for (i=0 ; i<4 ; i++)
  136. {
  137. if ( evenement->mouseMove.x >= (b[i].p.x-(b[i].t.l/2)) && evenement->mouseMove.x <= (b[i].p.x + (b[i].t.l/2))
  138. && evenement->mouseMove.y >= (b[i].p.y-(b[i].t.h/2)) && evenement->mouseMove.y <= (b[i].p.y + (b[i].t.h/2)) )
  139. colorButton(&b[i], {0,0,255});
  140. else
  141. colorButton(&b[i], {150,150,150});
  142. }
  143. }
  144.  
  145. void colorButton ( Button * b, CodeRGB c)
  146. {
  147. b->couleur.r = c.r;
  148. b->couleur.g = c.g;
  149. b->couleur.b = c.b;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement