[Module] LED - Gadget (all OS)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

[Module] LED - Gadget (all OS)

Post by Thorsten1867 »

LED Gadget - Module (all OS / 64Bit / DPI)

Image

Code: Select all

; LED::AttachPopupMenu()    - adds a popup menu
; LED::Gadget()             - new LED gadget
; LED::GetData()            - similar to 'GetGadgetData()'
; LED::GetID()              - similar to 'GetGadgetData()', but string
; LED::Hide()               - similar to 'HideGadget()'
; LED::SetAutoResizeFlags() - [#MoveX|#MoveY|#Width|#Height]
; LED::SetAttribute()       - similar to 'SetGadgetAttribute()'
; LED::SetColor()           - similar to 'SetGadgetColor()'
; LED::SetData()            - similar to 'SetGadgetData()'
; LED::SetID()              - similar to 'SetGadgetData()', but string
; LED::SetState()           - similar to 'SetGadgetState()'
Download: LEDGadgetModule.pbi
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
hoerbie
Enthusiast
Enthusiast
Posts: 137
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

Re: [Module] LED - Gadget (all OS)

Post by hoerbie »

Thanks, exactly what I needed, but with 5.72 on macOS 10.15 the example looks like this:
Image
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: [Module] LED - Gadget (all OS)

Post by StarBootics »

hoerbie wrote:Thanks, exactly what I needed, but with 5.72 on macOS 10.15 the example looks like this:
Image
Same thing on Ubuntu operating system.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by Thorsten1867 »

Please try it again.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: [Module] LED - Gadget (all OS)

Post by StarBootics »

Working now

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Shardik
Addict
Addict
Posts: 2075
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by Shardik »

It's a bit nitpicking but on MacOS 10.14.6 'Mojave' in Dark Mode and Light Mode the 3rd orange LED doesn't have the same background color as the window background has (like in the Windows snapshot above).

Image

Image
hoerbie
Enthusiast
Enthusiast
Posts: 137
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

Re: [Module] LED - Gadget (all OS)

Post by hoerbie »

Yes, thanks, it works now on macOS.

Nitpicking, I have the same problem with the not 100% identical background color, but this is a general problem of getting the real background color, I also tried a lot there, the problem seems to be in the function OSX_NSColorToRGB(NSColor) used in

Code: Select all

LED()\Color\Gadget = OSX_NSColorToRGB(CocoaMessage(0, 0, "NSColor windowBackgroundColor"))
User avatar
mk-soft
Always Here
Always Here
Posts: 6411
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by mk-soft »

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    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
  CompilerEndIf
  
  Procedure.i BlendColor(Color1.i, Color2.i, Scale.i = 50) ; Thanks to Thorsten
    Protected.f R1, G1, B1, R2, G2, B2
    Protected.f Blend1 = Scale / 100
    Protected.f Blend2 = 1.0 - Blend1
    R1 = Red(Color1): G1 = Green(Color1): B1 = Blue(Color1)
    R2 = Red(Color2): G2 = Green(Color2): B2 = Blue(Color2)
    ProcedureReturn RGB(R1*Blend1 + R2 * Blend2, G1*Blend1 + G2 * Blend2, B1*Blend1 + B2 * Blend2)
  EndProcedure
  
  Procedure GetSystemColor(Type)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        Select Type
          Case #PB_Gadget_FrontColor
            ProcedureReturn GetSysColor_(#COLOR_WINDOWTEXT)
          Case #PB_Gadget_BackColor
            ProcedureReturn GetSysColor_(#COLOR_3DFACE)
          Case #PB_Gadget_LineColor
            ProcedureReturn #Gray
        EndSelect
      CompilerCase #PB_OS_Linux
        Select Type
          Case #PB_Gadget_FrontColor
            ProcedureReturn #Black
          Case #PB_Gadget_BackColor
            ProcedureReturn $F8F8F8
          Case #PB_Gadget_LineColor
            ProcedureReturn #Gray
        EndSelect
      CompilerCase #PB_OS_MacOS
        Protected UserDefaults, NSString
        Select Type
          Case #PB_Gadget_FrontColor
            ProcedureReturn NSColorByNameToRGB("controlTextColor")
          Case #PB_Gadget_BackColor
            UserDefaults = CocoaMessage(0, 0, "NSUserDefaults standardUserDefaults")
            NSString = CocoaMessage(0, UserDefaults, "stringForKey:$", @"AppleInterfaceStyle")
            If NSString And PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8) = "Dark"
              ProcedureReturn BlendColor(NSColorByNameToRGB("controlBackgroundColor"), #White, 85)
            Else
              ProcedureReturn BlendColor(NSColorByNameToRGB("windowBackgroundColor"), #White, 85)
            EndIf  
          Case #PB_Gadget_LineColor
            ProcedureReturn #Gray
        EndSelect
    CompilerEndSelect
  EndProcedure
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by Thorsten1867 »

Please try it again!
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Shardik
Addict
Addict
Posts: 2075
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by Shardik »

Thorsten1867 wrote:Please try it again!
Error wrote:Zeile 220: BlendColor() is not a function, array, list, map or macro.
In module LED the procedure BlendColor_() is defined after the call of BlendColor(). In BlendColor() the trailing underscore is missing.
User avatar
mk-soft
Always Here
Always Here
Posts: 6411
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by mk-soft »

Fixed part macOS... :wink:

Code: Select all

  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    
    ; Addition of 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.9, green * 255.9, blue * 255.9, alpha * 255.)
        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 OSX_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.i OSX_BlendColor(Color1.i, Color2.i, Scale.i = 50) ; Thanks to Thorsten
      Protected.f R1, G1, B1, R2, G2, B2
      Protected.f Blend1 = Scale / 100
      Protected.f Blend2 = 1.0 - Blend1
      R1 = Red(Color1): G1 = Green(Color1): B1 = Blue(Color1)
      R2 = Red(Color2): G2 = Green(Color2): B2 = Blue(Color2)
      ProcedureReturn RGB(R1*Blend1 + R2 * Blend2, G1*Blend1 + G2 * Blend2, B1*Blend1 + B2 * Blend2)
    EndProcedure
    
    Procedure OSX_GadgetColor(Type = #PB_Gadget_BackColor)
      Protected UserDefaults, NSString
      Select Type
        Case #PB_Gadget_FrontColor
          ProcedureReturn OSX_NSColorByNameToRGB("controlTextColor")
        Case #PB_Gadget_BackColor
          UserDefaults = CocoaMessage(0, 0, "NSUserDefaults standardUserDefaults")
          NSString = CocoaMessage(0, UserDefaults, "stringForKey:$", @"AppleInterfaceStyle")
          If NSString And PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8) = "Dark"
            ProcedureReturn OSX_BlendColor(OSX_NSColorByNameToRGB("controlBackgroundColor"), #White, 87)
          Else
            ProcedureReturn OSX_BlendColor(OSX_NSColorByNameToRGB("windowBackgroundColor"), #White, 87)
          EndIf  
        Case #PB_Gadget_LineColor
          ProcedureReturn #Gray
      EndSelect
    EndProcedure
    
  CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by Thorsten1867 »

Tried to fix the MacOS problems, but without Mac this is always a bit difficult ;-)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2148
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [Module] LED - Gadget (all OS)

Post by Andre »

Another nice gadget, thank you! :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
hoerbie
Enthusiast
Enthusiast
Posts: 137
Joined: Fri Dec 06, 2013 11:57 am
Location: DE/BY/MUC

Re: [Module] LED - Gadget (all OS)

Post by hoerbie »

Thank you Thorsten1867 and mk-soft, now the background color looks fine on macOS 10.15 in normal mode, in dark mode the background ist still to dark.
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 6411
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] LED - Gadget (all OS)

Post by mk-soft »

Adjust OSX_GadgetColor -> BendColor (85%)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply