Browse Source

Add get/set scaling to Window

pull/83/head
falkTX 5 years ago
parent
commit
aa6ada4ece
3 changed files with 65 additions and 20 deletions
  1. +3
    -0
      dgl/Window.hpp
  2. +19
    -16
      dgl/src/WidgetPrivateData.hpp
  3. +43
    -4
      dgl/src/Window.cpp

+ 3
- 0
dgl/Window.hpp View File

@@ -111,6 +111,9 @@ public:

void setTransientWinId(uintptr_t winId);

double getScaling() const noexcept;
void setScaling(double scaling) noexcept;

Application& getApp() const noexcept;
intptr_t getWindowId() const noexcept;



+ 19
- 16
dgl/src/WidgetPrivateData.hpp View File

@@ -63,7 +63,7 @@ struct Widget::PrivateData {
subWidgets.clear();
}

void display(const uint width, const uint height, const bool renderingSubWidget)
void display(const uint width, const uint height, const double scaling, const bool renderingSubWidget)
{
if ((skipDisplay && ! renderingSubWidget) || size.isInvalid() || ! visible)
return;
@@ -76,29 +76,32 @@ struct Widget::PrivateData {
if (needsFullViewport || (absolutePos.isZero() && size == Size<uint>(width, height)))
{
// full viewport size
glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
glViewport(0,
-(height * scaling - height),
width * scaling,
height * scaling);
}
else if (needsScaling)
{
// limit viewport to widget bounds
glViewport(absolutePos.getX(),
static_cast<int>(height - self->getHeight()) - absolutePos.getY(),
static_cast<GLsizei>(self->getWidth()),
static_cast<GLsizei>(self->getHeight()));
height - self->getHeight() - absolutePos.getY(),
self->getWidth(),
self->getHeight());
}
else
{
// only set viewport pos
glViewport(absolutePos.getX(),
/*static_cast<int>(height - self->getHeight())*/ - absolutePos.getY(),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height));
glViewport(absolutePos.getX() * scaling,
-std::round((height * scaling - height) + (absolutePos.getY() * scaling)),
std::round(width * scaling),
std::round(height * scaling));

// then cut the outer bounds
glScissor(absolutePos.getX(),
static_cast<int>(height - self->getHeight()) - absolutePos.getY(),
static_cast<GLsizei>(self->getWidth()),
static_cast<GLsizei>(self->getHeight()));
glScissor(absolutePos.getX() * scaling,
height - std::round((self->getHeight() + absolutePos.getY()) * scaling),
std::round(self->getWidth() * scaling),
std::round(self->getHeight() * scaling));

glEnable(GL_SCISSOR_TEST);
needsDisableScissor = true;
@@ -113,17 +116,17 @@ struct Widget::PrivateData {
needsDisableScissor = false;
}

displaySubWidgets(width, height);
displaySubWidgets(width, height, scaling);
}

void displaySubWidgets(const uint width, const uint height)
void displaySubWidgets(const uint width, const uint height, const double scaling)
{
for (std::vector<Widget*>::iterator it = subWidgets.begin(); it != subWidgets.end(); ++it)
{
Widget* const widget(*it);
DISTRHO_SAFE_ASSERT_CONTINUE(widget->pData != this);

widget->pData->display(width, height, true);
widget->pData->display(width, height, scaling, true);
}
}



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

@@ -83,6 +83,7 @@ struct Window::PrivateData {
fUsingEmbed(false),
fWidth(1),
fHeight(1),
fScaling(1.0),
fTitle(nullptr),
fWidgets(),
fModal(),
@@ -113,6 +114,7 @@ struct Window::PrivateData {
fUsingEmbed(false),
fWidth(1),
fHeight(1),
fScaling(1.0),
fTitle(nullptr),
fWidgets(),
fModal(parent.pData),
@@ -155,6 +157,7 @@ struct Window::PrivateData {
fUsingEmbed(parentId != 0),
fWidth(1),
fHeight(1),
fScaling(1.0),
fTitle(nullptr),
fWidgets(),
fModal(),
@@ -689,6 +692,20 @@ struct Window::PrivateData {

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

double getScaling() const noexcept
{
return fScaling;
}

void setScaling(double scaling) noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(scaling > 0.0,);

fScaling = scaling;
}

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

void addWidget(Widget* const widget)
{
fWidgets.push_back(widget);
@@ -740,7 +757,7 @@ struct Window::PrivateData {
FOR_EACH_WIDGET(it)
{
Widget* const widget(*it);
widget->pData->display(fWidth, fHeight, false);
widget->pData->display(fWidth, fHeight, fScaling, false);
}

fSelf->onDisplayAfter();
@@ -800,7 +817,7 @@ struct Window::PrivateData {
return 1;
}

void onPuglMouse(const int button, const bool press, const int x, const int y)
void onPuglMouse(const int button, const bool press, int x, int y)
{
DBGp("PUGL: onMouse : %i %i %i %i\n", button, press, x, y);

@@ -810,6 +827,9 @@ struct Window::PrivateData {
if (fModal.childFocus != nullptr)
return fModal.childFocus->focus();

x /= fScaling;
y /= fScaling;

Widget::MouseEvent ev;
ev.button = button;
ev.press = press;
@@ -827,13 +847,16 @@ struct Window::PrivateData {
}
}

void onPuglMotion(const int x, const int y)
void onPuglMotion(int x, int y)
{
DBGp("PUGL: onMotion : %i %i\n", x, y);

if (fModal.childFocus != nullptr)
return;

x /= fScaling;
y /= fScaling;

Widget::MotionEvent ev;
ev.mod = static_cast<Modifier>(puglGetModifiers(fView));
ev.time = puglGetEventTimestamp(fView);
@@ -849,13 +872,18 @@ struct Window::PrivateData {
}
}

void onPuglScroll(const int x, const int y, const float dx, const float dy)
void onPuglScroll(int x, int y, float dx, float dy)
{
DBGp("PUGL: onScroll : %i %i %f %f\n", x, y, dx, dy);

if (fModal.childFocus != nullptr)
return;

x /= fScaling;
y /= fScaling;
dx /= fScaling;
dy /= fScaling;

Widget::ScrollEvent ev;
ev.delta = Point<float>(dx, dy);
ev.mod = static_cast<Modifier>(puglGetModifiers(fView));
@@ -1004,6 +1032,7 @@ struct Window::PrivateData {
bool fUsingEmbed;
uint fWidth;
uint fHeight;
double fScaling;
char* fTitle;
std::list<Widget*> fWidgets;

@@ -1290,6 +1319,16 @@ void Window::setTransientWinId(uintptr_t winId)
pData->setTransientWinId(winId);
}

double Window::getScaling() const noexcept
{
return pData->getScaling();
}

void Window::setScaling(double scaling) noexcept
{
pData->setScaling(scaling);
}

Application& Window::getApp() const noexcept
{
return pData->fApp;


Loading…
Cancel
Save