From 9e19e97b4fb3d194c22c3c41f690a0fa76d18c40 Mon Sep 17 00:00:00 2001
From: Silas Dohm <silas@sdohm.xyz>
Date: Mon, 13 Sep 2021 03:18:41 +0200
Subject: [PATCH] label can be turned on and off

---
 include/turtlesim/turtle.h |  3 ++-
 src/turtle.cpp             | 14 ++++++++------
 src/turtle_frame.cpp       |  6 +++---
 srv/SetLabel.srv           |  3 ++-
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/include/turtlesim/turtle.h b/include/turtlesim/turtle.h
index ad37123..901639c 100644
--- a/include/turtlesim/turtle.h
+++ b/include/turtlesim/turtle.h
@@ -97,7 +97,8 @@ private:
   ros::WallTime last_command_time_;
 
   float meter_;
-  QString label = "0";
+  bool label_on_ = false;
+  QString label_ = "";
 
   struct TeleportRequest
   {
diff --git a/src/turtle.cpp b/src/turtle.cpp
index bb128e8..e33ad7e 100644
--- a/src/turtle.cpp
+++ b/src/turtle.cpp
@@ -92,7 +92,8 @@ bool Turtle::setPenCallback(turtlesim::SetPen::Request& req, turtlesim::SetPen::
 }
 
 bool Turtle::setLabelCallback(turtlesim_xl::SetLabel::Request& req, turtlesim_xl::SetLabel::Response&){
-  Turtle::label = QString(req.name.c_str());
+  Turtle::label_ = QString(req.name.c_str());
+  label_on_ = req.on;
   return true;
 }
 bool Turtle::teleportRelativeCallback(turtlesim::TeleportRelative::Request& req, turtlesim::TeleportRelative::Response&)
@@ -220,14 +221,15 @@ bool Turtle::update(double dt, QPainter& path_painter, const QImage& path_image,
 void Turtle::paint(QPainter& painter)
 {
   QPointF p = pos_ * meter_;
-  QPointF pl = pos_ * meter_;
-  pl.rx() -= 0.3 * turtle_rotated_image_.width();
-  //pl.ry() -= 0.5 * turtle_rotated_image_.height();
   p.rx() -= 0.5 * turtle_rotated_image_.width();
   p.ry() -= 0.5 * turtle_rotated_image_.height();
   painter.drawImage(p, turtle_rotated_image_);
-  painter.setPen(Qt::red);
-  painter.drawText(pl,Turtle::label);
+  if(label_on_){
+    QPointF pl = pos_ * meter_;
+    pl.rx() -= 0.3 * turtle_rotated_image_.width();
+    painter.setPen(Qt::red);
+    painter.drawText(pl,Turtle::label_);
+  }
 }
 
 }
diff --git a/src/turtle_frame.cpp b/src/turtle_frame.cpp
index 55cff29..c0395b1 100644
--- a/src/turtle_frame.cpp
+++ b/src/turtle_frame.cpp
@@ -35,9 +35,9 @@
 #include <cstdlib>
 #include <ctime>
 
-#define DEFAULT_BG_R 0x2a
-#define DEFAULT_BG_G 0x2a
-#define DEFAULT_BG_B 0x2e
+#define DEFAULT_BG_R 0x00
+#define DEFAULT_BG_G 0x00
+#define DEFAULT_BG_B 0x00
 #define FRAME_WIDTH 1200
 #define FRAME_HEIGHT 800
 
diff --git a/srv/SetLabel.srv b/srv/SetLabel.srv
index ac4c27d..772f305 100644
--- a/srv/SetLabel.srv
+++ b/srv/SetLabel.srv
@@ -1 +1,2 @@
-string name
\ No newline at end of file
+string name
+uint8 on
\ No newline at end of file
-- 
GitLab