68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
/**
|
|
* @file menuAction.cpp
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief Implentation of the class MenuAction
|
|
* @version 0.1
|
|
* @date 2022-01-12
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
#include "menuAction.h"
|
|
|
|
MenuAction::MenuAction(const char* name, void (*function) (), void (*callback) ()) {
|
|
this->name = name;
|
|
this->function = function;
|
|
this->callback = callback;
|
|
}
|
|
|
|
MenuAction::MenuAction(const char* name, MenuControl* menu) {
|
|
this->name = name;
|
|
this->menu = menu;
|
|
this->isMenu = true;
|
|
}
|
|
|
|
MenuAction::MenuAction(const char* name, MenuActionWrapper* action) {
|
|
this->name = name;
|
|
this->action = action;
|
|
}
|
|
|
|
MenuAction::~MenuAction() {
|
|
if (this->menu)
|
|
delete this->menu;
|
|
|
|
if (this->action)
|
|
delete this->action;
|
|
}
|
|
|
|
void MenuAction::runAction() {
|
|
if (isMenu)
|
|
this->menu->printMenu();
|
|
else {
|
|
if (this->function)
|
|
this->function();
|
|
else if (this->action)
|
|
this->action->action();
|
|
else
|
|
std::cout << "Error in MenuAction::runAction" << std::endl;
|
|
}
|
|
|
|
if (this->callback)
|
|
this->callback();
|
|
}
|
|
|
|
const char* MenuAction::getName() {
|
|
return this->name;
|
|
}
|
|
|
|
bool MenuAction::getIsMenu() {
|
|
return this->isMenu;
|
|
}
|
|
|
|
MenuControl* MenuAction::getMenu() {
|
|
if (isMenu)
|
|
return this->menu;
|
|
else
|
|
return nullptr;
|
|
}
|