22 #ifndef BACKENDS_GRAPHICS_WINDOWED_H 23 #define BACKENDS_GRAPHICS_WINDOWED_H 25 #include "backends/graphics/graphics.h" 26 #include "common/frac.h" 27 #include "common/rect.h" 28 #include "common/config-manager.h" 29 #include "common/textconsole.h" 30 #include "graphics/scaler/aspect.h" 35 STRETCH_INTEGRAL_AR = 2,
38 STRETCH_FIT_FORCE_ASPECT = 5
42 SCREEN_ALIGN_CENTER = 0,
43 SCREEN_ALIGN_LEFT = 1,
44 SCREEN_ALIGN_RIGHT = 2,
45 SCREEN_ALIGN_XMASK = 3,
46 SCREEN_ALIGN_MIDDLE = 0,
48 SCREEN_ALIGN_BOTTOM = 8,
49 SCREEN_ALIGN_YMASK = 12
69 void showOverlay(
bool inGUI)
override {
90 void hideOverlay()
override {
106 void setShakePos(
int shakeXOffset,
int shakeYOffset)
override {
144 if (sourceWidth == 0 || sourceHeight == 0) {
145 error(
"convertVirtualToWindow called without a valid draw rect");
148 int windowX = targetX + (x * targetWidth + sourceWidth / 2) / sourceWidth;
149 int windowY = targetY + (y * targetHeight + sourceHeight / 2) / sourceHeight;
151 return Common::Point(CLIP<int>(windowX, targetX, targetX + targetWidth - 1),
152 CLIP<int>(windowY, targetY, targetY + targetHeight - 1));
170 if (sourceWidth == 0 || sourceHeight == 0) {
171 error(
"convertWindowToVirtual called without a valid draw rect");
174 x = CLIP<int>(x, sourceX, sourceMaxX);
175 y = CLIP<int>(y, sourceY, sourceMaxY);
177 int virtualX = ((x - sourceX) * targetWidth + sourceWidth / 2) / sourceWidth;
178 int virtualY = ((y - sourceY) * targetHeight + sourceHeight / 2) / sourceHeight;
180 return Common::Point(CLIP<int>(virtualX, 0, targetWidth - 1),
181 CLIP<int>(virtualY, 0, targetHeight - 1));
189 return intToFrac(4) / 3;
192 return intToFrac(getWidth()) / getHeight();
225 if (getOverlayHeight()) {
226 const frac_t overlayAspect = intToFrac(getOverlayWidth()) / getOverlayHeight();
227 populateDisplayAreaDrawRect(overlayAspect, getOverlayWidth(), getOverlayHeight(),
_overlayDrawRect);
256 bool showMouse(
bool visible)
override {
277 if (virtualCursor.
x != x || virtualCursor.
y != y) {
299 if (
_cursorX != x || _cursorY != y) {
409 void populateDisplayAreaDrawRect(
const frac_t displayAspect,
int originalWidth,
int originalHeight,
Common::Rect &
drawRect)
const {
410 int mode = getStretchMode();
412 int rotatedWindowWidth;
413 int rotatedWindowHeight;
415 if (rotation == Common::kRotation90 || rotation == Common::kRotation270) {
428 int width = 0, height = 0;
429 if (mode == STRETCH_CENTER || mode == STRETCH_INTEGRAL || mode == STRETCH_INTEGRAL_AR) {
430 width = originalWidth;
431 height = intToFrac(width) / displayAspect;
432 if (width > rotatedWindowWidth || height > rotatedWindowHeight) {
433 int fac = 1 +
MAX((width - 1) / rotatedWindowWidth, (height - 1) / rotatedWindowHeight);
436 }
else if (mode == STRETCH_INTEGRAL) {
437 int fac =
MIN(rotatedWindowWidth / width, rotatedWindowHeight / height);
440 }
else if (mode == STRETCH_INTEGRAL_AR) {
441 int targetHeight =
height;
442 int horizontalFac = rotatedWindowWidth /
width;
444 width = originalWidth * horizontalFac;
445 int verticalFac = (targetHeight * horizontalFac + originalHeight / 2) / originalHeight;
446 height = originalHeight * verticalFac;
448 }
while (horizontalFac > 0 && height > rotatedWindowHeight);
449 if (height > rotatedWindowHeight)
450 height = targetHeight;
453 frac_t windowAspect = intToFrac(rotatedWindowWidth) / rotatedWindowHeight;
454 width = rotatedWindowWidth;
455 height = rotatedWindowHeight;
456 if (mode == STRETCH_FIT_FORCE_ASPECT) {
457 frac_t ratio = intToFrac(4) / 3;
458 if (windowAspect < ratio)
459 height = intToFrac(width) / ratio;
460 else if (windowAspect > ratio)
461 width = fracToInt(height * ratio);
462 }
else if (mode != STRETCH_STRETCH) {
463 if (windowAspect < displayAspect)
464 height = intToFrac(width) / displayAspect;
465 else if (windowAspect > displayAspect)
466 width = fracToInt(height * displayAspect);
471 switch (_screenAlign & SCREEN_ALIGN_XMASK) {
473 case SCREEN_ALIGN_CENTER:
474 alignX = ((rotatedWindowWidth -
width) / 2);
476 case SCREEN_ALIGN_LEFT:
479 case SCREEN_ALIGN_RIGHT:
480 alignX = (rotatedWindowWidth -
width);
484 switch (_screenAlign & SCREEN_ALIGN_YMASK) {
486 case SCREEN_ALIGN_MIDDLE:
487 alignY = ((rotatedWindowHeight -
height) / 2);
489 case SCREEN_ALIGN_TOP:
492 case SCREEN_ALIGN_BOTTOM:
493 alignY = (rotatedWindowHeight -
height);
497 drawRect.
left = alignX + _gameScreenShakeXOffset * width / getWidth();
498 drawRect.top = alignY + _gameScreenShakeYOffset * height / getHeight();
void setHeight(int16 aHeight)
Definition: rect.h:198
int _gameScreenShakeYOffset
Definition: windowed.h:342
Common::Point convertVirtualToWindow(const int x, const int y) const
Definition: windowed.h:136
virtual void handleResizeImpl(const int width, const int height)=0
int16 right
Definition: rect.h:146
Common::Rect _gameDrawRect
Definition: windowed.h:347
bool _cursorNeedsRedraw
Definition: windowed.h:395
virtual bool gameNeedsAspectRatioCorrection() const =0
int _windowHeight
Definition: windowed.h:315
bool _overlayVisible
Definition: windowed.h:327
int height
Definition: windowed.h:372
int _cursorX
Definition: windowed.h:406
bool _cursorVisible
Definition: windowed.h:390
frac_t getDesiredGameAspectRatio() const
Definition: windowed.h:187
Definition: windowed.h:52
bool _overlayInGUI
Definition: windowed.h:332
bool _forceRedraw
Definition: windowed.h:385
Common::Rect drawRect
Definition: windowed.h:362
int _windowWidth
Definition: windowed.h:310
int16 width() const
Definition: rect.h:191
Common::Point convertWindowToVirtual(int x, int y) const
Definition: windowed.h:160
bool _cursorLastInActiveArea
Definition: windowed.h:401
void setWidth(int16 aWidth)
Definition: rect.h:194
void handleResize(const int width, const int height)
Definition: windowed.h:208
int width
Definition: windowed.h:367
int16 left
Definition: rect.h:145
virtual void recalculateDisplayAreas()
Definition: windowed.h:218
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: windowed.h:358
void setMousePosition(int x, int y)
Definition: windowed.h:298
Definition: graphics.h:37
int16 x
Definition: rect.h:46
void warpMouse(int x, int y) override
Definition: windowed.h:273
RotationMode
Definition: rotationmode.h:44
int16 y
Definition: rect.h:47
T MIN(T a, T b)
Definition: util.h:59
DisplayArea _activeArea
Definition: windowed.h:380
Common::Rect _overlayDrawRect
Definition: windowed.h:353
T MAX(T a, T b)
Definition: util.h:62
virtual void setSystemMousePosition(const int x, const int y)=0
virtual int getGameRenderScale() const
Definition: windowed.h:198
int32 frac_t
Definition: frac.h:52
int _screenAlign
Definition: windowed.h:321
int _gameScreenShakeXOffset
Definition: windowed.h:337
int16 height() const
Definition: rect.h:192
virtual void notifyActiveAreaChanged()
Definition: windowed.h:254