|
#include <Wt/WApplication>
|
|
#include <Wt/WBrush>
|
|
#include <Wt/WColor>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WPaintedWidget>
|
|
#include <Wt/WPainter>
|
|
#include <Wt/WPen>
|
|
#include <Wt/WServer>
|
|
|
|
class MyPaintedWidget : public Wt::WPaintedWidget {
|
|
public:
|
|
MyPaintedWidget(Wt::WContainerWidget *parent = nullptr);
|
|
|
|
protected:
|
|
virtual void paintEvent(Wt::WPaintDevice *paintDevice) override;
|
|
};
|
|
|
|
MyPaintedWidget::MyPaintedWidget(Wt::WContainerWidget *parent)
|
|
: WPaintedWidget{parent}
|
|
{
|
|
resize(400, 800);
|
|
setInline(true);
|
|
}
|
|
|
|
void MyPaintedWidget::paintEvent(Wt::WPaintDevice *paintDevice)
|
|
{
|
|
Wt::WPainter painter{paintDevice};
|
|
painter.setRenderHint(Wt::WPainter::Antialiasing);
|
|
|
|
Wt::WPen pen{Wt::WColor{Wt::red}};
|
|
pen.setWidth(50);
|
|
painter.setPen(pen);
|
|
painter.setBrush(Wt::NoBrush);
|
|
|
|
painter.drawLine(0, 50, 200, 50);
|
|
painter.drawArc(100, 50, 200, 200, 0, 90 * 16);
|
|
|
|
Wt::WPainterPath path;
|
|
path.moveTo(0, 400);
|
|
path.lineTo(200, 400);
|
|
path.arcTo(200, 500, 100, 90, -90);
|
|
path.setOpenSubPathsEnabled();
|
|
|
|
pen.setColor(Wt::WColor{Wt::blue});
|
|
painter.setPen(pen);
|
|
painter.drawPath(path);
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
|
|
Wt::WApplication *app = new Wt::WApplication(env);
|
|
|
|
MyPaintedWidget *pw1 = new MyPaintedWidget(app->root());
|
|
pw1->setPreferredMethod(Wt::WPaintedWidget::PngImage);
|
|
MyPaintedWidget *pw2 = new MyPaintedWidget(app->root());
|
|
pw2->setPreferredMethod(Wt::WPaintedWidget::HtmlCanvas);
|
|
MyPaintedWidget *pw3 = new MyPaintedWidget(app->root());
|
|
pw3->setPreferredMethod(Wt::WPaintedWidget::InlineSvgVml);
|
|
|
|
return app;
|
|
});
|
|
}
|