#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")
#endif // SFML_STATIC
#include <SFML/Graphics.hpp>
int posx, posy;
sf::View view1;
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
sf::View view1(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::MouseMoved)
{
posx = event.mouseMove.x ;
posy = event.mouseMove.y ;
}
if (event.type == sf::Event::MouseWheelMoved)
{
if (event.mouseWheel.delta >= 1)
{
sf::View view1(sf::FloatRect(0.3f, 0.3f, window.getSize().x, window.getSize().y));
view1.zoom(0.3f);
view1.setCenter(posx, posy);
window.setView(view1);
}
if (event.mouseWheel.delta <= -1)
{
sf::View view1(sf::FloatRect(3.f, 3.f, window.getSize().x, window.getSize().y));
view1.zoom(3.f);
view1.setCenter(posx, posy);
window.setView(view1);
}
}
if (event.type == sf::Event::Resized)
{
sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
window.setView(sf::View(visibleArea));
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
My problem is, It not zoom to area that cursor point.
I have move center of view into right position but It still have problem.
And when I resize window, It will reset zoom and position. How can I still zoom and position when resize window?
Thanks