Slick Forums

Discuss the Slick 2D Library
It is currently Wed Oct 16, 2019 11:36 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Jun 28, 2013 5:49 pm 
Offline

Joined: Sat Aug 13, 2011 8:04 pm
Posts: 87
Location: Canada
Hi Matthias,

It's about how to tint images loaded from the theme. I have a situation where the solution I'm using works, but seems heavyweight.

I have an image (actually several of them) which gets loaded from theme and, as normal, it's a GridImage with an array of 9 TextureAreas inside it. Each of those is created in TWL with a tint colour, I load a white one from the theme, because I want to tint them.

I've been keeping a tinted version of each of the colours I need by calling createTintedVersion() on the Image returned by the theme. I thought it would be a good idea to cache these, as I could have many to draw, but the number of colours can grow (the user would create as many as they like), and so I looked at how to just store the one base white image and then use the LWJGLTexture.bind(Color) method in a call to my own version of draw... that is, add Color to the current draw() methods.

Trouble is, I'm getting deeper and deeper into your classes trying to find a way to do this, and I'm not sure how far I'd end up in order to achieve what is essentially fairly easy. The trouble is I can't get access to the LWJGLTexture to either sub-class or make my own version of a TextureArea.

So, I guess my question has 2 parts:
1) Is there already a way to draw a grid image in different colours on the fly without creating new tinted versions?
2) If there isn't, can you suggest a way for me to load an image from the theme that I can then use to make my own MutableColourTextarea or MutableColourGridImage (or similar)? Does the theme always load the same type of image, or is there a parameter that loads another type? I would really like to keep using the theme for this, as it does so much cool stuff, like breaking down the image into a grid :)

I hope all of this makes sense, essentially instead of calling draw() like this :
Code:
image.draw(animationState, x, y, w, h);

I'd like to call it like this :
Code:
image.draw(animationState, x, y, w, h, tintColor);


thanks for any help!
tomas


Top
 Profile  
 
PostPosted: Fri Jun 28, 2013 6:01 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
Do this inside your paintWidget method:
Code:
final Renderer renderer = gui.getRenderer();
renderer.pushGlobalTintColor(r, g, b, a);
try {
   // your rendering code here
} finally {
   renderer.popGlobalTintColor();
}

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Jun 28, 2013 6:26 pm 
Offline

Joined: Sat Aug 13, 2011 8:04 pm
Posts: 87
Location: Canada
Perfect!!

So easy... lucky I didn't find a way to do it haha
:mrgreen:

thanks a lot


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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