summaryrefslogtreecommitdiff
path: root/libs/dgl/src/Window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/dgl/src/Window.cpp')
-rw-r--r--libs/dgl/src/Window.cpp92
1 files changed, 57 insertions, 35 deletions
diff --git a/libs/dgl/src/Window.cpp b/libs/dgl/src/Window.cpp
index f2c92e7..9d3c744 100644
--- a/libs/dgl/src/Window.cpp
+++ b/libs/dgl/src/Window.cpp
@@ -67,17 +67,19 @@ struct Window::PrivateData {
fVisible(false),
fResizable(true),
fUsingEmbed(false),
+ fWidth(1),
+ fHeight(1),
+ fModal(),
#if defined(DISTRHO_OS_WINDOWS)
- hwnd(0)
+ hwnd(0),
#elif defined(DISTRHO_OS_LINUX)
xDisplay(nullptr),
- xWindow(0)
+ xWindow(0),
#elif defined(DISTRHO_OS_MAC)
fNeedsIdle(true),
- xWindow(nullptr)
-#else
- _dummy('\0')
+ xWindow(nullptr),
#endif
+ leakDetector_PrivateData()
{
DBG("Creating window without parent..."); DBGF;
init();
@@ -91,18 +93,19 @@ struct Window::PrivateData {
fVisible(false),
fResizable(true),
fUsingEmbed(false),
+ fWidth(1),
+ fHeight(1),
fModal(parent.pData),
#if defined(DISTRHO_OS_WINDOWS)
- hwnd(0)
+ hwnd(0),
#elif defined(DISTRHO_OS_LINUX)
xDisplay(nullptr),
- xWindow(0)
+ xWindow(0),
#elif defined(DISTRHO_OS_MAC)
fNeedsIdle(false),
- xWindow(nullptr)
-#else
- _dummy('\0')
+ xWindow(nullptr),
#endif
+ leakDetector_PrivateData()
{
DBG("Creating window with parent..."); DBGF;
init();
@@ -122,19 +125,21 @@ struct Window::PrivateData {
fVisible(parentId != 0),
fResizable(parentId == 0),
fUsingEmbed(parentId != 0),
+ fWidth(1),
+ fHeight(1),
+ fModal(),
#if defined(DISTRHO_OS_WINDOWS)
- hwnd(0)
+ hwnd(0),
#elif defined(DISTRHO_OS_LINUX)
xDisplay(nullptr),
- xWindow(0)
+ xWindow(0),
#elif defined(DISTRHO_OS_MAC)
fNeedsIdle(false),
- xWindow(nullptr)
-#else
- _dummy('\0')
+ xWindow(nullptr),
#endif
+ leakDetector_PrivateData()
{
- if (parentId != 0)
+ if (fUsingEmbed)
{
DBG("Creating embedded window..."); DBGF;
puglInitWindowParent(fView, parentId);
@@ -146,7 +151,7 @@ struct Window::PrivateData {
init();
- if (parentId != 0)
+ if (fUsingEmbed)
{
DBG("NOTE: Embed window is always visible and non-resizable\n");
puglShowWindow(fView);
@@ -164,6 +169,7 @@ struct Window::PrivateData {
}
puglInitResizable(fView, fResizable);
+ puglInitWindowSize(fView, fWidth, fHeight);
puglSetHandle(fView, this);
puglSetDisplayFunc(fView, onDisplayCallback);
@@ -209,6 +215,12 @@ struct Window::PrivateData {
//fOnModal = false;
fWidgets.clear();
+ if (fUsingEmbed)
+ {
+ puglHideWindow(fView);
+ fApp.pData->oneHidden();
+ }
+
if (fSelf != nullptr)
{
fApp.pData->windows.remove(fSelf);
@@ -238,6 +250,10 @@ struct Window::PrivateData {
void close()
{
DBG("Window close\n");
+
+ if (fUsingEmbed)
+ return;
+
setVisible(false);
if (! fFirstInit)
@@ -351,7 +367,7 @@ struct Window::PrivateData {
fVisible = yesNo;
if (yesNo && fFirstInit)
- setSize(static_cast<uint>(fView->width), static_cast<uint>(fView->height), true);
+ setSize(fWidth, fHeight, true);
#if defined(DISTRHO_OS_WINDOWS)
if (yesNo)
@@ -405,7 +421,7 @@ struct Window::PrivateData {
fResizable = yesNo;
- setSize(static_cast<uint>(fView->width), static_cast<uint>(fView->height), true);
+ setSize(fWidth, fHeight, true);
}
// -------------------------------------------------------------------
@@ -418,14 +434,14 @@ struct Window::PrivateData {
return;
}
- if (fView->width == static_cast<int>(width) && fView->height == static_cast<int>(height) && ! forced)
+ if (fWidth == width && fHeight == height && ! forced)
{
DBGp("Window setSize matches current size, ignoring request (%i %i)\n", width, height);
return;
}
- fView->width = static_cast<int>(width);
- fView->height = static_cast<int>(height);
+ fWidth = width;
+ fHeight = height;
DBGp("Window setSize called %s, size %i %i\n", forced ? "(forced)" : "(not forced)", width, height);
@@ -573,15 +589,15 @@ struct Window::PrivateData {
// reset color
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- if (widget->fNeedsFullViewport || widget->fArea == Rectangle<int>(0, 0, fView->width, fView->height))
+ if (widget->fNeedsFullViewport || (widget->fAbsolutePos.isZero() && widget->fSize == Size<uint>(fWidth, fHeight)))
{
// full viewport size
- glViewport(0, 0, fView->width, fView->height);
+ glViewport(0, 0, fWidth, fHeight);
}
else if (! widget->fNeedsScaling)
{
// only set viewport pos
- glViewport(widget->getAbsoluteX(), /*fView->height - widget->getHeight()*/ - widget->getAbsoluteY(), fView->width, fView->height);
+ glViewport(widget->getAbsoluteX(), /*fView->height - widget->getHeight()*/ - widget->getAbsoluteY(), fWidth, fHeight);
// then cut the outer bounds
glScissor(widget->getAbsoluteX(), fView->height - widget->getHeight() - widget->getAbsoluteY(), widget->getWidth(), widget->getHeight());
@@ -725,6 +741,12 @@ struct Window::PrivateData {
{
DBGp("PUGL: onReshape : %i %i\n", width, height);
+ if (width == 1 && height == 1)
+ return;
+
+ fWidth = width;
+ fHeight = height;
+
fSelf->onReshape(width, height);
FOR_EACH_WIDGET(it)
@@ -761,6 +783,8 @@ struct Window::PrivateData {
bool fVisible;
bool fResizable;
bool fUsingEmbed;
+ uint fWidth;
+ uint fHeight;
std::list<Widget*> fWidgets;
struct Modal {
@@ -793,8 +817,6 @@ struct Window::PrivateData {
#elif defined(DISTRHO_OS_MAC)
bool fNeedsIdle;
id xWindow;
-#else
- char _dummy;
#endif
// -------------------------------------------------------------------
@@ -843,6 +865,8 @@ struct Window::PrivateData {
}
#undef handlePtr
+
+ DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
};
// -----------------------------------------------------------------------
@@ -912,21 +936,19 @@ void Window::setResizable(bool yesNo)
pData->setResizable(yesNo);
}
-int Window::getWidth() const noexcept
+uint Window::getWidth() const noexcept
{
- return pData->fView->width;
+ return pData->fWidth;
}
-int Window::getHeight() const noexcept
+uint Window::getHeight() const noexcept
{
- return pData->fView->height;
+ return pData->fHeight;
}
Size<uint> Window::getSize() const noexcept
{
- DISTRHO_SAFE_ASSERT_RETURN(pData->fView->width >= 0 && pData->fView->height >= 0, Size<uint>(0, 0));
-
- return Size<uint>(pData->fView->width, pData->fView->height);
+ return Size<uint>(pData->fWidth, pData->fHeight);
}
void Window::setSize(uint width, uint height)
@@ -1002,7 +1024,7 @@ void Window::onDisplayAfter()
{
}
-void Window::onReshape(int width, int height)
+void Window::onReshape(uint width, uint height)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);