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.

117 lines
3.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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_APP_PRIVATE_DATA_HPP_INCLUDED
  17. #define DGL_APP_PRIVATE_DATA_HPP_INCLUDED
  18. #include "../Application.hpp"
  19. #include "../Window.hpp"
  20. #include "pugl-upstream/include/pugl/pugl.h"
  21. #include <list>
  22. START_NAMESPACE_DGL
  23. // -----------------------------------------------------------------------
  24. struct Application::PrivateData {
  25. bool isQuitting;
  26. bool isStandalone;
  27. uint visibleWindows;
  28. std::list<Window*> windows;
  29. std::list<IdleCallback*> idleCallbacks;
  30. PuglWorld* const world;
  31. PrivateData(const bool standalone)
  32. : isQuitting(false),
  33. isStandalone(standalone),
  34. visibleWindows(0),
  35. windows(),
  36. idleCallbacks(),
  37. world(puglNewWorld(isStandalone ? PUGL_PROGRAM : PUGL_MODULE,
  38. isStandalone ? PUGL_WORLD_THREADS : 0x0))
  39. {
  40. puglSetWorldHandle(world, this);
  41. // TODO puglSetClassName
  42. }
  43. ~PrivateData()
  44. {
  45. DISTRHO_SAFE_ASSERT(isQuitting);
  46. DISTRHO_SAFE_ASSERT(visibleWindows == 0);
  47. windows.clear();
  48. idleCallbacks.clear();
  49. puglFreeWorld(world);
  50. }
  51. void oneWindowShown() noexcept
  52. {
  53. DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
  54. if (++visibleWindows == 1)
  55. isQuitting = false;
  56. }
  57. void oneWindowHidden() noexcept
  58. {
  59. DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
  60. DISTRHO_SAFE_ASSERT_RETURN(visibleWindows > 0,);
  61. if (--visibleWindows == 0)
  62. isQuitting = true;
  63. }
  64. void idle(const uint timeout)
  65. {
  66. puglUpdate(world, timeout == 0 ? 0.0 : (1.0 / static_cast<double>(timeout)));
  67. for (std::list<Window*>::iterator it = windows.begin(), ite = windows.end(); it != ite; ++it)
  68. {
  69. Window* const window(*it);
  70. window->_idle();
  71. }
  72. for (std::list<IdleCallback*>::iterator it = idleCallbacks.begin(), ite = idleCallbacks.end(); it != ite; ++it)
  73. {
  74. IdleCallback* const idleCallback(*it);
  75. idleCallback->idleCallback();
  76. }
  77. }
  78. void quit()
  79. {
  80. isQuitting = true;
  81. for (std::list<Window*>::reverse_iterator rit = windows.rbegin(), rite = windows.rend(); rit != rite; ++rit)
  82. {
  83. Window* const window(*rit);
  84. window->close();
  85. }
  86. }
  87. DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData)
  88. };
  89. // -----------------------------------------------------------------------
  90. END_NAMESPACE_DGL
  91. #endif // DGL_APP_PRIVATE_DATA_HPP_INCLUDED