Skip to content

Commit

Permalink
Merge branch 'fmuecke#3-Kapselung-des-Gamepads' into 'main'
Browse files Browse the repository at this point in the history
3-Kapselung-des-Gamepads

See merge request r_bernhard/Ipponboard!4
  • Loading branch information
r-bernhard committed Feb 3, 2024
2 parents fb25211 + 28e3222 commit 1bd32c7
Show file tree
Hide file tree
Showing 17 changed files with 737 additions and 664 deletions.
40 changes: 25 additions & 15 deletions _build/win/qt4/_cmake_qt4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ cmake_minimum_required(VERSION 3.13)
project(Ipponboard VERSION 2.0.0 LANGUAGES C CXX)
message(STATUS "using: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")

find_package(Qt4 4.8.7 REQUIRED QtCore QtGui QtXmlPatterns)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_PREFIX_PATH "$ENV{QTDIR}")
set (BOOST_DIR C:/dev/inst/boost_1_82_0)
set (XMLQUERY $ENV{QTDIR}/include/QtXmlPatterns)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

#####################################################
# compile Ipponboard
#####################################################
set (BASE_DIR ../../../..)
set( SOURCES
${BASE_DIR}/core/Controller.cpp ${BASE_DIR}/core/Controller.h
Expand Down Expand Up @@ -68,45 +64,59 @@ ${BASE_DIR}/base/view_vertical_single.ui
${BASE_DIR}/base/qrc_ipponboard.cpp
)

set(BOOST_DIR C:/dev/inst/boost_1_82_0)
include_directories(base ${BOOST_DIR} ${XMLQUERY} )

#####################################################
# Target Ipponboard: create a binary
#####################################################
add_executable(Ipponboard ${SOURCES} ${BASE_DIR}/base/Ipponboard.rc)
set_target_properties(Ipponboard PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${BASE_DIR}/bin"
if (WIN32)
LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup"
else()
LINK_FLAGS_RELEASE "-mwindows"
# oder das? --> SUBSYSTEM_LINKER_OPTIONS "-mwindows"
endif()
)
target_link_libraries(Ipponboard Qt4::QtCore Qt4::QtGui Qt4::QtXmlPatterns)

#####################################################
# Target Ipponboard_Debug: create a debug binary
#####################################################
add_executable(Ipponboard_Debug ${SOURCES} ${BASE_DIR}/base/Ipponboard.rc)
set_target_properties(Ipponboard_Debug PROPERTIES
OUTPUT_NAME Ipponboard_Debug
DEBUG_POSTFIX _d
RUNTIME_OUTPUT_DIRECTORY "${BASE_DIR}/bin"
COMPILE_FLAGS -D_WITH_GAMEPAD_
)
target_link_libraries(Ipponboard_Debug Qt4::QtCore Qt4::QtGui Qt4::QtXmlPatterns)

if(WIN32)
set(CMAKE_SUPPRESS_REGENERATION true)
set (CMAKE_SUPPRESS_REGENERATION true)
set (CMAKE_PREFIX_PATH "$ENV{QTDIR}")
set (XMLQUERY $ENV{QTDIR}/include/QtXmlPatterns)

# Target Ipponboard
add_custom_command(TARGET Ipponboard POST_BUILD
COMMAND call "${BASE_DIR}/base/_copy_files.cmd" -release
)
message(STATUS "Using QTDIR=$ENV{QTDIR}")
find_package(Qt4 4.8.7 REQUIRED QtCore QtGui QtXmlPatterns)

# Target Ipponboard_Debug
#####################################################
# custom commands
#####################################################
add_custom_command(TARGET Ipponboard_Debug POST_BUILD
COMMAND call "../_env_cfg-x64.cmd"
# the following environment variable is needed, if using VStudio GUI (solution)
COMMAND set QTDIR="c:\\dev\\inst\\qt\\qt-4.8.7-x64-msvc2017"
COMMAND call "${BASE_DIR}/base/_copy_files.cmd" -debug
)

add_custom_command(TARGET Ipponboard POST_BUILD
COMMAND call "${BASE_DIR}/base/_copy_files.cmd" -release
)

#####################################################
# Target setup
#####################################################
add_custom_target(setup
COMMAND call "../_build_doc.cmd" ${BASE_DIR}
COMMAND cmd /c "%INNO_DIR%/iscc.exe" /Q /O${BASE_DIR}/bin ${BASE_DIR}/setup/setup.iss
Expand All @@ -117,4 +127,4 @@ endif ()

# compile Testsuites
add_subdirectory(${BASE_DIR}/test/cmake_qt4 ${BASE_DIR}/test/_build_cmake_qt4)
add_subdirectory(${BASE_DIR}/GamepadDemo/cmake_qt4 ${BASE_DIR}/GamepadDemo/_build_cmake_qt4)
#add_subdirectory(${BASE_DIR}/GamepadDemo/cmake_qt4 ${BASE_DIR}/GamepadDemo/_build_cmake_qt4)
7 changes: 6 additions & 1 deletion _build/win/qt4/_create_env_cfg.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ if EXIST "%LOCAL_CONFIG%" (
call "%LOCAL_CONFIG%"
echo;
) else (
echo create file=%LOCAL_CONFIG%
echo @echo off>"%LOCAL_CONFIG%"
echo set QTDIR=C:\dev\inst\qt\qt-4.8.7-%ARCH%-msvc2017>>"%LOCAL_CONFIG%"
echo set PATH=%%PATH%%;%%QTDIR%%\bin;C:\dev\inst\jom_1_1_3>>"%LOCAL_CONFIG%"
echo set QMAKESPEC=%%QTDIR%%\mkspecs\win32-msvc2017>>"%LOCAL_CONFIG%"
echo set BOOST_DIR=C:\dev\inst\boost_1_82_0>>"%LOCAL_CONFIG%"
echo set INNO_DIR=C:\dev\inst\InnoSetup6>>"%LOCAL_CONFIG%"
CALL "%LOCAL_CONFIG%"
echo set REDIST_DIR_x86=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.38.33135\x86\Microsoft.VC143.CRT>>"%LOCAL_CONFIG%"
echo set REDIST_DIR_x64=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.38.33135\x64\Microsoft.VC143.CRT>>"%LOCAL_CONFIG%"
echo set REDIST_DIR_x86d=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.38.33135\debug_nonredist\x86\Microsoft.VC143.DebugCRT>>"%LOCAL_CONFIG%"
echo set REDIST_DIR_x64d=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.38.33135\debug_nonredist\x64\Microsoft.VC143.DebugCRT>>"%LOCAL_CONFIG%"
CALL "%LOCAL_CONFIG%"
)
2 changes: 1 addition & 1 deletion _build/win/qt4/_create_versioninfo.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
::@echo off
@echo off
setlocal

if [%1] == [] (
Expand Down
5 changes: 4 additions & 1 deletion _build/win/qt4/build_qmake_qt4-x86.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if not exist "%QTDIR%\bin\qmake.exe" (
setlocal

set BASE_DIR=%~dp0..\..\..
call _create_versioninfo.cmd %BASE_DIR%\base
call _create_versioninfo.cmd %BASE_DIR%\base || exit /b %errorlevel%

if "%2"=="debug" (set BIN_DIR=%BASE_DIR%\bin\Debug) else (set BIN_DIR=%BASE_DIR%\bin\Release)

Expand Down Expand Up @@ -133,9 +133,12 @@ exit /b 0
rd /Q /S "%BIN_DIR%" >nul 2>&1
if exist "%BASE_DIR%\base\versioninfo.h" del "%BASE_DIR%\base\versioninfo.h" >nul || exit /b %errorlevel%

call :make_makefiles
call :clean test || exit /b %errorlevel%
call :clean base || exit /b %errorlevel%
call :clean GamepadDemo || exit /b %errorlevel%

call %~dp0_create_versioninfo.cmd %BASE_DIR%\base || exit /b %errorlevel%
exit /b 0

::-------------------------------
Expand Down
2 changes: 1 addition & 1 deletion base/FightCategoryManagerDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void FightCategoryManagerDlg::on_pushButton_add_pressed()
void FightCategoryManagerDlg::load_values()
//---------------------------------------------------------
{
for (int i(0); i < m_pClassMgr->CategoryCount(); ++i)
for (int i(0); i < (int)m_pClassMgr->CategoryCount(); ++i)
{
Ipponboard::FightCategory classItem;
m_pClassMgr->GetCategory(i, classItem);
Expand Down
8 changes: 6 additions & 2 deletions base/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include "../core/ControllerConfig.h"
#include "../core/Fighter.h"
#include "../core/TournamentModel.h"
#ifdef _WITH_GAMEPAD_
#include "../gamepad/gamepad.h"
#endif
#include "../util/path_helpers.h"
#include "../Widgets/ScaledImage.h"
#include "../Widgets/ScaledText.h"
Expand All @@ -40,7 +42,9 @@ namespace StrTags
static const char* const edition = "Basic Edition";
}

#ifdef _WITH_GAMEPAD_
using namespace FMlib;
#endif
using namespace Ipponboard;

MainWindow::MainWindow(QWidget* parent)
Expand All @@ -62,7 +66,7 @@ void MainWindow::Init()
MainWindowBase::Init();

// init tournament classes (if there are none present)
for (int i(0); i < m_pCategoryManager->CategoryCount(); ++i)
for (int i(0); i < (int)m_pCategoryManager->CategoryCount(); ++i)
{
FightCategory t("");
m_pCategoryManager->GetCategory(i, t);
Expand All @@ -86,7 +90,7 @@ void MainWindow::on_actionManageClasses_triggered()

m_pUi->comboBox_weight_class->clear();

for (int i(0); i < m_pCategoryManager->CategoryCount(); ++i)
for (int i(0); i < (int)m_pCategoryManager->CategoryCount(); ++i)
{
FightCategory t("");
m_pCategoryManager->GetCategory(i, t);
Expand Down
17 changes: 16 additions & 1 deletion base/MainWindowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "../core/Enums.h"
#include "../base/versioninfo.h"
#include "../base/SettingsDlg.h"
#ifdef _WITH_GAMEPAD_
#include "../gamepad/gamepad.h"
#endif
#include "../core/Rules.h"
#include "../util/path_helpers.h"

Expand All @@ -27,7 +29,9 @@
#include <QTimer>
#include <QStyle>

#ifdef _WITH_GAMEPAD_
using namespace FMlib;
#endif
using namespace Ipponboard;
using Point = Score::Point;

Expand All @@ -44,7 +48,9 @@ MainWindowBase::MainWindowBase(QWidget* parent)
, m_secondScreenNo(0)
, m_secondScreenSize()
, m_controllerCfg()
#ifdef _WITH_GAMEPAD_
, m_pGamepad(new Gamepad)
#endif
{
}

Expand Down Expand Up @@ -83,10 +89,12 @@ void MainWindowBase::Init()

change_lang(true);

#ifdef _WITH_GAMEPAD_
// Init gamepad
QTimer* m_pTimer = new QTimer;
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(EvaluateInput()));
m_pTimer->start(75);
#endif

update_statebar();

Expand Down Expand Up @@ -598,6 +606,7 @@ void MainWindowBase::read_settings()
}
settings.endGroup();

#ifdef _WITH_GAMEPAD_
settings.beginGroup(str_tag_Input);
{
m_controllerCfg.button_hajime_mate =
Expand Down Expand Up @@ -647,6 +656,7 @@ void MainWindowBase::read_settings()
m_pGamepad->SetInverted(FMlib::Gamepad::eAxis_Z, m_controllerCfg.axis_inverted_Z);
}
settings.endGroup();
#endif

settings.beginGroup(str_tag_Sounds);
{
Expand Down Expand Up @@ -736,7 +746,9 @@ void MainWindowBase::on_actionPreferences_triggered()
dlg.SetTextColorsFirst(m_pPrimaryView->GetTextColorFirst(), m_pPrimaryView->GetTextBgColorFirst());
dlg.SetTextColorsSecond(m_pPrimaryView->GetTextColorSecond(), m_pPrimaryView->GetTextBgColorSecond());
dlg.SetScreensSettings(m_secondScreenNo, m_secondScreenSize);
#ifdef _WITH_GAMEPAD_
dlg.SetControllerConfig(&m_controllerCfg);
#endif
dlg.SetLabels(m_MatLabel, m_pController->GetHomeLabel(), m_pController->GetGuestLabel());
dlg.SetGongFile(m_pController->GetGongFile());

Expand All @@ -752,13 +764,14 @@ void MainWindowBase::on_actionPreferences_triggered()
m_secondScreenNo = dlg.GetSelectedScreen();
m_secondScreenSize = dlg.GetSize();

#ifdef _WITH_GAMEPAD_
dlg.GetControllerConfig(&m_controllerCfg);
// apply settings to gamepad
m_pGamepad->SetInverted(FMlib::Gamepad::eAxis_X, m_controllerCfg.axis_inverted_X);
m_pGamepad->SetInverted(FMlib::Gamepad::eAxis_Y, m_controllerCfg.axis_inverted_Y);
m_pGamepad->SetInverted(FMlib::Gamepad::eAxis_R, m_controllerCfg.axis_inverted_R);
m_pGamepad->SetInverted(FMlib::Gamepad::eAxis_Z, m_controllerCfg.axis_inverted_Z);

#endif
m_MatLabel = dlg.GetMatLabel();
m_pController->SetLabels(dlg.GetHomeLabel(), dlg.GetGuestLabel());

Expand Down Expand Up @@ -814,6 +827,7 @@ void MainWindowBase::show_hide_view() const
isAlreadyCalled = false;
}

#ifdef _WITH_GAMEPAD_
void MainWindowBase::EvaluateInput()
{
if (Gamepad::eState_ok != m_pGamepad->GetState())
Expand Down Expand Up @@ -973,6 +987,7 @@ void MainWindowBase::EvaluateInput()
}
}
}
#endif

void MainWindowBase::update_info_text_color(const QColor& color, const QColor& bgColor)
{
Expand Down
8 changes: 8 additions & 0 deletions base/MainWindowBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class ScoreScreen;
}
class QSettings;

#ifdef _WITH_GAMEPAD_
namespace FMlib
{
class Gamepad;
}
typedef std::shared_ptr<FMlib::Gamepad> PGamepad;
#endif

static const char* const str_golden_score = "Golden Score";
static const char* const str_normal_round_time = "Normal";
Expand Down Expand Up @@ -147,7 +149,9 @@ protected slots:
//void on_actionReset_Scores_triggered();
void on_actionPreferences_triggered();
void on_button_reset_clicked();
#ifdef _WITH_GAMEPAD_
void EvaluateInput();
#endif
void on_actionLang_English_triggered(bool);
void on_actionLang_Deutsch_triggered(bool);
void on_actionLang_Dutch_triggered(bool);
Expand All @@ -165,7 +169,9 @@ protected slots:


protected:
#ifdef _WITH_GAMEPAD_
virtual bool EvaluateSpecificInput(FMlib::Gamepad const* /*pGamepad*/) { return false; }
#endif

std::shared_ptr<Ipponboard::View> m_pPrimaryView;
std::shared_ptr<Ipponboard::View> m_pSecondaryView;
Expand All @@ -180,7 +186,9 @@ protected slots:
Ipponboard::ControllerConfig m_controllerCfg;

private:
#ifdef _WITH_GAMEPAD_
PGamepad m_pGamepad;
#endif
};

#endif // BASE__MAINWINDOW_BASE_H_
8 changes: 7 additions & 1 deletion base/MainWindowTeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "../core/ControllerConfig.h"
#include "../core/Tournament.h"
#include "../core/TournamentModel.h"
#ifdef _WITH_GAMEPAD_
#include "../gamepad/gamepad.h"
#endif
#include "../util/path_helpers.h"
#include "../Widgets/ScaledImage.h"
#include "../Widgets/ScaledText.h"
Expand Down Expand Up @@ -54,7 +56,9 @@ static const char* const mode = "Mode";
static const char* const host = "Host";
}

#ifdef _WITH_GAMEPAD_
using namespace FMlib;
#endif
using namespace Ipponboard;

namespace { bool initialized = false; }
Expand Down Expand Up @@ -378,7 +382,7 @@ void MainWindowTeam::update_club_views()
m_pUi->comboBox_club_home->clear();
m_pUi->comboBox_club_guest->clear();

for (int i = 0; i < m_pClubManager->ClubCount(); ++i)
for (int i = 0; i < (int)m_pClubManager->ClubCount(); ++i)
{
Ipponboard::Club club;
m_pClubManager->GetClub(i, club);
Expand Down Expand Up @@ -670,6 +674,7 @@ void MainWindowTeam::on_actionReset_Scores_triggered()
UpdateButtonText_();
}

#ifdef _WITH_GAMEPAD_
bool MainWindowTeam::EvaluateSpecificInput(const Gamepad* pGamepad)
{
// back
Expand All @@ -691,6 +696,7 @@ bool MainWindowTeam::EvaluateSpecificInput(const Gamepad* pGamepad)

return false;
}
#endif

void MainWindowTeam::on_tabWidget_currentChanged(int /*index*/)
{
Expand Down
2 changes: 2 additions & 0 deletions base/MainWindowTeam.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private slots:
//void on_comboBox_weight_class_currentIndexChanged(const QString&);

void on_actionReset_Scores_triggered();
#ifdef _WITH_GAMEPAD_
virtual bool EvaluateSpecificInput(FMlib::Gamepad const* pGamepad) override;
#endif

private:
void update_weights(QString const& weightString);
Expand Down
Loading

0 comments on commit 1bd32c7

Please sign in to comment.