1 //  SuperTux
2 //  Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_INTERFACE_LABEL_HPP
18 #define HEADER_SUPERTUX_INTERFACE_LABEL_HPP
19 
20 #include <SDL.h>
21 
22 #include "editor/widget.hpp"
23 #include "video/drawing_context.hpp"
24 
25 class InterfaceLabel : public Widget
26 {
27 public:
28   InterfaceLabel();
29   InterfaceLabel(const Rectf& rect, std::string label);
~InterfaceLabel()30   ~InterfaceLabel() override {}
31 
32   virtual void draw(DrawingContext& context) override;
33   virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override;
34 
set_rect(const Rectf & rect)35   void set_rect(const Rectf& rect) { m_rect = rect; }
get_rect() const36   Rectf get_rect() const { return m_rect; }
37 
set_label(const std::string & label)38   void set_label(const std::string& label) { m_label = label; }
get_label() const39   std::string get_label() const { return m_label; }
40 
41   bool fits(const std::string& text) const;
42   std::string get_truncated_text() const;
43 
44 protected:
45   /** The rectangle where the InterfaceLabel should be rendered */
46   Rectf m_rect;
47   /** The text of the label */
48   std::string m_label;
49 
50 private:
51   Vector m_mouse_pos;
52 
53 private:
54   InterfaceLabel(const InterfaceLabel&) = delete;
55   InterfaceLabel& operator=(const InterfaceLabel&) = delete;
56 };
57 
58 #endif
59 
60 /* EOF */
61