Cataclysm-DDA icon indicating copy to clipboard operation
Cataclysm-DDA copied to clipboard

font and rasterization improvements for ImGui

Open db48x opened this issue 1 year ago • 9 comments

Summary

Interface "use Freetype to render fonts for ImGui, and use multiple fonts in the ImGui interface"

Purpose of change

Make ImGui use Roboto by default, and the Freetype rasterizer. Load both the configured gui font and the normal monospaced font for use by ImGui. Make item descriptions use the mono font for drawing ASCII artwork. Configure hinting so that Terminus and unifont don’t look awful.

Fixes #76420

Testing

Check out the artwork for a pistol or something.

Additional context

This is a draft for a reason: I need someone who builds on Windows and/or Mac to give me the right CFLAGS/LDFLAGS for linking against Freetype2

db48x avatar Sep 18 '24 18:09 db48x

Is there a particular reason for adding a new font to the mix, and are there any issues with including Apache licensed material in a cc-by-sa 3.0 project?

harakka avatar Sep 19 '24 04:09 harakka

Good questions. Yes, the reason for adding Roboto is that it is a proportional font. We could pick from quite a selection, but Roboto was ready to hand, appropriately licensed, inoffensively styled (not deliberately weird or thematic, or deliberately bad like Comic Sans, etc), and has relatively thick strokes even at small font sizes (which makes it render well even if we stick to the default STB rasterizer which cannot do any hinting). And of course the user can override the choice if they prefer something else.

Apache 2.0 is completely compatible with the Creative Commons license, and it meets the definition of an Open Source license.

db48x avatar Sep 19 '24 04:09 db48x

I guess it builds fine on OSX. Anyone want to give it a try and make sure it works?

db48x avatar Sep 20 '24 15:09 db48x

Weird. It compiled just fine on Windows while it was a draft…

db48x avatar Oct 06 '24 17:10 db48x

It's broken at the macOS build referencing imgui so I'm assuming this isn't a random failure?

Maleclypse avatar Oct 15 '24 01:10 Maleclypse

I wish it were. It's been more than 15 years since I did any development on OSX, and I never had to dig too deep into the build system on that project. I don’t have a Windows machine either. I’d appreciate some help getting this patch to work on those platforms from anyone who has the time.

I spent a little time last weekend trying to find documentation on the subject, but didn’t make much headway. I didn’t really want to spam the CI system with guesses, but on the other hand the only guess I have is to add -lfreetype to the LDFLAGS and hope for the best.

db48x avatar Oct 15 '24 04:10 db48x

@db48x I took a look. does not compile on VS2022. VS2022 does not like your usage of '__attribute__((unused))'. Instead it prefers the C++17 '[[maybe_unused]]'. If we can't use C++17 across the board, maybe consider a preprocessor definition?

katemonster33 avatar Oct 16 '24 23:10 katemonster33

Oops, sorry about that. It looks like I fixed that last week and then just never pushed it. Must have gotten distracted.

db48x avatar Oct 17 '24 00:10 db48x

A little improvement: Screenshot from 2024-10-19 01-40-13 Screenshot from 2024-10-19 01-49-23

db48x avatar Oct 19 '24 12:10 db48x

Crap I misread this and thought it was no longer breaking Mac builds.

Maleclypse avatar Oct 24 '24 03:10 Maleclypse

Hi @db48x I realize this is super, super late... but can I ask what motivated the choice of Roboto-Medium? I just spent a while chasing down what's going on in this menu only to find out that the | and . characters are simply how Roboto-Medium renders them. (I used this to compare the characters outside of the game's rendering pipeline)

image

(Side note, the mismatched lines is because we were previously relying on utf8width. I can mostly paper over that: ) image

I don't want to say "Hey, let's change the font again! A year after the last change! (which itself had 3 changes in as few months)"... but it is pretty ugly here. So just looking for your opinion, thanks.

For comparison, unifont looks absolutely great:

image

(It also plays nicely with utf8width!)

RenechCDDA avatar Sep 27 '25 12:09 RenechCDDA

I gave my reasons in a previous comment.

If you just want the health bars to make an actual column, then put them in the second column of the menu entries. Instead of calling uilist::addentry, call uilist::addentry_col.

If you want the health bars to look more like bars, might I suggest changing what characters we use? What if we used ██▃▁▁ or ██▍ ?

db48x avatar Sep 27 '25 13:09 db48x