Mercurial > hg > svgui
comparison view/View.cpp @ 1341:ab2cafd3a7cb zoom
Fixes for TimeRuler spacing and for the boundaries of the WaveformLayer paint area
author | Chris Cannam |
---|---|
date | Thu, 27 Sep 2018 15:20:25 +0100 |
parents | 9758dfc12555 |
children | 5f3e374746b6 |
comparison
equal
deleted
inserted
replaced
1340:fc3c9971a43a | 1341:ab2cafd3a7cb |
---|---|
379 } | 379 } |
380 | 380 |
381 int | 381 int |
382 View::getXForFrame(sv_frame_t frame) const | 382 View::getXForFrame(sv_frame_t frame) const |
383 { | 383 { |
384 // In FramesPerPixel mode, the pixel should be the one "covering" | |
385 // the given frame, i.e. to the "left" of it - not necessarily the | |
386 // nearest boundary. | |
387 | |
388 sv_frame_t level = m_zoomLevel.level; | |
384 sv_frame_t fdiff = frame - getCentreFrame(); | 389 sv_frame_t fdiff = frame - getCentreFrame(); |
390 int diff, result; | |
385 | 391 |
386 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) { | 392 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) { |
387 fdiff /= m_zoomLevel.level; | 393 diff = fdiff / level; |
394 if ((fdiff < 0) && ((fdiff % level) != 0)) { | |
395 --diff; // round to the left | |
396 } | |
388 } else { | 397 } else { |
389 fdiff *= m_zoomLevel.level; | 398 diff = fdiff * level; |
390 } | 399 } |
391 | 400 |
392 return int(fdiff + (width()/2)); | 401 result = int(diff + (width()/2)); |
402 return result; | |
393 } | 403 } |
394 | 404 |
395 sv_frame_t | 405 sv_frame_t |
396 View::getFrameForX(int x) const | 406 View::getFrameForX(int x) const |
397 { | 407 { |
398 // Note, this must always return a value that is on a zoom-level | 408 // Note, this must always return a value that is on a zoom-level |
399 // boundary - regardless of whether the nominal centre frame is on | 409 // boundary - regardless of whether the nominal centre frame is on |
400 // such a boundary or not | 410 // such a boundary or not. |
411 | |
412 // In PixelsPerFrame mode, the frame should be the one immediately | |
413 // left of the given pixel, not necessarily the nearest. | |
401 | 414 |
402 int diff = x - (width()/2); | 415 int diff = x - (width()/2); |
403 sv_frame_t level = m_zoomLevel.level; | 416 sv_frame_t level = m_zoomLevel.level; |
404 sv_frame_t fdiff, result; | 417 sv_frame_t fdiff, result; |
405 | 418 |
406 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) { | 419 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) { |
407 fdiff = diff * level; | 420 fdiff = diff * level; |
408 result = ((fdiff + m_centreFrame) / level) * level; | 421 result = ((fdiff + m_centreFrame) / level) * level; |
409 } else { | 422 } else { |
410 fdiff = diff / level; | 423 fdiff = diff / level; |
424 if ((diff < 0) && ((diff % level) != 0)) { | |
425 --fdiff; // round to the left | |
426 } | |
411 result = fdiff + m_centreFrame; | 427 result = fdiff + m_centreFrame; |
412 } | 428 } |
413 /* | 429 |
414 if (x == 0) { | 430 if (x == 0) { |
415 SVCERR << "getFrameForX(" << x << "): diff = " << diff << ", fdiff = " | 431 SVCERR << "getFrameForX(" << x << "): diff = " << diff << ", fdiff = " |
416 << fdiff << ", m_centreFrame = " << m_centreFrame | 432 << fdiff << ", m_centreFrame = " << m_centreFrame |
417 << ", level = " << m_zoomLevel.level | 433 << ", level = " << m_zoomLevel.level |
418 << ", diff % level = " << (diff % m_zoomLevel.level) | 434 << ", diff % level = " << (diff % m_zoomLevel.level) |
419 << ", nominal " << fdiff + m_centreFrame | 435 << ", nominal " << fdiff + m_centreFrame |
420 << ", will return " << result | 436 << ", will return " << result |
421 << endl; | 437 << endl; |
422 } | 438 } |
423 */ | 439 |
424 return result; | 440 return result; |
425 } | 441 } |
426 | 442 |
427 double | 443 double |
428 View::getYForFrequency(double frequency, | 444 View::getYForFrequency(double frequency, |