2022-02-07 15:00:02 +06:00
|
|
|
/*
|
2023-01-06 15:36:05 -05:00
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Program settings UI module.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
|
|
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Copyright 2021 Joakim L. Gilje
|
2022-02-07 15:00:02 +06:00
|
|
|
*/
|
|
|
|
|
|
2022-01-30 22:13:41 +02:00
|
|
|
#include "qt_renderercommon.hpp"
|
2021-12-29 23:49:09 +06:00
|
|
|
#include "qt_mainwindow.hpp"
|
2021-12-07 13:47:42 +01:00
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QWidget>
|
2021-12-29 23:49:09 +06:00
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QApplication>
|
2021-12-07 13:47:42 +01:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
#include <86box/86box.h>
|
2022-02-16 01:09:11 +06:00
|
|
|
#include <86box/plat.h>
|
2021-12-07 13:47:42 +01:00
|
|
|
#include <86box/video.h>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RendererCommon::RendererCommon() = default;
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
extern MainWindow *main_window;
|
2021-12-07 13:47:42 +01:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
static void
|
|
|
|
|
integer_scale(double *d, double *g)
|
|
|
|
|
{
|
2021-12-07 13:47:42 +01:00
|
|
|
double ratio;
|
|
|
|
|
|
|
|
|
|
if (*d > *g) {
|
|
|
|
|
ratio = std::floor(*d / *g);
|
2022-11-19 08:49:04 -05:00
|
|
|
*d = *g * ratio;
|
2021-12-07 13:47:42 +01:00
|
|
|
} else {
|
|
|
|
|
ratio = std::ceil(*d / *g);
|
2022-11-19 08:49:04 -05:00
|
|
|
*d = *g / ratio;
|
2021-12-07 13:47:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
|
|
|
|
RendererCommon::onResize(int width, int height)
|
|
|
|
|
{
|
2023-08-11 04:45:32 +02:00
|
|
|
/* This is needed so that the if below does not take like, 5 lines. */
|
|
|
|
|
bool is_fs = (video_fullscreen == 0);
|
|
|
|
|
bool parent_max = (parentWidget->isMaximized() == false);
|
|
|
|
|
bool main_is_ancestor = main_window->isAncestorOf(parentWidget);
|
|
|
|
|
bool main_max = main_window->isMaximized();
|
|
|
|
|
bool main_is_max = (main_is_ancestor && main_max == false);
|
|
|
|
|
|
|
|
|
|
if (is_fs && (video_fullscreen_scale_maximized ? (parent_max && main_is_max) : 1))
|
2021-12-07 13:47:42 +01:00
|
|
|
destination.setRect(0, 0, width, height);
|
2023-08-11 04:45:32 +02:00
|
|
|
else {
|
|
|
|
|
double dx;
|
|
|
|
|
double dy;
|
|
|
|
|
double dw;
|
|
|
|
|
double dh;
|
|
|
|
|
double gsr;
|
2021-12-07 13:47:42 +01:00
|
|
|
|
2023-08-11 04:45:32 +02:00
|
|
|
double hw = width;
|
|
|
|
|
double hh = height;
|
|
|
|
|
double gw = source.width();
|
|
|
|
|
double gh = source.height();
|
|
|
|
|
double hsr = hw / hh;
|
2023-10-14 23:42:02 +02:00
|
|
|
double r43 = 4.0 / 3.0;
|
2021-12-07 13:47:42 +01:00
|
|
|
|
2023-08-11 04:45:32 +02:00
|
|
|
switch (video_fullscreen_scale) {
|
|
|
|
|
case FULLSCR_SCALE_INT:
|
2023-10-13 23:30:31 +02:00
|
|
|
case FULLSCR_SCALE_INT43:
|
2023-10-14 23:42:02 +02:00
|
|
|
gsr = gw / gh;
|
2023-10-13 23:30:31 +02:00
|
|
|
|
2023-10-16 01:41:57 +02:00
|
|
|
if (video_fullscreen_scale == FULLSCR_SCALE_INT43) {
|
2023-10-16 18:30:35 +02:00
|
|
|
gh = gw / r43;
|
2023-12-17 15:34:18 -05:00
|
|
|
// gw = gw;
|
2021-12-07 13:47:42 +01:00
|
|
|
|
2023-10-16 01:41:57 +02:00
|
|
|
gsr = r43;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 04:45:32 +02:00
|
|
|
if (gsr <= hsr) {
|
|
|
|
|
dw = hh * gsr;
|
|
|
|
|
dh = hh;
|
|
|
|
|
} else {
|
|
|
|
|
dw = hw;
|
|
|
|
|
dh = hw / gsr;
|
|
|
|
|
}
|
2023-10-14 23:42:02 +02:00
|
|
|
|
2023-08-11 04:45:32 +02:00
|
|
|
integer_scale(&dw, &gw);
|
|
|
|
|
integer_scale(&dh, &gh);
|
2023-10-14 23:42:02 +02:00
|
|
|
|
2023-08-11 04:45:32 +02:00
|
|
|
dx = (hw - dw) / 2.0;
|
|
|
|
|
dy = (hh - dh) / 2.0;
|
|
|
|
|
destination.setRect((int) dx, (int) dy, (int) dw, (int) dh);
|
|
|
|
|
break;
|
|
|
|
|
case FULLSCR_SCALE_43:
|
|
|
|
|
case FULLSCR_SCALE_KEEPRATIO:
|
|
|
|
|
if (video_fullscreen_scale == FULLSCR_SCALE_43)
|
2023-10-14 23:42:02 +02:00
|
|
|
gsr = r43;
|
2023-08-11 04:45:32 +02:00
|
|
|
else
|
|
|
|
|
gsr = gw / gh;
|
2021-12-07 13:47:42 +01:00
|
|
|
|
2023-08-11 04:45:32 +02:00
|
|
|
if (gsr <= hsr) {
|
|
|
|
|
dw = hh * gsr;
|
|
|
|
|
dh = hh;
|
|
|
|
|
} else {
|
|
|
|
|
dw = hw;
|
|
|
|
|
dh = hw / gsr;
|
|
|
|
|
}
|
|
|
|
|
dx = (hw - dw) / 2.0;
|
|
|
|
|
dy = (hh - dh) / 2.0;
|
|
|
|
|
destination.setRect((int) dx, (int) dy, (int) dw, (int) dh);
|
|
|
|
|
break;
|
|
|
|
|
case FULLSCR_SCALE_FULL:
|
|
|
|
|
default:
|
|
|
|
|
destination.setRect(0, 0, (int) hw, (int) hh);
|
|
|
|
|
break;
|
2021-12-07 13:47:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-11 04:45:32 +02:00
|
|
|
|
2023-08-12 00:17:01 +02:00
|
|
|
monitors[r_monitor_index].mon_res_x = (double) destination.width();
|
|
|
|
|
monitors[r_monitor_index].mon_res_y = (double) destination.height();
|
2021-12-07 13:47:42 +01:00
|
|
|
}
|
2021-12-29 23:49:09 +06:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
bool
|
|
|
|
|
RendererCommon::eventDelegate(QEvent *event, bool &result)
|
2021-12-29 23:49:09 +06:00
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
switch (event->type()) {
|
2021-12-29 23:49:09 +06:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
|
result = QApplication::sendEvent(main_window, event);
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
|
case QEvent::Wheel:
|
|
|
|
|
case QEvent::Enter:
|
|
|
|
|
case QEvent::Leave:
|
|
|
|
|
result = QApplication::sendEvent(parentWidget, event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|