-
Notifications
You must be signed in to change notification settings - Fork 0
/
bouton.cpp
85 lines (76 loc) · 1.6 KB
/
bouton.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
77
78
79
80
81
82
83
84
85
#include "bouton.h"
#include "rect.h"
#include <iostream>
#include <string.h>
#include <allegro.h>
using namespace std;
bouton::bouton():rectangle(),ch()
{
nb=0;
xch=x;
ych=y;
}
bouton::bouton(float px, float py, char* pch):rectangle(),ch(pch)
{
float lch, hch;
x=px;
y=py;
nb=strlen(pch);
lch=text_length(font,pch); // instruction allegro
hch=text_height(font); // instruction allegro
xch=x-lch/2;
ych=y-hch/2;
l=lch+20;
h=hch+10;
}
bouton::~bouton()
{}
bouton::bouton(const bouton& s):rectangle(s)
{
ch=s.ch;
nb=s.nb;
xch=s.xch;
ych=s.ych;
}
bouton& bouton::operator=(const bouton& s)
{
if(this!=&s) //compare les adresses
{
rectangle *mg;
const rectangle *md; //cast dynamique, force l'appel a la classe mere
mg = this;
md = &s;
(*mg) = (*md);
}
ch=s.ch;
nb=s.nb;
xch=s.xch;
ych=s.ych;
return (*this);
}
void bouton::affiche()
{
rectangle::affiche();
//instruction graphique d'affichage de texte au point xch, ych
cout << "ch = " << ch << endl;
textprintf_ex(page, font, xch, ych, makecol(255,213,0), -1, "%s", ch.c_str());
}
void bouton::init(char * tab)
{
float lch, hch;
ch.append(tab); //ch=tab;
nb=strlen(tab);
lch=text_length(font,tab); // instruction allegro
hch=text_height(font);
xch=x-lch/2;
ych=y-hch/2;
}
int bouton::selection()
{
if((mouse_x >= x1) && (mouse_x <= x2) && (mouse_y >= y1) && (mouse_y <= y2))
{
if(mouse_b & 1)
return 1;
}
return 0;
}