summaryrefslogtreecommitdiff
path: root/canevas.cpp
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2023-01-13 02:34:01 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2023-01-13 02:34:01 -0500
commit3fb8effa3603e9a9b96d263009fc1397433436ba (patch)
treeae4d7bf573f69245713b07c253a8027ace8d5244 /canevas.cpp
parentb4f16386c70bfeab700e7cc129f2f04295aa0059 (diff)
Tout sauf les tests
Diffstat (limited to 'canevas.cpp')
-rw-r--r--canevas.cpp76
1 files changed, 62 insertions, 14 deletions
diff --git a/canevas.cpp b/canevas.cpp
index bc7a0e5..1010ea6 100644
--- a/canevas.cpp
+++ b/canevas.cpp
@@ -9,38 +9,86 @@
#include "canevas.h"
Canevas::Canevas() {
+ Couche couches[MAX_COUCHES];
+ for (int i = 0; i < MAX_COUCHES; i++) {
+ couches[i] = Couche();
+ };
+ couches[0].changerEtat(STATE_ACTIVE);
}
Canevas::~Canevas() {
+ reinitialiser();
}
bool Canevas::reinitialiser() {
- return true;
+ for (int i = 0; i < MAX_COUCHES; i++) {
+ if (!couches[i].reinitialiser()) {
+ return false;
+ }
+ }
+ return true;
}
bool Canevas::activerCouche(int index) {
- return true;
-}
+ if (index < 0 || index >= MAX_COUCHES)
+ return false;
+ for (int i = 0; i < MAX_COUCHES; i++) {
+ if (couches[i].getEtat() == STATE_ACTIVE) {
+ couches[i].changerEtat(STATE_INACTIVE);
+ };
+ };
+ return couches[index].changerEtat(STATE_ACTIVE);
+};
bool Canevas::cacherCouche(int index) {
- return true;
-}
+ if (index < 0 || index >= MAX_COUCHES)
+ return false;
+ couches[index].changerEtat(STATE_INACTIVE);
+ return true;
+};
bool Canevas::ajouterForme(Forme *p_forme) {
- return true;
-}
+ int active = -1;
+ for (int i = 0; i < MAX_COUCHES; i++)
+ active = (couches[i].getEtat() == STATE_ACTIVE) ? i : active;
+ if (active == -1)
+ return false;
+ return couches[active].ajouterForme(p_forme);
+};
bool Canevas::retirerForme(int index) {
- return true;
-}
+ int active = -1;
+ for (int i = 0; i < MAX_COUCHES; i++)
+ active = (couches[i].getEtat() == STATE_ACTIVE) ? i : active;
+ if (active == -1)
+ return false;
+ if (couches[active].supprimerForme(index)==NULL)
+ return false;
+ return true;
+};
double Canevas::aire() {
- return 0.0;
-}
+ double aire = 0;
+ for (int i = 0; i < MAX_COUCHES; i++) {
+ if (couches[i].getEtat() == STATE_ACTIVE) {
+ aire += couches[i].aire();
+ };
+ };
+ return aire;
+};
bool Canevas::translater(int deltaX, int deltaY) {
- return true;
-}
+ int active = -1;
+ for (int i = 0; i < MAX_COUCHES; i++)
+ active = (couches[i].getEtat() == STATE_ACTIVE) ? i : active;
+ if (active == -1)
+ return false;
+ return couches[active].translater(deltaX, deltaY);
+};
void Canevas::afficher(ostream & s) {
-}
+ for (int i = 0; i < MAX_COUCHES; i++) {
+ s << "----- Couche " << i << "\n";
+ couches[i].afficher(s);
+ };
+};