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.

314 lines
7.2KB

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