[Ex] Créer un panneau d'affichage (comme dans les trams ^^)
Posté : mar. 22 juin 2010 19:08
par TommyDDR
Voila, je me suis rendu compte que je demandais beaucoup d'aide sans pour autant partager énormément,
c'est pourquoi je post ici un petit UDF que je viens de "finir" (il reste quelques améliorations à faire, mais il est fonctionnel)
J'ai créé un testeur pour pouvoir voir directement ce que propose l UDF ^^
Have Fun.
Edit : J'ajoute l'outil pour créer ses propre caracteres
Utilisation : appuyez sur 0 et 1 (Pavé numérique) pour "allumer" ou non un pixel
c'est pourquoi je post ici un petit UDF que je viens de "finir" (il reste quelques améliorations à faire, mais il est fonctionnel)
J'ai créé un testeur pour pouvoir voir directement ce que propose l UDF ^^
Have Fun.
Edit : J'ajoute l'outil pour créer ses propre caracteres
Utilisation : appuyez sur 0 et 1 (Pavé numérique) pour "allumer" ou non un pixel
► Afficher le texteUDF
Code : Tout sélectionner
Dim $Alphabet[27] = ["011111001100011011000110110001101100011011111110110001101100011011000110", "111111001100011011000110110001101111110011000110110001101100011011111100", "011111001100011011000000110000001100000011000000110000001100011001111100", "111111001100011011000110110001101100011011000110110001101100011011111100", "111111101100000011000000110000001111100011000000110000001100000011111110", "111111001100000011000000110000001111100011000000110000001100000011000000", "011111001100011011000000110000001100000011001110110001101100011001111100", "110001101100011011000110110001101111111011000110110001101100011011000110", "000110000001100000011000000110000001100000011000000110000001100000011000", "111111100001100000011000000110000001100000011000000110000001100011110000", "110001101100011011000110110011001111100011001100110001101100011011000110", "110000001100000011000000110000001100000011000000110000001100000011111110", "110001101110111011111110110101101100011011000110110001101100011011000110", "110001101100011011100110111101101111111011011110110011101100011011000110", "011111001100011011000110110001101100011011000110110001101100011001111100", "111111001100011011000110110001101100011011111100110000001100000011000000", "011111001100011011000110110001101100011011000110110011100111110000000110", "111111001100011011000110110001101111110011001100110001101100011011000110", "011111101100000011000000110000000111110000000110000001100000011011111100", "111111100011000000110000001100000011000000110000001100000011000000110000", "110001101100011011000110110001101100011011000110110001101100011001111100", "110001101100011011000110110001101100011011000110011011000011100000010000", "110001101100011011000110110001101100011011010110111111101110111011000110", "110001101100011011000110011011000011100001101100110001101100011011000110", "110001101100011011000110110001100111111000000110000001100000011001111100", "111111100000011000001100000110000011000001100000110000001100000011111110", "000000000000000000000000000000000000000000000000000000000000000000000000"]
Dim $Cases[9][7]
Dim $Casess[9][7]
Dim $CouleurTexte = 0xA00000
Dim $CouleurFond = 0x002000
Dim $Texte = ""
Dim $Position = 0
Dim $NbCaracteresX = 0
Dim $RandMin = 0
Dim $RandMax = 0
Dim $TempsDelai = 100
Dim $TaillePix[2] = [5, 5]
Dim $EspacementPix[2] = [2, 2]
Dim $EtatClignotement = False
Dim $Defiler = False
Dim $Clignoter = False
;===============================================================================
; Nom: CreerPanneau()
; Description: Créé un panneau d'affichage (style tram)
; Paramètres: $TexteParam : Texte afficher par le panneau
; $PosX : Position dans la fenêtre (abscisse)
; $PosY : Position dans la fenêtre (ordonnée)
; $NbCaracteresXParam : Taille du panneau (en nombre de caractères)
; $Delai : Temps d'attente entre chaque mouvements du texte
; $TaillePixX : Taille d'un pixel d'affichage (abscisse)
; $TaillePixY : Taille d'un pixel d'affichage (ordonnée)
; $EspacementX : Taille de l'espacement entre 2 pixels d'affichage (abscisse)
; $EspacementY : Taille de l'espacement entre 2 pixels d'affichage (ordonnée)
; Auteur: TommyDDR
;===============================================================================
Func CreerPanneau($TexteParam, $PosX, $PosY, $NbCaracteresXParam, $TextCouleur = 0x00A000, $FondCouleur = 0x002000, $Delai = 100, $TaillePixX = 5, $TaillePixY = 5, $EspacementX = 2, $EspacementY = 2)
If($TextCouleur = -1) Then
$CouleurTexte = 0x00A000
Else
$CouleurTexte = $TextCouleur
EndIf
If($FondCouleur = -1) Then
$CouleurFond = 0x002000
Else
$CouleurFond = $FondCouleur
EndIf
If($Delai = -1) Then
$TempsDelai = 100
Else
$TempsDelai = $Delai
EndIf
If($TaillePixX = -1) Then
$TaillePix[0] = 5
Else
$TaillePix[0] = $TaillePixX
EndIf
If($TaillePixY = -1) Then
$TaillePix[1] = 5
Else
$TaillePix[1] = $TaillePixY
EndIf
If($EspacementX = -1) Then
$EspacementPix[0] = 2
Else
$EspacementPix[0] = $EspacementX
EndIf
If($EspacementY = -1) Then
$EspacementPix[1] = 2
Else
$EspacementPix[1] = $EspacementY
EndIf
$TaillePix[0] = $TaillePixX
$TaillePix[1] = $TaillePixY
$EspacementPix[0] = $EspacementX
$EspacementPix[1] = $EspacementY
$NbCaracteresX = $NbCaracteresXParam
ReDim $Cases[9][$NbCaracteresX*8]
ReDim $Casess[9][$NbCaracteresX*8]
Panneau_Set_Text($TexteParam)
$Position = $NbCaracteresX*8
For $i = 0 To ($NbCaracteresX*8)-1
For $j = 0 To 8
$Cases[$j][$i] = GUICtrlCreateLabel("", $PosX+$i*($TaillePix[0] + $EspacementPix[0])+Random($RandMin, $RandMax, 1), $PosY+$j*($TaillePix[1] + $EspacementPix[1])+Random($RandMin, $RandMax, 1), $TaillePix[0], $TaillePix[1])
$Casess[$j][$i] = 0
GUICtrlSetBkColor(-1, $CouleurFond)
Next
Next
$Defiler = True
DemarrerDefilement()
EndFunc
;===============================================================================
; Nom: ChangerDefilement()
; Description: Arrête / relance le défilement du texte
; Auteur: TommyDDR
;===============================================================================
Func ChangerDefilement()
$Defiler = Not $Defiler
If($Defiler) Then
DemarrerDefilement()
Else
StoperDefilement()
EndIf
EndFunc
;===============================================================================
; Nom: DemarrerDefilement()
; Description: Lance le défilement du texte
; Auteur: TommyDDR
;===============================================================================
Func DemarrerDefilement()
AdlibRegister("FaireDefiler", $TempsDelai)
EndFunc
;===============================================================================
; Nom: StoperDefilement()
; Description: Arrête le défilement du texte
; Auteur: TommyDDR
;===============================================================================
Func StoperDefilement()
AdlibUnRegister("FaireDefiler")
EndFunc
;===============================================================================
; Nom: ChangerClignotement()
; Description: Arrête / relance le clignotement du texte
; Auteur: TommyDDR
;===============================================================================
Func ChangerClignotement()
$Clignoter = Not $Clignoter
If($Clignoter) Then
DemarrerClignotement()
Else
StoperClignotement()
EndIf
EndFunc
;===============================================================================
; Nom: DemarrerClignotement()
; Description: Lance le clignotement du texte
; Auteur: TommyDDR
;===============================================================================
Func DemarrerClignotement()
StoperDefilement()
AdlibRegister("FaireClignoter", 200)
EndFunc
;===============================================================================
; Nom: StoperClignotement()
; Description: Arrête le clignotement du texte
; Auteur: TommyDDR
;===============================================================================
Func StoperClignotement()
AdlibUnRegister("FaireClignoter")
If($EtatClignotement) Then
FaireClignoter()
EndIf
If($Defiler) Then
DemarrerDefilement()
EndIf
EndFunc
;===============================================================================
; Nom: FaireClignoter()
; Description: Fait clignoter le texte
; Auteur: TommyDDR
;===============================================================================
Func FaireClignoter()
If($EtatClignotement) Then
For $i = 0 To ($NbCaracteresX*8)-1
For $j = 0 To 8
If($Casess[$j][$i] <> 0) Then
GUICtrlSetBkColor($Cases[$j][$i], $CouleurTexte)
EndIf
Next
Next
Else
For $i = 0 To ($NbCaracteresX*8)-1
For $j = 0 To 8
If($Casess[$j][$i] <> 0) Then
GUICtrlSetBkColor($Cases[$j][$i], $CouleurFond)
EndIf
Next
Next
EndIf
$EtatClignotement = Not $EtatClignotement
EndFunc
;===============================================================================
; Nom: FaireDefiler()
; Description: Fait défiler le texte
; Auteur: TommyDDR
;===============================================================================
Func FaireDefiler()
StoperDefilement()
Local $Start = 0
Local $NumeroLettre = ""
Local $Police = ""
Local $Couleur = ""
Local $var = ""
Local $Decalage = 0
$Position -= 1
If($Position < -(StringLen($Texte)*8)) Then
$Position = $NbCaracteresX*8
EndIf
$Start = $Position
If($Position < 0) Then
$Start = 0
$Decalage = Mod(Abs($Position), 8)
EndIf
If($Position >= 0) Then
$NumeroLettre = 1
$Decalage = 0
Else
$NumeroLettre = Int((Abs($Position))/8)+1
EndIf
$Lettre = Asc(StringMid($Texte, $NumeroLettre, 1))-65
If(Not($Lettre >= 0 And $Lettre < 26)) Then
$Lettre = 26
EndIf
$Police = $Alphabet[$Lettre]
For $i = $Start To ($NbCaracteresX*8)-1
If(Mod(($i-$Start+1+$Decalage), 8) = 0) Then
$NumeroLettre += 1
$Lettre = Asc(StringMid($Texte, $NumeroLettre, 1))-65
If(Not($Lettre >= 0 And $Lettre < 26)) Then
$Lettre = 26
EndIf
$Police = $Alphabet[$Lettre]
EndIf
If($Lettre <= 26 And $Lettre >= 0) Then
For $j = 0 To 8
$Couleur = StringMid($Police, $j*8+1+Mod($i-$Start+$Decalage, 8), 1)
If($Couleur = 0 And $Casess[$j][$i] = 1) Then
GUICtrlSetBkColor($Cases[$j][$i], $CouleurFond)
$Casess[$j][$i] = 0
ElseIf($Couleur = 1 And $Casess[$j][$i] = 0) Then
GUICtrlSetBkColor($Cases[$j][$i], $CouleurTexte)
$Casess[$j][$i] = 1
EndIf
Next
EndIf
Next
If($Defiler And Not $Clignoter) Then
DemarrerDefilement()
EndIf
EndFunc
;===============================================================================
; Nom: Panneau_Set_Text()
; Description: Change le texte affiché
; Auteur: TommyDDR
;===============================================================================
Func Panneau_Set_Text($NewTxt)
If($Defiler) Then
StoperDefilement()
EndIf
$NewTxt = StringUpper($NewTxt)
$Texte = $NewTxt
For $i = 0 To ($NbCaracteresX*8)-1
For $j = 0 To 8
If($Casess[$j][$i] <> 0) Then
GUICtrlSetBkColor($Cases[$j][$i], $CouleurFond)
$Casess[$j][$i] = 0
EndIf
Next
Next
If($Defiler) Then
DemarrerDefilement()
EndIf
EndFunc
► Afficher le textetesteur
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <CreerPanneau.au3>
Opt("GUIOnEventMode", 1)
Dim $Gui
$Gui = GUICreate("Panneau", 400, 150)
GUISetBkColor(0x000000)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
CreerPanneau("TommyDDR", 5, 5, 8, -1, -1, -1, 4, 4)
$Input = GUICtrlCreateInput("TommyDDR", 5, 90, 190, 20)
$BoutonValider = GUICtrlCreateButton("Valider", 200, 90, 190, 20)
$BoutonDefil = GUICtrlCreateButton("Defiler", 5, 120, 190, 20)
$BoutonClign = GUICtrlCreateButton("Clignoter", 200, 120, 190, 20)
GUICtrlSetOnEvent($BoutonValider, "ChangerText")
GUICtrlSetOnEvent($BoutonDefil, "ChangerDefilement")
GUICtrlSetOnEvent($BoutonClign, "ChangerClignotement")
GUISetState()
Func ChangerText()
$Txt = GUICtrlRead($Input)
Panneau_Set_Text($Txt)
EndFunc
While(True)
Sleep(10)
WEnd
Func quit()
Exit
EndFunc
► Afficher le texteEdit :Caligraphie
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1)
Dim $Gui
Dim $Cases[9][7]
Dim $Casess[9][7]
$Gui = GUICreate("Créer Caracteres", 60, 80)
GUISetBkColor(0x000000)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")
CreerPanneau("", 5, 5, 1)
GUISetState()
While(True)
For $j = 0 To 8
For $i = 0 To 6
Do
Sleep(10)
Until(_IsPressed("60") Or _IsPressed("61") Or _IsPressed("DE"))
If(_IsPressed("DE")) Then
Exit
ElseIf(_IsPressed("60")) Then
$Couleur = 0
Else
$Couleur = 1
EndIf
Do
Sleep(10)
Until(Not(_IsPressed("60") Or _IsPressed("61") Or _IsPressed("DE")))
If($Couleur = 0) Then
GUICtrlSetBkColor($Cases[$j][$i], 0x001000)
Else
GUICtrlSetBkColor($Cases[$j][$i], 0x008000)
EndIf
$Casess[$j][$i] = $Couleur
Next
Next
If(MsgBox(4, "Résultat", "Satisfait ?") = 6) Then
$file = FileOpen("Test.txt", 1)
FileWrite($file, ", """)
For $j = 0 To 8
For $i = 0 To 6
FileWrite($file, $Casess[$j][$i])
Next
Next
FileWrite($file, """")
FileClose($file)
EndIf
For $j = 0 To 8
For $i = 0 To 6
GUICtrlSetBkColor($Cases[$j][$i], 0xFF0000)
Next
Next
WEnd
Func quit()
Exit
EndFunc
Func CreerPanneau($Texte, $X, $Y, $NbCaracteresX)
For $j = 0 To 8
For $i = 0 To ($NbCaracteresX*7)-1
$Cases[$j][$i] = GUICtrlCreateLabel("", $X+$i*7, $Y+$j*7, 5, 5)
GUICtrlSetBkColor(-1, 0xFF0000)
Next
Next
EndFunc