Merge pull request #701 from Zer0xFF/qt_osx

OSX: Qt UI
This commit is contained in:
Jean-Philip Desjardins 2018-07-29 12:50:21 -04:00 committed by GitHub
commit 80423c1bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 158 additions and 24 deletions

View File

@ -26,25 +26,27 @@ set(PROJECT_LIBS)
include(PrecompiledHeader)
if(BUILD_PLAY)
if(TARGET_PLATFORM_UNIX)
if(TARGET_PLATFORM_UNIX OR USE_QT)
add_subdirectory(Source/ui_unix/)
endif(TARGET_PLATFORM_UNIX)
endif(TARGET_PLATFORM_UNIX OR USE_QT)
if(TARGET_PLATFORM_MACOS)
add_subdirectory(Source/ui_macosx/)
endif(TARGET_PLATFORM_MACOS)
if(NOT USE_QT)
if(TARGET_PLATFORM_MACOS)
add_subdirectory(Source/ui_macosx/)
endif(TARGET_PLATFORM_MACOS)
if(TARGET_PLATFORM_IOS)
add_subdirectory(Source/ui_ios/)
endif(TARGET_PLATFORM_IOS)
if(TARGET_PLATFORM_IOS)
add_subdirectory(Source/ui_ios/)
endif(TARGET_PLATFORM_IOS)
if(TARGET_PLATFORM_ANDROID)
add_subdirectory(Source/ui_android/)
endif(TARGET_PLATFORM_ANDROID)
if(TARGET_PLATFORM_ANDROID)
add_subdirectory(Source/ui_android/)
endif(TARGET_PLATFORM_ANDROID)
if(TARGET_PLATFORM_WIN32)
add_subdirectory(Source/ui_win32)
endif(TARGET_PLATFORM_WIN32)
if(TARGET_PLATFORM_WIN32)
add_subdirectory(Source/ui_win32)
endif(TARGET_PLATFORM_WIN32)
endif()
endif(BUILD_PLAY)
if(BUILD_TESTS)

BIN
Source/ui_unix/AppIcon.icns Executable file

Binary file not shown.

View File

@ -26,8 +26,19 @@ if(NOT TARGET gsh_opengl)
endif()
list(INSERT PROJECT_LIBS 0 gsh_opengl)
find_package(LIBEVDEV REQUIRED)
list(APPEND PROJECT_LIBS ${LIBEVDEV_LIBRARY})
if (NOT TARGET glew_s)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../../../Dependencies/glew-2.0.0
${CMAKE_CURRENT_BINARY_DIR}/glew-2.0.0
)
endif()
list(APPEND PROJECT_LIBS glew_s)
if(TARGET_PLATFORM_UNIX)
find_package(LIBEVDEV REQUIRED)
list(APPEND PROJECT_LIBS ${LIBEVDEV_LIBRARY})
list(APPEND DEFINITIONS_LIST HAS_LIBEVDEV=1)
endif()
set(QT_SOURCES
main.cpp
@ -48,10 +59,14 @@ set(QT_SOURCES
bindingmodel.cpp
inputeventselectiondialog.cpp
GamePad/GamePadUtils.cpp
GamePad/GamePadInputEventListener.cpp
GamePad/GamePadDeviceListener.cpp
)
if(LIBEVDEV_FOUND)
set(QT_SOURCES
${QT_SOURCES}
GamePad/GamePadInputEventListener.cpp
GamePad/GamePadDeviceListener.cpp
)
endif()
set(QT_MOC_HEADERS
mainwindow.h
ElidedLabel.h
@ -71,9 +86,14 @@ set(QT_MOC_HEADERS
bindingmodel.h
inputeventselectiondialog.h
GamePad/GamePadUtils.h
GamePad/GamePadInputEventListener.h
GamePad/GamePadDeviceListener.h
)
if(LIBEVDEV_FOUND)
set(QT_SOURCES
${QT_SOURCES}
GamePad/GamePadInputEventListener.h
GamePad/GamePadDeviceListener.h
)
endif()
set(QT_UIS
Qt_ui/mainwindow.ui
@ -97,8 +117,37 @@ QT5_ADD_RESOURCES(QT_RES_SOURCES ${QT_RESOURCES})
QT5_WRAP_UI(QT_UI_HEADERS ${QT_UIS})
QT5_WRAP_CPP(QT_MOC_SRCS ${QT_MOC_HEADERS})
add_executable(Play ${QT_SOURCES} ${QT_MOC_SRCS} ${QT_RES_SOURCES} ${QT_UI_HEADERS})
if(TARGET_PLATFORM_MACOS)
set(OSX_RES
${CMAKE_CURRENT_SOURCE_DIR}/AppIcon.icns
${CMAKE_CURRENT_SOURCE_DIR}/../../patches.xml
)
add_executable(Play MACOSX_BUNDLE ${QT_SOURCES} ${QT_MOC_SRCS} ${QT_RES_SOURCES} ${QT_UI_HEADERS} ${OSX_RES})
# Set a custom plist file for the app bundle
# NOTE: for these values to be used Info.plist has to be edited
# NOTE: from cmake 3.7.0 you can use %b for month name abbreviations
string(TIMESTAMP DATE "%d-%m-%Y")
set_target_properties(
Play
PROPERTIES
MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME}"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.virtualapplications.Play"
MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} Version ${PROJECT_Version}"
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_Version}"
MACOSX_BUNDLE_BUNDLE_VERSION ${DATE}
MACOSX_BUNDLE_COPYRIGHT "© Virtual Applications, 2017"
MACOSX_BUNDLE_ICON_FILE "AppIcon.icns"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
RESOURCE "${OSX_RES}"
)
else()
add_executable(Play ${QT_SOURCES} ${QT_MOC_SRCS} ${QT_RES_SOURCES} ${QT_UI_HEADERS})
endif()
target_link_libraries(Play ${PROJECT_LIBS})
target_compile_definitions(Play PRIVATE ${DEFINITIONS_LIST})
target_include_directories(Play PRIVATE
./
../../

View File

@ -27,9 +27,11 @@ void CGSH_OpenGLQt::InitializeImpl()
succeeded = m_context->makeCurrent(m_renderWindow);
Q_ASSERT(succeeded);
#ifndef __APPLE__
glewExperimental = GL_TRUE;
auto result = glewInit();
Q_ASSERT(result == GLEW_OK);
#endif
CGSH_OpenGL::InitializeImpl();
}

View File

@ -1,6 +1,9 @@
#include "GamePadUtils.h"
#include <cstring>
#include <string>
#include <cstdio>
#ifdef HAS_LIBEVDEV
std::array<uint32, 6> CGamePadUtils::GetDeviceID(libevdev* dev)
{
std::array<uint32, 6> device{0};
@ -30,6 +33,7 @@ std::array<uint32, 6> CGamePadUtils::GetDeviceID(libevdev* dev)
}
return device;
}
#endif
bool CGamePadUtils::ParseMAC(std::array<uint32, 6>& out, std::string const& in)
{

View File

@ -1,12 +1,16 @@
#pragma once
#ifdef HAS_LIBEVDEV
#include <libevdev.h>
#endif
#include <array>
#include "Types.h"
class CGamePadUtils
{
public:
#ifdef HAS_LIBEVDEV
static std::array<uint32, 6> GetDeviceID(libevdev* dev);
#endif
static bool ParseMAC(std::array<uint32, 6>&, std::string const&);
};

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>Play</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Play!</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -1,6 +1,8 @@
#include <QKeySequence>
#include <cstring>
#ifdef HAS_LIBEVDEV
#include <libevdev.h>
#endif
#include "InputBindingManager.h"
#include "GamePad/GamePadUtils.h"
#include "string_format.h"
@ -271,6 +273,7 @@ std::string CInputBindingManager::CSimpleBinding::GetDescription() const
{
return QString("Key: %1").arg(QKeySequence(m_keyCode).toString()).toStdString();
}
#ifdef HAS_LIBEVDEV
else
{
const char* buttonname = libevdev_event_code_get_name(m_type, m_keyCode);
@ -283,6 +286,7 @@ std::string CInputBindingManager::CSimpleBinding::GetDescription() const
return QString("Key: %1").arg(QString::number(m_keyCode)).toStdString();
}
}
#endif
}
void CInputBindingManager::CSimpleBinding::SetValue(uint32 state)
@ -385,6 +389,7 @@ std::string CInputBindingManager::CSimulatedAxisBinding::GetDescription() const
{
desc += QKeySequence(m_key1Binding.id).toString().toStdString();
}
#ifdef HAS_LIBEVDEV
else
{
const char* buttonname = libevdev_event_code_get_name(m_key1Binding.type, m_key1Binding.id);
@ -397,11 +402,13 @@ std::string CInputBindingManager::CSimulatedAxisBinding::GetDescription() const
desc += string_format("%d", m_key1Binding.id);
}
}
#endif
desc += "/ Key: ";
if(m_key2Binding.type == 0)
{
desc += QKeySequence(m_key2Binding.id).toString().toStdString();
}
#ifdef HAS_LIBEVDEV
else
{
const char* buttonname = libevdev_event_code_get_name(m_key2Binding.type, m_key2Binding.id);
@ -414,6 +421,7 @@ std::string CInputBindingManager::CSimulatedAxisBinding::GetDescription() const
desc += string_format("%d", m_key2Binding.id);
}
}
#endif
return desc;
}
@ -541,6 +549,7 @@ std::string CInputBindingManager::CPovHatBinding::GetDescription() const
{
return key + QKeySequence(m_binding.id).toString().toStdString();
}
#ifdef HAS_LIBEVDEV
else
{
const char* buttonname = libevdev_event_code_get_name(m_binding.type, m_binding.id);
@ -553,6 +562,7 @@ std::string CInputBindingManager::CPovHatBinding::GetDescription() const
return key + string_format("%d", m_binding.id);
}
}
#endif
}
uint32 CInputBindingManager::CPovHatBinding::GetValue() const

View File

@ -2,6 +2,7 @@
#include "Config.h"
#include "ControllerInfo.h"
#include <array>
#include <memory>
#include <functional>
#include <qnamespace.h>

View File

@ -14,7 +14,9 @@
ControllerConfigDialog::ControllerConfigDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::ControllerConfigDialog)
#ifdef HAS_LIBEVDEV
, m_inputDeviceManager(std::make_unique<CGamePadDeviceListener>(true))
#endif
{
ui->setupUi(this);
}
@ -85,9 +87,13 @@ int ControllerConfigDialog::OpenBindConfigDialog(int index)
std::transform(button.begin(), button.end(), button.begin(), ::toupper);
InputEventSelectionDialog IESD;
#ifdef HAS_LIBEVDEV
IESD.Setup(button.c_str(), m_inputManager,
static_cast<PS2::CControllerInfo::BUTTON>(index), m_inputDeviceManager);
#endif
auto res = IESD.exec();
#ifdef HAS_LIBEVDEV
m_inputDeviceManager.get()->DisconnectInputEventCallback();
#endif
return res;
}

View File

@ -4,7 +4,9 @@
#include <QAbstractButton>
#include <QXmlStreamReader>
#ifdef HAS_LIBEVDEV
#include "GamePad/GamePadDeviceListener.h"
#endif
#include "InputBindingManager.h"
namespace Ui
@ -30,6 +32,8 @@ private slots:
private:
int OpenBindConfigDialog(int index);
CInputBindingManager* m_inputManager;
#ifdef HAS_LIBEVDEV
std::unique_ptr<CGamePadDeviceListener> m_inputDeviceManager;
#endif
Ui::ControllerConfigDialog* ui;
};

View File

@ -25,6 +25,7 @@ InputEventSelectionDialog::~InputEventSelectionDialog()
delete ui;
}
#ifdef HAS_LIBEVDEV
void InputEventSelectionDialog::Setup(const char* text, CInputBindingManager* inputManager,
PS2::CControllerInfo::BUTTON button, std::unique_ptr<CGamePadDeviceListener> const& GPDL)
{
@ -101,6 +102,8 @@ void InputEventSelectionDialog::Setup(const char* text, CInputBindingManager* in
GPDL.get()->UpdateOnInputEventCallback(onInput);
}
#endif
void InputEventSelectionDialog::keyPressEvent(QKeyEvent* ev)
{
if(ev->key() == Qt::Key_Escape)

View File

@ -6,8 +6,10 @@
#include <thread>
#include "ui_unix/PH_HidUnix.h"
#ifdef HAS_LIBEVDEV
#include "GamePad/GamePadInputEventListener.h"
#include "GamePad/GamePadDeviceListener.h"
#endif
namespace Ui
{
@ -22,7 +24,9 @@ public:
explicit InputEventSelectionDialog(QWidget* parent = 0);
~InputEventSelectionDialog();
#ifdef HAS_LIBEVDEV
void Setup(const char* text, CInputBindingManager* inputManager, PS2::CControllerInfo::BUTTON button, const std::unique_ptr<CGamePadDeviceListener>& GPDL);
#endif
protected:
void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE;

View File

@ -62,7 +62,9 @@ MainWindow::MainWindow(QWidget* parent)
MainWindow::~MainWindow()
{
CAppConfig::GetInstance().Save();
#ifdef HAS_LIBEVDEV
m_GPDL.reset();
#endif
if(g_virtualMachine != nullptr)
{
g_virtualMachine->Pause();
@ -94,6 +96,7 @@ void MainWindow::InitEmu()
m_InputBindingManager = new CInputBindingManager(CAppConfig::GetInstance());
g_virtualMachine->CreatePadHandler(CPH_HidUnix::GetFactoryFunction(m_InputBindingManager));
#ifdef HAS_LIBEVDEV
auto onInput = [=](std::array<uint32, 6> device, int code, int value, int type, const input_absinfo* abs) -> void {
if(m_InputBindingManager != nullptr)
{
@ -101,6 +104,7 @@ void MainWindow::InitEmu()
}
};
m_GPDL = std::make_unique<CGamePadDeviceListener>(onInput);
#endif
StatsManager = new CStatsManager();
g_virtualMachine->m_ee->m_gs->OnNewFrame.connect(std::bind(&CStatsManager::OnNewFrame, StatsManager, std::placeholders::_1));
@ -136,10 +140,11 @@ void MainWindow::openGLWindow_resized()
{
GLint w = m_openglpanel->size().width(), h = m_openglpanel->size().height();
auto scale = devicePixelRatioF();
CGSHandler::PRESENTATION_PARAMS presentationParams;
presentationParams.mode = (CGSHandler::PRESENTATION_MODE)CAppConfig::GetInstance().GetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE);
presentationParams.windowWidth = w;
presentationParams.windowHeight = h;
presentationParams.windowWidth = w * scale;
presentationParams.windowHeight = h * scale;
g_virtualMachine->m_ee->m_gs->SetPresentationParams(presentationParams);
g_virtualMachine->m_ee->m_gs->Flip();
}

View File

@ -14,8 +14,10 @@
#include "PH_HidUnix.h"
#include "ElidedLabel.h"
#ifdef HAS_LIBEVDEV
#include "GamePad/GamePadInputEventListener.h"
#include "GamePad/GamePadDeviceListener.h"
#endif
namespace Ui
{
@ -62,7 +64,9 @@ private:
CPS2VM* g_virtualMachine = nullptr;
bool m_deactivatePause = false;
bool m_pauseFocusLost = true;
#ifdef HAS_LIBEVDEV
std::unique_ptr<CGamePadDeviceListener> m_GPDL;
#endif
enum BootType
{
CD,