Browse Source

Added resize window support

master
Macoy Madson 3 years ago
parent
commit
00a45086c4
2 changed files with 27 additions and 4 deletions
  1. +21
    -4
      graphics/graphics.cpp
  2. +6
    -0
      graphics/graphics.hpp

+ 21
- 4
graphics/graphics.cpp View File

@ -8,12 +8,26 @@
window::window(int width,int height, std::string title)
{
isClearing=true;
win=new sf::RenderWindow(sf::VideoMode(width, height), title, sf::Style::Close);
//win->setVerticalSyncEnabled(false);
win = new sf::RenderWindow(sf::VideoMode(width, height), title,
sf::Style::Close | sf::Style::Resize);
//win->setVerticalSyncEnabled(false);
//win->setFramerateLimit(45);
focused=true;
time.start();
}
window::window(int width, int height, std::string title, WindowResizeCB onResizeCallback)
: onResize(onResizeCallback)
{
isClearing=true;
win = new sf::RenderWindow(sf::VideoMode(width, height), title,
sf::Style::Close | sf::Style::Resize);
//win->setVerticalSyncEnabled(false);
//win->setFramerateLimit(45);
focused=true;
time.start();
}
//Close & delete the window
window::~window()
{
@ -54,8 +68,11 @@ bool window::shouldClose()
if (event.type==sf::Event::Closed) return true;
if (event.type==sf::Event::Resized)
{
//std::cout << "Window resized to " << event.size.width << " , " << event.size.height << "\n";
//win->setSize(sf::Vector2u(event.size.width, event.size.height));
win->setView(
sf::View(sf::Vector2<float>(event.size.width / 2.f, event.size.height / 2.f),
sf::Vector2<float>(event.size.width, event.size.height)));
if (onResize)
onResize(event.size.width, event.size.height);
}
if (event.type==sf::Event::GainedFocus)
{


+ 6
- 0
graphics/graphics.hpp View File

@ -106,6 +106,9 @@ class pixels
int getWidth();
int getHeight();
};
typedef void (*WindowResizeCB)(float, float);
//The core of the graphics, the window.
class window
{
@ -115,8 +118,11 @@ class window
bool isClearing;
bool focused;
timer time;
WindowResizeCB onResize;
public:
window(int width,int height, std::string title);
window(int width, int height, std::string title, WindowResizeCB onResizeCallback);
//Close & delete the window
~window();
//Various drawing functions


Loading…
Cancel
Save