Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #define LARGEUR_FENETRE_MENUUN 1360
- #define HAUTEUR_FENETRE_MENUUN 800
- using namespace sf;
- typedef struct
- {
- int x, y ;
- } Point ;
- typedef struct
- {
- int l, h ;
- } Size ;
- typedef struct
- {
- int r, g, b ;
- } CodeRGB ;
- typedef struct
- {
- char name[20] ;
- Size t /* t = taille */;
- Point p /* p = position */;
- CodeRGB couleur ;
- } Button ;
- void DrawButton ( RenderWindow * fenetre, Button b[], int nbBouton ) ;
- void Drawfenetre( RenderWindow * fenetre) ;
- void ChoixLevel();
- void hoverButton(Event * evenement, Button b[4]);
- void colorButton ( Button * b, CodeRGB c);
- int main()
- {
- int i, nbBouton = 4, sdf;
- RenderWindow fenetre (VideoMode(LARGEUR_FENETRE_MENUUN, HAUTEUR_FENETRE_MENUUN), "SFML window");
- /*Création des boutons du menu*/
- Button menu[nbBouton] ;
- sprintf( menu[0].name, "LEVELS" ) ;
- sprintf( menu[1].name, "SETTINGS" ) ;
- sprintf( menu[2].name, "CREDITS" ) ;
- sprintf( menu[3].name, "EXIT" ) ;
- for ( i=0 ; i<nbBouton ; i++)
- {
- menu[i].couleur.r = 150 ;
- menu[i].couleur.g = 150 ;
- menu[i].couleur.b = 150 ;
- menu[i].p.x = LARGEUR_FENETRE_MENUUN/2 ;
- menu[i].p.y = HAUTEUR_FENETRE_MENUUN/3 + 150 * (i-1) ;
- menu[i].t.l = 300 ;
- menu[i].t.h = 100 ;
- }
- while (fenetre.isOpen())
- {
- Event evenement;
- while (fenetre.pollEvent(evenement))
- {
- switch (evenement.type)
- {
- case Event::Closed :
- fenetre.close();
- break;
- case Event::MouseMoved :
- hoverButton(&evenement, menu);
- break;
- case Event::MouseButtonPressed:
- break;
- }
- }
- fenetre.clear();
- Drawfenetre(&fenetre);
- DrawButton(&fenetre, menu, nbBouton);
- fenetre.display();
- }
- return 0;
- }
- void DrawButton ( RenderWindow * fenetre, Button b[], int nbBouton )
- {
- int i ;
- Font font;
- font.loadFromFile("arial.ttf");
- for ( i=0 ; i<nbBouton ; i++ )
- {
- RectangleShape buton ( Vector2f ( b[i].t.l, b[i].t.h ) ) ;
- buton.setFillColor ( Color ( b[i].couleur.r, b[i].couleur.g, b[i].couleur.b ) ) ;
- buton.setOrigin ( (b[i].t.l)/2, (b[i].t.h)/2 ) ;
- buton.setPosition ( (b[i].p.x), (b[i].p.y) ) ;
- Text text;
- text.setFont(font);
- text.setString(b[i].name);
- text.setColor(Color::Red);
- text.setOrigin(( text.getGlobalBounds().width)/2, (text.getGlobalBounds().height) );
- text.setPosition( (b[i].p.x), (b[i].p.y) );
- fenetre->draw(buton) ;
- fenetre->draw(text);
- }
- }
- void Drawfenetre( RenderWindow * fenetre)
- {
- Texture texture;
- texture.loadFromFile("Fond-menu-1.png");
- Sprite sprite(texture);
- fenetre->draw(sprite);
- }
- void ChoixLevel()
- {
- RenderWindow level (VideoMode(LARGEUR_FENETRE_MENUUN, HAUTEUR_FENETRE_MENUUN), "Choix de niveaux");
- Texture fond1;
- fond1.loadFromFile("Fond-menu-1.png");
- Sprite fond;
- fond.setTexture(fond1);
- level.draw(fond);
- level.display();
- }
- void hoverButton(Event * evenement, Button b[4])
- {
- int i, res=0;
- for (i=0 ; i<4 ; i++)
- {
- 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))
- && evenement->mouseMove.y >= (b[i].p.y-(b[i].t.h/2)) && evenement->mouseMove.y <= (b[i].p.y + (b[i].t.h/2)) )
- colorButton(&b[i], {0,0,255});
- else
- colorButton(&b[i], {150,150,150});
- }
- }
- void colorButton ( Button * b, CodeRGB c)
- {
- b->couleur.r = c.r;
- b->couleur.g = c.g;
- b->couleur.b = c.b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement