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.

ui_launcher.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Carla Native Plugin UI launcher
  3. * Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "dgl/Application.hpp"
  18. #include "dgl/ImageWidgets.hpp"
  19. #include "CarlaNative.h"
  20. #include "ui_launcher_res.hpp"
  21. #include "CarlaDefines.h"
  22. // --------------------------------------------------------------------------------------------------------------------
  23. START_NAMESPACE_DGL
  24. class CarlaButtonWidget : public Widget,
  25. private ImageButton::Callback
  26. {
  27. public:
  28. CarlaButtonWidget(Window& parent, const NativePluginDescriptor* const d, const NativePluginHandle h)
  29. : Widget(parent),
  30. startButtonImage(ui_launcher_res::carla_uiData,
  31. ui_launcher_res::carla_uiWidth,
  32. ui_launcher_res::carla_uiHeight,
  33. GL_BGR),
  34. startButton(this, startButtonImage),
  35. descriptor(d),
  36. handle(h)
  37. {
  38. startButton.setCallback(this);
  39. setSize(startButtonImage.getSize());
  40. parent.setSize(startButtonImage.getSize());
  41. }
  42. protected:
  43. void onDisplay() override
  44. {
  45. }
  46. void imageButtonClicked(ImageButton* imageButton, int) override
  47. {
  48. if (imageButton != &startButton)
  49. return;
  50. if (descriptor->ui_show != nullptr)
  51. descriptor->ui_show(handle, true);
  52. }
  53. private:
  54. Image startButtonImage;
  55. ImageButton startButton;
  56. const NativePluginDescriptor* const descriptor;
  57. const NativePluginHandle handle;
  58. CARLA_DECLARE_NON_COPY_CLASS(CarlaButtonWidget);
  59. };
  60. END_NAMESPACE_DGL
  61. // --------------------------------------------------------------------------------------------------------------------
  62. struct CarlaUILauncher {
  63. DGL_NAMESPACE::Application app;
  64. DGL_NAMESPACE::Window window;
  65. CarlaButtonWidget widget;
  66. CarlaUILauncher(const intptr_t winId, const NativePluginDescriptor* const d, const NativePluginHandle h)
  67. : app(),
  68. window(app, winId),
  69. widget(window, d, h) {}
  70. };
  71. CarlaUILauncher* createUILauncher(const intptr_t winId,
  72. const NativePluginDescriptor* const d,
  73. const NativePluginHandle h)
  74. {
  75. return new CarlaUILauncher(winId, d, h);
  76. }
  77. void idleUILauncher(CarlaUILauncher* const ui)
  78. {
  79. ui->app.idle();
  80. }
  81. void destoryUILauncher(CarlaUILauncher* const ui)
  82. {
  83. delete ui;
  84. }
  85. // --------------------------------------------------------------------------------------------------------------------