15 changed files with 6 additions and 284 deletions
@ -1,83 +0,0 @@
|
||||
#include "DiabloUI/art.h" |
||||
|
||||
#include <cstddef> |
||||
#include <cstdint> |
||||
#include <memory> |
||||
|
||||
#include "engine/assets.hpp" |
||||
#include "utils/display.h" |
||||
#include "utils/log.hpp" |
||||
#include "utils/pcx.hpp" |
||||
#include "utils/sdl_compat.h" |
||||
#include "utils/sdl_wrap.h" |
||||
|
||||
namespace devilution { |
||||
namespace { |
||||
|
||||
Uint32 GetPcxSdlPixelFormat(unsigned bpp) |
||||
{ |
||||
switch (bpp) { |
||||
case 8: // NOLINT(readability-magic-numbers)
|
||||
return SDL_PIXELFORMAT_INDEX8; |
||||
case 24: // NOLINT(readability-magic-numbers)
|
||||
return SDL_PIXELFORMAT_RGB888; |
||||
case 32: // NOLINT(readability-magic-numbers)
|
||||
return SDL_PIXELFORMAT_RGBA8888; |
||||
default: |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
void LoadArt(const char *pszFile, Art *art, int frames, SDL_Color *pPalette, const std::array<uint8_t, 256> *colorMapping) |
||||
{ |
||||
if (art == nullptr || art->surface != nullptr) |
||||
return; |
||||
|
||||
art->frames = frames; |
||||
|
||||
int width; |
||||
int height; |
||||
std::uint8_t bpp; |
||||
SDL_RWops *handle = OpenAsset(pszFile); |
||||
if (handle == nullptr) { |
||||
return; |
||||
} |
||||
|
||||
if (!LoadPcxMeta(handle, width, height, bpp)) { |
||||
Log("LoadArt(\"{}\"): LoadPcxMeta failed with code {}", pszFile, SDL_GetError()); |
||||
SDL_RWclose(handle); |
||||
return; |
||||
} |
||||
|
||||
SDLSurfaceUniquePtr artSurface = SDLWrap::CreateRGBSurfaceWithFormat(SDL_SWSURFACE, width, height, bpp, GetPcxSdlPixelFormat(bpp)); |
||||
if (!LoadPcxPixelsAndPalette(handle, width, height, bpp, static_cast<uint8_t *>(artSurface->pixels), |
||||
artSurface->pitch, pPalette)) { |
||||
Log("LoadArt(\"{}\"): LoadPcxPixelsAndPalette failed with code {}", pszFile, SDL_GetError()); |
||||
SDL_RWclose(handle); |
||||
return; |
||||
} |
||||
SDL_RWclose(handle); |
||||
|
||||
if (colorMapping != nullptr) { |
||||
for (int i = 0; i < artSurface->h * artSurface->pitch; i++) { |
||||
auto &pixel = static_cast<uint8_t *>(artSurface->pixels)[i]; |
||||
pixel = (*colorMapping)[pixel]; |
||||
} |
||||
} |
||||
|
||||
art->logical_width = artSurface->w; |
||||
art->frame_height = height / frames; |
||||
|
||||
art->surface = ScaleSurfaceToOutput(std::move(artSurface)); |
||||
} |
||||
|
||||
void LoadMaskedArt(const char *pszFile, Art *art, int frames, int mask, const std::array<uint8_t, 256> *colorMapping) |
||||
{ |
||||
LoadArt(pszFile, art, frames, nullptr, colorMapping); |
||||
if (art->surface != nullptr) |
||||
SDLC_SetColorKey(art->surface.get(), mask); |
||||
} |
||||
|
||||
} // namespace devilution
|
||||
@ -1,57 +0,0 @@
|
||||
#pragma once |
||||
|
||||
#include <array> |
||||
#include <cstdint> |
||||
|
||||
#include "utils/sdl_ptrs.h" |
||||
|
||||
namespace devilution { |
||||
|
||||
struct Art { |
||||
SDLSurfaceUniquePtr surface; |
||||
int frames; |
||||
int logical_width; |
||||
int frame_height; |
||||
unsigned int palette_version; |
||||
|
||||
#ifndef USE_SDL1 |
||||
SDLTextureUniquePtr texture; |
||||
#endif |
||||
|
||||
Art() |
||||
{ |
||||
surface = nullptr; |
||||
frames = 1; |
||||
logical_width = 0; |
||||
frame_height = 0; // logical frame height (before scaling)
|
||||
palette_version = 0; |
||||
|
||||
#ifndef USE_SDL1 |
||||
texture = nullptr; |
||||
#endif |
||||
} |
||||
|
||||
int w() const |
||||
{ |
||||
return logical_width; |
||||
} |
||||
|
||||
int h() const |
||||
{ |
||||
return frame_height; |
||||
} |
||||
|
||||
void Unload() |
||||
{ |
||||
surface = nullptr; |
||||
|
||||
#ifndef USE_SDL1 |
||||
texture = nullptr; |
||||
#endif |
||||
} |
||||
}; |
||||
|
||||
void LoadArt(const char *pszFile, Art *art, int frames = 1, SDL_Color *pPalette = nullptr, const std::array<uint8_t, 256> *colorMapping = nullptr); |
||||
void LoadMaskedArt(const char *pszFile, Art *art, int frames = 1, int mask = 250, const std::array<uint8_t, 256> *colorMapping = nullptr); |
||||
|
||||
} // namespace devilution
|
||||
@ -1,60 +0,0 @@
|
||||
#include "DiabloUI/art_draw.h" |
||||
|
||||
#include "DiabloUI/diabloui.h" |
||||
#include "engine/palette.h" |
||||
#include "utils/display.h" |
||||
#include "utils/sdl_compat.h" |
||||
|
||||
namespace devilution { |
||||
|
||||
void UpdatePalette(Art *art, const SDL_Surface *output) |
||||
{ |
||||
if (art->surface->format->BitsPerPixel != 8) |
||||
return; |
||||
|
||||
if (art->palette_version == pal_surface_palette_version) |
||||
return; |
||||
|
||||
if (output == nullptr || output->format->BitsPerPixel != 8) |
||||
output = PalSurface; |
||||
|
||||
if (SDLC_SetSurfaceColors(art->surface.get(), output->format->palette) <= -1) |
||||
ErrSdl(); |
||||
|
||||
art->palette_version = pal_surface_palette_version; |
||||
} |
||||
|
||||
void DrawArt(Point screenPosition, Art *art, int nFrame, Uint16 srcW, Uint16 srcH) |
||||
{ |
||||
if (art->surface == nullptr || screenPosition.y >= gnScreenHeight || screenPosition.x >= gnScreenWidth) |
||||
return; |
||||
|
||||
SDL_Rect srcRect = MakeSdlRect(0, nFrame * art->h(), art->w(), art->h()); |
||||
|
||||
ScaleOutputRect(&srcRect); |
||||
|
||||
if (srcW != 0 && srcW < srcRect.w) |
||||
srcRect.w = srcW; |
||||
if (srcH != 0 && srcH < srcRect.h) |
||||
srcRect.h = srcH; |
||||
|
||||
if (screenPosition.x + srcRect.w <= 0 || screenPosition.y + srcRect.h <= 0) |
||||
return; |
||||
|
||||
SDL_Rect dstRect = MakeSdlRect(screenPosition.x, screenPosition.y, srcRect.w, srcRect.h); |
||||
ScaleOutputRect(&dstRect); |
||||
|
||||
UpdatePalette(art); |
||||
|
||||
if (SDL_BlitSurface(art->surface.get(), &srcRect, DiabloUiSurface(), &dstRect) < 0) |
||||
ErrSdl(); |
||||
} |
||||
|
||||
int GetAnimationFrame(int frames, int fps) |
||||
{ |
||||
int frame = (SDL_GetTicks() / fps) % frames; |
||||
|
||||
return frame > frames ? 0 : frame; |
||||
} |
||||
|
||||
} // namespace devilution
|
||||
@ -1,14 +0,0 @@
|
||||
#pragma once |
||||
|
||||
#include "DiabloUI/art.h" |
||||
#include "engine.h" |
||||
|
||||
namespace devilution { |
||||
|
||||
void UpdatePalette(Art *art, const SDL_Surface *output = nullptr); |
||||
|
||||
void DrawArt(Point screenPosition, Art *art, int nFrame = 0, Uint16 srcW = 0, Uint16 srcH = 0); |
||||
|
||||
int GetAnimationFrame(int frames, int fps = 60); |
||||
|
||||
} // namespace devilution
|
||||
Loading…
Reference in new issue