libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
410 stars 36 forks source link

Wrong behavior for tcod.console.Console.draw_frame with title and colors #95

Closed Earl7Fx3 closed 2 years ago

Earl7Fx3 commented 4 years ago

version 11.13.5 but it's been around for a while.

This call will produce the following (expected) result: con.draw_frame(0, 0, 11, 5, 'test3') image

If I want to modify the border color (and the title color), according to the doc:

fg and bg are the foreground text color and background tile color respectfully. This is a 3-item tuple with (r, g, b) color values from 0 to 255. These parameters can also be set to None to leave the colors unchanged.

but this call produces this: con.draw_frame(0, 0, 11, 5, 'test3', fg=tcod.grey) image

so if I want to get the title visible again, I either need to write above it or do the following call: con.draw_frame(0, 0, 11, 5, 'test3', fg=tcod.grey, bg=tcod.black) image which is not what I wanted, though, and neither what the doc describes.

to sum up, I believe the color of the border, which is given by fg, shouldn't be the color of the background for the title area, that should remain given by bg.

HexDecimal commented 4 years ago

Thanks for going through the effort to post this. Unfortunately the docs were already fixed, at least as far as being more clear on the behavior of colors.

This should perform what you originally wanted to do:

con.draw_frame(0, 0, 11, 5, fg=tcod.grey)
con.print_box(0, 0, 11, 1, ' test3 ', fg=tcod.grey, alignment=tcod.CENTER)
Earl7Fx3 commented 4 years ago

Thank you, it is indeed a work-around but I humbly believe the inconsistency with the default call is wrong, albeit not a bug: If I want a white border with black background, like the 1st picture provided, it would make sense that

con.canvas.draw_frame(0, 0, 11, 5, 'test3')
con.canvas.draw_frame(0, 0, 11, 5, 'test3', fg=tcod.white, bg=tcod.black)

produce the same results, but instead we get this: image image

It feels wrong that the default behavior gives same color for the text than the border, but if you specify the border color it is not. Furthermore, if you specify only fg, then both the text color and the background text color are the same color.

HexDecimal commented 4 years ago

I don't see it as a workaround, I see it as the correct way to draw frame titles. I don't want all libtcod games to have this single style of frame banner enforced by draw_frame.

To me, it's the function limiting what a title banner can look like that's wrong, and if draw_frame didn't already take the title parameter then I'd feel no need to add it.

The technical problem of draw_frame is that it draws the frame with one set of colors then draws the title with a swapped set, which absolutely breaks if either of the colors are None. It can be fixed by changing from one forced style to another or by disallowing None for the colors when a title is given.

HexDecimal commented 2 years ago

Closing since the confusing syntax has been deprecated in the current versions, and the code examples demonstrate the better way to render title text.