Page 1 of 1
Pens and colors
Posted: Sun Sep 13, 2020 6:49 pm
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?
Re: Pens and colors
Posted: Mon Sep 14, 2020 9:15 am
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.
Re: Pens and colors
Posted: Mon Sep 14, 2020 12:43 pm
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.