Lumiera  0.pre.03
»edit your freedom«
cmd-context.hpp
Go to the documentation of this file.
1 /*
2  CMD-CONTEXT.hpp - interface to access command context binding services within the UI
3 
4  Copyright (C) Lumiera.org
5  2017, 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 
53 #ifndef STAGE_INTERACT_CMD_CONTEXT_H
54 #define STAGE_INTERACT_CMD_CONTEXT_H
55 
56 
57 #include "lib/error.hpp"
58 #include "lib/nocopy.hpp"
59 //#include "stage/ctrl/bus-term.hpp"
60 //#include "lib/idi/entry-id.hpp"
61 #include "lib/hash-indexed.hpp"
62 #include "lib/opaque-holder.hpp"
63 #include "lib/symbol.hpp"
64 #include "lib/nocopy.hpp"
65 //#include "lib/util.hpp"
66 
67 //#include <string>
68 #include <utility>
69 
70 namespace Gtk {
71  class Widget;
72 }
73 namespace stage {
74 namespace interact {
75 
76 // using lib::HashVal;
77  using lib::hash::LuidH;
78  using lib::Symbol;
79 // using util::isnil;
80 // using std::string;
81 
82  class InteractionState;
83 
84 
85 
98  : public util::MoveAssign
99  {
100  Symbol cmdID_;
101 
102  public:
103  virtual ~GestureObserver();
104 
105  GestureObserver (Symbol cmdID) : cmdID_(cmdID) { }
106 
107  GestureObserver (GestureObserver&&) = default;
108  GestureObserver& operator= (GestureObserver&&) = default;
109 
110 
111  Symbol getCmdID() const { return cmdID_; }
112 
113  virtual void updateOffset (double deltaX, double deltaY) =0;
114  virtual void markGestureCompleted() =0;
115  };
116 
117 
120  : public GestureObserver
121  {
122  void updateOffset (double, double) override { /*NOOP*/ }
123  void markGestureCompleted() override { /*NOOP*/ }
124  public:
125  InactiveObserver() : GestureObserver(Symbol::BOTTOM) { }
126  };
127 
128 
129 
136  class Subject
138  {
139  protected:
140  virtual ~Subject();
141 
142  public:
144  virtual void buildGestureObserver (Symbol cmdID, Buffer) =0;
145  virtual Gtk::Widget& exposeWidget() =0;
146  };
147 
148 
149 
157  {
158  InteractionState& iState_;
159  Symbol cmdID_;
160 
161  /* ===== Builder State ===== */
162  Subject* subject_{nullptr};
163 
164  CmdContext (InteractionState& iState, Symbol cmdID)
165  : iState_{iState}
166  , cmdID_{cmdID}
167  { }
168  public:
169  // using the default move-ctor
170 
171  /* === access front-end === */
172  static CmdContext of (Symbol cmdID, Symbol ctxID);
173 
174  struct Resolver;
175 
177  CmdContext&& linkSubject (Subject& subj) { this->subject_ = &subj; return std::move (*this); }
178 
187  void setupRelocateDrag();
188 
189  protected:
190  private:
191  };
192 
193 
199  {
200 
204  operator LuidH ();
205 
206 
207  enum Spec {
208  HERE,
209  RECENT
210  };
211 
212 
213  friend Resolver
214  scope (Spec scopeSpec)
215  {
216  return Resolver{scopeSpec};
217  }
218 
219 
220  friend Resolver
221  element (Spec elementSpec)
222  {
223  return Resolver{elementSpec};
224  }
225 
226  private:
227  const Spec spec = HERE;
228 
229  Resolver(Spec s)
230  : spec(s)
231  { }
232  };
233 
234 
235 }} // namespace stage::interact
236 #endif /*STAGE_INTERACT_CMD_CONTEXT_H*/
Types marked with this mix-in may be moved and move-assigned.
Definition: nocopy.hpp:72
CmdContext && linkSubject(Subject &subj)
Builder operation: define the subject to use for the following interaction bindings.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
Types marked with this mix-in may be moved but not copied.
Definition: nocopy.hpp:58
Abstract foundation for context dependent UI interactions.
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:113
Marker types to indicate a literal string and a Symbol.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Helper allowing type erasure while holding the actual object inline.
»Null Object« when no gesture is being tracked currently.
A template for generating hash based ID tags carrying compile-time type info.
Lumiera error handling (C++ interface).
Hash implementation based on a lumiera unique object id (LUID) When invoking the default ctor...
Helper for dynamic command argument resolution.
Collaboration interface for tracking the formation of a gesture.
Definition: cmd-context.hpp:97
Builder to define a binding to relate some entity or place within the UI with a specific from of inte...
Role-Interface: the Subject of Interaction.