Page 1 sur 1

Animation de fenêtre

Publié : mar. 21/févr./2006 0:04
par Le Soldat Inconnu
Un truc tout bête utilisant la fonction AnimateWindow de l'API

Code : Tout sélectionner

; Auteur : Le Soldat Inconnu
; Version de PB : 4.00
;
; Explication du programme :
; Animation d'ouverture et de fermeture


#AW_HOR_POSITIVE = $1 ; Animates the window from left to right. This flag can be used with roll or slide animation.
#AW_HOR_NEGATIVE = $2 ; Animates the window from right to left. This flag can be used with roll or slide animation.
#AW_VER_POSITIVE = $4 ; Animates the window from top to bottom. This flag can be used with roll or slide animation.
#AW_VER_NEGATIVE = $8 ; Animates the window from bottom to top. This flag can be used with roll or slide animation.
#AW_CENTER = $10 ; Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
#AW_HIDE = $10000 ; Hides the window. By default, the window is shown.
#AW_ACTIVATE = $20000 ; Activates the window.
#AW_SLIDE = $40000 ; Uses slide animation. By default, roll animation is used.
#AW_BLEND = $80000 ; Uses a fade effect. This flag can be used only if hwnd is a top-level window.

Procedure.l Valeur_Duree()
    ProcedureReturn Val(GetGadgetText(1))
EndProcedure

Procedure Animation(Fenetre, Effet, Duree)
    ; On cache la fenêtre
    AnimateWindow_(WindowID(Fenetre), Duree, Effet | #AW_HIDE)
    
    Delay(1000)
    
    ; On affiche la fenêtre
    AnimateWindow_(WindowID(Fenetre), Duree, Effet)
    
    ; On redessine la fenêtre, certain gadget ne se réaffiche pas correctement
    RedrawWindow_(WindowID(Fenetre), 0, 0, 1)
EndProcedure



; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0 Or CreateGadgetList(WindowID(0)) = 0
    End
EndIf

TextGadget(#PB_Any, 0, 0, 300, 15, "Durée de l'animation en ms :")
StringGadget(1, 0, 15, 100, 20, "500", #PB_String_Numeric)

ButtonGadget(2, 0, 50, 150, 25, "Effet de transparence") : ButtonGadget(3, 150, 50, 150, 25, "Du centre")
ButtonGadget(4, 0, 75, 150, 25, "De la gauche vers la droite") : ButtonGadget(5, 150, 75, 150, 25, "De la droite vers la gauche")
ButtonGadget(6, 0, 100, 150, 25, "Du haut vers le bas") : ButtonGadget(7, 150, 100, 150, 25, "Du bas vers le haut")
ButtonGadget(8, 0, 125, 150, 25, "Diagonale HG vers BD") : ButtonGadget(9, 150, 125, 150, 25, "Diagonale BG vers HD")
ButtonGadget(10, 0, 150, 150, 25, "Diagonale HD vers BG") : ButtonGadget(11, 150, 150, 150, 25, "Diagonale BD vers HG")
Repeat
    Event = WaitWindowEvent()
    
    Select Event
        Case #PB_Event_Gadget
            Select EventGadget() ; Gadgets
                Case 2
                    Animation(0, #AW_BLEND, Valeur_Duree())
                Case 3
                    Animation(0, #AW_CENTER, Valeur_Duree())
                Case 4
                    Animation(0, #AW_HOR_POSITIVE, Valeur_Duree())
                Case 5
                    Animation(0, #AW_HOR_NEGATIVE, Valeur_Duree())
                Case 6
                    Animation(0, #AW_VER_POSITIVE, Valeur_Duree())
                Case 7
                    Animation(0, #AW_VER_NEGATIVE, Valeur_Duree())
                Case 8
                    Animation(0, #AW_HOR_POSITIVE | #AW_VER_POSITIVE, Valeur_Duree())
                Case 9
                    Animation(0, #AW_HOR_POSITIVE | #AW_VER_NEGATIVE, Valeur_Duree())
                Case 10
                    Animation(0, #AW_HOR_NEGATIVE | #AW_VER_POSITIVE, Valeur_Duree())
                Case 11
                    Animation(0, #AW_HOR_NEGATIVE | #AW_VER_NEGATIVE, Valeur_Duree())
            EndSelect
    EndSelect
    
Until Event = #PB_Event_CloseWindow

End

Publié : mar. 21/févr./2006 0:12
par flaith
8O Mortel !!! :D
:10:

Publié : mar. 21/févr./2006 0:20
par Backup
alors Microsoft m'a piqué mon idée ? 8O :lol:

Publié : mar. 21/févr./2006 11:08
par mangatome
C'est toujours utile des effets comme ça !
Merci !

Publié : mar. 21/févr./2006 12:17
par Jacobus
Yes! :D et facile à mettre en application comme ça. Merci!

Juste un exemple pour ouverture et fermeture :

Code : Tout sélectionner

#AW_CENTER = $10 
    #AW_HIDE = $10000 
    
    Procedure AnimationClose(Fenetre, Effet, Duree) 
      AnimateWindow_(WindowID(Fenetre), Duree, Effet | #AW_HIDE)  
    EndProcedure 
    
    Procedure AnimationOpen(Fenetre, Effet, Duree) 
      AnimateWindow_(WindowID(Fenetre), Duree, Effet)  
      RedrawWindow_(WindowID(Fenetre), 0, 0, 1) 
    EndProcedure 
    
  Procedure Slide()
    Hwnd = OpenWindow(0,0,0, 300, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget, "SLIDE!")
     HideWindow(0,1)
    If Hwnd = 0 Or CreateGadgetList(WindowID())=0  
        End 
      EndIf
    
      TextGadget(1, 0, 100, 300, 15, "BONJOUR TOUT LE MONDE !",#PB_Text_Center) 
      ButtonGadget(2, 75, 200, 150, 25, "CLICK ON !")
    
    AnimationOpen(0, #AW_CENTER, 500)
    ActivateWindow()
  EndProcedure 
   Slide()
    Repeat 
      Event = WaitWindowEvent()  
      Select Event 
        Case #PB_EventGadget 
          Select EventGadgetID() 
            Case 2 
              SetGadgetText(1,"BON, BEN AU REVOIR ALORS.") 
              Delay(1000)
              AnimationClose(0, #AW_CENTER, 500) 
              End 
          EndSelect 
      EndSelect 
      
    Until Event = #PB_EventCloseWindow 
     AnimationClose(0, #AW_CENTER, 500)
    End
L'effet est plus saisissant en exe qu' en compile avec le debugger.
Merci LSI.
(Merci Dobro d'avoir inspiré Bill :D )