Get system highlight color?
BlitzMax Forums/MaxGUI Module/Get system highlight color?
| ||
Is there any way to get the system highlight color? I would like to make an image in a canvas selected by matching the color to the system's highlight color for a uniform look for the user. |
| ||
There's no built-in function but here's one that I've cooked up for you that should work with MaxGUI on all three platforms:Strict ' Sample App Local red:Byte, green:Byte, blue:Byte GetSelectionColor( red, green, blue ) Print "Selection Color: RGB( " + red + ", " + green + ", " + blue + " )" End ' Selection Color Functions ?Win32 Import Pub.Win32 Extern "win32" Function GetSysColor:Int( nIndex:Int ) EndExtern ?MacOS Import "color.m" Extern "C" Function NSGetTextSelectionColor( red:Int Ptr, green:Int Ptr, blue:Int Ptr ) EndExtern ?Linux Import MaxGUI.FLTKMaxGUI Import "flcolor.cpp" Extern "C" Function fl_get_color( color ) EndExtern ? Function GetSelectionColor( pRed:Byte Var, pGreen:Byte Var, pBlue:Byte Var ) ?Win32 Local tmpColour:Int = GetSysColor(COLOR_HIGHLIGHT) pRed = tmpColour & $FF pGreen = (tmpColour Shr 8) & $FF pBlue = (tmpColour Shr 16) & $FF ?MacOs Local red, green, blue NSGetTextSelectionColor( Varptr red, Varptr green, Varptr blue ) pRed = red pGreen = green pBlue = blue ?Linux Local color = fl_get_color( 15 ) 'FL_SELECTION_COLOR: 15 pRed = color Shr 24 pGreen = (color Shr 16) & $FF pBlue = (color Shr 8) & $FF ? EndFunctionYou will also need to save this into a new file called color.m in the same directory as the BMX source: #include <AppKit/AppKit.h> void NSGetTextSelectionColor( int* red, int* green, int* blue ){ float r, g, b; NSColor* c = [[NSColor selectedTextBackgroundColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; [c getRed:&r green:&g blue:&b alpha:NULL]; *red = (int)(255 * r); *green = (int)(255 * g); *blue = (int)(255 * b); }And for the Linux driver, save the following into flcolor.cpp: #include <FL/Fl.H> extern "C" { unsigned fl_get_color( Fl_Color i ){ return Fl::get_color( i ); } } Edit: Updated with Mac OS X/FLTK Linux code. |
| ||
Update code example so that it should now work on Windows, Mac OS X and Linux (with FLTK) and have added to the code archives here. |
| ||
Rock! I will give that a shot ASAP, thanks! [Edit] on mac Compile Error expected ')' before '*' token in color.m [/Edit] |
| ||
on mac Compile Error expected ')' before '*' token in color.m Hmmmm... How bizarre... I tested on 10.5 a few hours ago, and it compiled OK. Which line is the error reported on? |
| ||
void NSGetTextSelectionColor( Int* red, Int* green, Int* blue ) I'm running 10.6.3 with almost the newest Xcode (haven't updated for iPad yet...) [edit]must have been something in my copy paste, I went through Xcode to create the color.m and it works now, thanks![/code] |
| ||
Would love to see this integrated into maxgui officially, allows for canvases to be cleanly integrated with the OS standard gadgets as Gui fields. |
| ||
I'm running 10.6.3 with almost the newest Xcode (haven't updated for iPad yet...) [edit]must have been something in my copy paste, I went through Xcode to create the color.m and it works now, thanks! Yep - I'm guessing you pasted it into a new untitled .bmx file in MaxIDE first and then saved the file as cocoa.m. When you pasted it in, MaxIDE thinks the code is BlitzMax code and so autocorrects the case on 'int' to 'Int' - but C/C++/Objective-C are case-sensitive and so it doesn't recognise the type identifier 'Int'. Anyhoo - glad you got it working. :-) Just for future reference, it should also work if you save the file with the desired file extension first, and then paste it into IDE as then MaxIDE knows not to autocorrect code it isn't able to parse. Would love to see this integrated into maxgui officially, allows for canvases to be cleanly integrated with the OS standard gadgets as Gui fields. If I get time, I'll see what I can do. :-) |
| ||
Would love to see this integrated into maxgui officially, allows for canvases to be cleanly integrated with the OS standard gadgets as Gui fields. And so MaxGUI 1.39 was born... HTH! :-) |
| ||
Yep - I'm guessing you pasted it into a new untitled .bmx file in MaxIDE first and then saved the file as cocoa.m. When you pasted it in, MaxIDE thinks the code is BlitzMax code and so autocorrects the case on 'int' to 'Int' - but C/C++/Objective-C are case-sensitive and so it doesn't recognise the type identifier 'Int'. exactly my mistake. Was too lazy to launch xcode or even textedit. And so MaxGUI 1.39 was born... And there was much rejoicing! Love the other flags too, started putting them to use as soon as it was compiled. I was just fudging background colors before but that didn't take into account custom themes and such which should be covered automatically now, lovely! |