Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 1:52 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: TextAreaModel Questions
PostPosted: Wed Jun 13, 2012 8:10 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 269
Hello!

I am implementing my own TextAreaModel to use a mark up language I designed in the past. This allows me to use a single font and then add color and formatting based on this markup language.

I have managed to do this in TWL! The only issue is that the text formatting does not seem to be working at all. I implemented my own TextAreaModel and then made my own Style.

For example, I have done the following in my custom Style:
Code:
put(StyleAttribute.FONT_WEIGHT, 700);


which, from my understanding is equivalent to the HTML model of "bold". But this has no affect on my text for my TextArea. I can color the text just fine - just the formatting doesn't seem to be working. I have also tried FONT_SIZE and FONT_ITALICS and both do not seem to work.

I've looked at the HTMLTextAreaModel code and they do not seem to do anything special for these StyleAttributes - put(attribute, value) is essentially used.

Here is the code in the custom style (simplified):
Code:
private void parseText ( String text )
{
    //This works just fine:
    put(StyleAttribute.COLOR, Color.RED);
    //This does not work:
    put(StyleAttribute.FONT_WEIGHT, 700);
      
}


And here is the code in my custom TextAreaModel:
Code:
public void setText(String text)
{
    ColorFormatStyle textStyle = new ColorFormatStyle(text);
    Element element = new TextElement(textStyle, text);

    elements.add(element);
    doCallback();
}

@Override
public Iterator<Element> iterator ()
{
    return elements.iterator();
}



Thanks for any help you can give!


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 10:18 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1188
The extended font support requires the use of a FontMapper. You can try the TWLFontMapper library which is like a plugin into the LWJGLRenderer which offers runtime TrueTypeFont support (currently only used by TextArea).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 11:22 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 269
Thanks!

I'll try and use this.

Are there some .jar files around that contain these new features or do I have to use the source (which is fine but is easier to simply add a jar file to my build path, etc).


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 12:07 am 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 269
Update!


I have managed to get all of this to work except something funky happens.

When I mouse over the widget that displays my tooltip with the font, it makes everything that Slick is rendering vanish!

I had a FPS counter and "Hello World!" in the background but they just sorta...go away after the tooltip pops up.

Do you know what could be causing this?

EDIT:

Ok, I think I fixed this, but it is kinda odd. Slick was using AngelCodeFont. And I had "Arial" as the font for my tool tip. I was setting it like so in my custom Style:
Code:
put(StyleAttribute.FONT_FAMILIES, new StringList("Arial"));


This seemed to be somehow overriding what Slick was using, like it sorta lost it's font. So I put a call in the Slick render method to set the font I want to use, and it worked just fine. If anyone knows why this happened, please due explain because it seems very odd to me due to my limited experience with all of these tools/etc.


One thing I noticed is that there is now a disconnect from the theme xml and my component because I need to use these special fonts. But I guess this is a small price I have to pay to get fancy looking tool tips!


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 5:32 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1188
I don't know how Slick's internal GL state caching works so I can't really help you there - do you use Slick to render from within a TWL widget's paintWidget method?
Also it seems that LWJGLRenderer does not restore the current GL color - so if your Slick font is gone missing it could also be caused by having a black color?

As for using different fonts in the XML and in the TextArea - I'm working on an enhancement to the XML <fontDef> tag to allow it to use the FontMapper.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 2:10 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 269
MatthiasM wrote:
I don't know how Slick's internal GL state caching works so I can't really help you there - do you use Slick to render from within a TWL widget's paintWidget method?
Also it seems that LWJGLRenderer does not restore the current GL color - so if your Slick font is gone missing it could also be caused by having a black color?


I am not rendering on a TWL widget. It may be using black for the color - I will check this out. I usually set the font and color on the real game/etc but I haven't written any Slick code yet since I am still playing around with TWL. It is really great so far. You've done a great job, both from an implementation stand point and from supporting it (I ask a ton of questions).

MatthiasM wrote:
As for using different fonts in the XML and in the TextArea - I'm working on an enhancement to the XML <fontDef> tag to allow it to use the FontMapper.


Sounds cool!

On a side note, do you ever take requests for features?


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 5:50 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1188
Sure - several people already posted feature requests - and most have been implemented. I'll decline a request if it duplicates functionality which is already in, or when it doesn't fit into the overall design of the library.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 9:22 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 269
MatthiasM wrote:
Sure - several people already posted feature requests - and most have been implemented. I'll decline a request if it duplicates functionality which is already in, or when it doesn't fit into the overall design of the library.


Cool! I'll keep that in mind. This pleases me greatly because I'm writing a 4X game. As I'm sure you know, they can require some heavy/specific stuff. :)

A few updates...

1. I managed to get my text area to work great with my markup language. Thanks a lot for your help.

2. I looked into the color going "Black" and it seemed to "fix" itself after I got the final version of my model and style completed. Guess I was doing something odd =P.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group