1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-01-26 15:03:47 +01:00

Add and use some ZoomInfo and ViewInfo member functions, so we can eliminate...

... miscellaneous direct uses of ZoomInfo::zoom to test and set zoom level.

This includes all the remaining assignments to it.

But moving TrackInfo::PositionToTime and TrackInfo::TimeToPosition into
ZoomInfo and using them is needed to eliminate many more uses.

Also #if'd out the unused AudacityProject::OnZoomToggle().
This commit is contained in:
Paul-Licameli
2015-04-19 19:26:36 -04:00
committed by Paul Licameli
parent 8ba9ea5621
commit 5a6d5d1443
11 changed files with 174 additions and 73 deletions

View File

@@ -10,9 +10,16 @@ Paul Licameli
#include "ViewInfo.h"
#include <algorithm>
#include "Internat.h"
#include "xml/XMLWriter.h"
namespace {
static const double gMaxZoom = 6000000;
static const double gMinZoom = 0.001;
}
ZoomInfo::ZoomInfo(double start, double screenDuration, double pixelsPerSecond)
: vpos(0)
, h(start)
@@ -25,6 +32,46 @@ ZoomInfo::~ZoomInfo()
{
}
/// Converts a position (mouse X coordinate) to
/// project time, in seconds. Needs the left edge of
/// the track as an additional parameter.
double ZoomInfo::PositionToTime(wxInt64 position,
wxInt64 origin
) const
{
return h + (position - origin) / zoom;
}
/// STM: Converts a project time to screen x position.
wxInt64 ZoomInfo::TimeToPosition(double projectTime,
wxInt64 origin
) const
{
return floor(0.5 +
zoom * (projectTime - h) + origin
);
}
bool ZoomInfo::ZoomInAvailable() const
{
return zoom < gMaxZoom;
}
bool ZoomInfo::ZoomOutAvailable() const
{
return zoom > gMinZoom;
}
void ZoomInfo::SetZoom(double pixelsPerSecond)
{
zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
}
void ZoomInfo::ZoomBy(double multiplier)
{
SetZoom(zoom * multiplier);
}
ViewInfo::ViewInfo(double start, double screenDuration, double pixelsPerSecond)
: ZoomInfo(start, screenDuration, pixelsPerSecond)
@@ -40,6 +87,14 @@ ViewInfo::ViewInfo(double start, double screenDuration, double pixelsPerSecond)
{
}
void ViewInfo::SetBeforeScreenWidth(wxInt64 width, double lowerBoundTime)
{
h =
std::max(lowerBoundTime,
std::min(total - screen,
width / zoom));
}
void ViewInfo::WriteXMLAttributes(XMLWriter &xmlFile)
{
selectedRegion.WriteXMLAttributes(xmlFile, wxT("sel0"), wxT("sel1"));