Wt examples  4.10.4
ShapesWidget.C
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4  *
5  * See the LICENSE file for terms of use.
6  */
7 
8 #include "ShapesWidget.h"
9 
10 #include <Wt/WPainter.h>
11 #include <Wt/WPainterPath.h>
12 #include <Wt/WPointF.h>
13 #include <Wt/WRectF.h>
14 #include <Wt/WAny.h>
15 
16 #include <math.h>
17 #include <iostream>
18 #include <algorithm>
19 
20 namespace {
21  // the blue emweb color
22  WColor emweb(0x04, 0x7c, 0x93);
23 }
24 
26  : WPaintedWidget(),
27  angle_(0),
28  size_(1)
29 {
30  resize(710, 400);
31 }
32 
33 void ShapesWidget::setAngle(double angle)
34 {
35  angle = std::max(-30.0, std::min(30.0, angle));
36 
37  if (angle_ != angle) {
38  angle_ = angle;
39  update();
40  }
41 }
42 
44 {
45  size = std::max(0.1, std::min(1.0, size));
46 
47  if (size_ != size) {
48  size_ = size;
49  update();
50  }
51 }
52 
54 {
55  WPainter painter(paintDevice);
56 
57  painter.setShadow(WShadow(10, 10, WColor(0, 0, 0, 50), 10));
58  painter.setRenderHint(RenderHint::Antialiasing);
59 
60  painter.translate(width().value()/2, height().value()/2);
61  painter.rotate(angle_);
62  painter.scale(size_, size_);
63  painter.translate(-width().value()/2 + 50, -height().value()/2 + 150);
64 
65  drawEmwebLogo(painter);
66 }
67 
69 {
70  WPainterPath p;
71 
72  /* Path copied from our SVG for half of the E */
73 
74  p.moveTo(46.835084,58.783624);
75  p.cubicTo(45.700172,58.783624,35.350098,58.911502,24.656354,63.283309);
76  p.cubicTo(8.7595992,69.78907,0,82.38499,0,98.809238);
77  p.cubicTo(0,115.20152,08.7595992,127.82141,24.656354,134.31119);
78  p.cubicTo(35.350098,138.69099,45.700172,138.81088,46.835084,138.81088);
79  p.lineTo(94.509362,138.81088);
80  p.lineTo(94.509362,117.58323);
81  p.lineTo(46.835084,117.58323);
82  p.cubicTo(46.811106,117.58323,39.466151,117.47134,32.608727,114.53815);
83  p.cubicTo(25.095932,111.34122,21.747144,106.47389,21.747144,98.809238);
84  p.cubicTo(21.747144,91.120612,25.095932,86.269265,32.608727,83.064338);
85  p.cubicTo(39.466151,80.123159,46.811106,80.027251,46.89103,80.027251);
86  p.lineTo(94.509362,80.027251);
87  p.lineTo(94.509362,58.783624);
88  p.lineTo(46.835084,58.783624);
89 
90  painter.drawPath(p);
91 
92  painter.save();
93  painter.translate(0,-58.783624);
94  painter.drawPath(p);
95  painter.restore();
96 }
97 
99 {
100  WPainterPath p;
101 
102  /* Path copied from our SVG for one fourth of the MW */
103 
104  p.moveTo(120.59634,24.072913);
105  p.cubicTo(116.12064,34.518895,115.98477,44.605222,115.98477,45.732141);
106  p.lineTo(115.98477,138.81088);
107  p.lineTo(137.7399,138.81088);
108  p.lineTo(137.7399,45.732141);
109  p.cubicTo(137.7399,45.708164,137.83581,38.53904,140.84892,31.841463);
110  p.cubicTo(144.14176,24.512492,149.113,21.235634,156.98545,21.235634);
111  p.cubicTo(164.8499,21.235634,169.81314,24.512492,173.10599,31.841463);
112  p.cubicTo(176.10311,38.53904,176.215,45.708164,176.215,45.780095);
113  p.lineTo(176.215,70.41343);
114  p.lineTo(197.97014,70.41343);
115  p.lineTo(197.97014,45.732141);
116  p.cubicTo(197.97014,44.605222,197.83427,34.518895,193.35057,24.072913);
117  p.cubicTo(186.70894,8.5517985,173.77734,0,156.99344,0);
118  p.cubicTo(140.17756,0,127.25396,8.5517985,120.59634,24.072913);
119 
120  /*
121  * Paint it four times, translated and inverted
122  */
123 
124  painter.drawPath(p);
125 
126  const double dx = 176. - 115.98477;
127 
128  painter.save();
129 
130  painter.translate(dx, 0);
131  painter.drawPath(p);
132 
133  painter.translate(dx, 0);
134 
135  painter.scale(-1, -1);
136  painter.translate(0, -138.81088);
137  painter.translate(-115.98477 - 197.95 - dx, 0);
138  painter.drawPath(p);
139 
140  painter.translate(dx, 0);
141  painter.drawPath(p);
142 
143  painter.restore();
144 }
145 
147 {
148  painter.save();
149  painter.setPen(WPen(PenStyle::None));
150 
151  /*
152  * The emweb logo can be drawn as 3 e's, and one combined m/w
153  */
154 
155  // Emweb
157  drawEmwebE(painter);
158 
159  // emwEb
160  painter.save();
161  painter.translate(397, 0);
162  drawEmwebE(painter);
163 
164  // emweB
165  painter.translate(210, 0);
166  painter.scale(-1, 1);
167  drawEmwebE(painter);
168 
169  painter.restore();
170 
171  // eMWeb
172  painter.setBrush(emweb);
173  drawEmwebMW(painter);
174 
175  painter.restore();
176 }
void drawEmwebMW(WPainter &p)
Definition: ShapesWidget.C:98
double size_
Definition: ShapesWidget.h:35
void drawEmwebE(WPainter &p)
Definition: ShapesWidget.C:68
void setAngle(double angle)
Definition: ShapesWidget.C:33
virtual void paintEvent(WPaintDevice *paintDevice) override
Definition: ShapesWidget.C:53
void drawEmwebLogo(WPainter &p)
Definition: ShapesWidget.C:146
double angle() const
Definition: ShapesWidget.h:25
double angle_
Definition: ShapesWidget.h:34
void setRelativeSize(double size)
Definition: ShapesWidget.C:43
virtual void resize(const WLength &width, const WLength &height) override
void update(WFlags< PaintFlag > flags=None)
void moveTo(const WPointF &point)
void lineTo(const WPointF &point)
void cubicTo(const WPointF &c1, const WPointF &c2, const WPointF &endPoint)
void scale(double sx, double sy)
void setPen(const WPen &pen)
void drawPath(const WPainterPath &path)
void restore()
void setShadow(const WShadow &shadow)
void translate(const WPointF &offset)
void rotate(double angle)
void setBrush(const WBrush &brush)
void setRenderHint(RenderHint hint, bool on=true)
virtual WLength width() const override
virtual WLength height() const override