It is currently Tue Sep 17, 2019 7:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Control border color
PostPosted: Fri Apr 05, 2019 11:45 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 447
Hi,

I use the CanvasGadget for some custom controls. I want the border of them to match the TreeGadget, ListIconGadget, etc., which have a border color of 197, 197, 197.

However, none of the system colors match.

Is there a color I'm missing or is there a way to get a color from another control?
Code:
NewList colors.s()
AddElement(colors()) : colors() = "labelColor"
AddElement(colors()) : colors() = "secondaryLabelColor"
AddElement(colors()) : colors() = "tertiaryLabelColor"
AddElement(colors()) : colors() = "quaternaryLabelColor"
AddElement(colors()) : colors() = "systemRedColor"
AddElement(colors()) : colors() = "systemGreenColor"
AddElement(colors()) : colors() = "systemBlueColor"
AddElement(colors()) : colors() = "systemOrangeColor"
AddElement(colors()) : colors() = "systemYellowColor"
AddElement(colors()) : colors() = "systemBrownColor"
AddElement(colors()) : colors() = "systemPinkColor"
AddElement(colors()) : colors() = "systemPurpleColor"
AddElement(colors()) : colors() = "systemGrayColor"
AddElement(colors()) : colors() = "linkColor"
AddElement(colors()) : colors() = "placeholderTextColor"
AddElement(colors()) : colors() = "windowFrameTextColor"
AddElement(colors()) : colors() = "selectedMenuItemTextColor"
AddElement(colors()) : colors() = "alternateSelectedControlTextColor"
AddElement(colors()) : colors() = "headerTextColor"
AddElement(colors()) : colors() = "separatorColor"
AddElement(colors()) : colors() = "gridColor"
AddElement(colors()) : colors() = "textColor"
AddElement(colors()) : colors() = "textBackgroundColor"
AddElement(colors()) : colors() = "selectedTextColor"
AddElement(colors()) : colors() = "selectedTextBackgroundColor"
AddElement(colors()) : colors() = "unemphasizedSelectedTextBackgroundColor"
AddElement(colors()) : colors() = "unemphasizedSelectedTextColor"
AddElement(colors()) : colors() = "windowBackgroundColor"
AddElement(colors()) : colors() = "underPageBackgroundColor"
AddElement(colors()) : colors() = "controlBackgroundColor"
AddElement(colors()) : colors() = "selectedContentBackgroundColor"
AddElement(colors()) : colors() = "unemphasizedSelectedContentBackgroundColor"
AddElement(colors()) : colors() = "alternatingContentBackgroundColor"
AddElement(colors()) : colors() = "findHighlightColor"
AddElement(colors()) : colors() = "controlColor"
AddElement(colors()) : colors() = "controlTextColor"
AddElement(colors()) : colors() = "selectedControlColor"
AddElement(colors()) : colors() = "selectedControlTextColor"
AddElement(colors()) : colors() = "disabledControlTextColor"
AddElement(colors()) : colors() = "keyboardFocusIndicatorColor"
AddElement(colors()) : colors() = "controlAccentColor"

; By wilbert: https://www.purebasic.fr/english/viewtopic.php?p=419571#p419571
Procedure.i GetCocoaColor(ColorName.s)
  Protected.i Result, Rect.NSRect, Image, NSColor = CocoaMessage(#Null, #Null, "NSColor " + ColorName)
  If NSColor
    Rect\size\width = 1
    Rect\size\height = 1
    Image = CreateImage(#PB_Any, 1, 1)
    StartDrawing(ImageOutput(Image))
    CocoaMessage(#Null, NSColor, "drawSwatchInRect:@", @Rect)
    Result = Point(0, 0)
    StopDrawing()
    FreeImage(Image)
    ProcedureReturn Result
  Else
    ProcedureReturn -1
  EndIf
EndProcedure

ForEach colors()
  color = GetCocoaColor(colors())
  Debug colors() + " = " + Str(Red(color)) + ", " + Str(Green(color)) + ", " + Str(Blue(color))
Next


Top
 Profile  
Reply with quote  
 Post subject: Re: Control border color
PostPosted: Fri Apr 05, 2019 4:30 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1902
Location: Germany
I haven't found it either... Use lightGray or systemGrayColor

Link https://developer.apple.com/documentati ... ntrolcolor

Code:
;-TOP
; by mk-soft

Procedure OSX_NSColorToRGBA(NSColor)
  Protected.cgfloat red, green, blue, alpha
  Protected nscolorspace, rgba
  nscolorspace = CocoaMessage(0, nscolor, "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
  If nscolorspace
    CocoaMessage(@red, nscolorspace, "redComponent")
    CocoaMessage(@green, nscolorspace, "greenComponent")
    CocoaMessage(@blue, nscolorspace, "blueComponent")
    CocoaMessage(@alpha, nscolorspace, "alphaComponent")
    rgba = RGBA(red * 255.0, green * 255.0, blue * 255.0, alpha * 255.0)
    ProcedureReturn rgba
  EndIf
EndProcedure

Procedure OSX_NSColorToRGB(NSColor)
  Protected.cgfloat red, green, blue
  Protected r, g, b, a
  Protected nscolorspace, rgb
  nscolorspace = CocoaMessage(0, nscolor, "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
  If nscolorspace
    CocoaMessage(@red, nscolorspace, "redComponent")
    CocoaMessage(@green, nscolorspace, "greenComponent")
    CocoaMessage(@blue, nscolorspace, "blueComponent")
    rgb = RGB(red * 255.0, green * 255.0, blue * 255.0)
    ProcedureReturn rgb
  EndIf
EndProcedure

Procedure.i BlendColor(Color1.i, Color2.i, Scale.i=50) ; Thanks to Thorsten
  Protected.i R1, G1, B1, R2, G2, B2
  Protected.f Blend = Scale / 100
  R1 = Red(Color1): G1 = Green(Color1): B1 = Blue(Color1)
  R2 = Red(Color2): G2 = Green(Color2): B2 = Blue(Color2)
  ProcedureReturn RGB((R1*Blend) + (R2 * (1-Blend)), (G1*Blend) + (G2 * (1-Blend)), (B1*Blend) + (B2 * (1-Blend)))
EndProcedure


If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 10, 10, 200, 200)
  If StartDrawing(CanvasOutput(0))
    nscolor = CocoaMessage(0, 0, "NSColor controlBackgroundColor")
    color = BlendColor(OSX_NSColorToRGB(nscolor), $FFFFFF, 85) ; Correction for solid gadget
    Box(0, 0, 200, 200, color)
    nscolor = CocoaMessage(0, 0, "NSColor systemGrayColor")
    color = OSX_NSColorToRGB(nscolor)
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(10, 10, 180, 180, color)
    StopDrawing()
  EndIf
     
  Repeat
    Event = WaitWindowEvent()
   
  Until Event = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Control border color
PostPosted: Fri Apr 05, 2019 6:43 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 447
Thank you. I guess that's close enough, but I would prefer to have the actual color in case the user is in Dark Mode.


Top
 Profile  
Reply with quote  
 Post subject: Re: Control border color
PostPosted: Fri Apr 05, 2019 9:47 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1902
Location: Germany
wombats wrote:
Thank you. I guess that's close enough, but I would prefer to have the actual color in case the user is in Dark Mode.


NSColor systemGrayColor also fits in dark and light mode :wink:

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Control border color
PostPosted: Fri Apr 05, 2019 10:38 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 447
mk-soft wrote:
wombats wrote:
Thank you. I guess that's close enough, but I would prefer to have the actual color in case the user is in Dark Mode.


NSColor systemGrayColor also fits in dark and light mode :wink:
Good point! Haha. Thanks again for the example.


Top
 Profile  
Reply with quote  
 Post subject: Re: Control border color
PostPosted: Mon Apr 15, 2019 3:32 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3434
Location: Netherlands
wombats wrote:
Is there a color I'm missing

You seem to have all of them. Maybe it has to do with the alpha channel or different color space.
deviceRGBColorSpace seems to return the same results as the drawSwatchInRect on a canvas method.
When using genericRGBColorSpace / NSCalibratedRGBColorSpace, grid color for example returns 193 instead of 204 for r,g and b.

Code:
ColorList = CocoaMessage(0, 0, "NSColorList colorListNamed:$", @"System")
If ColorList
  ColorSpace = CocoaMessage(0, 0, "NSColorSpace deviceRGBColorSpace")
  Keys = CocoaMessage(0, ColorList, "allKeys")
  NumKeys = CocoaMessage(0, Keys, "count")
  For k = 1 To NumKeys
    Key = CocoaMessage(0, Keys, "objectAtIndex:", k - 1)
    Color = CocoaMessage(0, ColorList, "colorWithKey:", Key)
    Color = CocoaMessage(0, Color, "colorUsingColorSpace:", ColorSpace)
    If Color
      KeyName.s = PeekS(CocoaMessage(0, Key, "UTF8String"), -1, #PB_UTF8)
      CocoaMessage(@r.CGFloat, Color, "redComponent")
      CocoaMessage(@g.CGFloat, Color, "greenComponent")
      CocoaMessage(@b.CGFloat, Color, "blueComponent")
      CocoaMessage(@a.CGFloat, Color, "alphaComponent")
      Debug KeyName + " = RGBA(" + Str(r*255) + "," + Str(g*255) + "," + Str(b*255) + "," + Str(a*255) + ")"
    EndIf
  Next
EndIf

_________________
macOS 10.14 Mojave, PB 5.62 x64


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye