Lumiera  0.pre.03
»edit your freedom«
canvas-hook.hpp
Go to the documentation of this file.
1 /*
2  CANVAS-HOOK.hpp - abstracted attachment to a canvas with free positioning
3 
4  Copyright (C)
5  2020, 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 
43 #ifndef STAGE_MODEL_CANVAS_HOOK_H
44 #define STAGE_MODEL_CANVAS_HOOK_H
45 
46 #include "lib/time/timevalue.hpp"
47 #include "lib/nocopy.hpp"
48 #include "lib/util.hpp"
49 
50 #include <utility>
51 
52 
53 namespace stage {
54 namespace model {
55 
56  using lib::time::Time;
57  using lib::time::Offset;
59  using lib::time::TimeSpan;
60 
61 
62 
74  {
75  public:
76  virtual ~DisplayMetric() { }
77 
79  virtual TimeSpan coveredTime() const =0;
80 
82  virtual int translateTimeToPixels (TimeValue) const =0;
83 
85  virtual int translateScreenDelta (Offset) const =0;
86 
92  virtual TimeValue applyScreenDelta(Time anchor, double deltaPx) const =0;
93  };
94 
95 
96 
108  template<class WID>
110  {
111  public:
112  virtual ~CanvasHook() { }
113 
114  virtual void hook (WID& widget, int xPos, int yPos) =0;
115  virtual void move (WID& widget, int xPos, int yPos) =0;
116  virtual void remove (WID& widget) =0;
117 
119  virtual DisplayMetric& getMetric() const =0;
120 
122  virtual CanvasHook<WID>&
123  getAnchorHook() noexcept
124  {
125  return *this;
126  }
127 
128  struct Pos
129  {
130  CanvasHook* view;
131  int x,y;
132  };
133 
134  Pos
135  hookedAt (int x, int y)
136  {
137  return Pos{this, x,y};
138  }
139 
145  Pos
146  hookedAt (Time start, int downshift=0)
147  {
148  return hookedAt (getMetric().translateTimeToPixels (start), downshift);
149  }
150  };
151 
152 
153 
177  template<class WID, class BASE =WID>
179  : public WID
181  {
182  using Canvas = CanvasHook<BASE>;
183  Canvas* view_;
184 
185  protected:
186  Canvas& getCanvas() const { return *view_; }
187 
188  public:
189  template<typename...ARGS>
190  CanvasHooked (typename Canvas::Pos attachmentPos, ARGS&& ...args)
191  : WID{std::forward<ARGS>(args)...}
192  , view_{attachmentPos.view}
193  {
194  getCanvas().hook (*this, attachmentPos.x, attachmentPos.y);
195  }
196 
197  ~CanvasHooked() noexcept
198  {
199  try {
200  if (view_)
201  view_->remove (*this);
202  }
203  ERROR_LOG_AND_IGNORE (progress, "Detaching of CanvasHooked widgets from the presentation")
204  }
205 
206  void
207  moveTo (int xPos, int yPos)
208  {
209  getCanvas().move (*this, xPos,yPos);
210  }
211  };
212 
213 
214 
215 }}// namespace stage::model
216 #endif /*STAGE_MODEL_CANVAS_HOOK_H*/
Mix-in interface to allow for concrete CanvasHooked widgets to adapt themselves to the metric current...
Definition: canvas-hook.hpp:73
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error...
Definition: error.hpp:266
Pos hookedAt(Time start, int downshift=0)
build the "construction hook" for a CanvasHooked element, which is to be attached to some timeline ca...
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
A widget attached onto a display canvas or similar central presentation context.
virtual ~CanvasHook()
this is an interface
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
virtual int translateTimeToPixels(TimeValue) const =0
extension point for time axis zoom management.
Interface to represent _"some presentation layout entity",_ with the ability to place widgets (manage...
Mix-Ins to allow or prohibit various degrees of copying and cloning.
virtual CanvasHook< WID > & getAnchorHook() noexcept
Anchor point to build chains of related View Hooks.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
virtual TimeValue applyScreenDelta(Time anchor, double deltaPx) const =0
translate an offset in pixel coordinates into a temporal position
virtual ~DisplayMetric()
this is an interface
Definition: canvas-hook.hpp:76
Offset measures a distance in time.
Definition: timevalue.hpp:358
virtual int translateScreenDelta(Offset) const =0
translate a temporal offset into a pixel Δ
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:573
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133
virtual TimeSpan coveredTime() const =0
the overall time Duration covered by this timeline canvas