Symphony Of Empires
progress_bar.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/progress_bar.cpp
20
//
21
// Abstract:
22
// Does some important stuff.
23
// ----------------------------------------------------------------------------
24
25
#include "eng3d/ui/progress_bar.hpp"
26
#include "eng3d/ui/widget.hpp"
27
#include "eng3d/ui/input.hpp"
28
#include "eng3d/ui/ui.hpp"
29
#include "eng3d/texture.hpp"
30
#include "eng3d/rectangle.hpp"
31
#include "eng3d/state.hpp"
32
#include "eng3d/primitive.hpp"
33
34
using namespace
UI
;
35
36
ProgressBar::ProgressBar
(
int
_x,
int
_y,
unsigned
w,
unsigned
h,
const
float
_min,
const
float
_max,
Widget
* _parent)
37
:
Widget
(_parent, _x, _y, w, h,
UI
::
WidgetType
::
PROGRESS_BAR
),
38
min{ _min },
39
max{ _max }
40
{
41
42
}
43
44
void
ProgressBar::on_render
(
Context
&,
Eng3D::Rect
viewport) {
46
g_ui_context
->
obj_shader
->set_texture(0,
"diffuse_map"
, *
g_ui_context
->
button
);
47
g_ui_context
->
obj_shader
->set_uniform(
"diffuse_color"
, glm::vec4(1.f, 1.f, 1.f, 1.f));
48
Eng3D::Square
(0, 0,
width
,
height
).
draw
();
49
auto
ratio = (value == 0 ||
max
== 0) ? 0.f : value /
max
;
50
Eng3D::Rect
pos_rect(0, 0,
width
,
height
);
51
switch
(
direction
) {
52
case
UI::Direction::LEFT_TO_RIGHT
:
53
pos_rect.
right
=
width
* ratio;
54
break
;
55
case
UI::Direction::RIGHT_TO_LEFT
:
56
pos_rect.
left
=
width
* (1.f - ratio);
57
break
;
58
case
UI::Direction::TOP_TO_BOTTOM
:
59
pos_rect.
bottom
=
height
* ratio;
60
break
;
61
case
UI::Direction::BOTTOM_TO_TOP
:
62
pos_rect.
top
=
height
* (1.f - ratio);
63
break
;
64
}
65
66
g_ui_context
->
obj_shader
->set_texture(0,
"diffuse_map"
, *
g_ui_context
->
window_top
);
67
g_ui_context
->
obj_shader
->set_uniform(
"diffuse_color"
, glm::vec4(1.f, 1.f, 1.f, 1.f));
68
Eng3D::Square
(pos_rect.
left
, pos_rect.
top
, pos_rect.
right
, pos_rect.
bottom
).
draw
();
69
70
if
(
text_texture
.get() !=
nullptr
) {
71
g_ui_context
->
obj_shader
->set_uniform(
"diffuse_color"
, glm::vec4(
text_color
.
r
,
text_color
.
g
,
text_color
.
b
,
text_color
.
a
));
72
draw_rectangle
(4, 2,
text_texture
->width,
text_texture
->height, viewport,
text_texture
.get());
73
}
74
}
UI::Context
The UI context that handles all the ui widgets.
Definition:
ui.hpp:63
UI::Context::button
std::shared_ptr< Eng3D::Texture > button
Definition:
ui.hpp:150
UI::Context::obj_shader
std::unique_ptr< Eng3D::OpenGL::Program > obj_shader
Definition:
ui.hpp:159
UI::Context::window_top
std::shared_ptr< Eng3D::Texture > window_top
Definition:
ui.hpp:149
UI::ProgressBar::max
float max
Definition:
progress_bar.hpp:60
UI::ProgressBar::on_render
virtual void on_render(UI::Context &ctx, Eng3D::Rect viewport) override
Definition:
progress_bar.cpp:44
UI::ProgressBar::ProgressBar
ProgressBar(int x, int y, unsigned w, unsigned h, float min, float max, Widget *_parent=nullptr)
Definition:
progress_bar.cpp:36
UI::ProgressBar::direction
UI::Direction direction
Definition:
progress_bar.hpp:61
UI::Widget
The master widget all the other widgets inherit from, do not use directly instead use one of the many...
Definition:
widget.hpp:176
UI::Widget::draw_rectangle
void draw_rectangle(int x, int y, unsigned w, unsigned h, Eng3D::Rect viewport, const Eng3D::Texture *tex)
Definition:
widget.cpp:221
UI::Widget::text_texture
std::shared_ptr< Eng3D::Texture > text_texture
Definition:
widget.hpp:328
UI::Widget::width
size_t width
Definition:
widget.hpp:325
UI::Widget::text_color
Eng3D::Color text_color
Definition:
widget.hpp:332
UI::Widget::height
size_t height
Definition:
widget.hpp:325
UI::WidgetType
WidgetType
The type of the widget, some widgets share types between them to keep simplicity.
Definition:
widget.hpp:76
UI::WidgetType::PROGRESS_BAR
@ PROGRESS_BAR
UI::Direction::RIGHT_TO_LEFT
@ RIGHT_TO_LEFT
UI::Direction::LEFT_TO_RIGHT
@ LEFT_TO_RIGHT
UI::Direction::BOTTOM_TO_TOP
@ BOTTOM_TO_TOP
UI::Direction::TOP_TO_BOTTOM
@ TOP_TO_BOTTOM
UI
Definition:
game_state.hpp:117
UI::g_ui_context
Context * g_ui_context
Definition:
ui.cpp:63
Eng3D::Color::g
float g
Definition:
color.hpp:33
Eng3D::Color::b
float b
Definition:
color.hpp:33
Eng3D::Color::r
float r
Definition:
color.hpp:33
Eng3D::Color::a
float a
Definition:
color.hpp:34
Eng3D::MeshStatic::draw
void draw(int instances=0) const
Definition:
mesh.hpp:205
Eng3D::Rectangle
Definition:
rectangle.hpp:31
Eng3D::Rectangle::right
float right
Definition:
rectangle.hpp:32
Eng3D::Rectangle::bottom
float bottom
Definition:
rectangle.hpp:32
Eng3D::Rectangle::left
float left
Definition:
rectangle.hpp:32
Eng3D::Rectangle::top
float top
Definition:
rectangle.hpp:32
Eng3D::Square
Definition:
primitive.hpp:50
eng3d
src
ui
progress_bar.cpp
Generated by
1.9.1