~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/analyzers/nyancatanalyzer.h

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
4
   Clementine is free software: you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation, either version 3 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   Clementine is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef NYANCATANALYZER_H
 
19
#define NYANCATANALYZER_H
 
20
 
 
21
#include "analyzerbase.h"
 
22
 
 
23
#include <QDateTime>
 
24
 
 
25
class NyanCatAnalyzer : public Analyzer::Base {
 
26
  Q_OBJECT
 
27
 
 
28
public:
 
29
  Q_INVOKABLE NyanCatAnalyzer(QWidget* parent);
 
30
 
 
31
  static const char* kName;
 
32
 
 
33
protected:
 
34
  void transform(Scope&);
 
35
  void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
 
36
 
 
37
  void timerEvent(QTimerEvent* e);
 
38
  void resizeEvent(QResizeEvent* e);
 
39
 
 
40
private:
 
41
  static const int kCatHeight = 21;
 
42
  static const int kCatWidth = 34;
 
43
  static const int kCatFrameCount = 5;
 
44
  static const int kRainbowOverlap = 13;
 
45
 
 
46
  static const int kHistorySize = 128;
 
47
  static const int kRainbowBands = 6;
 
48
  static const float kPixelScale;
 
49
 
 
50
  static const int kFrameIntervalMs = 150;
 
51
 
 
52
private:
 
53
  inline QRect CatSourceRect() const {
 
54
    return QRect(0, kCatHeight * frame_, kCatWidth, kCatHeight);
 
55
  }
 
56
 
 
57
private:
 
58
  // "constants" that get initialised in the constructor
 
59
  float band_scale_[kRainbowBands];
 
60
  QPen colors_[kRainbowBands];
 
61
 
 
62
  // Nyan cat!
 
63
  QPixmap cat_;
 
64
 
 
65
  // For the nyan cat animation
 
66
  int timer_id_;
 
67
  int frame_;
 
68
 
 
69
  // The y positions of each point on the rainbow.
 
70
  float history_[kHistorySize * kRainbowBands];
 
71
 
 
72
  // A cache of the last frame's rainbow, so it can be used in the next frame.
 
73
  QPixmap buffer_[2];
 
74
  int current_buffer_;
 
75
 
 
76
  // Geometry information that's updated on resize:
 
77
  // The width of the widget minus the space for the cat
 
78
  int available_rainbow_width_;
 
79
 
 
80
  // X spacing between each point in the polyline.
 
81
  int px_per_frame_;
 
82
 
 
83
  // Amount the buffer_ is shifted to the left (off the edge of the widget) to
 
84
  // make the rainbow extend from 0 to available_rainbow_width_.
 
85
  int x_offset_;
 
86
 
 
87
  QBrush background_brush_;
 
88
};
 
89
 
 
90
#endif // NYANCATANALYZER_H