set keys again both for new guis and new scenes

This commit is contained in:
KlausMu 2024-04-25 22:22:36 +02:00 committed by Klaus Musch
parent 17ee1f06d0
commit 8f0ceeb72b
5 changed files with 32 additions and 32 deletions

View file

@ -48,10 +48,21 @@ void register_gui(
// Can be overwritten by scenes to have their own gui_list.
main_gui_list.insert(main_gui_list.end(), {std::string(a_name)});
// Whenever a new gui is registered, a new gui command could have been defined.
// But this new gui command could have been already been used before in the key definition of another gui. The command at this time was 0, which is undefined.
// So we have to set the keys again for all guis that have been registered before.
// Loop over all registered guis and call setKeys()
setKeysForAllRegisteredGUIsAndScenes();
}
void setKeysForAllRegisteredGUIsAndScenes() {
// Whenever a new gui or scene is registered, a new gui or scene command could have been defined in the gui or scene.
// But this new command could have already been used before in the key definition of another gui or scene. The command at this time was 0, which is undefined.
// So we have to set the keys again for all guis and scenes that have been registered before.
// 1. set again the defaultKeys
register_scene_defaultKeys();
// 2. loop over all registered scenes and call setKeys()
for (std::map<std::string, scene_definition>::iterator it = registered_scenes.begin(); it != registered_scenes.end(); ++it) {
it->second.this_scene_setKeys();
}
// 3. loop over all registered guis and call setKeys()
for (std::map<std::string, gui_definition>::iterator it = registered_guis_byName_map.begin(); it != registered_guis_byName_map.end(); ++it) {
if (it->second.this_gui_setKeys != NULL) {
it->second.this_gui_setKeys();

View file

@ -50,3 +50,5 @@ void register_gui(
key_commands_short a_key_commands_short = NULL,
key_commands_long a_key_commands_long = NULL
);
void setKeysForAllRegisteredGUIsAndScenes();

View file

@ -8,18 +8,6 @@
// scenes
#include "scenes/scene__default.h"
// https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
struct scene_definition {
scene_setKeys this_scene_setKeys;
scene_start_sequence this_scene_start_sequence;
scene_end_sequence this_scene_end_sequence;
key_repeatModes this_key_repeatModes;
key_commands_short this_key_commands_short;
key_commands_long this_key_commands_long;
gui_list this_gui_list;
uint16_t this_activate_scene_command;
};
std::map<std::string, scene_definition> registered_scenes;
t_scene_list scenes_on_sceneSelectionGUI;
@ -51,21 +39,7 @@ void register_scene(
// Can be overwritten in main.cpp
scenes_on_sceneSelectionGUI.insert(scenes_on_sceneSelectionGUI.end(), {std::string(a_scene_name)});
// Whenever a new scene is registered, normally a new scene command has been defined immediately before (e.g. see register_scene_TV()).
// But this new scene command could have been already been used before in the key definition of another scene or a gui. The command at this time was 0, which is undefined.
// So we have to set the keys again for all scenes and guis that have been registered before.
// 1. set again the defaultKeys
register_scene_defaultKeys();
// 2. loop over all registered scenes and call setKeys()
for (std::map<std::string, scene_definition>::iterator it = registered_scenes.begin(); it != registered_scenes.end(); ++it) {
it->second.this_scene_setKeys();
}
// 3. loop over all registered guis and call setKeys()
for (std::map<std::string, gui_definition>::iterator it = registered_guis_byName_map.begin(); it != registered_guis_byName_map.end(); ++it) {
if (it->second.this_gui_setKeys != NULL) {
it->second.this_gui_setKeys();
}
}
setKeysForAllRegisteredGUIsAndScenes();
}

View file

@ -14,6 +14,20 @@ typedef void (*scene_end_sequence)(void);
typedef t_gui_list *gui_list;
typedef t_scene_list *scene_list;
// https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
struct scene_definition {
scene_setKeys this_scene_setKeys;
scene_start_sequence this_scene_start_sequence;
scene_end_sequence this_scene_end_sequence;
key_repeatModes this_key_repeatModes;
key_commands_short this_key_commands_short;
key_commands_long this_key_commands_long;
gui_list this_gui_list;
uint16_t this_activate_scene_command;
};
extern std::map<std::string, scene_definition> registered_scenes;
void register_scene(
std::string a_scene_name,
scene_setKeys a_scene_setKeys,

View file

@ -104,7 +104,6 @@ int main(int argc, char *argv[]) {
register_keyboardCommands();
// Register the GUIs. They will be displayed in the order they have been registered.
// GUIs must be registered before the scenes, because only the scenes re-register key bindings to commands which have been defined after the key binding (see register_scene())
register_gui_sceneSelection();
register_gui_irReceiver();
register_gui_settings();