Add first version of SFMLController and View class
This commit is contained in:
parent
ddaf5ba3ba
commit
ce3f721e16
9 changed files with 113 additions and 3 deletions
|
@ -12,7 +12,8 @@ set_property(GLOBAL PROPERTY SFML_INCLUDE_DIR "${SFML_INCLUDE_DIR}")
|
||||||
|
|
||||||
#Include "Includes" and "Libraries"
|
#Include "Includes" and "Libraries"
|
||||||
include_directories(${SFML_INCLUDE_DIR})
|
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(./Model)
|
||||||
add_subdirectory(./Controllers/)
|
add_subdirectory(./Controllers/)
|
||||||
|
add_subdirectory(./View/)
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
add_subdirectory(./ConsoleController/)
|
add_subdirectory(./ConsoleController/)
|
||||||
|
add_subdirectory(./SFMLController/)
|
||||||
|
|
3
src/Controllers/SFMLController/CMakeLists.txt
Normal file
3
src/Controllers/SFMLController/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#Make Model lib
|
||||||
|
add_library(SFMLController ./SFMLController.cpp)
|
||||||
|
target_link_libraries(SFMLController Model View)
|
37
src/Controllers/SFMLController/SFMLController.cpp
Normal file
37
src/Controllers/SFMLController/SFMLController.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
21
src/Controllers/SFMLController/SFMLController.hpp
Normal file
21
src/Controllers/SFMLController/SFMLController.hpp
Normal 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
2
src/View/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#Make Model lib
|
||||||
|
add_library(View ./MainWindow.cpp)
|
25
src/View/MainWindow.cpp
Normal file
25
src/View/MainWindow.cpp
Normal 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
20
src/View/MainWindow.hpp
Normal 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();
|
||||||
|
|
||||||
|
};
|
|
@ -6,7 +6,7 @@
|
||||||
//----------------------
|
//----------------------
|
||||||
|
|
||||||
//----- Personnal include -----
|
//----- Personnal include -----
|
||||||
#include "./Controllers/ConsoleController/ConsoleController.hpp"
|
#include "./Controllers/SFMLController/SFMLController.hpp"
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ int main()
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
//Init controller
|
//Init controller
|
||||||
ConsoleController controller;
|
SFMLController controller;
|
||||||
|
|
||||||
//Run the game
|
//Run the game
|
||||||
controller.run();
|
controller.run();
|
||||||
|
|
Loading…
Add table
Reference in a new issue