Skip to content

Commit

Permalink
presets: bug fix. anon struct should be inside union. add clamping.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilszdev committed May 26, 2022
1 parent 8cccfb4 commit fe45b21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion UFV Controller/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Collapsed=0
DockId=0x00000010,0

[Docking][Data]
DockSpace ID=0xF2944C7F Window=0x4647B76E Pos=138,187 Size=1600,874 Split=Y
DockSpace ID=0xF2944C7F Window=0x4647B76E Pos=64,108 Size=1600,874 Split=Y
DockNode ID=0x0000000A Parent=0xF2944C7F SizeRef=1920,704 Split=X
DockNode ID=0x00000003 Parent=0x0000000A SizeRef=1088,874 Split=X
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=505,874 Split=X Selected=0xB10717DB
Expand Down
Binary file modified UFV Controller/presets.dat
Binary file not shown.
16 changes: 16 additions & 0 deletions UFV Controller/src/Layers/PresetsLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#include "PresetsLayer.h"
#include "../Win32Helpers.h"

static void ClampPresets()
{
for (int i = 0; i < NUM_PRESETS; ++i)
{
angle_preset* preset = g_anglePresets + i;
if (preset->pan < -80) preset->pan = -80;
if (preset->pan > 80) preset->pan = 80;
if (preset->tilt < -5) preset->tilt = -5;
if (preset->tilt > 80) preset->tilt = 80;
}
}

static void SavePresets()
{
HANDLE file = CreateFileA("presets.dat", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
Expand Down Expand Up @@ -33,6 +45,8 @@ static void LoadPresets()
else
Win32Log("[LoadPresets] CreateFileA() failed with error %d: %s",
GetLastError(), Win32GetErrorCodeDescription(GetLastError()).c_str());

ClampPresets();
}

void PresetsLayer::OnUIRender()
Expand All @@ -51,6 +65,8 @@ void PresetsLayer::OnUIRender()
ImGui::InputInt2(buf2, g_anglePresets[i].angles);
}

ClampPresets();

if (ImGui::Button("Save these presets"))
{
SavePresets();
Expand Down
10 changes: 5 additions & 5 deletions UFV Controller/src/WalnutApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ extern ufv_state g_ufvState;
#define NUM_PRESETS 6
struct angle_preset
{
struct
{
int pan;
int tilt;
};
union
{
int angles[2];
struct
{
int pan;
int tilt;
};
};
};

Expand Down

0 comments on commit fe45b21

Please sign in to comment.