PureCOLOR library : coloring gadgets (and much more)

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

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

This code example should work (I removed all PureCOLOR lib dependencies).

Code: Select all

;
; Code example : how to colorize standard buttons
;
; --------------------------------------------------------
; Get Text Height (only a TextLength() function in PB)
;
Procedure GetTextHeight(hdc.l)
  Protected tm.textmetric, PrevMapMode.l
  PrevMapMode = SetMapMode_(hdc, #MM_Text)
  GetTextMetrics_(hdc, @tm)
  If PrevMapMode
    SetMapMode_(hdc, PrevMapMode)
  EndIf
  ProcedureReturn tm\tmHeight
EndProcedure
; --------------------------------------------------------
; Create color button (fake with image)
;
Procedure CreateColoredButton(GadgetNumber.l, ImageNumber.l, ButtonTextColor.l, ButtonBackColor.l)
  Protected ButtonW.l, ButtonH.l, hFont.l, ButtonText.s, Button_hdc.l, GadgetHandle.l
  ButtonW = GadgetWidth(GadgetNumber)
  ButtonH = GadgetHeight(GadgetNumber)
  GadgetHandle = GadgetID(GadgetNumber)
  If CreateImage(ImageNumber, ButtonW, ButtonH)
    ; Create image
    Button_hdc = StartDrawing(ImageOutput())
    ; Button color
    Box(0, 0, ButtonW, ButtonH, ButtonBackColor)
    ; Button font
    hFont = SendMessage_(GadgetHandle, #WM_GETFONT, 0, 0)
    DrawingFont(hFont)
    ; Button text
    ButtonText = GetGadgetText(GadgetNumber)
    FrontColor(Red(ButtonTextColor), Green(ButtonTextColor), Blue(ButtonTextColor))
    DrawingMode(1)
    Locate((ButtonW - TextLength(ButtonText)) / 2, (ButtonH - GetTextHeight(Button_hdc)) / 2)
    DrawText(ButtonText)
    StopDrawing()
    ; Add bitmap style
    SetWindowLong_(GadgetHandle, #GWL_Style, GetWindowLong_(GadgetHandle, #GWL_Style) | #BS_BITMAP)
    ; Use image
    SendMessage_(GadgetHandle, #BM_SETIMAGE, #IMAGE_BITMAP, UseImage(ImageNumber))
  EndIf
EndProcedure
; --------------------------------------------------------
; Clear button color
;
Procedure ClearColoredButton(GadgetNumber.l, ImageNumber.l)
  Protected GadgetHandle.l
  GadgetHandle = GadgetID(GadgetNumber)
  ; Substract bitmap style
  SetWindowLong_(GadgetHandle, #GWL_Style, GetWindowLong_(GadgetHandle, #GWL_Style) & ~#BS_BITMAP)
  ; Free image
  FreeImage(ImageNumber)
EndProcedure
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

in the follwing example i made, there is 2 bugs.

1/ problem when you set a font to a buttongadget
2/ problem when you set a flag to a buttongadget

Code: Select all

Procedure.l WindowCallBack(WindowID.l, Message.l, wParam.l, lParam.l) 
  ReturnValue = #PB_ProcessPureBasicEvents 
  ReturnValue = PureCOLOR_CallBack(WindowID, Message, wParam, lParam, ReturnValue)
  ProcedureReturn ReturnValue 
EndProcedure

OpenWindow(0, 100, 300, 200, 200, #PB_Window_SystemMenu, "PureCOLOR test") 
SetWindowCallback(@WindowCallBack()) 
CreateGadgetList(WindowID()) 
ButtonGadget(0, 20, 20, 80, 50, "Button Number Four",#PB_Button_MultiLine|#PB_Button_Right)
LoadFont(0,"Arial",9,#PB_Font_Bold)
SetGadgetFont(0,FontID())

;- comment and uncomment and see
PureCOLOR_SetGadgetColor(0, RGB(255,0,0), RGB(0,255,0))

Repeat : Until WaitWindowEvent() = #PB_EventCloseWindow 
End
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 »

I must say I never tested that ! I only wanted to add basic button support. I will take a look ...
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 »

Library update
- new : help is now CHM
- fixed : buttons with #BS_RIGHT or #BS_LEFT style are colorized correctly (tested only with Win98SE), see PureCOLOR_TEST_4.pb file.
The buttons with #BS_MULTILINE style are not supported yet.

(To download, see first post of thread)
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 »

Library update

What's new :
- fixed : all 'Button' class gadgets were colorized like buttons (CheckBox ...) : new function PureCOLOR_SetButtonColor() for buttons only
- added : functions to colorize individual listicon cells

New functions :
- PureCOLOR_SetButtonColor(GadgetNumber.l, TextColor.l, BackColor.l) : Set button colors
- PureCOLOR_SetCellColor(ListIconNumber.l, Row.l, Column.l, TextColor.l, BackColor.l) : Set listicon cell color
- PureCOLOR_ClearCellColor(ListIconNumber.l, Row.l, Column.l) : Clear listicon cell color

Image

To download, see first post of thread
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Great! :D

added:
Incredible, i needed this feature just few hours after you released it! thanks!!!
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Thanks :D

There was a little bug in the version released yesterday (only if you colorize cells of more than one listicon). Please download again.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Small bug:
I use PureCOLOR_SetCellColor to colorize a cell.
When I do RemoveGadgetItem, the correct line is naturally deleted, but the colors aren't updated.
I could re-scan all the gadget items and re-apply the correct colors, but I wonder if this can be fixed :)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Blade wrote:Small bug:
I use PureCOLOR_SetCellColor to colorize a cell.
When I do RemoveGadgetItem, the correct line is naturally deleted, but the colors aren't updated.
I could re-scan all the gadget items and re-apply the correct colors, but I wonder if this can be fixed :)
Well, it's not really a bug: the library does not handle the listicon events, so it don't know if you add/remove/insert columns/rows.
But I could add a command to call after such modifications.

Or, I could do some subclassing, handle the LVM_[DELETE|INSERT][COLUMN|ITEM] messages and adjust the cells coordinates.
Last edited by gnozal on Wed Mar 02, 2005 8:41 am, edited 1 time in total.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

I wasn't sure about this to be a bug too...
Anyway that additional command would be nice :)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

Fixed
- ComboBox drop down list is now colorized
New functions
- PureCOLOR_SetWindowColor(WindowNumber.l, BackColor.l)
- PureCOLOR_ClearWindowColor(WindowNumber.l)
- PureCOLOR_SetColumnColor(ListIconNumber.l, Column.l, TextColor.l, BackColor.l)
- PureCOLOR_SetRowColor(ListIconNumber.l, Row.l, TextColor.l, BackColor.l)
- PureCOLOR_ClearColumnColor(ListIconNumber.l, Column.l)
- PureCOLOR_ClearRowColor(ListIconNumber.l, Row.l)
The coloring priority is Cells > Columns > Rows.
Changed
The listicon cell / row / column coloring functions use dynamic coordinates, e.g. the colorized cells / rows / columns coordinates are changed in realtime when the listicon [Add|Remove]Gadget[Item|Column]() functions are used.
For example : if cell (1,1) is colorized and a column is added at position 1, the cell coordinates are changed to (1,2) : the cell remains colorized (the new cell (1,1) is not).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Gnozal,
is there possible to colorize one only character on a StringGadget() ?
For example, i want the character * to be blue and the others black in the next string: "asdfiufibaifb*askdjhf"
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

It is possible for a RichEdit control (EditorGadget) by sending #EM_SETCHARFORMAT messages for example.
I don't think it's possible for an Edit control (StringGadget). Perhaps you could use a little EditorGadget to simulate a StringGadget ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thanx for your reply :)
I will replace StringGadgets by Editor ones.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Thanks gnozal!
This is much more than simply wrap some OS functions... :)
Post Reply