Sat, 06 Jul 2013 04:08:57 +0300
rename: msglog.cpp/h -> messagelog.cpp/h
src/messagelog.cpp | file | annotate | diff | comparison | revisions | |
src/messagelog.h | file | annotate | diff | comparison | revisions | |
src/msglog.cpp | file | annotate | diff | comparison | revisions | |
src/msglog.h | file | annotate | diff | comparison | revisions |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/messagelog.cpp Sat Jul 06 04:08:57 2013 +0300 @@ -0,0 +1,119 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "msglog.h" +#include "gldraw.h" +#include "gui.h" +#include <QTimer> +#include <QDate> + +static const unsigned int g_maxMessages = 5; +static const int g_expiry = 5; +static const int g_fadeTime = 500; // msecs + +MessageManager::MessageManager( QObject* parent ) : QObject( parent ) +{ + m_ticker = new QTimer; + m_ticker->start( 100 ); + connect( m_ticker, SIGNAL( timeout() ), this, SLOT( tick() )); +} + +MessageManager::Line::Line( str text ) : text( text ), alpha( 1.0f ) +{ + // Init expiry + expiry = QDateTime::currentDateTime().addSecs( g_expiry ); +} + +// ============================================================================= +// Check this line's expiry and update alpha accordingly. Returns true if the +// line is still around, false if it expired. +bool MessageManager::Line::update( bool& changed ) +{ + changed = false; + + QDateTime now = QDateTime::currentDateTime(); + if( now >= expiry ) + { + changed = true; + return false; + } + + int msec = now.msecsTo( expiry ); + if( msec <= g_fadeTime ) + { + alpha = ( (float) msec ) / g_fadeTime; + changed = true; + } + + return true; +} + +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 ); + + m_lines << Line( line ); + + // Update the renderer view + if( renderer() ) + renderer()->update(); +} + +MessageManager& MessageManager::operator<<( str line ) +{ + addLine( line ); + return *this; +} + +void MessageManager::tick() +{ + if( m_lines.size() == 0 ) + return; + + bool changed = false; + + for( uint i = 0; i < m_lines.size(); ++i ) + { + bool lineChanged; + + if( !m_lines[i].update( lineChanged )) + m_lines.erase( i-- ); + + changed |= lineChanged; + } + + if( changed && renderer() ) + renderer()->update(); +} + +MessageManager::c_it MessageManager::begin() const +{ + return m_lines.begin(); +} + +MessageManager::c_it MessageManager::end() const +{ + return m_lines.end(); +} + +void DoLog( std::initializer_list<StringFormatArg> args ) +{ + g_win->addMessage( DoFormat( args )); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/messagelog.h Sat Jul 06 04:08:57 2013 +0300 @@ -0,0 +1,64 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 Santeri Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MSGLOG_H +#define MSGLOG_H + +#include <QObject> +#include <QDate> +#include "common.h" +#include "types.h" + +class GLRenderer; +class QTimer; +class MessageManager : public QObject +{ + Q_OBJECT + PROPERTY( GLRenderer*, renderer, setRenderer ) + +public: + class Line + { + public: + Line( str text ); + bool update( bool& changed ); + + str text; + float alpha; + QDateTime expiry; + }; + + typedef vector<Line>::it it; + typedef vector<Line>::c_it c_it; + + explicit MessageManager( QObject* parent = 0 ); + void addLine( str line ); + c_it begin() const; + c_it end() const; + + MessageManager& operator<<( str line ); + +private: + vector<Line> m_lines; + QTimer* m_ticker; + +private slots: + void tick(); +}; + +#endif // MSGLOG_H \ No newline at end of file
--- a/src/msglog.cpp Sat Jul 06 04:00:50 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 Santeri Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "msglog.h" -#include "gldraw.h" -#include "gui.h" -#include <QTimer> -#include <QDate> - -static const unsigned int g_maxMessages = 5; -static const int g_expiry = 5; -static const int g_fadeTime = 500; // msecs - -MessageManager::MessageManager( QObject* parent ) : QObject( parent ) -{ - m_ticker = new QTimer; - m_ticker->start( 100 ); - connect( m_ticker, SIGNAL( timeout() ), this, SLOT( tick() )); -} - -MessageManager::Line::Line( str text ) : text( text ), alpha( 1.0f ) -{ - // Init expiry - expiry = QDateTime::currentDateTime().addSecs( g_expiry ); -} - -// ============================================================================= -// Check this line's expiry and update alpha accordingly. Returns true if the -// line is still around, false if it expired. -bool MessageManager::Line::update( bool& changed ) -{ - changed = false; - - QDateTime now = QDateTime::currentDateTime(); - if( now >= expiry ) - { - changed = true; - return false; - } - - int msec = now.msecsTo( expiry ); - if( msec <= g_fadeTime ) - { - alpha = ( (float) msec ) / g_fadeTime; - changed = true; - } - - return true; -} - -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 ); - - m_lines << Line( line ); - - // Update the renderer view - if( renderer() ) - renderer()->update(); -} - -MessageManager& MessageManager::operator<<( str line ) -{ - addLine( line ); - return *this; -} - -void MessageManager::tick() -{ - if( m_lines.size() == 0 ) - return; - - bool changed = false; - - for( uint i = 0; i < m_lines.size(); ++i ) - { - bool lineChanged; - - if( !m_lines[i].update( lineChanged )) - m_lines.erase( i-- ); - - changed |= lineChanged; - } - - if( changed && renderer() ) - renderer()->update(); -} - -MessageManager::c_it MessageManager::begin() const -{ - return m_lines.begin(); -} - -MessageManager::c_it MessageManager::end() const -{ - return m_lines.end(); -} - -void DoLog( std::initializer_list<StringFormatArg> args ) -{ - g_win->addMessage( DoFormat( args )); -} \ No newline at end of file
--- a/src/msglog.h Sat Jul 06 04:00:50 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 Santeri Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MSGLOG_H -#define MSGLOG_H - -#include <QObject> -#include <QDate> -#include "common.h" -#include "types.h" - -class GLRenderer; -class QTimer; -class MessageManager : public QObject -{ - Q_OBJECT - PROPERTY( GLRenderer*, renderer, setRenderer ) - -public: - class Line - { - public: - Line( str text ); - bool update( bool& changed ); - - str text; - float alpha; - QDateTime expiry; - }; - - typedef vector<Line>::it it; - typedef vector<Line>::c_it c_it; - - explicit MessageManager( QObject* parent = 0 ); - void addLine( str line ); - c_it begin() const; - c_it end() const; - - MessageManager& operator<<( str line ); - -private: - vector<Line> m_lines; - QTimer* m_ticker; - -private slots: - void tick(); -}; - -#endif // MSGLOG_H \ No newline at end of file