From 216410f8856675c12b88febb6822d8403fd23b4a Mon Sep 17 00:00:00 2001
From: Lucas Philippe <lucasphilippe@MacBook-Air-de-Lucas.local>
Date: Thu, 4 Apr 2024 12:17:48 +0200
Subject: [PATCH] ajout etape 6

---
 TP5/sketch_240321a/City.pde           | 15 +++++++++++++++
 TP5/sketch_240321a/ColorPalette.pde   |  5 +++++
 TP5/sketch_240321a/sketch_240321a.pde |  4 ++--
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/TP5/sketch_240321a/City.pde b/TP5/sketch_240321a/City.pde
index 287e73e..1aabf0e 100644
--- a/TP5/sketch_240321a/City.pde
+++ b/TP5/sketch_240321a/City.pde
@@ -35,6 +35,21 @@ class City {
     }
     fill(hue, 100, 100, alpha);
     ellipse(x, y, radius, radius);
+    
+    // Draw city name
+    if (isHighlighted) {
+      textSize(16);
+      textAlign(LEFT, CENTER);
+      float textWidth = textWidth(name);
+      float rectWidth = textWidth + 10;
+      float rectHeight = 20;
+      fill(255);
+      rect(x + radius/2 + 5, y - rectHeight/2, rectWidth, rectHeight, 5);
+      fill(0);
+      text(name, x + radius/2 + 10, y - 2);
+      setBasePen();
+  }
+
 }
 
     boolean contains(int px, int py){
diff --git a/TP5/sketch_240321a/ColorPalette.pde b/TP5/sketch_240321a/ColorPalette.pde
index 0db5541..b66f0df 100644
--- a/TP5/sketch_240321a/ColorPalette.pde
+++ b/TP5/sketch_240321a/ColorPalette.pde
@@ -1,3 +1,8 @@
 float getColorForAltitude(float altitude) {
     return map(altitude, 0, 100, 230, -50);
 }
+
+void setBasePen() {
+    fill(0);
+    textSize(12);
+}
diff --git a/TP5/sketch_240321a/sketch_240321a.pde b/TP5/sketch_240321a/sketch_240321a.pde
index ea8a991..806fc4f 100644
--- a/TP5/sketch_240321a/sketch_240321a.pde
+++ b/TP5/sketch_240321a/sketch_240321a.pde
@@ -32,7 +32,7 @@ void draw(){
   textSize(20);
   textAlign(CENTER,CENTER);
   text("Afficher les populations supérieures à " + minPopulationToDisplay, width/2, 20);
-  textSize(12);
+  setBasePen();
   
   for (int i = 0 ; i < totalCount; ++i) {
     // draw a point at the coordinates of the city
@@ -153,7 +153,7 @@ void mouseMoved() {
         lastCitySelected.isHighlighted = false;
       }
       lastCitySelected = city;
-      println(city.name);
+      //println(city.name);
       lastCitySelected.isHighlighted = true;
       redraw();
     }
-- 
GitLab