Skip to content

Commit f60c49b

Browse files
committed
Fix text issues
1 parent 10e41fe commit f60c49b

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/robot_dart/gui/magnum/gs/camera.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,29 @@ namespace robot_dart {
327327
auto viewport = Magnum::Vector2{_camera->viewport()};
328328
auto sc = Magnum::Vector2{viewport.max() / 1024.f};
329329
auto text_scaling = Magnum::Matrix3::scaling(sc);
330-
auto extra_tr = Magnum::Matrix3(Magnum::Math::IdentityInit);
331-
if ((text->alignment & Magnum::Text::Implementation::AlignmentVertical) == Magnum::Text::Implementation::AlignmentLine) // if line (bottom) alignment, push the text a bit above
332-
extra_tr = Magnum::Matrix3::translation({0.f, sc[1] * 0.25f * rectangle.sizeY()});
333330

334331
auto text_tr = Magnum::Matrix3(Magnum::Matrix3d(text->transformation));
335332

336333
if (text->draw_background) {
337-
auto bg_scaling = Magnum::Matrix3::scaling(Magnum::Vector2{viewport[0], rectangle.sizeY() * sc[1]});
334+
auto extra_tr = Magnum::Matrix3(Magnum::Math::IdentityInit);
335+
if ((text->alignment & Magnum::Text::Implementation::AlignmentVertical) == Magnum::Text::Implementation::AlignmentBottom) // if bottom alignment, push the bg a bit above
336+
extra_tr = Magnum::Matrix3::translation({0.f, sc[1] * 0.5f * rectangle.sizeY()});
337+
if ((text->alignment & Magnum::Text::Implementation::AlignmentVertical) == Magnum::Text::Implementation::AlignmentTop) // if top alignment, push the bg a bit down
338+
extra_tr = Magnum::Matrix3::translation({0.f, -sc[1] * 0.5f * rectangle.sizeY()});
339+
340+
auto bg_tr = text_tr * extra_tr; // * Magnum::Matrix3::translation({0.f, rectangle.sizeY() * sc[1] / 2.f});
341+
auto bg_scaling = Magnum::Matrix3::scaling(Magnum::Vector2{viewport[0], rectangle.sizeY() * sc[1] / 2.f});
338342

339343
// draw the background
340344
(*debug_data.background_shader)
341-
.setTransformationProjectionMatrix(Magnum::Matrix3::projection(viewport) * text_tr * bg_scaling)
345+
.setTransformationProjectionMatrix(Magnum::Matrix3::projection(viewport) * bg_tr * bg_scaling)
342346
.setColor(Magnum::Vector4(Magnum::Vector4d(text->background_color)))
343347
.draw(*debug_data.background_mesh);
344348
}
345349

346350
(*debug_data.text_shader)
347351
.bindVectorTexture(debug_data.cache->texture())
348-
.setTransformationProjectionMatrix(Magnum::Matrix3::projection(viewport) * text_tr * extra_tr * text_scaling)
349-
// .setTransformationProjectionMatrix(Magnum::Matrix3::projection(Magnum::Vector2{_camera->viewport()}) * Magnum::Matrix3::translation(Magnum::Vector2{-text_renderer->rectangle().sizeX() / 2.f, -text_renderer->rectangle().sizeY() / 2.f}) * Magnum::Matrix3(Magnum::Matrix3d(text.transformation)))
352+
.setTransformationProjectionMatrix(Magnum::Matrix3::projection(viewport) * text_tr * text_scaling)
350353
.setColor(Magnum::Vector4(Magnum::Vector4d(text->color)))
351354
.setOutlineRange(0.4f, 0.45f)
352355
.setSmoothness(0.075f)

src/robot_dart/gui_data.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace robot_dart {
2121
std::vector<std::shared_ptr<simu::TextData>> text_drawings;
2222

2323
public:
24-
std::shared_ptr<simu::TextData> add_text(const std::string& text, const Eigen::Affine2d& tf = Eigen::Affine2d::Identity(), Eigen::Vector4d color = Eigen::Vector4d(1, 1, 1, 1), std::uint8_t alignment = (1 | 3 << 3), bool draw_bg = false, Eigen::Vector4d bg_color = Eigen::Vector4d(0, 0, 0, 0.75), double font_size = 28)
24+
std::shared_ptr<simu::TextData> add_text(const std::string& text, const Eigen::Affine2d& tf = Eigen::Affine2d::Identity(), Eigen::Vector4d color = Eigen::Vector4d(1, 1, 1, 1), std::uint8_t alignment = 2 << 2, bool draw_bg = false, Eigen::Vector4d bg_color = Eigen::Vector4d(0, 0, 0, 0.75), double font_size = 28)
2525
{
2626
text_drawings.emplace_back(new TextData{text, tf, color, alignment, draw_bg, bg_color, font_size});
2727

src/robot_dart/robot_dart_simu.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ namespace robot_dart {
141141
if (_text_panel) { // Need to re-transform as the size of the window might have changed
142142
Eigen::Affine2d tf = Eigen::Affine2d::Identity();
143143
tf.translate(Eigen::Vector2d(-static_cast<double>(_graphics->width()) / 2., _graphics->height() / 2.));
144+
// tf.translate(Eigen::Vector2d(-static_cast<double>(_graphics->width()) / 2., 0.));
144145
_text_panel->transformation = tf;
145146
}
146147
if (_status_bar) {
147148
_status_bar->text = status_bar_text(); // this is dynamic text (timings)
148149
Eigen::Affine2d tf = Eigen::Affine2d::Identity();
149150
tf.translate(Eigen::Vector2d(-static_cast<double>(_graphics->width()) / 2., -static_cast<double>(_graphics->height() / 2.)));
151+
// tf.translate(Eigen::Vector2d(-static_cast<double>(_graphics->width()) / 2., 0.));
150152
_status_bar->transformation = tf;
151153
}
152154

@@ -385,13 +387,21 @@ namespace robot_dart {
385387

386388
simu::GUIData* RobotDARTSimu::gui_data() { return &(*_gui_data); }
387389

388-
void RobotDARTSimu::enable_text_panel(bool enable, double font_size) { _enable(_text_panel, enable, font_size); }
390+
void RobotDARTSimu::enable_text_panel(bool enable, double font_size)
391+
{
392+
_enable(_text_panel, enable, font_size);
393+
if (enable) {
394+
_text_panel->alignment = 3 << 2; // alignment of status bar should be LineTop; TO-DO: Check how to get types automatically from Magnum?
395+
// _text_panel->draw_background = true; // we want to draw a background
396+
// _text_panel->background_color = Eigen::Vector4d(0, 0, 0, 0.75); // black-transparent bar
397+
}
398+
}
389399

390400
void RobotDARTSimu::enable_status_bar(bool enable, double font_size)
391401
{
392402
_enable(_status_bar, enable, font_size);
393403
if (enable) {
394-
_status_bar->alignment = (1 | 1 << 3); // alignment of status bar should be LineLeft
404+
_status_bar->alignment = 1 << 2; // alignment of status bar should be LineBottom; TO-DO: Check how to get types automatically from Magnum?
395405
_status_bar->draw_background = true; // we want to draw a background
396406
_status_bar->background_color = Eigen::Vector4d(0, 0, 0, 0.75); // black-transparent bar
397407
}
@@ -400,7 +410,7 @@ namespace robot_dart {
400410
void RobotDARTSimu::_enable(std::shared_ptr<simu::TextData>& text, bool enable, double font_size)
401411
{
402412
if (!text && enable) {
403-
text = _gui_data->add_text("");
413+
text = add_text("");
404414
}
405415
else if (!enable) {
406416
if (text)

src/robot_dart/robot_dart_simu.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace robot_dart {
109109
void enable_status_bar(bool enable = true, double font_size = -1);
110110
std::string status_bar_text() const;
111111

112-
std::shared_ptr<simu::TextData> add_text(const std::string& text, const Eigen::Affine2d& tf = Eigen::Affine2d::Identity(), Eigen::Vector4d color = Eigen::Vector4d(1, 1, 1, 1), std::uint8_t alignment = (1 | 3 << 3), bool draw_bg = false, Eigen::Vector4d bg_color = Eigen::Vector4d(0, 0, 0, 0.75), double font_size = 28);
112+
std::shared_ptr<simu::TextData> add_text(const std::string& text, const Eigen::Affine2d& tf = Eigen::Affine2d::Identity(), Eigen::Vector4d color = Eigen::Vector4d(1, 1, 1, 1), std::uint8_t alignment = 2 << 2, bool draw_bg = false, Eigen::Vector4d bg_color = Eigen::Vector4d(0, 0, 0, 0.75), double font_size = 28);
113113

114114
std::shared_ptr<Robot> add_floor(double floor_width = 10.0, double floor_height = 0.1, const Eigen::Isometry3d& tf = Eigen::Isometry3d::Identity(), const std::string& floor_name = "floor");
115115
std::shared_ptr<Robot> add_checkerboard_floor(double floor_width = 10.0, double floor_height = 0.1, double size = 1., const Eigen::Isometry3d& tf = Eigen::Isometry3d::Identity(), const std::string& floor_name = "checkerboard_floor", const Eigen::Vector4d& first_color = dart::Color::White(1.), const Eigen::Vector4d& second_color = dart::Color::Gray(1.));

0 commit comments

Comments
 (0)