Transició a surface: ending.cpp fet

This commit is contained in:
2025-03-03 20:48:31 +01:00
parent d7e0178602
commit b320030547
11 changed files with 128 additions and 134 deletions

View File

@@ -8,9 +8,9 @@
#include <iostream> // Para cerr
#include <stdexcept> // Para runtime_error
#include "screen.h" // Para Screen
#include "s_sprite.h" // Para SSprite
#include "s_sprite.h" // Para SSprite
#include "surface.h" // Para Surface
#include "utils.h" // Para Color, getFileName, printWithDots
#include "utils.h" // Para Uint8, getFileName, printWithDots
// Llena una estructuta TextFile desde un fichero
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
@@ -145,54 +145,59 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
std::shared_ptr<Surface> Text::writeToSurface(const std::string &text, int zoom, int kerning)
{
auto renderer = Screen::get()->getRenderer();
auto surface = std::make_shared<Surface>(renderer);
auto width = lenght(text, kerning) * zoom;
auto height = box_height_ * zoom;
auto temp = SDL_GetRenderTarget(renderer);
//surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
//surface->setBlendMode(SDL_BLENDMODE_BLEND);
//surface->setAsRenderTarget(renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
//zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
SDL_SetRenderTarget(renderer, temp);
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), width, height);
Screen::get()->setRenderSurfaceData(surface);
Screen::get()->clean(stringToColor("transparent"));
write(0, 0, text, kerning);
Screen::get()->setRenderSurfaceData(nullptr);
return surface;
}
// Escribe el texto con extras en una surface
std::shared_ptr<Surface> Text::writeDXToSurface(Uint8 flags, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
std::shared_ptr<Surface> Text::writeDXToSurface(Uint8 flags, const std::string &text, int kerning, Uint8 textColor, Uint8 shadow_distance, Uint8 shadow_color, int lenght)
{
auto renderer = Screen::get()->getRenderer();
auto surface = std::make_shared<Surface>(renderer);
auto width = Text::lenght(text, kerning) + shadow_distance;
auto height = box_height_ + shadow_distance;
auto temp = SDL_GetRenderTarget(renderer);
//surface->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
//surface->setBlendMode(SDL_BLENDMODE_BLEND);
//surface->setAsRenderTarget(renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
auto surface = std::make_shared<Surface>(Screen::get()->getRenderSurfaceData(), width, height);
Screen::get()->setRenderSurfaceData(surface);
Screen::get()->clean(stringToColor("transparent"));
writeDX(flags, 0, 0, text, kerning, textColor, shadow_distance, shadow_color, lenght);
SDL_SetRenderTarget(renderer, temp);
Screen::get()->setRenderSurfaceData(nullptr);
return surface;
}
// Escribe el texto con colores
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int lenght)
void Text::writeColored(int x, int y, const std::string &text, Uint8 color, int kerning, int lenght)
{
//sprite_->getSurface()->setColor(color.r, color.g, color.b);
write(x, y, text, kerning, lenght);
//sprite_->getSurface()->setColor(255, 255, 255);
int shift = 0;
if (lenght == -1)
{
lenght = text.length();
}
sprite_->setY(y);
for (int i = 0; i < lenght; ++i)
{
auto index = static_cast<int>(text[i]);
sprite_->setClip(offset_[index].x, offset_[index].y, box_width_, box_height_);
sprite_->setX(x + shift);
sprite_->render(1, color);
shift += offset_[static_cast<int>(text[i])].w + kerning;
}
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int lenght)
void Text::writeShadowed(int x, int y, const std::string &text, Uint8 color, Uint8 shadow_distance, int kerning, int lenght)
{
//sprite_->getSurface()->setColor(color.r, color.g, color.b);
write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
//sprite_->getSurface()->setColor(255, 255, 255);
writeColored(x + shadow_distance, y + shadow_distance, text, color, kerning, lenght);
write(x, y, text, kerning, lenght);
}
@@ -204,7 +209,7 @@ void Text::writeCentered(int x, int y, const std::string &text, int kerning, int
}
// Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Uint8 textColor, Uint8 shadow_distance, Uint8 shadow_color, int lenght)
{
const auto centered = ((flags & TEXT_CENTER) == TEXT_CENTER);
const auto shadowed = ((flags & TEXT_SHADOW) == TEXT_SHADOW);