forked from Lasercake/Lasercake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl_qt_usage.cpp
69 lines (60 loc) · 2.69 KB
/
gl_qt_usage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Copyright Eli Dupree and Isaac Dupree, 2011, 2012, 2013
This file is part of Lasercake.
Lasercake is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Lasercake is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Lasercake. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gl_rendering.hpp"
#if LASERCAKE_USE_QT
#include "main.hpp"
#endif
#include "gl_data_format.hpp"
// Hopefully someday this file will be unnecessary.
void gl_renderer::render_2d_text_overlay_(
abstract_gl_data const& abstract_gl_data,
viewport_dimension viewport_width,
viewport_dimension viewport_height,
LasercakeGLWidget& gl_widget
) {
#if LASERCAKE_USE_QT
gl_data_format::gl_all_data const& gl_data = abstract_gl_data.data();
QPainter painter(&gl_widget);
painter.setRenderHint(QPainter::Antialiasing);
const QString text = QString::fromUtf8(gl_data.hud_text.text.c_str());
painter.setOpacity(gl_data.hud_text.c.a / 255.0);
painter.setFont(QFont(gl_data.hud_text.font_name.c_str(), gl_data.hud_text.point_size));
painter.setPen(QColor(gl_data.hud_text.c.r/2, gl_data.hud_text.c.g/2, gl_data.hud_text.c.b/2));
painter.drawText(
gl_data.hud_text.horizontal_margin_in_pixels,
gl_data.hud_text.vertical_margin_in_pixels+1,
viewport_width - 2*gl_data.hud_text.horizontal_margin_in_pixels,
viewport_height - 2*gl_data.hud_text.vertical_margin_in_pixels,
Qt::AlignBottom | Qt::AlignHCenter | Qt::TextWordWrap,
text);
painter.setPen(QColor(0, 0, 0));
painter.drawText(
gl_data.hud_text.horizontal_margin_in_pixels+1,
gl_data.hud_text.vertical_margin_in_pixels+1,
viewport_width - 2*gl_data.hud_text.horizontal_margin_in_pixels,
viewport_height - 2*gl_data.hud_text.vertical_margin_in_pixels,
Qt::AlignBottom | Qt::AlignHCenter | Qt::TextWordWrap,
text);
painter.setPen(QColor(gl_data.hud_text.c.r, gl_data.hud_text.c.g, gl_data.hud_text.c.b));
painter.drawText(
gl_data.hud_text.horizontal_margin_in_pixels,
gl_data.hud_text.vertical_margin_in_pixels,
viewport_width - 2*gl_data.hud_text.horizontal_margin_in_pixels,
viewport_height - 2*gl_data.hud_text.vertical_margin_in_pixels,
Qt::AlignBottom | Qt::AlignHCenter | Qt::TextWordWrap,
text);
painter.end();
#endif
}