PureCOLOR library : coloring gadgets (and much more)

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

That did it, I was using -1 as backcolor but now, using #PureCOLOR_DontSetBackColor the results are exactly how I wanted. Thank you :D!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

Just found this today which will help me on a new project I am working on...

Freakin awesome Gnozal!!
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Hello Gnozal,

I'm trying to do a tricky thing but to finish it i need just one more constant for :

- PureCOLOR_SetButtonColor()
- PureCOLOR_SetGadgetColor()

#PureCOLOR_Ignore = #PB_Ignore ; New constant, Means No Change.

Here is the tricky thing i would like to do :
I would like to extends the possibilities of SetGadgetColor() thanks to the PureCOLOR but by keeping the original PureBasic syntax. :? :D

PureCOLOR_Patch.pbi

Code: Select all

;- 
;- Object: PureCOLOR Library for PureBasic 4.0
;- Author: Written by Gnozal
;- Link:   http://people.freenet.de/gnozal/
;- 
;- Patch v0.1 by flype, July 2006.
;- 

#PureCOLOR_Ignore = #PB_Ignore

Enumeration 1 ; #PB_Gadget_xxxColor
  #PB_Gadget_FrontColor
  #PB_Gadget_BackColor
  #PB_Gadget_LineColor
  #PB_Gadget_TitleFrontColor
  #PB_Gadget_TitleBackColor
  #PB_Gadget_GrayTextColor
  #PB_Gadget_TextPushedColor ; PureCOLOR_SetButtonColor()
  #PB_Gadget_BackPushedColor ; PureCOLOR_SetButtonColor()
EndEnumeration

Procedure.l SetGadgetColorA(gadget.l, type.l, color.l) ; Workaround to avoid unlimited recursive call to the macro SetGadgetColor()
  
  SetGadgetColor(gadget, type, color)
  
EndProcedure

Procedure.l SetGadgetColorB(gadget.l, type.l, color.l) ; Extends the possibilities of SetGadgetColor()
  
  Select GadgetType(gadget)
    
    Case #PB_GadgetType_Button
      
      ; Not supported by PureBasic. Time to use PureCOLOR.
      
      Select type
        Case #PB_Gadget_BackColor
          PureCOLOR_SetButtonColor(gadget, #PureCOLOR_Ignore, color)
        Case #PB_Gadget_FrontColor
          PureCOLOR_SetButtonColor(gadget, color, #PureCOLOR_Ignore) 
        Case #PB_Gadget_TextPushedColor
          PureCOLOR_SetButtonColor(gadget, #PureCOLOR_Ignore, #PureCOLOR_Ignore, color) 
        Case #PB_Gadget_BackPushedColor
          PureCOLOR_SetButtonColor(gadget, #PureCOLOR_Ignore, #PureCOLOR_Ignore, #PureCOLOR_Ignore, color) 
      EndSelect
      
    Case #PB_GadgetType_Panel
      
      ; Not supported by PureBasic. Time to use PureCOLOR.
      
      Select type
        Case #PB_Gadget_BackColor
          PureCOLOR_SetGadgetColor(gadget, #PureCOLOR_Ignore, color)
        Case #PB_Gadget_FrontColor
          PureCOLOR_SetGadgetColor(gadget, color, #PureCOLOR_Ignore) 
      EndSelect
      
    Case #PB_GadgetType_IPAddress
      
      ; Not supported. Neither PureBasic, Nor PureCOLOR.
      
    Default
      
      ; Supported by PureBasic. No need to use PureCOLOR.
      
      SetGadgetColorA(gadget, type, color)
      
  EndSelect
  
EndProcedure

Macro SetGadgetColor(gadget, type, color) ; Patch PureBasic Built-In command.
  SetGadgetColorB(gadget, type, color)
EndMacro

;- EOF

PureCOLOR_Patch_Test.pb

a classic purebasic source, using builtins commands.
should be colored even if those gadgets are not supported by purebasic.

Code: Select all

;XIncludeFile "PureCOLOR_PATCH.pb"

If OpenWindow(0, 0, 0, 320, 240, "SetGadgetColor()", #PB_Window_ScreenCentered)
  
  If CreateGadgetList(WindowID(0))
    
    PanelGadget(0, 10, 10, 300, 220)
    
    SetGadgetColor(0, #PB_Gadget_BackColor, $A0F0F0)
    
    AddGadgetItem (0, -1, "Page 1")
    
    ButtonGadget(1, 5, 5, 150, 40, "Exit")
    
    ;SetGadgetColor(1, #PB_Gadget_TextPushedColor, #Green)
    ;SetGadgetColor(1, #PB_Gadget_BackPushedColor, #Blue)
    SetGadgetColor(1, #PB_Gadget_FrontColor, #Red)
    SetGadgetColor(1, #PB_Gadget_BackColor, #Yellow)
    
  EndIf
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_Gadget
  
EndIf

No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

@Flype : very nice idea.
Why not use #PureCOLOR_Ignore = #PureCOLOR_SystemColor ?

And there are the transparent TextGadgets with BackColor = #PureCOLOR_DontSetBackColor ...
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Yes, i know Gnozal for the #PureCOLOR_DontSetBackColor.

But it is not enough. As well, #PureCOLOR_SystemColor is not enough nor adapted.

I would need :

#PureCOLOR_DontSetTextColor ; not implemented
#PureCOLOR_DontSetBackColor ; yet implemented
#PureCOLOR_DontSetTextPushedColor ; not implemented
#PureCOLOR_DontSetBackPushedColor ; not implemented

Or

#PureCOLOR_Ignore,
which is simpler (and shorter) i think. Should be possible.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Hmm
PureCOLOR does not work that way : it always expects TextColor and BackColor in the callbacks.
The colors (Text/Back/Brush) are stored at the beginning when you call PureCOLOR_SetGagdetColor().

You could do the following :
If color already set for gadget, Ignore = #PureCOLOR_UseLastColor
If color not already set for gadget, use Ignore = #PureCOLOR_SystemColor
But you have to remember wich colors were set and wich not.

Sorry, not much time now ...
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

But you have to remember which colors were set and which not.

>> Yes, that was the solution i was thinking of...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Update (both libs)

- Fixed a small listicon subclassing problem : http://www.purebasic.fr/german/viewtopi ... 2&start=10
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

Hi Gnozal,

i found a bug where the Font information on a listicon is lost when i use a callback :
Image
Heres the code for the callback i´m using :

Code: Select all

Procedure ColorCallBack(GadgetNumber.l, CellRow.l, CellColumn.l, *TextColor.LONG, *BackColor.LONG, *FontID.LONG)
  Select GadgetNumber
    Case #Fehlerstatistik_LGadget1
      CellText.s=GetGadgetItemText(GadgetNumber,CellRow,1)
      Select LCase(CellText)
        Case "in produktion"
          Col=#Orange
        Case "ok"
          Col=#Gruen
        Case "gesperrt" 
          Col=#Rot
        Case "ausschuss"
          Col=#Purpur
        Case "nacharbeit"
          Col=#Mint
        Default
          Col=#Sys1
      EndSelect
      If Col<>#Gruen
        *BackColor\l=Background_Edit(Col)
      EndIf
    Case #Ausschuss_LGadget1
      CellText.s=GetGadgetItemText(GadgetNumber,CellRow,5)
      If LCase(CellText)="nicht zugeordnet"
        *BackColor\l=Background_Edit(#Rot)
      EndIf
    Case #Qualitaetsmanagement_LGadget1
      Select CellColumn
        Case 0 To 4
          CellText.s=GetGadgetItemText(GadgetNumber,CellRow,4)
          Select LCase(CellText)
            Case "in produktion"
              Col=#Orange
            Case "ok"
              Col=#Gruen
            Case "gesperrt" 
              Col=#Rot
            Case "ausschuss"
              Col=#Purpur
            Case "nacharbeit"
              Col=#Mint
            Default
              Col=#Sys1
          EndSelect
          *BackColor\l=Background_Edit(Col)
        Case 5 To 10
          CellText.s=GetGadgetItemText(GadgetNumber,CellRow,CellColumn)
          Select LCase(CellText)
            Case ""
              Col1=#Orange
            Case "ok"
              Col1=#Gruen
            Case "gesperrt" 
              Col1=#Rot
            Case "ausschuss"
              Col1=#Purpur
            Case "nacharbeit"
              Col1=#Mint
          EndSelect
          *BackColor\l=Background_Edit(Col1)
      EndSelect
    Case #WDLGadget1
      Select CellColumn
        Case 0,1,2,3,4,15,16 
          CellText.s=GetGadgetItemText(GadgetNumber,CellRow,16)
          Select LCase(CellText)
            Case "in produktion"
              Col=#Orange
            Case "ok"
              Col=#Gruen
            Case "gesperrt" 
              Col=#Rot
            Case "ausschuss"
              Col=#Purpur
            Case "nacharbeit"
              Col=#Mint
            Default
              Col=#Sys1
          EndSelect
          If Col<Gruen>5
            *BackColor\l=Background_Edit(#Rot)
          EndIf
        Case 7,9,11,13,14
          Value=Val(GetGadgetItemText(GadgetNumber,CellRow,CellColumn))
          If Value>500
            *BackColor\l=Background_Edit(#Rot)
          EndIf
      EndSelect
    Case #IDNut_LGadget_IDNut
      ;*FontID\l=FontID2 ; Workaround for Bug in PureColor Library 16.7.2006 19:33
      CellText.s=GetGadgetItemText(GadgetNumber,CellRow,2)
      Select LCase(CellText)
        Case "in produktion"
          Col=#Orange
        Case "ok"
          Col=#Gruen
        Case "gesperrt" 
          Col=#Rot
        Case "ausschuss"
          Col=#Purpur
        Case "nacharbeit"
          Col=#Mint
        Default
          Col=#Sys1
      EndSelect
      *BackColor\l=Background_Edit(Col)
  EndSelect
EndProcedure
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

@ABBKlaus :
It's not a bug, it's how it is planned to work : maybe it's a bad design :wink:

If you use the Cell Color Callback, the default font is the default GUI font [ GetStockObject_(#ANSI_VAR_FONT) ] and not the gadget font, since you are supposed to control Color/BackColor/Font for each cell.

Maybe I shoud change the default font to GetGadgetFont(#ListIcon) ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

Thanks for the reply Gnozal.
I only wanted to change the backcolor !
If this is the standard behavior it should be in the manual :wink:
i now use your workaround :

Code: Select all

  If IsGadget(GadgetNumber)
    *FontID\l=GetGadgetFont(GadgetNumber)
  EndIf
Klaus
magicjo
User
User
Posts: 61
Joined: Sun May 07, 2006 10:43 am
Location: Italy

Post by magicjo »

@gnozal,

I would ask you if is possible change colors (front & back) of then combogadget's edit control too ( i've tried with the last version of your library (v12.20)) .
I've used the message #WM_CTLCOLOREDIT to do it for now , but i think is useful and logic if you'll add in you SUPER library!

Thanks in advance.
PB Registered User, Egrid Registered User
Win7 x64 Ultimate, 4,00 Gb Mem, Ati Radeon HD4600 Series, Realtek High Definition Audio Integrated
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

magicjo wrote:@gnozal,

I would ask you if is possible change colors (front & back) of then combogadget's edit control too ( i've tried with the last version of your library (v12.20)) .
I've used the message #WM_CTLCOLOREDIT to do it for now , but i think is useful and logic if you'll add in you SUPER library!

Thanks in advance.
Ok, for the next version.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Update 12.21 (both libs)

- bug fix : editable ComboBoxGadget was not colorized
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
magicjo
User
User
Posts: 61
Joined: Sun May 07, 2006 10:43 am
Location: Italy

Post by magicjo »

Thanks Gnozal for the update(obviously functions) :wink:
PB Registered User, Egrid Registered User
Win7 x64 Ultimate, 4,00 Gb Mem, Ati Radeon HD4600 Series, Realtek High Definition Audio Integrated
Post Reply