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.

299 lines
6.5KB

  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. #include "WindowPrivateData.hpp"
  17. #include "pugl.hpp"
  18. START_NAMESPACE_DGL
  19. // -----------------------------------------------------------------------
  20. // Window
  21. // Window::Window(Window& transientParentWindow)
  22. // : pData(new PrivateData(transientParentWindow.pData->fAppData, this, transientParentWindow)) {}
  23. Window::Window(Application& app)
  24. : pData(new PrivateData(app, this)) {}
  25. Window::Window(Application& app,
  26. const uintptr_t parentWindowHandle,
  27. const uint width,
  28. const uint height,
  29. const double scaling,
  30. const bool resizable)
  31. : pData(new PrivateData(app, this, parentWindowHandle, width, height, scaling, resizable)) {}
  32. Window::~Window()
  33. {
  34. delete pData;
  35. }
  36. bool Window::isEmbed() const noexcept
  37. {
  38. return pData->isEmbed;
  39. }
  40. bool Window::isVisible() const noexcept
  41. {
  42. return pData->isVisible;
  43. }
  44. void Window::setVisible(const bool visible)
  45. {
  46. if (visible)
  47. pData->show();
  48. else
  49. pData->hide();
  50. }
  51. void Window::show()
  52. {
  53. pData->show();
  54. }
  55. void Window::hide()
  56. {
  57. pData->hide();
  58. }
  59. void Window::close()
  60. {
  61. pData->close();
  62. }
  63. uint Window::getWidth() const noexcept
  64. {
  65. return puglGetFrame(pData->view).width;
  66. }
  67. uint Window::getHeight() const noexcept
  68. {
  69. return puglGetFrame(pData->view).height;
  70. }
  71. Size<uint> Window::getSize() const noexcept
  72. {
  73. const PuglRect rect = puglGetFrame(pData->view);
  74. return Size<uint>(rect.width, rect.height);
  75. }
  76. void Window::setWidth(const uint width)
  77. {
  78. setSize(width, getHeight());
  79. }
  80. void Window::setHeight(const uint height)
  81. {
  82. setSize(getWidth(), height);
  83. }
  84. void Window::setSize(const uint width, const uint height)
  85. {
  86. DISTRHO_SAFE_ASSERT_UINT2_RETURN(width > 1 && height > 1, width, height,);
  87. puglSetWindowSize(pData->view, width, height);
  88. }
  89. void Window::setSize(const Size<uint>& size)
  90. {
  91. setSize(size.getWidth(), size.getHeight());
  92. }
  93. const char* Window::getTitle() const noexcept
  94. {
  95. return puglGetWindowTitle(pData->view);
  96. }
  97. void Window::setTitle(const char* const title)
  98. {
  99. puglSetWindowTitle(pData->view, title);
  100. }
  101. Application& Window::getApp() const noexcept
  102. {
  103. return pData->app;
  104. }
  105. uintptr_t Window::getNativeWindowHandle() const noexcept
  106. {
  107. return puglGetNativeWindow(pData->view);
  108. }
  109. void Window::repaint() noexcept
  110. {
  111. puglPostRedisplay(pData->view);
  112. }
  113. void Window::repaint(const Rectangle<uint>& rect) noexcept
  114. {
  115. const PuglRect prect = {
  116. static_cast<double>(rect.getX()),
  117. static_cast<double>(rect.getY()),
  118. static_cast<double>(rect.getWidth()),
  119. static_cast<double>(rect.getHeight()),
  120. };
  121. puglPostRedisplayRect(pData->view, prect);
  122. }
  123. void Window::onReshape(uint, uint)
  124. {
  125. puglFallbackOnResize(pData->view);
  126. }
  127. bool Window::onClose()
  128. {
  129. return true;
  130. }
  131. #if 0
  132. #if 0
  133. void Window::exec(bool lockWait)
  134. {
  135. pData->exec(lockWait);
  136. }
  137. #endif
  138. void Window::focus()
  139. {
  140. if (! pData->fUsingEmbed)
  141. puglRaiseWindow(pData->fView);
  142. puglGrabFocus(pData->fView);
  143. }
  144. bool Window::isResizable() const noexcept
  145. {
  146. return puglGetViewHint(pData->fView, PUGL_RESIZABLE) == PUGL_TRUE;
  147. }
  148. void Window::setResizable(const bool resizable)
  149. {
  150. DISTRHO_SAFE_ASSERT_RETURN(pData->fUsingEmbed,);
  151. if (pData->fUsingEmbed)
  152. {
  153. DGL_DBG("Window setResizable cannot be called when embedded\n");
  154. return;
  155. }
  156. DGL_DBG("Window setResizable called\n");
  157. puglSetViewHint(pData->fView, PUGL_RESIZABLE, resizable ? PUGL_TRUE : PUGL_FALSE);
  158. #ifdef DISTRHO_OS_WINDOWS
  159. puglWin32SetWindowResizable(pData->fView, resizable);
  160. #endif
  161. }
  162. bool Window::getIgnoringKeyRepeat() const noexcept
  163. {
  164. return puglGetViewHint(pData->fView, PUGL_IGNORE_KEY_REPEAT) == PUGL_TRUE;
  165. }
  166. void Window::setIgnoringKeyRepeat(const bool ignore) noexcept
  167. {
  168. puglSetViewHint(pData->fView, PUGL_IGNORE_KEY_REPEAT, ignore);
  169. }
  170. void Window::setGeometryConstraints(const uint width, const uint height, bool aspect)
  171. {
  172. // Did you forget to set DISTRHO_UI_USER_RESIZABLE ?
  173. DISTRHO_SAFE_ASSERT_RETURN(isResizable(),);
  174. puglUpdateGeometryConstraints(pData->fView, width, height, aspect);
  175. }
  176. void Window::setTransientWinId(const uintptr_t winId)
  177. {
  178. puglSetTransientFor(pData->fView, winId);
  179. }
  180. double Window::getScaling() const noexcept
  181. {
  182. return pData->fScaling;
  183. }
  184. #if 0
  185. Application& Window::getApp() const noexcept
  186. {
  187. return pData->fApp;
  188. }
  189. #endif
  190. void Window::_setAutoScaling(double scaling) noexcept
  191. {
  192. DISTRHO_SAFE_ASSERT_RETURN(scaling > 0.0,);
  193. pData->fAutoScaling = scaling;
  194. }
  195. void Window::_addWidget(Widget* const widget)
  196. {
  197. pData->addWidget(widget);
  198. }
  199. void Window::_removeWidget(Widget* const widget)
  200. {
  201. pData->removeWidget(widget);
  202. }
  203. void Window::_idle()
  204. {
  205. pData->windowSpecificIdle();
  206. }
  207. // -----------------------------------------------------------------------
  208. void Window::addIdleCallback(IdleCallback* const callback)
  209. {
  210. DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
  211. pData->fAppData->idleCallbacks.push_back(callback);
  212. }
  213. void Window::removeIdleCallback(IdleCallback* const callback)
  214. {
  215. DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
  216. pData->fAppData->idleCallbacks.remove(callback);
  217. }
  218. // -----------------------------------------------------------------------
  219. #ifndef DGL_FILE_BROWSER_DISABLED
  220. void Window::fileBrowserSelected(const char*)
  221. {
  222. }
  223. #endif
  224. bool Window::handlePluginKeyboard(const bool press, const uint key)
  225. {
  226. // TODO
  227. return false;
  228. // return pData->handlePluginKeyboard(press, key);
  229. }
  230. bool Window::handlePluginSpecial(const bool press, const Key key)
  231. {
  232. // TODO
  233. return false;
  234. // return pData->handlePluginSpecial(press, key);
  235. }
  236. #endif
  237. // -----------------------------------------------------------------------
  238. END_NAMESPACE_DGL