-
Notifications
You must be signed in to change notification settings - Fork 16
Description
A suggestion to separate font handling from drawText
to PixelWindow
.
Currently, the drawText
method creates a new font on every call, fonts in java are allocated on the heap, which is generally quite slow, so to de-allocate and allocate the same object over and over seems wasteful.
The suggestion then is to move font handling from drawText
to PixelWindow
in the form of three methods, a change to positioning, and possibly a new class member.
The suggested methods are loadFont
, getFont
, and measureText
.
loadFont
is for loading a font, taking parameters - name, style, size.
getFont
is for getting the currently loaded font, this could be done using either canvas.g.getFont
or a class member called font.
measureText
is for helping with correctly aligning text, it would take in a size and give out a tuple of (width, height). Currently when drawing text it draws at (x, y + size), which for me was a bit counter-intuitive when trying the lib out preparing for the course.
The expected thing is to manually need to offset so when it is done for you some spacing calculations get weird. Also, the size property is font size, not pixel size so that is more reason for a real measureText
method since the font size doesn't always corrolate 1:1 to pixels.
It is important to note that changing size within drawText
should still be possible, both to keep compatibility in BlockGame but also for convenience.