DPF OpenGL examples
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.

128 lines
3.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2015 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. // ------------------------------------------------------
  17. // DGL Stuff
  18. #include "Application.hpp"
  19. #include "Window.hpp"
  20. #include "widgets/ExampleRectanglesWidget.hpp"
  21. // ------------------------------------------------------
  22. // Qt Stuff
  23. #include <QtGui/QApplication>
  24. #include <QtGui/QIcon>
  25. #include <QtGui/QResizeEvent>
  26. #if DISTRHO_OS_LINUX
  27. # include <QtGui/QX11EmbedContainer>
  28. typedef QX11EmbedContainer QWidgetContainer;
  29. #elif DISTRHO_OS_MAC
  30. # include <QtGui/QMacCocoaViewContainer>
  31. typedef QMacCocoaViewContainer QWidgetContainer;
  32. #else
  33. # define DISTRHO_NEEDS_WINDOW_SIZE
  34. # include <QtGui/QWidget>
  35. typedef QWidget QWidgetContainer;
  36. #endif
  37. // ------------------------------------------------------
  38. // Qt widget
  39. template<class DGLWidget>
  40. class DGLtoQtWidget : public QWidgetContainer
  41. {
  42. public:
  43. DGLtoQtWidget(QWidget* const qParent = nullptr)
  44. #if DISTRHO_OS_MAC
  45. : QWidgetContainer(nullptr, qParent),
  46. glApp(),
  47. glWindow(glApp, 0),
  48. #else
  49. : QWidgetContainer(qParent),
  50. glApp(),
  51. glWindow(glApp, winId()),
  52. #endif
  53. glWidget(glWindow),
  54. qTimerId(startTimer(30))
  55. {
  56. #if DISTRHO_OS_MAC
  57. //NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  58. //[pool release];
  59. setCocoaView((void*)glWindow.getWindowId());
  60. #endif
  61. }
  62. ~DGLtoQtWidget() override
  63. {
  64. killTimer(qTimerId);
  65. glWindow.close();
  66. }
  67. protected:
  68. void resizeEvent(QResizeEvent* const event) override
  69. {
  70. const QSize& size(event->size());
  71. glWidget.setSize(size.width(), size.height());
  72. #ifdef DISTRHO_NEEDS_WINDOW_SIZE
  73. // only needed if not handled by qt
  74. glWindow.setSize(size.width(), size.height());
  75. #endif
  76. QWidgetContainer::resizeEvent(event);
  77. }
  78. void timerEvent(QTimerEvent* const event) override
  79. {
  80. if (event->timerId() == qTimerId)
  81. glApp.idle();
  82. QWidgetContainer::timerEvent(event);
  83. }
  84. private:
  85. App glApp;
  86. Window glWindow;
  87. DGLWidget glWidget;
  88. const int qTimerId;
  89. };
  90. #ifdef DISTRHO_NEEDS_WINDOW_SIZE
  91. # undef DISTRHO_NEEDS_WINDOW_SIZE
  92. #endif
  93. // ------------------------------------------------------
  94. // main entry point
  95. int main(int argc, char* argv[])
  96. {
  97. QApplication app(argc, argv);
  98. app.setWindowIcon(QIcon::fromTheme("firefox"));
  99. DGLtoQtWidget<ExampleRectanglesWidget> widget;
  100. widget.setWindowIcon(QIcon::fromTheme("firefox"));
  101. widget.resize(300, 300);
  102. widget.show();
  103. return app.exec();
  104. }
  105. // ------------------------------------------------------