Voici une petite fonction assez pratique ... qui permet de créer un menu simple.
Il gère:
- jusqu'à 8 boutons consécutifs,
- l'affichage de la sélection du bouton(changement de couleur au passage de la souris)
- peut être modifié pour être adapté selon les besion (rajouter quand on clique, la modification d'une variable)
Voici le code de la fonction (pour Set display mode 800,600,16)
Function menu2(texte1$,texte2$,texte3$,texte4$,texte5$,texte6$,texte7$,texte8$)
Rem Fond
Ink rgb(224,226,235),0 : Box 0,0,800,20
Rem Sélection
Ink rgb(187,183,199),0
Rem on détermine la taille que prendra le mot [grâce à len("texte")]
t1=(len(texte1$)+2)*6 : t2=(len(texte2$)+2)*6 : t3=(len(texte3$)+2)*6 : t4=(len(texte4$)+2)*6
t5=(len(texte5$)+2)*6 : t6=(len(texte6$)+2)*6 : t7=(len(texte7$)+2)*6 : t8=(len(texte8$)+2)*6
Rem distance
d1=t1 : d2=d1+t2 : d3=d2+t3 : d4=d3+t4 : d5=d4+t5
d6=d5+t6 : d7=d6+t7 : d8=d7+t8
Rem Selon la position de la souris
If mousey()<20
If mousex()<d1 Then Box 0,0,d1,20
If mousex()>d1 and mousex()<d2 Then Box d1,0,d2,20
If mousex()>d2 and mousex()<d3 Then Box d2,0,d3,20
If mousex()>d3 and mousex()<d4 Then Box d3,0,d4,20
If mousex()>d4 and mousex()<d5 Then Box d4,0,d5,20
If mousex()>d5 and mousex()<d6 Then Box d5,0,d6,20
If mousex()>d6 and mousex()<d7 Then Box d6,0,d7,20
If mousex()>d7 and mousex()<d8 Then Box d7,0,d8,20
EndIf
Rem Affiche le texte
Ink 0,0 : Set text size 14
Center text t1/2,3,texte1$
Center text d1+t2/2,3,texte2$
Center text d2+t3/2,3,texte3$
Center text d3+t4/2,3,texte4$
Center text d4+t5/2,3,texte5$
Center text d5+t6/2,3,texte6$
Center text d6+t7/2,3,texte7$
Center text d7+t8/2,3,texte8$
EndFunction
Voici un exemple où la fonction est en application:
rem ***** Menu simple *****
rem ***** par Sprite *****
rem ***** fonction *****
Rem Affichage
Set display mode 800,600,16
Rem Boucle
DO : Sync
Rem Appeller la fonction
menu2("Fichier","Edition","Recherche","Vue","Compilation","Outils","Fenêtre","Aide")
LOOP
REM FONCTION
Rem le nombre de texte n'est limité que par la taille, ici limité à 8, mais peut être augmenté
Function menu2(texte1$,texte2$,texte3$,texte4$,texte5$,texte6$,texte7$,texte8$)
Rem Fond
Ink rgb(224,226,235),0 : Box 0,0,800,20
Rem Sélection
Ink rgb(187,183,199),0
Rem on détermine la taille que prendra le mot [grâce à len("texte")]
t1=(len(texte1$)+2)*6 : t2=(len(texte2$)+2)*6 : t3=(len(texte3$)+2)*6 : t4=(len(texte4$)+2)*6
t5=(len(texte5$)+2)*6 : t6=(len(texte6$)+2)*6 : t7=(len(texte7$)+2)*6 : t8=(len(texte8$)+2)*6
Rem distance
d1=t1 : d2=d1+t2 : d3=d2+t3 : d4=d3+t4 : d5=d4+t5
d6=d5+t6 : d7=d6+t7 : d8=d7+t8
Rem Selon la position de la souris
If mousey()<20
If mousex()<d1 Then Box 0,0,d1,20
If mousex()>d1 and mousex()<d2 Then Box d1,0,d2,20
If mousex()>d2 and mousex()<d3 Then Box d2,0,d3,20
If mousex()>d3 and mousex()<d4 Then Box d3,0,d4,20
If mousex()>d4 and mousex()<d5 Then Box d4,0,d5,20
If mousex()>d5 and mousex()<d6 Then Box d5,0,d6,20
If mousex()>d6 and mousex()<d7 Then Box d6,0,d7,20
If mousex()>d7 and mousex()<d8 Then Box d7,0,d8,20
EndIf
Rem Affiche le texte
Ink 0,0 : Set text size 14
Center text t1/2,3,texte1$
Center text d1+t2/2,3,texte2$
Center text d2+t3/2,3,texte3$
Center text d3+t4/2,3,texte4$
Center text d4+t5/2,3,texte5$
Center text d5+t6/2,3,texte6$
Center text d6+t7/2,3,texte7$
Center text d7+t8/2,3,texte8$
EndFunction
Et voici le résultat (avec le bouton fichier sélectionné):