-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
112 lines (84 loc) · 2.14 KB
/
menu.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "menu.hpp"
#include <iostream>
#include <cstdlib>
Menu :: Menu() {
about = nullptr;
settings = nullptr;
game = nullptr;
set_title("SOS game");
set_default_size(300, 300);
set_visible(true);
set_resizable(false);
set_position(Gtk::WIN_POS_CENTER_ALWAYS);
draw_widgets();
set_hierarchy();
show_all_children();
has_focus = true;
}
Menu :: ~Menu() {
if(about) delete about;
if(settings) delete settings;
if(game) delete game;
}
void Menu :: on_about_hided() {
delete about;
about = nullptr;
has_focus = true;
set_opacity(1);
}
void Menu :: on_settings_hided() {
delete settings;
settings = nullptr;
has_focus = true;
set_opacity(1);
}
void Menu :: on_play_hided() {
delete game;
game = nullptr;
has_focus = true;
set_opacity(1);
}
void Menu :: on_play_clicked() {
if(!has_focus) return;
has_focus = false;
game = new Game;
game->signal_hide().connect(sigc :: mem_fun(*this, &Menu :: on_play_hided));
game->show();
set_opacity(0);
}
void Menu :: on_settings_clicked() {
if(!has_focus) return;
has_focus = false;
settings = new Settings;
settings->signal_hide().connect(sigc :: mem_fun(*this, &Menu :: on_settings_hided));
settings->show();
set_opacity(0);
}
void Menu :: on_about_clicked() {
if(!has_focus) return;
has_focus = false;
about = new About;
about->signal_hide().connect(sigc :: mem_fun(*this, &Menu :: on_about_hided));
about->show();
set_opacity(0);
}
void Menu :: set_hierarchy() {
add(mbox);
mbox.pack_start(lblSos);
mbox.pack_start(btnPlay, Gtk :: PACK_SHRINK);
mbox.pack_start(btnSettings, Gtk :: PACK_SHRINK);
mbox.pack_start(btnAbout, Gtk :: PACK_SHRINK);
// btnPlay button
btnPlay.signal_clicked().connect(sigc :: mem_fun(*this, &Menu :: on_play_clicked));
//btnSettings button
btnSettings.signal_clicked().connect(sigc :: mem_fun(*this, &Menu :: on_settings_clicked));
// btnPlay button
btnAbout.signal_clicked().connect(sigc :: mem_fun(*this, &Menu :: on_about_clicked));
}
void Menu :: draw_widgets() {
mbox = Gtk :: Box(Gtk :: ORIENTATION_VERTICAL);
lblSos.set_label("SOS game");
btnPlay.set_label("Play");
btnSettings.set_label("Settings");
btnAbout.set_label("About");
}