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.

85 lines
2.3KB

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