2011-06-23 01:25:08 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-11-29 20:07:01 +01:00
|
|
|
Copyright 2011, Tyler Rhodes <tyler.s.rhodes@gmail.com>
|
|
|
|
Copyright 2011-2012, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2011, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2011-06-23 01:25:08 +02:00
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
#ifndef ANALYZERS_NYANCATANALYZER_H_
|
|
|
|
#define ANALYZERS_NYANCATANALYZER_H_
|
2011-06-23 01:25:08 +02:00
|
|
|
|
|
|
|
#include "analyzerbase.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
class NyanCatAnalyzer : public Analyzer::Base {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2011-06-23 01:25:08 +02:00
|
|
|
Q_INVOKABLE NyanCatAnalyzer(QWidget* parent);
|
|
|
|
|
|
|
|
static const char* kName;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2014-05-13 14:46:22 +02:00
|
|
|
void transform(Analyzer::Scope&);
|
2011-06-23 22:36:14 +02:00
|
|
|
void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
|
2011-06-23 01:25:08 +02:00
|
|
|
|
2011-06-23 22:36:38 +02:00
|
|
|
void timerEvent(QTimerEvent* e);
|
|
|
|
void resizeEvent(QResizeEvent* e);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-06-23 01:25:08 +02:00
|
|
|
static const int kCatHeight = 21;
|
|
|
|
static const int kCatWidth = 34;
|
2012-10-16 12:20:56 +02:00
|
|
|
static const int kCatFrameCount = 6;
|
2011-06-23 01:25:08 +02:00
|
|
|
static const int kRainbowOverlap = 13;
|
2012-10-16 12:20:56 +02:00
|
|
|
static const int kSleepingCatHeight = 24;
|
2011-06-23 01:25:08 +02:00
|
|
|
|
2011-06-23 02:22:56 +02:00
|
|
|
static const int kHistorySize = 128;
|
2011-06-23 01:25:08 +02:00
|
|
|
static const int kRainbowBands = 6;
|
2011-06-23 14:34:30 +02:00
|
|
|
static const float kPixelScale;
|
2011-06-23 01:25:08 +02:00
|
|
|
|
|
|
|
static const int kFrameIntervalMs = 150;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-06-23 01:25:08 +02:00
|
|
|
inline QRect CatSourceRect() const {
|
|
|
|
return QRect(0, kCatHeight * frame_, kCatWidth, kCatHeight);
|
|
|
|
}
|
|
|
|
|
2012-10-16 12:20:56 +02:00
|
|
|
inline QRect SleepingCatSourceRect() const {
|
|
|
|
return QRect(0, kCatHeight * kCatFrameCount, kCatWidth, kSleepingCatHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QRect CatDestRect() const {
|
2014-02-07 16:34:20 +01:00
|
|
|
return QRect(width() - kCatWidth, (height() - kCatHeight) / 2, kCatWidth,
|
|
|
|
kCatHeight);
|
2012-10-16 12:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline QRect SleepingCatDestRect() const {
|
|
|
|
return QRect(width() - kCatWidth, (height() - kSleepingCatHeight) / 2,
|
|
|
|
kCatWidth, kSleepingCatHeight);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-06-23 22:36:38 +02:00
|
|
|
// "constants" that get initialised in the constructor
|
2011-06-23 22:36:30 +02:00
|
|
|
float band_scale_[kRainbowBands];
|
2011-06-23 22:36:38 +02:00
|
|
|
QPen colors_[kRainbowBands];
|
|
|
|
|
|
|
|
// Nyan cat!
|
|
|
|
QPixmap cat_;
|
2011-06-23 22:36:30 +02:00
|
|
|
|
2011-06-23 22:36:38 +02:00
|
|
|
// For the nyan cat animation
|
2011-06-23 01:25:08 +02:00
|
|
|
int timer_id_;
|
|
|
|
int frame_;
|
|
|
|
|
2011-06-23 22:36:38 +02:00
|
|
|
// The y positions of each point on the rainbow.
|
2011-06-23 01:25:08 +02:00
|
|
|
float history_[kHistorySize * kRainbowBands];
|
2011-06-23 22:36:38 +02:00
|
|
|
|
|
|
|
// A cache of the last frame's rainbow, so it can be used in the next frame.
|
2011-12-01 18:29:27 +01:00
|
|
|
QPixmap buffer_[2];
|
|
|
|
int current_buffer_;
|
2011-06-23 15:21:08 +02:00
|
|
|
|
2011-06-24 00:49:33 +02:00
|
|
|
// Geometry information that's updated on resize:
|
|
|
|
// The width of the widget minus the space for the cat
|
|
|
|
int available_rainbow_width_;
|
|
|
|
|
|
|
|
// X spacing between each point in the polyline.
|
|
|
|
int px_per_frame_;
|
|
|
|
|
|
|
|
// Amount the buffer_ is shifted to the left (off the edge of the widget) to
|
|
|
|
// make the rainbow extend from 0 to available_rainbow_width_.
|
|
|
|
int x_offset_;
|
|
|
|
|
2011-06-23 15:21:08 +02:00
|
|
|
QBrush background_brush_;
|
2011-06-23 01:25:08 +02:00
|
|
|
};
|
|
|
|
|
2014-11-29 20:07:01 +01:00
|
|
|
#endif // ANALYZERS_NYANCATANALYZER_H_
|