menu: enum class Menu::Background/Sound + constant Menu::NO_OPTION
This commit is contained in:
+12
-12
@@ -25,7 +25,7 @@ Menu::Menu(SDL_Renderer *renderer, const std::string &file)
|
||||
// Inicializa variables
|
||||
selector_.index = 0;
|
||||
selector_.previous_index = 0;
|
||||
item_selected_ = MENU_NO_OPTION;
|
||||
item_selected_ = NO_OPTION;
|
||||
x_ = 0;
|
||||
y_ = 0;
|
||||
w_ = 0;
|
||||
@@ -33,7 +33,7 @@ Menu::Menu(SDL_Renderer *renderer, const std::string &file)
|
||||
rect_bg_.rect = {.x = 0, .y = 0, .w = 0, .h = 0};
|
||||
rect_bg_.color = {0, 0, 0};
|
||||
rect_bg_.a = 0;
|
||||
background_type_ = MENU_BACKGROUND_SOLID;
|
||||
background_type_ = Background::SOLID;
|
||||
is_centered_on_x_ = false;
|
||||
is_centered_on_y_ = false;
|
||||
are_elements_centered_on_x_ = false;
|
||||
@@ -286,7 +286,7 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
|
||||
} else if (var == "centerY") {
|
||||
center_y_ = std::stoi(value);
|
||||
} else if (var == "backgroundType") {
|
||||
background_type_ = std::stoi(value);
|
||||
background_type_ = static_cast<Background>(std::stoi(value));
|
||||
} else if (var == "areElementsCenteredOnX") {
|
||||
are_elements_centered_on_x_ = (value == "true");
|
||||
} else if (var == "isCenteredOnX") {
|
||||
@@ -303,17 +303,17 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
|
||||
}
|
||||
|
||||
// Carga los ficheros de audio
|
||||
void Menu::loadAudioFile(const std::string &file, int sound) {
|
||||
void Menu::loadAudioFile(const std::string &file, Sound sound) {
|
||||
switch (sound) {
|
||||
case SOUND_ACCEPT:
|
||||
case Sound::ACCEPT:
|
||||
sound_accept_ = Ja::loadSound(file.c_str());
|
||||
break;
|
||||
|
||||
case SOUND_CANCEL:
|
||||
case Sound::CANCEL:
|
||||
sound_cancel_ = Ja::loadSound(file.c_str());
|
||||
break;
|
||||
|
||||
case SOUND_MOVE:
|
||||
case Sound::MOVE:
|
||||
sound_move_ = Ja::loadSound(file.c_str());
|
||||
break;
|
||||
|
||||
@@ -331,7 +331,7 @@ auto Menu::getName() const -> const std::string & {
|
||||
auto Menu::getItemSelected() -> int {
|
||||
// Al llamar a esta funcion, se obtiene el valor y se borra
|
||||
const int TEMP = item_selected_;
|
||||
item_selected_ = MENU_NO_OPTION;
|
||||
item_selected_ = NO_OPTION;
|
||||
return TEMP;
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ auto Menu::getWidestItem() -> int {
|
||||
|
||||
// Deja el menu apuntando al primer elemento
|
||||
void Menu::reset() {
|
||||
item_selected_ = MENU_NO_OPTION;
|
||||
item_selected_ = NO_OPTION;
|
||||
selector_.index = 0;
|
||||
if (items_.empty()) {
|
||||
return;
|
||||
@@ -527,7 +527,7 @@ void Menu::update() {
|
||||
// Pinta el menu en pantalla
|
||||
void Menu::render() {
|
||||
// Rendereritza el fondo del menu
|
||||
if (background_type_ == MENU_BACKGROUND_SOLID) {
|
||||
if (background_type_ == Background::SOLID) {
|
||||
SDL_FRect f_bg = {(float)rect_bg_.rect.x, (float)rect_bg_.rect.y, (float)rect_bg_.rect.w, (float)rect_bg_.rect.h};
|
||||
SDL_SetRenderDrawColor(renderer_, rect_bg_.color.r, rect_bg_.color.g, rect_bg_.color.b, rect_bg_.a);
|
||||
SDL_RenderFillRect(renderer_, &f_bg);
|
||||
@@ -539,7 +539,7 @@ void Menu::render() {
|
||||
SDL_RenderFillRect(renderer_, &F_TEMP);
|
||||
|
||||
// Renderiza el borde del fondo
|
||||
if (background_type_ == MENU_BACKGROUND_SOLID) {
|
||||
if (background_type_ == Background::SOLID) {
|
||||
SDL_FRect f_bg_border = {(float)rect_bg_.rect.x, (float)rect_bg_.rect.y, (float)rect_bg_.rect.w, (float)rect_bg_.rect.h};
|
||||
SDL_SetRenderDrawColor(renderer_, rect_bg_.color.r, rect_bg_.color.g, rect_bg_.color.b, 255);
|
||||
SDL_RenderRect(renderer_, &f_bg_border);
|
||||
@@ -830,7 +830,7 @@ void Menu::setPos(int x, int y) {
|
||||
}
|
||||
|
||||
// Establece el tipo de fondo del menu
|
||||
void Menu::setBackgroundType(int value) {
|
||||
void Menu::setBackgroundType(Background value) {
|
||||
background_type_ = value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user