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
404 stars 37 forks source link

Request: Add access to the Atlas and Tileset used by SDLConsoleRender #121

Closed kotrenn closed 1 year ago

kotrenn commented 1 year ago

Ran into a case where I wanted to know the pixel dimensions of a font for a console renderer. Dug through the source and found I could get it through console_render._atlas.tileset where console_render is an instance of SDLConsoleRender. Was wondering if we could get more explicit support for access to these along with a note in the documentaiton.

HexDecimal commented 1 year ago

The atlas dimensions are arbitrary since they're generated on-demand, but I can't really tell why you'd need them unless you wanted to access the tiles on the atlas directly. The tileset itself is accessible and tells you the size of a tile which is used for most cases I can think of. What's your example for why you need the atlas size?

kotrenn commented 1 year ago

The atlas dimensions were not my goal, but the size of individual tiles within the tileset as you suggested. My issue was that there is no console_render.tileset, and instead I went through the atlas with console_render._atlas.tileset.tile_width.

I wanted to be able to generate textures of strings that could later be used during rendering. I was trying to optimize by keeping one console around for rendering the string to rather than create a new console every time. I initialized this string console with a fixed width of 80. The tile_width / tile_height come in when I want to crop this to just the characters being printed (e.g. if rendering 'foo' then just return a texture of size 3 tile_width x tile_height rather than 80 tile_width x tile_height).

HexDecimal commented 1 year ago

Sorry, I thought you were talking about the internals. I'll go ahead and make SDLConsoleRender._atlas a public attribute.

kotrenn commented 1 year ago

Thank you!