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)
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
37 #ifndef STAGE_MODEL_ZOOM_METRIC_H
38 #define STAGE_MODEL_ZOOM_METRIC_H
39 
40 
41 #include "lib/time/timevalue.hpp"
42 #include "lib/meta/trait.hpp"
45 
46 
47 
48 namespace stage {
49 namespace model {
50 
52  using lib::time::TimeSpan;
53  using lib::time::Offset;
54  using lib::time::Time;
55 
56 
63  template<class I>
64  class ZoomMetric
65  : public I
66  {
68 
69  protected:
70  ZoomWindow zoomWindow_;
71 
72  ZoomMetric()
73  : zoomWindow_{}
74  { }
75 
76 
77  public:
78  /* ==== Interface : DisplayMetric ==== */
79 
80  TimeSpan
81  coveredTime() const override
82  {
83  return zoomWindow_.overallSpan();
84  }
85 
86  int
87  translateTimeToPixels (TimeValue startTimePoint) const override
88  {
89  return ZoomMetric::translateScreenDelta (Offset{zoomWindow_.overallSpan().start(), startTimePoint});
90  }
91 
92  int
93  translateScreenDelta (Offset timeOffset) const override
94  {
95  auto pxOffset = rational_cast<int64_t> (zoomWindow_.px_per_sec() * _FSecs(timeOffset));
96  // // use 64-bit for the division to prevent numeric-wrap...
97  REQUIRE (abs (pxOffset) <= std::numeric_limits<int>::max());
98  return int(pxOffset);
99  }
100 
101  TimeValue
102  applyScreenDelta(Time anchor, double deltaPx) const override
103  {
104  return anchor + Offset{int64_t(deltaPx) / zoomWindow_.px_per_sec()};
105  }
106  };
107 
108 
109 }} // namespace stage::model
110 #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:64
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
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:37
Helpers for type detection, type rewriting and metaprogramming.
Offset measures a distance in time.
Definition: timevalue.hpp:358
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:573
verify compliance to an interface by subtype check
Definition: trait.hpp:323
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133