Setting Gadget Colors

Just starting out? Need help? Post your questions and find answers here.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Setting Gadget Colors

Post by chris319 »

I'm having trouble changing the color of the ProgressBarGadgets in this program. The left gadget should be red, the center one green and the right one blue. The gadgets are coming out green despite not being initialized to that color.

Code: Select all

    ; (c) 2002 - Franco's template - absolutely freeware
    ; Thank's Pupil for the hint :)
    ; Desktop Loupe Function
Enumeration 1
#gadRedDec
#gadRedHex
#gadRedText
#gadGrnDec
#gadGrnHex
#gadGrnText
#gadBluDec
#gadBluHex
#gadBluText
#gadYDec
#gadYText
#gadSDec
#gadSText
#gadRedParade
#gadGreenParade
#gadBlueParade
EndEnumeration
Global s.f

#WI = 1:#HE=1
pass = 1

;#KR = 0.30: #KG = 0.59: #KB = 0.11 ;NTSC
;#KR = 0.299:#KG = 0.587:#KB = 0.114 ;REC.601
#KR = 0.2126:#KG = 0.7152:#KB = 0.0722;SMPTE 274M-1995 ALSO REC.709

    Procedure CaptureScreen(Left.l, Top.l)
      DC = GetDC_(0)
      MemDC = CreateCompatibleDC_(DC)
      BmpID = CreateImage(0, #WI, #HE)
      SelectObject_( MemDC, BmpID)
      StretchBlt_( MemDC, 0, 0,#WI,#HE, DC,Left, Top, #WI, #HE, #SRCCOPY)
      DeleteDC_( MemDC)
      ReleaseDC_(0,DC)
      ProcedureReturn BmpID
    EndProcedure
    
;If 
OpenWindow(1,0,0,300,600,"",#PB_Window_SystemMenu)
ProgressBarGadget(#gadredParade,0, 150, 100, 400, 0, 100,#PB_ProgressBar_Smooth|#PB_ProgressBar_Vertical)

SetGadgetColor(#gadRedParade,#PB_Gadget_FrontColor,#Red)

;SetGadgetColor(#gadRedParade,#PB_Gadget_frontColor,$E6FFFF)

;SetGadgetColor(#gadRedParade,#PB_Gadget_BackColor,#Red)

ProgressBarGadget(#gadGreenParade,100, 150, 100, 400, 0, 100,#PB_ProgressBar_Smooth|#PB_ProgressBar_Vertical)

ProgressBarGadget(#gadBlueParade,200, 150, 100, 400, 0, 100,#PB_ProgressBar_Smooth|#PB_ProgressBar_Vertical)


StickyWindow(1,#True)
;Else : End
; : EndIf
LoadFont(1,"Arial",10,#PB_Font_Bold)

TextGadget(#gadRedText,5,5,50,20,"Red")
SetGadgetColor(#gadRedText,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadRedText,#PB_Gadget_BackColor,#Red)
TextGadget(#gadRedDec,60,5,35,20,"",#PB_Text_Center)
SetGadgetColor(#gadRedDec,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadRedDec,#PB_Gadget_BackColor,#Red)

TextGadget(#gadGrnText,5,25,50,20,"Green")
SetGadgetColor(#gadGrnText,#PB_Gadget_FrontColor,#Black)
SetGadgetColor(#gadGrnText,#PB_Gadget_BackColor,#Green)
TextGadget(#gadGrnDec,60,25,35,20,"",#PB_Text_Center)
SetGadgetColor(#gadGrnDec,#PB_Gadget_FrontColor,#Black)
SetGadgetColor(#gadGrnDec,#PB_Gadget_BackColor,#Green)

TextGadget(#gadBluText,5,45,50,20,"Blue")
SetGadgetColor(#gadBluText,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadBluText,#PB_Gadget_BackColor,#Blue)
TextGadget(#gadBluDec,60,45,35,20,"",#PB_Text_Center)
SetGadgetColor(#gadBluDec,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadBluDec,#PB_Gadget_BackColor,#Blue)

TextGadget(#gadRedHex,100,5,35,20,"",#PB_Text_Center)
SetGadgetColor(#gadRedHex,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadRedHex,#PB_Gadget_BackColor,#Red)

TextGadget(#gadGrnHex,100,25,35,20,"",#PB_Text_Center)
SetGadgetColor(#gadGrnHex,#PB_Gadget_FrontColor,#Black)
SetGadgetColor(#gadGrnHex,#PB_Gadget_BackColor,#Green)

TextGadget(#gadBluHex,100,45,35,20,"",#PB_Text_Center)
SetGadgetColor(#gadBluHex,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadBluHex,#PB_Gadget_BackColor,#Blue)

TextGadget(#gadYText,5,65,120,20,"Y")
SetGadgetColor(#gadYText,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadYText,#PB_Gadget_BackColor,#Black)

TextGadget(#gadYDec,60,65,50,20,"",#PB_Text_Center)
SetGadgetColor(#gadYDec,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadYDec,#PB_Gadget_BackColor,#Black)

TextGadget(#gadSDec,60,85,50,20,"",#PB_Text_Center);IRE
SetGadgetColor(#gadSDec,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadSDec,#PB_Gadget_BackColor,#Black)
SetGadgetFont(#gadSDec,FontID(1))

TextGadget(#gadSText,5,85,120,20,"IRE")
SetGadgetColor(#gadSText,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#gadSText,#PB_Gadget_BackColor,#Black)
SetGadgetFont(#gadSText,FontID(1))

SetGadgetFont(#gadRedDec,FontID(1))
SetGadgetFont(#gadRedHex,FontID(1))
SetGadgetFont(#gadRedText,FontID(1))
SetGadgetFont(#gadGrnDec,FontID(1))
SetGadgetFont(#gadGrnHex,FontID(1))
SetGadgetFont(#gadGrnText,FontID(1))
SetGadgetFont(#gadBluDec,FontID(1))
SetGadgetFont(#gadBluHex,FontID(1))
SetGadgetFont(#gadBluText,FontID(1))
SetGadgetFont(#gadYText,FontID(1))
SetGadgetFont(#gadYDec,FontID(1))


    CursorPosition.POINT
    StartDrawing(WindowOutput(1))

    Repeat
      EventID = WaitWindowEvent(10)
      GetCursorPos_(CursorPosition)
      hImage = CaptureScreen(CursorPosition\x,CursorPosition\y)
      DrawImage(hImage, 0, 0,#WI,#HE)
colr = Point(0,0)
re = Red(colr)
gr = Green(colr)
bl = Blue(colr)
Box(150,0,100,100,RGB(re,gr,bl))

r.f = re: g.f = gr: b.f = bl

redIRE.f =((r-16)/((235-16)/(100)))
SetGadgetState(#gadRedParade,redIRE)
SetGadgetColor(#gadRedParade,#PB_Gadget_FrontColor,#Red)
;SetGadgetColor(#gadRedParade,#PB_Gadget_BackColor,#Red)



greenIRE.f =((g-16)/((235-16)/(100)))
SetGadgetState(#gadGreenParade,greenIRE)
blueIRE.f =((b-16)/((235-16)/(100)))
SetGadgetState(#gadBlueParade,blueIRE)



Y.f = (r*#KR) + (g*#KG) + (b*#KB)

IRE.f =((Y-16)/((235-16)/(100)))

SetGadgetText(#gadYDec,StrF(Y,0))
SetGadgetText(#gadSDec,StrF(IRE,0));IRE

SetGadgetText(#gadRedDec,Str(re))
SetGadgetText(#gadGrnDec,Str(gr))
SetGadgetText(#gadBluDec,Str(bl))

SetGadgetText(#gadRedHex,Hex(re))
SetGadgetText(#gadGrnHex,Hex(gr))
SetGadgetText(#gadBluHex,Hex(bl))

    Until EventID=#PB_Event_CloseWindow   

    End
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Setting Gadget Colors

Post by Dude »

The manual says: "On Windows XP with enabled skins, this coloring has no effect."

So you need to disable modern theme support in the Compiler Options, or turn off modern themes for each ProgressBarGadget() manually, like this:

Code: Select all

SetWindowTheme_(GadgetID(#ProgressBarGadgetNumber),"","") ; Turn off modern theme.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Setting Gadget Colors

Post by chris319 »

Disabling modern theme support globally got it to work, thank you.
Post Reply