Pens and colors

This forum is for general developer support questions.
Post Reply
djg
Posts: 30
Joined: Sat Jan 26, 2013 5:00 pm

Pens and colors

Post by djg »

Hello,

What is the right way to set a pen to a certain color and then use it from within your program running in a window you openend on say the Workbbench screen? My guess is that you have to use ObtainPen() and GetColorMap(), but after reading the AutoDocs, I still have no idea how to do it as I can find no examples whatsoever anywhere.

Let's say I want to fill a rectangle with color 0x#0000FF00 and write some text using color #00FF0000, how would I do this in an Intuition window after I opened it?
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: Pens and colors

Post by thomasrapp »

GetColorMap will allocate a new color map independently from the current display. It is of no use for applications.

If you need access to the color map of a screen you get a pointer from Screen->ViewPort.ColorMap.

How you can get a certain color depends on the OS version and the screen mode.

For true color screens (each pixel has its own RGB value) on OS4 you can use SetRPAttrs and directly set the RGB value to draw with.

For true color screens on OS3 you can allocate a single pen, set its color to the desired value, draw what you want to draw and free the pen. Freeing the pen does not lose anything because each pixel has and keeps its own color value.

For palette mapped screens you should keep in mind that pens are shared and there is a limited number of them. So if you allocate a pen exclusively, you can dictate its color, but you also reduce the number of available pens in the system. Therefore it's better and friendlier to allocate pens shared using ObtainBestPen. Pens allocated this way must not have their color changed. So you might not get exactly the color you want, but a best match. But you keep the pens available for use by other programs, too. And it's more likely that you actually get a pen.
djg
Posts: 30
Joined: Sat Jan 26, 2013 5:00 pm

Re: Pens and colors

Post by djg »

Great explanation, thanks!

Tried it (on OS4.1 FE) and it worked. I noticed that although the alpha channel part of is ignored, I still had to set it to 0xFF (like the docs say), or Text() would not show text in the chosen color.
Post Reply