bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, const std::string& text) { //TODO: this could be moved to lua // first message if(m_messages.size() == 0) { m_name = name; m_mode = mode; } // check if we can really own the message else if(m_name != name || m_mode != mode) { return false; } // too many messages else if(m_messages.size() > 10) { m_messages.pop_front(); m_updateEvent->cancel(); m_updateEvent = nullptr; } int delay = std::max<int>(Otc::STATIC_DURATION_PER_CHARACTER * text.length(), Otc::MIN_STATIC_TEXT_DURATION); if(isYell()) delay *= 2; m_messages.push_back(std::make_pair(text, g_clock.millis() + delay)); compose(); if(!m_updateEvent) scheduleUpdate(); return true; }
void StaticText::draw(const Point& dest, const Rect& parentRect) { Size textSize = m_cachedText.getTextSize(); Rect rect = Rect(dest - Point(textSize.width() / 2, textSize.height()) + Point(20, 5), textSize); Rect boundRect = rect; boundRect.bind(parentRect); // draw only if the real center is not too far from the parent center, or its a yell if((boundRect.center() - rect.center()).length() < parentRect.width() / 15 || isYell()) { g_painter->setColor(m_color); m_cachedText.draw(boundRect); } }