subsoap / defos

Extra native OS functions for games written using the Defold game engine
Creative Commons Zero v1.0 Universal
112 stars 16 forks source link

Fixing the defos_set_window_title() #127

Closed e1e5en-gd closed 2 years ago

e1e5en-gd commented 2 years ago

Changing parameter encoding when window title changes. Fix https://github.com/subsoap/defos/issues/126

subsoap commented 2 years ago

2022-01-31 12_06_29-______

What I see when testing, but it is different from before (which was garbled characters) so I'll assume it does work and just requires Russian / Chinese / etc. to be enabled in the OS for chars to properly display? I don't know enough about this to say.

Thank you for the patch!

britzl commented 2 years ago

What I see when testing, but it is different from before (which was garbled characters) so I'll assume it does work and just requires Russian / Chinese / etc. to be enabled in the OS for chars to properly display?

I don't think that's the case. When I tested the change in the engine itself I got it to show a Russian title on my Win 10.

@e1e5en-gd what did you test with?

e1e5en-gd commented 2 years ago

@britzl, I tested on Windows 11. image

If I'm not mistaken, then: • if the characters are displayed incorrectly, then this is a problem in the encoding; • if instead of characters one character is displayed (a question mark, for example), then the font does not support these characters.

@Subsoap, you can ask you to try in the project settings to change the name to a string with Russian characters "Привет, мир!". If the name is displayed correctly, then the problem is in my modifications. If question marks are displayed, then the system font may not support these characters.

britzl commented 2 years ago

@subsoap, you can ask you to try in the project settings to change the name to a string with Russian characters "Привет, мир!". If the name is displayed correctly, then the problem is in my modifications. If question marks are displayed, then the system font may not support these characters.

Good point. This would be a quick way of testing if it works or not!

e1e5en-gd commented 2 years ago

Also tried on Windows 7: image

subsoap commented 2 years ago

I tried again with 192 beta but it's still the same for me.

DefOSWinTitle.zip

2022-02-01 04_00_30-___ Defos _______

But then I tried just setting the window title with 192 game.project and it does display properly. So there must be something missing or done wrong somewhere.

2022-02-01 04_04_19-我使用

2022-02-01 04_05_20-Я установил этот заголовок с помощью Defos

Setting the window title after this doesn't help, still shows as ???s for me.

subsoap commented 2 years ago

Also

2022-02-01 04_06_56-______, ___!

vs

2022-02-01 04_08_12-Привет, мир!

e1e5en-gd commented 2 years ago

I'll try to reproduce the error myself (I'll try to change the system language). Is it possible to somehow display values from the C++ extension to see what comes in the argument, how is the recoding done? I'm not very good at understanding how to work with the extension

e1e5en-gd commented 2 years ago

@subsoap How does the previous version with CA2W work with Russian characters?

e1e5en-gd commented 2 years ago

In the above working example in Defold, the code is as follows:

wchar_t unicode_title[MAX_WINDOW_TITLE_LENGTH];
int res = MultiByteToWideChar(CP_UTF8, 0, title, -1, &unicode_title, MAX_WINDOW_TITLE_LENGTH);
if (res <= 0)
{
    unicode_title[0] = 0;
}
(void) SetWindowTextW( _glfwWin.window, unicode_title );

When editing in the extension and transferring this code, I cursed at & in the MultiByteToWideChar function. As a result, the code is written like this:

wchar_t unicode_title[MAX_WINDOW_TITLE_LENGTH];
int res = MultiByteToWideChar(CP_UTF8, 0, title_lua, -1, unicode_title, MAX_WINDOW_TITLE_LENGTH);
if (res <= 0)
{
    unicode_title[0] = 0;
}
SetWindowTextW(dmGraphics::GetNativeWindowsHWND(), unicode_title);

Now I decided to check and display the results that comes to the input and we get after the conversion. To do this, I use a MessageBox and thought, suddenly converting LPCWSTR is not enough (so I added it):

MessageBox(
    NULL,
    (LPCSTR)title_lua,
    (LPCSTR)"Input",
    MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1
);
wchar_t unicode_title[MAX_WINDOW_TITLE_LENGTH];
int res = MultiByteToWideChar(CP_UTF8, 0, title_lua, -1, unicode_title, MAX_WINDOW_TITLE_LENGTH);
if (res <= 0)
{
    unicode_title[0] = 0;
}
MessageBoxW(
    NULL,
    unicode_title,
    (LPCWSTR)L"Without (LPCWSTR)",
    MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1
);
MessageBoxW(
    NULL,
    (LPCWSTR)unicode_title,
    (LPCWSTR)L"With (LPCWSTR)",
    MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1
);
SetWindowTextW(dmGraphics::GetNativeWindowsHWND(), (LPCWSTR)unicode_title);

My results are the following: imageimageimage

Unfortunately, there is no way I can reproduce the error that occurs. So I ask you to try. I'm not very good at C++. Sorry.