38 #include <OGRE/OgreMaterialManager.h>
39 #include <OGRE/OgreTextureManager.h>
40 #include <OGRE/OgreTexture.h>
41 #include <OGRE/OgreHardwarePixelBuffer.h>
42 #include <OGRE/OgreTechnique.h>
60 ros::message_traits::datatype<jsk_rviz_plugins::OverlayMenu>(),
61 "jsk_rviz_plugins::OverlayMenu topic to subscribe to.",
64 "left of the image window",
68 "top of the image window",
72 "enable automatic center adjustment",
73 this, SLOT(updateKeepCentered()));
77 "Overtake FG Color Properties",
true,
78 "overtake color properties specified by message such as foreground color and alpha",
79 this, SLOT(updateOvertakeFGColorProperties()));
81 "Overtake BG Color Properties",
true,
82 "overtake color properties specified by message such as background color and alpha",
83 this, SLOT(updateOvertakeBGColorProperties()));
86 "Foreground Color", QColor(25, 255, 240),
88 this, SLOT(updateFGColor()));
90 "Foreground Alpha", 1.0,
"Foreground Alpha",
91 this, SLOT(updateFGAlpha()));
92 fg_alpha_property_->setMin(0.0);
93 fg_alpha_property_->setMax(1.0);
96 "Background Color", QColor(0, 0, 0),
98 this, SLOT(updateBGColor()));
100 "Background Alpha", 0.5,
"Background Alpha",
101 this, SLOT(updateBGAlpha()));
102 bg_alpha_property_->setMin(0.0);
103 bg_alpha_property_->setMax(1.0);
160 if (topic_name.length() > 0 && topic_name !=
"/") {
168 (
const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg)
171 if (!overtake_bg_color_properties_)
172 bg_color_ = QColor(
msg->bg_color.r * 255.0,
173 msg->bg_color.g * 255.0,
174 msg->bg_color.b * 255.0,
175 msg->bg_color.a * 255.0);
176 if (!overtake_fg_color_properties_)
177 fg_color_ = QColor(
msg->fg_color.r * 255.0,
178 msg->fg_color.g * 255.0,
179 msg->fg_color.b * 255.0,
180 msg->fg_color.a * 255.0);
186 ROS_DEBUG(
"need to resize because this is the first time to draw");
192 ROS_DEBUG(
"no need to resize because the plugin tries to draw without message reception");
197 ROS_DEBUG(
"no need to resize, this is unexpected case. please debug");
202 ROS_DEBUG(
"need to resize because the length of menu is different");
212 ROS_DEBUG(
"need to resize because the content of menu is different");
216 ROS_DEBUG(
"no need to resize because the content of menu is same");
225 font.setPointSize(20);
231 QFontMetrics fm(
font());
236 const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg)
240 for (
size_t i = 0; i <
msg->menus.size(); i++) {
246 int w = fm.width(
msg->title.c_str());
255 const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg)
258 return fm.height() * (
msg->menus.size() + 1)
266 ROS_DEBUG(
"next_menu_ is null, no need to update");
269 if (
next_menu_->action == jsk_rviz_plugins::OverlayMenu::ACTION_CLOSE &&
271 ROS_DEBUG(
"request is close and state is closed, we ignore it completely");
275 if (
next_menu_->action == jsk_rviz_plugins::OverlayMenu::ACTION_CLOSE) {
279 ROS_WARN(
"request is CLOSE and state is CLOSED, it should be ignored before...");
349 const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg,
352 if (index >=
msg->menus.size()) {
356 return msg->menus[index];
363 static int count = 0;
365 ss <<
"OverlayMenuDisplayObject" <<
count++;
366 overlay_.reset(
new OverlayObject(ss.str()));
373 ROS_DEBUG(
"no need to update texture size");
385 QColor transparent(0, 0, 0, 0.0);
387 for (
int i = 0; i <
overlay_->getTextureWidth(); i++) {
388 for (
int j = 0; j <
overlay_->getTextureHeight(); j++) {
389 if (i > (
overlay_->getTextureWidth() - current_width) / 2.0 &&
390 i < overlay_->getTextureWidth() - (
overlay_->getTextureWidth() - current_width) / 2.0 &&
391 j > (
overlay_->getTextureHeight() - current_height) / 2.0 &&
392 j < overlay_->getTextureHeight() - (
overlay_->getTextureHeight() - current_height) / 2.0) {
396 Hud.setPixel(i, j, transparent.rgba());
412 QPainter painter( &Hud );
413 painter.setRenderHint(QPainter::Antialiasing,
true);
414 painter.setPen(QPen(
fg_color_, 1, Qt::SolidLine));
415 painter.setFont(
font());
420 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
422 for (
size_t i = 0; i <
next_menu_->menus.size(); i++) {
426 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
434 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
438 int texture_width =
overlay_->getTextureWidth();
439 int texture_height =
overlay_->getTextureHeight();
462 left_ = (window_width - (int)
overlay_->getTextureWidth()) / 2.0;
463 top_ = (window_height - (int)
overlay_->getTextureHeight()) / 2.0;
465 left_ = std::max(0, std::min(window_width - (
int)
overlay_->getTextureWidth(),
left_));
466 top_ = std::max(0, std::min(window_height - (
int)
overlay_->getTextureHeight(),
top_));
581 top_ < y && top_ + overlay_->getTextureHeight() >
y &&
582 left_ < x && left_ + overlay_->getTextureWidth() >
x);