Changeset View
Changeset View
Standalone View
Standalone View
src/context/applets/analyzer/plugin/DiscoAnalyzer.cpp
- This file was moved from src/context/applets/analyzer/DiscoAnalyzer.cpp.
Show All 11 Lines | |||||
12 | * * | 12 | * * | ||
13 | * You should have received a copy of the GNU General Public License along with * | 13 | * You should have received a copy of the GNU General Public License along with * | ||
14 | * this program. If not, see <http://www.gnu.org/licenses/>. * | 14 | * this program. If not, see <http://www.gnu.org/licenses/>. * | ||
15 | ****************************************************************************************/ | 15 | ****************************************************************************************/ | ||
16 | 16 | | |||
17 | #include "DiscoAnalyzer.h" | 17 | #include "DiscoAnalyzer.h" | ||
18 | 18 | | |||
19 | #include <QImage> | 19 | #include <QImage> | ||
20 | #include <KStandardDirs> | 20 | #include <QStandardPaths> | ||
21 | 21 | | |||
22 | #include <cmath> | 22 | #include <cmath> | ||
23 | #include <cstdlib> | 23 | #include <cstdlib> | ||
24 | #include <sys/time.h> | 24 | #include <sys/time.h> | ||
25 | 25 | | |||
26 | 26 | | |||
27 | DiscoAnalyzer::DiscoAnalyzer( QWidget *parent ): | 27 | DiscoAnalyzer::DiscoAnalyzer( QWidget *parent ): | ||
28 | Analyzer::Base( parent ) | 28 | Analyzer::Base( parent ) | ||
29 | { | 29 | { | ||
30 | setObjectName( "Disco" ); | 30 | setObjectName( "Disco" ); | ||
31 | 31 | | |||
32 | m_dotTexture = bindTexture( QImage( KStandardDirs::locate( "data", "amarok/images/dot.png" ) ) ); | 32 | m_dotTexture = bindTexture( QImage( QStandardPaths::locate( QStandardPaths::GenericDataLocation, "amarok/images/dot.png" ) ) ); | ||
33 | m_w1Texture = bindTexture( QImage( KStandardDirs::locate( "data", "amarok/images/wirl1.png" ) ) ); | 33 | m_w1Texture = bindTexture( QImage( QStandardPaths::locate( QStandardPaths::GenericDataLocation, "amarok/images/wirl1.png" ) ) ); | ||
34 | m_w2Texture = bindTexture( QImage( KStandardDirs::locate( "data", "amarok/images/wirl2.png" ) ) ); | 34 | m_w2Texture = bindTexture( QImage( QStandardPaths::locate( QStandardPaths::GenericDataLocation, "amarok/images/wirl2.png" ) ) ); | ||
35 | 35 | | |||
36 | m_show.paused = true; | 36 | m_show.paused = true; | ||
37 | m_show.pauseTimer = 0.0; | 37 | m_show.pauseTimer = 0.0; | ||
38 | m_show.rotDegrees = 0.0; | 38 | m_show.rotDegrees = 0.0; | ||
39 | m_frame.rotDegrees = 0.0; | 39 | m_frame.rotDegrees = 0.0; | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | DiscoAnalyzer::~DiscoAnalyzer() | 42 | DiscoAnalyzer::~DiscoAnalyzer() | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 150 | // printf( "%d [%f :: %f ]\t%f \n", bands, frame.energy, frame.meanBand, maxValue ); | |||
151 | } | 151 | } | ||
152 | else | 152 | else | ||
153 | m_frame.energy = 0.0; | 153 | m_frame.energy = 0.0; | ||
154 | } | 154 | } | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | void DiscoAnalyzer::paintGL() | 157 | void DiscoAnalyzer::paintGL() | ||
158 | { | 158 | { | ||
159 | // Compute the dT since the last call to paintGL and update timings | | |||
160 | timeval tv; | | |||
161 | gettimeofday( &tv, NULL ); | | |||
162 | double currentTime = ( double )tv.tv_sec + ( double )tv.tv_usec / 1000000.0; | | |||
163 | m_show.dT = currentTime - m_show.timeStamp; | | |||
164 | m_show.timeStamp = currentTime; | | |||
165 | | ||||
166 | // Clear frame | | |||
167 | glClear( GL_COLOR_BUFFER_BIT ); | | |||
168 | | ||||
169 | // Shitch to MODEL matrix and reset it to default | | |||
170 | glMatrixMode( GL_MODELVIEW ); | | |||
171 | glLoadIdentity(); | | |||
172 | | ||||
173 | // Fade the previous drawings. | | |||
174 | /* glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | | |||
175 | glBegin( GL_TRIANGLE_STRIP ); | | |||
176 | glColor4f( 0.0f, 0.0f, 0.0f, 0.2f ); | | |||
177 | glVertex2f( 10.0f, 10.0f ); | | |||
178 | glVertex2f( -10.0f, 10.0f ); | | |||
179 | glVertex2f( 10.0f, -10.0f ); | | |||
180 | glVertex2f( -10.0f, -10.0f ); | | |||
181 | glEnd();*/ | | |||
182 | | ||||
183 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | | |||
184 | glEnable( GL_TEXTURE_2D ); | | |||
185 | float alphaN = m_show.paused ? 0.2 : ( m_frame.energy / 10.0 ), | | |||
186 | alphaP = m_show.paused ? 1.0 : ( 1 - m_frame.energy / 20.0 ); | | |||
187 | if( alphaN > 1.0 ) | | |||
188 | alphaN = 1.0; | | |||
189 | if( alphaP < 0.1 ) | | |||
190 | alphaP = 0.1; | | |||
191 | glBindTexture( GL_TEXTURE_2D, m_w2Texture ); | | |||
192 | setTextureMatrix( m_show.rotDegrees, 0.707 * alphaP ); | | |||
193 | glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); | | |||
194 | glBegin( GL_TRIANGLE_STRIP ); | | |||
195 | glTexCoord2f( 1.0, 1.0 ); | | |||
196 | glVertex2f( 10.0f, 10.0f ); | | |||
197 | glTexCoord2f( 0.0, 1.0 ); | | |||
198 | glVertex2f( -10.0f, 10.0f ); | | |||
199 | glTexCoord2f( 1.0, 0.0 ); | | |||
200 | glVertex2f( 10.0f, -10.0f ); | | |||
201 | glTexCoord2f( 0.0 , 0.0 ); | | |||
202 | glVertex2f( -10.0f, -10.0f ); | | |||
203 | glEnd(); | | |||
204 | glBindTexture( GL_TEXTURE_2D, m_w1Texture ); | | |||
205 | setTextureMatrix( -m_show.rotDegrees * 2, 0.707 ); | | |||
206 | glColor4f( 1.0f, 1.0f, 1.0f, alphaN ); | | |||
207 | glBegin( GL_TRIANGLE_STRIP ); | | |||
208 | glTexCoord2f( 1.0, 1.0 ); | | |||
209 | glVertex2f( 10.0f, 10.0f ); | | |||
210 | glTexCoord2f( 0.0, 1.0 ); | | |||
211 | glVertex2f( -10.0f, 10.0f ); | | |||
212 | glTexCoord2f( 1.0, 0.0 ); | | |||
213 | glVertex2f( 10.0f, -10.0f ); | | |||
214 | glTexCoord2f( 0.0 , 0.0 ); | | |||
215 | glVertex2f( -10.0f, -10.0f ); | | |||
216 | glEnd(); | | |||
217 | setTextureMatrix( 0.0, 0.0 ); | | |||
218 | glDisable( GL_TEXTURE_2D ); | | |||
219 | glBlendFunc( GL_SRC_ALPHA, GL_ONE ); | | |||
220 | | ||||
221 | // Here begins the real draw loop | | |||
222 | // some updates to the showStruct | | |||
223 | m_show.rotDegrees += 40.0 * m_show.dT; | | |||
224 | m_frame.rotDegrees += 80.0 * m_show.dT; | | |||
225 | | ||||
226 | // handle the 'pause' status | | |||
227 | if( m_show.paused ) | | |||
228 | { | | |||
229 | if( m_show.pauseTimer > 0.5 ) | | |||
230 | { | | |||
231 | if( m_show.pauseTimer > 0.6 ) | | |||
232 | m_show.pauseTimer -= 0.6; | | |||
233 | drawFullDot( 0.0f, 0.4f, 0.8f, 1.0f ); | | |||
234 | drawFullDot( 0.0f, 0.4f, 0.8f, 1.0f ); | | |||
235 | } | | |||
236 | m_show.pauseTimer += m_show.dT; | | |||
237 | return; | | |||
238 | } | | |||
239 | 159 | | |||
240 | if( m_dotTexture ) | | |||
241 | { | | |||
242 | glEnable( GL_TEXTURE_2D ); | | |||
243 | glBindTexture( GL_TEXTURE_2D, m_dotTexture ); | | |||
244 | } | | |||
245 | else | | |||
246 | glDisable( GL_TEXTURE_2D ); | | |||
247 | | ||||
248 | glLoadIdentity(); | | |||
249 | // glRotatef( -frame.rotDegrees, 0,0,1 ); | | |||
250 | glBegin( GL_QUADS ); | | |||
251 | // Particle * particle = particleList.first(); | | |||
252 | // for (; particle; particle = particleList.next()) | | |||
253 | { | | |||
254 | glColor4f( 0.0f, 1.0f, 0.0f, 1.0f ); | | |||
255 | drawDot( 0, 0, qMax( 10.0, ( 10.0 * m_frame.energy ) ) ); | | |||
256 | glColor4f( 1.0f, 0.0f, 0.0f, 1.0f ); | | |||
257 | drawDot( 6, 0, qMax( 10.0, ( 5.0 * m_frame.energy ) ) ); | | |||
258 | glColor4f( 0.0f, 0.4f, 1.0f, 1.0f ); | | |||
259 | drawDot( -6, 0, qMax( 10.0, ( 5.0 * m_frame.energy ) ) ); | | |||
260 | } | | |||
261 | glEnd(); | | |||
262 | } | 160 | } | ||
263 | 161 | | |||
264 | void DiscoAnalyzer::drawDot( float x, float y, float size ) | 162 | void DiscoAnalyzer::drawDot( float x, float y, float size ) | ||
265 | { | 163 | { | ||
266 | float sizeX = size * m_unitX, | 164 | float sizeX = size * m_unitX, | ||
267 | sizeY = size * m_unitY, | 165 | sizeY = size * m_unitY, | ||
268 | pLeft = x - sizeX, | 166 | pLeft = x - sizeX, | ||
269 | pTop = y + sizeY, | 167 | pTop = y + sizeY, | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |