New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gui: replace deprecated printEx with printf #51
Conversation
The libtcod/src/libtcod/sys_sdl_c.c Line 214 in 790b3f5
So far this does break the hmtool, but I'd rather update the hmtool than keep the deprecated function calls. The landmass status now has |
src/libtcod/gui/togglebutton.cpp
Outdated
@@ -37,10 +37,11 @@ void ToggleButton::render() { | |||
con->setDefaultBackground(mouseIn ? backFocus : back); | |||
con->setDefaultForeground(mouseIn ? foreFocus : fore); | |||
con->rect(x,y,w,h,true,TCOD_BKGND_SET); | |||
const char check = pressed ? TCOD_CHAR_CHECKBOX_SET : TCOD_CHAR_CHECKBOX_UNSET; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If printf
is used then this will need to be Unicode. The correct codes are listed here (U+2610/U+2611). These codes also need to be mapped to the TCOD layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codes no longer need to be remapped on the develop branch.
UTF-8 example, check
is now a char pointer:
const char* check = pressed ? "\u2611": "\u2610";
if (label) {
con->printf(x,y,TCOD_BKGND_NONE,TCOD_LEFT,"%s %s", check, label);
} else {
con->printf(x,y,TCOD_BKGND_NONE,TCOD_LEFT,"%s", check);
}
Ahh, quite a bit more involved then i expected. didnt put much thought behind this, my bad. a few things noticed while getting it to work -- toolbar which uses printframe passes in the name directly to the format argument, which can be unsafe if it uses % characters. -- |
Welcome to libtcod development, encodings are tricky to work with everywhere. Hopefully I've made things better since I took over as the primary maintainer, but it's hard to tell.
I didn't see any problems with your changes so far other than the need to upgrade non-deprecated functions to Unicode. If you push more changes then I'll comment on them, and I can take over if it ever gets too complex.
That would be true for other parts of the API and I'd make a big deal about it if that were the case. Semantic Versioning forbids making breaking changes to the public API without a major version increment, but the GUI headers were never properly documented, and are technically not part of the public API, just some of the samples happen to use them.
I probably missed it because it was part of the C++ API. I have major plans on refactoring the C++ API to use actual namespaces instead of namespace classes. So either I'll handle that or we'll coordinate on it.
I lot of the old functions do that, fixing it will always break the rare cases where
You have this backwards, while the libtcod/samples/hmtool/operation.cpp Line 13 in 790b3f5
vs "↑↓ z", With a Unicode mapping and UTF-8 functions you can use the special glyphs directly in the strings of C and C++ code. It's harder to do that with the EASCII functions since those numbers could mean anything, so It's only a partial mapping because I've been lazy. The correct thing to do would be to go through the entire TCOD layout and map them all to Unicode. Other layouts like CP437 and any font loaded from a BDF or TTF file are already fully mapped to Unicode instead of |
regarding the magic numbers, i wasnt referring to the unicode argument, but the 2nd argument. for example from one branch libtcod/src/libtcod/sys_sdl_c.c Line 215 in 790b3f5
and in the other branch libtcod/src/libtcod/sys_sdl_c.c Line 243 in 790b3f5
they both pass in the same values, but the second passes it in as 0xC4 rather then the equivalent TCOD_CHAR_HLINE which the first does. anyway, i guess i can go and cleanup the changes ive made and commit the rest of the gui changes. |
Sorry for the mistake. That 2nd branch is for people who end up using a raw layout for a CP437 tileset, I'm forced to guess that the raw layout might be CP437 and remap some of the special characters to Unicode so that any pre-existing code doesn't break. The alternative would be to map any raw tilesets to the raw codepoints and CP437 Unicode codepoints simultaneously. It could be removed, but only in an a major version release. You could add the printframe function, but |
I pushed some changes to the TCOD layout. The develop branch will load TCOD fonts as Unicode. Just pull from your upstream/develop branch and continue. There is another alternative to the magic mappings in the 2nd branch. I've been considering procedurally generating the box drawing glyphs needed by most of the drawing functions, but it was never a high enough priority for me to start working on. |
thanks, one thing im stuck on is getting it to draw the arrows that the Z label needs. |
You no longer need to mess with |
e7280c4
to
2460e7a
Compare
Ok, i got it, had to tweak the libtcod.cfg file to get it showing right, as the mapping from the newly added anyway, this commit fixes the issues, |
Sorry for that. I forgot that the old samples have never been updated in years. They'll need to be switched to use the set custom font function so that they can handle Unicode, and I'll handle that myself. |
Replaces printEx functions with the printf alternatives in the gui.
came across an assertion failure when trying the sample hmtool due to it trying to draw one of the widgets off screen.
also, avoid passing in the label directly as that causes problems if it conains any % formatting characters