Mercurial > hg > svgui
comparison layer/SingleColourLayer.cpp @ 367:06360ed99cd1
* Further fixes to the handling of playback frame and buffered frame counts
author | Chris Cannam |
---|---|
date | Mon, 11 Feb 2008 12:46:39 +0000 |
parents | a55affd7ab6c |
children | e1a9e478b7f2 |
comparison
equal
deleted
inserted
replaced
366:a55affd7ab6c | 367:06360ed99cd1 |
---|---|
20 #include <iostream> | 20 #include <iostream> |
21 | 21 |
22 #include <QTextStream> | 22 #include <QTextStream> |
23 #include <QApplication> | 23 #include <QApplication> |
24 | 24 |
25 //#define DEBUG_COLOUR_SELECTION 1 | |
26 | |
25 SingleColourLayer::ColourRefCount | 27 SingleColourLayer::ColourRefCount |
26 SingleColourLayer::m_colourRefCount; | 28 SingleColourLayer::m_colourRefCount; |
27 | 29 |
28 SingleColourLayer::SingleColourLayer() : | 30 SingleColourLayer::SingleColourLayer() : |
29 m_colour(0), | 31 m_colour(0), |
124 } | 126 } |
125 | 127 |
126 void | 128 void |
127 SingleColourLayer::setDefaultColourFor(View *v) | 129 SingleColourLayer::setDefaultColourFor(View *v) |
128 { | 130 { |
131 #ifdef DEBUG_COLOUR_SELECTION | |
129 std::cerr << "SingleColourLayer::setDefaultColourFor: m_colourExplicitlySet = " << m_colourExplicitlySet << ", m_defaultColourSet " << m_defaultColourSet << std::endl; | 132 std::cerr << "SingleColourLayer::setDefaultColourFor: m_colourExplicitlySet = " << m_colourExplicitlySet << ", m_defaultColourSet " << m_defaultColourSet << std::endl; |
133 #endif | |
130 | 134 |
131 if (m_colourExplicitlySet || m_defaultColourSet) return; | 135 if (m_colourExplicitlySet || m_defaultColourSet) return; |
136 | |
137 if (v) m_defaultColourSet = true; // v==0 case doesn't really count | |
132 | 138 |
133 bool dark = false; | 139 bool dark = false; |
134 if (v) { | 140 if (v) { |
135 dark = !v->hasLightBackground(); | 141 dark = !v->hasLightBackground(); |
136 } else { | 142 } else { |
149 } | 155 } |
150 // We don't want to call this if !v because that probably | 156 // We don't want to call this if !v because that probably |
151 // means we're being called from the constructor, and this is | 157 // means we're being called from the constructor, and this is |
152 // a virtual function | 158 // a virtual function |
153 hint = getDefaultColourHint(dark, impose); | 159 hint = getDefaultColourHint(dark, impose); |
154 // std::cerr << "hint = " << hint << ", impose = " << impose << std::endl; | 160 #ifdef DEBUG_COLOUR_SELECTION |
155 } else { | 161 std::cerr << "hint = " << hint << ", impose = " << impose << std::endl; |
156 // std::cerr << "(from ctor)" << std::endl; | 162 #endif |
163 } else { | |
164 #ifdef DEBUG_COLOUR_SELECTION | |
165 std::cerr << "(from ctor)" << std::endl; | |
166 #endif | |
157 } | 167 } |
158 | 168 |
159 if (hint >= 0 && impose) { | 169 if (hint >= 0 && impose) { |
160 setBaseColour(hint); | 170 setBaseColour(hint); |
161 m_defaultColourSet = true; | |
162 return; | 171 return; |
163 } | 172 } |
164 | 173 |
165 int bestCount = 0, bestColour = -1; | 174 int bestCount = 0, bestColour = -1; |
166 | 175 |
173 int count = 0; | 182 int count = 0; |
174 if (m_colourRefCount.find(index) != m_colourRefCount.end()) { | 183 if (m_colourRefCount.find(index) != m_colourRefCount.end()) { |
175 count = m_colourRefCount[index]; | 184 count = m_colourRefCount[index]; |
176 } | 185 } |
177 | 186 |
178 // std::cerr << "index = " << index << ", count = " << count; | 187 #ifdef DEBUG_COLOUR_SELECTION |
188 std::cerr << "index = " << index << ", count = " << count; | |
189 #endif | |
179 | 190 |
180 if (bestColour < 0 || count < bestCount) { | 191 if (bestColour < 0 || count < bestCount) { |
181 bestColour = index; | 192 bestColour = index; |
182 bestCount = count; | 193 bestCount = count; |
183 // std::cerr << " *"; | 194 #ifdef DEBUG_COLOUR_SELECTION |
184 } | 195 std::cerr << " *"; |
185 | 196 #endif |
186 // std::cerr << std::endl; | 197 } |
198 | |
199 #ifdef DEBUG_COLOUR_SELECTION | |
200 std::cerr << std::endl; | |
201 #endif | |
187 } | 202 } |
188 | 203 |
189 if (bestColour < 0) m_colour = 0; | 204 if (bestColour < 0) m_colour = 0; |
190 else m_colour = bestColour; | 205 else m_colour = bestColour; |
191 | 206 |
192 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { | 207 if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) { |
193 m_colourRefCount[m_colour] = 1; | 208 m_colourRefCount[m_colour] = 1; |
194 } else { | 209 } else { |
195 m_colourRefCount[m_colour]++; | 210 m_colourRefCount[m_colour]++; |
196 } | 211 } |
197 | |
198 m_defaultColourSet = true; | |
199 } | 212 } |
200 | 213 |
201 void | 214 void |
202 SingleColourLayer::setBaseColour(int colour) | 215 SingleColourLayer::setBaseColour(int colour) |
203 { | 216 { |
293 | 306 |
294 m_colourExplicitlySet = true; | 307 m_colourExplicitlySet = true; |
295 | 308 |
296 if (m_colour != colour) { | 309 if (m_colour != colour) { |
297 | 310 |
311 #ifdef DEBUG_COLOUR_SELECTION | |
298 std::cerr << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << std::endl; | 312 std::cerr << "SingleColourLayer::setProperties: changing colour from " << m_colour << " to " << colour << std::endl; |
313 #endif | |
299 | 314 |
300 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && | 315 if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() && |
301 m_colourRefCount[m_colour] > 0) { | 316 m_colourRefCount[m_colour] > 0) { |
302 m_colourRefCount[m_colour]--; | 317 m_colourRefCount[m_colour]--; |
303 } | 318 } |