40 #include <boost/algorithm/string.hpp> 
   41 #include <boost/format.hpp> 
   42 #include <jsk_topic_tools/log_utils.h> 
   43 #include <OGRE/OgreHardwarePixelBuffer.h> 
   44 #include <OGRE/OgreMaterialManager.h> 
   45 #include <OGRE/OgreTexture.h> 
   47 #include <QFontDatabase> 
   49 #include <QStaticText> 
   50 #include <QTextDocument> 
   56                                    texture_width_(0), texture_height_(0),
 
   60                                    bg_color_(0, 0, 0, 0),
 
   61                                    fg_color_(255, 255, 255, 255.0),
 
   62                                    require_update_texture_(false)
 
   66       ros::message_traits::datatype<std_msgs::String>(),
 
   67       "std_msgs::String topic to subscribe to.",
 
   70       "Overtake Position Properties", 
false,
 
   71       "overtake position properties specified by message such as left, top and font",
 
   72       this, SLOT(updateOvertakePositionProperties()));
 
   74       "Overtake Color Properties", 
false,
 
   75       "overtake color properties specified by message such as foreground/background color and alpha",
 
   76       this, SLOT(updateOvertakeColorProperties()));
 
   78       "Align Bottom", 
false,
 
   79       "align text with the bottom of the overlay region",
 
   80       this, SLOT(updateAlignBottom()));
 
   84       this, SLOT(updateTop()));
 
   85     top_property_->setMin(0);
 
   89       this, SLOT(updateLeft()));
 
   90     left_property_->setMin(0);
 
   94       this, SLOT(updateWidth()));
 
   95     width_property_->setMin(0);
 
   99       this, SLOT(updateHeight()));
 
  100     height_property_->setMin(0);
 
  104       this, SLOT(updateTextSize()));
 
  105     text_size_property_->setMin(0);
 
  109       this, SLOT(updateLineWidth()));
 
  110     line_width_property_->setMin(0);
 
  112       "Foreground Color", QColor(25, 255, 240),
 
  114       this, SLOT(updateFGColor()));
 
  116       "Foreground Alpha", 0.8, 
"Foreground Alpha",
 
  117       this, SLOT(updateFGAlpha()));
 
  118     fg_alpha_property_->setMin(0.0);
 
  119     fg_alpha_property_->setMax(1.0);
 
  121       "Background Color", QColor(0, 0, 0),
 
  123       this, SLOT(updateBGColor()));
 
  125       "Background Alpha", 0.8, 
"Background Alpha",
 
  126       this, SLOT(updateBGAlpha()));
 
  127     bg_alpha_property_->setMin(0.0);
 
  128     bg_alpha_property_->setMax(1.0);
 
  130     QFontDatabase database;
 
  131     font_families_ = database.families();
 
  133       "font", 
"DejaVu Sans Mono",
 
  136     for (
size_t i = 0; 
i < font_families_.size(); 
i++)
 
  138       font_property_->addOption(font_families_[i], 
static_cast<int>(i));
 
  189     if (topic_name.length() > 0 && topic_name != 
"/")
 
  242       QPainter painter( &Hud );
 
  243       painter.setRenderHint(QPainter::Antialiasing, 
true);
 
  245       uint16_t 
w = 
overlay_->getTextureWidth();
 
  246       uint16_t h = 
overlay_->getTextureHeight();
 
  251         QFont 
font(
font_.length() > 0 ? 
font_.c_str(): 
"Liberation Sans");
 
  254         painter.setFont(
font);
 
  256       if (
text_.length() > 0)
 
  258         std::string color_wrapped_text
 
  259           = (boost::format(
"<span style=\"color: rgba(%2%, %3%, %4%, %5%)\">%1%</span>")
 
  262         QStaticText static_text(
 
  263           boost::algorithm::replace_all_copy(color_wrapped_text, 
"\n", 
"<br >").c_str());
 
  264         static_text.setTextWidth(
w);
 
  267           painter.drawStaticText(0, 0, static_text);
 
  271           QStaticText only_wrapped_text(color_wrapped_text.c_str());
 
  272           QFontMetrics fm(painter.fontMetrics());
 
  273           QRect text_rect = fm.boundingRect(0, 0, 
w, h,
 
  274                                             Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop,
 
  275                                             only_wrapped_text.text().remove(QRegExp(
"<[^>]*>")));
 
  276           painter.drawStaticText(0, h - text_rect.height(), static_text);
 
  286   (
const std_msgs::String::ConstPtr& msg)
 
  294       static int count = 0;
 
  296       ss << 
"StringDisplayObject" << 
count++;
 
  297       overlay_.reset(
new OverlayObject(ss.str()));
 
  482       ROS_FATAL(
"Unexpected error at selecting font index %d.", font_index);
 
  502     return (top_ < y && top_ + texture_height_ > 
y &&
 
  503             left_ < x && left_ + texture_width_ > 
x);