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
|
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
class BOX
{
public:
int x, y, w, h;
};
class Obj
{
public:
BOX box;
};
bool active(Obj obj, int mx, int my)
{
if(mx > obj.box.x && mx < obj.box.x + obj.box.w && my > obj.box.y && my < obj.box.y + obj.box.h)
{
return true;
}
return false;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600),"My first Visual Studio window!");
sf::Texture texture;
if(!texture.loadFromFile("button1.png"))
{
return 1;
}
sf::Sprite sprite;
sprite.setTexture(texture);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
if(active == true && event.MouseButtonReleased == sf::Mouse::Right)
sf::RenderWindow window(sf::VideoMode(400, 200),"The button worked!");
if(sf::Keyboard::isKeyPressed(sf::Keyboard::N))
{
sf::RenderWindow window2(sf::VideoMode(400, 200),"Another window!");
(window2);
while(window2.isOpen())
{
sf::Event event;
while(window2.pollEvent(event))
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::C))
{
window2.close();
}
}
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::B))
{
sf::RenderWindow window3(sf::VideoMode(500, 300),"The third window!");
(window3);
while(window3.isOpen())
{
sf::Event event;
while(window3.pollEvent(event))
if(sf::Keyboard::isKeyPressed(sf::Keyboard::C))
{
window3.close();
}
}
}
}
window.clear(sf::Color::Black);
sprite.setPosition(sf::Vector2f(50, 300));
window.draw(sprite);
window.display();
}
return 0;
}
|