Skip to content

Commit

Permalink
Update to latest pugl
Browse files Browse the repository at this point in the history
  • Loading branch information
drobilla committed Feb 11, 2025
1 parent a8b7ef9 commit 1f20156
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
47 changes: 23 additions & 24 deletions dgl/src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,22 @@ int Window::getOffsetX() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

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

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

return puglGetFrame(pData->view).y;
return puglGetPositionHint(pData->view, PUGL_CURRENT_POSITION).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);
const PuglPoint point = puglGetPositionHint(pData->view, PUGL_CURRENT_POSITION);
return Point<int>(point.x, point.y);
}

void Window::setOffsetX(const int x)
Expand All @@ -214,7 +214,7 @@ void Window::setOffset(const int x, const int y)
DISTRHO_SAFE_ASSERT_RETURN(!pData->isEmbed,);

if (pData->view != nullptr)
puglSetPosition(pData->view, x, y);
puglSetPositionHint(pData->view, PUGL_CURRENT_POSITION, x, y);
}

void Window::setOffset(const Point<int>& offset)
Expand All @@ -226,7 +226,7 @@ uint Window::getWidth() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

const double width = puglGetFrame(pData->view).width;
const double width = puglGetSizeHint(pData->view, PUGL_CURRENT_SIZE).width;
DISTRHO_SAFE_ASSERT_RETURN(width > 0.0, 0);
return static_cast<uint>(width + 0.5);
}
Expand All @@ -235,7 +235,7 @@ uint Window::getHeight() const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(pData->view != nullptr, 0);

const double height = puglGetFrame(pData->view).height;
const double height = puglGetSizeHint(pData->view, PUGL_CURRENT_SIZE).height;
DISTRHO_SAFE_ASSERT_RETURN(height > 0.0, 0);
return static_cast<uint>(height + 0.5);
}
Expand All @@ -244,11 +244,11 @@ 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>());
return Size<uint>(static_cast<uint>(rect.width + 0.5),
static_cast<uint>(rect.height + 0.5));
const PuglArea size = puglGetSizeHint(pData->view, PUGL_CURRENT_SIZE);
DISTRHO_SAFE_ASSERT_RETURN(size.width > 0.0, Size<uint>());
DISTRHO_SAFE_ASSERT_RETURN(size.height > 0.0, Size<uint>());
return Size<uint>(static_cast<uint>(size.width + 0.5),
static_cast<uint>(size.height + 0.5));
}

void Window::setWidth(const uint width)
Expand Down Expand Up @@ -429,7 +429,7 @@ void Window::repaint() noexcept
if (pData->usesScheduledRepaints)
pData->appData->needsRepaint = true;

puglPostRedisplay(pData->view);
puglObscureView(pData->view);
}

void Window::repaint(const Rectangle<uint>& rect) noexcept
Expand All @@ -440,22 +440,21 @@ void Window::repaint(const Rectangle<uint>& rect) noexcept
if (pData->usesScheduledRepaints)
pData->appData->needsRepaint = true;

PuglRect prect = {
static_cast<PuglCoord>(rect.getX()),
static_cast<PuglCoord>(rect.getY()),
static_cast<PuglSpan>(rect.getWidth()),
static_cast<PuglSpan>(rect.getHeight()),
};
PuglCoord x = static_cast<PuglCoord>(rect.getX());
PuglCoord y = static_cast<PuglCoord>(rect.getY());
PuglSpan w = static_cast<PuglSpan>(rect.getWidth());
PuglSpan h = static_cast<PuglSpan>(rect.getHeight());

if (pData->autoScaling)
{
const double autoScaleFactor = pData->autoScaleFactor;

prect.x = static_cast<PuglCoord>(prect.x * autoScaleFactor);
prect.y = static_cast<PuglCoord>(prect.y * autoScaleFactor);
prect.width = static_cast<PuglSpan>(prect.width * autoScaleFactor + 0.5);
prect.height = static_cast<PuglSpan>(prect.height * autoScaleFactor + 0.5);
x = static_cast<PuglCoord>(x * autoScaleFactor);
y = static_cast<PuglCoord>(y * autoScaleFactor);
w = static_cast<PuglSpan>(w * autoScaleFactor + 0.5);
h = static_cast<PuglSpan>(h * autoScaleFactor + 0.5);
}
puglPostRedisplayRect(pData->view, prect);
puglObscureRegion(pData->view, x, y, w, h);
}

void Window::renderToPicture(const char* const filename)
Expand Down
10 changes: 5 additions & 5 deletions dgl/src/WindowPrivateData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ static PuglView* puglNewViewWithParentWindow(PuglWorld* const world, const uintp

if (PuglView* const view = puglNewView(world))
{
puglSetParentWindow(view, parentWindowHandle);
puglSetParent(view, parentWindowHandle);

if (parentWindowHandle != 0)
puglSetPosition(view, 0, 0);
puglSetPositionHint(view, PUGL_CURRENT_POSITION, 0, 0);

return view;
}
Expand Down Expand Up @@ -617,7 +617,7 @@ void Window::PrivateData::onPuglConfigure(const uint width, const uint height)
#endif

// always repaint after a resize
puglPostRedisplay(view);
puglObscureView(view);
}

void Window::PrivateData::onPuglExpose()
Expand All @@ -637,9 +637,9 @@ void Window::PrivateData::onPuglExpose()

if (char* const filename = filenameToRenderInto)
{
const PuglRect rect = puglGetFrame(view);
const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
filenameToRenderInto = nullptr;
renderToPicture(filename, getGraphicsContext(), static_cast<uint>(rect.width), static_cast<uint>(rect.height));
renderToPicture(filename, getGraphicsContext(), static_cast<uint>(size.width), static_cast<uint>(size.height));
std::free(filename);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion dgl/src/pugl-upstream
Submodule pugl-upstream updated 113 files
2 changes: 1 addition & 1 deletion dgl/src/pugl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ PuglStatus puglSetSizeAndDefault(PuglView* view, uint width, uint height)
// matches upstream pugl, adds flush at the end
if (view->impl->win)
{
if (const PuglStatus status = puglSetSize(view, width, height))
if (const PuglStatus status = puglSetSizeHint(view, PUGL_CURRENT_SIZE, width, height))
return status;

// updateSizeHints will use last known size, which is not yet updated
Expand Down

0 comments on commit 1f20156

Please sign in to comment.