37 #include <OGRE/OgreMaterialManager.h> 39 #include <OGRE/OgreTexture.h> 40 #include <OGRE/OgreHardwarePixelBuffer.h> 41 #include <QFontDatabase> 43 #include <QStaticText> 44 #include <QTextDocument> 45 #include <boost/algorithm/string.hpp> 46 #include <boost/format.hpp> 53 texture_width_(0), texture_height_(0),
57 bg_color_(0, 0, 0, 0),
58 fg_color_(255, 255, 255, 255.0),
59 require_update_texture_(false)
63 ros::message_traits::datatype<jsk_rviz_plugins::OverlayText>(),
64 "jsk_rviz_plugins::OverlayText topic to subscribe to.",
67 "Overtake Position Properties",
false,
68 "overtake position properties specified by message such as left, top and font",
71 "Overtake FG Color Properties",
false,
72 "overtake color properties specified by message such as foreground color and alpha",
75 "Overtake BG Color Properties",
false,
76 "overtake color properties specified by message such as background color and alpha",
79 "Align Bottom",
false,
80 "align text with the bottom of the overlay region",
83 "Invert Shadow",
false,
84 "make shadow lighter than original text",
117 "Foreground Color", QColor(25, 255, 240),
121 "Foreground Alpha", 0.8,
"Foreground Alpha",
126 "Background Color", QColor(0, 0, 0),
130 "Background Alpha", 0.8,
"Background Alpha",
135 QFontDatabase database;
138 "font",
"DejaVu Sans Mono",
193 if (topic_name.length() > 0 && topic_name !=
"/") {
243 QPainter painter( &Hud );
244 painter.setRenderHint(QPainter::Antialiasing,
true);
246 uint16_t
w =
overlay_->getTextureWidth();
247 uint16_t h =
overlay_->getTextureHeight();
252 QFont
font(
font_.length() > 0 ?
font_.c_str():
"Liberation Sans");
255 painter.setFont(
font);
257 if (
text_.length() > 0) {
261 shadow_color = Qt::white;
263 shadow_color = Qt::black;
264 shadow_color.setAlpha(
fg_color_.alpha());
266 std::string color_wrapped_text
267 = (boost::format(
"<span style=\"color: rgba(%2%, %3%, %4%, %5%)\">%1%</span>")
272 std::regex color_tag_re(
"color:.+?;");
273 std::string null_char(
"");
274 std::string formatted_text_ = std::regex_replace(
text_, color_tag_re, null_char);
275 std::string color_wrapped_shadow
276 = (boost::format(
"<span style=\"color: rgba(%2%, %3%, %4%, %5%)\">%1%</span>")
277 % formatted_text_ % shadow_color.red() % shadow_color.green() % shadow_color.blue() % shadow_color.alpha()).
str();
279 QStaticText static_text(
280 boost::algorithm::replace_all_copy(color_wrapped_text,
"\n",
"<br >").c_str());
281 static_text.setTextWidth(w);
283 painter.setPen(QPen(shadow_color, std::max(
line_width_,1), Qt::SolidLine));
284 QStaticText static_shadow(
285 boost::algorithm::replace_all_copy(color_wrapped_shadow,
"\n",
"<br >").c_str());
286 static_shadow.setTextWidth(w);
289 painter.drawStaticText(1, 1, static_shadow);
290 painter.drawStaticText(0, 0, static_text);
292 QStaticText only_wrapped_text(color_wrapped_text.c_str());
293 QFontMetrics fm(painter.fontMetrics());
294 QRect text_rect = fm.boundingRect(0, 0, w, h,
295 Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
296 only_wrapped_text.text().remove(QRegExp(
"<[^>]*>")));
297 painter.drawStaticText(1, h - text_rect.height()+1, static_shadow);
298 painter.drawStaticText(0, h - text_rect.height(), static_text);
308 (
const jsk_rviz_plugins::OverlayText::ConstPtr& msg)
314 static int count = 0;
316 ss <<
"OverlayTextDisplayObject" << count++;
321 if (msg->action == jsk_rviz_plugins::OverlayText::DELETE) {
324 else if (msg->action == jsk_rviz_plugins::OverlayText::ADD) {
339 bg_color_ = QColor(msg->bg_color.r * 255.0,
340 msg->bg_color.g * 255.0,
341 msg->bg_color.b * 255.0,
342 msg->bg_color.a * 255.0);
344 fg_color_ = QColor(msg->fg_color.r * 255.0,
345 msg->fg_color.g * 255.0,
346 msg->fg_color.b * 255.0,
347 msg->fg_color.a * 255.0);
534 ROS_FATAL(
"Unexpected error at selecting font index %d.", font_index);
552 return (top_ < y && top_ + texture_height_ > y &&
553 left_ < x && left_ + texture_width_ > x);
virtual QColor getColor() const
rviz::IntProperty * top_property_
virtual bool setValue(const QVariant &new_value)
bool overtake_position_properties_
rviz::ColorProperty * bg_color_property_
bool overtake_bg_color_properties_
virtual void update(float wall_dt, float ros_dt)
virtual QImage getQImage(unsigned int width, unsigned int height)
void updateOvertakeBGColorProperties()
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
virtual int getInt() const
virtual float getFloat() const
jsk_rviz_plugins::OverlayObject::Ptr overlay_
rviz::ColorProperty * fg_color_property_
virtual ~OverlayTextDisplay()
virtual bool getBool() const
rviz::IntProperty * left_property_
void processMessage(const jsk_rviz_plugins::OverlayText::ConstPtr &msg)
virtual void unsubscribe()
virtual void addOption(const QString &option, int value=0)
rviz::IntProperty * line_width_property_
rviz::FloatProperty * bg_alpha_property_
virtual bool isInRegion(int x, int y)
bool overtake_fg_color_properties_
rviz::FloatProperty * fg_alpha_property_
void updateOvertakeFGColorProperties()
void updateInvertShadow()
rviz::BoolProperty * overtake_position_properties_property_
rviz::BoolProperty * invert_shadow_property_
rviz::IntProperty * text_size_property_
rviz::IntProperty * width_property_
rviz::RosTopicProperty * update_topic_property_
rviz::EnumProperty * font_property_
void updateOvertakePositionProperties()
virtual void movePosition(int x, int y)
rviz::BoolProperty * overtake_fg_color_properties_property_
bool require_update_texture_
rviz::BoolProperty * overtake_bg_color_properties_property_
std::string getTopicStd() const
virtual int getOptionInt()
rviz::BoolProperty * align_bottom_property_
QStringList font_families_
virtual void setPosition(int x, int y)
rviz::IntProperty * height_property_
virtual void onInitialize()