The MacView

Virtual Instrumentation from a Mac perspective

Thursday, June 03, 2010

How to Get All Mac System Colors in LabVIEW

Christina Roger's blog posts over at Eyes on VIs (specifically Secret LabVIEW System Colors and System Colors - Don't Believe Your Eyes) got me looking into the System Colors on the Mac. In doing so I wrote some VIs to query the OS directly (at least on the Mac) what all the system colors are. You can download the VIs at:

Mac System Color VIs

Both the Text Color API and the Brush Color API are very similar. They differ only in the function to call (duh) and the constants passed for what color to get. Here is GetThemeBrushAsColor.vi's block diagram:



My last post talked about converting a list of constants into an enum. I used this method (for both API calls) to create the enum input. For the RGBColor input, I just used an array of three Unsigned 16-bit Integers (Red, Green and Blue in that order in the array). The trickiest part was how to convert three u16s to a LabVIEW color code. LabVIEWs colors are an Unsigned 32-bit integer. The least significant byte is the Blue value. The next most significant byte is the Green value and the next most is the Red value, in other words: 0x00RRGGBB. The most significant byte is where LabVIEW stores magic flags, so we'll keep that zero. To convert from 16-bit values to 8-bit values, we just need the upper half of the 16-bit values. So we use Split Number primitive to get the upper half of the 16-bit values and use Join Numbers to put the colors in the right places.



Then it's just a matter of getting the Call Library Function primitive set up correctly. There you go. Simple call to get all sorts of colors from the OS.

Labels: , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.