Skip to content

Commit

Permalink
Merge pull request #104 from friction2d/gradient-hidpi
Browse files Browse the repository at this point in the history
GradientWidgets: fix HiDPI issues
  • Loading branch information
rodlie authored Nov 26, 2023
2 parents 3c8190f + 61e187f commit afb002e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/app/GUI/GradientWidgets/currentgradientwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void CurrentGradientWidget::setCurrentGradient(Gradient * const gradient) {
}

void CurrentGradientWidget::paintGL() {
qreal pixelRatio = devicePixelRatioF();
glClearColor(0.3f, 0.3f, 0.3f, 1);
glClear(GL_COLOR_BUFFER_BIT);
if(!mGradient) return;
Expand All @@ -69,7 +70,10 @@ void CurrentGradientWidget::paintGL() {
for(int j = 0; j < nColors; j++) {
const QColor color = mGradient->getColorAt(j);
const int cWidth = j == nColors - 1 ? width() - colX : xInc;
glViewport(colX, 0, cWidth, height());
glViewport(colX * pixelRatio,
0,
cWidth * pixelRatio,
height() * pixelRatio);

const bool lightBorder = shouldValPointerBeLightHSV(color.hueF(),
color.hsvSaturationF(),
Expand Down
11 changes: 9 additions & 2 deletions src/app/GUI/GradientWidgets/displayedgradientswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void DisplayedGradientsWidget::updateHeight() {

#include "GUI/ColorWidgets/colorwidgetshaders.h"
void DisplayedGradientsWidget::paintGL() {
qreal pixelRatio = devicePixelRatioF();
const int nVisible = qMin(mGradients.count() - mTopGradientId,
mMaxVisibleGradients);
int gradY = mDisplayedTop;
Expand All @@ -104,7 +105,10 @@ void DisplayedGradientsWidget::paintGL() {
eSizesUI::widget/(3.f*xInc), 1.f/3);
for(int j = (nColors == 1 ? 0 : 1); j < nColors; j++) {
const QColor color = gradient->getColorAt(j);
glViewport(xT, yInverted, qRound(xInc), eSizesUI::widget);
glViewport(xT * pixelRatio,
yInverted * pixelRatio,
qRound(xInc * pixelRatio),
eSizesUI::widget * pixelRatio);

glUniform4f(GRADIENT_PROGRAM.fRGBAColor1Loc,
lastColor.redF(), lastColor.greenF(),
Expand All @@ -117,7 +121,10 @@ void DisplayedGradientsWidget::paintGL() {
xT += qRound(xInc);
lastColor = color;
}
glViewport(0, yInverted, width(), eSizesUI::widget);
glViewport(0,
yInverted * pixelRatio,
width() * pixelRatio,
eSizesUI::widget * pixelRatio);
if(gradient == mSelectedGradient) {
glUseProgram(DOUBLE_BORDER_PROGRAM.fID);
glUniform2f(DOUBLE_BORDER_PROGRAM.fInnerBorderSizeLoc,
Expand Down
5 changes: 3 additions & 2 deletions src/app/GUI/GradientWidgets/gradientslistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

GradientsListWidget::GradientsListWidget(QWidget *parent) :
ScrollArea(parent) {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
eSizesUI::widget.add(this, [this](const int size) {
setFixedHeight(6*size);
verticalScrollBar()->setSingleStep(size);
Expand All @@ -51,9 +52,9 @@ void GradientsListWidget::resizeEvent(QResizeEvent *e) {
const QSize size = e->size();
mDisplayedGradients->setMinimumHeight(size.height());
mDisplayedGradients->updateHeight();
/*const int scrollBarWidth = verticalScrollBar()->width();
const int scrollBarWidth = verticalScrollBar()->width();
const int availableWidth = size.width() - scrollBarWidth;
mDisplayedGradients->setFixedWidth(availableWidth);*/
mDisplayedGradients->setFixedWidth(availableWidth);
}

void GradientsListWidget::showEvent(QShowEvent *e) {
Expand Down

0 comments on commit afb002e

Please sign in to comment.