Page 2 of 35

Posted: Wed Dec 15, 2004 8:34 am
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

Posted: Sat Jan 08, 2005 8:18 pm
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

Posted: Mon Jan 10, 2005 8:41 am
by gnozal
I must say I never tested that ! I only wanted to add basic button support. I will take a look ...

Posted: Wed Jan 26, 2005 8:40 am
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)

Posted: Wed Feb 23, 2005 8:58 am
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

Posted: Wed Feb 23, 2005 7:08 pm
by Blade
Great! :D

added:
Incredible, i needed this feature just few hours after you released it! thanks!!!

Posted: Thu Feb 24, 2005 8:41 am
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.

Posted: Sun Feb 27, 2005 3:56 pm
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 :)

Posted: Mon Feb 28, 2005 8:45 am
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.

Posted: Mon Feb 28, 2005 9:07 am
by Blade
I wasn't sure about this to be a bug too...
Anyway that additional command would be nice :)

Posted: Fri Mar 18, 2005 8:55 am
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).

Posted: Fri Mar 18, 2005 9:48 am
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"

Posted: Fri Mar 18, 2005 10:40 am
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 ?

Posted: Fri Mar 18, 2005 12:52 pm
by Psychophanta
Thanx for your reply :)
I will replace StringGadgets by Editor ones.

Posted: Fri Mar 18, 2005 7:12 pm
by Blade
Thanks gnozal!
This is much more than simply wrap some OS functions... :)