1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// (c) 2004 Max Howell ([email protected])
// See COPYING file for licensing information
#ifndef ANALYZER_H
#define ANALYZER_H
#ifdef __FreeBSD__
#include <sys/types.h>
#endif
#include "fht.h"
#include <tqpixmap.h> //stack allocated and convenience
#include <tqtimer.h> //stack allocated
#include <tqwidget.h> //baseclass
#include <vector> //included for convenience
namespace Analyzer
{
typedef std::vector<float> Scope;
template<class W> class Base : public W
{
public:
uint timeout() const { return m_timeout; }
protected:
Base( TQWidget*, uint, uint = 7 );
~Base() { delete m_fht; }
void drawFrame();
virtual void transform( Scope& ) = 0;
virtual void analyze( const Scope& ) = 0;
virtual void demo();
private:
virtual bool event( TQEvent* );
protected:
TQTimer m_timer;
uint m_timeout;
FHT *m_fht;
};
class Base2D : public Base<TQWidget>
{
TQ_OBJECT
public:
const TQPixmap *background() const { return &m_background; }
const TQPixmap *canvas() const { return &m_canvas; }
private slots:
void draw() { drawFrame(); bitBlt(this, 0, 0, canvas()); }
protected:
Base2D( TQWidget*, uint timeout, uint scopeSize = 7 );
TQPixmap *background() { return &m_background; }
TQPixmap *canvas() { return &m_canvas; }
void eraseCanvas()
{
bitBlt(canvas(), 0, 0, background());
}
void paintEvent( TQPaintEvent* ) override { if( !m_canvas.isNull() ) bitBlt( this, 0, 0, canvas() ); }
void resizeEvent( TQResizeEvent* ) override;
void paletteChange( const TQPalette& ) override;
private:
TQPixmap m_background;
TQPixmap m_canvas;
};
class Block : public Analyzer::Base2D
{
public:
explicit Block( TQWidget* );
static constexpr int HEIGHT = 2;
static constexpr int FADE_SIZE = 90;
static constexpr int MIN_COLUMNS = 32;
static constexpr int MAX_COLUMNS = 256;
static constexpr int MIN_ROWS = 3;
static constexpr int WIDTH = 4;
protected:
virtual void transform( Analyzer::Scope& );
virtual void analyze( const Analyzer::Scope& );
void paletteChange(const TQPalette&) override;
void resizeEvent(TQResizeEvent *) override;
void determineStep();
void drawBackground();
private:
TQPixmap *bar()
{
return &m_barPixmap;
}
// So we don't create a vector each frame.
Scope m_scope;
TQPixmap m_barPixmap;
TQPixmap m_topBarPixmap;
// Current bar heights
std::vector<float> m_store;
std::vector<float> m_yScale;
std::vector<TQPixmap> m_fadeBars;
std::vector<int> m_fadeIntensity;
std::vector<unsigned> m_fadePos;
// Number of rows and columns of blocks
unsigned m_columns;
unsigned m_rows;
// y-offset from top of widget
unsigned m_y;
// rows to fall per-step
float m_step;
};
void interpolate(const Scope&, Scope&);
}
#endif
|