-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.cpp
76 lines (70 loc) · 1.38 KB
/
menu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "menu.h"
#include <string.h>
menu::menu(const char* ptab[],int pnb)
{
float pasy,hint,xint,lmax,hmax;
int taillemax,ind;
nb=pnb;
taillemax = text_length(font,ptab[0]);
for(int i=0;i<nb;i++)
{
if(text_length(font,ptab[i])>taillemax)
{
taillemax = text_length(font,ptab[i]);
ind = i;
}
}
lmax = taillemax + 20;
hmax = text_height(font) + 10;
hint = taillemax + 10;
xint = 20 + hint/2;
pasy = (SCREEN_H)/(nb+1);
tab = new bouton*[nb];
for(int i=0;i<nb;i++)
{
tab[i] = new bouton(xint,(i+1)*pasy,ptab[i]);
tab[i]->rectangle::init(lmax, hmax);
}
}
menu::menu(const menu &S)
{
nb=S.nb;
tab=new bouton*[nb];
for(int i=0;i<nb;i++)
tab[i]=new bouton(*(S.tab[i]));
}
menu::~menu()
{
for(int i=0;i<nb;i++)
delete tab[i];
delete tab;
}
void menu::affiche()
{
for(int i=0;i<nb;i++)
tab[i]->affiche();
}
menu& menu::operator=(const menu &S)
{
if(this!=&S)
{
for(int i=0;i<nb;i++)
delete tab[i];
delete tab;
nb=S.nb;
tab=new bouton*[nb];
for(int i=0;i<nb;i++)
tab[i]=new bouton(*(S.tab[i]));
}
return (*this);
}
int menu::selection()
{
int i;
for(i=0;i<nb;i++)
{
if(tab[i]->selection()==1)
return i+1;
}
return 0;
}