tophat2d / tophat

:tophat: a 2d game library for Umka
https://tophat2d.dev
BSD 3-Clause "New" or "Revised" License
73 stars 5 forks source link

Combine `canvas::drawText()` and `Font.draw()` into one function #192

Closed vtereshkov closed 4 months ago

vtereshkov commented 4 months ago

Can canvas::drawText() take an optional ^Font parameter?

skejeton commented 4 months ago

Instead I think there should be canvas::font.draw which is an instance of Font, but that means Font is an interface. We need @marekmaskarinec to weigh in.

marekmaskarinec commented 4 months ago

My proposed solution:

This both prevents breaking and opens up possibilities for other types of fonts like bitmap fonts. What are your thoughts?

vtereshkov commented 4 months ago

@marekmaskarinec What function will finally draw the text? The interface method Font.draw()?

skejeton commented 4 months ago

@marekmaskarinec What function will finally draw the text? The interface method Font.draw()?

Yes

skejeton commented 4 months ago

My proposed solution:

  • change font::Font to an interface
  • add font::TrueType (name subject to change) which implements font::Font
  • add canvas::PixelFont (name subject to change) which is an empty struct that implements font::Font using existing canvas functions

This both prevents breaking and opens up possibilities for other types of fonts like bitmap fonts. What are your thoughts?

I agree. But how do we access the PixelFont?