Mercurial > hg > svgui
comparison layer/ScrollableImageCache.cpp @ 1118:175d4e15884d spectrogram-minor-refactor
Introduce ScrollableMagRangeCache, plus some tidying etc
author | Chris Cannam |
---|---|
date | Wed, 20 Jul 2016 08:30:20 +0100 |
parents | 261a00010918 |
children | 94370157b265 |
comparison
equal
deleted
inserted
replaced
1117:64709d4d09ef | 1118:175d4e15884d |
---|---|
43 } | 43 } |
44 | 44 |
45 int w = m_image.width(); | 45 int w = m_image.width(); |
46 | 46 |
47 if (dx == 0) { | 47 if (dx == 0) { |
48 // haven't moved visibly | 48 // haven't moved visibly (even though start frame may have changed) |
49 return; | 49 return; |
50 } | 50 } |
51 | 51 |
52 if (dx <= -w || dx >= w) { | 52 if (dx <= -w || dx >= w) { |
53 // scrolled entirely off | 53 // scrolled entirely off |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 // update valid area | 73 // update valid area |
74 | 74 |
75 int px = m_left; | 75 int px = m_validLeft; |
76 int pw = m_width; | 76 int pw = m_validWidth; |
77 | 77 |
78 px += dx; | 78 px += dx; |
79 | 79 |
80 if (dx < 0) { | 80 if (dx < 0) { |
81 // we scrolled left | 81 // we scrolled left |
94 pw = 0; | 94 pw = 0; |
95 } | 95 } |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 m_left = px; | 99 m_validLeft = px; |
100 m_width = pw; | 100 m_validWidth = pw; |
101 } | 101 } |
102 | 102 |
103 void | 103 void |
104 ScrollableImageCache::adjustToTouchValidArea(int &left, int &width, | 104 ScrollableImageCache::adjustToTouchValidArea(int &left, int &width, |
105 bool &isLeftOfValidArea) const | 105 bool &isLeftOfValidArea) const |
106 { | 106 { |
107 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE | 107 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE |
108 cerr << "ScrollableImageCache::adjustToTouchValidArea: left " << left | 108 cerr << "ScrollableImageCache::adjustToTouchValidArea: left " << left |
109 << ", width " << width << endl; | 109 << ", width " << width << endl; |
110 cerr << "ScrollableImageCache: my left " << m_left | 110 cerr << "ScrollableImageCache: my left " << m_validLeft |
111 << ", width " << m_width << " so right " << (m_left + m_width) << endl; | 111 << ", width " << m_validWidth << " so right " << (m_validLeft + m_validWidth) << endl; |
112 #endif | 112 #endif |
113 if (left < m_left) { | 113 if (left < m_validLeft) { |
114 isLeftOfValidArea = true; | 114 isLeftOfValidArea = true; |
115 if (left + width <= m_left + m_width) { | 115 if (left + width <= m_validLeft + m_validWidth) { |
116 width = m_left - left; | 116 width = m_validLeft - left; |
117 } | 117 } |
118 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE | 118 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE |
119 cerr << "ScrollableImageCache: we're left of valid area, adjusted width to " << width << endl; | 119 cerr << "ScrollableImageCache: we're left of valid area, adjusted width to " << width << endl; |
120 #endif | 120 #endif |
121 } else { | 121 } else { |
122 isLeftOfValidArea = false; | 122 isLeftOfValidArea = false; |
123 width = left + width - (m_left + m_width); | 123 width = left + width - (m_validLeft + m_validWidth); |
124 left = m_left + m_width; | 124 left = m_validLeft + m_validWidth; |
125 if (width < 0) width = 0; | 125 if (width < 0) width = 0; |
126 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE | 126 #ifdef DEBUG_SCROLLABLE_IMAGE_CACHE |
127 cerr << "ScrollableImageCache: we're right of valid area, adjusted left to " << left << ", width to " << width << endl; | 127 cerr << "ScrollableImageCache: we're right of valid area, adjusted left to " << left << ", width to " << width << endl; |
128 #endif | 128 #endif |
129 } | 129 } |
162 image, | 162 image, |
163 QRect(imageLeft, 0, imageWidth, image.height())); | 163 QRect(imageLeft, 0, imageWidth, image.height())); |
164 painter.end(); | 164 painter.end(); |
165 | 165 |
166 if (!isValid()) { | 166 if (!isValid()) { |
167 m_left = left; | 167 m_validLeft = left; |
168 m_width = width; | 168 m_validWidth = width; |
169 return; | 169 return; |
170 } | 170 } |
171 | 171 |
172 if (left < m_left) { | 172 if (left < m_validLeft) { |
173 if (left + width > m_left + m_width) { | 173 if (left + width > m_validLeft + m_validWidth) { |
174 // new image completely contains the old valid area -- | 174 // new image completely contains the old valid area -- |
175 // use the new area as is | 175 // use the new area as is |
176 m_left = left; | 176 m_validLeft = left; |
177 m_width = width; | 177 m_validWidth = width; |
178 } else if (left + width < m_left) { | 178 } else if (left + width < m_validLeft) { |
179 // new image completely off left of old valid area -- | 179 // new image completely off left of old valid area -- |
180 // we can't extend the valid area because the bit in | 180 // we can't extend the valid area because the bit in |
181 // between is not valid, so must use the new area only | 181 // between is not valid, so must use the new area only |
182 m_left = left; | 182 m_validLeft = left; |
183 m_width = width; | 183 m_validWidth = width; |
184 } else { | 184 } else { |
185 // new image overlaps old valid area on left side -- | 185 // new image overlaps old valid area on left side -- |
186 // use new left edge, and extend width to existing | 186 // use new left edge, and extend width to existing |
187 // right edge | 187 // right edge |
188 m_width = (m_left + m_width) - left; | 188 m_validWidth = (m_validLeft + m_validWidth) - left; |
189 m_left = left; | 189 m_validLeft = left; |
190 } | 190 } |
191 } else { | 191 } else { |
192 if (left > m_left + m_width) { | 192 if (left > m_validLeft + m_validWidth) { |
193 // new image completely off right of old valid area -- | 193 // new image completely off right of old valid area -- |
194 // we can't extend the valid area because the bit in | 194 // we can't extend the valid area because the bit in |
195 // between is not valid, so must use the new area only | 195 // between is not valid, so must use the new area only |
196 m_left = left; | 196 m_validLeft = left; |
197 m_width = width; | 197 m_validWidth = width; |
198 } else if (left + width > m_left + m_width) { | 198 } else if (left + width > m_validLeft + m_validWidth) { |
199 // new image overlaps old valid area on right side -- | 199 // new image overlaps old valid area on right side -- |
200 // use existing left edge, and extend width to new | 200 // use existing left edge, and extend width to new |
201 // right edge | 201 // right edge |
202 m_width = (left + width) - m_left; | 202 m_validWidth = (left + width) - m_validLeft; |
203 // (m_left unchanged) | 203 // (m_validLeft unchanged) |
204 } else { | 204 } else { |
205 // new image completely contained within old valid | 205 // new image completely contained within old valid |
206 // area -- leave the old area unchanged | 206 // area -- leave the old area unchanged |
207 } | 207 } |
208 } | 208 } |