Browse Source

Ensure all TopLevelWidgets start with correct size; Cleanup

Signed-off-by: falkTX <falktx@falktx.com>
pull/456/head
falkTX 1 year ago
parent
commit
50e62f2dd9
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 25 additions and 11 deletions
  1. +3
    -3
      dgl/Base.hpp
  2. +14
    -4
      dgl/src/Window.cpp
  3. +1
    -1
      dgl/src/WindowPrivateData.cpp
  4. +7
    -3
      distrho/extra/Sleep.hpp

+ 3
- 3
dgl/Base.hpp View File

@@ -73,7 +73,7 @@ enum Key {
kKeySpace = 0x00000020U, ///< Space

// Unicode Private Use Area
kKeyF1 = 0x0000E000U, ///< F1
kKeyF1 = 0xE000U, ///< F1
kKeyF2, ///< F2
kKeyF3, ///< F3
kKeyF4, ///< F4
@@ -85,7 +85,7 @@ enum Key {
kKeyF10, ///< F10
kKeyF11, ///< F11
kKeyF12, ///< F12
kKeyPageUp = 0xE031, ///< Page Up
kKeyPageUp = 0xE031U, ///< Page Up
kKeyPageDown, ///< Page Down
kKeyEnd, ///< End
kKeyHome, ///< Home
@@ -100,7 +100,7 @@ enum Key {
kKeyNumLock, ///< Num Lock
kKeyScrollLock, ///< Scroll Lock
kKeyCapsLock, ///< Caps Lock
kKeyShiftL = 0xE051U, ///< Left Shift,
kKeyShiftL = 0xE051U, ///< Left Shift
kKeyShiftR, ///< Right Shift
kKeyControlL, ///< Left Control
kKeyControlR, ///< Right Control


+ 14
- 4
dgl/src/Window.cpp View File

@@ -227,7 +227,7 @@ uint Window::getWidth() const noexcept
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

const double width = puglGetFrame(pData->view).width;
DISTRHO_SAFE_ASSERT_RETURN(width >= 0.0, 0);
DISTRHO_SAFE_ASSERT_RETURN(width > 0.0, 0);
return static_cast<uint>(width + 0.5);
}

@@ -236,7 +236,7 @@ uint Window::getHeight() const noexcept
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

const double height = puglGetFrame(pData->view).height;
DISTRHO_SAFE_ASSERT_RETURN(height >= 0.0, 0);
DISTRHO_SAFE_ASSERT_RETURN(height > 0.0, 0);
return static_cast<uint>(height + 0.5);
}

@@ -245,8 +245,8 @@ Size<uint> Window::getSize() const noexcept
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, Size<uint>());

const PuglRect rect = puglGetFrame(pData->view);
DISTRHO_SAFE_ASSERT_RETURN(rect.width >= 0.0, Size<uint>());
DISTRHO_SAFE_ASSERT_RETURN(rect.height >= 0.0, Size<uint>());
DISTRHO_SAFE_ASSERT_RETURN(rect.width > 0.0, Size<uint>());
DISTRHO_SAFE_ASSERT_RETURN(rect.height > 0.0, Size<uint>());
return Size<uint>(static_cast<uint>(rect.width + 0.5),
static_cast<uint>(rect.height + 0.5));
}
@@ -315,6 +315,16 @@ void Window::setSize(uint width, uint height)
else if (pData->view != nullptr)
{
puglSetSizeAndDefault(pData->view, width, height);

// there are no resize events for closed windows, so short-circuit the top-level widgets here
if (pData->isClosed)
{
for (std::list<TopLevelWidget*>::iterator it = pData->topLevelWidgets.begin(),
end = pData->topLevelWidgets.end(); it != end; ++it)
{
((Widget*)*it)->setSize(width, height);
}
}
}
}



+ 1
- 1
dgl/src/WindowPrivateData.cpp View File

@@ -604,7 +604,7 @@ void Window::PrivateData::onPuglConfigure(const double width, const double heigh
#ifndef DPF_TEST_WINDOW_CPP
FOR_EACH_TOP_LEVEL_WIDGET(it)
{
TopLevelWidget* const widget(*it);
TopLevelWidget* const widget = *it;

/* Some special care here, we call Widget::setSize instead of the TopLevelWidget one.
* This is because we want TopLevelWidget::setSize to handle both window and widget size,


+ 7
- 3
distrho/extra/Sleep.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -29,7 +29,9 @@
# include <unistd.h>
#endif

// -----------------------------------------------------------------------
START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------------------------------------------
// d_*sleep

/*
@@ -66,6 +68,8 @@ void d_msleep(const uint msecs) noexcept
} DISTRHO_SAFE_EXCEPTION("d_msleep");
}

// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_SLEEP_HPP_INCLUDED

Loading…
Cancel
Save