Wt examples 3.3.12
PaintExample.C
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
3 *
4 * See the LICENSE file for terms of use.
5 */
6
7#include <Wt/WContainerWidget>
8#include <Wt/WGridLayout>
9#include <Wt/WSlider>
10#include <Wt/WText>
11
12#include "PaintExample.h"
13#include "ShapesWidget.h"
14
15using namespace Wt;
16
18 : WContainerWidget(root)
19{
20 std::string text;
21 if (showTitle)
22 text += "<h2>Paint example</h2>";
23
24 text +=
25 "<p>A simple example demonstrating cross-browser vector graphics."
26 "</p>"
27 "<p>The emweb logo below is painted using the Wt WPainter API from "
28 "bezier paths, and rendered to the browser using inline SVG, inline VML "
29 "or the HTML 5 &lt;canvas&gt; element."
30 "</p>"
31 "<p>"
32 "The example also demonstrates the horizontal and vertical "
33 "<a href=\"http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WSlider.html\" target=\"_blank\">"
34 "WSlider</a> widgets. Here,"
35 "the events of the WSlider widgets are used to scale and rotate the "
36 "emweb logo."
37 "</p>"
38 "<p>"
39 "In non-IE browsers, a different backend is used for positive or negative "
40 "angles (SVG or HTML canvas)."
41 "</p>";
42
43 new WText(text, this);
44
45 WContainerWidget *emweb = new WContainerWidget(this);
47
49 emweb->setLayout(layout);
50
51 WSlider *scaleSlider = new WSlider(Horizontal);
52 scaleSlider->setMinimum(0);
53 scaleSlider->setMaximum(20);
54 scaleSlider->setValue(10);
55 scaleSlider->setTickInterval(5);
57 scaleSlider->resize(300, 50);
58 scaleSlider->sliderMoved().connect(this, &PaintExample::scaleShape);
59
60 layout->addWidget(scaleSlider, 0, 1, AlignCenter | AlignMiddle);
61
62 WSlider *rotateSlider = new WSlider(Vertical);
63 rotateSlider->setMinimum(-30);
64 rotateSlider->setMaximum(30);
65 rotateSlider->setValue(0);
66 rotateSlider->setTickInterval(10);
68 rotateSlider->resize(50, 400);
69 rotateSlider->sliderMoved().connect(this, &PaintExample::rotateShape);
70
71 layout->addWidget(rotateSlider, 1, 0, AlignCenter | AlignMiddle);
72
73 shapes_ = new ShapesWidget();
74 shapes_->setAngle(0.0);
77
79}
80
82{
83 shapes_->setAngle(v / 2.0);
84
85 // Being silly: test alternate rendering method
88}
89
91{
92 shapes_->setRelativeSize(0.1 + 0.9 * (v/20.0));
93}
void rotateShape(int v)
PaintExample(WContainerWidget *root, bool showTitle=true)
ShapesWidget * shapes_
void scaleShape(int v)
void setAngle(double angle)
void setRelativeSize(double size)
Wt::Signals::connection connect(const F &function)
void setLayout(WLayout *layout)
void addWidget(WWidget *widget)
static WLength Auto
void setPreferredMethod(Method method)
void setTickInterval(int tickInterval)
JSignal< int > & sliderMoved()
void setTickPosition(WFlags< TickPosition > tickPosition)
virtual void resize(const WLength &width, const WLength &height)
static const Wt::WFlags< TickPosition > TicksBothSides
void setMaximum(int maximum)
void setMinimum(int minimum)
virtual void setValue(int value)
virtual void setMargin(const WLength &margin, WFlags< Side > sides=All)
Horizontal
Vertical
AlignCenter
AlignMiddle

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8