Wt examples 4.7.2
PaintExample.C
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
3 *
4 * See the LICENSE file for terms of use.
5 */
6
7#include <Wt/WContainerWidget.h>
8#include <Wt/WGridLayout.h>
9#include <Wt/WSlider.h>
10#include <Wt/WText.h>
11#include <iostream>
12
13#include "PaintExample.h"
14#include "ShapesWidget.h"
15
16using namespace Wt;
17
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);
78 shapes_->setPreferredMethod(RenderMethod::HtmlCanvas);
79
80 layout_->addWidget(std::move(shapes), 1, 1,
81 AlignmentFlag::Center | AlignmentFlag::Middle);
82}
83
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}
92
94{
95 shapes_->setRelativeSize(0.1 + 0.9 * (v/20.0));
96}
void rotateShape(int v)
Definition: PaintExample.C:84
ShapesWidget * shapes_
Definition: PaintExample.h:23
void scaleShape(int v)
Definition: PaintExample.C:93
PaintExample(bool showTitle=true)
Definition: PaintExample.C:18
void setAngle(double angle)
Definition: ShapesWidget.C:33
void setRelativeSize(double size)
Definition: ShapesWidget.C:43

Generated on Fri May 13 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.4