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.

80 lines
2.2KB

  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. DemoWidgetClickable::DemoWidgetClickable(Widget* group)
  20. : Widget(group)
  21. {
  22. }
  23. void DemoWidgetClickable::onDisplay()
  24. {
  25. cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
  26. Size<uint> sz = getSize();
  27. int w = sz.getWidth();
  28. int h = sz.getHeight();
  29. switch (fColorId)
  30. {
  31. case 0:
  32. cairo_set_source_rgb(cr, 0.75, 0.0, 0.0);
  33. break;
  34. case 1:
  35. cairo_set_source_rgb(cr, 0.0, 0.75, 0.0);
  36. break;
  37. case 2:
  38. cairo_set_source_rgb(cr, 0.0, 0.0, 0.75);
  39. break;
  40. }
  41. cairo_rectangle(cr, 0, 0, w, h);
  42. cairo_fill(cr);
  43. cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
  44. cairo_new_path(cr);
  45. cairo_move_to(cr, 0.25 * w, 0.25 * h);
  46. cairo_line_to(cr, 0.75 * w, 0.75 * h);
  47. cairo_stroke(cr);
  48. cairo_new_path(cr);
  49. cairo_move_to(cr, 0.75 * w, 0.25 * h);
  50. cairo_line_to(cr, 0.25 * w, 0.75 * h);
  51. cairo_stroke(cr);
  52. }
  53. bool DemoWidgetClickable::onMouse(const MouseEvent& event)
  54. {
  55. if (event.press)
  56. {
  57. int w = getWidth();
  58. int h = getHeight();
  59. int mx = event.pos.getX();
  60. int my = event.pos.getY();
  61. bool inside = mx >= 0 && my >= 0 && mx < w && my < h;
  62. if (inside)
  63. {
  64. fColorId = (fColorId + 1) % 3;
  65. repaint();
  66. }
  67. }
  68. return Widget::onMouse(event);
  69. }