Lumiera  0.pre.03
»edit your freedom«
zoom-metric.hpp
Go to the documentation of this file.
1 /*
2  ZOOM-METRIC.hpp - mix-in to provide a DisplayMetric based on a ZoomWindow
3 
4  Copyright (C) Lumiera.org
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
46 #ifndef STAGE_MODEL_ZOOM_METRIC_H
47 #define STAGE_MODEL_ZOOM_METRIC_H
48 
49 
50 #include "lib/time/timevalue.hpp"
51 #include "lib/meta/trait.hpp"
54 
55 
56 
57 namespace stage {
58 namespace model {
59 
61  using lib::time::TimeSpan;
62  using lib::time::Offset;
63  using lib::time::Time;
64 
65 
72  template<class I>
73  class ZoomMetric
74  : public I
75  {
77 
78  protected:
79  ZoomWindow zoomWindow_;
80 
81  ZoomMetric()
82  : zoomWindow_{}
83  { }
84 
85 
86  public:
87  /* ==== Interface : DisplayMetric ==== */
88 
89  TimeSpan
90  coveredTime() const override
91  {
92  return zoomWindow_.overallSpan();
93  }
94 
95  int
96  translateTimeToPixels (TimeValue startTimePoint) const override
97  {
98  return ZoomMetric::translateScreenDelta (Offset{zoomWindow_.overallSpan().start(), startTimePoint});
99  }
100 
101  int
102  translateScreenDelta (Offset timeOffset) const override
103  {
104  auto pxOffset = rational_cast<int64_t> (zoomWindow_.px_per_sec() * _FSecs(timeOffset));
105  // // use 64-bit for the division to prevent numeric-wrap...
106  REQUIRE (abs (pxOffset) <= std::numeric_limits<int>::max());
107  return int(pxOffset);
108  }
109 
110  TimeValue
111  applyScreenDelta(Time anchor, double deltaPx) const override
112  {
113  return anchor + Offset{int64_t(deltaPx) / zoomWindow_.px_per_sec()};
114  }
115  };
116 
117 
118 }} // namespace stage::model
119 #endif /*STAGE_MODEL_ZOOM_METRIC_H*/
Mix-In to implement the DisplayMetric interface on top of a ZoomWindow component, directly embedded h...
Definition: zoom-metric.hpp:73
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Specialised (abstracted) presentation context with positioning by coordinates.
A component to ensure uniform handling of zoom scale and visible interval on the timeline.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Helpers for type detection, type rewriting and metaprogramming.
Offset measures a distance in time.
Definition: timevalue.hpp:367
Abstraction: the current zoom- and navigation state of a view, possibly in multiple dimensions...
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
verify compliance to an interface by subtype check
Definition: trait.hpp:318
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142