Project

General

Profile

Bug #5622 ยป paintstroke.cpp

Roel Standaert, 03/24/2017 03:30 PM

 
1
#include <Wt/WApplication>
2
#include <Wt/WBrush>
3
#include <Wt/WColor>
4
#include <Wt/WContainerWidget>
5
#include <Wt/WPaintedWidget>
6
#include <Wt/WPainter>
7
#include <Wt/WPen>
8
#include <Wt/WServer>
9

    
10
class MyPaintedWidget : public Wt::WPaintedWidget {
11
public:
12
  MyPaintedWidget(Wt::WContainerWidget *parent = nullptr);
13

    
14
protected:
15
  virtual void paintEvent(Wt::WPaintDevice *paintDevice) override;
16
};
17

    
18
MyPaintedWidget::MyPaintedWidget(Wt::WContainerWidget *parent)
19
  : WPaintedWidget{parent}
20
{
21
  resize(400, 800);
22
  setInline(true);
23
}
24

    
25
void MyPaintedWidget::paintEvent(Wt::WPaintDevice *paintDevice)
26
{
27
  Wt::WPainter painter{paintDevice};
28
  painter.setRenderHint(Wt::WPainter::Antialiasing);
29

    
30
  Wt::WPen pen{Wt::WColor{Wt::red}};
31
  pen.setWidth(50);
32
  painter.setPen(pen);
33
  painter.setBrush(Wt::NoBrush);
34

    
35
  painter.drawLine(0, 50, 200, 50);
36
  painter.drawArc(100, 50, 200, 200, 0, 90 * 16);
37

    
38
  Wt::WPainterPath path;
39
  path.moveTo(0, 400);
40
  path.lineTo(200, 400);
41
  path.arcTo(200, 500, 100, 90, -90);
42
  path.setOpenSubPathsEnabled();
43

    
44
  pen.setColor(Wt::WColor{Wt::blue});
45
  painter.setPen(pen);
46
  painter.drawPath(path);
47
}
48

    
49

    
50
int main(int argc, char *argv[])
51
{
52
  return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
53
    Wt::WApplication *app = new Wt::WApplication(env);
54

    
55
    MyPaintedWidget *pw1 = new MyPaintedWidget(app->root());
56
    pw1->setPreferredMethod(Wt::WPaintedWidget::PngImage);
57
    MyPaintedWidget *pw2 = new MyPaintedWidget(app->root());
58
    pw2->setPreferredMethod(Wt::WPaintedWidget::HtmlCanvas);
59
    MyPaintedWidget *pw3 = new MyPaintedWidget(app->root());
60
    pw3->setPreferredMethod(Wt::WPaintedWidget::InlineSvgVml);
61

    
62
    return app;
63
  });
64
}
    (1-1/1)