Browse Source

DiabloUI: Fix software scaling along the X axis

pull/600/head
Gleb Mazovetskiy 6 years ago committed by Anders Jenbo
parent
commit
803217538a
  1. 2
      SourceX/DiabloUI/art.cpp
  2. 5
      SourceX/DiabloUI/art.h
  3. 1
      SourceX/DiabloUI/button.cpp
  4. 9
      SourceX/DiabloUI/diabloui.cpp
  5. 10
      SourceX/dx.cpp

2
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<BYTE *>(artData), w, h, 8, w, SDL_PIXELFORMAT_INDEX8);
art->logical_width = w;
art->frame_height = h / frames;
ScaleSurfaceToOutput(&art->surface);
}

5
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

1
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 {

9
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])) {

10
SourceX/dx.cpp

@ -1,3 +1,5 @@
#include <algorithm>
#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)) {

Loading…
Cancel
Save