You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.5 KiB
104 lines
2.5 KiB
|
6 years ago
|
#pragma once
|
||
|
|
|
||
|
6 years ago
|
#include <cstdint>
|
||
|
5 years ago
|
#include <type_traits>
|
||
|
5 years ago
|
|
||
|
7 years ago
|
#include <SDL.h>
|
||
|
5 years ago
|
#ifdef USE_SDL1
|
||
|
5 years ago
|
#include "utils/sdl2_to_1_2_backports.h"
|
||
|
5 years ago
|
#else
|
||
|
5 years ago
|
#include "utils/sdl2_backports.h"
|
||
|
5 years ago
|
#endif
|
||
|
|
|
||
|
5 years ago
|
#include "utils/sdl_ptrs.h"
|
||
|
|
#include "utils/ui_fwd.h"
|
||
|
7 years ago
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
7 years ago
|
|
||
|
6 years ago
|
extern int refreshDelay; // Screen refresh rate in nanoseconds
|
||
|
7 years ago
|
extern SDL_Window *window;
|
||
|
|
extern SDL_Renderer *renderer;
|
||
|
|
extern SDL_Texture *texture;
|
||
|
|
|
||
|
|
extern SDL_Palette *palette;
|
||
|
|
extern SDL_Surface *pal_surface;
|
||
|
|
extern unsigned int pal_surface_palette_version;
|
||
|
|
|
||
|
6 years ago
|
#ifdef USE_SDL1
|
||
|
6 years ago
|
void SetVideoMode(int width, int height, int bpp, uint32_t flags);
|
||
|
6 years ago
|
void SetVideoModeToPrimary(bool fullscreen, int width, int height);
|
||
|
6 years ago
|
#endif
|
||
|
|
|
||
|
5 years ago
|
bool IsFullScreen();
|
||
|
|
|
||
|
7 years ago
|
// Returns:
|
||
|
|
// SDL1: Video surface.
|
||
|
|
// SDL2, no upscale: Window surface.
|
||
|
|
// SDL2, upscale: Renderer texture surface.
|
||
|
|
SDL_Surface *GetOutputSurface();
|
||
|
|
|
||
|
6 years ago
|
// Whether the output surface requires software scaling.
|
||
|
|
// Always returns false on SDL2.
|
||
|
|
bool OutputRequiresScaling();
|
||
|
|
|
||
|
|
// Scales rect if necessary.
|
||
|
|
void ScaleOutputRect(SDL_Rect *rect);
|
||
|
|
|
||
|
6 years ago
|
// If the output requires software scaling, replaces the given surface with a scaled one.
|
||
|
5 years ago
|
SDLSurfaceUniquePtr ScaleSurfaceToOutput(SDLSurfaceUniquePtr surface);
|
||
|
|
|
||
|
6 years ago
|
// Convert from output coordinates to logical (resolution-independent) coordinates.
|
||
|
|
template <
|
||
|
|
typename T,
|
||
|
|
typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
|
||
|
|
void OutputToLogical(T *x, T *y)
|
||
|
|
{
|
||
|
|
#ifndef USE_SDL1
|
||
|
|
if (!renderer)
|
||
|
|
return;
|
||
|
|
float scaleX;
|
||
|
|
SDL_RenderGetScale(renderer, &scaleX, NULL);
|
||
|
|
*x /= scaleX;
|
||
|
|
*y /= scaleX;
|
||
|
|
|
||
|
|
SDL_Rect view;
|
||
|
|
SDL_RenderGetViewport(renderer, &view);
|
||
|
|
*x -= view.x;
|
||
|
|
*y -= view.y;
|
||
|
|
#else
|
||
|
|
if (!OutputRequiresScaling())
|
||
|
|
return;
|
||
|
6 years ago
|
const SDL_Surface *surface = GetOutputSurface();
|
||
|
5 years ago
|
*x = *x * gnScreenWidth / surface->w;
|
||
|
|
*y = *y * gnScreenHeight / surface->h;
|
||
|
6 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
template <
|
||
|
|
typename T,
|
||
|
|
typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
|
||
|
|
void LogicalToOutput(T *x, T *y)
|
||
|
|
{
|
||
|
|
#ifndef USE_SDL1
|
||
|
|
if (!renderer)
|
||
|
|
return;
|
||
|
|
SDL_Rect view;
|
||
|
|
SDL_RenderGetViewport(renderer, &view);
|
||
|
|
*x += view.x;
|
||
|
|
*y += view.y;
|
||
|
|
|
||
|
|
float scaleX;
|
||
|
|
SDL_RenderGetScale(renderer, &scaleX, NULL);
|
||
|
|
*x *= scaleX;
|
||
|
|
*y *= scaleX;
|
||
|
|
#else
|
||
|
|
if (!OutputRequiresScaling())
|
||
|
|
return;
|
||
|
6 years ago
|
const SDL_Surface *surface = GetOutputSurface();
|
||
|
5 years ago
|
*x = *x * surface->w / gnScreenWidth;
|
||
|
|
*y = *y * surface->h / gnScreenHeight;
|
||
|
6 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
} // namespace devilution
|