Here it is ^^.
Just copy all to main.cpp and compile.
// INCLUDES
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/Audio.hpp>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ios>
#include <iostream>
#include <fstream>
#include <ctime>
typedef struct{
int panoramica; // 1 for panoramic, 0 for 4:3
int proporcional; // 1 to keep aspect ratio
}SYSTEM;
// GLOBALS
SYSTEM sys;
sf::RenderWindow App;
int main(){
App.Create(sf::VideoMode(1024, 768, 32), "Minimize error");
App.SetFramerateLimit(60);
App.SetPosition(0,0);
App.Clear(sf::Color::Black );
sys.panoramica = false;
sys.proporcional = true;
const sf::Input& Input = App.GetInput();
// Main Loop
int i = 0;
while (App.IsOpened()){
sf::Event Event;
while (App.GetEvent(Event)){
// Close app(ESC)
if (Event.Type == sf::Event::Closed || (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Escape) ){
sf::Sleep (0.5);
App.Close();
}
// Keep aspect ratio
if (Event.Type == sf::Event::Resized){
if (sys.panoramica ){
if (sys.proporcional && ( (App.GetHeight()*100 / App.GetWidth() != 56) && (App.GetHeight()*100 / App.GetWidth() != 60) ) ){
App.SetSize(App.GetWidth(), ( App.GetWidth() * 60 / 100) );
}
}else{
if (sys.proporcional && (App.GetHeight()*100 / App.GetWidth() != 75)){
App.SetSize(App.GetWidth(), ( App.GetWidth() * 75 / 100) );
}
}
}
}
// Clean the screen
App.Clear(sf::Color::Black );
App.Display();
sf::Sleep (0.1);
}
sf::Sleep(1);
fflush (stdin);
return EXIT_SUCCESS;
}
EDIT: The problem was in App.GetWidth(), which at minimize window return 0, so there's a zero division. I solved it with:
// Keep aspect ratio
if (Event.Type == sf::Event::Resized){
if (App.GetHeight() > 10 && App.GetWidth() > 10){
if (sys.panoramica ){
...
Thank you, Laurent!