LMMS
Loading...
Searching...
No Matches
ui_launcher.cpp
Go to the documentation of this file.
1/*
2 * Carla Native Plugin UI launcher
3 * Copyright (C) 2018-2023 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
18#include "dgl/OpenGL.hpp"
19#include "dgl/src/pugl.hpp"
20#include "dgl/src/WindowPrivateData.hpp"
21
22#include "CarlaNative.h"
23#include "ui_launcher_res.hpp"
24#include "CarlaDefines.h"
25
26// --------------------------------------------------------------------------------------------------------------------
27
29
30class PluginApplication : public DGL_NAMESPACE::Application
31{
32public:
34 : Application(false)
35 {
36 setClassName("CarlaPluginWrapper");
37 }
38};
39
40class PluginWindow : public DGL_NAMESPACE::Window
41{
42public:
43 explicit PluginWindow(PluginApplication& app, const uintptr_t winId)
44 : Window(app, winId, ui_launcher_res::carla_uiWidth, ui_launcher_res::carla_uiHeight, 0.0, false, false, false)
45 {
46 // this is called just before creating UI, ensuring proper context to it
47 if (pData->view != nullptr && pData->initPost())
48 puglBackendEnter(pData->view);
49 }
50
52 {
53 if (pData->view != nullptr)
54 puglBackendLeave(pData->view);
55 }
56
57 // called right before deleting UI, ensuring correct context
59 {
60 if (pData->view != nullptr)
61 puglBackendEnter(pData->view);
62 }
63
64 // called after creating UI, restoring proper context
66 {
67 if (pData->view != nullptr)
68 puglBackendLeave(pData->view);
69 }
70};
71
73
74// --------------------------------------------------------------------------------------------------------------------
75
76START_NAMESPACE_DGL
77
78class CarlaButtonWidget : public TopLevelWidget,
79 private OpenGLImageButton::Callback
80{
81public:
83 : TopLevelWidget(parent),
84 startButtonImage(ui_launcher_res::carla_uiData,
85 ui_launcher_res::carla_uiWidth,
86 ui_launcher_res::carla_uiHeight,
87 kImageFormatBGR),
90 handle(h),
92 {
93 const uint width = ui_launcher_res::carla_uiWidth;
94 const uint height = ui_launcher_res::carla_uiHeight;
95
96 Widget::setSize(width, height);
97 setGeometryConstraints(width, height, true, true, true);
98
99 startButton.setCallback(this);
100
101 pluginWindow.leaveContextAfterCreation();
102 }
103
105 {
106 pluginWindow.enterContextForDeletion();
107 }
108
109protected:
110 void onDisplay() override
111 {
112 }
113
114 void imageButtonClicked(OpenGLImageButton* imageButton, int) override
115 {
116 if (imageButton != &startButton)
117 return;
118
119 if (descriptor->ui_show != nullptr)
120 descriptor->ui_show(handle, true);
121 }
122
123private:
124 OpenGLImage startButtonImage;
125 OpenGLImageButton startButton;
129
131};
132
133END_NAMESPACE_DGL
134
135// --------------------------------------------------------------------------------------------------------------------
136
137USE_NAMESPACE_DGL
138
149
150CarlaUILauncher* createUILauncher(const uintptr_t winId,
151 const NativePluginDescriptor* const d,
152 const NativePluginHandle h)
153{
154 return new CarlaUILauncher(winId, d, h);
155}
156
157void getUILauncherSize(CarlaUILauncher* const ui, VstRect* const rect)
158{
159 rect->right = ui->window.getWidth();
160 rect->bottom = ui->window.getHeight();
161 #ifdef DISTRHO_OS_MAC
162 const double scaleFactor = ui->window.getScaleFactor();
163 rect->right /= scaleFactor;
164 rect->bottom /= scaleFactor;
165 #endif
166}
167
169{
170 ui->app.idle();
171}
172
174{
175 delete ui;
176}
177
178// --------------------------------------------------------------------------------------------------------------------
unsigned int uint
Definition CarlaDefines.h:327
class MasterUI * ui
Definition Connection.cpp:39
#define END_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:191
#define START_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:190
Definition ui_launcher.cpp:80
PluginWindow & pluginWindow
Definition ui_launcher.cpp:128
OpenGLImage startButtonImage
Definition ui_launcher.cpp:124
~CarlaButtonWidget() override
Definition ui_launcher.cpp:104
const NativePluginHandle handle
Definition ui_launcher.cpp:127
OpenGLImageButton startButton
Definition ui_launcher.cpp:125
CARLA_DECLARE_NON_COPYABLE(CarlaButtonWidget)
CarlaButtonWidget(PluginWindow &parent, const NativePluginDescriptor *const d, const NativePluginHandle h)
Definition ui_launcher.cpp:82
const NativePluginDescriptor *const descriptor
Definition ui_launcher.cpp:126
void onDisplay() override
Definition ui_launcher.cpp:110
void imageButtonClicked(OpenGLImageButton *imageButton, int) override
Definition ui_launcher.cpp:114
Definition ui_launcher.cpp:31
PluginApplication()
Definition ui_launcher.cpp:33
Definition ui_launcher.cpp:41
PluginWindow(PluginApplication &app, const uintptr_t winId)
Definition ui_launcher.cpp:43
void leaveContextAfterCreation()
Definition ui_launcher.cpp:65
void enterContextForDeletion()
Definition ui_launcher.cpp:58
~PluginWindow()
Definition ui_launcher.cpp:51
unsigned d
Definition inflate.c:940
struct _NativePluginDescriptor NativePluginDescriptor
void * NativePluginHandle
Definition CarlaNative.h:37
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
static uintptr_t parent
Definition pugl.h:1644
#define false
Definition ordinals.h:83
START_NAMESPACE_DGL END_NAMESPACE_DGL START_NAMESPACE_DGL bool puglBackendEnter(PuglView *const view)
Definition pugl.cpp:189
bool puglBackendLeave(PuglView *const view)
Definition pugl.cpp:197
Definition ui_launcher.cpp:139
CarlaButtonWidget widget
Definition ui_launcher.cpp:142
CarlaUILauncher(const uintptr_t winId, const NativePluginDescriptor *const d, const NativePluginHandle h)
Definition ui_launcher.cpp:144
PluginWindow window
Definition ui_launcher.cpp:141
PluginApplication app
Definition ui_launcher.cpp:140
void idleUILauncher(CarlaUILauncher *const ui)
Definition ui_launcher.cpp:168
void destoryUILauncher(CarlaUILauncher *const ui)
Definition ui_launcher.cpp:173
void getUILauncherSize(CarlaUILauncher *const ui, VstRect *const rect)
Definition ui_launcher.cpp:157
CarlaUILauncher * createUILauncher(const uintptr_t winId, const NativePluginDescriptor *const d, const NativePluginHandle h)
Definition ui_launcher.cpp:150
uch h[RAND_HEAD_LEN]
Definition crypt.c:459