Mercurial > hg > svcore
diff base/BaseTypes.h @ 1324:d4a28d1479a8 zoom
Some hackery toward having a zoomlevel type
author | Chris Cannam |
---|---|
date | Mon, 12 Dec 2016 15:18:52 +0000 |
parents | cafd65fc411b |
children | 710e6250a401 |
line wrap: on
line diff
--- a/base/BaseTypes.h Fri Dec 09 19:04:33 2016 +0000 +++ b/base/BaseTypes.h Mon Dec 12 15:18:52 2016 +0000 @@ -12,8 +12,8 @@ COPYING included with this distribution for more information. */ -#ifndef BASE_TYPES_H -#define BASE_TYPES_H +#ifndef SV_BASE_TYPES_H +#define SV_BASE_TYPES_H #include <cstdint> @@ -46,5 +46,57 @@ */ typedef double sv_samplerate_t; + +/** Display zoom level. Can be an integer number of samples per pixel, + * or an integer number of pixels per sample. + */ +struct ZoomLevel { + + enum Zone { + FramesPerPixel, // zoomed out (as in classic SV) + PixelsPerFrame // zoomed in beyond 1-1 (interpolating the waveform) + }; + Zone zone; + int level; + + bool operator<(const ZoomLevel &other) const { + if (zone == FramesPerPixel) { + if (other.zone == zone) { + return level < other.level; + } else { + return false; + } + } else { + if (other.zone == zone) { + return level > other.level; + } else { + return false; + } + } + } + + ZoomLevel incremented() const { + if (zone == FramesPerPixel) { + return { zone, level + 1 }; + } else if (level == 1) { + return { FramesPerPixel, 2 }; + } else if (level == 2) { + return { FramesPerPixel, 1 }; + } else { + return { zone, level - 1 }; + } + } + + ZoomLevel decremented() const { + if (zone == PixelsPerFrame) { + return { zone, level + 1 }; + } else if (level == 1) { + return { PixelsPerFrame, 2 }; + } else { + return { zone, level - 1 }; + } + } +}; + #endif