supertux
label.hpp
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:
29  InterfaceLabel(const Rectf& rect, std::string label);
30  ~InterfaceLabel() override {}
31 
32  virtual void draw(DrawingContext& context) override;
33  virtual bool on_mouse_motion(const SDL_MouseMotionEvent& motion) override;
34 
35  void set_rect(const Rectf& rect) { m_rect = rect; }
36  Rectf get_rect() const { return m_rect; }
37 
38  void set_label(const std::string& label) { m_label = label; }
39  const 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:
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 */
Definition: label.hpp:25
Definition: rectf.hpp:31
std::string m_label
The text of the label.
Definition: label.hpp:48
Definition: widget.hpp:24
Rectf m_rect
The rectangle where the InterfaceLabel should be rendered.
Definition: label.hpp:46
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42