[bmx] Determine Text Selection Color by SebHoll [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

Title : Determine Text Selection Color
Author : SebHoll
Posted : 1+ years ago

Description : Requires MaxGUI on Linux, and the following files to be in the same directory:

flcolor.cpp:
#include <FL/Fl.H>

extern "C" {
unsigned fl_get_color( Fl_Color i ){
return Fl::get_color( i );
}
}
color.m:
#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);
}

The main source file is found below: [/i]

Code :
Code (blitzmax) Select
Strict

' Sample App

Local red:Byte, green:Byte, blue:Byte

GetSelectionColor( red, green, blue )

Print "Selection Color: RGB( " + red + ", " + green + ", " + blue + " )"
End

' Selection Color Function

?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
?
EndFunction


Comments : none...