bluescan / tacentview

An image and texture viewer for tga, png, apng, exr, dds, pvr, ktx, ktx2, astc, pkm, qoi, gif, hdr, jpg, tif, ico, webp, and bmp files. Uses Dear ImGui, OpenGL, and Tacent. Useful for game devs as it displays information like the presence of an alpha channel and querying specific pixels for their colour.
ISC License
344 stars 33 forks source link

[Suggestion] Support for non-US keyboards #33

Closed ClangPan closed 2 years ago

ClangPan commented 2 years ago

Now, I know this is a common issue with GLFW and ImGUI programs, but there are have been several workarounds posted to the ImGUI and GLFW issue trackers. I managed to make it work using a slightly 'dirty' method, but it would be nice to have this change made upstream.

I don't own any...although I'm sure you can set the OS to interpret the scancodes as if it were a different layout. If you have code (messy or not), it could be attached to this issue (after a sep bug is made for it).

        // Convert key codes to support non-US keyboards
        const char* keyName = glfwGetKeyName(key, 0);
        if (keyName)
        {
            key = static_cast<int>(static_cast<unsigned char>(keyName[0]));

        // Convert to upper-case
        if (key >= 97 && key <= 122)
            key -= 32;
        }

Adding this block of code just before the 'key' switch statement in 'KeyCallback()' seems to do the trick for AZERTY (need testing for other layouts such as QWERTZ). I also don't know if it has an impact on performance (probably not since it's a very small operation, but who knows). If this solution works out I feel like it's better than having the user change things in their OS as the vast majority of programs support different layouts natively (it seems to be a shortcoming on GLFW and ImGUI's side).

bluescan commented 2 years ago

It didn't seem to do anything bad. I've pushed a variant of the above in aa9c2350. There's also a change to the base library (tacent) that's needed... so a reconfigure (to fetch) is required.

It may change if/when I get to the key rebinding suggestion. I'm gonna leave this open a bit so more testing happens before next release. In any case, it 'should' now work for your French keyboard if latest is pulled.

ClangPan commented 2 years ago

I have tested multiple input methods (AZERTY, Dvorak, QWERTZ, QWERTY) and it seems to be working pretty well for now!

bluescan commented 2 years ago

Great. Will close this one. Thx for the additional tests.