-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIDisplay.cpp
More file actions
57 lines (52 loc) · 1.39 KB
/
Copy pathGUIDisplay.cpp
File metadata and controls
57 lines (52 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "GUIDisplay.h"
#include "GUIBoardArea.h"
#include "coordinate.h"
#include <iostream>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <thread>
#include <chrono>
using namespace std;
GUIDisplay::GUIDisplay(shared_ptr<BoardSubject> bs, int argc, char** argv)
{
td_ = make_shared<PImplGUIDisplay> ();
td_->subject = bs;
td_->subject->attach(this);
td_->argc_ = argc;
td_->argv_ = argv;
td_->guiDisplayed_ = false;
}
GUIDisplay::~GUIDisplay()
{
td_->subject->detach(this);
}
//Open the GUI application and run it
int GUIDisplay::displayGUI()
{
auto gtkApp = Gtk::Application::create(td_->argc_, td_->argv_, "org.gtkmm.examples.base");
Gtk::Window mainWindow;
mainWindow.set_default_size(390, 700);
td_->boardDisplay = shared_ptr<BoardArea>(new BoardArea(td_->subject));
mainWindow.add(*td_->boardDisplay);
td_->boardDisplay->show();
return gtkApp->run(mainWindow);
}
void GUIDisplay::update()
{
//Open window
if(!td_->guiDisplayed_)
{
//Separate thread for GUI
thread guiThread_(&GUIDisplay::displayGUI, this);
td_->guiDisplayed_ = true;
//Allow initial board to be displayed
this_thread::sleep_for(chrono::seconds(5));
guiThread_.detach();//detach GUI thread
}
else
{
//Redraw the board
td_->boardDisplay->hide();
td_->boardDisplay->show();
}
}