Fix Device::getPixelRatio for win32,android

This commit is contained in:
halx99 2023-12-13 01:56:53 +08:00
parent 910f037e00
commit a6107139b6
8 changed files with 17 additions and 13 deletions

View File

@ -6,6 +6,11 @@ version: 2.1.0.{build}
install: install:
- git submodule update --init --recursive - git submodule update --init --recursive
skip_commits:
files:
- docs/*
- '**/*.md'
build_script: build_script:
- pwsh: .\build.ps1 -p wasm -xb '--target','cpp-tests','--config','Release' -xc '-DAX_ENABLE_EXT_EFFEKSEER=ON','-DAX_WASM_THREADS=8' - pwsh: .\build.ps1 -p wasm -xb '--target','cpp-tests','--config','Release' -xc '-DAX_ENABLE_EXT_EFFEKSEER=ON','-DAX_WASM_THREADS=8'
- pwsh: .\build.ps1 -p wasm -xb '--target','fairygui-tests','--config','Release' -xc '-DAX_ENABLE_EXT_EFFEKSEER=ON','-DAX_WASM_THREADS=8' - pwsh: .\build.ps1 -p wasm -xb '--target','fairygui-tests','--config','Release' -xc '-DAX_ENABLE_EXT_EFFEKSEER=ON','-DAX_WASM_THREADS=8'

View File

@ -64,7 +64,7 @@ void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_ma
std::string_view type = settings["type"]; std::string_view type = settings["type"];
if (type != "fontatlas") if (type != "fontatlas")
{ {
ax::print("Load fontatlas %s fail, invalid asset type: ", fontatlasFile.data(), type.data()); ax::print("Load fontatlas %s fail, invalid asset type: %s", fontatlasFile.data(), type.data());
return; return;
} }

View File

@ -70,7 +70,7 @@ public:
static void setMissingGlyphCharacter(char32_t charCode) { _mssingGlyphCharacter = charCode; }; static void setMissingGlyphCharacter(char32_t charCode) { _mssingGlyphCharacter = charCode; };
/** /**
* @brief Whether enable SDF font rendering globally, by default: disabled, since axmol-2.0.1 * @brief Whether enable SDF font rendering globally, by default: disabled, since axmol-2.1.0
* *
* @param enabled * @param enabled
*/ */

View File

@ -550,11 +550,11 @@ public:
/** /**
* Set the ttf/ttc font face size to determine how big to generate SDF bitmap * Set the ttf/ttc font face size to determine how big to generate SDF bitmap
* since axmol-2.0.1 * since axmol-2.1.0
*/ */
void setTTFFaceSize(int faceSize); void setTTFFaceSize(int faceSize);
/** Gets ttf/ttc font face size, since axmol-2.0.1 */ /** Gets ttf/ttc font face size, since axmol-2.1.0 */
int getTTFFaceSize() const; int getTTFFaceSize() const;
/** /**

View File

@ -86,6 +86,7 @@ public:
/** /**
* Gets the device pixel ratio * Gets the device pixel ratio
* @since axmol-2.1.0
*/ */
static float getPixelRatio(); static float getPixelRatio();

View File

@ -404,12 +404,7 @@ public class AxmolEngine {
private static int displayMetricsToDPI(DisplayMetrics metrics) private static int displayMetricsToDPI(DisplayMetrics metrics)
{ {
if(metrics.xdpi != metrics.ydpi) { return metrics.densityDpi;
Log.w(AxmolEngine.TAG, "xdpi != ydpi, use (xdpi + ydpi)/2 instead.");
return (int) ((metrics.xdpi + metrics.ydpi) / 2.0);
} else {
return (int)metrics.xdpi;
}
} }
public static int getDPI() public static int getDPI()

View File

@ -46,9 +46,12 @@ int Device::getDPI()
return dpi; return dpi;
} }
float Device::getPixelRatio() float Device::getPixelRatio()
{ {
return Device::getDPI() / 96.0f; const HDC dc = GetDC(NULL);
const auto xdpi = GetDeviceCaps(dc, LOGPIXELSX);
ReleaseDC(nullptr, dc);
return xdpi / 96.0f;
} }
void Device::setAccelerometerEnabled(bool isEnabled) {} void Device::setAccelerometerEnabled(bool isEnabled) {}

View File

@ -59,7 +59,7 @@ void AxmolRenderer::Resume()
if (!glview) if (!glview)
{ {
GLViewImpl* glview = GLViewImpl::createWithRect( GLViewImpl* glview = GLViewImpl::createWithRect(
"AXMOL10", ax::Rect{0, 0, static_cast<float>(m_width), static_cast<float>(m_height)}); "axmol2", ax::Rect{0, 0, static_cast<float>(m_width), static_cast<float>(m_height)});
glview->UpdateOrientation(m_orientation); glview->UpdateOrientation(m_orientation);
glview->SetDPI(m_dpi); glview->SetDPI(m_dpi);
glview->setDispatcher(m_dispatcher); glview->setDispatcher(m_dispatcher);