BitMapText real TextWidth?

hi,

i ran into a little problem with BitMapText. As i see, getLineWidth() does return the Boxwidth as far as one is set.

In my case i need the real textwidth of a centered text - so i thought of extending BitMapText and override the getLinewidth() not to calculate the TextBox (or use a new Function to return the value).

As it turns out, thats not possible, because letters is private. Next try was to copy the whole class and use my own, but thats not possible either, because BitmapTextPage is not a public-class.

Is there another way to modify BitMapText?

How about changing some of those privates to at least protected or maybe add getters/setters for those?
(can anyone simply submit changes to the source or how are Source-Changes handled?)

thanks

@tyrion

Private fields can be accessed through reflection I believe.

Protected fields are EVIL. We will never change these to protected. It would imply that this class is designed for extension (and even then getters would be better) when it’s completely not at all not event slightly designed for extension. (Heck, it’s barely designed for any sort of future modification, just look at the long list of bug fixes and unfixes.)

It’s questionable whether this is really a bug in getLineWidth() but it’s been the behavior forever and I’m loathe to change it.

The solution is pretty easy, though… do what Lemur does: clear the text box, get the line width, then set the text box back again.

Someday BitmapText will be rewritten. In the mean time, we touch it lightly and walk away quickly. :wink:

Only if you mark them accessible. But really, this is the two ton sledge hammer approach to a problem that has a pretty simple solution. (Especially since half the time you want the line width is to set a new text box anyway.)

Another question to the OP… can you explain more of what you are trying to do? Because the center() method will also center any spatial but for BitmapText you might need one more step first depending on what you are doing.

Ok, first: Thanks. For now i did exactly as described, emptied the Texbox and got my textwidth.

It’s for caret/cursor-positioning in an editable Textfield. But i got another case ahead where i need to resize a Quad based on textwidth as well … and probably do some effects later. … maybe i try to copy all relevant classes … :smiling_imp:

(for now i decided to switch back to self-written UI-classes instead of nifty or tonegodui)

Someday BitmapText will be rewritten. In the mean time, we touch it lightly and walk away quickly.

… ok … didn’t touch it …

You can look at how Lemur does things if you want. Codewise, it’s lighter weight than any of the alternatives… so it’s closer to pure JME code (it uses BitmapText internally for example). Whether you use it or not, you can at least see how it does things. (It was also meant to be the base for custom GUIs since most of it’s parts are reusable… just not very documented.)