FlightGear next
PUICompatObject.hxx
Go to the documentation of this file.
1// PUICompatDialog.hxx - XML dialog object without using PUI
2// Copyright (C) 2022 James Turner
3// SPDX-License-Identifier: GPL-2.0-or-later
4
5#pragma once
6
7#include <simgear/math/SGMath.hxx>
8#include <simgear/nasal/cppbind/NasalHash.hxx>
9#include <simgear/nasal/cppbind/NasalObject.hxx>
10#include <simgear/props/propsfwd.hxx>
11#include <simgear/structure/SGBinding.hxx>
12#include <simgear/structure/SGReferenced.hxx>
13
14class PUICompatObject;
16
17using PUICompatObjectRef = SGSharedPtr<PUICompatObject>;
18using PUICompatObjectVec = std::vector<PUICompatObjectRef>;
19
20using PUICompatDialogRef = SGSharedPtr<FGPUICompatDialog>;
21
22class PUICompatObject : public nasal::Object, public SGPropertyChangeListener
23{
24public:
25 static PUICompatObjectRef createForType(const std::string& type, SGPropertyNode_ptr config);
26
27 static void setupGhost(nasal::Hash& guiModule);
28
29 virtual ~PUICompatObject();
30
31 virtual void init();
32
33 virtual void update();
34
35 virtual void apply();
36
37 virtual void updateValue();
38
39 naRef config() const;
40
42 naRef property() const;
43
46 naRef propertyValue(naContext ctx) const;
47
49
51
53
54 naRef show(naRef viewParent);
55
56 double getX() const;
57 double getY() const;
58 double width() const;
59 double height() const;
60
61 SGRectd geometry() const;
62
63 // bool heightForWidth properties
64
65 void setGeometry(const SGRectd& g);
66
67 bool visible() const;
68 bool enabled() const;
69 const std::string& type() const;
70
71 const std::string& name() const
72 {
73 return _name;
74 }
75
76 void setVisible(bool v);
77 void setEnabled(bool e);
78
85 PUICompatObjectRef widgetByName(const std::string& name) const;
86
87
94 std::string radioGroupIdent() const;
95
96 bool isLive() const
97 {
98 return _live != LiveValueMode::OnApply;
99 }
100
101 bool hasBindings() const;
102
103 std::string translatePluralString(const std::string& key, int cardinal,
104 const std::string& resource = {},
105 const std::string& domain = {}) const;
106 std::string translateString(const std::string& key,
107 const std::string& resource = {},
108 const std::string& domain = {}) const;
109protected:
110 PUICompatObject(naRef impl, const std::string& type);
111
112 virtual void activateBindings();
113
114 virtual void updateGeometry(const SGRectd& newGeom);
115
116 void valueChanged(SGPropertyNode* node) override;
117
118 // emporary solution to decide which SGPropertyNode children of an
119 // object, are children
120 static bool isNodeAChildObject(const std::string& nm, int uiVersion);
121
122private:
123 enum class LiveValueMode {
124 OnApply,
125 Listener,
126 Polled
127 };
128
129 friend class FGPUICompatDialog;
130
131 friend naRef f_makeCompatObjectPeer(const nasal::CallContext& ctx);
132
133 naRef nasalGetConfigValue(const nasal::CallContext ctx) const;
134
135 void setDialog(PUICompatDialogRef dialog);
136
137 void recursiveUpdate(const std::string& objectName = {});
138 void recursiveUpdateValues(const std::string& objectName = {});
139 void recursiveApply(const std::string& objectName = {});
140 void recursiveOnDelete();
141
142 void doActivate();
143
144 nasal::Hash gridLocation(const nasal::CallContext& ctx) const;
145
146 SGWeakPtr<PUICompatObject> _parent;
147 SGWeakPtr<FGPUICompatDialog> _dialog;
148
149 PUICompatObjectVec _children; // owning references to children
150
151 SGPropertyNode_ptr _config;
152
153 std::string _type;
154 std::string _label;
155 std::string _name;
156 std::string _oldPolledValue;
157
158 SGPropertyNode_ptr _value;
159 SGRectd _geometry;
160
161 LiveValueMode _live = LiveValueMode::OnApply;
162 bool _valueChanged = false;
163 bool _visible = true;
164 bool _enabled = true;
165 bool _labelChanged = false;
166
167 SGConditionRef _visibleCondition;
168 SGConditionRef _enableCondition;
169
170 SGBindingList _bindings;
171};
SGSharedPtr< PUICompatObject > PUICompatObjectRef
SGSharedPtr< FGPUICompatDialog > PUICompatDialogRef
SGSharedPtr< PUICompatObject > PUICompatObjectRef
std::vector< PUICompatObjectRef > PUICompatObjectVec
An XML-configured dialog box.
std::string radioGroupIdent() const
return the radio group ID associated with this widget (which is presumably a radio-button)
double width() const
bool isLive() const
bool hasBindings() const
std::string translatePluralString(const std::string &key, int cardinal, const std::string &resource={}, const std::string &domain={}) const
void valueChanged(SGPropertyNode *node) override
virtual void init()
void setEnabled(bool e)
virtual void updateGeometry(const SGRectd &newGeom)
naRef config() const
std::string translateString(const std::string &key, const std::string &resource={}, const std::string &domain={}) const
void setGeometry(const SGRectd &g)
friend class FGPUICompatDialog
PUICompatObject(naRef impl, const std::string &type)
double height() const
SGRectd geometry() const
const std::string & name() const
virtual void apply()
naRef show(naRef viewParent)
virtual void activateBindings()
friend naRef f_makeCompatObjectPeer(const nasal::CallContext &ctx)
PUICompatObjectRef parent() const
PUICompatDialogRef dialog() const
PUICompatObjectRef widgetByName(const std::string &name) const
find an object (which might be us, or a descendant) with the corresponding name, or nullptr.
virtual ~PUICompatObject()
static void setupGhost(nasal::Hash &guiModule)
static PUICompatObjectRef createForType(const std::string &type, SGPropertyNode_ptr config)
double getX() const
naRef propertyValue(naContext ctx) const
return the actual Nasal value of our property: this avoids the need to create a the property ghost an...
const std::string & type() const
naRef property() const
return the wrapped props,Node corresponding to our property
double getY() const
PUICompatObjectVec children() const
virtual void updateValue()
static bool isNodeAChildObject(const std::string &nm, int uiVersion)
virtual void update()
void setVisible(bool v)
const char * name