Advertisement
deseven

cocoa-colors.pb

Jul 20th, 2020
5,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Procedure SetTextColorABGR(EditorGadget, Color, StartPosition, Length = -1, BackColor = #NO)
  2.   Protected.CGFloat r,g,b,a
  3.   Protected range.NSRange, textStorage.i
  4.   If StartPosition > 0
  5.     textStorage = CocoaMessage(0, GadgetID(EditorGadget), "textStorage")
  6.     range\location = StartPosition - 1
  7.     range\length = CocoaMessage(0, textStorage, "length") - range\location
  8.     If range\length > 0
  9.       If Length >= 0 And Length < range\length
  10.         range\length = Length
  11.       EndIf
  12.       r = Red(Color) / 255
  13.       g = Green(Color) / 255
  14.       b = Blue(Color) / 255
  15.       a = Alpha(Color) / 255
  16.       Color = CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@", @r, "green:@", @g, "blue:@", @b, "alpha:@", @a)
  17.       If BackColor
  18.         CocoaMessage(0, textStorage, "addAttribute:$", @"NSBackgroundColor", "value:", Color, "range:@", @range)
  19.       Else
  20.         CocoaMessage(0, textStorage, "addAttribute:$", @"NSColor", "value:", Color, "range:@", @range)
  21.       EndIf
  22.     EndIf
  23.   EndIf
  24. EndProcedure
  25.  
  26. OpenWindow(0,#PB_Ignore,#PB_Ignore,500,800,"colors test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  27. EditorGadget(0,10,10,480,780)
  28.  
  29. ColorList = CocoaMessage(0, 0, "NSColorList colorListNamed:$", @"System")
  30. If ColorList
  31.   ColorSpace = CocoaMessage(0, 0, "NSColorSpace deviceRGBColorSpace")
  32.   Keys = CocoaMessage(0, ColorList, "allKeys")
  33.   NumKeys = CocoaMessage(0, Keys, "count")
  34.   For k = 1 To NumKeys
  35.     Key = CocoaMessage(0, Keys, "objectAtIndex:", k - 1)
  36.     Color = CocoaMessage(0, ColorList, "colorWithKey:", Key)
  37.     Color = CocoaMessage(0, Color, "colorUsingColorSpace:", ColorSpace)
  38.     If Color
  39.       KeyName.s = PeekS(CocoaMessage(0, Key, "UTF8String"), -1, #PB_UTF8)
  40.       CocoaMessage(@r.CGFloat, Color, "redComponent")
  41.       CocoaMessage(@g.CGFloat, Color, "greenComponent")
  42.       CocoaMessage(@b.CGFloat, Color, "blueComponent")
  43.       CocoaMessage(@a.CGFloat, Color, "alphaComponent")
  44.       ;Debug KeyName + " = RGBA(" + Str(r*255) + "," + Str(g*255) + "," + Str(b*255) + "," + Str(a*255) + ")"
  45.       AddGadgetItem(0,-1,KeyName + ", RGBA(" + Str(r*255) + "," + Str(g*255) + "," + Str(b*255) + "," + Str(a*255) + "):")
  46.       AddGadgetItem(0,-1,"█ █ █ █ █")
  47.       SetTextColorABGR(0,RGBA(r*255,g*255,b*255,a*255),Len(GetGadgetText(0))-8,9)
  48.       AddGadgetItem(0,-1,"")
  49.     EndIf
  50.   Next
  51. EndIf
  52.  
  53. Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement