Merge branch 'qt' of https://github.com/jgilje/86Box into qt
This commit is contained in:
@@ -6,7 +6,13 @@ set(CMAKE_AUTORCC ON)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
add_library(plat STATIC qt.c qt_main.cpp qt_platform.cpp cpp11_thread.cpp)
|
||||
add_library(plat STATIC
|
||||
qt.c
|
||||
qt_main.cpp
|
||||
qt_platform.cpp
|
||||
sdl_joystick.cpp
|
||||
cpp11_thread.cpp
|
||||
)
|
||||
add_library(ui STATIC
|
||||
qt_ui.cpp
|
||||
qt_cdrom.c
|
||||
@@ -69,6 +75,9 @@ add_library(ui STATIC
|
||||
qt_deviceconfig.cpp
|
||||
qt_deviceconfig.hpp
|
||||
qt_deviceconfig.ui
|
||||
qt_joystickconfiguration.cpp
|
||||
qt_joystickconfiguration.hpp
|
||||
qt_joystickconfiguration.ui
|
||||
|
||||
qt_filefield.cpp
|
||||
qt_filefield.hpp
|
||||
|
||||
183
src/qt/qt_joystickconfiguration.cpp
Normal file
183
src/qt/qt_joystickconfiguration.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
#include "qt_joystickconfiguration.hpp"
|
||||
#include "ui_qt_joystickconfiguration.h"
|
||||
|
||||
extern "C" {
|
||||
#include <86box/device.h>
|
||||
#include <86box/gameport.h>
|
||||
}
|
||||
|
||||
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include "qt_models_common.hpp"
|
||||
|
||||
JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::JoystickConfiguration),
|
||||
type(type),
|
||||
joystick_nr(joystick_nr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
auto model = ui->comboBoxDevice->model();
|
||||
Models::AddEntry(model, "None", 0);
|
||||
for (int c = 0; c < joysticks_present; c++) {
|
||||
Models::AddEntry(model, plat_joystick_state[c].name, c+1);
|
||||
}
|
||||
|
||||
ui->comboBoxDevice->setCurrentIndex(joystick_state[joystick_nr].plat_joystick_nr);
|
||||
}
|
||||
|
||||
JoystickConfiguration::~JoystickConfiguration()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
int JoystickConfiguration::selectedDevice() {
|
||||
return ui->comboBoxDevice->currentIndex();
|
||||
}
|
||||
|
||||
int JoystickConfiguration::selectedAxis(int axis) {
|
||||
auto* cbox = findChild<QComboBox*>(QString("cboxAxis%1").arg(QString::number(axis)));
|
||||
if (cbox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return cbox->currentIndex();
|
||||
}
|
||||
|
||||
int JoystickConfiguration::selectedButton(int button) {
|
||||
auto* cbox = findChild<QComboBox*>(QString("cboxButton%1").arg(QString::number(button)));
|
||||
if (cbox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return cbox->currentIndex();
|
||||
}
|
||||
|
||||
int JoystickConfiguration::selectedPov(int pov) {
|
||||
auto* cbox = findChild<QComboBox*>(QString("cboxPov%1").arg(QString::number(pov)));
|
||||
if (cbox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return cbox->currentIndex();
|
||||
}
|
||||
|
||||
void JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) {
|
||||
for (auto w : widgets) {
|
||||
ui->ct->removeWidget(w);
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int joystick = index - 1;
|
||||
int row = 0;
|
||||
for (int c = 0; c < joystick_get_axis_count(type); c++) {
|
||||
/*Combo box*/
|
||||
auto label = new QLabel(joystick_get_axis_name(type, c), this);
|
||||
auto cbox = new QComboBox(this);
|
||||
cbox->setObjectName(QString("cboxAxis%1").arg(QString::number(c)));
|
||||
auto model = cbox->model();
|
||||
|
||||
for (int d = 0; d < plat_joystick_state[joystick].nr_axes; d++) {
|
||||
Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0);
|
||||
}
|
||||
|
||||
for (int d = 0; d < plat_joystick_state[joystick].nr_povs; d++) {
|
||||
Models::AddEntry(model, QString("%1 (X axis)").arg(plat_joystick_state[joystick].pov[d].name), 0);
|
||||
Models::AddEntry(model, QString("%1 (Y axis)").arg(plat_joystick_state[joystick].pov[d].name), 0);
|
||||
}
|
||||
|
||||
for (int d = 0; d < plat_joystick_state[joystick].nr_sliders; d++) {
|
||||
Models::AddEntry(model, plat_joystick_state[joystick].slider[d].name, 0);
|
||||
}
|
||||
|
||||
int nr_axes = plat_joystick_state[joystick].nr_axes;
|
||||
int nr_povs = plat_joystick_state[joystick].nr_povs;
|
||||
int mapping = joystick_state[joystick_nr].axis_mapping[c];
|
||||
if (mapping & POV_X)
|
||||
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2);
|
||||
else if (mapping & POV_Y)
|
||||
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2 + 1);
|
||||
else if (mapping & SLIDER)
|
||||
cbox->setCurrentIndex(nr_axes + nr_povs * 2 + (mapping & 3));
|
||||
else
|
||||
cbox->setCurrentIndex(mapping);
|
||||
|
||||
ui->ct->addWidget(label, row, 0);
|
||||
ui->ct->addWidget(cbox, row, 1);
|
||||
|
||||
widgets.append(label);
|
||||
widgets.append(cbox);
|
||||
|
||||
++row;
|
||||
}
|
||||
|
||||
for (int c = 0; c < joystick_get_button_count(type); c++) {
|
||||
auto label = new QLabel(joystick_get_button_name(type, c), this);
|
||||
auto cbox = new QComboBox(this);
|
||||
cbox->setObjectName(QString("cboxButton%1").arg(QString::number(c)));
|
||||
auto model = cbox->model();
|
||||
|
||||
for (int d = 0; d < plat_joystick_state[joystick].nr_buttons; d++) {
|
||||
Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0);
|
||||
}
|
||||
|
||||
cbox->setCurrentIndex(joystick_state[joystick_nr].button_mapping[c]);
|
||||
|
||||
ui->ct->addWidget(label, row, 0);
|
||||
ui->ct->addWidget(cbox, row, 1);
|
||||
|
||||
widgets.append(label);
|
||||
widgets.append(cbox);
|
||||
|
||||
++row;
|
||||
}
|
||||
|
||||
for (int c = 0; c < joystick_get_pov_count(type) * 2; c++) {
|
||||
QLabel* label;
|
||||
if (c & 1) {
|
||||
label = new QLabel(QString("%1 (Y axis)").arg(joystick_get_pov_name(type, c/2)), this);
|
||||
} else {
|
||||
label = new QLabel(QString("%1 (X axis)").arg(joystick_get_pov_name(type, c/2)), this);
|
||||
}
|
||||
auto cbox = new QComboBox(this);
|
||||
cbox->setObjectName(QString("cboxPov%1").arg(QString::number(c)));
|
||||
auto model = cbox->model();
|
||||
|
||||
for (int d = 0; d < plat_joystick_state[joystick].nr_povs; d++) {
|
||||
Models::AddEntry(model, QString("%1 (X axis)").arg(plat_joystick_state[joystick].pov[d].name), 0);
|
||||
Models::AddEntry(model, QString("%1 (Y axis)").arg(plat_joystick_state[joystick].pov[d].name), 0);
|
||||
}
|
||||
|
||||
for (int d = 0; d < plat_joystick_state[joystick].nr_axes; d++) {
|
||||
Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0);
|
||||
}
|
||||
|
||||
int mapping = joystick_state[joystick_nr].pov_mapping[c][0];
|
||||
int nr_povs = plat_joystick_state[joystick].nr_povs;
|
||||
if (mapping & POV_X)
|
||||
cbox->setCurrentIndex((mapping & 3) * 2);
|
||||
else if (mapping & POV_Y)
|
||||
cbox->setCurrentIndex((mapping & 3)*2 + 1);
|
||||
else
|
||||
cbox->setCurrentIndex(mapping + nr_povs * 2);
|
||||
|
||||
mapping = joystick_state[joystick_nr].pov_mapping[c][1];
|
||||
if (mapping & POV_X)
|
||||
cbox->setCurrentIndex((mapping & 3)*2);
|
||||
else if (mapping & POV_Y)
|
||||
cbox->setCurrentIndex((mapping & 3)*2 + 1);
|
||||
else
|
||||
cbox->setCurrentIndex(mapping + nr_povs*2);
|
||||
|
||||
ui->ct->addWidget(label, row, 0);
|
||||
ui->ct->addWidget(cbox, row, 1);
|
||||
|
||||
widgets.append(label);
|
||||
widgets.append(cbox);
|
||||
|
||||
++row;
|
||||
}
|
||||
}
|
||||
32
src/qt/qt_joystickconfiguration.hpp
Normal file
32
src/qt/qt_joystickconfiguration.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef QT_JOYSTICKCONFIGURATION_HPP
|
||||
#define QT_JOYSTICKCONFIGURATION_HPP
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class JoystickConfiguration;
|
||||
}
|
||||
|
||||
class JoystickConfiguration : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit JoystickConfiguration(int type, int joystick_nr, QWidget *parent = nullptr);
|
||||
~JoystickConfiguration();
|
||||
|
||||
int selectedDevice();
|
||||
int selectedAxis(int axis);
|
||||
int selectedButton(int button);
|
||||
int selectedPov(int pov);
|
||||
private slots:
|
||||
void on_comboBoxDevice_currentIndexChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::JoystickConfiguration *ui;
|
||||
QList<QWidget*> widgets;
|
||||
int type;
|
||||
int joystick_nr;
|
||||
};
|
||||
|
||||
#endif // QT_JOYSTICKCONFIGURATION_HPP
|
||||
87
src/qt/qt_joystickconfiguration.ui
Normal file
87
src/qt/qt_joystickconfiguration.ui
Normal file
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>JoystickConfiguration</class>
|
||||
<widget class="QDialog" name="JoystickConfiguration">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="ct"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBoxDevice"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>JoystickConfiguration</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>223</x>
|
||||
<y>278</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>199</x>
|
||||
<y>149</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>JoystickConfiguration</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>223</x>
|
||||
<y>278</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>199</x>
|
||||
<y>149</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -28,9 +28,16 @@ extern uint64_t tsc;
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include <QStatusBar>
|
||||
#include <QMenu>
|
||||
|
||||
#include "qt_mediamenu.hpp"
|
||||
#include "qt_mainwindow.hpp"
|
||||
#include "qt_soundgain.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
extern MainWindow* main_window;
|
||||
|
||||
namespace {
|
||||
struct PixmapSetActive {
|
||||
QPixmap normal;
|
||||
@@ -195,7 +202,7 @@ struct MachineStatus::States {
|
||||
std::array<StateEmptyActive, MO_NUM> mo;
|
||||
std::array<StateActive, HDD_BUS_USB> hdds;
|
||||
StateActive net;
|
||||
std::unique_ptr<QLabel> sound;
|
||||
std::unique_ptr<ClickableLabel> sound;
|
||||
std::unique_ptr<QLabel> text;
|
||||
};
|
||||
|
||||
@@ -211,16 +218,12 @@ bool MachineStatus::hasCassette() {
|
||||
return cassette_enable > 0 ? true : false;
|
||||
}
|
||||
|
||||
bool MachineStatus::hasCartridge() {
|
||||
return machines[machine].flags & MACHINE_CARTRIDGE;
|
||||
}
|
||||
|
||||
bool MachineStatus::hasIDE() {
|
||||
return machines[machine].flags & MACHINE_IDE_QUAD;
|
||||
return machine_has_flags(machine, MACHINE_IDE_QUAD) > 0;
|
||||
}
|
||||
|
||||
bool MachineStatus::hasSCSI() {
|
||||
return machines[machine].flags & MACHINE_SCSI_DUAL;
|
||||
return machine_has_flags(machine, MACHINE_SCSI_DUAL) > 0;
|
||||
}
|
||||
|
||||
void MachineStatus::iterateFDD(const std::function<void (int)> &cb) {
|
||||
@@ -296,9 +299,9 @@ static int hdd_count(int bus) {
|
||||
}
|
||||
|
||||
void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
bool has_mfm = machines[machine].flags & MACHINE_MFM;
|
||||
bool has_xta = machines[machine].flags & MACHINE_XTA;
|
||||
bool has_esdi = machines[machine].flags & MACHINE_ESDI;
|
||||
bool has_mfm = machine_has_flags(machine, MACHINE_MFM) > 0;
|
||||
bool has_xta = machine_has_flags(machine, MACHINE_XTA) > 0;
|
||||
bool has_esdi = machine_has_flags(machine, MACHINE_ESDI) > 0;
|
||||
|
||||
int c_mfm = hdd_count(HDD_BUS_MFM);
|
||||
int c_esdi = hdd_count(HDD_BUS_ESDI);
|
||||
@@ -330,15 +333,23 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
sbar->removeWidget(d->sound.get());
|
||||
|
||||
if (cassette_enable) {
|
||||
d->cassette.label = std::make_unique<QLabel>();
|
||||
d->cassette.label = std::make_unique<ClickableLabel>();
|
||||
d->cassette.setEmpty(QString(cassette_fname).isEmpty());
|
||||
connect((ClickableLabel*)d->cassette.label.get(), &ClickableLabel::clicked, [this](QPoint pos) {
|
||||
MediaMenu::ptr->cassetteMenu->popup(pos);
|
||||
});
|
||||
d->cassette.label->setToolTip(MediaMenu::ptr->cassetteMenu->title());
|
||||
sbar->addWidget(d->cassette.label.get());
|
||||
}
|
||||
|
||||
if (hasCartridge()) {
|
||||
if (machine_has_cartridge(machine)) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
d->cartridge[i].label = std::make_unique<QLabel>();
|
||||
d->cartridge[i].setEmpty(QString(cart_fns[i]).isEmpty());
|
||||
connect((ClickableLabel*)d->cartridge[i].label.get(), &ClickableLabel::clicked, [this, i](QPoint pos) {
|
||||
MediaMenu::ptr->cartridgeMenus[i]->popup(pos);
|
||||
});
|
||||
d->cartridge[i].label->setToolTip(MediaMenu::ptr->cartridgeMenus[i]->title());
|
||||
sbar->addWidget(d->cartridge[i].label.get());
|
||||
}
|
||||
}
|
||||
@@ -352,68 +363,96 @@ void MachineStatus::refresh(QStatusBar* sbar) {
|
||||
} else {
|
||||
d->fdd[i].pixmaps = &d->pixmaps.floppy_35;
|
||||
}
|
||||
d->fdd[i].label = std::make_unique<QLabel>();
|
||||
d->fdd[i].label = std::make_unique<ClickableLabel>();
|
||||
d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty());
|
||||
d->fdd[i].setActive(false);
|
||||
connect((ClickableLabel*)d->fdd[i].label.get(), &ClickableLabel::clicked, [this, i](QPoint pos) {
|
||||
MediaMenu::ptr->floppyMenus[i]->popup(pos);
|
||||
});
|
||||
d->fdd[i].label->setToolTip(MediaMenu::ptr->floppyMenus[i]->title());
|
||||
sbar->addWidget(d->fdd[i].label.get());
|
||||
});
|
||||
|
||||
iterateCDROM([this, sbar](int i) {
|
||||
d->cdrom[i].label = std::make_unique<QLabel>();
|
||||
d->cdrom[i].label = std::make_unique<ClickableLabel>();
|
||||
d->cdrom[i].setEmpty(cdrom[i].host_drive != 200 || QString(cdrom[i].image_path).isEmpty());
|
||||
d->cdrom[i].setActive(false);
|
||||
connect((ClickableLabel*)d->cdrom[i].label.get(), &ClickableLabel::clicked, [this, i](QPoint pos) {
|
||||
MediaMenu::ptr->cdromMenus[i]->popup(pos);
|
||||
});
|
||||
d->cdrom[i].label->setToolTip(MediaMenu::ptr->cdromMenus[i]->title());
|
||||
sbar->addWidget(d->cdrom[i].label.get());
|
||||
});
|
||||
|
||||
iterateZIP([this, sbar](int i) {
|
||||
d->zip[i].label = std::make_unique<QLabel>();
|
||||
d->zip[i].label = std::make_unique<ClickableLabel>();
|
||||
d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty());
|
||||
d->zip[i].setActive(false);
|
||||
connect((ClickableLabel*)d->zip[i].label.get(), &ClickableLabel::clicked, [this, i](QPoint pos) {
|
||||
MediaMenu::ptr->zipMenus[i]->popup(pos);
|
||||
});
|
||||
d->zip[i].label->setToolTip(MediaMenu::ptr->zipMenus[i]->title());
|
||||
sbar->addWidget(d->zip[i].label.get());
|
||||
});
|
||||
|
||||
iterateMO([this, sbar](int i) {
|
||||
d->mo[i].label = std::make_unique<QLabel>();
|
||||
d->mo[i].label = std::make_unique<ClickableLabel>();
|
||||
d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty());
|
||||
d->mo[i].setActive(false);
|
||||
connect((ClickableLabel*)d->mo[i].label.get(), &ClickableLabel::clicked, [this, i](QPoint pos) {
|
||||
MediaMenu::ptr->moMenus[i]->popup(pos);
|
||||
});
|
||||
d->mo[i].label->setToolTip(MediaMenu::ptr->moMenus[i]->title());
|
||||
sbar->addWidget(d->mo[i].label.get());
|
||||
});
|
||||
|
||||
auto hdc_name = QString(hdc_get_internal_name(hdc_current));
|
||||
if ((has_mfm || hdc_name == QStringLiteral("st506")) && c_mfm > 0) {
|
||||
if ((has_mfm || hdc_name.left(5) == QStringLiteral("st506")) && c_mfm > 0) {
|
||||
d->hdds[HDD_BUS_MFM].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_MFM].setActive(false);
|
||||
d->hdds[HDD_BUS_MFM].label->setToolTip(QStringLiteral("Hard Disk (%1)").arg("MFM/RLL"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_MFM].label.get());
|
||||
}
|
||||
if ((has_esdi || hdc_name == QStringLiteral("esdi")) && c_esdi > 0) {
|
||||
if ((has_esdi || hdc_name.left(4) == QStringLiteral("esdi")) && c_esdi > 0) {
|
||||
d->hdds[HDD_BUS_ESDI].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_ESDI].setActive(false);
|
||||
d->hdds[HDD_BUS_ESDI].label->setToolTip(QStringLiteral("Hard Disk (%1)").arg("ESDI"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_ESDI].label.get());
|
||||
}
|
||||
if ((has_xta || hdc_name == QStringLiteral("xta")) && c_xta > 0) {
|
||||
if ((has_xta || hdc_name.left(3) == QStringLiteral("xta")) && c_xta > 0) {
|
||||
d->hdds[HDD_BUS_XTA].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_XTA].setActive(false);
|
||||
d->hdds[HDD_BUS_XTA].label->setToolTip(QStringLiteral("Hard Disk (%1)").arg("XTA"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_XTA].label.get());
|
||||
}
|
||||
if ((hasIDE() || hdc_name == QStringLiteral("xtide") || hdc_name == QStringLiteral("ide")) && c_ide > 0) {
|
||||
if ((hasIDE() || hdc_name.left(5) == QStringLiteral("xtide") || hdc_name.left(3) == QStringLiteral("ide")) && c_ide > 0) {
|
||||
d->hdds[HDD_BUS_IDE].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_IDE].setActive(false);
|
||||
d->hdds[HDD_BUS_IDE].label->setToolTip(QStringLiteral("Hard Disk (%1)").arg("IDE"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_IDE].label.get());
|
||||
}
|
||||
if ((hasSCSI() || (scsi_card_current[0] != 0) || (scsi_card_current[1] != 0) ||
|
||||
(scsi_card_current[2] != 0) || (scsi_card_current[3] != 0)) && c_scsi > 0) {
|
||||
d->hdds[HDD_BUS_SCSI].label = std::make_unique<QLabel>();
|
||||
d->hdds[HDD_BUS_SCSI].setActive(false);
|
||||
d->hdds[HDD_BUS_SCSI].label->setToolTip(QStringLiteral("Hard Disk (%1)").arg("SCSI"));
|
||||
sbar->addWidget(d->hdds[HDD_BUS_SCSI].label.get());
|
||||
}
|
||||
|
||||
if (do_net) {
|
||||
d->net.label = std::make_unique<QLabel>();
|
||||
d->net.setActive(false);
|
||||
d->net.label->setToolTip("Network");
|
||||
sbar->addWidget(d->net.label.get());
|
||||
}
|
||||
d->sound = std::make_unique<QLabel>();
|
||||
d->sound = std::make_unique<ClickableLabel>();
|
||||
d->sound->setPixmap(d->pixmaps.sound);
|
||||
|
||||
connect(d->sound.get(), &ClickableLabel::doubleClicked, d->sound.get(), [this](QPoint pos) {
|
||||
SoundGain gain(main_window);
|
||||
gain.exec();
|
||||
});
|
||||
d->sound->setToolTip("Sound");
|
||||
sbar->addWidget(d->sound.get());
|
||||
d->text = std::make_unique<QLabel>();
|
||||
sbar->addWidget(d->text.get());
|
||||
@@ -489,3 +528,36 @@ void MachineStatus::message(const QString &msg) {
|
||||
d->text->setText(msg);
|
||||
}
|
||||
|
||||
void MachineStatus::updateTip(int tag)
|
||||
{
|
||||
int category = tag & 0xfffffff0;
|
||||
int item = tag & 0xf;
|
||||
switch (category) {
|
||||
case SB_CASSETTE:
|
||||
d->cassette.label->setToolTip(MediaMenu::ptr->cassetteMenu->title());
|
||||
break;
|
||||
case SB_CARTRIDGE:
|
||||
d->cartridge[item].label->setToolTip(MediaMenu::ptr->cartridgeMenus[item]->title());
|
||||
break;
|
||||
case SB_FLOPPY:
|
||||
d->fdd[item].label->setToolTip(MediaMenu::ptr->floppyMenus[item]->title());
|
||||
break;
|
||||
case SB_CDROM:
|
||||
d->cdrom[item].label->setToolTip(MediaMenu::ptr->cdromMenus[item]->title());
|
||||
break;
|
||||
case SB_ZIP:
|
||||
d->zip[item].label->setToolTip(MediaMenu::ptr->zipMenus[item]->title());
|
||||
break;
|
||||
case SB_MO:
|
||||
d->mo[item].label->setToolTip(MediaMenu::ptr->moMenus[item]->title());
|
||||
break;
|
||||
case SB_HDD:
|
||||
break;
|
||||
case SB_NETWORK:
|
||||
break;
|
||||
case SB_SOUND:
|
||||
break;
|
||||
case SB_TEXT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,27 @@
|
||||
#define QT_MACHINESTATUS_HPP
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
|
||||
class QStatusBar;
|
||||
|
||||
class ClickableLabel : public QLabel {
|
||||
Q_OBJECT;
|
||||
public:
|
||||
explicit ClickableLabel(QWidget* parent = nullptr)
|
||||
: QLabel(parent) {}
|
||||
~ClickableLabel() {};
|
||||
|
||||
signals:
|
||||
void clicked(QPoint);
|
||||
void doubleClicked(QPoint);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) override { emit clicked(event->globalPos()); }
|
||||
void mouseDoubleClickEvent(QMouseEvent* event) override { emit doubleClicked(event->globalPos()); }
|
||||
};
|
||||
|
||||
class MachineStatus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -14,7 +32,6 @@ public:
|
||||
~MachineStatus();
|
||||
|
||||
static bool hasCassette();
|
||||
static bool hasCartridge();
|
||||
static bool hasIDE();
|
||||
static bool hasSCSI();
|
||||
static void iterateFDD(const std::function<void(int i)>& cb);
|
||||
@@ -26,6 +43,7 @@ public slots:
|
||||
void setActivity(int tag, bool active);
|
||||
void setEmpty(int tag, bool active);
|
||||
void message(const QString& msg);
|
||||
void updateTip(int tag);
|
||||
|
||||
private:
|
||||
struct States;
|
||||
|
||||
@@ -49,9 +49,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
Q_INIT_RESOURCE(qt_resources);
|
||||
status = std::make_unique<MachineStatus>(this);
|
||||
mm = std::make_shared<MediaMenu>(this);
|
||||
MediaMenu::ptr = mm;
|
||||
status = std::make_unique<MachineStatus>(this);
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->stackedWidget->setMouseTracking(true);
|
||||
@@ -63,7 +63,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection);
|
||||
|
||||
connect(this, &MainWindow::setTitleForNonQtThread, this, &MainWindow::setTitle_, Qt::BlockingQueuedConnection);
|
||||
connect(this, &MainWindow::setTitle, this, [this](const QString& title) {
|
||||
setWindowTitle(title);
|
||||
});
|
||||
connect(this, &MainWindow::getTitleForNonQtThread, this, &MainWindow::getTitle_, Qt::BlockingQueuedConnection);
|
||||
|
||||
connect(this, &MainWindow::updateMenuResizeOptions, [this]() {
|
||||
@@ -118,9 +120,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
});
|
||||
|
||||
connect(this, &MainWindow::updateStatusBarPanes, this, [this] {
|
||||
status->refresh(ui->statusbar);
|
||||
refreshMediaMenu();
|
||||
});
|
||||
connect(this, &MainWindow::updateStatusBarPanes, this, &MainWindow::refreshMediaMenu);
|
||||
connect(this, &MainWindow::updateStatusBarTip, status.get(), &MachineStatus::updateTip);
|
||||
connect(this, &MainWindow::updateStatusBarActivity, status.get(), &MachineStatus::setActivity);
|
||||
connect(this, &MainWindow::updateStatusBarEmpty, status.get(), &MachineStatus::setEmpty);
|
||||
connect(this, &MainWindow::statusBarMessage, status.get(), &MachineStatus::message);
|
||||
@@ -879,20 +882,6 @@ void MainWindow::on_actionFullscreen_triggered() {
|
||||
rc->onResize(widget->width(), widget->height());
|
||||
}
|
||||
|
||||
void MainWindow::setTitle_(const wchar_t *title)
|
||||
{
|
||||
this->setWindowTitle(QString::fromWCharArray(title));
|
||||
}
|
||||
|
||||
void MainWindow::setTitle(const wchar_t *title)
|
||||
{
|
||||
if (QThread::currentThread() == this->thread()) {
|
||||
setTitle_(title);
|
||||
} else {
|
||||
emit setTitleForNonQtThread(title);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::getTitle_(wchar_t *title)
|
||||
{
|
||||
this->windowTitle().toWCharArray(title);
|
||||
@@ -927,6 +916,7 @@ bool MainWindow::eventFilter(QObject* receiver, QEvent* event)
|
||||
|
||||
void MainWindow::refreshMediaMenu() {
|
||||
mm->refresh(ui->menuMedia);
|
||||
status->refresh(ui->statusbar);
|
||||
}
|
||||
|
||||
void MainWindow::showMessage(const QString& header, const QString& message) {
|
||||
|
||||
@@ -25,7 +25,6 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
void showMessage(const QString& header, const QString& message);
|
||||
void setTitle(const wchar_t* title);
|
||||
void getTitle(wchar_t* title);
|
||||
void blitToWidget(int x, int y, int w, int h);
|
||||
QSize getRenderWidgetSize();
|
||||
@@ -38,14 +37,15 @@ signals:
|
||||
void updateStatusBarPanes();
|
||||
void updateStatusBarActivity(int tag, bool active);
|
||||
void updateStatusBarEmpty(int tag, bool empty);
|
||||
void updateStatusBarTip(int tag);
|
||||
void updateMenuResizeOptions();
|
||||
void updateWindowRememberOption();
|
||||
|
||||
void setTitle(const QString& title);
|
||||
void setFullscreen(bool state);
|
||||
void setMouseCapture(bool state);
|
||||
|
||||
void showMessageForNonQtThread(const QString& header, const QString& message);
|
||||
void setTitleForNonQtThread(const wchar_t* title);
|
||||
void getTitleForNonQtThread(wchar_t* title);
|
||||
private slots:
|
||||
void on_actionFullscreen_triggered();
|
||||
@@ -94,7 +94,6 @@ private slots:
|
||||
|
||||
void refreshMediaMenu();
|
||||
void showMessage_(const QString& header, const QString& message);
|
||||
void setTitle_(const wchar_t* title);
|
||||
void getTitle_(wchar_t* title);
|
||||
void on_actionTake_screenshot_triggered();
|
||||
|
||||
|
||||
@@ -56,14 +56,14 @@ void MediaMenu::refresh(QMenu *parentMenu) {
|
||||
}
|
||||
|
||||
cartridgeMenus.clear();
|
||||
if (MachineStatus::hasCartridge()) {
|
||||
if (machine_has_cartridge(machine)) {
|
||||
for(int i = 0; i < 2; i++) {
|
||||
auto* menu = parentMenu->addMenu("");
|
||||
menu->addAction("Image", [this, i]() { cartridgeSelectImage(i); });
|
||||
menu->addSeparator();
|
||||
cartridgeEjectPos = menu->children().count();
|
||||
menu->addAction("Eject", [this, i]() { cartridgeEject(i); });
|
||||
cartridgeMenus.append(menu);
|
||||
cartridgeMenus[i] = menu;
|
||||
cartridgeUpdateMenu(i);
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ void MediaMenu::refresh(QMenu *parentMenu) {
|
||||
menu->addSeparator();
|
||||
floppyEjectPos = menu->children().count();
|
||||
menu->addAction("Eject", [this, i]() { floppyEject(i); });
|
||||
floppyMenus.append(menu);
|
||||
floppyMenus[i] = menu;
|
||||
floppyUpdateMenu(i);
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ void MediaMenu::refresh(QMenu *parentMenu) {
|
||||
menu->addSeparator();
|
||||
cdromImagePos = menu->children().count();
|
||||
menu->addAction("Image", [this, i]() { cdromMount(i); })->setCheckable(true);
|
||||
cdromMenus.append(menu);
|
||||
cdromMenus[i] = menu;
|
||||
cdromUpdateMenu(i);
|
||||
});
|
||||
|
||||
@@ -114,7 +114,7 @@ void MediaMenu::refresh(QMenu *parentMenu) {
|
||||
menu->addAction("Eject", [this, i]() { zipEject(i); });
|
||||
zipReloadPos = menu->children().count();
|
||||
menu->addAction("Reload previous image", [this, i]() { zipReload(i); });
|
||||
zipMenus.append(menu);
|
||||
zipMenus[i] = menu;
|
||||
zipUpdateMenu(i);
|
||||
});
|
||||
|
||||
@@ -130,7 +130,7 @@ void MediaMenu::refresh(QMenu *parentMenu) {
|
||||
menu->addAction("Eject", [this, i]() { moEject(i); });
|
||||
moReloadPos = menu->children().count();
|
||||
menu->addAction("Reload previous image", [this, i]() { moReload(i); });
|
||||
moMenus.append(menu);
|
||||
moMenus[i] = menu;
|
||||
moUpdateMenu(i);
|
||||
});
|
||||
}
|
||||
@@ -161,8 +161,8 @@ void MediaMenu::cassetteMount(const QString& filename, bool wp) {
|
||||
}
|
||||
|
||||
ui_sb_update_icon_state(SB_CASSETTE, filename.isEmpty() ? 1 : 0);
|
||||
ui_sb_update_tip(SB_CASSETTE);
|
||||
cassetteUpdateMenu();
|
||||
ui_sb_update_tip(SB_CASSETTE);
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ void MediaMenu::cassetteEject() {
|
||||
pc_cas_set_fname(cassette, nullptr);
|
||||
memset(cassette_fname, 0, sizeof(cassette_fname));
|
||||
ui_sb_update_icon_state(SB_CASSETTE, 1);
|
||||
ui_sb_update_tip(SB_CASSETTE);
|
||||
cassetteUpdateMenu();
|
||||
ui_sb_update_tip(SB_CASSETTE);
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -208,16 +208,16 @@ void MediaMenu::cartridgeSelectImage(int i) {
|
||||
cart_load(i, filenameBytes.data());
|
||||
|
||||
ui_sb_update_icon_state(SB_CARTRIDGE | i, filename.isEmpty() ? 1 : 0);
|
||||
ui_sb_update_tip(SB_CARTRIDGE | i);
|
||||
cartridgeUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_CARTRIDGE | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
void MediaMenu::cartridgeEject(int i) {
|
||||
cart_close(i);
|
||||
ui_sb_update_icon_state(SB_CARTRIDGE | i, 1);
|
||||
ui_sb_update_tip(SB_CARTRIDGE | i);
|
||||
cartridgeUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_CARTRIDGE | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -253,16 +253,16 @@ void MediaMenu::floppyMount(int i, const QString &filename, bool wp) {
|
||||
fdd_load(i, filenameBytes.data());
|
||||
}
|
||||
ui_sb_update_icon_state(SB_FLOPPY | i, filename.isEmpty() ? 1 : 0);
|
||||
ui_sb_update_tip(SB_FLOPPY | i);
|
||||
floppyUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_FLOPPY | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
void MediaMenu::floppyEject(int i) {
|
||||
fdd_close(i);
|
||||
ui_sb_update_icon_state(SB_FLOPPY | i, 1);
|
||||
ui_sb_update_tip(SB_FLOPPY | i);
|
||||
floppyUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_FLOPPY | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -329,19 +329,21 @@ void MediaMenu::cdromMount(int i) {
|
||||
} else {
|
||||
ui_sb_update_icon_state(SB_CDROM | i, 1);
|
||||
}
|
||||
ui_sb_update_tip(SB_CDROM | i);
|
||||
cdromUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_CDROM | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
void MediaMenu::cdromEject(int i) {
|
||||
cdrom_eject(i);
|
||||
cdromUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_CDROM | i);
|
||||
}
|
||||
|
||||
void MediaMenu::cdromReload(int i) {
|
||||
cdrom_reload(i);
|
||||
cdromUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_CDROM | i);
|
||||
}
|
||||
|
||||
void MediaMenu::cdromUpdateMenu(int i) {
|
||||
@@ -400,8 +402,8 @@ void MediaMenu::zipMount(int i, const QString &filename, bool wp) {
|
||||
}
|
||||
|
||||
ui_sb_update_icon_state(SB_ZIP | i, filename.isEmpty() ? 1 : 0);
|
||||
ui_sb_update_tip(SB_ZIP | i);
|
||||
zipUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_ZIP | i);
|
||||
|
||||
config_save();
|
||||
}
|
||||
@@ -416,8 +418,8 @@ void MediaMenu::zipEject(int i) {
|
||||
}
|
||||
|
||||
ui_sb_update_icon_state(SB_ZIP | i, 1);
|
||||
ui_sb_update_tip(SB_ZIP | i);
|
||||
zipUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_ZIP | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -431,8 +433,8 @@ void MediaMenu::zipReload(int i) {
|
||||
ui_sb_update_icon_state(SB_ZIP|i, 0);
|
||||
}
|
||||
|
||||
ui_sb_update_tip(SB_ZIP|i);
|
||||
zipUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_ZIP|i);
|
||||
|
||||
config_save();
|
||||
}
|
||||
@@ -488,8 +490,8 @@ void MediaMenu::moMount(int i, const QString &filename, bool wp) {
|
||||
}
|
||||
|
||||
ui_sb_update_icon_state(SB_MO | i, filename.isEmpty() ? 1 : 0);
|
||||
ui_sb_update_tip(SB_MO | i);
|
||||
moUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_MO | i);
|
||||
|
||||
config_save();
|
||||
}
|
||||
@@ -504,8 +506,8 @@ void MediaMenu::moEject(int i) {
|
||||
}
|
||||
|
||||
ui_sb_update_icon_state(SB_MO | i, 1);
|
||||
ui_sb_update_tip(SB_MO | i);
|
||||
moUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_MO | i);
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -519,8 +521,8 @@ void MediaMenu::moReload(int i) {
|
||||
ui_sb_update_icon_state(SB_MO|i, 0);
|
||||
}
|
||||
|
||||
ui_sb_update_tip(SB_MO|i);
|
||||
moUpdateMenu(i);
|
||||
ui_sb_update_tip(SB_MO|i);
|
||||
|
||||
config_save();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
|
||||
class QMenu;
|
||||
|
||||
@@ -57,11 +58,11 @@ private:
|
||||
QWidget* parentWidget = nullptr;
|
||||
|
||||
QMenu* cassetteMenu = nullptr;
|
||||
QList<QMenu*> cartridgeMenus;
|
||||
QList<QMenu*> floppyMenus;
|
||||
QList<QMenu*> cdromMenus;
|
||||
QList<QMenu*> zipMenus;
|
||||
QList<QMenu*> moMenus;
|
||||
QMap<int, QMenu*> cartridgeMenus;
|
||||
QMap<int, QMenu*> floppyMenus;
|
||||
QMap<int, QMenu*> cdromMenus;
|
||||
QMap<int, QMenu*> zipMenus;
|
||||
QMap<int, QMenu*> moMenus;
|
||||
|
||||
int cassetteRecordPos;
|
||||
int cassettePlayPos;
|
||||
@@ -84,4 +85,6 @@ private:
|
||||
|
||||
int moEjectPos;
|
||||
int moReloadPos;
|
||||
|
||||
friend class MachineStatus;
|
||||
};
|
||||
|
||||
@@ -70,9 +70,6 @@ int kbd_req_capture = 0;
|
||||
int hide_status_bar = 0;
|
||||
uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US
|
||||
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
joystick_t joystick_state[MAX_JOYSTICKS];
|
||||
|
||||
int stricmp(const char* s1, const char* s2)
|
||||
{
|
||||
return QByteArray(s1).compare(s2, Qt::CaseInsensitive);
|
||||
@@ -406,9 +403,6 @@ void dynld_close(void *handle)
|
||||
delete reinterpret_cast<QLibrary*>(handle);
|
||||
}
|
||||
|
||||
void joystick_init(void) {}
|
||||
void joystick_close(void) {}
|
||||
void joystick_process(void) {}
|
||||
void startblit()
|
||||
{
|
||||
blitmx_contention++;
|
||||
|
||||
@@ -36,7 +36,6 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) {
|
||||
// win_settings_video_proc, WM_INITDIALOG
|
||||
this->machineId = machineId;
|
||||
|
||||
auto* machine = &machines[machineId];
|
||||
auto* model = ui->comboBoxVideo->model();
|
||||
auto removeRows = model->rowCount();
|
||||
|
||||
@@ -44,7 +43,7 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) {
|
||||
int selectedRow = 0;
|
||||
while (true) {
|
||||
/* Skip "internal" if machine doesn't have it. */
|
||||
if ((c == 1) && !(machine->flags & MACHINE_VIDEO)) {
|
||||
if ((c == 1) && (machine_has_flags(machineId, MACHINE_VIDEO) == 0)) {
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
@@ -56,7 +55,7 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) {
|
||||
}
|
||||
|
||||
if (video_card_available(c) &&
|
||||
device_is_valid(video_dev, machine->flags)) {
|
||||
device_is_valid(video_dev, machineId)) {
|
||||
int row = Models::AddEntry(model, name, c);
|
||||
if (c == gfxcard) {
|
||||
selectedRow = row - removeRows;
|
||||
@@ -67,7 +66,7 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) {
|
||||
}
|
||||
model->removeRows(0, removeRows);
|
||||
|
||||
if (machine->flags & MACHINE_VIDEO_ONLY) {
|
||||
if (machine_has_flags(machineId, MACHINE_VIDEO_ONLY) > 0) {
|
||||
ui->comboBoxVideo->setEnabled(false);
|
||||
selectedRow = 1;
|
||||
} else {
|
||||
@@ -92,7 +91,7 @@ void SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) {
|
||||
int videoCard = ui->comboBoxVideo->currentData().toInt();
|
||||
ui->pushButtonConfigure->setEnabled(video_card_has_config(videoCard) > 0);
|
||||
|
||||
bool machineHasPci = machines[machineId].flags & MACHINE_BUS_PCI;
|
||||
bool machineHasPci = machine_has_bus(machineId, MACHINE_BUS_PCI) > 0;
|
||||
ui->checkBoxVoodoo->setEnabled(machineHasPci);
|
||||
if (machineHasPci) {
|
||||
ui->checkBoxVoodoo->setChecked(voodoo_enabled);
|
||||
|
||||
@@ -11,7 +11,9 @@ extern "C" {
|
||||
#include <86box/gameport.h>
|
||||
}
|
||||
|
||||
#include "qt_models_common.hpp"
|
||||
#include "qt_deviceconfig.hpp"
|
||||
#include "qt_joystickconfiguration.hpp"
|
||||
|
||||
SettingsInput::SettingsInput(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@@ -43,11 +45,11 @@ void SettingsInput::onCurrentMachineChanged(int machineId) {
|
||||
int selectedRow = 0;
|
||||
for (int i = 0; i < mouse_get_ndev(); ++i) {
|
||||
const auto* dev = mouse_get_device(i);
|
||||
if ((i == MOUSE_TYPE_INTERNAL) && !(machines[machineId].flags & MACHINE_MOUSE)) {
|
||||
if ((i == MOUSE_TYPE_INTERNAL) && (machine_has_flags(machineId, MACHINE_MOUSE) == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (device_is_valid(dev, machine->flags) == 0) {
|
||||
if (device_is_valid(dev, machineId) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -73,13 +75,7 @@ void SettingsInput::onCurrentMachineChanged(int machineId) {
|
||||
removeRows = joystickModel->rowCount();
|
||||
selectedRow = 0;
|
||||
while (joyName) {
|
||||
int row = joystickModel->rowCount();
|
||||
joystickModel->insertRow(row);
|
||||
auto idx = joystickModel->index(row, 0);
|
||||
|
||||
joystickModel->setData(idx, joyName, Qt::DisplayRole);
|
||||
joystickModel->setData(idx, i, Qt::UserRole);
|
||||
|
||||
int row = Models::AddEntry(joystickModel, joyName, i);
|
||||
if (i == joystick_type) {
|
||||
selectedRow = row - removeRows;
|
||||
}
|
||||
@@ -112,3 +108,80 @@ void SettingsInput::on_pushButtonConfigureMouse_clicked() {
|
||||
int mouseId = ui->comboBoxMouse->currentData().toInt();
|
||||
DeviceConfig::ConfigureDevice(mouse_get_device(mouseId));
|
||||
}
|
||||
|
||||
static int get_axis(JoystickConfiguration& jc, int axis, int joystick_nr) {
|
||||
int axis_sel = jc.selectedAxis(axis);
|
||||
int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes;
|
||||
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs;
|
||||
|
||||
if (axis_sel < nr_axes) {
|
||||
return axis_sel;
|
||||
}
|
||||
|
||||
axis_sel -= nr_axes;
|
||||
if (axis_sel < nr_povs * 2) {
|
||||
if (axis_sel & 1)
|
||||
return POV_Y | (axis_sel >> 1);
|
||||
else
|
||||
return POV_X | (axis_sel >> 1);
|
||||
}
|
||||
axis_sel -= nr_povs;
|
||||
|
||||
return SLIDER | (axis_sel >> 1);
|
||||
}
|
||||
|
||||
static int get_pov(JoystickConfiguration& jc, int pov, int joystick_nr) {
|
||||
int pov_sel = jc.selectedPov(pov);
|
||||
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr-1].nr_povs*2;
|
||||
|
||||
if (pov_sel < nr_povs)
|
||||
{
|
||||
if (pov_sel & 1)
|
||||
return POV_Y | (pov_sel >> 1);
|
||||
else
|
||||
return POV_X | (pov_sel >> 1);
|
||||
}
|
||||
|
||||
return pov_sel - nr_povs;
|
||||
}
|
||||
|
||||
static void updateJoystickConfig(int type, int joystick_nr, QWidget* parent) {
|
||||
JoystickConfiguration jc(type, joystick_nr, parent);
|
||||
switch (jc.exec()) {
|
||||
case QDialog::Rejected:
|
||||
return;
|
||||
case QDialog::Accepted:
|
||||
break;
|
||||
}
|
||||
|
||||
joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice();
|
||||
if (joystick_state[joystick_nr].plat_joystick_nr) {
|
||||
for (int c = 0; c < joystick_get_axis_count(type); c++) {
|
||||
joystick_state[joystick_nr].axis_mapping[c] = get_axis(jc, c, joystick_nr);
|
||||
}
|
||||
for (int c = 0; c < joystick_get_button_count(type); c++) {
|
||||
joystick_state[joystick_nr].button_mapping[c] = jc.selectedButton(c);
|
||||
}
|
||||
for (int c = 0; c < joystick_get_button_count(type); c++) {
|
||||
joystick_state[joystick_nr].pov_mapping[c][0] = get_pov(jc, c, joystick_nr);
|
||||
joystick_state[joystick_nr].pov_mapping[c][1] = get_pov(jc, c, joystick_nr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsInput::on_pushButtonJoystick1_clicked() {
|
||||
updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 0, this);
|
||||
}
|
||||
|
||||
void SettingsInput::on_pushButtonJoystick2_clicked() {
|
||||
updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 1, this);
|
||||
}
|
||||
|
||||
void SettingsInput::on_pushButtonJoystick3_clicked() {
|
||||
updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 2, this);
|
||||
}
|
||||
|
||||
void SettingsInput::on_pushButtonJoystick4_clicked() {
|
||||
updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 3, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ private slots:
|
||||
void on_pushButtonConfigureMouse_clicked();
|
||||
void on_comboBoxJoystick_currentIndexChanged(int index);
|
||||
void on_comboBoxMouse_currentIndexChanged(int index);
|
||||
void on_pushButtonJoystick1_clicked();
|
||||
void on_pushButtonJoystick2_clicked();
|
||||
void on_pushButtonJoystick3_clicked();
|
||||
void on_pushButtonJoystick4_clicked();
|
||||
|
||||
private:
|
||||
Ui::SettingsInput *ui;
|
||||
|
||||
@@ -24,87 +24,6 @@ extern "C" {
|
||||
#include "qt_deviceconfig.hpp"
|
||||
#include "qt_models_common.hpp"
|
||||
|
||||
/*
|
||||
class MachineModel : public QAbstractListModel {
|
||||
public:
|
||||
MachineModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
private:
|
||||
struct Entry {
|
||||
QString name;
|
||||
int id;
|
||||
};
|
||||
QList<Entry> entries;
|
||||
};
|
||||
|
||||
bool MachineModel::insertRows(int row, int count, const QModelIndex &parent) {
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
entries.insert(row, Entry{});
|
||||
}
|
||||
endInsertRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MachineModel::removeRows(int row, int count, const QModelIndex &parent) {
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
entries.removeAt(row);
|
||||
}
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant MachineModel::data(const QModelIndex &index, int role) const {
|
||||
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid));
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return entries.at(index.row()).name;
|
||||
case Qt::UserRole:
|
||||
return entries.at(index.row()).id;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
int MachineModel::rowCount(const QModelIndex &parent) const {
|
||||
(void) parent;
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
bool MachineModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||
Entry* entry = nullptr;
|
||||
if (index.row() < entries.size()) {
|
||||
entry = &entries[index.row()];
|
||||
} else if (index.row() == entries.size()) {
|
||||
entries.append(Entry{});
|
||||
entry = &entries.back();
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
if (entry != nullptr) {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
entry->name = value.toString();
|
||||
case Qt::UserRole:
|
||||
entry->id = value.toInt();
|
||||
default:
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
|
||||
SettingsMachine::SettingsMachine(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::SettingsMachine)
|
||||
@@ -138,8 +57,8 @@ SettingsMachine::SettingsMachine(QWidget *parent) :
|
||||
int selectedMachineType = 0;
|
||||
auto* machineTypesModel = ui->comboBoxMachineType->model();
|
||||
for (int i = 0; i < MACHINE_TYPE_MAX; ++i) {
|
||||
Models::AddEntry(machineTypesModel, machine_types[i].name, machine_types[i].id);
|
||||
if (machine_types[i].id == machines[machine].type) {
|
||||
Models::AddEntry(machineTypesModel, machine_getname_ex(i), machine_types[i].id);
|
||||
if (machine_types[i].id == machine_get_type(machine)) {
|
||||
selectedMachineType = i;
|
||||
}
|
||||
}
|
||||
@@ -156,11 +75,21 @@ void SettingsMachine::save() {
|
||||
cpu = ui->comboBoxSpeed->currentData().toInt();
|
||||
fpu_type = ui->comboBoxFPU->currentData().toInt();
|
||||
cpu_use_dynarec = ui->checkBoxDynamicRecompiler->isChecked() ? 1 : 0;
|
||||
if (machines[machine].ram_granularity < 1024) {
|
||||
mem_size = ui->spinBoxRAM->value();
|
||||
int64_t temp_mem_size;
|
||||
if (machine_get_ram_granularity(machine) < 1024) {
|
||||
temp_mem_size = ui->spinBoxRAM->value();
|
||||
} else {
|
||||
mem_size = ui->spinBoxRAM->value() * 1024;
|
||||
temp_mem_size = ui->spinBoxRAM->value() * 1024;
|
||||
}
|
||||
|
||||
temp_mem_size &= ~(machine_get_ram_granularity(machine) - 1);
|
||||
if (temp_mem_size < machine_get_min_ram(machine)) {
|
||||
temp_mem_size = machine_get_min_ram(machine);
|
||||
} else if (temp_mem_size > machine_get_max_ram(machine)) {
|
||||
temp_mem_size = machine_get_max_ram(machine);
|
||||
}
|
||||
mem_size = static_cast<uint32_t>(temp_mem_size);
|
||||
|
||||
if (ui->comboBoxWaitStates->isEnabled()) {
|
||||
cpu_waitstates = ui->comboBoxWaitStates->currentData().toInt();
|
||||
} else {
|
||||
@@ -182,7 +111,7 @@ void SettingsMachine::on_comboBoxMachineType_currentIndexChanged(int index) {
|
||||
|
||||
int selectedMachineRow = 0;
|
||||
for (int i = 0; i < machine_count(); ++i) {
|
||||
if ((machines[i].type == index) && machine_available(i)) {
|
||||
if ((machine_get_type(i) == index) && machine_available(i)) {
|
||||
int row = Models::AddEntry(model, machines[i].name, i);
|
||||
if (i == machine) {
|
||||
selectedMachineRow = row - removeRows;
|
||||
@@ -229,26 +158,25 @@ void SettingsMachine::on_comboBoxMachine_currentIndexChanged(int index) {
|
||||
|
||||
auto* machine = &machines[machineId];
|
||||
if ((machine->ram_granularity < 1024)) {
|
||||
ui->spinBoxRAM->setMinimum(machine->min_ram);
|
||||
ui->spinBoxRAM->setMaximum(machine->max_ram);
|
||||
ui->spinBoxRAM->setSingleStep(machine->ram_granularity);
|
||||
ui->spinBoxRAM->setMinimum(machine_get_min_ram(machineId));
|
||||
ui->spinBoxRAM->setMaximum(machine_get_max_ram(machineId));
|
||||
ui->spinBoxRAM->setSingleStep(machine_get_ram_granularity(machineId));
|
||||
ui->spinBoxRAM->setSuffix(" KiB");
|
||||
ui->spinBoxRAM->setValue(mem_size);
|
||||
} else {
|
||||
uint maxram;
|
||||
int maxram;
|
||||
#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64))
|
||||
maxram = std::min(machine->max_ram, 2097152U);
|
||||
maxram = std::min(machine->max_ram, 2097152);
|
||||
#else
|
||||
maxram = std::min(machine->max_ram, 3145728U);
|
||||
maxram = std::min(machine_get_max_ram(machineId), 3145728);
|
||||
#endif
|
||||
ui->spinBoxRAM->setMinimum(machine->min_ram / 1024);
|
||||
ui->spinBoxRAM->setMinimum(machine_get_min_ram(machineId) / 1024);
|
||||
ui->spinBoxRAM->setMaximum(maxram / 1024);
|
||||
ui->spinBoxRAM->setSingleStep(machine->ram_granularity / 1024);
|
||||
ui->spinBoxRAM->setSingleStep(machine_get_ram_granularity(machineId) / 1024);
|
||||
ui->spinBoxRAM->setSuffix(" MiB");
|
||||
ui->spinBoxRAM->setValue(mem_size / 1024);
|
||||
}
|
||||
ui->spinBoxRAM->setEnabled(machine->min_ram != machine->max_ram);
|
||||
ui->spinBoxRAM->setEnabled(machine->min_ram != machine->max_ram);
|
||||
ui->spinBoxRAM->setEnabled(machine_get_min_ram(machineId) != machine_get_max_ram(machineId));
|
||||
|
||||
emit currentMachineChanged(machineId);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ void SettingsNetwork::onCurrentMachineChanged(int machineId) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machine->flags)) {
|
||||
if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machineId)) {
|
||||
int row = Models::AddEntry(model, name, c);
|
||||
if (c == network_card) {
|
||||
selectedRow = row - removeRows;
|
||||
|
||||
@@ -40,7 +40,6 @@ void SettingsSound::save() {
|
||||
|
||||
void SettingsSound::onCurrentMachineChanged(int machineId) {
|
||||
this->machineId = machineId;
|
||||
auto* machine = &machines[machineId];
|
||||
|
||||
auto* model = ui->comboBoxSoundCard->model();
|
||||
auto removeRows = model->rowCount();
|
||||
@@ -48,7 +47,7 @@ void SettingsSound::onCurrentMachineChanged(int machineId) {
|
||||
int selectedRow = 0;
|
||||
while (true) {
|
||||
/* Skip "internal" if machine doesn't have it. */
|
||||
if ((c == 1) && !(machine->flags & MACHINE_SOUND)) {
|
||||
if ((c == 1) && (machine_has_flags(machineId, MACHINE_SOUND) == 0)) {
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
@@ -60,7 +59,7 @@ void SettingsSound::onCurrentMachineChanged(int machineId) {
|
||||
}
|
||||
|
||||
if (sound_card_available(c)) {
|
||||
if (device_is_valid(sound_dev, machine->flags)) {
|
||||
if (device_is_valid(sound_dev, machineId)) {
|
||||
int row = Models::AddEntry(model, name, c);
|
||||
if (c == sound_card_current) {
|
||||
selectedRow = row - removeRows;
|
||||
@@ -128,9 +127,14 @@ void SettingsSound::onCurrentMachineChanged(int machineId) {
|
||||
ui->checkBoxGUS->setChecked(GUS > 0);
|
||||
ui->checkBoxFloat32->setChecked(sound_is_float > 0);
|
||||
|
||||
ui->pushButtonConfigureSSI2001->setEnabled((SSI2001 > 0) && (machine->flags & MACHINE_BUS_ISA));
|
||||
ui->pushButtonConfigureCMS->setEnabled((GAMEBLASTER > 0) && (machine->flags & MACHINE_BUS_ISA));
|
||||
ui->pushButtonConfigureGUS->setEnabled((GUS > 0) && (machine->flags & MACHINE_BUS_ISA16));
|
||||
bool hasIsa = machine_has_bus(machineId, MACHINE_BUS_ISA) > 0;
|
||||
bool hasIsa16 = machine_has_bus(machineId, MACHINE_BUS_ISA) > 0;
|
||||
ui->checkBoxCMS->setEnabled(hasIsa);
|
||||
ui->pushButtonConfigureCMS->setEnabled((GAMEBLASTER > 0) && hasIsa);
|
||||
ui->checkBoxGUS->setEnabled(hasIsa16);
|
||||
ui->pushButtonConfigureGUS->setEnabled((GUS > 0) && hasIsa16);
|
||||
ui->checkBoxSSI2001->setEnabled(hasIsa);
|
||||
ui->pushButtonConfigureSSI2001->setEnabled((SSI2001 > 0) && hasIsa);
|
||||
}
|
||||
|
||||
static bool allowMpu401(Ui::SettingsSound *ui) {
|
||||
@@ -203,7 +207,7 @@ void SettingsSound::on_checkBoxGUS_stateChanged(int state) {
|
||||
}
|
||||
|
||||
void SettingsSound::on_pushButtonConfigureMPU401_clicked() {
|
||||
if (machines[machineId].flags & MACHINE_MCA) {
|
||||
if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) {
|
||||
DeviceConfig::ConfigureDevice(&mpu401_mca_device);
|
||||
} else {
|
||||
DeviceConfig::ConfigureDevice(&mpu401_device);
|
||||
|
||||
@@ -57,7 +57,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) {
|
||||
int selectedRow = 0;
|
||||
while (true) {
|
||||
/* Skip "internal" if machine doesn't have it. */
|
||||
if ((c == 1) && !(machine->flags & MACHINE_HDC)) {
|
||||
if ((c == 1) && (machine_has_flags(machineId, MACHINE_HDC) == 0)) {
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) {
|
||||
if (hdc_available(c)) {
|
||||
auto* hdc_dev = hdc_get_device(c);
|
||||
|
||||
if (device_is_valid(hdc_dev, machine->flags)) {
|
||||
if (device_is_valid(hdc_dev, machineId)) {
|
||||
int row = Models::AddEntry(model, name, c);
|
||||
if (c == hdc_current) {
|
||||
selectedRow = row - removeRows;
|
||||
@@ -98,7 +98,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) {
|
||||
if (fdc_card_available(c)) {
|
||||
auto* fdc_dev = fdc_card_getdevice(c);
|
||||
|
||||
if (device_is_valid(fdc_dev, machine->flags)) {
|
||||
if (device_is_valid(fdc_dev, machineId)) {
|
||||
int row = Models::AddEntry(model, name, c);
|
||||
if (c == fdc_type) {
|
||||
selectedRow = row - removeRows;
|
||||
@@ -127,7 +127,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) {
|
||||
|
||||
if (scsi_card_available(c)) {
|
||||
auto* scsi_dev = scsi_card_getdevice(c);
|
||||
if (device_is_valid(scsi_dev, machine->flags)) {
|
||||
if (device_is_valid(scsi_dev, machineId)) {
|
||||
int row = Models::AddEntry(model, name, c);
|
||||
if (c == scsi_card_current[i]) {
|
||||
selectedRow = row - removeRows;
|
||||
|
||||
@@ -28,7 +28,7 @@ wchar_t* ui_window_title(wchar_t* str)
|
||||
main_window->getTitle(title);
|
||||
str = title;
|
||||
} else {
|
||||
main_window->setTitle(str);
|
||||
emit main_window->setTitle(QString::fromWCharArray(str));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ void ui_sb_set_text_w(wchar_t *wstr) {
|
||||
|
||||
void
|
||||
ui_sb_update_tip(int arg) {
|
||||
qDebug() << Q_FUNC_INFO << arg;
|
||||
main_window->updateStatusBarTip(arg);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
161
src/qt/sdl_joystick.cpp
Normal file
161
src/qt/sdl_joystick.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
// Lifted from wx-sdl2-joystick.c in PCem
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
extern "C" {
|
||||
#include <86box/device.h>
|
||||
#include <86box/gameport.h>
|
||||
|
||||
int joysticks_present;
|
||||
joystick_t joystick_state[MAX_JOYSTICKS];
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS];
|
||||
}
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
void joystick_init() {
|
||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) {
|
||||
return;
|
||||
}
|
||||
joysticks_present = SDL_NumJoysticks();
|
||||
|
||||
memset(sdl_joy, 0, sizeof(sdl_joy));
|
||||
for (int c = 0; c < joysticks_present; c++)
|
||||
{
|
||||
sdl_joy[c] = SDL_JoystickOpen(c);
|
||||
|
||||
if (sdl_joy[c])
|
||||
{
|
||||
int d;
|
||||
|
||||
strncpy(plat_joystick_state[c].name, SDL_JoystickNameForIndex(c), 64);
|
||||
plat_joystick_state[c].nr_axes = SDL_JoystickNumAxes(sdl_joy[c]);
|
||||
plat_joystick_state[c].nr_buttons = SDL_JoystickNumButtons(sdl_joy[c]);
|
||||
plat_joystick_state[c].nr_povs = SDL_JoystickNumHats(sdl_joy[c]);
|
||||
|
||||
for (d = 0; d < std::min(plat_joystick_state[c].nr_axes, 8); d++)
|
||||
{
|
||||
sprintf(plat_joystick_state[c].axis[d].name, "Axis %i", d);
|
||||
plat_joystick_state[c].axis[d].id = d;
|
||||
}
|
||||
for (d = 0; d < std::min(plat_joystick_state[c].nr_buttons, 8); d++)
|
||||
{
|
||||
sprintf(plat_joystick_state[c].button[d].name, "Button %i", d);
|
||||
plat_joystick_state[c].button[d].id = d;
|
||||
}
|
||||
for (d = 0; d < std::min(plat_joystick_state[c].nr_povs, 4); d++)
|
||||
{
|
||||
sprintf(plat_joystick_state[c].pov[d].name, "POV %i", d);
|
||||
plat_joystick_state[c].pov[d].id = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void joystick_close()
|
||||
{
|
||||
int c;
|
||||
|
||||
for (c = 0; c < joysticks_present; c++)
|
||||
{
|
||||
if (sdl_joy[c])
|
||||
SDL_JoystickClose(sdl_joy[c]);
|
||||
}
|
||||
}
|
||||
|
||||
static int joystick_get_axis(int joystick_nr, int mapping)
|
||||
{
|
||||
if (mapping & POV_X)
|
||||
{
|
||||
switch (plat_joystick_state[joystick_nr].p[mapping & 3])
|
||||
{
|
||||
case SDL_HAT_LEFTUP: case SDL_HAT_LEFT: case SDL_HAT_LEFTDOWN:
|
||||
return -32767;
|
||||
|
||||
case SDL_HAT_RIGHTUP: case SDL_HAT_RIGHT: case SDL_HAT_RIGHTDOWN:
|
||||
return 32767;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (mapping & POV_Y)
|
||||
{
|
||||
switch (plat_joystick_state[joystick_nr].p[mapping & 3])
|
||||
{
|
||||
case SDL_HAT_LEFTUP: case SDL_HAT_UP: case SDL_HAT_RIGHTUP:
|
||||
return -32767;
|
||||
|
||||
case SDL_HAT_LEFTDOWN: case SDL_HAT_DOWN: case SDL_HAT_RIGHTDOWN:
|
||||
return 32767;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return plat_joystick_state[joystick_nr].a[plat_joystick_state[joystick_nr].axis[mapping].id];
|
||||
}
|
||||
void joystick_process()
|
||||
{
|
||||
int c, d;
|
||||
|
||||
SDL_JoystickUpdate();
|
||||
for (c = 0; c < joysticks_present; c++)
|
||||
{
|
||||
int b;
|
||||
|
||||
plat_joystick_state[c].a[0] = SDL_JoystickGetAxis(sdl_joy[c], 0);
|
||||
plat_joystick_state[c].a[1] = SDL_JoystickGetAxis(sdl_joy[c], 1);
|
||||
plat_joystick_state[c].a[2] = SDL_JoystickGetAxis(sdl_joy[c], 2);
|
||||
plat_joystick_state[c].a[3] = SDL_JoystickGetAxis(sdl_joy[c], 3);
|
||||
plat_joystick_state[c].a[4] = SDL_JoystickGetAxis(sdl_joy[c], 4);
|
||||
plat_joystick_state[c].a[5] = SDL_JoystickGetAxis(sdl_joy[c], 5);
|
||||
|
||||
for (b = 0; b < 16; b++)
|
||||
plat_joystick_state[c].b[b] = SDL_JoystickGetButton(sdl_joy[c], b);
|
||||
|
||||
for (b = 0; b < 4; b++)
|
||||
plat_joystick_state[c].p[b] = SDL_JoystickGetHat(sdl_joy[c], b);
|
||||
// pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", c, joystick_state[c].x, joystick_state[c].y, joystick_state[c].b[0], joystick_state[c].b[1], joysticks_present);
|
||||
}
|
||||
|
||||
for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++)
|
||||
{
|
||||
if (joystick_state[c].plat_joystick_nr)
|
||||
{
|
||||
int joystick_nr = joystick_state[c].plat_joystick_nr - 1;
|
||||
|
||||
for (d = 0; d < joystick_get_axis_count(joystick_type); d++)
|
||||
joystick_state[c].axis[d] = joystick_get_axis(joystick_nr, joystick_state[c].axis_mapping[d]);
|
||||
for (d = 0; d < joystick_get_button_count(joystick_type); d++)
|
||||
joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]];
|
||||
for (d = 0; d < joystick_get_pov_count(joystick_type); d++)
|
||||
{
|
||||
int x, y;
|
||||
double angle, magnitude;
|
||||
|
||||
x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]);
|
||||
y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]);
|
||||
|
||||
angle = (atan2((double)y, (double)x) * 360.0) / (2*M_PI);
|
||||
magnitude = sqrt((double)x*(double)x + (double)y*(double)y);
|
||||
|
||||
if (magnitude < 16384)
|
||||
joystick_state[c].pov[d] = -1;
|
||||
else
|
||||
joystick_state[c].pov[d] = ((int)angle + 90 + 360) % 360;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (d = 0; d < joystick_get_axis_count(joystick_type); d++)
|
||||
joystick_state[c].axis[d] = 0;
|
||||
for (d = 0; d < joystick_get_button_count(joystick_type); d++)
|
||||
joystick_state[c].button[d] = 0;
|
||||
for (d = 0; d < joystick_get_pov_count(joystick_type); d++)
|
||||
joystick_state[c].pov[d] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user