FlatButtonEx Crossplattform

Share your advanced PureBasic knowledge/code with the community.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: FlatButtonEx Crossplattform

Post by uwekel »

I am using the code below for myself. My primary system is Linux but also develop on Windows. Mac is not supported so far. If i want to get a system colour, i have to hand-over a gadget and the state of the gadget (enabled, desabled, selected...). Then this procedure returns the corresponding colour.

Code: Select all

Procedure.l GtkGadgetColor(Gadget, Type, State)
  ;color types
  #GtkGadgetColorBase = 0
  #GtkGadgetColorBg = 1
  #GtkGadgetColorDark = 2
  #GtkGadgetColorFg = 3
  #GtkGadgetColorLight = 4
  #GtkGadgetColorText = 5
  ;states
  #GtkStateNormal = 0
  #GtkStateActive = 1
  #GtkStatePrelight = 2
  #GtkStateSelected = 3
  #GtkStateIntensitive = 4
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      ;returns a widget color
      Protected *style.GtkStyle, *color.GdkColor
      ;get widget style
      *style = gtk_widget_get_style_(GadgetID(Gadget))
      ;return color according type and state
      Select Type
        Case #GtkGadgetColorBase
          *color = *style\base[State]
        Case #GtkGadgetColorBg
          *color = *style\bg[State]
        Case #GtkGadgetColorDark
          *color = *style\dark[State]
        Case #GtkGadgetColorFg
          *color = *style\fg[State]
        Case #GtkGadgetColorLight
          *color = *style\light[State]
        Case #GtkGadgetColorText
          *color = *style\text[State]
      EndSelect
      ;return color value
      ProcedureReturn RGB(*color\red >> 8, *color\green >> 8, *color\blue >> 8)
    CompilerCase #PB_OS_Windows
      Select Type
        Case #GtkGadgetColorBg, #GtkGadgetColorBase
          If State = #GtkStateSelected
            ProcedureReturn GetSysColor_(#COLOR_HIGHLIGHT)
          Else
            ProcedureReturn GetSysColor_(#COLOR_WINDOW)
          EndIf
        Case #GtkGadgetColorFg, #GtkGadgetColorText
          If State = #GtkStateSelected
            ProcedureReturn GetSysColor_(#COLOR_HIGHLIGHTTEXT)
          Else
            ProcedureReturn GetSysColor_(#COLOR_WINDOWTEXT)
          EndIf
        Case #GtkGadgetColorDark
          ProcedureReturn GetSysColor_(#COLOR_BTNSHADOW)
        Case #GtkGadgetColorLight
          ProcedureReturn GetSysColor_(#COLOR_3DLIGHT)
      EndSelect
  CompilerEndSelect
EndProcedure
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Thx :D
I will add it for the next update!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Update:
History wrote:; Version 1.6 (Feb 24, 2013)
; changed GetSpaceSupport() to GetShortCut()
; changed SetSpaceSupport() to SetShortCut(), default is #PB_Shortcut_Space, set to 0 for none shortcutsupport
; added default systemcolor for Linux, thx to uwekel
History wrote:; Version 1.7 (Feb 24, 2013)
; added Gradient-Support
; SetGradient() and SetHotGradient()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Update:
History wrote:; Version 1.8 (Feb 25, 2013)
; added Gradient-Type: SetGradientType([Type.i[, customcallback.i]])
; with types:
; #FlatButtonEx_Gradient_Linear (default)
; #FlatButtonEx_Gradient_Boxed
; #FlatButtonEx_Gradient_Custom (requires customcallback)
History wrote:; Version 1.8.1 (Feb 25, 2013)
; added Support for texthotcolor
; new colorconstant: #FlatButtonEx_Color_TextHotColor
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: FlatButtonEx Crossplattform

Post by wilbert »

For OS X (PB 5.10 Cocoa), you can get system colors like this

Code: Select all

CompilerCase #PB_OS_MacOS
  Protected ColorName.s, Color.i
  Protected.CGFloat R, G, B, A
  Select Type
    Case #GtkGadgetColorBg
      ColorName = "controlBackgroundColor"
    Case #GtkGadgetColorLight
      ColorName = "controlHighlightColor"
  EndSelect
  Color = CocoaMessage(0, 0, "NSColor " + ColorName)
  If Color : Color = CocoaMessage(0, Color, "colorUsingColorSpaceName:$", @"NSDeviceRGBColorSpace") : EndIf
  If Color : CocoaMessage(0, Color, "getRed:", @R, "green:", @G, "blue:", @B, "alpha:", @A) : EndIf
  ProcedureReturn RGBA(R * 255, G * 255, B * 255, A * 255)  
CompilerEndSelect
You first have to create a NSColor object using the color name and after that convert it to RGB color space and get the component values.
Possible color names for system colors are

Code: Select all

+ alternateSelectedControlColor
+ alternateSelectedControlTextColor
+ controlBackgroundColor
+ controlColor
+ controlAlternatingRowBackgroundColors
+ controlHighlightColor
+ controlLightHighlightColor
+ controlShadowColor
+ controlDarkShadowColor
+ controlTextColor
+ currentControlTint
+ disabledControlTextColor
+ gridColor
+ headerColor
+ headerTextColor
+ highlightColor
+ keyboardFocusIndicatorColor
+ knobColor
+ scrollBarColor
+ secondarySelectedControlColor
+ selectedControlColor
+ selectedControlTextColor
+ selectedMenuItemColor
+ selectedMenuItemTextColor
+ selectedTextBackgroundColor
+ selectedTextColor
+ selectedKnobColor
+ shadowColor
+ textBackgroundColor
+ textColor
+ windowBackgroundColor
+ windowFrameColor
+ windowFrameTextColor
+ underPageBackgroundColor
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

thx wilbert

Update:
History wrote:; Version 1.8.2 (Feb 25, 2013)
; added default systemcolor for MacOSX, thx to wilbert
I think, it is complete now :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Update:
History wrote:; Version 1.8.3 (Feb 25, 2013)
; added Icon-Support for Windows
; Attention: Icons can't be resized!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Frabbing
User
User
Posts: 10
Joined: Mon May 09, 2011 7:59 pm
Contact:

Re: FlatButtonEx Crossplattform

Post by Frabbing »

An error in all buttons: The right bottom pixel is missing...?
Best regards,
Frank
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Frabbing wrote:An error in all buttons: The right bottom pixel is missing...?
Thx for report, fixed

Update:
History wrote:; Version 1.8.4 (Feb 25, 2013)
; fixed a bug with right bottom pixel
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Frabbing
User
User
Posts: 10
Joined: Mon May 09, 2011 7:59 pm
Contact:

Re: FlatButtonEx Crossplattform

Post by Frabbing »

Thank you! :)
Best regards,
Frank
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Update:
History wrote:; Version 1.9
; added: Icon resizing is full supported (windows only)
; optimized code
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: FlatButtonEx Crossplattform

Post by idle »

looking good!

On linux, when I move the mouse over a button while it's got the keyboard focus (dotted box) it flickers
testing for mouse move fixes it

line 632

Code: Select all

  With *this
     If EventType <> #PB_EventType_MouseMove 
        StartDrawing(CanvasOutput(\ID))
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

thx for bugreport :D
I can't change this like you suggest, this give a problem with mouse outside button on windows.
I have made a other change (line 675), please check this.

Greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: FlatButtonEx Crossplattform

Post by idle »

That still flickers, the issue appears to be caused from startdrawing()

Code: Select all

  CompilerIf #PB_Compiler_OS = #PB_OS_Linux 
            If EventType <> #PB_EventType_MouseMove 
         CompilerEndIf  
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

fixed (i hope it :wink: )
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply