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.

104 lines
3.0KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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. #ifndef DGL_WIDGET_HPP_INCLUDED
  17. #define DGL_WIDGET_HPP_INCLUDED
  18. #include "Geometry.hpp"
  19. START_NAMESPACE_DGL
  20. // -----------------------------------------------------------------------
  21. class App;
  22. class Window;
  23. class Widget
  24. {
  25. public:
  26. explicit Widget(Window& parent);
  27. virtual ~Widget();
  28. bool isVisible() const noexcept;
  29. void setVisible(bool yesNo);
  30. void show();
  31. void hide();
  32. int getX() const noexcept;
  33. int getY() const noexcept;
  34. const Point<int>& getPos() const noexcept;
  35. void setX(int x) noexcept;
  36. void setY(int y) noexcept;
  37. void setPos(int x, int y) noexcept;
  38. void setPos(const Point<int>& pos) noexcept;
  39. int getWidth() const noexcept;
  40. int getHeight() const noexcept;
  41. const Size<int>& getSize() const noexcept;
  42. // virtual needed by cairo
  43. virtual void setWidth(int width) noexcept;
  44. virtual void setHeight(int height) noexcept;
  45. virtual void setSize(int width, int height) noexcept;
  46. virtual void setSize(const Size<int>& size) noexcept;
  47. uint getEventTimestamp() const noexcept;
  48. int getModifiers() const noexcept;
  49. App& getParentApp() const noexcept;
  50. Window& getParentWindow() const noexcept;
  51. /**
  52. Check if this widget contains the point defined by @a X and @a Y.
  53. */
  54. bool contains(int x, int y) const noexcept;
  55. /**
  56. Check if this widget contains the point @a pos.
  57. */
  58. bool contains(const Point<int>& pos) const noexcept;
  59. void repaint() noexcept;
  60. protected:
  61. virtual void onDisplay() = 0;
  62. virtual bool onKeyboard(bool press, uint key);
  63. virtual bool onMouse(int button, bool press, int x, int y);
  64. virtual bool onMotion(int x, int y);
  65. virtual bool onScroll(int x, int y, float dx, float dy);
  66. virtual bool onSpecial(bool press, Key key);
  67. virtual void onReshape(int width, int height);
  68. private:
  69. Window& fParent;
  70. bool fVisible;
  71. Rectangle<int> fArea;
  72. friend class CairoWidget;
  73. friend class Window;
  74. friend class StandaloneWindow;
  75. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Widget)
  76. };
  77. // -----------------------------------------------------------------------
  78. END_NAMESPACE_DGL
  79. #endif // DGL_WIDGET_HPP_INCLUDED