/
main.cpp
128 lines (115 loc) · 3.05 KB
/
main.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
#include <boost/program_options.hpp>
#include <boost/signals2.hpp>
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WPaintDevice>
#include <Wt/WPaintedWidget>
#include <Wt/WPainter>
#include <Wt/WPushButton>
struct WtWidget : public Wt::WPaintedWidget
{
WtWidget()
{
this->resize(32,32);
}
protected:
void paintEvent(Wt::WPaintDevice *paintDevice)
{
Wt::WPainter painter(paintDevice);
for (int y=0; y!=32; ++y)
{
for (int x=0; x!=32; ++x)
{
painter.setPen(
Wt::WPen(
Wt::WColor(
((x+0) * 8) % 256,
((y+0) * 8) % 256,
((x+y) * 8) % 256)));
//Draw a line of one pixel long
painter.drawLine(x,y,x+1,y);
//drawPoint yiels too white results
//painter.drawPoint(x,y);
}
}
}
};
struct WtDialog : public Wt::WContainerWidget
{
WtDialog()
: m_widget(new WtWidget)
{
this->addWidget(m_widget);
}
WtDialog(const WtDialog&) = delete;
WtDialog& operator=(const WtDialog&) = delete;
private:
WtWidget * const m_widget;
};
struct WtApplication : public Wt::WApplication
{
WtApplication(const Wt::WEnvironment& env)
: Wt::WApplication(env),
m_dialog(new WtDialog)
{
this->setTitle("Thinking Wt 2: creating a widget");
root()->addWidget(m_dialog);
}
WtApplication(const WtApplication&) = delete;
WtApplication& operator=(const WtApplication&) = delete;
private:
WtDialog * const m_dialog;
};
Wt::WApplication *createApplication(
const Wt::WEnvironment& env) noexcept
{
return new WtApplication(env);
}
int main(int argc, char **argv)
{
// Declare the supported options.
boost::program_options::options_description d(
"Allowed options for CppWtAutoRun");
std::string docroot;
std::string http_address;
std::string http_port;
d.add_options()
("help",
"produce this help message")
("docroot",
boost::program_options::value<std::string>(&docroot)->default_value("."),
"the docroot")
("http-address",
boost::program_options::value<std::string>(&http_address)->default_value("0.0.0.0"),
"the server's http address")
("http-port",
boost::program_options::value<std::string>(&http_port)->default_value("8080"),
"the server's http port")
;
boost::program_options::variables_map m;
boost::program_options::store(
boost::program_options::parse_command_line(
argc, argv, d), m);
boost::program_options::notify(m);
if (m.count("help"))
{
//Display the options_description
std::cout << d << "\n";
return 0;
}
//Create the arguments in std::string format
std::vector<std::string> v(7);
v[0] = argv[0];
v[1] = "--docroot";
v[2] = docroot;
v[3] = "--http-address";
v[4] = http_address;
v[5] = "--http-port";
v[6] = http_port;
//Convert the arguments to char* format
std::vector<char*> w(7);
for (int i=0; i!=7; ++i) w[i] = &v[i][0];
//Give Wt the modified parameters
return WRun(w.size(), &w[0], &createApplication);
}