4 #include <KrisLibrary/utils/AnyCollection.h> 5 #include <KrisLibrary/math3d/primitives.h> 35 virtual bool ProcessMessage(
const AnyCollection& msg);
37 virtual bool SendMessage(
const AnyCollection& msg);
42 void AddRule(
const AnyCollection& inschema,
const AnyCollection& outschema,
bool mapWildcardStrings=
true);
44 void AddCommandRule(
const AnyCollection& inschema,
const string& cmd,
const string& args,
bool mapWildcardStrings=
true);
45 bool LoadRules(
const char* fn);
46 bool LoadRules(istream& in);
48 virtual bool OnQuit() {
return false; }
49 virtual bool OnCommand(
const string& cmd,
const string& args) {
return false; }
50 virtual bool OnNotify(
const string& text,
const string& msglevel) {
return false; }
51 virtual bool OnPauseIdle(
double secs) {
return false; }
52 virtual bool OnRefresh() {
return false; }
53 virtual bool OnResize(
int w,
int h) {
return false; }
54 virtual bool OnDrawText(
double x,
double y,
double z,
const std::string &text,
int height) {
return false; }
55 virtual bool OnDrawText(
int x,
int y,
const std::string &text,
int height) {
return false; }
59 bool SendGLViewport(
int x,
int y,
int w,
int h);
60 bool SendCommand(
const string& cmd,
const string& args);
61 bool SendCommand(
const string& cmd);
63 bool SendCommand(
const string& cmd,
const T& arg1);
64 template <
class T1,
class T2>
65 bool SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2);
66 template <
class T1,
class T2,
class T3>
67 bool SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2,
const T3& arg3);
68 bool SendButtonPress(
const string& widget);
69 bool SendButtonToggle(
const string& widget,
int checked);
70 bool SendWidgetValue(
const string& widget,
const string& value);
71 bool SendMouseClick(
int button,
int state,
int mx,
int my);
72 bool SendMouseMove(
int mx,
int my);
73 bool SendMouseWheel(
int dwheel);
74 bool SendScroll(
int dy);
75 bool SendKeyDown(
const string& key);
76 bool SendKeyUp(
const string& key);
77 bool SendSpaceball(
const Math3D::RigidTransform& T);
78 bool SendDevice(
const string& name,
const string& data);
81 vector<pair<AnyCollection,AnyCollection> > rules;
91 virtual void Stop() {}
94 virtual bool ProcessMessage(
const AnyCollection& msg);
96 virtual bool SendMessage(
const AnyCollection& msg) {
return gui->ProcessMessage(msg); }
99 void MapButtonPress(
const string& button,
int* var);
100 void MapButtonToggle(
const string& button,
int* var);
101 void MapWidgetValue(
const string& button,
string* var);
102 void MapKeyToggle(
const string& key,
int* var);
104 virtual bool OnIdle() { SendPauseIdle();
return true; }
105 virtual bool OnGLRender() {
return false; }
106 virtual bool OnGLViewport(
int x,
int y,
int w,
int h) {
return false; }
107 virtual bool OnCommand(
const string& cmd,
const string& args) {
return false; }
108 virtual bool OnButtonPress(
const string& button);
109 virtual bool OnButtonToggle(
const string& button,
int checked);
110 virtual bool OnWidgetValue(
const string& widget,
const string& value);
111 virtual bool OnMouseClick(
int button,
int state,
int mx,
int my) {
return false; }
112 virtual bool OnMouseMove(
int mx,
int my) {
return false; }
113 virtual bool OnMouseWheel(
int dwheel) {
return false; }
114 virtual bool OnScroll(
int dy) {
return false; }
115 virtual bool OnKeyDown(
const string& key);
116 virtual bool OnKeyUp(
const string& key);
117 virtual bool OnSpaceball(
const Math3D::RigidTransform& T) {
return false; }
118 virtual bool OnDevice(
const string& name,
const string& data) {
return false; }
121 bool SendCommand(
const string& cmd,
const string& args);
122 bool SendNotify(
const string& text,
const string& msglevel=
"");
123 bool SendError(
const string& text) {
return SendNotify(text,
"error"); }
124 bool SendWarning(
const string& text) {
return SendNotify(text,
"warning"); }
125 bool SendPauseIdle(
double secs=1e300);
127 bool SendResize(
int w,
int h);
128 bool SendDrawText(
double x,
double y,
double z,
const std::string &text,
int height = 10);
129 bool SendDrawText(
int x,
int y,
const std::string &text,
int height = 10);
132 map<string,int*> liveButtonPresses;
133 map<string,int*> liveButtonToggles;
134 map<string,string*> liveWidgetValues;
135 map<string,int*> liveKeys;
155 void Add(std::shared_ptr<GenericBackendBase>& backend);
156 void SetDefaultBroadcasts();
157 void SetBroadcast(
const string& msgtype) { targets[msgtype]=
"all"; }
158 virtual bool ProcessMessage(
const AnyCollection& msg);
160 vector<std::shared_ptr<GenericBackendBase> > children;
161 map<string,string> targets;
169 #define DISPATCHBEGIN() \ 172 res = msg["type"].as<string>(type); \ 174 cerr<<"Message doesn't contain type"<<endl; \ 178 #define DISPATCHEND() \ 180 cerr<<"Unhandled message type "<<type<<endl; \ 185 #define DISPATCH0(msgtype,func) \ 186 else if(type == msgtype) \ 189 #define DISPATCH1(msgtype,arg1,func) \ 190 else if(type == msgtype) \ 191 return func(msg[#arg1]); 194 #define DISPATCH2(msgtype,arg1,arg2,func) \ 195 else if(type == msgtype) \ 196 return func(msg[#arg1],msg[#arg2]); 198 #define DISPATCH3(msgtype,arg1,arg2,arg3,func) \ 199 else if(type == msgtype) \ 200 return func(msg[#arg1],msg[#arg2],msg[#arg3]); 202 #define DISPATCH4(msgtype,arg1,arg2,arg3,arg4,func) \ 203 else if(type == msgtype) \ 204 return func(msg[#arg1],msg[#arg2],msg[#arg3],msg[#arg4]); 206 #define DISPATCH5(msgtype,arg1,arg2,arg3,arg4,arg5,func) \ 207 else if(type == msgtype) \ 208 return func(msg[#arg1],msg[#arg2],msg[#arg3],msg[#arg4],msg[#arg5]); 215 #define SEND0(msgtype)\ 217 msg["type"] = string(msgtype); \ 218 return SendMessage(msg); 220 #define SEND1(msgtype,arg1) \ 222 msg["type"] = string(msgtype); \ 224 return SendMessage(msg); 226 #define SEND2(msgtype,arg1,arg2) \ 228 msg["type"] = string(msgtype); \ 231 return SendMessage(msg); 233 #define SEND3(msgtype,arg1,arg2,arg3) \ 235 msg["type"] = string(msgtype); \ 239 return SendMessage(msg); 241 #define SEND4(msgtype,arg1,arg2,arg3,arg4) \ 243 msg["type"] = string(msgtype); \ 248 return SendMessage(msg); 250 #define SEND5(msgtype,arg1,arg2,arg3,arg4,arg5) \ 252 msg["type"] = string(msgtype); \ 258 return SendMessage(msg); 262 bool GenericGUIBase::SendCommand(
const string& cmd,
const T& arg1)
266 return this->SendCommand(cmd,ss.str());
269 template <
class T1,
class T2>
270 bool GenericGUIBase::SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2)
274 return this->SendCommand(cmd,ss.str());
277 template <
class T1,
class T2,
class T3>
278 bool GenericGUIBase::SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2,
const T3& arg3)
281 ss<<arg1<<
" "<<arg2<<
" "<<arg3<<endl;
282 return this->SendCommand(cmd,ss.str());
virtual bool SendMessage(const AnyCollection &msg)
Send a message to the gui.
Definition: GenericGUI.h:96
A base class for a GUI frontend. Performs message passing to the backend in the easily serializable A...
Definition: GenericGUI.h:25
Definition: GenericGUI.h:84
virtual void Start()
Default implementation of following do nothing.
Definition: GenericGUI.h:90
Definition: GenericGUI.h:152