Skip to content

Commit 75f4a5b

Browse files
authored
Merge pull request #4 from broken-bytes/dev
UI updates
2 parents 7e7be63 + b9bb2ff commit 75f4a5b

File tree

13 files changed

+228
-64
lines changed

13 files changed

+228
-64
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(SRC
3131
src/MainWindow.cxx
3232
src/ColorPicker.cxx
3333
DualSense4Windows.exe.manifest
34+
DeclareDPIAware.manifest
3435
)
3536

3637
set(ASSETS "$<TARGET_FILE_DIR:${APP}>/assets")

DeclareDPIAware.manifest

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
2+
<asmv3:application>
3+
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
4+
<dpiAware>true</dpiAware>
5+
</asmv3:windowsSettings>
6+
</asmv3:application>
7+
</assembly>

include/App.hxx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace BrokenBytes::DualSense4Windows::UI {
1919
constexpr uint32_t WINDOW_HEIGHT = 600;
2020

2121
class App {
22-
2322
public:
2423
/// <summary>
2524
/// Called when the app starts
@@ -28,37 +27,49 @@ namespace BrokenBytes::DualSense4Windows::UI {
2827
/// <summary>
2928
/// Called when the app receives a device change event
3029
/// </summary>
31-
sigslot::signal<> DeviceChange;
30+
sigslot::signal<> DevicesChanged;
3231

32+
/// <summary>
33+
/// Called when the app triggers a color picker change
34+
/// </summary>
3335
sigslot::signal<uint8_t, Color> ColorChanged;
3436

3537
/// <summary>
3638
/// Creates an app instance
3739
/// </summary>
38-
/// <param name="instance">The Win32 App instance</param>
39-
App(HINSTANCE instance);
40+
App();
4041
~App();
4142

4243
/// <summary>
4344
/// The currently window that is active
4445
/// </summary>
4546
/// <returns>The window handle</returns>
4647
std::shared_ptr<UI::Window> Window() const;
47-
48+
49+
/// <summary>
50+
/// Runs the app loop
51+
/// </summary>
4852
void Run();
53+
54+
/// <summary>
55+
/// Called on Update
56+
/// </summary>
4957
void OnUpdate();
58+
59+
/// <summary>
60+
/// Called on close of the App
61+
/// </summary>
5062
void OnClose();
5163

5264
// Slots
5365
/// <summary>
5466
/// Called when the number of DualSense devices connected changes
5567
/// </summary>
5668
/// <param name="devices"></param>
57-
void DualSenseDevicesChanged(std::map<char*, DualSense*> devices);
69+
void DualSenseDevicesChanged(std::vector<char*> devices);
5870

5971

6072
private:
61-
HINSTANCE _win32Instance;
6273
std::shared_ptr<UI::Window> _mainWindow;
6374
std::shared_ptr<UI::Window> _window;
6475

include/DualSense.hxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace BrokenBytes::DualSense4Windows {
1313
/// <summary>
1414
/// The rate at which to send reports to the DS
1515
/// </summary>
16-
constexpr uint8_t DS_SENDRATE = 50;
16+
constexpr uint8_t DS_SENDRATE = 20;
1717
/// <summary>
1818
/// The Default mode at which DualSense operates
1919
/// </summary>
@@ -111,6 +111,11 @@ namespace BrokenBytes::DualSense4Windows {
111111
/// <param name="controllerNumber">The number of the controller</param>
112112
DualSense(char* path, uint8_t controllerNumber);
113113

114+
/// <summary>
115+
/// Destroys this instance and frees resources
116+
/// </summary>
117+
~DualSense();
118+
114119
/// <summary>
115120
/// Returns the mode of the controller
116121
/// </summary>

include/Interface.hxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
#include "Core.hxx"
44
#include <map>
5-
#include <memory>
5+
#include <vector>
66
#include <ViGEm/Client.h>
77
#include <sigslot/signal.hpp>
88

99
#include "Types.hxx"
1010

1111
namespace BrokenBytes::DualSense4Windows {
12+
struct DS_LIGHTBARCOLOR;
13+
1214
namespace UI {
1315
struct Color;
1416
}
@@ -28,7 +30,7 @@ namespace BrokenBytes::DualSense4Windows {
2830
/// <summary>
2931
/// The signal used for device change notifications
3032
/// </summary>
31-
sigslot::signal < std::map<char*, DualSense*>> DevicesChanged;
33+
sigslot::signal < std::vector<char*>> DevicesChanged;
3234

3335

3436
/// <summary>
@@ -45,7 +47,7 @@ namespace BrokenBytes::DualSense4Windows {
4547
/// Gets all DualSense devices connected
4648
/// </summary>
4749
/// <returns>A map of devices, by HID path and instance </returns>
48-
std::map<char*, DualSense*> GetDualSenses();
50+
std::vector<char*> GetDualSenses();
4951
/// <summary>
5052
/// Updates the list of connected DualSenses
5153
/// </summary>
@@ -71,7 +73,7 @@ namespace BrokenBytes::DualSense4Windows {
7173
/// <param name="target">The target to be bound to</param>
7274
void BindVirtualDevice(DualSense* device, PVIGEM_TARGET target);
7375

74-
void SetColor(uint8_t ID, UI::Color c);
76+
void SetColor(uint8_t ID, DS_LIGHTBARCOLOR c);
7577

7678
// Slots
7779

include/MainWindow.hxx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
#pragma once
22

3+
#include <map>
4+
#include <vector>
35
#include <sigslot/signal.hpp>
46

57
#include "ColorPicker.hxx"
8+
#include "DualSense.hxx"
69
#include "Window.hxx"
710

811
namespace BrokenBytes::DualSense4Windows::UI {
12+
13+
enum class Dimensions : uint16_t {
14+
VSpacer = 1,
15+
HSpacer = 1,
16+
NameWidth = 30,
17+
ConnectionWidth = 10,
18+
ColorSize = 15,
19+
HideWidth = 10,
20+
BaseHeight = 5
21+
};
22+
923
class MainWindow : public Window {
1024
public:
11-
25+
sigslot::signal<> DevicesChanged;
1226
sigslot::signal<uint8_t, Color> ColorChanged;
1327

1428
/// <summary>
@@ -21,7 +35,29 @@ namespace BrokenBytes::DualSense4Windows::UI {
2135
void Show() override;
2236
void Hide() override;
2337

38+
/// <summary>
39+
/// Changes the device list of this window
40+
/// </summary>
41+
/// <param name="devices">The devices</param>
42+
void DualSenseDevicesChanged(std::vector<char*> devices);
2443

44+
protected:
2545
LRESULT CALLBACK ProcessEvent(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
46+
47+
private:
48+
std::vector<char*> _devices;
49+
std::map<char*, std::array<void*, 4>> _controls;
50+
51+
/// <summary>
52+
/// Adds the controls for a given DualSense
53+
/// </summary>
54+
/// <param name="id">The path of the DualSense</param>
55+
void AddControls(char* id);
56+
57+
/// <summary>
58+
/// Removes the controls for a given DualSense
59+
/// </summary>
60+
/// <param name="id">The path of the DualSense</param>
61+
void RemoveControls(char* id);
2662
};
2763
}

include/Window.hxx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <Uxtheme.h>
99

1010
#include "Core.hxx"
11+
#include "Math.hxx"
1112

1213
namespace BrokenBytes::DualSense4Windows::UI {
1314
constexpr LPCWSTR WINDOW_DEFAULT = L"WINDOW_DEFAULT";
@@ -17,10 +18,12 @@ namespace BrokenBytes::DualSense4Windows::UI {
1718
Window(
1819
LPCWSTR title,
1920
uint16_t width,
20-
uint16_t height
21+
uint16_t height,
22+
UINT extraStyles = 0
2123
) {
2224
_handle = nullptr;
2325
_isRegistered = false;
26+
_dimensions = { width, height };
2427
WNDCLASSW wnd = { };
2528
wnd.hInstance = GetModuleHandle(nullptr);
2629
wnd.lpszClassName = WINDOW_DEFAULT;
@@ -31,7 +34,7 @@ namespace BrokenBytes::DualSense4Windows::UI {
3134
_handle = CreateWindow(
3235
WINDOW_DEFAULT,
3336
title,
34-
WS_OVERLAPPEDWINDOW,
37+
WS_OVERLAPPEDWINDOW | extraStyles,
3538
0,
3639
0,
3740
width,
@@ -75,6 +78,22 @@ namespace BrokenBytes::DualSense4Windows::UI {
7578
ShowWindow(_handle, SW_HIDE);
7679
}
7780

81+
/// <summary>
82+
/// The width of the Window
83+
/// </summary>
84+
/// <returns>The width</returns>
85+
[[nodiscard]] uint16_t Width() const {
86+
return _dimensions.x;
87+
}
88+
89+
/// <summary>
90+
/// The height of the window
91+
/// </summary>
92+
/// <returns>The height</returns>
93+
[[nodiscard]] uint16_t Height() const {
94+
return _dimensions.y;
95+
}
96+
7897
/// <summary>
7998
/// Toggles if this window can be resized
8099
/// </summary>
@@ -148,5 +167,6 @@ namespace BrokenBytes::DualSense4Windows::UI {
148167
HWND _handle;
149168
WNDCLASS* _class;
150169
bool _isRegistered;
170+
Math::Vector2<uint16_t> _dimensions;
151171
};
152172
}

src/App.cxx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313

1414
namespace BrokenBytes::DualSense4Windows::UI {
15-
App::App(HINSTANCE instance) {
16-
_win32Instance = instance;
15+
App::App() {
1716
RegisterWindows();
1817
}
1918

@@ -31,19 +30,25 @@ namespace BrokenBytes::DualSense4Windows::UI {
3130
void App::Run() {
3231
_mainWindow = std::make_shared<MainWindow>(L"DualSense4Windows", 1024, 512);
3332

34-
reinterpret_cast<MainWindow*>(_mainWindow.get())->ColorChanged.connect([this](
33+
auto m = reinterpret_cast<MainWindow*>(_mainWindow.get());
34+
m->ColorChanged.connect([this](
3535
uint8_t id, Color c) {
3636
this->ColorChanged(id, c);
3737
});
38+
39+
m->DevicesChanged.connect([this] {
40+
DevicesChanged();
41+
});
42+
3843
_mainWindow->Show();
3944
AppStarted();
4045
}
4146

4247
void App::OnUpdate() {}
4348
void App::OnClose() {}
4449

45-
void App::DualSenseDevicesChanged(std::map<char*, DualSense*> devices) {
46-
50+
void App::DualSenseDevicesChanged(std::vector<char*> devices) {
51+
reinterpret_cast<MainWindow*>(_mainWindow.get())->DualSenseDevicesChanged(devices);
4752
}
4853
}
4954

src/ColorPicker.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
namespace BrokenBytes::DualSense4Windows::UI {
77
constexpr uint16_t WIDTH = 512;
8-
constexpr uint16_t HEIGHT = 242;
8+
constexpr uint16_t HEIGHT = 250;
99

1010
constexpr uint8_t BTN_OK = 0;
1111
constexpr uint8_t BTN_CANCEL = 1;
1212

1313
constexpr long COLOR_RANGE = MAKELONG(0, 255);
14-
ColorPicker::ColorPicker(Color initColor) : Window(TEXT("Color Picker"), WIDTH, HEIGHT) {
14+
ColorPicker::ColorPicker(Color initColor):
15+
Window(TEXT("Color Picker"), WIDTH, HEIGHT) {
1516
_color = initColor;
1617
_oldColor = initColor;
1718
_rH = CreateWindowEx(

src/ControllerKit.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace BrokenBytes::DualSense4Windows {
2323
}
2424

2525
void InitUI() {
26-
APP = std::make_unique<UI::App>(*INSTANCE);
26+
APP = std::make_unique<UI::App>();
2727
}
2828

2929
void InitInterface() {
@@ -34,16 +34,16 @@ namespace BrokenBytes::DualSense4Windows {
3434
APP->AppStarted.connect([] {
3535
INTERFACE->Init();
3636
});
37-
APP->DeviceChange.connect([] {
37+
APP->DevicesChanged.connect([] {
3838
INTERFACE->UpdateDualSenseDevices();
3939
});
4040
INTERFACE->DevicesChanged.connect([](
41-
std::map<char*, DualSense*> devices
41+
std::vector<char*> devices
4242
) {
4343
APP->DualSenseDevicesChanged(devices);
4444
});
4545
APP->ColorChanged.connect([](uint8_t id, UI::Color c) {
46-
INTERFACE->SetColor(id, c);
46+
INTERFACE->SetColor(id, DS_LIGHTBARCOLOR{c.R, c.G, c.B});
4747
});
4848
}
4949

0 commit comments

Comments
 (0)