Basic Univers
; RollOver effects par Jacobus
; Astuce rendue possible grâce à DrDri et son Image Toggle
;
Enumeration
#win
#Btn_1
#Txt_Btn_1
#Btn_2
#Txt_Btn_2
#texto
#Statusbar
EndEnumeration

Global MyHand, Start, Image0, Image1, Font0
MyHand = LoadCursor_(0, #IDC_HAND) ; curseur main
Start  = LoadCursor_(0, #IDC_APPSTARTING) ; curseur démarrage application
Image0 = LoadIcon_(0, #IDI_ASTERISK)
Image1 = LoadIcon_(0, #IDI_EXCLAMATION)
Font0  = LoadFont(0, "Verdana", 9, #PB_Font_Bold|#PB_Font_HighQuality)

Procedure   IsMouseOver(hgadget)
  GetWindowRect_(hgadget, re.RECT)
  GetCursorPos_(pt.POINT)
  ProcedureReturn PtInRect_(re, pt\x, pt\y)
EndProcedure

Macro ImageGadgetBorderWidth()
  GetSystemMetrics_(#SM_CXEDGE)
EndMacro

Macro ImageGadgetBorderHeight()
  GetSystemMetrics_(#SM_CYEDGE)
EndMacro

Procedure.l SetImageGadgetBorder(Gadget.l, State.l)
  Protected Set.l = #False, GadgetID.l, Style.l
  Protected Width.l, Height.l, Change.l = #False
 
  GadgetID = GadgetID(Gadget)
 
  If GadgetID
    Style = GetWindowLong_(GadgetID, #GWL_EXSTYLE)
   
    Width  = GadgetWidth(Gadget)
    Height = GadgetHeight(Gadget)
   
    If State
      If Not Style & #PB_Image_Border
        Width  + ImageGadgetBorderWidth()  * 2
        Height + ImageGadgetBorderHeight() * 2
        Style |  #PB_Image_Border
        Change = #True
      EndIf
    Else
      If Style & #PB_Image_Border
        Width  - ImageGadgetBorderWidth()  * 2
        Height - ImageGadgetBorderHeight() * 2
        Style & ~#PB_Image_Border
        Change = #True
      EndIf
    EndIf
   
    If Change
      SetWindowLong_(GadgetID, #GWL_EXSTYLE, Style)
      SetWindowPos_(GadgetID, 0, 0, 0, Width, Height, #SWP_NOMOVE | #SWP_FRAMECHANGED)
    EndIf
   
    Set = #True
  EndIf
 
  ProcedureReturn Set
EndProcedure

Procedure Release_Mouse()
   Mouse_x = WindowMouseX(#win)
   Mouse_y = WindowMouseY(#win)
   If Mouse_x = - 1  Or Mouse_y = - 1
    ProcedureReturn 0
   EndIf
EndProcedure

Procedure Disable_MouseOver()
 StatusBarText(#Statusbar, 0, "RollOver effects")
  SetImageGadgetBorder(#Btn_1, #False)
  SetImageGadgetBorder(#Btn_2, #False)
  If GetGadgetFont(#Txt_Btn_1) <> FontParDefaut
    SetGadgetFont(#Txt_Btn_1, #PB_Default)
  EndIf
  If GetGadgetFont(#Txt_Btn_2) <> FontParDefaut
    SetGadgetFont(#Txt_Btn_2, #PB_Default)
  EndIf
  If GetGadgetFont(#texto) <> FontParDefaut
    SetGadgetFont(#texto, #PB_Default)
  EndIf
EndProcedure


Global FontParDefaut.l

OpenWindow(#win, 0, 0, 240, 280, "RollOver Buttons Example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(#win))
SetWindowColor(#win, RGB(157, 173, 206))
 
    btn1 = ImageGadget(#Btn_1, 85, 10, 100, 60, Image1) ; on se sert d'une image comme bouton
    TextGadget(#Txt_Btn_1, 5, 70, 220, 30, "Button Number 1" + Chr(13)+"Ce bouton vous mène à rien", #PB_Text_Center)
    SetGadgetColor(#Txt_Btn_1, #PB_Gadget_FrontColor, RGB(255, 255, 255))
    SetGadgetColor(#Txt_Btn_1, #PB_Gadget_BackColor, RGB(157, 173, 206))
       
    btn2 = ImageGadget(#Btn_2, 85, 105, 100, 60, Image0) ; ImageGadget ajuste sa taille à celle de l'image
    TextGadget(#Txt_Btn_2, 5, 165, 220, 30, "Button Number 2" + Chr(13)+"Celui-ci non plus d'ailleurs", #PB_Text_Center)
    SetGadgetColor(#Txt_Btn_2, #PB_Gadget_FrontColor, RGB(255, 255, 255))
    SetGadgetColor(#Txt_Btn_2, #PB_Gadget_BackColor, RGB(157, 173, 206))
   
    Texto = TextGadget(#texto, 5, 210, 220, 30, "Mais vous pourriez leur donner une destination", #PB_Text_Center)
    SetGadgetColor(#texto, #PB_Gadget_FrontColor, RGB(255, 255, 255))
    SetGadgetColor(#texto, #PB_Gadget_BackColor, RGB(157, 173, 206))

    FontParDefaut = GetGadgetFont(#Txt_Btn_1)
   
;-STATUSBAR
If CreateStatusBar(#Statusbar, WindowID(#win))
    AddStatusBarField(WindowWidth(#win)/2)
    AddStatusBarField(WindowWidth(#win)/2)
    StatusBarText(#Statusbar, 0, "RollOver effects",  #PB_StatusBar_Raised)
    StatusBarText(#Statusbar, 1, "PureBasic Users" + Chr(169),  #PB_StatusBar_Raised|#PB_StatusBar_Right)
EndIf


Repeat
 Event = WaitWindowEvent()
  Select Event
   
  Case #WM_MOUSEMOVE
    If IsMouseOver(btn1): SetCursor_(MyHand)
      StatusBarText(#Statusbar, 0, "Bouton 1 survolé")
      SetImageGadgetBorder(#Btn_1, #True)
      SetImageGadgetBorder(#Btn_2, #False)
      If GetGadgetFont(#Txt_Btn_1) <> Font0
         SetGadgetFont(#Txt_Btn_1, Font0)
      EndIf
      If GetGadgetFont(#Txt_Btn_2) <> FontParDefaut
         SetGadgetFont(#Txt_Btn_2, #PB_Default)
      EndIf
      If GetGadgetFont(#texto) <> FontParDefaut
        SetGadgetFont(#texto, #PB_Default)
      EndIf
    ElseIf IsMouseOver(btn2): SetCursor_(MyHand)
      StatusBarText(#Statusbar, 0, "Bouton 2 survolé")
      SetImageGadgetBorder(#Btn_1, #False)
      SetImageGadgetBorder(#Btn_2, #True)
      If GetGadgetFont(#Txt_Btn_1) <> FontParDefaut
         SetGadgetFont(#Txt_Btn_1, #PB_Default)
      EndIf
      If GetGadgetFont(#Txt_Btn_2) <> Font0
         SetGadgetFont(#Txt_Btn_2, Font0)
      EndIf
      If GetGadgetFont(#texto) <> FontParDefaut
        SetGadgetFont(#texto, #PB_Default)
      EndIf
    ElseIf IsMouseOver(Texto): SetCursor_(Start)
      StatusBarText(#Statusbar, 0, "Votre texto activé")
      SetImageGadgetBorder(#Btn_1, #False)
      SetImageGadgetBorder(#Btn_2, #False)
      If GetGadgetFont(#Txt_Btn_1) <> FontParDefaut
         SetGadgetFont(#Txt_Btn_1, #PB_Default)
      EndIf
      If GetGadgetFont(#Txt_Btn_2) <> FontParDefaut
         SetGadgetFont(#Txt_Btn_2, #PB_Default)
      EndIf
      If GetGadgetFont(#texto) <> Font0
         SetGadgetFont(#texto, Font0)
      EndIf
    Else
      StatusBarText(#Statusbar, 0, "RollOver effects")
      SetImageGadgetBorder(#Btn_1, #False)
      SetImageGadgetBorder(#Btn_2, #False)
      If GetGadgetFont(#Txt_Btn_1) <> FontParDefaut
         SetGadgetFont(#Txt_Btn_1, #PB_Default)
      EndIf
      If GetGadgetFont(#Txt_Btn_2) <> FontParDefaut
         SetGadgetFont(#Txt_Btn_2, #PB_Default)
      EndIf
      If GetGadgetFont(#texto) <> FontParDefaut
        SetGadgetFont(#texto, #PB_Default)
      EndIf
    EndIf
   
  Case #PB_Event_Gadget
     Select EventGadget()
     
     Case #Btn_1
       Select EventType()
           Case #PB_EventType_LeftClick
             MessageRequester("BOUTON 1", "Pas de programme de destination", #IDI_HAND)
             If Release_Mouse()= 0
                Disable_MouseOver()
            EndIf
       EndSelect
     
     
     Case #Btn_2
       Select EventType()
         Case #PB_EventType_LeftClick
           MessageRequester("BOUTON 2", "Pas de programme de destination", #IDI_APPLICATION)
           If Release_Mouse()= 0
                Disable_MouseOver()
            EndIf
       EndSelect
     
     EndSelect
   EndSelect
Until Event = #PB_Event_CloseWindow
End