Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////Biblioteki game aplicances
- #ifndef GAMEAPLIANCES_HPP_INCLUDED
- #define GAMEAPLIANCES_HPP_INCLUDED
- #endif // GAMEAPLIANCES_HPP_INCLUDED
- #pragma once
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <list>
- enum ButtonActions {Play,Back,Forward,Other,Nothing};
- enum MenuTribe {Powrot, Nic, FramePerSeconds};
- class Button{
- public:
- void draw(sf::RenderWindow&);
- void FullFill(int,int,std::string &,ButtonActions );//wypelnia tekst i wspó³rzêdne
- Button();
- ButtonActions IsClicked(int,int);
- private:
- sf::Sprite duszek;
- sf::Font tekscior;
- sf::Texture teksturka;
- sf::Text napis;
- ButtonActions action;
- };
- class MenuPanel{
- public:
- MenuPanel();
- int Run(sf::RenderWindow&);
- private:
- void draw(sf::RenderWindow&);
- void ProcessEvents(sf::RenderWindow&);
- MenuTribe IsClicked(int, int);
- MenuTribe Tryb=MenuTribe::Nic;
- int WhatToDo();
- int HandleFPS();
- Button taski[2];
- sf::Event zdarzenie;
- };
- class FPSwindow
- {
- public:
- FPSwindow();
- void draw(sf::RenderWindow&);
- void update (int );
- private:
- std::string FPS="A";
- sf::Sprite ikona;
- sf::Font font;
- sf::Texture teksturka;
- sf::Text napis;
- };
- class Taskbar{
- public:
- Taskbar();
- void draw(sf::RenderWindow &);
- ButtonActions IsClicked(int, int);
- void update(int);
- private:
- Button taski[4];
- FPSwindow FPScounter;
- };
- ///////////////////////////////////////
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <list>
- #include "GameApliances.hpp"
- #include <string>
- void MenuPanel::draw(sf::RenderWindow& appwindow)
- {
- taski[0].draw(appwindow);
- taski[1].draw(appwindow);
- }
- int MenuPanel::Run(sf::RenderWindow& appwindow)
- {
- int i=0;
- while(i==0){
- appwindow.clear();
- draw(appwindow);
- ProcessEvents(appwindow);
- i=WhatToDo();
- }
- }
- int MenuPanel::HandleFPS()
- {
- return 0;
- }
- int MenuPanel::WhatToDo()
- {
- switch(Tryb)
- {
- case MenuTribe::Nic:
- {
- return 0;
- }break;
- case MenuTribe::Powrot:
- {
- return -1;
- }
- case MenuTribe::FramePerSeconds:
- {
- return HandleFPS();
- }break;
- }
- }
- void MenuPanel::ProcessEvents(sf::RenderWindow& appwindow)
- {
- while(appwindow.pollEvent(zdarzenie))
- {
- if(zdarzenie.type==sf::Event::Closed)
- {
- appwindow.close();
- exit(0);
- }
- if(zdarzenie.type==sf::Event::MouseButtonPressed)
- {
- Tryb=IsClicked(zdarzenie.mouseButton.x,zdarzenie.mouseButton.y);
- }
- }
- }
- MenuTribe MenuPanel::IsClicked(int x,int y)
- {
- ButtonActions bufor=ButtonActions::Nothing;
- for(int i=0;i<2;i++)
- {
- bufor=taski[i].IsClicked(x,y);
- if(ButtonActions::Nothing!=bufor)
- {
- switch(bufor)
- {
- case ButtonActions::Play:
- {
- return MenuTribe::Powrot;
- }break;
- case ButtonActions::Other:
- {
- return MenuTribe::FramePerSeconds;
- }break;
- }
- }
- }
- return MenuTribe::Nic;
- }
- MenuPanel::MenuPanel()
- {
- std::string buf="FPS setter";
- taski[0].FullFill(600,400,buf,ButtonActions::Other);
- buf="Powrot";
- taski[1].FullFill(600,1200,buf,ButtonActions::Play);
- }
- FPSwindow::FPSwindow()
- {
- teksturka.loadFromFile("ikona.jpg");
- ikona.setTexture(teksturka);
- font.loadFromFile("font.ttf");
- napis.setFont(font);
- napis.setString(FPS);
- ikona.setPosition(1850,1550);
- napis.setPosition(1850,1550);
- }
- void FPSwindow::draw(sf::RenderWindow&appwindow)
- {
- appwindow.draw(ikona);
- appwindow.draw(napis);
- }
- void FPSwindow::update (int a){
- FPS=std::to_string(a);
- napis.setString(FPS);
- }
- void Taskbar::update(int a)
- {
- FPScounter.update(a);
- }
- ButtonActions Taskbar::IsClicked(int x, int y)
- {
- for(int i=0;i<4;i++)
- {
- if(ButtonActions::Nothing!=taski[i].IsClicked(x,y))
- return taski[i].IsClicked(x,y);
- }
- return ButtonActions::Nothing;
- }
- ButtonActions Button::IsClicked(int x,int y)
- {
- if((x>duszek.getGlobalBounds().left)&&(x<duszek.getGlobalBounds().width)&&
- (y>duszek.getGlobalBounds().top)&&(y>duszek.getGlobalBounds().height))
- return action;
- return Nothing;
- }
- void Taskbar::draw(sf::RenderWindow& appwindow)
- {
- for(int i=0;i<4;i++)
- taski[i].draw(appwindow);
- FPScounter.draw(appwindow);
- }
- Taskbar::Taskbar()
- {
- std::string napis="Play";
- taski[0].FullFill(200,1520,napis,ButtonActions::Play);
- napis="StepBack";
- taski [1].FullFill(600,1520,napis,ButtonActions::Back);
- napis="StepForward";
- taski [2].FullFill(1000,1520,napis,ButtonActions::Forward);
- napis="Other";
- taski [3].FullFill(1400,1520,napis,ButtonActions::Other);
- }
- void Button::FullFill(int x,int y,std::string & tresc,ButtonActions akcja)
- {
- duszek.setPosition(x,y);
- napis.setPosition(x+150,y+80);
- napis.setString(tresc);
- action=akcja;
- }
- void Button::draw(sf::RenderWindow& appwindow)
- {
- appwindow.draw(duszek);
- appwindow.draw(napis);
- }
- /*Button::Button(std::string& ciag)
- {
- teksturka.loadFromFile("button.jpg");
- duszek.setTexture(teksturka);
- tekscior.loadFromFile("font.ttf");
- napis.setFont(tekscior);
- napis.setString(ciag);
- duszek.setPosition(100,100);
- napis.setPosition(150,150);
- }*/
- Button::Button()
- {
- teksturka.loadFromFile("button.jpg");
- duszek.setTexture(teksturka);
- tekscior.loadFromFile("font.ttf");
- napis.setFont(tekscior);
- action=ButtonActions::Other;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement