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.

87 lines
2.5KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. * Copyright (C) 2019-2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  7. * or without fee is hereby granted, provided that the above copyright notice and this
  8. * permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  11. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  12. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "DemoWidgetClickable.hpp"
  18. START_NAMESPACE_DGL
  19. // -----------------------------------------------------------------------
  20. DemoWidgetClickable::DemoWidgetClickable(SubWidget* parent)
  21. : CairoSubWidget(parent) {}
  22. DemoWidgetClickable::DemoWidgetClickable(TopLevelWidget* parent)
  23. : CairoSubWidget(parent) {}
  24. void DemoWidgetClickable::onCairoDisplay(const CairoGraphicsContext& context)
  25. {
  26. cairo_t* cr = context.handle;
  27. Size<uint> sz = getSize();
  28. int w = sz.getWidth();
  29. int h = sz.getHeight();
  30. switch (fColorId)
  31. {
  32. case 0:
  33. cairo_set_source_rgb(cr, 0.75, 0.0, 0.0);
  34. break;
  35. case 1:
  36. cairo_set_source_rgb(cr, 0.0, 0.75, 0.0);
  37. break;
  38. case 2:
  39. cairo_set_source_rgb(cr, 0.0, 0.0, 0.75);
  40. break;
  41. }
  42. cairo_rectangle(cr, 0, 0, w, h);
  43. cairo_fill(cr);
  44. cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
  45. cairo_new_path(cr);
  46. cairo_move_to(cr, 0.25 * w, 0.25 * h);
  47. cairo_line_to(cr, 0.75 * w, 0.75 * h);
  48. cairo_stroke(cr);
  49. cairo_new_path(cr);
  50. cairo_move_to(cr, 0.75 * w, 0.25 * h);
  51. cairo_line_to(cr, 0.25 * w, 0.75 * h);
  52. cairo_stroke(cr);
  53. }
  54. bool DemoWidgetClickable::onMouse(const MouseEvent& event)
  55. {
  56. if (event.press)
  57. {
  58. int w = getWidth();
  59. int h = getHeight();
  60. int mx = event.pos.getX();
  61. int my = event.pos.getY();
  62. bool inside = mx >= 0 && my >= 0 && mx < w && my < h;
  63. if (inside)
  64. {
  65. fColorId = (fColorId + 1) % 3;
  66. repaint();
  67. }
  68. }
  69. return Widget::onMouse(event);
  70. }
  71. // -----------------------------------------------------------------------
  72. END_NAMESPACE_DGL