Separate drawing out to view.cpp

This commit is contained in:
Sheldon Lee 2023-03-30 23:49:36 +01:00
parent dbb69dd80e
commit b9470696f6
3 changed files with 43 additions and 17 deletions

View File

@ -1,26 +1,13 @@
#include <SFML/Graphics.hpp>
#include <stdio.h> #include <stdio.h>
#include "view.h"
int main() int main()
{ {
sf::Uint32 style = sf::Style::Titlebar;
sf::RenderWindow window(sf::VideoMode(1600, 900), "SFML works!", style);
sf::CircleShape shape(450.f);
shape.setFillColor(sf::Color::Green);
printf("Hello meme!\n"); printf("Hello meme!\n");
while (window.isOpen()) { view_init();
sf::Event event; while (view_update());
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0; return 0;
} }

32
view.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <SFML/Graphics.hpp>
#include "view.h"
static sf::Uint32 style = sf::Style::Titlebar;
static sf::RenderWindow window(sf::VideoMode(1600, 900), "SFML works!", style);
static sf::CircleShape shape(450.f);
int view_init()
{
shape.setFillColor(sf::Color::Green);
return 1;
}
int view_update()
{
if (!window.isOpen()) return 0;
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
return 0;
}
}
window.clear();
window.draw(shape);
window.display();
return 1;
}

7
view.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef VIEW_H
#define VIEW_H
int view_init();
int view_update();
#endif