comparison view/View.cpp @ 1375:694004228ab7 zoom

Fix incorrect start/end overlay drawing when zoomed far in
author Chris Cannam
date Tue, 06 Nov 2018 10:51:46 +0000
parents bbeffb29bf09
children 28075cc658c9
comparison
equal deleted inserted replaced
1374:631897ba9fca 1375:694004228ab7
393 // the given frame, i.e. to the "left" of it - not necessarily the 393 // the given frame, i.e. to the "left" of it - not necessarily the
394 // nearest boundary. 394 // nearest boundary.
395 395
396 sv_frame_t level = m_zoomLevel.level; 396 sv_frame_t level = m_zoomLevel.level;
397 sv_frame_t fdiff = frame - getCentreFrame(); 397 sv_frame_t fdiff = frame - getCentreFrame();
398 int diff, result; 398 int result = 0;
399 399
400 bool inRange = false;
400 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) { 401 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) {
401 diff = int(fdiff / level); 402 inRange = ((fdiff / level) < sv_frame_t(INT_MAX) &&
402 if ((fdiff < 0) && ((fdiff % level) != 0)) { 403 (fdiff / level) > sv_frame_t(INT_MIN));
403 --diff; // round to the left
404 }
405 } else { 404 } else {
406 diff = int(fdiff * level); 405 inRange = (fdiff < sv_frame_t(INT_MAX) / level &&
407 } 406 fdiff > sv_frame_t(INT_MIN) / level);
408 407 }
409 result = int(diff + (width()/2)); 408
409 if (inRange) {
410
411 sv_frame_t adjusted;
412
413 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) {
414 adjusted = fdiff / level;
415 if ((fdiff < 0) && ((fdiff % level) != 0)) {
416 --adjusted; // round to the left
417 }
418 } else {
419 adjusted = fdiff * level;
420 }
421
422 adjusted = adjusted + (width()/2);
423
424 if (adjusted > INT_MAX || adjusted < INT_MIN) {
425 inRange = false;
426 } else {
427 result = int(adjusted);
428 }
429 }
430
431 if (!inRange) {
432 SVCERR << "ERROR: Frame " << frame
433 << " is out of range in View::getXForFrame" << endl;
434 SVCERR << "ERROR: (centre frame = " << getCentreFrame() << ", fdiff = "
435 << fdiff << ", zoom level = " << m_zoomLevel << ")" << endl;
436 SVCERR << "ERROR: This is a logic error: getXForFrame should not be "
437 << "called for locations unadjacent to the current view"
438 << endl;
439 return 0;
440 }
441
410 return result; 442 return result;
411 } 443 }
412 444
413 sv_frame_t 445 sv_frame_t
414 View::getFrameForX(int x) const 446 View::getFrameForX(int x) const