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) Lumiera.org
5  2020, 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 
52 #ifndef STAGE_MODEL_CANVAS_HOOK_H
53 #define STAGE_MODEL_CANVAS_HOOK_H
54 
55 #include "lib/time/timevalue.hpp"
56 #include "lib/nocopy.hpp"
57 #include "lib/util.hpp"
58 
59 #include <utility>
60 
61 
62 namespace stage {
63 namespace model {
64 
65  using lib::time::Time;
66  using lib::time::Offset;
68  using lib::time::TimeSpan;
69 
70 
71 
83  {
84  public:
85  virtual ~DisplayMetric() { }
86 
88  virtual TimeSpan coveredTime() const =0;
89 
91  virtual int translateTimeToPixels (TimeValue) const =0;
92 
94  virtual int translateScreenDelta (Offset) const =0;
95 
101  virtual TimeValue applyScreenDelta(Time anchor, double deltaPx) const =0;
102  };
103 
104 
105 
117  template<class WID>
119  {
120  public:
121  virtual ~CanvasHook() { }
122 
123  virtual void hook (WID& widget, int xPos, int yPos) =0;
124  virtual void move (WID& widget, int xPos, int yPos) =0;
125  virtual void remove (WID& widget) =0;
126 
128  virtual DisplayMetric& getMetric() const =0;
129 
131  virtual CanvasHook<WID>&
132  getAnchorHook() noexcept
133  {
134  return *this;
135  }
136 
137  struct Pos
138  {
139  CanvasHook* view;
140  int x,y;
141  };
142 
143  Pos
144  hookedAt (int x, int y)
145  {
146  return Pos{this, x,y};
147  }
148 
154  Pos
155  hookedAt (Time start, int downshift=0)
156  {
157  return hookedAt (getMetric().translateTimeToPixels (start), downshift);
158  }
159  };
160 
161 
162 
186  template<class WID, class BASE =WID>
188  : public WID
190  {
191  using Canvas = CanvasHook<BASE>;
192  Canvas* view_;
193 
194  protected:
195  Canvas& getCanvas() const { return *view_; }
196 
197  public:
198  template<typename...ARGS>
199  CanvasHooked (typename Canvas::Pos attachmentPos, ARGS&& ...args)
200  : WID{std::forward<ARGS>(args)...}
201  , view_{attachmentPos.view}
202  {
203  getCanvas().hook (*this, attachmentPos.x, attachmentPos.y);
204  }
205 
206  ~CanvasHooked() noexcept
207  {
208  try {
209  if (view_)
210  view_->remove (*this);
211  }
212  ERROR_LOG_AND_IGNORE (progress, "Detaching of CanvasHooked widgets from the presentation")
213  }
214 
215  void
216  moveTo (int xPos, int yPos)
217  {
218  getCanvas().move (*this, xPos,yPos);
219  }
220  };
221 
222 
223 
224 }}// namespace stage::model
225 #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:82
#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:275
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:46
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:308
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:46
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:85
Offset measures a distance in time.
Definition: timevalue.hpp:367
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:582
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142
virtual TimeSpan coveredTime() const =0
the overall time Duration covered by this timeline canvas