Add first version of SFMLController and View class

This commit is contained in:
manzerbredes 2015-05-03 14:19:30 +02:00
parent ddaf5ba3ba
commit ce3f721e16
9 changed files with 113 additions and 3 deletions

View file

@ -12,7 +12,8 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}")
#Include "Includes" and "Libraries"
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController)
target_link_libraries(2P11 ${SFML_LIBRARIES} Model ConsoleController View SFMLController)
add_subdirectory(./Model)
add_subdirectory(./Controllers/)
add_subdirectory(./View/)

View file

@ -1 +1,2 @@
add_subdirectory(./ConsoleController/)
add_subdirectory(./SFMLController/)

View file

@ -0,0 +1,3 @@
#Make Model lib
add_library(SFMLController ./SFMLController.cpp)
target_link_libraries(SFMLController Model View)

View file

@ -0,0 +1,37 @@
#include "SFMLController.hpp"
SFMLController::SFMLController() : m_MainWindow(800,800, "2P11"){
}
SFMLController::~SFMLController(){
}
void SFMLController::run(){
while(m_MainWindow.isOpen()){
sf::Event event;
while (m_MainWindow.pollEvent(event))
{
// évènement "fermeture demandée" : on ferme la fenêtre
if (event.type == sf::Event::Closed)
m_MainWindow.close();
}
m_MainWindow.clearMW();
m_MainWindow.display();
}
}

View file

@ -0,0 +1,21 @@
#include <iostream>
#include <string>
#include <SFML/Window.hpp>
#include "../../View/MainWindow.hpp"
class SFMLController{
private:
MainWindow m_MainWindow;
public:
SFMLController();
~SFMLController();
void run();
};

2
src/View/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
#Make Model lib
add_library(View ./MainWindow.cpp)

25
src/View/MainWindow.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "MainWindow.hpp"
MainWindow::MainWindow(int width, int height, std::string title):
RenderWindow(sf::VideoMode(width,height), title),
skin()
{
//Define skin:
skin.push_back(sf::Color(250,248,239));
}
MainWindow::~MainWindow(){
}
void MainWindow::clearMW(){
RenderWindow::clear(skin.at(0));
}

20
src/View/MainWindow.hpp Normal file
View file

@ -0,0 +1,20 @@
#include <iostream>
#include <vector>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
class MainWindow : public sf::RenderWindow{
private:
std::vector<sf::Color> skin;
public:
MainWindow(int width, int height, std::string title);
~MainWindow();
void clearMW();
};

View file

@ -6,7 +6,7 @@
//----------------------
//----- Personnal include -----
#include "./Controllers/ConsoleController/ConsoleController.hpp"
#include "./Controllers/SFMLController/SFMLController.hpp"
//-----------------------------
@ -20,7 +20,7 @@ int main()
srand(time(NULL));
//Init controller
ConsoleController controller;
SFMLController controller;
//Run the game
controller.run();