diff --git a/SourceX/DiabloUI/art.cpp b/SourceX/DiabloUI/art.cpp index 4e517f767..a9c27b4ec 100644 --- a/SourceX/DiabloUI/art.cpp +++ b/SourceX/DiabloUI/art.cpp @@ -40,6 +40,7 @@ void LoadArt(const char *pszFile, Art *art, int frames, SDL_Color *pPalette) } art->surface = art_surface; + art->logical_width = art_surface->w; art->frame_height = height / frames; ScaleSurfaceToOutput(&art->surface); @@ -57,6 +58,7 @@ void LoadArt(Art *art, const BYTE *artData, int w, int h, int frames) art->frames = frames; art->surface = SDL_CreateRGBSurfaceWithFormatFrom( const_cast(artData), w, h, 8, w, SDL_PIXELFORMAT_INDEX8); + art->logical_width = w; art->frame_height = h / frames; ScaleSurfaceToOutput(&art->surface); } diff --git a/SourceX/DiabloUI/art.h b/SourceX/DiabloUI/art.h index 18f8050cd..1b8f6b064 100644 --- a/SourceX/DiabloUI/art.h +++ b/SourceX/DiabloUI/art.h @@ -7,12 +7,13 @@ namespace dvl { struct Art { SDL_Surface *surface = NULL; int frames = 1; - int frame_height = 0; + int logical_width = 0; + int frame_height = 0; // logical frame height (before scaling) unsigned int palette_version = 0; int w() const { - return surface ? surface->w : 0; + return logical_width; } int h() const diff --git a/SourceX/DiabloUI/button.cpp b/SourceX/DiabloUI/button.cpp index d08b1f730..d228f5557 100644 --- a/SourceX/DiabloUI/button.cpp +++ b/SourceX/DiabloUI/button.cpp @@ -2,6 +2,7 @@ #include "DiabloUI/art_draw.h" #include "DiabloUI/text_draw.h" #include "DiabloUI/errorart.h" +#include "display.h" namespace dvl { diff --git a/SourceX/DiabloUI/diabloui.cpp b/SourceX/DiabloUI/diabloui.cpp index 3641a811f..0b7397afa 100644 --- a/SourceX/DiabloUI/diabloui.cpp +++ b/SourceX/DiabloUI/diabloui.cpp @@ -303,10 +303,6 @@ void UiFocusNavigation(SDL_Event *event) } if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) { - // In SDL2 mouse events already use logical coordinates. -#ifdef USE_SDL1 - OutputToLogical(&event->button.x, &event->button.y); -#endif if (UiItemMouseEvents(event, gUiItems, gUiItemCnt)) return; } @@ -842,6 +838,11 @@ bool UiItemMouseEvents(SDL_Event *event, UiItem *items, std::size_t size) if (!items || size == 0) return false; + // In SDL2 mouse events already use logical coordinates. +#ifdef USE_SDL1 + OutputToLogical(&event->button.x, &event->button.y); +#endif + bool handled = false; for (std::size_t i = 0; i < size; i++) { if (HandleMouseEvent(*event, &items[i])) { diff --git a/SourceX/dx.cpp b/SourceX/dx.cpp index e0a312c84..9d0a1a895 100644 --- a/SourceX/dx.cpp +++ b/SourceX/dx.cpp @@ -1,3 +1,5 @@ +#include + #include "diablo.h" #include "../3rdParty/Storm/Source/storm.h" #include "display.h" @@ -188,7 +190,13 @@ void Blit(SDL_Surface *src, SDL_Rect *src_rect, SDL_Rect *dst_rect) ErrSdl(); return; } - if (dst_rect != nullptr) ScaleOutputRect(dst_rect); + + SDL_Rect scaled_dst_rect; + if (dst_rect != nullptr) { + scaled_dst_rect = *dst_rect; + ScaleOutputRect(&scaled_dst_rect); + dst_rect = &scaled_dst_rect; + } // Same pixel format: We can call BlitScaled directly. if (SDLBackport_PixelFormatFormatEq(src->format, dst->format)) {