-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappwindow.cpp
168 lines (137 loc) · 4.52 KB
/
appwindow.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include "appwindow.hpp"
#include "game_engine.hpp"
AppWindow::AppWindow() :
ag(Gtk::AccelGroup::create()),
m_slow(speed_group, "Slow"),
m_medium(speed_group, "Medium"),
m_fast(speed_group, "Fast"),
m_double("Double Buffer"),
game_started(0),
base_speed(TICK_SPEED),
update_speed(0)
{
set_title("A5");
// A utility class for constructing things that go into menus, which
// we'll set up next.
using Gtk::Menu_Helpers::MenuElem;
m_slow.signal_toggled().connect(sigc::mem_fun(*this, &AppWindow::slow_toggle));
m_medium.signal_toggled().connect(sigc::mem_fun(*this, &AppWindow::medium_toggle));
m_fast.signal_toggled().connect(sigc::mem_fun(*this, &AppWindow::fast_toggle));
// Set up the application menu
// The slot we use here just causes AppWindow::hide() on this,
// which shuts down the application.
// m_menu_app.items().push_back(MenuElem("_New Game", Gtk::AccelKey("n"), sigc::mem_fun(*this, &AppWindow::newgame)));
m_menu_app.items().push_back(MenuElem("_Reset", Gtk::AccelKey("r"), sigc::mem_fun(*this, &AppWindow::reset)));
m_menu_app.items().push_back(MenuElem("_Quit", Gtk::AccelKey("q"),
sigc::mem_fun(*this, &AppWindow::hide)));
m_menu_draw_mode.items().push_back(MenuElem("_Wire-frame", Gtk::AccelKey("w"),
sigc::mem_fun(*this, &AppWindow::wireframe)));
m_menu_draw_mode.items().push_back(MenuElem("_Face", Gtk::AccelKey("f"),
sigc::mem_fun(*this, &AppWindow::face)));
m_menu_draw_mode.items().push_back(MenuElem("_Multicoloured", Gtk::AccelKey("m"),
sigc::mem_fun(*this, &AppWindow::multicoloured)));
m_menu_speed.items().push_back(m_slow);
m_menu_speed.items().push_back(m_medium);
m_menu_speed.items().push_back(m_fast);
//m_menu_buffering.items().push_back(m_double);
m_menu_buffering.items().push_back(
Gtk::Menu_Helpers::CheckMenuElem("Double _Buffering",
Gtk::AccelKey("b"),
sigc::mem_fun(*this, &AppWindow::double_buffer)));
this->add_accel_group( ag );
//m_double.add_accelerator("activate", ag, 'b', Gdk::SHIFT_MASK, Gtk::ACCEL_VISIBLE);
// Set up the menu bar
m_menubar.items().push_back(Gtk::Menu_Helpers::MenuElem("_Application", m_menu_app));
// m_menubar.items().push_back(Gtk::Menu_Helpers::MenuElem("_Draw Mode", m_menu_draw_mode));
// m_menubar.items().push_back(Gtk::Menu_Helpers::MenuElem("_Speed", m_menu_speed));
// m_menubar.items().push_back(Gtk::Menu_Helpers::MenuElem("_Buffering", m_menu_buffering));
// Pack in our widgets
// First add the vertical box as our single "top" widget
add(m_vbox);
// Put the menubar on the top, and make it as small as possible
m_vbox.pack_start(m_menubar, Gtk::PACK_SHRINK);
// Put the viewer below the menubar. pack_start "grows" the widget
// by default, so it'll take up the rest of the window.
m_viewer.set_size_request(600, 600);
m_vbox.pack_start(m_viewer);
show_all();
Glib::signal_timeout().connect(
sigc::mem_fun(*this, &AppWindow::tick), 100);
}
bool AppWindow::tick()
{
m_viewer.tick();
return true;
if (game_started) {
m_viewer.tick();
if (comp_rows < m_viewer.completed_rows || update_speed)
{
update_speed = 0;
comp_rows = m_viewer.completed_rows;
Glib::signal_timeout().connect(
sigc::mem_fun(*this, &AppWindow::tick), base_speed-(10*(comp_rows)));
return false;
}
}
return true;
}
void AppWindow::double_buffer()
{
m_viewer.double_buf( m_double.property_active() );
}
void AppWindow::newgame()
{
game_started = 1;
comp_rows = 0;
m_viewer.reset_game();
}
void AppWindow::double_buf(int do_double_buffer)
{
}
void AppWindow::slow_toggle()
{
if (base_speed != SLOW_SPEED)
update_speed = 1;
base_speed = SLOW_SPEED;
}
void AppWindow::medium_toggle()
{
if (base_speed != MEDIUM_SPEED)
update_speed = 1;
base_speed = MEDIUM_SPEED;
}
void AppWindow::fast_toggle()
{
if (base_speed != FAST_SPEED)
update_speed = 1;
base_speed = FAST_SPEED;
}
void AppWindow::reset()
{
m_viewer.reset();
}
void AppWindow::wireframe()
{
m_viewer.wireframe();
}
void AppWindow::face()
{
m_viewer.face();
}
void AppWindow::multicoloured()
{
m_viewer.multicoloured();
}
bool AppWindow::on_key_press_event( GdkEventKey *ev )
{
// This is a convenient place to handle non-shortcut
// keys. You'll want to look at ev->keyval.
// An example key; delete and replace with the
// keys you want to process
if( ev->keyval == 't' ) {
return true;
} else {
return Gtk::Window::on_key_press_event( ev );
}
}