Browse Source

Add window offset related functions

pull/375/head
falkTX 3 years ago
parent
commit
21330021ce
5 changed files with 104 additions and 2 deletions
  1. +35
    -0
      dgl/Window.hpp
  2. +42
    -0
      dgl/src/Window.cpp
  3. +12
    -0
      dgl/src/pugl.cpp
  4. +6
    -2
      dgl/src/pugl.hpp
  5. +9
    -0
      distrho/src/DistrhoUIInternal.hpp

+ 35
- 0
dgl/Window.hpp View File

@@ -206,6 +206,41 @@ public:
*/
void setResizable(bool resizable);

/**
Get X offset, typically 0.
*/
int getOffsetX() const noexcept;

/**
Get Y offset, typically 0.
*/
int getOffsetY() const noexcept;

/**
Get offset.
*/
Point<int> getOffset() const noexcept;

/**
Set X offset.
*/
void setOffsetX(int x);

/**
Set Y offset.
*/
void setOffsetY(int y);

/**
Set offset using @a x and @a y values.
*/
void setOffset(int x, int y);

/**
Set offset.
*/
void setOffset(const Point<int>& offset);

/**
Get width.
*/


+ 42
- 0
dgl/src/Window.cpp View File

@@ -155,6 +155,48 @@ void Window::setResizable(const bool resizable)
pData->setResizable(resizable);
}

int Window::getOffsetX() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

return puglGetFrame(pData->view).x;
}

int Window::getOffsetY() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

return puglGetFrame(pData->view).y;
}

Point<int> Window::getOffset() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, Point<int>());

const PuglRect rect = puglGetFrame(pData->view);
return Point<int>(rect.x, rect.y);
}

void Window::setOffsetX(const int x)
{
setOffset(x, getOffsetY());
}

void Window::setOffsetY(const int y)
{
setOffset(getOffsetX(), y);
}

void Window::setOffset(const int x, const int y)
{
puglSetWindowOffset(pData->view, x, y);
}

void Window::setOffset(const Point<int>& offset)
{
setOffset(offset.getX(), offset.getY());
}

uint Window::getWidth() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);


+ 12
- 0
dgl/src/pugl.cpp View File

@@ -339,6 +339,18 @@ PuglStatus puglSetGeometryConstraints(PuglView* const view, const uint width, co
return PUGL_SUCCESS;
}

// --------------------------------------------------------------------------------------------------------------------
// set window offset without changing size

PuglStatus puglSetWindowOffset(PuglView* const view, const int x, const int y)
{
// TODO custom setFrame version
PuglRect rect = puglGetFrame(view);
rect.x = x;
rect.y = y;
return puglSetFrame(view, rect);
}

// --------------------------------------------------------------------------------------------------------------------
// set window size with default size and without changing frame x/y position



+ 6
- 2
dgl/src/pugl.hpp View File

@@ -81,11 +81,15 @@ puglSetMatchingBackendForCurrentBuild(PuglView* view);

// Combine puglSetMinSize and puglSetAspectRatio
PUGL_API PuglStatus
puglSetGeometryConstraints(PuglView* view, unsigned int width, unsigned int height, bool aspect);
puglSetGeometryConstraints(PuglView* view, uint width, uint height, bool aspect);

// set window offset without changing size
PUGL_API PuglStatus
puglSetWindowOffset(PuglView* view, int x, int y);

// set window size with default size and without changing frame x/y position
PUGL_API PuglStatus
puglSetWindowSize(PuglView* view, unsigned int width, unsigned int height);
puglSetWindowSize(PuglView* view, uint width, uint height);

// DGL specific, build-specific drawing prepare
PUGL_API void


+ 9
- 0
distrho/src/DistrhoUIInternal.hpp View File

@@ -284,6 +284,15 @@ public:

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

void setWindowOffset(const int x, const int y)
{
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
// TODO
#else
uiData->window->setOffset(x, y);
#endif
}

#ifdef DISTRHO_PLUGIN_TARGET_VST3
void setWindowSizeForVST3(const uint width, const uint height)
{


Loading…
Cancel
Save