Windows UI Scaling Causes Screen Size To Be Incorrect

Is there a way to detect the UI scaling and adjust the screen size correctly?

I'm specifically talking about the Windows setting System > Display > Scale and layout > Change the size of text, apps, and other items.

When this is set to anything other than 100%, it causes only screen size (orxDisplay_GetScreenSize) to be scaled. The mouse position is not scaled with the screen size. This cascades and causes mouse to world coordinates and object placement to be calculated incorrectly.

I've posted an example below. With Scale set to 100%, left clicking the mouse makes the orx logo follow the mouse. If the scale is set higher, the orx logo is no longer placed under the mouse correctly. When the mouse is in the top left corner, the logo is underneath the mouse pointer. As you move the mouse down and to the right, the logo moves at scale across the screen the same direction. (i.e. When the mouse will move 100 pixels to the right, the logo moves much more than 100 pixels to the right.)

How can I prevent this from happening, other than forcing a user to change the setting to 100% which may make other parts of the screen hard to read?

LogoTest.ini

; LogoTest - Template basic config file

[Display]
Title           = LogoTest
FullScreen      = false
Decoration      = false
Smoothing       = true
VSync           = true

[Resource]
Texture         = ../data/texture
Sound           = ../data/sound

[Input]
SetList         = MainInput

[MainInput]
KEY_ESCAPE      = Quit
MOUSE_LEFT      = MouseLeft

[Viewport]
Camera          = Camera

[Camera]
FrustumWidth    = 1280
FrustumHeight   = 720
FrustumFar      = 2
FrustumNear     = 0
Position        = (0, 0, -1) ; Objects with -1 <= Z <= 1 will be visible
GroupList       = Logo

[Object]
Graphic         = @
Texture         = logo.png
SoundList       = @
Sound           = appear.ogg
Pivot           = center
AngularVelocity = 18
FXList          = FadeIn # ColorCycle
Group           = Logo

[FadeIn]
SlotList        = @
Type            = alpha
Curve           = smooth
StartTime       = 0
EndTime         = 1.5
StartValue      = -1
EndValue        = 0

[ColorCycle]
Loop            = true
SlotList        = @
Type            = hsv
Curve           = linear
Absolute        = true
StartTime       = 0
EndTime         = 6
StartValue      = (0, 1, 1)
EndValue        = (1, 1, 1)

Visual Studio 2019 (Community Edition)
LogoTest.cpp

/**
 * @file LogoTest.cpp
 * @date 27-Dec-2019
 */

#include "orx.h"

void orxFASTCALL InputUpdate(const orxCLOCK_INFO* _pstClockInfo, void* _pstContext)
{
    const orxSTRINGID logoID = orxString_GetID("Logo");
    orxOBJECT* logoObj;

    if (orxInput_IsActive("MouseLeft"))
    {
        orxVECTOR mousePosition = orxVECTOR_0;
        orxMouse_GetPosition(&mousePosition);
        orxLOG("Mouse position X '%f' Y '%f' Z '%f'", mousePosition.fX, mousePosition.fY, mousePosition.fZ);
        orxRender_GetWorldPosition(&mousePosition, orxNULL, &mousePosition);
        orxLOG("Mouse world position X '%f' Y '%f' Z '%f'", mousePosition.fX, mousePosition.fY, mousePosition.fZ);
        mousePosition.fZ = 0;
        logoObj = orxObject_GetNext(orxNULL, logoID);
        orxObject_SetPosition(logoObj, &mousePosition);
    }
}

orxSTATUS orxFASTCALL Init()
{
    orxCLOCK* pstMainClock;
    orxFLOAT width = orxFLOAT_0;
    orxFLOAT height = orxFLOAT_0;
    orxINPUT_TYPE   eType;
    orxENUM         eID;
    orxINPUT_MODE   eMode;
    const orxSTRING zMouseLeft;

    /* Gets input binding names */
    orxInput_GetBinding("MouseLeft", 0, &eType, &eID, &eMode);
    zMouseLeft = orxInput_GetBindingName(eType, eID, eMode);

    // Create the viewport
    orxViewport_CreateFromConfig("Viewport");

    // Create the object
    orxOBJECT* obj = orxObject_CreateFromConfig("Object");
    orxDisplay_GetScreenSize(&width, &height);
    orxLOG("Screen width '%f' height '%f'", width, height);

    pstMainClock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);
    orxClock_Register(pstMainClock, InputUpdate, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL);

    // Done!
    return orxSTATUS_SUCCESS;
}

orxSTATUS orxFASTCALL Run()
{
    orxSTATUS eResult = orxSTATUS_SUCCESS;

    // Should quit?
    if(orxInput_IsActive("Quit"))
    {
        // Update result
        eResult = orxSTATUS_FAILURE;
    }

    // Done!
    return eResult;
}

void orxFASTCALL Exit()
{
    // Let Orx clean all our mess automatically. :)
}

orxSTATUS orxFASTCALL Bootstrap()
{
    orxResource_AddStorage(orxCONFIG_KZ_RESOURCE_GROUP, "../data/config", orxFALSE);

    return orxSTATUS_SUCCESS;
}

/** Main function
 */
int main(int argc, char **argv)
{
    orxConfig_SetBootstrap(Bootstrap);

    orx_Execute(argc, argv, Init, Run, Exit);

    return EXIT_SUCCESS;
}
Tagged:

Comments

  • Hi @Freedom and welcome here!

    Thanks for reporting this, I was hoping we fixed all the scaling issues on all OSes over the course of last year, but apparently it's not the case.
    Just to be sure, which version of orx are you using? Is it the latest from the master branch on github?

  • I've pushed a tentative fix in https://github.com/orx/orx/tree/b-content_scale
    Would you mind trying it and letting me know if it fixed your issue?

    Also, please note that until I can find someone to test the changes on a Mac+Retina screen, it'll have to live in its own separate branch as I'm afraid I might have broken the retina support.

  • Just tested https://github.com/orx/orx/tree/b-content_scale in Windows 10 and it's working great. I have a MacBook I can test it on tomorrow, but I'd need to check if it has a retina screen.

  • To confirm, I pulled the latest master and tried on that. It had the broken scaling.

  • Thanks for testing!
    Lemme know if your MacBook has a retina screen. In which case I might have you run a handful of tests if you don't mind.
  • edited January 2020

    My MacBook has a retina screen.

    Unfortunately when I try to run ./setup.sh, I get the error Bad CPU type in executable.

  • Ha. That's a new one. Could you run code/build/rebol/r3-mac directly to see if that's the problem there?

  • Ah I see.

    λ file r3-mac
    r3-mac: Mach-O i386 executable
    

    I guess x86 binaries are not supported anymore on latest versions of OSX?

  • -bash: code/build/rebol/r3-mac: Bad CPU type in executable

    Anything I can do to help?

  • edited January 2020

    Rebol3 needs to be rebuilt for OSX/x64. I'll try to do it sometime next week (I'm a bit swamped with work lately).
    In the meantime, you can try to do it yourself if you want. The repository is https://github.com/orx/r3
    And there are instructions in the HOWTO.md file.
    For the OS_ID, you might want to use 0.2.40.

  • I might be able to check it out this weekend. I'll post if I get the chance.

  • Thanks. I'll keep you posted if I get a chance to do it first. Sorry about the delay, btw.

Sign In or Register to comment.