From 3fb8effa3603e9a9b96d263009fc1397433436ba Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Fri, 13 Jan 2023 02:34:01 -0500 Subject: Tout sauf les tests --- canevas.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 14 deletions(-) (limited to 'canevas.cpp') 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); + }; +}; -- cgit v1.2.3