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

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