Audio plugin host https://kx.studio/carla
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.

StandaloneWindow.hpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_STANDALONE_WINDOW_HPP_INCLUDED
  17. #define DGL_STANDALONE_WINDOW_HPP_INCLUDED
  18. #include "App.hpp"
  19. #include "Widget.hpp"
  20. #include "Window.hpp"
  21. START_NAMESPACE_DGL
  22. // -----------------------------------------------------------------------
  23. class StandaloneWindow : public App,
  24. public Window
  25. {
  26. public:
  27. StandaloneWindow()
  28. : App(),
  29. Window((App&)*this),
  30. fWidget(nullptr) {}
  31. void exec()
  32. {
  33. Window::show();
  34. App::exec();
  35. }
  36. protected:
  37. void onReshape(uint width, uint height) override
  38. {
  39. if (fWidget != nullptr)
  40. fWidget->setSize(width, height);
  41. Window::onReshape(width, height);
  42. }
  43. private:
  44. Widget* fWidget;
  45. void _addWidget(Widget* widget) override
  46. {
  47. if (fWidget == nullptr)
  48. {
  49. fWidget = widget;
  50. fWidget->setNeedsFullViewport(true);
  51. }
  52. Window::_addWidget(widget);
  53. }
  54. void _removeWidget(Widget* widget) override
  55. {
  56. if (fWidget == widget)
  57. {
  58. fWidget->setNeedsFullViewport(false);
  59. fWidget = nullptr;
  60. }
  61. Window::_removeWidget(widget);
  62. }
  63. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneWindow)
  64. };
  65. // -----------------------------------------------------------------------
  66. END_NAMESPACE_DGL
  67. #endif // DGL_STANDALONE_WINDOW_HPP_INCLUDED