HyperLinkGadget with centered text

Just starting out? Need help? Post your questions and find answers here.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

HyperLinkGadget with centered text

Post by eJan »

Is it possible to create HyperLinkGadget with centered text - like TextGadget() #PB_Text_Center. I have already added spaces before text to set it centered, but with large Fonts it looks messed. Any other solution?

Code: Select all

If OpenWindow(0, 0, 0, 300, 200, "GUI", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    
    TextGadget(1, 100, 90, 90, 16, "", #SS_GRAYFRAME) ; decorative
    HyperLinkGadget(2, 101, 91, 88,14,"Button", RGB(74,170,202))
    SetGadgetColor(2, #PB_Gadget_FrontColor, RGB(23,221,0))
    
    Repeat
      EventID = WaitWindowEvent()
      If EventID = #WM_MOUSEMOVE
        GetCursorPos_(pt.POINT) 
        GetWindowRect_(GadgetID(2),rect.RECT) 
        If PtInRect_(@rect,pt\x,pt\y)
          SetCursor_(LoadCursor_(0, #IDC_ARROW))  
        EndIf 
      EndIf
      
      If EventID = #PB_Event_Gadget
        Select EventGadget()
          Case 2
            SetGadgetText(2, "Clicked") 
            ;MessageRequester("Msg", "Clicked")
        EndSelect
      EndIf
      
    Until EventID = #PB_Event_CloseWindow
    
  EndIf
EndIf
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I don't think you can - at least not directly.

A hyperlink gadget is based on a Window's static control and as such, you can set the #SS_CENTER style only on creation (it's a Window's limitation). I guess that PB prevents this flag from being set.

What I can do however, is roll our own version of a hyperling gadget by simply adjusting your code.

Code: Select all

If OpenWindow(0, 0, 0, 300, 200, "GUI", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered) 
  If CreateGadgetList(WindowID(0)) 
    TextGadget(2, 101, 91, 88,18,"Button", #PB_Text_Center|#WS_BORDER) 
    SetGadgetColor(2, #PB_Gadget_FrontColor, RGB(23,221,0)) 
    Repeat 
      EventID = WaitWindowEvent() 
      If EventID = #WM_MOUSEMOVE 
        GetCursorPos_(pt.POINT) 
        GetWindowRect_(GadgetID(2),rect.RECT) 
        If PtInRect_(@rect,pt\x,pt\y) 
          SetCursor_(LoadCursor_(0, #IDC_HAND))  
          SetGadgetColor(2, #PB_Gadget_FrontColor, #Red) 
        Else
          SetGadgetColor(2, #PB_Gadget_FrontColor, RGB(23,221,0)) 
        EndIf 
      EndIf 
      
      If EventID = #PB_Event_Gadget 
        Select EventGadget() 
          Case 2 
            SetGadgetText(2, "Clicked") 
            ;MessageRequester("Msg", "Clicked") 
        EndSelect 
      EndIf 
      
    Until EventID = #PB_Event_CloseWindow 
    
  EndIf 
EndIf
I may look like a mule, but I'm not a complete ass.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Thanks srod, I'm using HyperLinkGadget because the text is visible over gradient, in case with TextGadget the text is not visible - maybe You can help Me (again) to set TextGadget over gradient.

Code: Select all

Declare WinProc(hwnd,msg,wParam,lParam)
Declare GradientImage(image,width,height,color1,color2,type)
Declare Gradient(FirstColor.l,LastColor.l,Colors.l,Direction.l)
 
Global hwnd.l,BackImage.l,hBrush.l,ButtonShadow

hwnd = OpenWindow(0,0,0,230,90,"Template",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
If hwnd
  If CreateGadgetList(WindowID(0))
    ButtonFace=GetSysColor_(#COLOR_BTNFACE) 
    ButtonShadow=GetSysColor_(#COLOR_BTNSHADOW)
    Color3DLight=GetSysColor_(#COLOR_INFOBK) 
    Gradient(ButtonShadow,ButtonFace,255,0)
    TopColor=RGB(Red(ButtonShadow)+10,Green(ButtonShadow)+10,Blue(ButtonShadow)+10)
    DownColor=RGB(Red(Color3DLight)-15,Green(Color3DLight)-15,Blue(Color3DLight)-15)
    ImageGadget(1,10,10,210,30,GradientImage(2,210,30,TopColor,DownColor,1))
    reg.s="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\eMule\"
    quotR.s = Left(reg, Len(reg) - FindString(Right(reg, 1), Chr(34), 1))
    quotL.s = Right(quotR, Len(quotR) - FindString(Left(quotR, 1), Chr(34), 1))
    cls.s = Left(quotL, Len(quotL) - FindString(Right(quotL, 1), "\", 1))
    TextGadget(2,10,10,210,30,cls+#CRLF$+cls,#SS_SUNKEN)
    TextGadget(3,4,4,222,82,"",#SS_GRAYFRAME)
    TextGadget(4,85,60,60,18,"",#SS_GRAYFRAME)
    TextGadget(5,86,61,58,16,"",#SS_WHITEFRAME) 
    HyperLinkGadget(6, 85, 62, 60,18,"Action", RGB(74,170,202)) ; to replace with TextGadget
    SetGadgetColor(6, #PB_Gadget_FrontColor, RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20))
    If LoadFont(0, "Verdana", 9, #PB_Font_Bold)
      SetGadgetFont(6, FontID(0))
    EndIf
  EndIf
  
  SetWindowCallback(@WinProc())
  ShowWindow_(hwnd,#SW_SHOWNORMAL)
  Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #WM_MOUSEMOVE
      GetCursorPos_(pt.POINT) 
      GetWindowRect_(GadgetID(6),rect.RECT) 
      If PtInRect_(@rect,pt\x,pt\y)
        SetCursor_(LoadCursor_(0, #IDC_ARROW))  
      EndIf 
    EndIf
    If EventID = #PB_Event_Gadget
      Select EventGadget()
        Case 6
          SendMessage_(hwnd, #WM_CLOSE,0,0)
      EndSelect
    EndIf
  Until EventID = #PB_Event_CloseWindow
EndIf
End

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select Msg 
    Case #WM_CTLCOLORSTATIC 
      SetBkMode_(wParam,#TRANSPARENT)
      TextColor=RGB(Red(ButtonShadow)-60,Green(ButtonShadow)-60,Blue(ButtonShadow)-60)
      SetTextColor_(wParam,TextColor) 
      result = GetStockObject_(#NULL_BRUSH) 
  EndSelect 
  ProcedureReturn result 
EndProcedure

Procedure GradientImage(image,width,height,color1,color2,type) 
  #vert = 0 
  #horz = 1 
  hImg = CreateImage(image,width,height) 
  If hImg 
    If type=#vert : i = width : Else : i = height : EndIf 
    sRed.f   = Red(color1)   : r.f = (Red  (color1) - Red  (color2))/i 
    sGreen.f = Green(color1) : g.f = (Green(color1) - Green(color2))/i 
    sBlue.f  = Blue(color1)  : b.f = (Blue (color1) - Blue (color2))/i 
    StartDrawing(ImageOutput(image)) 
    For a = 0 To i-1 
      x.f = sRed   - a*r 
      y.f = sGreen - a*g 
      z.f = sBlue  - a*b 
      If type=#horz 
        Line(0,a,width,0,RGB(x,y,z)) 
      Else 
        Line(a,0,0,height,RGB(x,y,z)) 
      EndIf 
    Next a 
    StopDrawing() 
  EndIf 
  ProcedureReturn hImg 
EndProcedure 

Procedure Gradient(FirstColor.l,EndColor.l,Colors.l,Direction.l)
  Protected r.l,g.l,b.l,reddif.l,greendif.l,bluedif.l,h.l,w.l,i.l,rt.l,gt.l,bt.l
  If Colors < 8 : Colors = 8:EndIf
  reddif   = Red(EndColor) - Red(FirstColor)
  greendif = Green(EndColor) - Green(FirstColor)
  bluedif  = Blue(EndColor) - Blue(FirstColor)
  h  = WindowHeight(0)
  w  = WindowWidth(0)
  rt = Red(FirstColor)
  gt = Green(FirstColor)
  bt = Blue(FirstColor)
  If BackImage : DeleteObject_(BackImage):EndIf
  BackImage = CreateImage(0, w,h)
  StartDrawing(ImageOutput(0))
  While i < Colors
    r = rt +  MulDiv_(i,reddif,Colors)
    g = gt +  MulDiv_(i,greendif,Colors)
    b = bt +  MulDiv_(i,bluedif,Colors)
    BackColor = RGB(r,g,b)
    If Direction = 1
      Box(MulDiv_(i,w,Colors),0,MulDiv_(i+2,w,Colors),h,BackColor)
    Else
      Box(0,MulDiv_(i,h,Colors),w,MulDiv_(i+2,h,Colors),BackColor)
    EndIf
    i = i + 1
  Wend
  StopDrawing()
  If hBrush : DeleteObject_(hBrush):EndIf
  hBrush = CreatePatternBrush_(BackImage)
  SetClassLong_(hwnd,#GCL_HBRBACKGROUND,hBrush)
  InvalidateRect_(hwnd,0,1)
EndProcedure
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here you are. The code carries almost directly over, but because you set a class background brush for your window before changing the text gadget's brush, you need to force a redraw of the main window. I did this by setting the window to be invisible in the OpenWindow() command.

Code: Select all

Declare WinProc(hwnd,msg,wParam,lParam) 
Declare GradientImage(image,width,height,color1,color2,type) 
Declare Gradient(FirstColor.l,LastColor.l,Colors.l,Direction.l) 
  
Global hwnd.l,BackImage.l,hBrush.l,ButtonShadow 

hwnd = OpenWindow(0,0,0,230,90,"Template",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible) 
If hwnd 
  If CreateGadgetList(WindowID(0)) 
    ButtonFace=GetSysColor_(#COLOR_BTNFACE) 
    ButtonShadow=GetSysColor_(#COLOR_BTNSHADOW) 
    Color3DLight=GetSysColor_(#COLOR_INFOBK) 
    Gradient(ButtonShadow,ButtonFace,255,0) 
    TopColor=RGB(Red(ButtonShadow)+10,Green(ButtonShadow)+10,Blue(ButtonShadow)+10) 
    DownColor=RGB(Red(Color3DLight)-15,Green(Color3DLight)-15,Blue(Color3DLight)-15) 
    ImageGadget(1,10,10,210,30,GradientImage(2,210,30,TopColor,DownColor,1)) 
    reg.s="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\eMule\" 
    quotR.s = Left(reg, Len(reg) - FindString(Right(reg, 1), Chr(34), 1)) 
    quotL.s = Right(quotR, Len(quotR) - FindString(Left(quotR, 1), Chr(34), 1)) 
    cls.s = Left(quotL, Len(quotL) - FindString(Right(quotL, 1), "\", 1)) 
    TextGadget(2,10,10,210,30,cls+#CRLF$+cls,#SS_SUNKEN) 
    TextGadget(3,4,4,222,82,"",#SS_GRAYFRAME) 
;    TextGadget(4,85,60,60,18,"",#SS_GRAYFRAME) 
;    TextGadget(5,86,61,58,16,"",#SS_WHITEFRAME) 
;    HyperLinkGadget(6, 85, 62, 60,18,"Action", RGB(74,170,202)) ; to replace with TextGadget 
    TextGadget(6, 85, 62, 60,18,"Action", #PB_Text_Center|#WS_BORDER) 
    SetGadgetColor(6, #PB_Gadget_FrontColor, RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20)) 
    If LoadFont(0, "Verdana", 9, #PB_Font_Bold) 
      SetGadgetFont(6, FontID(0)) 
    EndIf 
  EndIf 
  
  SetWindowCallback(@WinProc()) 
  ShowWindow_(hwnd,#SW_SHOWNORMAL) 
  Repeat 
    EventID.l = WaitWindowEvent() 
    If EventID = #WM_MOUSEMOVE 
        GetCursorPos_(pt.POINT) 
        GetWindowRect_(GadgetID(6),rect.RECT) 
        If PtInRect_(@rect,pt\x,pt\y) 
          SetCursor_(LoadCursor_(0, #IDC_HAND))  
          SetGadgetColor(6, #PB_Gadget_FrontColor, #Red) 
        Else
          SetGadgetColor(6, #PB_Gadget_FrontColor, RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20)) 
        EndIf 
    EndIf 
    If EventID = #PB_Event_Gadget 
      Select EventGadget() 
        Case 6 
          SendMessage_(hwnd, #WM_CLOSE,0,0) 
      EndSelect 
    EndIf 
  Until EventID = #PB_Event_CloseWindow 
EndIf 
End 

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select Msg 
    Case #WM_CTLCOLORSTATIC 
      SetBkMode_(wParam,#TRANSPARENT) 
      TextColor=RGB(Red(ButtonShadow)-60,Green(ButtonShadow)-60,Blue(ButtonShadow)-60) 
      SetTextColor_(wParam,TextColor) 
      result = GetStockObject_(#NULL_BRUSH) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

Procedure GradientImage(image,width,height,color1,color2,type) 
  #vert = 0 
  #horz = 1 
  hImg = CreateImage(image,width,height) 
  If hImg 
    If type=#vert : i = width : Else : i = height : EndIf 
    sRed.f   = Red(color1)   : r.f = (Red  (color1) - Red  (color2))/i 
    sGreen.f = Green(color1) : g.f = (Green(color1) - Green(color2))/i 
    sBlue.f  = Blue(color1)  : b.f = (Blue (color1) - Blue (color2))/i 
    StartDrawing(ImageOutput(image)) 
    For a = 0 To i-1 
      x.f = sRed   - a*r 
      y.f = sGreen - a*g 
      z.f = sBlue  - a*b 
      If type=#horz 
        Line(0,a,width,0,RGB(x,y,z)) 
      Else 
        Line(a,0,0,height,RGB(x,y,z)) 
      EndIf 
    Next a 
    StopDrawing() 
  EndIf 
  ProcedureReturn hImg 
EndProcedure 

Procedure Gradient(FirstColor.l,EndColor.l,Colors.l,Direction.l) 
  Protected r.l,g.l,b.l,reddif.l,greendif.l,bluedif.l,h.l,w.l,i.l,rt.l,gt.l,bt.l 
  If Colors < 8 : Colors = 8:EndIf 
  reddif   = Red(EndColor) - Red(FirstColor) 
  greendif = Green(EndColor) - Green(FirstColor) 
  bluedif  = Blue(EndColor) - Blue(FirstColor) 
  h  = WindowHeight(0) 
  w  = WindowWidth(0) 
  rt = Red(FirstColor) 
  gt = Green(FirstColor) 
  bt = Blue(FirstColor) 
  If BackImage : DeleteObject_(BackImage):EndIf 
  BackImage = CreateImage(0, w,h) 
  StartDrawing(ImageOutput(0)) 
  While i < Colors 
    r = rt +  MulDiv_(i,reddif,Colors) 
    g = gt +  MulDiv_(i,greendif,Colors) 
    b = bt +  MulDiv_(i,bluedif,Colors) 
    BackColor = RGB(r,g,b) 
    If Direction = 1 
      Box(MulDiv_(i,w,Colors),0,MulDiv_(i+2,w,Colors),h,BackColor) 
    Else 
      Box(0,MulDiv_(i,h,Colors),w,MulDiv_(i+2,h,Colors),BackColor) 
    EndIf 
    i = i + 1 
  Wend 
  StopDrawing() 
  If hBrush : DeleteObject_(hBrush):EndIf 
  hBrush = CreatePatternBrush_(BackImage) 
  SetClassLong_(hwnd,#GCL_HBRBACKGROUND,hBrush) 
  InvalidateRect_(hwnd,0,1) 
EndProcedure
By the way, I like your gradient code. I've been using this myself lately, so thanks for that. :)
I may look like a mule, but I'm not a complete ass.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Almost done, I have to find a way how to change color.

Code: Select all

    If EventID = #WM_MOUSEMOVE 
        GetCursorPos_(pt.POINT) 
        GetWindowRect_(GadgetID(6),rect.RECT) 
        If PtInRect_(@rect,pt\x,pt\y) 
          ;SetCursor_(LoadCursor_(0, #IDC_HAND))  
          SetGadgetColor(6, #PB_Gadget_FrontColor, #Red) 
        Else 
          SetGadgetColor(6, #PB_Gadget_FrontColor, RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20)) 
        EndIf 
    EndIf
Edit:

Code: Select all

    If EventID = #PB_Event_Gadget 
      Select EventGadget() 
        Case 6 ; does nothing
          SendMessage_(hwnd, #WM_CLOSE,0,0) 
      EndSelect 
    EndIf
Thanks srod!! Maybe it's better to keep HyperLinkGadget with spaces :(. Thanks again!!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here you are:

Code: Select all

Declare WinProc(hwnd,msg,wParam,lParam) 
Declare GradientImage(image,width,height,color1,color2,type) 
Declare Gradient(FirstColor.l,LastColor.l,Colors.l,Direction.l) 
  
Global hwnd.l,BackImage.l,hBrush.l,ButtonShadow, textcolor

hwnd = OpenWindow(0,0,0,230,90,"Template",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible) 
If hwnd 
  If CreateGadgetList(WindowID(0)) 
    ButtonFace=GetSysColor_(#COLOR_BTNFACE) 
    ButtonShadow=GetSysColor_(#COLOR_BTNSHADOW) 
    Color3DLight=GetSysColor_(#COLOR_INFOBK) 
    Gradient(ButtonShadow,ButtonFace,255,0) 
    TopColor=RGB(Red(ButtonShadow)+10,Green(ButtonShadow)+10,Blue(ButtonShadow)+10) 
    DownColor=RGB(Red(Color3DLight)-15,Green(Color3DLight)-15,Blue(Color3DLight)-15) 
    ImageGadget(1,10,10,210,30,GradientImage(2,210,30,TopColor,DownColor,1)) 
    reg.s="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\eMule\" 
    quotR.s = Left(reg, Len(reg) - FindString(Right(reg, 1), Chr(34), 1)) 
    quotL.s = Right(quotR, Len(quotR) - FindString(Left(quotR, 1), Chr(34), 1)) 
    cls.s = Left(quotL, Len(quotL) - FindString(Right(quotL, 1), "\", 1)) 
    TextGadget(2,10,10,210,30,cls+#CRLF$+cls,#SS_SUNKEN) 
    TextGadget(3,4,4,222,82,"",#SS_GRAYFRAME) 
;    TextGadget(4,85,60,60,18,"",#SS_GRAYFRAME) 
;    TextGadget(5,86,61,58,16,"",#SS_WHITEFRAME) 
;    HyperLinkGadget(6, 85, 62, 60,18,"Action", RGB(74,170,202)) ; to replace with TextGadget 
    TextGadget(6, 85, 62, 60,18,"Action", #PB_Text_Center|#WS_BORDER) 
    SetWindowLong_(GadgetID(6), #GWL_STYLE, GetWindowLong_(GadgetID(6), #GWL_STYLE) | #SS_NOTIFY) 

    textcolor=RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20) 
    If LoadFont(0, "Verdana", 9, #PB_Font_Bold) 
      SetGadgetFont(6, FontID(0)) 
    EndIf 
  EndIf 
  
  SetWindowCallback(@WinProc()) 
  ShowWindow_(hwnd,#SW_SHOWNORMAL) 
  Repeat 
    EventID.l = WaitWindowEvent() 
    If EventID = #WM_MOUSEMOVE 
        GetCursorPos_(pt.POINT) 
        GetWindowRect_(GadgetID(6),rect.RECT) 
        If PtInRect_(@rect,pt\x,pt\y) 
          SetCursor_(LoadCursor_(0, #IDC_HAND))  
          textcolor=#Red
        Else
          textcolor=RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20) 
        EndIf 
        InvalidateRect_(GadgetID(6),0,1)
    EndIf 
    If EventID = #PB_Event_Gadget 
      Select EventGadget() 
        Case 6 
          Debug "Link clicked!"
      EndSelect 
    EndIf 
  Until EventID = #PB_Event_CloseWindow 
EndIf 
End 

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select Msg 
    Case #WM_CTLCOLORSTATIC 
      SetBkMode_(wParam,#TRANSPARENT) 
;      TextColor=RGB(Red(ButtonShadow)-60,Green(ButtonShadow)-60,Blue(ButtonShadow)-60) 
      If lParam=GadgetID(6)
        SetTextColor_(wParam,textcolor) 
      Else
        SetTextColor_(wParam,RGB(Red(ButtonShadow)-20,Green(ButtonShadow)-20,Blue(ButtonShadow)-20)) 
      EndIf   
      
      result = GetStockObject_(#NULL_BRUSH) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

Procedure GradientImage(image,width,height,color1,color2,type) 
  #vert = 0 
  #horz = 1 
  hImg = CreateImage(image,width,height) 
  If hImg 
    If type=#vert : i = width : Else : i = height : EndIf 
    sRed.f   = Red(color1)   : r.f = (Red  (color1) - Red  (color2))/i 
    sGreen.f = Green(color1) : g.f = (Green(color1) - Green(color2))/i 
    sBlue.f  = Blue(color1)  : b.f = (Blue (color1) - Blue (color2))/i 
    StartDrawing(ImageOutput(image)) 
    For a = 0 To i-1 
      x.f = sRed   - a*r 
      y.f = sGreen - a*g 
      z.f = sBlue  - a*b 
      If type=#horz 
        Line(0,a,width,0,RGB(x,y,z)) 
      Else 
        Line(a,0,0,height,RGB(x,y,z)) 
      EndIf 
    Next a 
    StopDrawing() 
  EndIf 
  ProcedureReturn hImg 
EndProcedure 

Procedure Gradient(FirstColor.l,EndColor.l,Colors.l,Direction.l) 
  Protected r.l,g.l,b.l,reddif.l,greendif.l,bluedif.l,h.l,w.l,i.l,rt.l,gt.l,bt.l 
  If Colors < 8 : Colors = 8:EndIf 
  reddif   = Red(EndColor) - Red(FirstColor) 
  greendif = Green(EndColor) - Green(FirstColor) 
  bluedif  = Blue(EndColor) - Blue(FirstColor) 
  h  = WindowHeight(0) 
  w  = WindowWidth(0) 
  rt = Red(FirstColor) 
  gt = Green(FirstColor) 
  bt = Blue(FirstColor) 
  If BackImage : DeleteObject_(BackImage):EndIf 
  BackImage = CreateImage(0, w,h) 
  StartDrawing(ImageOutput(0)) 
  While i < Colors 
    r = rt +  MulDiv_(i,reddif,Colors) 
    g = gt +  MulDiv_(i,greendif,Colors) 
    b = bt +  MulDiv_(i,bluedif,Colors) 
    BackColor = RGB(r,g,b) 
    If Direction = 1 
      Box(MulDiv_(i,w,Colors),0,MulDiv_(i+2,w,Colors),h,BackColor) 
    Else 
      Box(0,MulDiv_(i,h,Colors),w,MulDiv_(i+2,h,Colors),BackColor) 
    EndIf 
    i = i + 1 
  Wend 
  StopDrawing() 
  If hBrush : DeleteObject_(hBrush):EndIf 
  hBrush = CreatePatternBrush_(BackImage) 
  SetClassLong_(hwnd,#GCL_HBRBACKGROUND,hBrush) 
  InvalidateRect_(hwnd,0,1) 
EndProcedure
Several things needed changing this time. One thing is the fact that TextGadgets do not send mouse notifications to their parent window's by default. For this you have to set the #SS_NOTIFY style etc.
Last edited by srod on Wed Jun 28, 2006 10:17 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

srod thanks a million, You're lifesaver!!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome. My payment for stealing your gradient colouring code! :D
I may look like a mule, but I'm not a complete ass.
Post Reply