void c_text_display::draw_strings(void) { if (is_initalized) { c_text_data_list_iterator my_iterator(&m_strings); for (my_iterator.set_at_start(); !my_iterator.at_end(); my_iterator.next()) { s_text_data current_text_data = my_iterator.get_data(); RECT display_rect; display_rect.top = static_cast<long>(current_text_data.position.get_position().y); display_rect.left = static_cast<long>(current_text_data.position.get_position().x); display_rect.bottom = static_cast<long>(display_rect.top + 25); display_rect.right = static_cast<long>(display_rect.left + current_text_data.text.length() * 32); int result = font->DrawTextA( NULL, current_text_data.text.get_string_const(), current_text_data.text.length(), &display_rect, 0, font_color(current_text_data)); std::cout << current_text_data.text.get_string_const() << std::endl; } } }
SDL_Surface * new_text_surface(TTF_Font * font, const string text,unsigned short r, unsigned short g, unsigned short b){ SDL_Color color = font_color(r,g,b); SDL_Surface * text_surface = NULL; text_surface = TTF_RenderText_Solid(font,text.c_str(),color); if(text_surface==NULL) quit("Could not create text surface with text '"+text+"'"); return text_surface; }
/* * keyboard_input * DESCRIPTION: Processes all keyboard input. Letters get printed to screen while read fn. is * running, some other keys have special functions. * INPUTS: key -- 8 bit scancode passed in from keyboard handler * OUTPUTS: none * RETURN VALUE: none * SIDE EFFECTS: none */ void keyboard_input(uint8_t key) { // Only process keyboard input if read fn. is executing if(!reading) return; switch(key) { // Ctrl pressed case 0x1D: ctrl = 1; return; // Ctrl realeased case 0x9D: ctrl = 0; return; // Up arrow pressed case 0x48: scroll(-1); return; // Down arrow pressed case 0x50: scroll(1); return; // Page Up pressed case 0x49: scroll(-12); return; // Page Down pressed case 0x51: scroll(12); return; // Caps Lock pressed/released case 0x3A: caps_lock = 1 - caps_lock; return; // Left shift pressed case 0x2A: shift = 1; return; // Left shift released case 0xAA: shift = 0; return; // Right shift pressed case 0x36: shift = 1; return; // Right shift released case 0xB6: shift = 0; return; // F7 pressed case 0x41: font_color(); return; // F8 pressed case 0x42: background_color(); return; } uint8_t kbd_data; // Decide which kbd array to use. if(shift || caps_lock) kbd_data = shift_chars[key]; else kbd_data = chars[key]; if(ctrl) { // Clear screen on <Ctrl + l> if(kbd_data == 'l') { clear(); line_pos = 0; } return; } // Return if scancode is for key release. if((0x80 & key) != 0) return; // Only process valid characters. if(kbd_data != 0) { if(kbd_data == '\b') { // Don't allow backspacing farther than beginning of typed buffer. if(line_pos == 0) return; line_pos--; } else if(kbd_data == '\n') { reading = 0; typed[line_pos] = '\n'; enter_pressed = 1; } // Printable characters else { // Only allow 1024 characters in buffer. if(line_pos >= 10) return; typed[line_pos] = kbd_data; line_pos++; } putc(kbd_data); } }
void DiagnosticsDisplay::processMessage (const diagnostic_msgs::DiagnosticArray::ConstPtr& msg) { if (!isEnabled()) { return; } // update namespaces_ if needed std::set<std::string> new_namespaces; for (size_t i = 0; i < msg->status.size(); i++) { new_namespaces.insert(msg->status[i].name); } std::set<std::string> difference_namespaces; std::set_difference(namespaces_.begin(), namespaces_.end(), new_namespaces.begin(), new_namespaces.end(), std::inserter(difference_namespaces, difference_namespaces.end())); if (difference_namespaces.size() != 0) { namespaces_ = new_namespaces; fillNamespaceList(); } else { difference_namespaces.clear(); std::set_difference(new_namespaces.begin(), new_namespaces.end(), namespaces_.begin(), namespaces_.end(), std::inserter(difference_namespaces, difference_namespaces.end())); if (difference_namespaces.size() != 0) { namespaces_ = new_namespaces; fillNamespaceList(); } } if (diagnostics_namespace_.length() == 0) { return; } const float alpha = 0.8; const Ogre::ColourValue OK(0.3568627450980392, 0.7529411764705882, 0.8705882352941177, alpha); const Ogre::ColourValue WARN(0.9411764705882353, 0.6784313725490196, 0.3058823529411765, alpha); const Ogre::ColourValue ERROR(0.8509803921568627, 0.3254901960784314, 0.30980392156862746, 0.5); const Ogre::ColourValue UNKNOWN(0.2, 0.2, 0.2, 0.5); Ogre::ColourValue color; std::string message; bool foundp = false; for (size_t i = 0; i < msg->status.size(); i++) { diagnostic_msgs::DiagnosticStatus status = msg->status[i]; if (status.name == diagnostics_namespace_) { if (status.level == diagnostic_msgs::DiagnosticStatus::OK) { color = OK; message = status.message; } else if (status.level == diagnostic_msgs::DiagnosticStatus::WARN) { color = WARN; message = status.message; } else if (status.level == diagnostic_msgs::DiagnosticStatus::ERROR) { color = ERROR; message = status.message; } else { // unknwon color = UNKNOWN; message = "unknown"; } foundp = true; break; } } if (!foundp) { color = UNKNOWN; message = "stall"; } line_->setColor(color.r, color.g, color.b, color.a); Ogre::ColourValue font_color(color); font_color.a = 1.0; msg_->setColor(font_color); msg_->setCaption(diagnostics_namespace_ + "\n" + message); context_->queueRender(); }