Afegit global_events.cpp
This commit is contained in:
147
source/logo.cpp
147
source/logo.cpp
@@ -14,7 +14,7 @@
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, Zone
|
||||
#include "mouse.h"
|
||||
#include "global_events.h"
|
||||
|
||||
// Constructor
|
||||
Logo::Logo()
|
||||
@@ -63,39 +63,13 @@ Logo::~Logo()
|
||||
JA_StopChannel(-1);
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
void Logo::reloadTextures()
|
||||
{
|
||||
jail_texture_->reLoad();
|
||||
since_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Logo::checkEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_FROM_EVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||
else if (event.type == SDL_WINDOWEVENT)
|
||||
{
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el cursor
|
||||
Mouse::handleEvent(event);
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +213,6 @@ void Logo::render()
|
||||
break;
|
||||
|
||||
case LogoState::RETROWEEKEND:
|
||||
renderRETROWEEKEND();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -277,118 +250,4 @@ void Logo::renderJAILGAMES()
|
||||
{
|
||||
since_sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Renderiza el logo de RETROWEEKEND
|
||||
void Logo::renderRETROWEEKEND()
|
||||
{
|
||||
// SDL_RenderCopy(Screen::get()->getRenderer(), mi_textura, nullptr, nullptr);
|
||||
|
||||
// SDL_RenderCopy(Screen::get()->getRenderer(), Resource::get()->getTexture("logo_retroweekend.png")->getSDLTexture(), nullptr, nullptr);
|
||||
// Dibujar y evaporar los píxeles
|
||||
renderAndEvaporate(Screen::get()->getRenderer(), pixels_);
|
||||
}
|
||||
|
||||
std::vector<Pixel> Logo::extractPixels(SDL_Texture *texture)
|
||||
{
|
||||
std::vector<Pixel> pixels;
|
||||
|
||||
// Obtener el formato y tamaño de la textura
|
||||
Uint32 format;
|
||||
int access, width, height;
|
||||
SDL_QueryTexture(texture, &format, &access, &width, &height);
|
||||
|
||||
// Imprimir el nombre del formato de la textura
|
||||
std::cout << "Texture format: " << SDL_GetPixelFormatName(format) << std::endl;
|
||||
|
||||
// Crear una superficie temporal para leer los píxeles
|
||||
SDL_Surface *temp_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, format);
|
||||
if (!temp_surface)
|
||||
{
|
||||
std::cout << "Error: SDL_CreateRGBSurfaceWithFormat failed - " << SDL_GetError() << std::endl;
|
||||
return pixels;
|
||||
}
|
||||
|
||||
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||
SDL_SetRenderTarget(renderer, nullptr); // Dibujar en pantalla principal
|
||||
SDL_RenderClear(renderer); // Limpiar pantalla
|
||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer); // Mostrar en pantalla
|
||||
|
||||
std::cout << "Se ha dibujado la textura en pantalla." << std::endl;
|
||||
|
||||
if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0)
|
||||
{
|
||||
std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl;
|
||||
SDL_FreeSurface(temp_surface);
|
||||
return pixels;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "SDL_RenderReadPixels se ejecutó correctamente." << std::endl;
|
||||
}
|
||||
|
||||
// Leer los píxeles de la textura
|
||||
if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0)
|
||||
{
|
||||
std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl;
|
||||
SDL_FreeSurface(temp_surface);
|
||||
return pixels;
|
||||
}
|
||||
|
||||
// Extraer los píxeles y almacenarlos en el vector
|
||||
SDL_PixelFormat *pixel_format = SDL_AllocFormat(format);
|
||||
Uint8 r, g, b, a;
|
||||
/*for (int y = 0; y < height; ++y)
|
||||
{
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x];
|
||||
SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a);
|
||||
if (a > 0)
|
||||
{
|
||||
pixels.push_back({x, y, r, g, b, a});
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x];
|
||||
SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a);
|
||||
|
||||
// Imprimir algunos píxeles para depuración
|
||||
if (x < 5 && y < 5)
|
||||
{
|
||||
std::cout << "Pixel (" << x << "," << y << ") - RGBA("
|
||||
<< (int)r << "," << (int)g << "," << (int)b << "," << (int)a << ")" << std::endl;
|
||||
}
|
||||
|
||||
// No filtrar por alfa por ahora
|
||||
pixels.push_back({x, y, r, g, b, a});
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Cantidad de píxeles a renderizar: " << pixels.size() << std::endl;
|
||||
|
||||
// Liberar recursos
|
||||
SDL_FreeFormat(pixel_format);
|
||||
SDL_FreeSurface(temp_surface);
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
void Logo::renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels)
|
||||
{
|
||||
for (auto &pixel : pixels)
|
||||
{
|
||||
// Establecer el color para el píxel actual
|
||||
SDL_SetRenderDrawColor(renderer, pixel.r, pixel.g, pixel.b, pixel.a);
|
||||
// Dibujar el píxel
|
||||
SDL_RenderDrawPoint(renderer, pixel.x, pixel.y);
|
||||
// Evaporar el píxel
|
||||
// pixel.evaporate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user