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.

88 lines
2.4KB

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