-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
81 lines (73 loc) · 2.47 KB
/
Copy pathMainWindow.cpp
File metadata and controls
81 lines (73 loc) · 2.47 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* MainWindow.cpp – Coffee Toolkit */
#include "MainWindow.h"
#include "Constants.h"
#include "Settings.h"
#include "BrewRatioWindow.h"
#include "ExtractionWindow.h"
#include "RoastColorWindow.h"
#include "DetailWindow.h"
#include <Application.h>
#include <InterfaceDefs.h>
#include <LayoutBuilder.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Message.h>
#include <Rect.h>
#include <View.h>
MainWindow::MainWindow()
: BWindow(BRect(100, 100, 200, 200),
"Coffee Toolkit",
B_TITLED_WINDOW,
B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
BMenuBar* menuBar = new BMenuBar("menubar");
BMenu* helpMenu = new BMenu("Help");
helpMenu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
menuBar->AddItem(helpMenu);
CoffeeSettings::BuildSettingsMenu(menuBar);
auto MakeBtn = [&](const char* label, uint32 cmd) -> BButton* {
BButton* btn = new BButton("btn", label, new BMessage(cmd));
btn->SetExplicitMinSize(BSize(kBtnW, kBtnH));
btn->SetExplicitMaxSize(BSize(kBtnW, kBtnH));
return btn;
};
fBrewRatioBtn = MakeBtn("Brew Ratio\nCalculator", MSG_BREW_RATIO);
fParticleBtn = MakeBtn("Particle\nAnalyzer", MSG_PARTICLE);
fExtractionBtn = MakeBtn("Extraction\n%", MSG_EXTRACTION);
fRoastBtn = MakeBtn("Roast Color\nAnalyzer", MSG_ROAST_COLOR);
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.Add(menuBar)
.AddGroup(B_HORIZONTAL, kPad)
.SetInsets(kPad, kPad, kPad, kPad)
.Add(fBrewRatioBtn)
.Add(fParticleBtn)
.Add(fExtractionBtn)
.Add(fRoastBtn)
.End();
ResizeTo(GetLayout()->PreferredSize().width,
GetLayout()->PreferredSize().height);
CenterOnScreen();
}
void MainWindow::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case MSG_BREW_RATIO:
(new BrewRatioWindow())->Show();
break;
case MSG_EXTRACTION:
(new ExtractionWindow())->Show();
break;
case MSG_PARTICLE:
(new DetailWindow())->Show();
break;
case MSG_ROAST_COLOR:
(new RoastColorWindow())->Show();
break;
default:
if (CoffeeSettings::Get()->HandleSettingsMessage(msg))
break;
BWindow::MessageReceived(msg);
}
}