Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 11:26 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Nov 03, 2011 6:01 pm 
Offline

Joined: Sat Aug 13, 2011 8:04 pm
Posts: 70
Location: Canada
Hi Matthias/all,

Situation so far: I have a cell in a table that has a coloured background and a text label. The colour of the background depends on data behind the cell and can be changed by clicking on the cell and bringing up the TWL colour selector widget.

This all works fine, I made a cell renderer that makes objects of the type of ColourButton (my subclass of Button).

What I want to do is: If I set the colour of the widget to a dark colour I want to change the text on the button to a light one. I figured out how to find the luminance value for the colour selected ok, and my first guess was to use the animation state like this: getAnimationState().setAnimationState(STATE_REVERSE_VIDEO, true)
[NB. I edited this post, previously I didn't have my own state for it]

But what happens is that no text is displayed when I do this (not visible is more correct I think). I know that if I use this same method and state key it does show white text on a button that is not inside a table, so I figure it must be to do with the cell rendering. [Edit. I now see that if my font doesn't define the state I'm using I just get the default (black) text, so it looks like it does find the font param, but doesn't paint it the right colour... fyi this is the font param definition: <fontParam if="reverseVideo" color="#FFFFFF"/>]

I looked at your DecoratedTextRenderer (which you pointed me to in a previous post for showing coloured text in string cells). The way it's done there is to setAnimationState on the renderer itself which indirectly subclasses Widget. This makes me think that the approach I'm trying is correct, to set the state on my table button widget.

I must be missing something... thanks for any help!
tomas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2011 1:01 am 
Offline

Joined: Sat Aug 13, 2011 8:04 pm
Posts: 70
Location: Canada
Little update... been stepping through with the debugger and now I know what's happening to it.

But I'd still like a way round it if there is a better one than what follows:

Reason for no text: by setting the font state I'm getting a font colour of white from my theme file. But because the button widget is already tinted, the white is added to the tint stack, not overlayed on top of it... so, white being submissive to other colours, the result is text = same colour as tinted background.

One way I can get around it: I can create a tinted version of the background image and use it as the background for the button instead of applying a tint when the user selects a new colour.

Please let me know if that's an ok way to do it, or if there's a more elegant solution.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2011 1:47 am 
Offline

Joined: Sat Aug 13, 2011 8:04 pm
Posts: 70
Location: Canada
Doing all the replying to my own post :lol:

fyi. that works really fine, and it's easy. I just override setBackground on my colour button widget and create a tinted version based on my colour.

I'm constantly amazed by how complete TWL is... Matthias, you thought of everything!

Thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2011 6:31 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
:)

One thing to be aware of when using setBackground is that it is also called by the theme engine. So it might happen that your background is again replaced by the one from the theme.

There are 2 easy ways to solve this:
- override setBackground() and paintBackground() and manage your own tinted copy and update it when ever setBackground() is called (or your color changed).
- override applyThemeBackground() and handle the new theme background there.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2011 1:20 pm 
Offline

Joined: Sat Aug 13, 2011 8:04 pm
Posts: 70
Location: Canada
Haven't seen any issue with it yet, but thanks for the heads up!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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