yolobs-studio/UI/display-helpers.hpp

64 lines
2 KiB
C++
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
/******************************************************************************
Copyright (C) 2014 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
2019-07-27 12:47:10 +00:00
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
#define SUPPORTS_FRACTIONAL_SCALING
#endif
2019-09-22 21:19:10 +00:00
static inline void GetScaleAndCenterPos(int baseCX, int baseCY, int windowCX,
int windowCY, int &x, int &y,
float &scale)
2016-02-23 23:16:51 +00:00
{
double windowAspect, baseAspect;
int newCX, newCY;
windowAspect = double(windowCX) / double(windowCY);
2019-09-22 21:19:10 +00:00
baseAspect = double(baseCX) / double(baseCY);
2016-02-23 23:16:51 +00:00
if (windowAspect > baseAspect) {
scale = float(windowCY) / float(baseCY);
newCX = int(double(windowCY) * baseAspect);
newCY = windowCY;
} else {
scale = float(windowCX) / float(baseCX);
newCX = windowCX;
newCY = int(float(windowCX) / baseAspect);
}
2019-09-22 21:19:10 +00:00
x = windowCX / 2 - newCX / 2;
y = windowCY / 2 - newCY / 2;
2016-02-23 23:16:51 +00:00
}
2019-09-22 21:19:10 +00:00
static inline void GetCenterPosFromFixedScale(int baseCX, int baseCY,
int windowCX, int windowCY,
int &x, int &y, float scale)
2017-04-19 19:54:15 +00:00
{
2019-09-22 21:19:10 +00:00
x = (float(windowCX) - float(baseCX) * scale) / 2.0f;
y = (float(windowCY) - float(baseCY) * scale) / 2.0f;
2017-04-19 19:54:15 +00:00
}
2016-02-23 23:16:51 +00:00
static inline QSize GetPixelSize(QWidget *widget)
{
2019-07-27 12:47:10 +00:00
#ifdef SUPPORTS_FRACTIONAL_SCALING
return widget->size() * widget->devicePixelRatioF();
#else
2016-02-23 23:16:51 +00:00
return widget->size() * widget->devicePixelRatio();
2019-07-27 12:47:10 +00:00
#endif
2016-02-23 23:16:51 +00:00
}