17 using std::shared_ptr;
27 virtual string help(
const vector<string>& tokens)
const;
31 void create (
const vector<TclObject>& tokens,
TclObject& result);
32 void destroy (
const vector<TclObject>& tokens,
TclObject& result);
33 void info (
const vector<TclObject>& tokens,
TclObject& result);
34 void exists (
const vector<TclObject>& tokens,
TclObject& result);
35 void configure(
const vector<TclObject>& tokens,
TclObject& result);
36 shared_ptr<OSDWidget> create(
string_ref type,
const string& name)
const;
37 void configure(
OSDWidget& widget,
const vector<TclObject>& tokens,
78 :
Command(commandController,
"osd")
85 if (tokens.size() < 2) {
89 if (subCommand ==
"create") {
90 create(tokens, result);
92 }
else if (subCommand ==
"destroy") {
93 destroy(tokens, result);
95 }
else if (subCommand ==
"info") {
97 }
else if (subCommand ==
"exists") {
98 exists(tokens, result);
99 }
else if (subCommand ==
"configure") {
100 configure(tokens, result);
104 "Invalid subcommand '" + subCommand +
"', expected "
105 "'create', 'destroy', 'info', 'exists' or 'configure'.");
109 void OSDCommand::create(
const vector<TclObject>& tokens,
TclObject& result)
111 if (tokens.size() < 4) {
118 if (name.
empty()) std::swap(parentname, name);
122 throw CommandException(
123 "Parent widget doesn't exist yet:" + parentname);
125 if (parent->findSubWidget(name)) {
126 throw CommandException(
127 "There already exists a widget with this name: " +
131 shared_ptr<OSDWidget> widget = create(type, name.
str());
132 configure(*widget, tokens, 4);
133 parent->addWidget(widget);
138 shared_ptr<OSDWidget> OSDCommand::create(
141 if (type ==
"rectangle") {
142 return std::make_shared<OSDRectangle>(gui, name);
143 }
else if (type ==
"text") {
144 return std::make_shared<OSDText>(gui, name);
146 throw CommandException(
147 "Invalid widget type '" + type +
"', expected "
148 "'rectangle' or 'text'.");
152 void OSDCommand::destroy(
const vector<TclObject>& tokens, TclObject& result)
154 if (tokens.size() != 3) {
160 result.setBoolean(
false);
165 throw CommandException(
"Can't destroy the top widget.");
167 parent->deleteWidget(*widget);
168 result.setBoolean(
true);
171 void OSDCommand::info(
const vector<TclObject>& tokens, TclObject& result)
173 switch (tokens.size()) {
176 vector<string> names;
178 result.addListElements(names);
183 const OSDWidget& widget = getWidget(tokens[2].getString());
184 result.addListElements(widget.getProperties());
189 const OSDWidget& widget = getWidget(tokens[2].getString());
190 widget.getProperty(tokens[3].getString(), result);
198 void OSDCommand::exists(
const vector<TclObject>& tokens, TclObject& result)
200 if (tokens.size() != 3) {
204 result.setBoolean(widget !=
nullptr);
207 void OSDCommand::configure(
const vector<TclObject>& tokens, TclObject& )
209 if (tokens.size() < 3) {
212 configure(getWidget(tokens[2].getString()), tokens, 3);
215 void OSDCommand::configure(OSDWidget& widget,
const vector<TclObject>& tokens,
218 assert(tokens.size() >= skip);
219 if ((tokens.size() - skip) & 1) {
221 throw CommandException(
222 "Missing value for '" + tokens.back().getString() +
"'.");
225 for (
size_t i = skip; i < tokens.size(); i += 2) {
226 const auto& name = tokens[i + 0].getString();
227 widget.setProperty(name, tokens[i + 1]);
233 if (tokens.size() >= 2) {
234 if (tokens[1] ==
"create") {
236 "osd create <type> <widget-path> [<property-name> <property-value>]...\n"
238 "Creates a new OSD widget of given type. Path is a "
239 "hierarchical name for the wiget (separated by '.')."
240 "The parent widget for this new widget must already "
242 "Optionally you can set initial values for one or "
244 "This command returns the path of the newly created "
245 "widget. This is path is again needed to configure "
246 "or to remove the widget. It may be useful to assign "
247 "this path to a variable.";
248 }
else if (tokens[1] ==
"destroy") {
250 "osd destroy <widget-path>\n"
252 "Remove the specified OSD widget. Returns '1' on "
253 "success and '0' when widget couldn't be destroyed "
254 "because there was no widget with that name";
255 }
else if (tokens[1] ==
"info") {
257 "osd info [<widget-path> [<property-name>]]\n"
259 "Query various information about the OSD status. "
260 "You can call this command with 0, 1 or 2 arguments.\n"
261 "Without any arguments, this command returns a list "
262 "of all existing widget IDs.\n"
263 "When a path is given as argument, this command "
264 "returns a list of available properties for that widget.\n"
265 "When both path and property name arguments are "
266 "given, this command returns the current value of "
268 }
else if (tokens[1] ==
"exists") {
270 "osd exists <widget-path>\n"
272 "Test whether there exists a widget with given name. "
273 "This subcommand is meant to be used in scripts.";
274 }
else if (tokens[1] ==
"configure") {
276 "osd configure <widget-path> [<property-name> <property-value>]...\n"
278 "Modify one or more properties on the given widget.";
280 return "No such subcommand, see 'help osd'.";
284 "Low level OSD GUI commands\n"
285 " osd create <type> <widget-path> [<property-name> <property-value>]...\n"
286 " osd destroy <widget-path>\n"
287 " osd info [<widget-path> [<property-name>]]\n"
288 " osd exists <widget-path>\n"
289 " osd configure <widget-path> [<property-name> <property-value>]...\n"
290 "Use 'help osd <subcommand>' to see more info on a specific subcommand";
296 if (tokens.size() == 2) {
297 static const char*
const cmds[] = {
298 "create",
"destroy",
"info",
"exists",
"configure"
301 }
else if ((tokens.size() == 3) && (tokens[1] ==
"create")) {
302 static const char*
const types[] = {
"rectangle",
"text" };
304 }
else if ((tokens.size() == 3) ||
305 ((tokens.size() == 4) && (tokens[1] ==
"create"))) {
306 vector<string> names;
311 vector<string_ref> properties;
312 if (tokens[1] ==
"create") {
313 shared_ptr<OSDWidget> widget = create(tokens[2],
"");
314 properties = widget->getProperties();
315 }
else if ((tokens[1] ==
"configure") ||
316 (tokens[1] ==
"info")) {
317 const OSDWidget& widget = getWidget(tokens[2]);