Commit 02773ce8 authored by Loic Guegan's avatar Loic Guegan
Browse files

Remove useless code

parent 3f382b4d
Pipeline #213293686 passed with stage
in 8 minutes and 40 seconds
#ifndef CONTROLLER_HPP
#define CONTROLLER_HPP
#include "View.hpp"
#include <vector>
#include <mutex>
namespace ochess {
namespace gui {
class Controller {
protected:
std::vector<View*> RegisteredViews;
std::mutex model;
public:
void RegisterView(View *v) {
RegisteredViews.push_back(v);
}
void Notify() {
for (auto &view : RegisteredViews)
view->Touch();
}
};
} // namespace gui
} // namespace ochess
#endif
......@@ -14,23 +14,7 @@ class Controller;
class View {
public:
virtual ~View(){};
/**
* This function can be called by the different applications controllers
*/
virtual void Touch() {
}
;
/**
* This function is called when all views has been added to the OchessInstance
*/
virtual void Initialize() {
}
;
/**
* Should return a pointer to the actual window controller
*/
virtual Controller* GetController() = 0;
virtual wxMenu* GetMenu() {
return (nullptr);
}
......
......@@ -34,10 +34,6 @@ void BoardPanel::paintEvent(wxPaintEvent&WXUNUSED(evt)) {
render(dc);
}
void BoardPanel::Touch() {
Refresh();
}
void BoardPanel::render(wxDC &dc) {
C.RefreshDC(dc);
......
......@@ -43,17 +43,7 @@ public:
void HandleKey(wxKeyEvent &event);
void SetPiecesSkin(std::string path);
void SetBoardSkin(std::string path);
void Touch() override;
void Configure() override {
}
;
void Initialize() override {
}
;
Controller* GetController() override {
return (&C);
}
void Configure() override {};
DECLARE_EVENT_TABLE()
};
......
......@@ -22,10 +22,6 @@ BoardView::BoardView(wxFrame *parent) :
}
Controller* BoardView::GetController() {
return (nullptr);
}
}
}
......@@ -15,7 +15,6 @@ private:
public:
BoardPanel *BP;
BoardView(wxFrame *parent);
Controller* GetController() override;
};
}
}
......
......@@ -17,7 +17,6 @@ BoardController::BoardController(View *v) :
}
void BoardController::Move(Coord src, Coord dst) {
model.lock();
if (G.Move(src, dst) && BlackEngine != NULL) {
FenState state = G.GetState();
if (state.ActiveColor == ochess::model::BLACK) {
......@@ -33,7 +32,6 @@ void BoardController::Move(Coord src, Coord dst) {
G.Promote(m.promoteTo);
}
}
model.unlock();
}
} // namespace gui
} // namespace ochess
......@@ -2,7 +2,6 @@
#define BOARDCONTROLLER_HPP
#include "gui/View.hpp"
#include "gui/Controller.hpp"
#include "DrawingToolBox.hpp"
#include "Skin.hpp"
#include "model/Game.hpp"
......@@ -20,7 +19,7 @@ using namespace model;
namespace ochess {
namespace gui {
class BoardController: public DrawingToolBox, public Controller {
class BoardController: public DrawingToolBox {
private:
View *V;
Engine *BlackEngine;
......
......@@ -29,8 +29,6 @@ void EngineView::AddEngine(wxCommandEvent &event) {
this->Show();
}
Controller* EngineView::GetController() {
return (&C);
}
} // namespace gui
} // namespace ochess
......@@ -19,7 +19,6 @@ private:
public:
EngineView();
Controller* GetController() override;
wxMenu* GetMenu() override;
void OnClose(wxCloseEvent &event);
void AddEngine(wxCommandEvent &event);
......
......@@ -3,13 +3,12 @@
#include "../../../log.hpp"
#include "engine/Engine.hpp"
#include "gui/Controller.hpp"
#include "gui/View.hpp"
namespace ochess {
namespace gui {
class EngineController: public Controller {
class EngineController {
private:
View *V;
......
......@@ -33,23 +33,19 @@ wxMenu* MainFrame::getSquaresMenu() {
return themes;
}
void MainFrame::Create(CTRL name) {
void MainFrame::Create(WIN name) {
switch (name) {
case BOARD: {
BoardView *b = new BoardView((wxFrame*) this);
Panels.push_back(b);
Views[name] =b;
Windows[name]=b;
break;
}
case ENGINE:
{
EngineView *e = new EngineView();
Panels.push_back(e);
Views[name] = e;
Windows[name]=e;
break;
}
break;
}
}
......@@ -81,14 +77,14 @@ wxFrame(NULL, wxID_ANY, title, pos, size) {
void MainFrame::OnClose(wxCloseEvent &event) {
event.Skip();
for(auto w:Panels)
w->Destroy();
for(auto pair:Windows)
pair.second->Destroy();
}
void MainFrame::ChangeSquares(wxCommandEvent &event) {
wxMenu *menu = getSquaresMenu();
wxMenuItem *item = menu->FindItem(event.GetId());
p->BP->SetBoardSkin(item->GetItemLabel().ToStdString());
//p->BP->SetBoardSkin(item->GetItemLabel().ToStdString());
(void) item;
}
......@@ -97,7 +93,7 @@ void MainFrame::ChangePieces(wxCommandEvent &event) {
wxMenu *menu = getPiecesMenu();
wxMenuItem *item = menu->FindItem(event.GetId());
(void) item;
p->BP->SetPiecesSkin(item->GetItemLabel().ToStdString());
//p->BP->SetPiecesSkin(item->GetItemLabel().ToStdString());
}
void MainFrame::OnExit(wxCommandEvent &event) {
......
......@@ -8,18 +8,23 @@
#include "gui/board/BoardView.hpp"
#include "gui/engine/EngineView.hpp"
#include "ochess.hpp"
#include "ViewManager.hpp"
#include <unordered_map>
namespace ochess {
namespace gui {
typedef enum WIN {
BOARD,ENGINE
} WIN;
/**
* @class MainFrame
* @brief The main frame of the application.
*
* This class contains every sub-graphical components (board etc..).
*/
class MainFrame: public wxFrame, ViewManager {
class MainFrame: public wxFrame {
public:
/**
......@@ -33,9 +38,7 @@ private:
/**
* Main window components
*/
BoardView *p;
EngineView *e;
vector<wxWindow*> Panels;
unordered_map<WIN,wxWindow*> Windows;
void OnHello(wxCommandEvent &event);
void OnExit(wxCommandEvent &event);
......@@ -45,7 +48,7 @@ private:
wxMenu* getPiecesMenu();
wxMenu* getSquaresMenu();
void OnClose(wxCloseEvent &event);
void Create(CTRL name) override;
void Create(WIN name);
wxDECLARE_EVENT_TABLE();
};
......
/*
* ControllerManager.cpp
*
* Created on: 8 nov. 2020
* Author: loic
*/
#include "ViewManager.hpp"
namespace ochess {
namespace gui {
View* ViewManager::operator[](CTRL name){
// If the controller is not available, ask the main frame to create it
if(Views.find(name)==Views.end()){
this->Create(name);
}
return(Views[name]);
}
} /* namespace gui */
} /* namespace ochess */
/*
* ControllerManager.h
*
* Created on: 8 nov. 2020
* Author: loic
*/
#ifndef GUI_CONTROLLERMANAGER_H_
#define GUI_CONTROLLERMANAGER_H_
#include <unordered_map>
#include <mutex>
#include <memory>
#include "gui/Controller.hpp"
#include <iostream>
using namespace std;
namespace ochess {
namespace gui {
typedef enum CTRL {
BOARD,ENGINE
} CTRL;
class ViewManager {
protected:
unordered_map<CTRL, View*> Views;
virtual void Create(CTRL name) = 0;
public:
View* operator[](CTRL name);
};
} /* namespace gui */
} /* namespace ochess */
#endif /* SRC_GUI_CONTROLLERMANAGER_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment