Wt examples: PaintExample Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PaintExample Class Reference

`#include <PaintExample.h>`

Inheritance diagram for PaintExample:
[legend]

## Public Member Functions
| PaintExample (bool showTitle=true)

## Private Member Functions
void | rotateShape (int v)
void | scaleShape (int v)

## Private Attributes
ShapesWidget * | shapes_

## Detailed Description

Definition at line 17 of file PaintExample.h.

## Constructor & Destructor Documentation

## ◆ PaintExample()

PaintExample::PaintExample | ( | bool | showTitle = true | ) |

Definition at line 18 of file PaintExample.C.

19 : WContainerWidget()
20{
21 std::string text;
22 if (showTitle)
23 text += "<h2>Paint example</h2>";
24
25 text +=
26 "<p>A simple example demonstrating cross-browser vector graphics."
27 "</p>"
28 "<p>The emweb logo below is painted using the Wt WPainter API from "
29 "bezier paths, and rendered to the browser using inline SVG, inline VML "
30 "or the HTML 5 &lt;canvas&gt; element."
31 "</p>"
32 "<p>"
33 "The example also demonstrates the horizontal and vertical "
34 "<a href=\"http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WSlider.html\" target=\"_blank\">"
35 "WSlider</a> widgets. Here, "
36 "the events of the WSlider widgets are used to scale and rotate the "
37 "emweb logo."
38 "</p>"
39 "<p>"
40 "To demonstrate the different rendering methods, a different backend is used for positive or negative "
41 "angles (SVG or HTML canvas)."
42 "</p>";
43
44 this->addWidget(std::make_unique<WText>(text));
45
46 WContainerWidget *emweb = this->addWidget(std::make_unique<WContainerWidget>());
47 emweb->setMargin(WLength::Auto, Side::Left | Side::Right);
48
49 auto layout = std::make_unique<WGridLayout>();
50 auto layout_ = emweb->setLayout(std::move(layout));
51
52 std::unique_ptr<WSlider> scaleSlider(std::make_unique<WSlider>());
53 scaleSlider->setMinimum(0);
54 scaleSlider->setMaximum(20);
55 scaleSlider->setValue(10);
56 scaleSlider->setTickInterval(5);
57 scaleSlider->setTickPosition(WSlider::TicksBothSides);
58 scaleSlider->resize(300, 50);
59 scaleSlider->sliderMoved().connect(this, &PaintExample::scaleShape);
60
61 layout_->addWidget(std::move(scaleSlider), 0, 1, AlignmentFlag::Center | AlignmentFlag::Middle);
62
63 auto rotateSlider = std::make_unique<WSlider>(Orientation::Vertical);
64 rotateSlider->setMinimum(-30);
65 rotateSlider->setMaximum(30);
66 rotateSlider->setValue(0);
67 rotateSlider->setTickInterval(10);
68 rotateSlider->setTickPosition(WSlider::TicksBothSides);
69 rotateSlider->resize(50, 400);
70 rotateSlider->sliderMoved().connect(this, &PaintExample::rotateShape);
71
72 layout_->addWidget(std::move(rotateSlider), 1, 0, AlignmentFlag::Center | AlignmentFlag::Middle);
73
74 auto shapes = std::make_unique<ShapesWidget>();
75 shapes_ = shapes.get();
76 shapes_->setAngle(0.0);
77 shapes_->setRelativeSize(0.5);
78 shapes_->setPreferredMethod(RenderMethod::HtmlCanvas);
79
80 layout_->addWidget(std::move(shapes), 1, 1,
81 AlignmentFlag::Center | AlignmentFlag::Middle);
82}
PaintExample::rotateShape
void rotateShape(int v)
Definition PaintExample.C:84
PaintExample::shapes_
ShapesWidget * shapes_
Definition PaintExample.h:23
PaintExample::scaleShape
void scaleShape(int v)
Definition PaintExample.C:93
ShapesWidget::setAngle
void setAngle(double angle)
Definition ShapesWidget.C:33
ShapesWidget::setRelativeSize
void setRelativeSize(double size)
Definition ShapesWidget.C:43

## Member Function Documentation

## ◆ rotateShape()

void PaintExample::rotateShape | ( | int | v | ) |
| private

Definition at line 84 of file PaintExample.C.

85{
86 shapes_->setAngle(v / 2.0);
87
88 // Being silly: test alternate rendering method
89 shapes_->setPreferredMethod(v < 0 ? RenderMethod::InlineSvgVml
90 : RenderMethod::HtmlCanvas);
91}

## ◆ scaleShape()

void PaintExample::scaleShape | ( | int | v | ) |
| private

Definition at line 93 of file PaintExample.C.

94{
95 shapes_->setRelativeSize(0.1 + 0.9 * (v/20.0));
96}

## Member Data Documentation

## ◆ shapes_

ShapesWidget* PaintExample::shapes_
| private

Definition at line 23 of file PaintExample.h.

The documentation for this class was generated from the following files:

- painting/PaintExample.h
- painting/PaintExample.C