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.

74 lines
1.2KB

  1. #include "PianoKey.hpp"
  2. START_NAMESPACE_DISTRHO
  3. PianoKey::PianoKey()
  4. : fPressed(false),
  5. fImageNormal(),
  6. fImageDown(),
  7. fIndex(-1)
  8. {
  9. }
  10. void PianoKey::setImages(const Image& imageNormal, const Image& imageDown) noexcept
  11. {
  12. fImageNormal = imageNormal;
  13. fImageDown = imageDown;
  14. fBoundingBox.setSize(imageNormal.getWidth(), imageNormal.getHeight());
  15. }
  16. void PianoKey::setPressed(bool pressed) noexcept
  17. {
  18. fPressed = pressed;
  19. }
  20. bool PianoKey::isPressed() const noexcept
  21. {
  22. return fPressed;
  23. }
  24. void PianoKey::setIndex(const int index) noexcept
  25. {
  26. fIndex = index;
  27. }
  28. int PianoKey::getIndex() const noexcept
  29. {
  30. return fIndex;
  31. }
  32. bool PianoKey::contains(Point<int> point) const noexcept
  33. {
  34. return fBoundingBox.contains(point);
  35. }
  36. void PianoKey::setPosition(const int x, const int y) noexcept
  37. {
  38. fBoundingBox.setPos(x, y);
  39. }
  40. uint PianoKey::getWidth() const noexcept
  41. {
  42. return fBoundingBox.getWidth();
  43. }
  44. void PianoKey::draw() noexcept
  45. {
  46. Image* img;
  47. if (isPressed())
  48. {
  49. img = &fImageDown;
  50. }
  51. else
  52. {
  53. img = &fImageNormal;
  54. }
  55. img->drawAt(fBoundingBox.getPos());
  56. }
  57. END_NAMESPACE_DISTRHO