void GameLog::print(const std::string& msg) { CEGUI::ListboxTextItem* text; if(log_->getItemCount() >= log_history_) { text = (CEGUI::ListboxTextItem*)log_->getListboxItemFromIndex(0); text->setAutoDeleted(false); log_->removeItem(text); text->setAutoDeleted(true); text->setText(msg); } else text = new CEGUI::ListboxTextItem(msg); text->setTextColours(CEGUI::Colour{0.f, 1.f, 0.f}); log_->addItem(text); //log_->getVertScrollbar()->scrollForwardsByStep(); log_->getVertScrollbar()->setScrollPosition(log_->getVertScrollbar()->getDocumentSize()); }
void CSimulatorWindowHandler::addToLog(const std::string &text) { unsigned int historySize = 7; unsigned int shortHistorySize = 3; std::ostringstream message; // If there's text then add it if(text.size()) { message << m_simulator->getReferee()->getMinute() << "' - " << text.c_str(); // Add the Editbox text to the history Listbox CEGUI::ListboxTextItem* logItem; if(m_logHistoryList->getItemCount() == historySize) { /* We have reached the capacity of the Listbox so re-use the first Listbox item. This code is a little crafty. By default the ListboxTextItem is created with the auto-delete flag set to true, which results in its automatic deletion when removed from the Listbox. So we change that flag to false, extract the item from the Listbox, change its text, put the auto-delete flag back to true, and finally put the item back into the Listbox. */ logItem = static_cast<CEGUI::ListboxTextItem*>(m_logHistoryList->getListboxItemFromIndex(0)); logItem->setAutoDeleted(false); m_logHistoryList->removeItem(logItem); logItem->setAutoDeleted(true); logItem->setText((CEGUI::utf8*)message.str().c_str()); } else { // Create a new listbox item logItem = new CEGUI::ListboxTextItem((CEGUI::utf8*)message.str().c_str()); } m_logHistoryList->addItem(logItem); m_logHistoryList->ensureItemIsVisible(m_logHistoryList->getItemCount()); if(m_logHistoryListShort->getItemCount() == shortHistorySize) { logItem = static_cast<CEGUI::ListboxTextItem*>(m_logHistoryListShort->getListboxItemFromIndex(0)); logItem->setAutoDeleted(false); m_logHistoryListShort->removeItem(logItem); logItem->setAutoDeleted(true); logItem->setText((CEGUI::utf8*)message.str().c_str()); } else { logItem = new CEGUI::ListboxTextItem((CEGUI::utf8*)message.str().c_str()); } m_logHistoryListShort->addItem(logItem); m_logHistoryListShort->ensureItemIsVisible(m_logHistoryListShort->getItemCount()); } }