Ooops
November 28, 2020, 11:15:33 AM

Author Topic: [bmx] Determine Text Selection Color by SebHoll [ 1+ years ago ]  (Read 575 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
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:
Code: [Select]
#include <FL/Fl.H>

extern "C" {
unsigned fl_get_color( Fl_Color i ){
return Fl::get_color( i );
}
}
color.m:
Code: [Select]
#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
  1. Strict
  2.  
  3. ' Sample App
  4.  
  5. Local red:Byte, green:Byte, blue:Byte
  6.  
  7. GetSelectionColor( red, green, blue )
  8.  
  9. Print "Selection Color: RGB( " + red + ", " + green + ", " + blue + " )"
  10. End
  11.  
  12. ' Selection Color Function
  13.  
  14. ?Win32
  15.        
  16.         Import Pub.Win32
  17.        
  18.         Extern "win32"
  19.                 Function GetSysColor:Int( nIndex:Int )
  20.         EndExtern
  21.  
  22. ?MacOS
  23.  
  24.         Import "color.m"
  25.        
  26.         Extern "C"
  27.                 Function NSGetTextSelectionColor( red:Int Ptr, green:Int Ptr, blue:Int Ptr )
  28.         EndExtern
  29.  
  30. ?Linux
  31.  
  32.         Import MaxGUI.FLTKMaxGUI
  33.         Import "flcolor.cpp"
  34.        
  35.         Extern "C"
  36.                 Function fl_get_color( color )
  37.         EndExtern
  38.  
  39. ?
  40.  
  41. Function GetSelectionColor( pRed:Byte Var, pGreen:Byte Var, pBlue:Byte Var )
  42.         ?Win32
  43.                 Local tmpColour:Int = GetSysColor(COLOR_HIGHLIGHT)
  44.                 pRed = tmpColour & $FF
  45.                 pGreen = (tmpColour Shr 8) & $FF
  46.                 pBlue = (tmpColour Shr 16) & $FF
  47.         ?MacOs
  48.                 Local red, green, blue
  49.                 NSGetTextSelectionColor( Varptr red, Varptr green, Varptr blue )
  50.                 pRed = red
  51.                 pGreen = green
  52.                 pBlue = blue
  53.         ?Linux
  54.                 Local color = fl_get_color( 15 )  'FL_SELECTION_COLOR: 15
  55.                 pRed = color Shr 24
  56.                 pGreen = (color Shr 16) & $FF
  57.                 pBlue = (color Shr 8) & $FF
  58.         ?
  59. EndFunction


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal