author | simon <simon> | 2002-12-11 17:50:15 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 17:50:15 (UTC) |
commit | 7c897dfbee81f0fabce4b1a8de4ebab70f3783ee (patch) (unidiff) | |
tree | ec8571ae41c07f78ec697b57f42ebb2d3af947b2 /noncore/multimedia/opieplayer2 | |
parent | 483e550c75f935706fde4e0ca29c4486aeca09a0 (diff) | |
download | opie-7c897dfbee81f0fabce4b1a8de4ebab70f3783ee.zip opie-7c897dfbee81f0fabce4b1a8de4ebab70f3783ee.tar.gz opie-7c897dfbee81f0fabce4b1a8de4ebab70f3783ee.tar.bz2 |
- restructing a bit the skin data storage, in preparation for cache
improvements
Diffstat (limited to 'noncore/multimedia/opieplayer2') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 57 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 11 |
2 files changed, 41 insertions, 27 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index cef3259..9ad5f3f 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -27,6 +27,17 @@ | |||
27 | 27 | ||
28 | #include <assert.h> | 28 | #include <assert.h> |
29 | 29 | ||
30 | struct SkinData | ||
31 | { | ||
32 | typedef QMap<QString, QImage> ButtonMaskImageMap; | ||
33 | |||
34 | QImage backgroundImage; | ||
35 | QImage buttonUpImage; | ||
36 | QImage buttonDownImage; | ||
37 | QImage buttonMask; | ||
38 | ButtonMaskImageMap buttonMasks; | ||
39 | }; | ||
40 | |||
30 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 41 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
31 | : m_fileNameInfix( fileNameInfix ) | 42 | : m_fileNameInfix( fileNameInfix ) |
32 | { | 43 | { |
@@ -39,9 +50,15 @@ Skin::Skin( const QString &fileNameInfix ) | |||
39 | init( defaultSkinName() ); | 50 | init( defaultSkinName() ); |
40 | } | 51 | } |
41 | 52 | ||
53 | Skin::~Skin() | ||
54 | { | ||
55 | delete d; | ||
56 | } | ||
57 | |||
42 | void Skin::init( const QString &name ) | 58 | void Skin::init( const QString &name ) |
43 | { | 59 | { |
44 | m_skinPath = "opieplayer2/skins/" + name; | 60 | m_skinPath = "opieplayer2/skins/" + name; |
61 | d = new SkinData; | ||
45 | } | 62 | } |
46 | 63 | ||
47 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) | 64 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) |
@@ -54,39 +71,39 @@ void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint butt | |||
54 | 71 | ||
55 | QImage Skin::backgroundImage() const | 72 | QImage Skin::backgroundImage() const |
56 | { | 73 | { |
57 | if ( m_backgroundImage.isNull() ) | 74 | if ( d->backgroundImage.isNull() ) |
58 | m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); | 75 | d->backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); |
59 | return m_backgroundImage; | 76 | return d->backgroundImage; |
60 | } | 77 | } |
61 | 78 | ||
62 | QImage Skin::buttonUpImage() const | 79 | QImage Skin::buttonUpImage() const |
63 | { | 80 | { |
64 | if ( m_buttonUpImage.isNull() ) | 81 | if ( d->buttonUpImage.isNull() ) |
65 | m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 82 | d->buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
66 | return m_buttonUpImage; | 83 | return d->buttonUpImage; |
67 | } | 84 | } |
68 | 85 | ||
69 | QImage Skin::buttonDownImage() const | 86 | QImage Skin::buttonDownImage() const |
70 | { | 87 | { |
71 | if ( m_buttonDownImage.isNull() ) | 88 | if ( d->buttonDownImage.isNull() ) |
72 | m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 89 | d->buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
73 | return m_buttonDownImage; | 90 | return d->buttonDownImage; |
74 | } | 91 | } |
75 | 92 | ||
76 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const | 93 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const |
77 | { | 94 | { |
78 | if ( !m_buttonMask.isNull() ) | 95 | if ( !d->buttonMask.isNull() ) |
79 | return m_buttonMask; | 96 | return d->buttonMask; |
80 | 97 | ||
81 | QSize buttonAreaSize = buttonUpImage().size(); | 98 | QSize buttonAreaSize = buttonUpImage().size(); |
82 | 99 | ||
83 | m_buttonMask = QImage( buttonAreaSize, 8, 255 ); | 100 | d->buttonMask = QImage( buttonAreaSize, 8, 255 ); |
84 | m_buttonMask.fill( 0 ); | 101 | d->buttonMask.fill( 0 ); |
85 | 102 | ||
86 | for ( uint i = 0; i < buttonCount; ++i ) | 103 | for ( uint i = 0; i < buttonCount; ++i ) |
87 | addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); | 104 | addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); |
88 | 105 | ||
89 | return m_buttonMask; | 106 | return d->buttonMask; |
90 | } | 107 | } |
91 | 108 | ||
92 | void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | 109 | void Skin::addButtonToMask( int tag, const QImage &maskImage ) const |
@@ -94,10 +111,10 @@ void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | |||
94 | if ( maskImage.isNull() ) | 111 | if ( maskImage.isNull() ) |
95 | return; | 112 | return; |
96 | 113 | ||
97 | uchar **dest = m_buttonMask.jumpTable(); | 114 | uchar **dest = d->buttonMask.jumpTable(); |
98 | for ( int y = 0; y < m_buttonMask.height(); y++ ) { | 115 | for ( int y = 0; y < d->buttonMask.height(); y++ ) { |
99 | uchar *line = dest[y]; | 116 | uchar *line = dest[y]; |
100 | for ( int x = 0; x < m_buttonMask.width(); x++ ) | 117 | for ( int x = 0; x < d->buttonMask.width(); x++ ) |
101 | if ( !qRed( maskImage.pixel( x, y ) ) ) | 118 | if ( !qRed( maskImage.pixel( x, y ) ) ) |
102 | line[x] = tag; | 119 | line[x] = tag; |
103 | } | 120 | } |
@@ -105,11 +122,11 @@ void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | |||
105 | 122 | ||
106 | QImage Skin::buttonMaskImage( const QString &fileName ) const | 123 | QImage Skin::buttonMaskImage( const QString &fileName ) const |
107 | { | 124 | { |
108 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); | 125 | SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); |
109 | if ( it == m_buttonMasks.end() ) { | 126 | if ( it == d->buttonMasks.end() ) { |
110 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); | 127 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); |
111 | QString path = prefix + fileName + ".png"; | 128 | QString path = prefix + fileName + ".png"; |
112 | it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); | 129 | it = d->buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); |
113 | } | 130 | } |
114 | return *it; | 131 | return *it; |
115 | } | 132 | } |
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index 9f7326e..5ab6574 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -32,11 +32,14 @@ | |||
32 | #include "threadutil.h" | 32 | #include "threadutil.h" |
33 | #include "singleton.h" | 33 | #include "singleton.h" |
34 | 34 | ||
35 | struct SkinData; | ||
36 | |||
35 | class Skin | 37 | class Skin |
36 | { | 38 | { |
37 | public: | 39 | public: |
38 | Skin( const QString &name, const QString &fileNameInfix ); | 40 | Skin( const QString &name, const QString &fileNameInfix ); |
39 | Skin( const QString &fileNameInfix ); | 41 | Skin( const QString &fileNameInfix ); |
42 | ~Skin(); | ||
40 | 43 | ||
41 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); | 44 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); |
42 | 45 | ||
@@ -58,13 +61,7 @@ private: | |||
58 | QString m_fileNameInfix; | 61 | QString m_fileNameInfix; |
59 | QString m_skinPath; | 62 | QString m_skinPath; |
60 | 63 | ||
61 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 64 | SkinData *d; |
62 | |||
63 | mutable QImage m_backgroundImage; | ||
64 | mutable QImage m_buttonUpImage; | ||
65 | mutable QImage m_buttonDownImage; | ||
66 | mutable QImage m_buttonMask; | ||
67 | mutable ButtonMaskImageMap m_buttonMasks; | ||
68 | 65 | ||
69 | Skin( const Skin & ); | 66 | Skin( const Skin & ); |
70 | Skin &operator=( const Skin & ); | 67 | Skin &operator=( const Skin & ); |