Symphony Of Empires
label.cpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
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 <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // eng3d/ui/label.cpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #include <cstdlib>
26 #include <cstring>
27 #include <string>
28 #include <algorithm>
29 
30 #include <glm/vec2.hpp>
31 
32 #include "eng3d/ui/widget.hpp"
33 #include "eng3d/ui/label.hpp"
34 #include "eng3d/ui/ui.hpp"
35 #include "eng3d/texture.hpp"
36 #include "eng3d/rectangle.hpp"
37 #include "eng3d/state.hpp"
38 
39 using namespace UI;
40 
41 UI::Label::Label(int _x, int _y, const std::string& _text, Widget* _parent)
42  : Widget(_parent, _x, _y, 0, 0, UI::WidgetType::LABEL)
43 {
44  this->text_color = this->parent->text_color;
45  this->set_text(_text);
46 }
47 
49 
50 }
51 
52 void UI::Label::set_text(const std::string& _text) {
53  UI::Widget::set_text(_text);
54  if(this->text_texture.get() != nullptr) {
55  this->text_offset_x = this->text_offset_y = 0;
56  this->width = this->text_texture->width;
57  this->height = this->text_texture->height;
58  }
59 }
virtual ~Label()
Definition: label.cpp:48
virtual void set_text(const std::string &_text)
Generates text for the widget and overrides the current text texture.
Definition: label.cpp:52
Label(int x, int y, const std::string &text=" ", Widget *parent=nullptr)
Definition: label.cpp:41
The master widget all the other widgets inherit from, do not use directly instead use one of the many...
Definition: widget.hpp:176
Eng3D::Color text_color
Definition: widget.hpp:332
virtual void set_text(const std::string &text)
Generates text for the widget and overrides the current text texture.
Definition: widget.cpp:445
UI::Widget * parent
Definition: widget.hpp:314
WidgetType
The type of the widget, some widgets share types between them to keep simplicity.
Definition: widget.hpp:76