DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.2KB

  1. // Copyright Jean Pierre Cimalando 2018.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include "DemoWidgetBanner.h"
  6. #include "Cairo.hpp"
  7. #include "Window.hpp"
  8. static const char *banner =
  9. " "
  10. " * * * * * "
  11. " ** ** * * * * "
  12. " * * * * * * * "
  13. " * * * **** *** * **** * * ** **** * *** "
  14. " * * * * ** * * * * * * ** * "
  15. " * * ***** * * ****** * * * * * * * "
  16. " * * * * * * * * * * * * * * "
  17. " * * * ** * ** * * * * * * * * * * "
  18. " * * *** * *** * **** ** ** ***** ** * * "
  19. " "
  20. " "
  21. " "
  22. " ***** **** ***** "
  23. " * * * * * "
  24. " * * * * * "
  25. " * * * * * "
  26. " * * **** **** "
  27. " * * * * "
  28. " * * * * "
  29. " * * * * "
  30. " ***** * * "
  31. " ";
  32. enum {
  33. rows = 23,
  34. columns = 72,
  35. };
  36. DemoWidgetBanner::DemoWidgetBanner(Widget *group)
  37. : Widget(group)
  38. {
  39. }
  40. void DemoWidgetBanner::onDisplay()
  41. {
  42. cairo_t *cr = getParentWindow().getGraphicsContext().cairo;
  43. Point<int> pt = getAbsolutePos();
  44. Size<uint> sz = getSize();
  45. int x = pt.getX();
  46. int y = pt.getY();
  47. int w = sz.getWidth();
  48. int h = sz.getHeight();
  49. double diameter = (double)w / columns;
  50. double radius = 0.5 * diameter;
  51. double xoff = 0;
  52. double yoff = 0.5 * (h - rows * diameter);
  53. for (int r = 0; r < rows; ++r) {
  54. for (int c = 0; c < columns; ++c) {
  55. double cx = x + xoff + radius + c * diameter;
  56. double cy = y + yoff + radius + r * diameter;
  57. char ch = banner[c + r * columns];
  58. if (ch != ' ')
  59. cairo_set_source_rgb(cr, 0.5, 0.9, 0.2);
  60. else
  61. cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
  62. cairo_save(cr);
  63. cairo_translate(cr, cx, cy);
  64. cairo_scale(cr, radius, radius);
  65. cairo_arc(cr, 0.0, 0.0, 1.0, 0.0, 2 * M_PI);
  66. cairo_restore(cr);
  67. cairo_fill(cr);
  68. }
  69. }
  70. }