2014-03-23 01:07:54 -07: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
|
|
|
|
|
2018-12-16 03:14:42 -08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
#define SUPPORTS_FRACTIONAL_SCALING
|
|
|
|
#endif
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static inline void GetScaleAndCenterPos(int baseCX, int baseCY, int windowCX,
|
|
|
|
int windowCY, int &x, int &y,
|
|
|
|
float &scale)
|
2014-03-23 01:07:54 -07:00
|
|
|
{
|
|
|
|
double windowAspect, baseAspect;
|
|
|
|
int newCX, newCY;
|
|
|
|
|
|
|
|
windowAspect = double(windowCX) / double(windowCY);
|
2019-06-22 22:13:45 -07:00
|
|
|
baseAspect = double(baseCX) / double(baseCY);
|
2014-03-23 01:07:54 -07: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-06-22 22:13:45 -07:00
|
|
|
x = windowCX / 2 - newCX / 2;
|
|
|
|
y = windowCY / 2 - newCY / 2;
|
2014-03-23 01:07:54 -07:00
|
|
|
}
|
2014-04-16 11:28:02 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
static inline void GetCenterPosFromFixedScale(int baseCX, int baseCY,
|
|
|
|
int windowCX, int windowCY,
|
|
|
|
int &x, int &y, float scale)
|
2016-11-05 09:48:46 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
x = (float(windowCX) - float(baseCX) * scale) / 2.0f;
|
|
|
|
y = (float(windowCY) - float(baseCY) * scale) / 2.0f;
|
2016-11-05 09:48:46 -07:00
|
|
|
}
|
|
|
|
|
2014-04-16 11:28:02 -07:00
|
|
|
static inline QSize GetPixelSize(QWidget *widget)
|
|
|
|
{
|
2018-12-16 03:14:42 -08:00
|
|
|
#ifdef SUPPORTS_FRACTIONAL_SCALING
|
|
|
|
return widget->size() * widget->devicePixelRatioF();
|
|
|
|
#else
|
2014-04-16 11:28:02 -07:00
|
|
|
return widget->size() * widget->devicePixelRatio();
|
2018-12-16 03:14:42 -08:00
|
|
|
#endif
|
2014-04-16 11:28:02 -07:00
|
|
|
}
|