petite surprise pour les amateurs de tarot

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
david
Messages : 208
Inscription : jeu. 03/févr./2005 21:10

petite surprise pour les amateurs de tarot

Message par david »

Compteur d'atouts:

j'avais promis il y a longtemps mais j'ai été absent encore cause ma santé
le source suivant a abouti avec l'aide de nombreux d'entre vous que je remercie au passage et qui se reconnaitront sans doute
je l'ai laissé tel quel faudrait qq modifications pour qu'il soit exploitable (modifier le nom des images a charger....)

si quelqu'un a des idées d'améliorations je suis preneur car je l'utilise tout le temps pour compter les atouts lors de mes parties de tarots pc

Code : Tout sélectionner

;******************************************************charge param.ini**************
If ReadFile(0, "Param.prefs")
  While Eof(0) = 0
    ligne1$  = ReadString()
    ligne2$  = ReadString()
    path1$   = ReadString()
    path2$   = ReadString()
    chemin$ = ReadString()
    transparent$ = ReadString()
    delay$ = ReadString()
    taillex$   = ReadString()
    tailley$ = ReadString()
    posix$ = ReadString()
    posiy$ = ReadString()
  Wend
    CloseFile(0) 
  Else
  MessageRequester ( "Alert vx.4" , "fichier 'param.prefs' non chargé"+Chr(13)+Chr(13)+"veuillez contacter David TURQUIN" , 0)
EndIf
;************************************************************************************
If ligne2$<>"David TURQUIN @2005"
MessageRequester ( "Alert vx.3" , "la version originale du programme a été modifiée"+Chr(13)+Chr(13)+"veuillez contacter David TURQUIN" , 0)
End
EndIf
;
;
UseJPEGImageDecoder ()  ;***DECODEUR JPEG
UsePNGImageDecoder ()   ;
UseTGAImageDecoder ()   ;
UseTIFFImageDecoder ()  ;

;***********DECODE VARIABLES***********
a=0 
textb=21 
textb$=Str(textb) 
taille=3
transparent=Val(transparent$)
taillex= Val(taillex$) 
tailley = Val(tailley$) 
posix = Val(posix$) 
posiy = Val(posiy$) 
delay=Val(delay$)
fenetre=tailley
; 
; 
Declare TimerProc(hwnd.l, uMsg.l, idEvent.l, dwTime.l) 
Declare SetWinTransparency(WinHandle.l, Transparency_Level.l) 
Global bouton,flag,Handle 

;- Gadget Constants 
; 
Enumeration 
  #Window_0 
  #Button_1 
  #Button_2 
  #Button_3 
  #String_0 
  #Button_4 
  #Button_5 
  #Button_6 
  #Button_7 
  #Button_8 
  #Button_9 
  #image_gadget1 ;arriere plan 
  #image1 ;gaby1 
  #image2 ;gaby2 
  #image0 ; image variable... 
  #TrackBar_0 
  #TrackBar_10 
  #TrackBar_2 
  #TrackBar_20 
  #Path_0 
  #Button_11 
  #ImageBuffet1

EndEnumeration 

NewList Maliste.s() 
  
;************************************ 
;*** Test Images pas piratees ******* 
;************************************ 
Resultat=FileSize("gaby1.jpg") 
If Resultat<>470168
MessageRequester ( "Alert vx.3" , "la version originale du programme a été modifiée"+Chr(13)+Chr(13)+"veuillez contacter David TURQUIN" , 0)
End
EndIf
Resultat=FileSize("gaby2.jpg") 
If Resultat<>746918
MessageRequester ( "Alert vx.3" , "la version originale du programme a été modifiée"+Chr(13)+Chr(13)+"veuillez contacter David TURQUIN" , 0)
End
EndIf


;************************************ 
;*** charge image programme ********* 
;************************************ 
LoadImage ( #image1 , "gaby1.jpg" ) ;image de depart 
LoadImage ( #image2 , "gaby2.jpg" );image en cas de clic sur bouton 
ResizeImage ( #image1 , taillex-126, tailley ) 
ResizeImage ( #image2 , taillex-126, tailley) 
CopyImage(#Image1, #ImageBuffet1) ;met image en memoire buffet


If OpenWindow ( #Window_0 , posix, posiy, taillex, fenetre, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Compteur Atouts" ) 
  SetWindowPos_(WindowID(), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE) ;fenetre toujours devant 
  Handle = WindowID (0) 
  
      If CreateGadgetList ( WindowID ()) 
         ImageGadget ( #image_gadget1 , 2,34,100*taille,100*taille, UseImage ( #image1 )) 
    
          ButtonGadget ( #Button_1 , 2, 2, 30, 30, "1" ) 
      ButtonGadget ( #Button_2 , 32, 2, 30, 30, "2" ) 
      ButtonGadget ( #Button_3 , 62, 2, 30, 30, "3" ) 
      ButtonGadget ( #Button_4 , 92, 2, 30, 30, "4" ) 
      ButtonGadget ( #Button_5 , 122, 2, 40, 30, "<-" ) 
      ButtonGadget ( #Button_6 , 162, 2, 90, 30, "remise Zero" ) 
      StringGadget ( #String_0 , 252, 2, 30, 30, textb$ ) 
      ButtonGadget ( #Button_7 , 282, 2, 60, 30, "info" )
      ButtonGadget ( #Button_8 , 342, 2, 60, 30, "visio" )
      ButtonGadget ( #Button_9 , 402, 2, 60, 30, "reduire" )
    
    TextGadget    (#TrackBar_10, taillex-120,46,120, 20,"Niv. Transparence",#PB_Text_Center) 
    TrackBarGadget(#TrackBar_0, taillex-120, 60, 120, 30, 25, 255) 
    SetGadgetState(#TrackBar_0, transparent) 
    
    TextGadget    (#TrackBar_20, taillex-120,110,120, 20,"durée images",#PB_Text_Center) 
    TrackBarGadget(#TrackBar_2, taillex-120, 124, 120, 30, 1, 30) 
    SetGadgetState(#TrackBar_2, delay) 

    StringGadget  (#Path_0,  taillex-120, 180, 118, 24, chemin$) 
    ButtonGadget ( #Button_11 , taillex-120, 194, 120, 20, "sauve paramètres" ) 
    EndIf 
  
SetTimer_(WindowID(),1,delay*1000,0)           ;affiche param de depart***
SetWinTransparency(WindowID(),transparent)     ;affiche param de depart***

  Repeat  ;La boucle Repeat-Until sert à la gestion des évènements 
    
    Select WaitWindowEvent () ; on sélectionne cet évènement 
      
      Case #WM_TIMER ; cet évènement concerne le timer 
        
        ;******************************************* 
        ;*** Affiche aléatoirement Maliste(x) *** 
        ;******************************************* 
        
        If CountList(Maliste()) 
          
          SelectElement(Maliste(),Random(Compteur)) 
          
          If IsImage(#image0) 
            FreeImage(#image0) 
          EndIf 
          
          If LoadImage(#image0,chemin$+"\"+Maliste()) 
            ResizeImage ( #image0 , 112*taille, 83*taille ) 
            ResizeImage ( #image0 , taillex-124, tailley )
            SetGadgetState(#image_gadget1,UseImage(#image0)) 
          EndIf 
          
        EndIf 
        
      Case #PB_EventGadget ; cet évènement concerne une action sur un Gadget 
        
        Select EventGadgetID () ; dans ce cas, on récupère l'identifiant du gadget qui l'a créé 
          
               Case #Button_1 ; on compare l'identifiant à #ButtonGadget 
                  a=1
                  If textb-a<0
                  a=0
                  EndIf 
                  textb=textb-a 
                  SetGadgetText(#String_0,Str(textb)) 
                  
               Case #Button_2 ; on compare l'identifiant à #ButtonGadget 
                  a=2
                  If textb-a<0
                  a=0
                  EndIf 
                  textb=textb-a 
                  SetGadgetText(#String_0,Str(textb)) 
                  
               Case #Button_3 ; on compare l'identifiant à #ButtonGadget 
                  a=3
                  If textb-a<0
                  a=0
                  EndIf 
                  textb=textb-a 
                  SetGadgetText(#String_0,Str(textb)) 
                  
               Case #Button_4 ; on compare l'identifiant à #ButtonGadget 
                  a=4
                  If textb-a<0
                  a=0
                  EndIf 
                  textb=textb-a 
                  SetGadgetText(#String_0,Str(textb)) 
                  
               Case #Button_5 ; on compare l'identifiant à #ButtonGadget 
                  textb=textb+a
                  If textb+a>21
                  a=0
                  EndIf 
                  SetGadgetText(#String_0,Str(textb)) 
                  
               Case #Button_6 ; on compare l'identifiant à #ButtonGadget 
                  textb=21 
                  SetGadgetText(#String_0,Str(textb)) 
                  
               Case #Button_7 ; on compare l'identifiant à #ButtonGadget 
              ResizeImage ( #image2 , taillex-124, tailley )
              SetGadgetState ( #image_gadget1 , UseImage ( #image2 )) 
              MessageRequester ( "Compteur Info" , " version spéciale les GG..."+Chr(13)+Chr(13)+"Par David TURQUIN @2005" , 0)        
              SetGadgetState ( #image_gadget1 , UseImage ( #image1 )) 
          
          Case #TrackBar_0 
            transparent = GetGadgetState(#TrackBar_0) 
            SetGadgetText(#TrackBar_10,"Transparence: "+Str(transparent)+"/255") 
            SetWinTransparency(WindowID(),transparent) 
            
          Case #TrackBar_2 
            delay = GetGadgetState(#TrackBar_2) 
            SetGadgetText(#TrackBar_20,"Intervalle: "+Str(delay)+" s") 
            KillTimer_(WindowID(),1) 
            SetTimer_(WindowID(),1,delay*1000,0) 
            
          Case #Button_8 ;visionneuse charge images 
            
            ;*********************************************** 
            ;*** Examine le dossier et remplit Maliste() *** 
            ;*********************************************** 
            ClearList(Maliste()) 
            
            If ExamineDirectory (0,chemin$,"*.*") 
              Repeat 
                Select NextDirectoryEntry() 
                  Case 0 
                    Break 
                  Case 1 
                    FileName$ = DirectoryEntryName() 
                    FileExt$ = UCase(GetExtensionPart(FileName$)) 
                    If FindString("JPG,JPEG,BMP,PNG",FileExt$,1) 
                      AddElement(Maliste()) 
                      Maliste() = FileName$ 
                    EndIf 
                EndSelect 
              ForEver 
            Else 
              MessageRequester("Erreur","impossible de créer la liste"+#LF$+"Veuillez reconfigurer les paramètres...") 
            EndIf 
            
            ;********************************** 
            ;*** Vérification de Maliste(x) *** 
            ;********************************** 
            
            Compteur = CountList(Maliste()) 
             If Compteur 
              MessageRequester("Information",Str(Compteur)+" images chargées.") 
            Else 
              MessageRequester("Erreur","Aucune image chargée.") 
            EndIf 
            
            Case #Button_9   
                   taillex=341
                   tailley=216
                   ResizeWindow(taillex, tailley)

                  Case #Button_11

 resultat= CreateFile(0, "Param.prefs") 
  If resultat = 0
         MessageRequester ( "Paramètres" , "Pb sauvegarde paramètres" , 0) 
         EndIf
   MessageRequester ( "Sauvegarde" , "Enregistrement des paramètres effectué"+Chr(10)+"Appuyez sur ok pour continuer..." , 0) 


delay$=Str(delay)                   ;********remet les valeurs*****
transparent$=Str(transparent)
chemin$ = GetGadgetText(#Path_0)

  WriteStringN(ligne1$)
  WriteStringN(ligne2$)
  WriteStringN(path1$)
  WriteStringN(path2$)
  WriteStringN(chemin$)
  WriteStringN(transparent$)
  WriteStringN(delay$)
  WriteStringN(Str(WindowWidth()))   ;taillex
  WriteStringN(Str(WindowHeight()))  ;tailley
  WriteStringN(Str(WindowX()))       ;posix
  WriteStringN(Str(WindowY()))       ;posiy
 
  CloseFile(0)
   EndSelect 
        
      Case #PB_Event_CloseWindow ; cet évènement concerne la fermeture de la fenêtre 
        Quit=1 
   
     Case #PB_Event_SizeWindow  
       taillex=WindowWidth() 
      tailley = WindowHeight() 
 
ResizeGadget(#TrackBar_10,taillex-120,-1,-1,-1) 
ResizeGadget(#TrackBar_0,taillex-120,-1,-1,-1) 
ResizeGadget(#TrackBar_20,taillex-120,-1,-1,-1) 
ResizeGadget(#TrackBar_2,taillex-120,-1,-1,-1) 
ResizeGadget(#Path_0,taillex-120,-1,-1,-1) 
ResizeGadget(#Button_11,taillex-120,-1,-1,-1) 

CopyImage(#ImageBuffet1,#Image1) ;remet image orgirine en memoire a partir du buffet

ResizeImage ( #image1 , taillex-124, tailley ) ;sinon image se dégrade en redimensionnement
SetGadgetState(#image_gadget1,UseImage(#image1)) 

    EndSelect 
    
  Until Quit=1 
EndIf 
; 
KillTimer_(WindowID(),1) 
;
 
Procedure SetWinTransparency(WinHandle.l, Transparency_Level.l) 
  SetWindowLong_ (WinHandle, #GWL_EXSTYLE , GetWindowLong_ (WinHandle, #GWL_EXSTYLE ) | $00080000) ; #WS_EX_LAYERED = $00080000 
  If OpenLibrary (0, "user32.dll" ) 
    CallFunction (0, "SetLayeredWindowAttributes" , WinHandle, 0, Transparency_Level, 2) 
    CloseLibrary (0) 
  EndIf 
EndProcedure