src/messagelog.cpp

changeset 421
7d26db0be944
parent 410
a5aebcf4a1c8
child 455
c5d14d112034
--- a/src/messagelog.cpp	Fri Aug 02 15:57:03 2013 +0300
+++ b/src/messagelog.cpp	Fri Aug 02 16:33:30 2013 +0300
@@ -28,39 +28,38 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-MessageManager::MessageManager( QObject* parent ) :
-	QObject( parent )
-{
+MessageManager::MessageManager (QObject* parent) :
+	QObject (parent) {
 	m_ticker = new QTimer;
-	m_ticker->start( 100 );
-	connect( m_ticker, SIGNAL( timeout() ), this, SLOT( tick() ));
+	m_ticker->start (100);
+	connect (m_ticker, SIGNAL (timeout()), this, SLOT (tick()));
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-MessageManager::Line::Line( str text ) :
-	text( text ),
-	alpha( 1.0f ),
-	expiry( QDateTime::currentDateTime().addSecs( g_expiry )) {}
+MessageManager::Line::Line (str text) :
+	text (text),
+	alpha (1.0f),
+	expiry (QDateTime::currentDateTime().addSecs (g_expiry)) {}
 
 // =============================================================================
 // Check this line's expiry and update alpha accordingly. Returns true if the
 // line is to still stick around, false if it expired. 'changed' is updated to
 // whether the line has somehow changed since the last update.
-bool MessageManager::Line::update( bool& changed ) {
+bool MessageManager::Line::update (bool& changed) {
 	changed = false;
+	QDateTime now = QDateTime::currentDateTime();
+	int msec = now.msecsTo (expiry);
 	
-	QDateTime now = QDateTime::currentDateTime();
-	if( now >= expiry ) {
+	if (now >= expiry) {
 		// Message line has expired
 		changed = true;
 		return false;
 	}
 	
-	int msec = now.msecsTo( expiry );
-	if( msec <= g_fadeTime ) {
+	if (msec <= g_fadeTime) {
 		// Message line has not expired but is fading out
-		alpha = ( (float) msec ) / g_fadeTime;
+		alpha = ((float) msec) / g_fadeTime;
 		changed = true;
 	}
 	
@@ -70,23 +69,23 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 // Add a line to the message manager.
-void MessageManager::addLine( str line ) {
+void MessageManager::addLine (str line) {
 	// If there's too many entries, pop the excess out
-	while( m_lines.size() >= g_maxMessages )
-		m_lines.erase( 0 );
+	while (m_lines.size() >= g_maxMessages)
+		m_lines.erase (0);
 	
-	m_lines << Line( line );
+	m_lines << Line (line);
 	
 	// Update the renderer view
-	if( renderer() )
+	if (renderer())
 		renderer()->update();
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 // Shortcut
-MessageManager& MessageManager::operator<<( str line ) {
-	addLine( line );
+MessageManager& MessageManager::operator<< (str line) {
+	addLine (line);
 	return *this;
 }
 
@@ -95,21 +94,21 @@
 // Ticks the message manager. All lines are ticked and the renderer scene is
 // redrawn if something changed.
 void MessageManager::tick() {
-	if( m_lines.size() == 0 )
+	if (m_lines.size() == 0)
 		return;
 	
 	bool changed = false;
 	
-	for( uint i = 0; i < m_lines.size(); ++i ) {
+	for (uint i = 0; i < m_lines.size(); ++i) {
 		bool lineChanged;
 		
-		if( !m_lines[i].update( lineChanged ))
-			m_lines.erase( i-- );
+		if (!m_lines[i].update (lineChanged))
+			m_lines.erase (i--);
 		
 		changed |= lineChanged;
 	}
 	
-	if( changed && renderer() )
+	if (changed && renderer())
 		renderer()->update();
 }
 
@@ -130,12 +129,12 @@
 // -----------------------------------------------------------------------------
 // log() interface - format the argument list and add the resulting string to
 // the main message manager.
-void DoLog( std::initializer_list<StringFormatArg> args ) {
-	const str msg = DoFormat( args );
-	g_win->addMessage( msg );
+void DoLog (std::initializer_list<StringFormatArg> args) {
+	const str msg = DoFormat (args);
+	g_win->addMessage (msg);
 	
 	// Also print it to stdout
-	print( "%1\n", msg );
+	print ("%1\n", msg);
 }
 
 #include "build/moc_messagelog.cpp"
\ No newline at end of file

mercurial