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",
77 "Overtake FG Color Properties",
true,
78 "overtake color properties specified by message such as foreground color and alpha",
81 "Overtake BG Color Properties",
true,
82 "overtake color properties specified by message such as background color and alpha",
86 "Foreground Color", QColor(25, 255, 240),
90 "Foreground Alpha", 1.0,
"Foreground Alpha",
96 "Background Color", QColor(0, 0, 0),
100 "Background Alpha", 0.5,
"Background Alpha",
160 if (topic_name.length() > 0 && topic_name !=
"/") {
168 (
const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg)
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);
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());
251 return max_width + menu_padding_x * 2;
255 const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg)
258 return fm.height() * (msg->menus.size() + 1)
259 + menu_padding_y * (msg->menus.size() + 1 - 1)
260 + menu_last_padding_y * 2;
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++;
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());
418 painter.drawText(menu_padding_x, menu_padding_y,
420 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
422 for (
size_t i = 0; i <
next_menu_->menus.size(); i++) {
424 painter.drawText(menu_padding_x, line_height * ( 1 + i ) + menu_padding_y + menu_last_padding_y,
426 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
432 line_height * ( 1 +
next_menu_->current_index ) + menu_padding_y + menu_last_padding_y,
434 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
438 int texture_width =
overlay_->getTextureWidth();
439 int texture_height =
overlay_->getTextureHeight();
440 painter.drawLine(menu_padding_x / 2, menu_last_padding_y / 2 + line_height,
441 menu_padding_x / 2, texture_height - menu_last_padding_y / 2);
442 painter.drawLine(texture_width - menu_padding_x / 2, menu_last_padding_y / 2 + line_height,
443 texture_width - menu_padding_x / 2, texture_height - menu_last_padding_y / 2);
444 painter.drawLine(menu_padding_x / 2, menu_last_padding_y / 2 + line_height,
445 texture_width - menu_padding_x / 2, menu_last_padding_y / 2 + line_height);
446 painter.drawLine(menu_padding_x / 2, texture_height - menu_last_padding_y / 2,
447 texture_width - menu_padding_x / 2, texture_height - menu_last_padding_y / 2);
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_));
virtual QColor getColor() const
virtual bool setValue(const QVariant &new_value)
virtual QImage getQImage(unsigned int width, unsigned int height)
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
DisplayContext * context_
virtual ViewManager * getViewManager() const =0
virtual int getInt() const
virtual float getFloat() const
const int menu_last_padding_y
virtual bool getBool() const
const double animate_duration
RenderPanel * getRenderPanel() const
std::string getTopicStd() const