void OverlayMenuDisplay::redraw() { ROS_DEBUG("redraw"); prepareOverlay(); { ScopedPixelBuffer buffer = overlay_->getBuffer(); QColor bg_color(0, 0, 0, 255.0 / 2.0); QColor fg_color(25, 255, 240, 255.0); QImage Hud = buffer.getQImage(*overlay_, bg_color); QPainter painter( &Hud ); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(fg_color, 1, Qt::SolidLine)); painter.setFont(font()); int line_height = fontMetrics().height(); int w = drawAreaWidth(next_menu_); painter.drawText(menu_padding_x, menu_padding_y, w, line_height, Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, next_menu_->title.c_str()); for (size_t i = 0; i < next_menu_->menus.size(); i++) { std::string menu = getMenuString(next_menu_, i); painter.drawText(menu_padding_x, line_height * ( 1 + i ) + menu_padding_y + menu_last_padding_y, w, line_height, Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, menu.c_str()); } if (next_menu_->current_index <= next_menu_->menus.size()) { // draw '>' painter.drawText(menu_padding_x - fontMetrics().width(">") * 2, line_height * ( 1 + next_menu_->current_index ) + menu_padding_y + menu_last_padding_y, w, line_height, Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, ">"); } // draw line int texture_width = overlay_->getTextureWidth(); int texture_height = overlay_->getTextureHeight(); painter.drawLine(menu_padding_x / 2, menu_last_padding_y / 2 + line_height, menu_padding_x / 2, texture_height - menu_last_padding_y / 2); painter.drawLine(texture_width - menu_padding_x / 2, menu_last_padding_y / 2 + line_height, texture_width - menu_padding_x / 2, texture_height - menu_last_padding_y / 2); painter.drawLine(menu_padding_x / 2, menu_last_padding_y / 2 + line_height, texture_width - menu_padding_x / 2, menu_last_padding_y / 2 + line_height); painter.drawLine(menu_padding_x / 2, texture_height - menu_last_padding_y / 2, texture_width - menu_padding_x / 2, texture_height - menu_last_padding_y / 2); painter.end(); current_menu_ = next_menu_; } overlay_->setDimensions(overlay_->getTextureWidth(), overlay_->getTextureHeight()); int window_width = context_->getViewManager()->getRenderPanel()->width(); int window_height = context_->getViewManager()->getRenderPanel()->height(); double window_left = (window_width - (int)overlay_->getTextureWidth()) / 2.0; double window_top = (window_height - (int)overlay_->getTextureHeight()) / 2.0; overlay_->setPosition(window_left, window_top); }
int OverlayMenuDisplay::drawAreaWidth( const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg) { QFontMetrics fm = fontMetrics(); int max_width = 0; for (size_t i = 0; i < msg->menus.size(); i++) { int w = fm.width(getMenuString(msg, i).c_str()); if (max_width < w) { max_width = w; } } int w = fm.width(msg->title.c_str()); if (max_width < w) { max_width = w; } return max_width + menu_padding_x * 2; }
void LCDDisplay::refresh() { char blockNumber1[1]={128};//first character of the display char playbackOutputString[1]={0};//initialise the playback output string as NULL char playIcon[1]={62}; //ASCII value of closest symbol to play icon char pauseIcon[1]={4}; //ASCII value of closest symbol to pause icon char rewindIcon[1]={127}; //ASCII value of closest symbol to rewind icon char fForwardIcon[1]={126}; //ASCII value of closest symbol to fast forward icon char *playbackString; //char pointer for the playback String char *trackInfoString; //char pointer for the track Info String char *menuString; //char pointer for the menu String char *errorString; //char pointer for the error String struct timeval currentTime; // contains the struct needed for gettimeofday to function gettimeofday(¤tTime,NULL);//saves the current time in seconds that refresh was called //if the last time the function ran is half a second more than the current time: if ((((blocks[0].lastTime.tv_sec*1000000)+blocks[0].lastTime.tv_usec)+500000) < ((currentTime.tv_sec*1000000)+currentTime.tv_usec)) { setPlaybackDirty(true); // set the playback dirty flag } //if the playback region is dirty and the string does not contain a NULL: if (playbackIsDirty() && getPlaybackString(&playbackString) != NULL) { std::cout << "playback Button Pressed\n"; int tokenSize = strlen(playbackString); //Based on the letter passed by the playback String enter a following case: switch(*playbackString){ case 'p': //copy the ASCII value into the playback output String strncpy(playbackOutputString,playIcon,8); break; case 'w': //copy the ASCII value into the playback output String strncpy(playbackOutputString,pauseIcon,8); break; case 'f': //copy the ASCII value into the playback output String strncpy(playbackOutputString,fForwardIcon,8); break; case 'r': //copy the ASCII value into the playback output String strncpy(playbackOutputString,rewindIcon,8); break; } write(displayDevice, &displayOptionMode, 1);//enter the option mode for the device write(displayDevice, &blockNumber1, 1);//set the device to begin writing to block 1 //write the currrent contents of the playback string to the display write(displayDevice, playbackOutputString, 1); delete playbackString; //delete the contents of the playback String setPlaybackDirty(false); //set the playback region flag to clean } //if the track info region is dirty: if (trackInfoIsDirty()==true){ blocks[1].scrollPosition=0;//set the scroll position to the first character of the region } //if the region is not dirty wait until half a second has passed and make the region dirty. else if ((((blocks[1].lastTime.tv_sec*1000000)+blocks[1].lastTime.tv_usec)+500000) < ((currentTime.tv_sec*1000000)+currentTime.tv_usec)) { setTrackInfoDirty(true);//Set the region flag to dirty } // if the track info region is dirty and the track info string does not contain NULL : if (trackInfoIsDirty() && getTrackInfoString(&trackInfoString) != NULL) { //call the write block function passing the track info string and the block number 1 writeBlock(1,trackInfoString); delete trackInfoString; // delete the track info string setTrackInfoDirty(false); // set the track info region flag to clean } //if the menu region is dirty if (menuIsDirty()==true){ blocks[2].scrollPosition=0;//set the scroll position to 0 } //if the region is not dirty wait until half a second has passed and make the region dirty else if ((((blocks[2].lastTime.tv_sec*1000000)+blocks[2].lastTime.tv_usec)+500000) < ((currentTime.tv_sec*1000000)+currentTime.tv_usec)) { setMenuDirty(true);//Set the region flag to dirty } //if the menu region is dirt and the menuString doesnt contain NULL if (menuIsDirty() && getMenuString(&menuString) != NULL) { //call the write block function passing the menu string and the block number 2 writeBlock(2,menuString); delete menuString;//delete the menu String setMenuDirty(false); // set the menu region flag to clean } // if the error String is not NULL : if (getErrorString(&errorString) != NULL) { //call the write block function passing the Error string and the block number 3 writeBlock(3,errorString); delete errorString; // delete the error String setErrorString(NULL); // set the Error String to NULL } }