Wt examples  3.3.6
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PaintExample Class Reference

#include <PaintExample.h>

Inheritance diagram for PaintExample:
Inheritance graph
[legend]

Public Member Functions

 PaintExample (WContainerWidget *root, bool showTitle=true)
 

Private Member Functions

void rotateShape (int v)
 
void scaleShape (int v)
 

Private Attributes

ShapesWidgetshapes_
 

Detailed Description

Definition at line 17 of file PaintExample.h.

Constructor & Destructor Documentation

◆ PaintExample()

PaintExample::PaintExample ( WContainerWidget *  root,
bool  showTitle = true 
)

Definition at line 17 of file PaintExample.C.

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);
46  emweb->setMargin(WLength::Auto, Left | Right);
47 
48  WGridLayout *layout = new WGridLayout();
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);
56  scaleSlider->setTickPosition(WSlider::TicksBothSides);
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);
67  rotateSlider->setTickPosition(WSlider::TicksBothSides);
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);
76  shapes_->setPreferredMethod(WPaintedWidget::HtmlCanvas);
77 
78  layout->addWidget(shapes_, 1, 1, AlignCenter | AlignMiddle);
79 }
void scaleShape(int v)
Definition: PaintExample.C:90
ShapesWidget * shapes_
Definition: PaintExample.h:23
void rotateShape(int v)
Definition: PaintExample.C:81
void setAngle(double angle)
Definition: ShapesWidget.C:32
void setRelativeSize(double size)
Definition: ShapesWidget.C:42

Member Function Documentation

◆ rotateShape()

void PaintExample::rotateShape ( int  v)
private

Definition at line 81 of file PaintExample.C.

82 {
83  shapes_->setAngle(v / 2.0);
84 
85  // Being silly: test alternate rendering method
86  shapes_->setPreferredMethod(v < 0 ? WPaintedWidget::InlineSvgVml
87  : WPaintedWidget::HtmlCanvas);
88 }
ShapesWidget * shapes_
Definition: PaintExample.h:23
void setAngle(double angle)
Definition: ShapesWidget.C:32

◆ scaleShape()

void PaintExample::scaleShape ( int  v)
private

Definition at line 90 of file PaintExample.C.

91 {
92  shapes_->setRelativeSize(0.1 + 0.9 * (v/20.0));
93 }
ShapesWidget * shapes_
Definition: PaintExample.h:23
void setRelativeSize(double size)
Definition: ShapesWidget.C:42

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:

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.13