Mercurial > hg > svgui
comparison layer/ScrollableMagRangeCache.cpp @ 1411:6dc3a36d9794
Sample a column only if it is set (avoids flash of mis-ranged material when scrolling with view normalisation on)
author | Chris Cannam |
---|---|
date | Wed, 19 Dec 2018 10:40:09 +0000 |
parents | a34a2a25907c |
children |
comparison
equal
deleted
inserted
replaced
1409:24234307c9b2 | 1411:6dc3a36d9794 |
---|---|
13 */ | 13 */ |
14 | 14 |
15 #include "ScrollableMagRangeCache.h" | 15 #include "ScrollableMagRangeCache.h" |
16 | 16 |
17 #include "base/HitCount.h" | 17 #include "base/HitCount.h" |
18 #include "base/Debug.h" | |
18 | 19 |
19 #include <iostream> | 20 #include <iostream> |
20 using namespace std; | 21 using namespace std; |
21 | 22 |
22 //#define DEBUG_SCROLLABLE_MAG_RANGE_CACHE 1 | 23 //#define DEBUG_SCROLLABLE_MAG_RANGE_CACHE 1 |
29 | 30 |
30 int dx = (v->getXForFrame(m_startFrame) - | 31 int dx = (v->getXForFrame(m_startFrame) - |
31 v->getXForFrame(newStartFrame)); | 32 v->getXForFrame(newStartFrame)); |
32 | 33 |
33 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | 34 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE |
34 cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame | 35 SVDEBUG << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame |
35 << " -> " << newStartFrame << ", dx = " << dx << endl; | 36 << " -> " << newStartFrame << ", dx = " << dx << endl; |
36 #endif | 37 #endif |
37 | 38 |
38 if (m_startFrame == newStartFrame) { | 39 if (m_startFrame == newStartFrame) { |
39 // haven't moved | 40 // haven't moved |
40 count.hit(); | 41 count.hit(); |
84 m_ranges.begin() + dx, m_ranges.end()); | 85 m_ranges.begin() + dx, m_ranges.end()); |
85 m_ranges = newRanges; | 86 m_ranges = newRanges; |
86 } | 87 } |
87 | 88 |
88 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | 89 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE |
89 cerr << "maxes (" << m_ranges.size() << ") now: "; | 90 SVDEBUG << "maxes (" << m_ranges.size() << ") now: "; |
90 for (int i = 0; in_range_for(m_ranges, i); ++i) { | 91 for (int i = 0; in_range_for(m_ranges, i); ++i) { |
91 cerr << m_ranges[i].getMax() << " "; | 92 SVDEBUG << m_ranges[i].getMax() << " "; |
92 } | 93 } |
93 cerr << endl; | 94 SVDEBUG << endl; |
94 #endif | 95 #endif |
95 } | 96 } |
96 | 97 |
97 MagnitudeRange | 98 MagnitudeRange |
98 ScrollableMagRangeCache::getRange(int x, int count) const | 99 ScrollableMagRangeCache::getRange(int x, int count) const |
99 { | 100 { |
100 MagnitudeRange r; | 101 MagnitudeRange r; |
101 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | 102 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE |
102 cerr << "ScrollableMagRangeCache::getRange(" << x << ", " << count << ")" << endl; | 103 SVDEBUG << "ScrollableMagRangeCache::getRange(" << x << ", " << count << ")" << endl; |
103 #endif | 104 #endif |
104 for (int i = 0; i < count; ++i) { | 105 for (int i = 0; i < count; ++i) { |
105 r.sample(m_ranges.at(x + i)); | 106 const auto &cr = m_ranges.at(x + i); |
107 if (cr.isSet()) { | |
108 r.sample(cr); | |
109 } | |
110 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | |
111 SVDEBUG << cr.getMin() << "->" << cr.getMax() << " "; | |
112 #endif | |
106 } | 113 } |
114 #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE | |
115 SVDEBUG << endl; | |
116 #endif | |
107 return r; | 117 return r; |
108 } | 118 } |
109 | 119 |
110 void | 120 void |
111 ScrollableMagRangeCache::sampleColumn(int column, const MagnitudeRange &r) | 121 ScrollableMagRangeCache::sampleColumn(int column, const MagnitudeRange &r) |
112 { | 122 { |
113 if (!in_range_for(m_ranges, column)) { | 123 if (!in_range_for(m_ranges, column)) { |
114 cerr << "ERROR: ScrollableMagRangeCache::sampleColumn: column " << column | 124 SVCERR << "ERROR: ScrollableMagRangeCache::sampleColumn: column " << column |
115 << " is out of range for cache of width " << m_ranges.size() | 125 << " is out of range for cache of width " << m_ranges.size() |
116 << " (with start frame " << m_startFrame << ")" << endl; | 126 << " (with start frame " << m_startFrame << ")" << endl; |
117 throw logic_error("column out of range"); | 127 throw logic_error("column out of range"); |
118 } else { | 128 } else { |
119 m_ranges[column].sample(r); | 129 m_ranges[column].sample(r); |
120 } | 130 } |
121 } | 131 } |