Aktuelle Zeit: 22.10.2019 13:54

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]




Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Autor Nachricht
 Betreff des Beitrags: Module NSColor
BeitragVerfasst: 15.04.2019 12:13 
Online
Benutzeravatar

Registriert: 24.11.2004 13:12
Wohnort: Germany
Bevor ich den Code wieder verbummele. :roll:
Code:
;-TOP
; by mk-soft
; v1.01
; 15.05.2019

DeclareModule NSColor
  Declare NSColorToRGB(NSColor)
  Declare NSColorToRGBA(NSColor)
  Declare NSColorByNameToRGB(NSColorName.s)
  Declare NSColorByNameToRGBA(NSColorName.s)
  Declare RGBtoNSColor(Color)
  Declare RGBAtoNSColor(Color)
  Declare BlendColor(Color1.i, Color2.i, Scale.i) ; Thanks to Thorsten
EndDeclareModule

Module NSColor
 
  Procedure NSColorToRGB(NSColor)
    Protected.cgfloat red, green, blue
    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 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 NSColorByNameToRGB(NSColorName.s)
    Protected.cgfloat red, green, blue
    Protected nscolorspace, rgb
    nscolorspace = CocoaMessage(0, CocoaMessage(0, 0, "NSColor " + NSColorName), "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 NSColorByNameToRGBA(NSColorName.s)
    Protected.cgfloat red, green, blue, alpha
    Protected nscolorspace, rgba
    nscolorspace = CocoaMessage(0, CocoaMessage(0, 0, "NSColor " + NSColorName), "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
    If nscolorspace
      CocoaMessage(@red, nscolorspace, "redComponent")
      CocoaMessage(@green, nscolorspace, "greenComponent")
      CocoaMessage(@blue, nscolorspace, "blueComponent")
      CocoaMessage(@alpha, nscolorspace, "alphaComponent")
      rgb = RGBA(red * 255.0, green * 255.0, blue * 255.0, alpha * 255.0)
      ProcedureReturn rgb
    EndIf
  EndProcedure
 
  Procedure RGBtoNSColor(Color)
    Protected Alpha.CGFloat, Blue.CGFloat, Green.CGFloat, Red.CGFloat
    Red = Red(Color) / 255
    Green = Green(Color) / 255
    Blue = Blue(Color) / 255
    Alpha = 1.0
    ProcedureReturn CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@",
                 @Red, "green:@", @Green, "blue:@", @Blue, "alpha:@", @Alpha)
  EndProcedure
 
  Procedure RGBAtoNSColor(Color)
    Protected Alpha.CGFloat, Blue.CGFloat, Green.CGFloat, Red.CGFloat
    Red = Red(Color) / 255
    Green = Green(Color) / 255
    Blue = Blue(Color) / 255
    Alpha = Alpha(Color) / 255
    ProcedureReturn CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@",
                 @Red, "green:@", @Green, "blue:@", @Blue, "alpha:@", @Alpha)
  EndProcedure
 
  Procedure BlendColor(Color1.i, Color2.i, Scale.i) ; 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
 
EndModule

;- End Module

CompilerIf #PB_Compiler_IsMainFile
 
  UseModule NSColor
 
  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, WindowID(0), "backgroundColor")
      ;color = BlendColor(NSColorToRGB(nscolor), $FFFFFF, 90) ; Correction for solid gadget
      color = BlendColor(NSColorByNameToRGB("controlBackgroundColor"), $FFFFFF, 85) ; Correction for solid gadget
      Box(0, 0, 200, 200, color)
      color = NSColorByNameToRGB("lightGrayColor")
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(10, 10, 180, 180, color)
      StopDrawing()
    EndIf
       
    Repeat
      Event = WaitWindowEvent()
     
    Until Event = #PB_Event_CloseWindow
  EndIf
 
CompilerEndIf

_________________
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul / OPC-Helper DLL
PB v3.30 / v5.4x - OS Mac Mini OSX 10.xx / Window 10 Pro. (X64) /Window 7 Pro. (X64) / Window XP Pro. (X86) / Ubuntu 14.04
Downloads auf Webspace


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast


Sie dürfen keine neuen Themen in diesem Forum erstellen.
Sie dürfen keine Antworten zu Themen in diesem Forum erstellen.
Sie dürfen Ihre Beiträge in diesem Forum nicht ändern.
Sie dürfen Ihre Beiträge in diesem Forum nicht löschen.

Suche nach:
Gehe zu:  

 


Powered by phpBB © 2008 phpBB Group | Deutsche Übersetzung durch phpBB.de
subSilver+ theme by Canver Software, sponsor Sanal Modifiye