generated from StudioCherno/WalnutAppTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add layer for managing angle presets
- Loading branch information
wilszdev
committed
May 26, 2022
1 parent
6d2400a
commit 8cccfb4
Showing
7 changed files
with
128 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "PresetsLayer.h" | ||
#include "../Win32Helpers.h" | ||
|
||
static void SavePresets() | ||
{ | ||
HANDLE file = CreateFileA("presets.dat", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); | ||
if (file && file != INVALID_HANDLE_VALUE) | ||
{ | ||
DWORD size = sizeof(*g_anglePresets) * NUM_PRESETS; | ||
DWORD written = 0; | ||
if (!WriteFile(file, g_anglePresets, size, &written, 0)) | ||
Win32Log("[SavePresets] WriteFile() failed with error %d: %s", | ||
GetLastError(), Win32GetErrorCodeDescription(GetLastError()).c_str()); | ||
CloseHandle(file); | ||
} | ||
else | ||
Win32Log("[LoadPresets] CreateFileA() failed with error %d: %s", | ||
GetLastError(), Win32GetErrorCodeDescription(GetLastError()).c_str()); | ||
} | ||
|
||
static void LoadPresets() | ||
{ | ||
HANDLE file = CreateFileA("presets.dat", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); | ||
if (file && file != INVALID_HANDLE_VALUE) | ||
{ | ||
DWORD size = sizeof(*g_anglePresets) * NUM_PRESETS; | ||
DWORD read = 0; | ||
if (!ReadFile(file, g_anglePresets, size, &read, 0)) | ||
Win32Log("[LoadPresets] ReadFile failed with error %d: %s", | ||
GetLastError(), Win32GetErrorCodeDescription(GetLastError()).c_str()); | ||
CloseHandle(file); | ||
} | ||
else | ||
Win32Log("[LoadPresets] CreateFileA() failed with error %d: %s", | ||
GetLastError(), Win32GetErrorCodeDescription(GetLastError()).c_str()); | ||
} | ||
|
||
void PresetsLayer::OnUIRender() | ||
{ | ||
ImGui::Begin("Presets"); | ||
|
||
for (int i = 0; i < NUM_PRESETS; ++i) | ||
{ | ||
char buf[16] = {}; | ||
sprintf(buf, "Preset %d", i + 1); | ||
|
||
char buf2[18] = "##"; | ||
strcat_s(buf2, buf); | ||
|
||
ImGui::Text(buf); ImGui::SameLine(); | ||
ImGui::InputInt2(buf2, g_anglePresets[i].angles); | ||
} | ||
|
||
if (ImGui::Button("Save these presets")) | ||
{ | ||
SavePresets(); | ||
} | ||
|
||
ImGui::End(); | ||
} | ||
|
||
void PresetsLayer::OnAttach() | ||
{ | ||
LoadPresets(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include "Walnut/Application.h" | ||
#include "../WalnutApp.h" | ||
|
||
class PresetsLayer : public Walnut::Layer | ||
{ | ||
public: | ||
virtual void OnUIRender() override; | ||
virtual void OnAttach() override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters