ShapesWidget.C 4.1 KB

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