diff --git a/source/credits.cpp b/source/credits.cpp index 0a6f0b8..57ee7ec 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -142,6 +142,7 @@ void Credits::fillTexture() iniTexts(); // Rellena la textura de texto + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(text_surface_); text_surface_->clear(stringToColor("black")); @@ -164,10 +165,8 @@ void Credits::fillTexture() // Recoloca el sprite del brillo shining_sprite_->setPosX(POS_X + 2); - Screen::get()->setRendererSurface(nullptr); // Rellena la textura que cubre el texto con color transparente - Screen::get()->setRendererSurface(text_surface_); text_surface_->clear(stringToColor("transparent")); // Los primeros 8 pixels crea una malla @@ -203,7 +202,7 @@ void Credits::fillTexture() rect = {0, 8, 256, 192}; surface->fillRect(&rect, color); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } // Actualiza el contador diff --git a/source/director.cpp b/source/director.cpp index cd3235e..67fa2c8 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -91,13 +91,13 @@ Director::~Director() saveOptionsToFile(Asset::get()->get("config.txt")); // Destruye los singletones - Asset::destroy(); - Input::destroy(); - Screen::destroy(); - Notifier::destroy(); - Debug::destroy(); - Resource::destroy(); Cheevos::destroy(); + Debug::destroy(); + Input::destroy(); + Notifier::destroy(); + Resource::destroy(); + Screen::destroy(); + Asset::destroy(); SDL_DestroyRenderer(renderer_); SDL_DestroyWindow(window_); diff --git a/source/ending.cpp b/source/ending.cpp index 276b485..1bcdc10 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -174,6 +174,7 @@ void Ending::iniTexts() // Crea la textura st.image_surface = std::make_shared(WIDTH, HEIGHT); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(st.image_surface); text->writeDX(TEXT_STROKE, 2, 2, txt.caption, 1, text_color, 2, shadow_color); @@ -216,7 +217,7 @@ void Ending::iniTexts() st.cover_clip_height = HEIGHT; sprite_texts_.push_back(st); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } } @@ -250,6 +251,7 @@ void Ending::iniPics() // Crea la cover_surface sp.cover_surface = std::make_shared(WIDTH, HEIGHT + 8); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(sp.cover_surface); // Rellena la cover_surface con color transparente @@ -283,7 +285,7 @@ void Ending::iniPics() sp.cover_clip_height = HEIGHT; sprite_pics_.push_back(sp); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } } @@ -473,6 +475,7 @@ void Ending::checkChangeScene() void Ending::fillCoverTexture() { // Rellena la textura que cubre el texto con color transparente + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(cover_surface_); cover_surface_->clear(stringToColor("transparent")); @@ -495,7 +498,7 @@ void Ending::fillCoverTexture() SDL_Rect rect = {0, 0, 256, options.game.height}; surface->fillRect(&rect, color); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } // Dibuja la cortinilla de cambio de escena diff --git a/source/ending2.cpp b/source/ending2.cpp index 5862fc0..06921a9 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -424,6 +424,7 @@ void Ending2::createSpriteTexts() // Crea la surface auto surface = std::make_shared(W, H); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface); text->write(0, 0, txt); @@ -431,7 +432,7 @@ void Ending2::createSpriteTexts() SDL_Rect pos = {X, Y, W, H}; sprite_texts_.emplace_back(std::make_shared(surface, pos)); sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED_); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } } @@ -456,14 +457,15 @@ void Ending2::createTexts() // Crea la surface auto surface = std::make_shared(w, h); - Screen::get()->setRendererSurface(surface); + auto previuos_renderer = Screen::get()->getRendererSurface(); + Screen::get()->setRendererSurface(surface); text->write(0, 0, list[i]); // Crea el sprite SDL_Rect pos = {x + dx, y, w, h}; texts_.emplace_back(std::make_shared(surface, pos)); texts_.back()->setVelY(SPRITE_DESP_SPEED_); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } // Crea los últimos textos @@ -485,6 +487,7 @@ void Ending2::createTexts() // Crea la surface auto surface = std::make_shared(w, h); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface); text->write(0, 0, list[i]); @@ -492,7 +495,7 @@ void Ending2::createTexts() SDL_Rect pos = {x + dx, y, w, h}; texts_.emplace_back(std::make_shared(surface, pos)); texts_.back()->setVelY(SPRITE_DESP_SPEED_); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } } diff --git a/source/game.cpp b/source/game.cpp index f1a1fac..27d4fca 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -562,6 +562,7 @@ void Game::initStats() void Game::fillRoomNameTexture() { // Pone la textura como destino de renderizado + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(room_name_surface_); // Rellena la textura de color @@ -572,7 +573,7 @@ void Game::fillRoomNameTexture() text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor()); // Deja el renderizador por defecto - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } // Comprueba algunos logros diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index d34ce8e..5195335 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -136,8 +136,10 @@ void LoadingScreen::updateCounter() // Dibuja la pantalla de carga void LoadingScreen::renderLoad() { + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(screen_surface_); loading_first_part_ ? mono_loading_screen_sprite_->render(1, stringToColor("black")) : color_loading_screen_sprite_->render(); + Screen::get()->setRendererSurface(previuos_renderer); } // Dibuja el efecto de carga en el borde diff --git a/source/notifier.cpp b/source/notifier.cpp index 4e42fae..f1db333 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -183,13 +183,13 @@ void Notifier::show(std::vector texts, NotificationText text_is, in } // Inicializa variables - const auto padding_in_h = text_->getCharacterSize(); - const auto padding_in_v = text_->getCharacterSize() / 2; - const int icon_space = icon >= 0 ? ICON_SIZE_ + padding_in_h : 0; - text_is = icon_space > 0 ? NotificationText::LEFT : text_is; - const int width = options.game.width - (PADDING_OUT_ * 2); - const int height = (text_->getCharacterSize() * texts.size()) + (padding_in_v * 2); - const auto shape = NotificationShape::SQUARED; + const auto PADDING_IN_H = text_->getCharacterSize(); + const auto PADDING_IN_V = text_->getCharacterSize() / 2; + const int ICON_SPACE = icon >= 0 ? ICON_SIZE_ + PADDING_IN_H : 0; + text_is = ICON_SPACE > 0 ? NotificationText::LEFT : text_is; + const int WIDTH = options.game.width - (PADDING_OUT_ * 2); + const int HEIGHT = (text_->getCharacterSize() * texts.size()) + (PADDING_IN_V * 2); + const auto SHAPE = NotificationShape::SQUARED; // Posición horizontal auto desp_h = 0; @@ -199,25 +199,25 @@ void Notifier::show(std::vector texts, NotificationText text_is, in } else if (options.notifications.getHorizontalPosition() == NotificationPosition::CENTER) { - desp_h = ((options.game.width / 2) - (width / 2)); + desp_h = ((options.game.width / 2) - (WIDTH / 2)); } else if (options.notifications.getHorizontalPosition() == NotificationPosition::RIGHT) { - desp_h = options.game.width - width - PADDING_OUT_; + desp_h = options.game.width - WIDTH - PADDING_OUT_; } // Posición vertical - const int desp_v = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? PADDING_OUT_ : options.game.height - height - PADDING_OUT_; + const int DESP_V = (options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? PADDING_OUT_ : options.game.height - HEIGHT - PADDING_OUT_; // Offset - const auto travel_dist = height + PADDING_OUT_; + const auto TRAVEL_DIST = HEIGHT + PADDING_OUT_; auto offset = 0; if (options.notifications.getVerticalPosition() == NotificationPosition::TOP) { - offset = !notifications_.empty() ? notifications_.back().y + notifications_.back().travel_dist : desp_v; + offset = !notifications_.empty() ? notifications_.back().y + notifications_.back().travel_dist : DESP_V; } else if (options.notifications.getVerticalPosition() == NotificationPosition::BOTTOM) { - offset = !notifications_.empty() ? notifications_.back().y - notifications_.back().travel_dist : desp_v; + offset = !notifications_.empty() ? notifications_.back().y - notifications_.back().travel_dist : DESP_V; } // Crea la notificacion @@ -227,36 +227,37 @@ void Notifier::show(std::vector texts, NotificationText text_is, in n.code = code; n.can_be_removed = can_be_removed; n.y = offset; - n.travel_dist = travel_dist; + n.travel_dist = TRAVEL_DIST; n.texts = texts; - n.shape = shape; - int y_pos = offset + ((options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -travel_dist : travel_dist); - n.rect = {desp_h, y_pos, width, height}; + n.shape = SHAPE; + int y_pos = offset + ((options.notifications.getVerticalPosition() == NotificationPosition::TOP) ? -TRAVEL_DIST : TRAVEL_DIST); + n.rect = {desp_h, y_pos, WIDTH, HEIGHT}; // Crea la textura - n.surface = std::make_shared(width, height); + n.surface = std::make_shared(WIDTH, HEIGHT); // Prepara para dibujar en la textura + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(n.surface); // Dibuja el fondo de la notificación SDL_Rect rect; - if (shape == NotificationShape::ROUNDED) + if (SHAPE == NotificationShape::ROUNDED) { - rect = {4, 0, width - (4 * 2), height}; + rect = {4, 0, WIDTH - (4 * 2), HEIGHT}; n.surface->fillRect(&rect, bg_color_); - rect = {4 / 2, 1, width - 4, height - 2}; + rect = {4 / 2, 1, WIDTH - 4, HEIGHT - 2}; n.surface->fillRect(&rect, bg_color_); - rect = {1, 4 / 2, width - 2, height - 4}; + rect = {1, 4 / 2, WIDTH - 2, HEIGHT - 4}; n.surface->fillRect(&rect, bg_color_); - rect = {0, 4, width, height - (4 * 2)}; + rect = {0, 4, WIDTH, HEIGHT - (4 * 2)}; n.surface->fillRect(&rect, bg_color_); } - else if (shape == NotificationShape::SQUARED) + else if (SHAPE == NotificationShape::SQUARED) { n.surface->clear(bg_color_); } @@ -265,36 +266,37 @@ void Notifier::show(std::vector texts, NotificationText text_is, in if (has_icons_ && icon >= 0 && texts.size() >= 2) { auto sp = std::make_unique(icon_surface_, (SDL_Rect){0, 0, ICON_SIZE_, ICON_SIZE_}); - sp->setPosition({padding_in_h, padding_in_v, ICON_SIZE_, ICON_SIZE_}); + sp->setPosition({PADDING_IN_H, PADDING_IN_V, ICON_SIZE_, ICON_SIZE_}); sp->setClip({ICON_SIZE_ * (icon % 10), ICON_SIZE_ * (icon / 10), ICON_SIZE_, ICON_SIZE_}); sp->render(); } // Escribe el texto de la notificación - const Uint8 color = stringToColor("white"); + const Uint8 COLOR = stringToColor("white"); int iterator = 0; for (const auto &text : texts) { - if (text_is == NotificationText::LEFT) + switch (text_is) { - text_->writeColored(padding_in_h + icon_space, padding_in_v + iterator * (text_->getCharacterSize() + 1), text, color); - } - else if (text_is == NotificationText::CENTER) - { - text_->writeDX(TEXT_CENTER | TEXT_COLOR, width / 2, padding_in_v + iterator * (text_->getCharacterSize() + 1), text, 1, color); + case NotificationText::LEFT: + text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + iterator * (text_->getCharacterSize() + 1), text, COLOR); + break; + case NotificationText::CENTER: + text_->writeDX(TEXT_CENTER | TEXT_COLOR, WIDTH / 2, PADDING_IN_V + iterator * (text_->getCharacterSize() + 1), text, 1, COLOR); + break; + default: + break; } + ++iterator; } // Deja de dibujar en la textura - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); // Crea el sprite de la notificación n.sprite = std::make_shared(n.surface, n.rect); - // Deja la notificación invisible - // n.surface->setAlpha(0); - // Añade la notificación a la lista notifications_.emplace_back(n); } diff --git a/source/room.cpp b/source/room.cpp index 41242a2..bbed97b 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -474,6 +474,7 @@ void Room::initializeRoom(const RoomData &room) void Room::fillMapTexture() { const Uint8 color = stringToColor(bg_color_); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(map_surface_); map_surface_->clear(color); @@ -593,7 +594,7 @@ void Room::fillMapTexture() } #endif - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } // Dibuja el mapa en pantalla diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 890ea1c..f63f0c9 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -136,6 +136,7 @@ int Scoreboard::getMinutes() void Scoreboard::fillTexture() { // Empieza a dibujar en la textura + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface_); // Limpia la textura @@ -179,5 +180,5 @@ void Scoreboard::fillTexture() text->writeColored(28 * BLOCK, LINE2, ROOMS_TEXT, stringToColor("white")); // Deja el renderizador como estaba - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } \ No newline at end of file diff --git a/source/text.cpp b/source/text.cpp index 17065cf..e1240a5 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -147,10 +147,11 @@ std::shared_ptr Text::writeToSurface(const std::string &text, int zoom, auto width = lenght(text, kerning) * zoom; auto height = box_height_ * zoom; auto surface = std::make_shared(width, height); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface); surface->clear(stringToColor("transparent")); write(0, 0, text, kerning); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); return surface; } @@ -161,10 +162,11 @@ std::shared_ptr Text::writeDXToSurface(Uint8 flags, const std::string & auto width = Text::lenght(text, kerning) + shadow_distance; auto height = box_height_ + shadow_distance; auto surface = std::make_shared(width, height); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface); surface->clear(stringToColor("transparent")); writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght); - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); return surface; } diff --git a/source/title.cpp b/source/title.cpp index 66fa81d..c4b7259 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -313,6 +313,7 @@ void Title::moveCheevosList(int direction) void Title::fillSurface() { // Coloca el puntero del renderizador sobre la textura + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(bg_surface_); // Rellena la textura de color @@ -332,7 +333,7 @@ void Title::fillSurface() text->writeColored(PLAY_AREA_CENTER_X, 30 * TEXT_SIZE, "ESC.EXIT GAME", COLOR); // Devuelve el puntero del renderizador a su sitio - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); } // Crea y rellena la textura para mostrar los logros @@ -350,6 +351,7 @@ void Title::createCheevosTexture() cheevos_surface_ = std::make_shared(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT); // Prepara para dibujar sobre la textura + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(cheevos_surface_); // Rellena la textura con color sólido @@ -382,7 +384,7 @@ void Title::createCheevosTexture() } // Restablece el RenderSurface - Screen::get()->setRendererSurface(nullptr); + Screen::get()->setRendererSurface(previuos_renderer); // Crea el sprite para el listado de logros cheevos_sprite_ = std::make_shared(cheevos_surface_, (GAMECANVAS_WIDTH - cheevos_surface_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight());