Thu, 04 Jul 2013 03:05:39 +0300
Re-added the message log, now draws into the viewport
322
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include "msglog.h" |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "gldraw.h" |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "gui.h" |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QTimer> |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <QDate> |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | static const unsigned int g_maxMessages = 5; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | static const int g_expiry = 5; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | static const int g_fadeTime = 500; // msecs |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | MessageManager::MessageManager( QObject* parent ) : QObject( parent ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | m_ticker = new QTimer; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | m_ticker->start( 100 ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | connect( m_ticker, SIGNAL( timeout() ), this, SLOT( tick() )); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | MessageManager::Line::Line( str text ) : text( text ), alpha( 1.0f ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | // Init expiry |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | expiry = QDateTime::currentDateTime().addSecs( g_expiry ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | // ============================================================================= |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | // Check this line's expiry and update alpha accordingly. Returns true if the |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | // line is still around, false if it expired. |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | bool MessageManager::Line::update( bool& changed ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | changed = false; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | QDateTime now = QDateTime::currentDateTime(); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | if( now >= expiry ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | changed = true; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | return false; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | int msec = now.msecsTo( expiry ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | if( msec <= g_fadeTime ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | alpha = ( (float) msec ) / g_fadeTime; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | changed = true; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | return true; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | void MessageManager::addLine( str line ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // If there's too many entries, pop the excess out |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | while( m_lines.size() >= g_maxMessages ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | m_lines.erase( 0 ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | m_lines << Line( line ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | // Force a tick, we added a new message and it should |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | // show up immediately. |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | tick(); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | MessageManager& MessageManager::operator<<( str line ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | addLine( line ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | return *this; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | void MessageManager::tick() |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | bool changed = false; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | for( uint i = 0; i < m_lines.size(); ++i ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | bool lineChanged; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | if( !m_lines[i].update( lineChanged )) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | m_lines.erase( i-- ); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | changed |= lineChanged; |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | if( changed ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | renderer()->update(); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | MessageManager::c_it MessageManager::begin() const |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | return m_lines.begin(); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | MessageManager::c_it MessageManager::end() const |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | return m_lines.end(); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | } |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | void DoLog( std::initializer_list<StringFormatArg> args ) |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | { |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | g_win->addMessage( DoFormat( args )); |
5e701c3c3d8e
Re-added the message log, now draws into the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |