Changeset View
Changeset View
Standalone View
Standalone View
src/context/applets/analyzer/plugin/BlockAnalyzer.h
- This file was moved from src/context/applets/analyzer/BlockAnalyzer.h.
Show All 16 Lines | |||||
17 | 17 | | |||
18 | #ifndef BLOCKANALYZER_H | 18 | #ifndef BLOCKANALYZER_H | ||
19 | #define BLOCKANALYZER_H | 19 | #define BLOCKANALYZER_H | ||
20 | 20 | | |||
21 | #include "AnalyzerBase.h" | 21 | #include "AnalyzerBase.h" | ||
22 | 22 | | |||
23 | #include <QImage> | 23 | #include <QImage> | ||
24 | #include <QPixmap> | 24 | #include <QPixmap> | ||
25 | #include <QQuickWindow> | ||||
25 | #include <QSharedPointer> | 26 | #include <QSharedPointer> | ||
26 | #include <QSize> | 27 | #include <QSize> | ||
27 | 28 | | |||
28 | class QMouseEvent; | | |||
29 | class QPalette; | 29 | class QPalette; | ||
30 | class QResizeEvent; | 30 | class QSGTexture; | ||
31 | 31 | | |||
32 | class BlockAnalyzer : public Analyzer::Base | 32 | class BlockAnalyzer : public Analyzer::Base | ||
33 | { | 33 | { | ||
34 | friend class BlockRenderer; | ||||
35 | | ||||
36 | Q_OBJECT | ||||
37 | Q_PROPERTY(FallSpeed fallSpeed READ fallSpeed WRITE setFallSpeed NOTIFY fallSpeedChanged) | ||||
38 | Q_PROPERTY(int columnWidth READ columnWidth WRITE setColumnWidth NOTIFY columnWidthChanged) | ||||
39 | Q_PROPERTY(bool showFadebars READ showFadebars WRITE setShowFadebars NOTIFY showFadebarsChanged) | ||||
40 | | ||||
34 | public: | 41 | public: | ||
35 | BlockAnalyzer( QWidget* ); | 42 | enum FallSpeed | ||
43 | { | ||||
44 | VerySlow = 0, | ||||
45 | Slow = 1, | ||||
46 | Medium = 2, | ||||
47 | Fast = 3, | ||||
48 | VeryFast = 4 | ||||
49 | }; | ||||
50 | Q_ENUM( FallSpeed ) | ||||
36 | 51 | | |||
37 | static GLuint createTexture( const QImage &image ) { return instance->bindTexture( image ); } | 52 | BlockAnalyzer( QQuickItem *parent = Q_NULLPTR ); | ||
38 | static void freeTexture( GLuint id ) { instance->deleteTexture( id ); } | 53 | | ||
54 | Renderer* createRenderer() const Q_DECL_OVERRIDE; | ||||
55 | | ||||
56 | FallSpeed fallSpeed() const { return m_fallSpeed; } | ||||
57 | void setFallSpeed( FallSpeed fallSpeed ); | ||||
58 | int columnWidth() const { return m_columnWidth; } | ||||
59 | void setColumnWidth( int columnWidth ); | ||||
60 | bool showFadebars() const { return m_showFadebars; } | ||||
61 | void setShowFadebars( bool showFadebars ); | ||||
39 | 62 | | |||
40 | // Signed ints because most of what we compare them against are ints | 63 | // Signed ints because most of what we compare them against are ints | ||
41 | static const int BLOCK_HEIGHT = 2; | 64 | static const int BLOCK_HEIGHT = 2; | ||
42 | static const int BLOCK_WIDTH = 4; | | |||
43 | static const int MIN_ROWS = 30; //arbitrary | | |||
44 | static const int MIN_COLUMNS = 32; //arbitrary | | |||
45 | static const int MAX_COLUMNS = 256; //must be 2**n | | |||
46 | static const int FADE_SIZE = 90; | 65 | static const int FADE_SIZE = 90; | ||
47 | 66 | | |||
67 | signals: | ||||
68 | void fallSpeedChanged(); | ||||
69 | void columnWidthChanged(); | ||||
70 | void showFadebarsChanged( bool ); | ||||
71 | void stepChanged( qreal ); | ||||
72 | void rowsChanged( int ); | ||||
73 | void columnsChanged( int ); | ||||
74 | void refreshRateChanged( qreal ); | ||||
75 | | ||||
48 | protected: | 76 | protected: | ||
49 | virtual void initializeGL(); | 77 | virtual void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) Q_DECL_OVERRIDE; | ||
50 | virtual void paintGL(); | 78 | virtual Analyzer::Worker* createWorker() const Q_DECL_OVERRIDE; | ||
51 | virtual void resizeGL( int w, int h ); | | |||
52 | virtual void transform( QVector<float>& ); | | |||
53 | virtual void analyze( const QVector<float>& ); | | |||
54 | virtual void paletteChange( const QPalette& ); | 79 | virtual void paletteChange( const QPalette& ); | ||
55 | 80 | | |||
56 | void drawBackground(); | 81 | void drawBackground( const QPalette &palette ); | ||
57 | void determineStep(); | 82 | void determineStep(); | ||
58 | 83 | | |||
59 | private: | 84 | private: | ||
60 | struct Texture | 85 | void newWindow( QQuickWindow *window ); | ||
61 | { | | |||
62 | Texture( const QPixmap &pixmap ) : | | |||
63 | id( BlockAnalyzer::createTexture( pixmap.toImage().mirrored() ) ), // Flip texture vertically for OpenGL bottom-left coordinate system | | |||
64 | size( pixmap.size() ) | | |||
65 | {} | | |||
66 | Texture( const Texture& texture ) | | |||
67 | { | | |||
68 | id = texture.id; | | |||
69 | size = texture.size; | | |||
70 | } | | |||
71 | ~Texture() | | |||
72 | { | | |||
73 | BlockAnalyzer::freeTexture( id ); | | |||
74 | } | | |||
75 | | ||||
76 | GLuint id; | | |||
77 | QSize size; | | |||
78 | }; | | |||
79 | | ||||
80 | void drawTexture( Texture* texture, int x, int y, int sx, int sy ); | | |||
81 | | ||||
82 | static BlockAnalyzer* instance; | | |||
83 | 86 | | |||
84 | int m_columns, m_rows; //number of rows and columns of blocks | 87 | int m_columns, m_rows; //number of rows and columns of blocks | ||
88 | int m_columnWidth; | ||||
89 | bool m_showFadebars; | ||||
85 | QPixmap m_barPixmap; | 90 | QPixmap m_barPixmap; | ||
86 | QVector<float> m_scope; //so we don't create a vector every frame | 91 | QPixmap m_topBarPixmap; | ||
87 | QVector<float> m_store; //current bar heights | 92 | QPixmap m_backgroundPixmap; | ||
88 | QVector<float> m_yscale; | 93 | QVector<QPixmap> m_fadeBarsPixmaps; | ||
89 | 94 | bool m_pixmapsChanged; | |||
90 | QSharedPointer<Texture> m_barTexture; | | |||
91 | QSharedPointer<Texture> m_topBarTexture; | | |||
92 | QSharedPointer<Texture> m_background; | | |||
93 | QVector<QSharedPointer<Texture>> m_fade_bars; | | |||
94 | | ||||
95 | QVector<uint> m_fade_pos; | | |||
96 | QVector<int> m_fade_intensity; | | |||
97 | 95 | | |||
98 | float m_step; //rows to fall per frame | 96 | qreal m_step; //rows to fall per frame | ||
97 | FallSpeed m_fallSpeed; | ||||
99 | }; | 98 | }; | ||
100 | 99 | | |||
101 | #endif | 100 | #endif |