Files
86Box/src/qt/qt_ui.cpp

291 lines
6.7 KiB
C++
Raw Normal View History

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
* Common UI functions.
2022-02-07 15:00:02 +06:00
*
*
*
2023-01-06 15:36:05 -05:00
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
2022-02-07 15:00:02 +06:00
* Cacodemon345
*
2023-01-06 15:36:05 -05:00
* Copyright 2021 Joakim L. Gilje
* Copyright 2021-2022 Cacodemon345
2022-02-07 15:00:02 +06:00
*/
2021-11-25 10:20:56 +01:00
#include <cstdint>
2021-11-28 20:49:05 +01:00
#include <QDebug>
2021-11-25 10:20:56 +01:00
#include <QThread>
#include <QMessageBox>
2021-11-25 10:20:56 +01:00
#include <QStatusBar>
#include "qt_mainwindow.hpp"
#include "qt_machinestatus.hpp"
2021-11-25 10:20:56 +01:00
2022-11-19 08:49:04 -05:00
MainWindow *main_window = nullptr;
2021-11-25 10:20:56 +01:00
2023-05-29 01:30:51 -04:00
static QString sb_text;
static QString sb_buguitext;
static QString sb_mt32lcdtext;
2021-11-25 10:20:56 +01:00
extern "C" {
2022-07-12 14:41:38 +06:00
#include "86box/86box.h"
2021-11-25 10:20:56 +01:00
#include <86box/plat.h>
2022-02-02 22:08:19 +06:00
#include <86box/ui.h>
#include <86box/mouse.h>
#include <86box/timer.h>
#include <86box/86box.h>
#include <86box/device.h>
#include <86box/fdd.h>
#include <86box/hdc.h>
#include <86box/scsi.h>
#include <86box/scsi_device.h>
#include <86box/cartridge.h>
#include <86box/cassette.h>
#include <86box/cdrom.h>
#include <86box/zip.h>
#include <86box/mo.h>
#include <86box/hdd.h>
#include <86box/thread.h>
#include <86box/network.h>
#include <86box/machine_status.h>
2021-11-25 10:20:56 +01:00
void
plat_delay_ms(uint32_t count)
{
QThread::msleep(count);
}
2022-11-19 08:49:04 -05:00
wchar_t *
ui_window_title(wchar_t *str)
2021-11-25 10:20:56 +01:00
{
if (str == nullptr) {
static wchar_t title[512];
2021-12-01 15:55:41 +06:00
memset(title, 0, sizeof(title));
main_window->getTitle(title);
2021-11-25 10:20:56 +01:00
str = title;
} else {
emit main_window->setTitle(QString::fromWCharArray(str));
2021-11-25 10:20:56 +01:00
}
return str;
}
2023-01-03 15:42:57 +06:00
void
ui_hard_reset_completed()
{
emit main_window->hardResetCompleted();
}
2022-11-19 08:49:04 -05:00
extern "C" void
qt_blit(int x, int y, int w, int h, int monitor_index)
{
2022-07-04 01:50:42 +06:00
main_window->blitToWidget(x, y, w, h, monitor_index);
}
2022-07-12 14:41:38 +06:00
extern "C" int vid_resize;
2022-11-19 08:49:04 -05:00
void
plat_resize_request(int w, int h, int monitor_index)
2022-07-12 14:41:38 +06:00
{
2022-11-19 08:49:04 -05:00
if (video_fullscreen || is_quit)
return;
2022-07-12 14:41:38 +06:00
if (vid_resize & 2) {
plat_resize(fixed_size_x, fixed_size_y, monitor_index);
2022-11-19 08:49:04 -05:00
} else {
plat_resize(w, h, monitor_index);
2022-07-12 14:41:38 +06:00
}
}
2022-11-19 08:49:04 -05:00
void
plat_resize(int w, int h, int monitor_index)
2022-11-19 08:49:04 -05:00
{
if (monitor_index >= 1)
main_window->resizeContentsMonitor(w, h, monitor_index);
else
main_window->resizeContents(w, h);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
plat_mouse_capture(int on)
{
if (!kbd_req_capture && (mouse_type == MOUSE_TYPE_NONE) && !machine_has_mouse())
return;
2021-11-25 10:20:56 +01:00
main_window->setMouseCapture(on > 0 ? true : false);
}
2022-11-19 08:49:04 -05:00
int
ui_msgbox_header(int flags, void *header, void *message)
{
auto hdr = (flags & MBX_ANSI) ? QString((char *) header) : QString::fromWCharArray(reinterpret_cast<const wchar_t *>(header));
auto msg = (flags & MBX_ANSI) ? QString((char *) message) : QString::fromWCharArray(reinterpret_cast<const wchar_t *>(message));
2021-11-25 10:20:56 +01:00
// any error in early init
if (main_window == nullptr) {
QMessageBox msgBox(QMessageBox::Icon::Critical, hdr, msg);
msgBox.setTextFormat(Qt::TextFormat::RichText);
msgBox.exec();
} else {
// else scope it to main_window
main_window->showMessage(flags, hdr, msg);
}
2021-11-25 10:20:56 +01:00
return 0;
}
2022-11-19 08:49:04 -05:00
void
ui_init_monitor(int monitor_index)
{
2022-07-04 01:50:42 +06:00
if (QThread::currentThread() == main_window->thread()) {
emit main_window->initRendererMonitor(monitor_index);
2022-11-19 08:49:04 -05:00
} else
emit main_window->initRendererMonitorForNonQtThread(monitor_index);
2022-07-04 01:50:42 +06:00
}
2022-11-19 08:49:04 -05:00
void
ui_deinit_monitor(int monitor_index)
{
2022-07-04 01:50:42 +06:00
if (QThread::currentThread() == main_window->thread()) {
emit main_window->destroyRendererMonitor(monitor_index);
2022-11-19 08:49:04 -05:00
} else
emit main_window->destroyRendererMonitorForNonQtThread(monitor_index);
2022-07-04 01:50:42 +06:00
}
2022-11-19 08:49:04 -05:00
int
ui_msgbox(int flags, void *message)
{
2021-11-25 10:20:56 +01:00
return ui_msgbox_header(flags, nullptr, message);
}
2022-11-19 08:49:04 -05:00
void
ui_sb_update_text()
{
emit main_window->statusBarMessage(!sb_mt32lcdtext.isEmpty() ? sb_mt32lcdtext : sb_text.isEmpty() ? sb_buguitext
: sb_text);
}
2022-11-19 08:49:04 -05:00
void
ui_sb_mt32lcd(char *str)
{
sb_mt32lcdtext = QString(str);
ui_sb_update_text();
}
2022-11-19 08:49:04 -05:00
void
ui_sb_set_text_w(wchar_t *wstr)
{
sb_text = QString::fromWCharArray(wstr);
ui_sb_update_text();
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
ui_sb_set_text(char *str)
{
sb_text = str;
ui_sb_update_text();
}
2021-11-28 20:49:05 +01:00
void
2022-11-19 08:49:04 -05:00
ui_sb_update_tip(int arg)
{
main_window->updateStatusBarTip(arg);
2021-11-28 20:49:05 +01:00
}
void
2022-11-19 08:49:04 -05:00
ui_sb_update_panes()
{
2021-11-28 20:49:05 +01:00
main_window->updateStatusBarPanes();
}
2022-11-19 08:49:04 -05:00
void
ui_sb_bugui(char *str)
{
sb_buguitext = str;
2022-11-19 08:49:04 -05:00
ui_sb_update_text();
2021-11-28 20:49:05 +01:00
}
2022-11-19 08:49:04 -05:00
void
ui_sb_set_ready(int ready)
{
if (ready == 0) {
ui_sb_bugui(nullptr);
ui_sb_set_text(nullptr);
}
2021-11-28 20:49:05 +01:00
}
void
2022-11-19 08:49:04 -05:00
ui_sb_update_icon_state(int tag, int state)
{
int category = tag & 0xfffffff0;
2022-11-19 08:49:04 -05:00
int item = tag & 0xf;
switch (category) {
2022-11-19 08:49:04 -05:00
case SB_CASSETTE:
machine_status.cassette.empty = state > 0 ? true : false;
break;
case SB_CARTRIDGE:
machine_status.cartridge[item].empty = state > 0 ? true : false;
break;
case SB_FLOPPY:
machine_status.fdd[item].empty = state > 0 ? true : false;
break;
case SB_CDROM:
machine_status.cdrom[item].empty = state > 0 ? true : false;
break;
case SB_ZIP:
machine_status.zip[item].empty = state > 0 ? true : false;
break;
case SB_MO:
machine_status.mo[item].empty = state > 0 ? true : false;
break;
case SB_HDD:
break;
case SB_NETWORK:
machine_status.net[item].empty = state > 0 ? true : false;
break;
case SB_SOUND:
break;
case SB_TEXT:
break;
2021-11-28 20:49:05 +01:00
}
}
void
2022-11-19 08:49:04 -05:00
ui_sb_update_icon(int tag, int active)
{
int category = tag & 0xfffffff0;
2022-11-19 08:49:04 -05:00
int item = tag & 0xf;
switch (category) {
2022-11-19 08:49:04 -05:00
case SB_CASSETTE:
break;
case SB_CARTRIDGE:
break;
case SB_FLOPPY:
machine_status.fdd[item].active = active > 0 ? true : false;
break;
case SB_CDROM:
machine_status.cdrom[item].active = active > 0 ? true : false;
break;
case SB_ZIP:
machine_status.zip[item].active = active > 0 ? true : false;
break;
case SB_MO:
machine_status.mo[item].active = active > 0 ? true : false;
break;
case SB_HDD:
machine_status.hdd[item].active = active > 0 ? true : false;
break;
case SB_NETWORK:
machine_status.net[item].active = active > 0 ? true : false;
break;
case SB_SOUND:
break;
case SB_TEXT:
break;
}
2021-11-28 20:49:05 +01:00
}
2021-11-25 10:20:56 +01:00
}