Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
47#include "lib/nocopy.hpp"
48#include "lib/util.hpp"
49
50#include <utility>
51
52
53namespace stage {
54namespace model {
55
56 using lib::time::Time;
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 {
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 {
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*/
Offset measures a distance in time.
A time interval anchored at a specific point in time.
basic constant internal time value.
Lumiera's internal time value datatype.
Interface to represent _"some presentation layout entity",_ with the ability to place widgets (manage...
virtual ~CanvasHook()
this is an interface
virtual void move(WID &widget, int xPos, int yPos)=0
virtual void hook(WID &widget, int xPos, int yPos)=0
Pos hookedAt(Time start, int downshift=0)
build the "construction hook" for a CanvasHooked element, which is to be attached to some timeline ca...
virtual CanvasHook< WID > & getAnchorHook() noexcept
Anchor point to build chains of related View Hooks.
virtual void remove(WID &widget)=0
virtual DisplayMetric & getMetric() const =0
access the component to handle layout metric
Pos hookedAt(int x, int y)
A widget attached onto a display canvas or similar central presentation context.
CanvasHooked(typename Canvas::Pos attachmentPos, ARGS &&...args)
CanvasHook< BASE > Canvas
void moveTo(int xPos, int yPos)
Mix-in interface to allow for concrete CanvasHooked widgets to adapt themselves to the metric current...
virtual TimeSpan coveredTime() const =0
the overall time Duration covered by this timeline canvas
virtual int translateScreenDelta(Offset) const =0
translate a temporal offset into a pixel Δ
virtual TimeValue applyScreenDelta(Time anchor, double deltaPx) const =0
translate an offset in pixel coordinates into a temporal position
virtual int translateTimeToPixels(TimeValue) const =0
extension point for time axis zoom management.
virtual ~DisplayMetric()
this is an interface
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
#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:267
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
STL namespace.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
a family of time value like entities and their relationships.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...