initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,87 @@
|
||||
#include "Dpi/DpiCommon.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QtMath>
|
||||
|
||||
namespace Dpi {
|
||||
|
||||
int ScreenInfo::dpi()
|
||||
{
|
||||
return qRound(96.0 * toNative());
|
||||
}
|
||||
|
||||
double ScreenInfo::toNative()
|
||||
{
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
return screen ? screen->devicePixelRatio() : 1.0;
|
||||
}
|
||||
|
||||
double ScreenInfo::fromNative()
|
||||
{
|
||||
const double ratio = toNative();
|
||||
return ratio != 0.0 ? 1.0 / ratio : 1.0;
|
||||
}
|
||||
|
||||
int scaleToNative(int value)
|
||||
{
|
||||
return qRound(value * ScreenInfo::toNative());
|
||||
}
|
||||
|
||||
int scaleFromNative(int value)
|
||||
{
|
||||
return qRound(value * ScreenInfo::fromNative());
|
||||
}
|
||||
|
||||
int scaleToNativeDist(int base, int value)
|
||||
{
|
||||
return scaleToNative(base + value) - scaleToNative(base);
|
||||
}
|
||||
|
||||
QPoint scalePointToNative(const QPoint &value)
|
||||
{
|
||||
return QPoint(scaleToNative(value.x()), scaleToNative(value.y()));
|
||||
}
|
||||
|
||||
QPoint scalePointFromNative(const QPoint &value)
|
||||
{
|
||||
return QPoint(scaleFromNative(value.x()), scaleFromNative(value.y()));
|
||||
}
|
||||
|
||||
QSize scaleSizeToNative(const QSize &value)
|
||||
{
|
||||
return QSize(scaleToNative(value.width()), scaleToNative(value.height()));
|
||||
}
|
||||
|
||||
QSize scaleSizeFromNative(const QSize &value)
|
||||
{
|
||||
return QSize(scaleFromNative(value.width()), scaleFromNative(value.height()));
|
||||
}
|
||||
|
||||
QRect scaleRectToNative(const QRect &value)
|
||||
{
|
||||
return QRect(scalePointToNative(value.topLeft()), scaleSizeToNative(value.size()));
|
||||
}
|
||||
|
||||
QRect scaleRectFromNative(const QRect &value)
|
||||
{
|
||||
return QRect(scalePointFromNative(value.topLeft()), scaleSizeFromNative(value.size()));
|
||||
}
|
||||
|
||||
double scaleFloatToNative(double value)
|
||||
{
|
||||
return value * ScreenInfo::toNative();
|
||||
}
|
||||
|
||||
double scaleFloatFromNative(double value)
|
||||
{
|
||||
return value * ScreenInfo::fromNative();
|
||||
}
|
||||
|
||||
void writeLog(const QString &text)
|
||||
{
|
||||
qDebug().noquote() << text;
|
||||
}
|
||||
|
||||
} // namespace Dpi
|
||||
Reference in new issue
Block a user