templates
This commit is contained in:
@@ -17,13 +17,11 @@ int main()
|
||||
{
|
||||
ApplicationData applicationData{};
|
||||
|
||||
startImgui(&applicationData, init, draw, "Asuro's Tool", 600, 400);
|
||||
startImgui<ApplicationData>(applicationData, init, draw, "Asuro's Tool", 600, 400);
|
||||
}
|
||||
|
||||
void init(DrawData& drawData, void* customData)
|
||||
void init(DrawData& drawData, ApplicationData& appData)
|
||||
{
|
||||
ApplicationData* appData = static_cast<ApplicationData*>(customData);
|
||||
|
||||
// Load text font
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontFromFileTTF("Montserrat-Regular.ttf", 18.0f);
|
||||
@@ -40,14 +38,14 @@ void init(DrawData& drawData, void* customData)
|
||||
audioResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
isError(audioResult, "Failed to initialize COM: ");
|
||||
|
||||
audioResult = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&appData->audioData->deviceEnumerator));
|
||||
audioResult = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&appData.audioData->deviceEnumerator));
|
||||
isError(audioResult, "Failed to set up audio device enumerator: ");
|
||||
|
||||
appData->audioData->audioNotificationListener = new AudioNotificationListener(appData->audioData);
|
||||
audioResult = appData->audioData->deviceEnumerator->RegisterEndpointNotificationCallback(appData->audioData->audioNotificationListener);
|
||||
appData.audioData->audioNotificationListener = new AudioNotificationListener(appData.audioData);
|
||||
audioResult = appData.audioData->deviceEnumerator->RegisterEndpointNotificationCallback(appData.audioData->audioNotificationListener);
|
||||
isError(audioResult, "Failed to register audio notification listener: ");
|
||||
|
||||
reloadDeviceLists(*appData->audioData);
|
||||
reloadDeviceLists(*appData.audioData);
|
||||
|
||||
// Set window icon
|
||||
LPWSTR iconId = MAKEINTRESOURCE(IDI_ICON1);
|
||||
@@ -58,9 +56,8 @@ void init(DrawData& drawData, void* customData)
|
||||
SendMessage(drawData.window_handle, WM_SETICON, ICON_SMALL2, (LPARAM)iconSmall);
|
||||
}
|
||||
|
||||
void draw(DrawData& drawData, void* customData)
|
||||
void draw(DrawData& drawData, ApplicationData& appData)
|
||||
{
|
||||
ApplicationData* appData = static_cast<ApplicationData*>(customData);
|
||||
float customYCursor = 0;
|
||||
ImVec2 viewportSize = ImGui::GetMainViewport()->Size;
|
||||
|
||||
@@ -70,23 +67,23 @@ void draw(DrawData& drawData, void* customData)
|
||||
// Playback Devices
|
||||
ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
|
||||
ImGui::SetNextWindowSize(ImVec2(viewportSize.x, 0));
|
||||
customYCursor += audioDeviceWindow(appData, appData->audioData->playbackDevices, " \xEE\xB8\x84 Playback").y;
|
||||
customYCursor += audioDeviceWindow(appData, appData.audioData->playbackDevices, " \xEE\xB8\x84 Playback").y;
|
||||
|
||||
customYCursor += 5.;
|
||||
|
||||
// Recording devices
|
||||
ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
|
||||
ImGui::SetNextWindowSize(ImVec2(viewportSize.x, 0));
|
||||
customYCursor += audioDeviceWindow(appData, appData->audioData->recordingDevices, " \xEE\xBD\x8F Recording").y;
|
||||
customYCursor += audioDeviceWindow(appData, appData.audioData->recordingDevices, " \xEE\xBD\x8F Recording").y;
|
||||
|
||||
// Resize viewport
|
||||
if (appData->settings.fitWindowHeight)
|
||||
if (appData.settings.fitWindowHeight)
|
||||
{
|
||||
drawData.window_size.y = customYCursor;
|
||||
}
|
||||
}
|
||||
|
||||
ImVec2 menuBar(ApplicationData* appData)
|
||||
ImVec2 menuBar(ApplicationData& appData)
|
||||
{
|
||||
ImVec2 size{};
|
||||
|
||||
@@ -94,8 +91,8 @@ ImVec2 menuBar(ApplicationData* appData)
|
||||
{
|
||||
if (ImGui::BeginMenu("Settings"))
|
||||
{
|
||||
ImGui::Checkbox("Show Disabled Devices", &appData->settings.showDisabledDevices);
|
||||
ImGui::Checkbox("Fit Window Height", &appData->settings.fitWindowHeight);
|
||||
ImGui::Checkbox("Show Disabled Devices", &appData.settings.showDisabledDevices);
|
||||
ImGui::Checkbox("Fit Window Height", &appData.settings.fitWindowHeight);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@@ -103,7 +100,7 @@ ImVec2 menuBar(ApplicationData* appData)
|
||||
{
|
||||
if (ImGui::Button("Manual Refresh"))
|
||||
{
|
||||
reloadDeviceLists(*appData->audioData);
|
||||
reloadDeviceLists(*appData.audioData);
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
@@ -134,7 +131,7 @@ bool customButton(const char* id_start, const char* id_end, const char* title, b
|
||||
return result;
|
||||
}
|
||||
|
||||
ImVec2 audioDeviceWindow(ApplicationData* appData, std::vector<AudioDevice>& deviceList, const char* title)
|
||||
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title)
|
||||
{
|
||||
if (ImGui::Begin(title, 0, ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
@@ -153,7 +150,7 @@ ImVec2 audioDeviceWindow(ApplicationData* appData, std::vector<AudioDevice>& dev
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1., 1., 1., 1.));
|
||||
}
|
||||
else if (!appData->settings.showDisabledDevices)
|
||||
else if (!appData.settings.showDisabledDevices)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -196,7 +193,7 @@ ImVec2 audioDeviceWindow(ApplicationData* appData, std::vector<AudioDevice>& dev
|
||||
}
|
||||
if (customButton("bn_d_", deviceIdUtf8.c_str(), "\xEE\xBE\x82", !dev.isDefaultConsole))
|
||||
{
|
||||
setDefaultAudioDevice(*appData->audioData, dev.id.c_str(), ERole::eConsole);
|
||||
setDefaultAudioDevice(*appData.audioData, dev.id.c_str(), ERole::eConsole);
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
@@ -206,7 +203,7 @@ ImVec2 audioDeviceWindow(ApplicationData* appData, std::vector<AudioDevice>& dev
|
||||
}
|
||||
if (customButton("bn_c_", deviceIdUtf8.c_str(), "\xEE\xBF\xA9", !dev.isDefaultCommunication))
|
||||
{
|
||||
setDefaultAudioDevice(*appData->audioData, dev.id.c_str(), ERole::eCommunications);
|
||||
setDefaultAudioDevice(*appData.audioData, dev.id.c_str(), ERole::eCommunications);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "ImguiBase.h"
|
||||
#include "ApplicationData.h"
|
||||
|
||||
void init(DrawData& drawData, void* customData);
|
||||
void draw(DrawData& drawData, void* customData);
|
||||
ImVec2 menuBar(ApplicationData* appData);
|
||||
ImVec2 audioDeviceWindow(ApplicationData* appData, std::vector<AudioDevice>& deviceList, const char* title);
|
||||
void init(DrawData& drawData, ApplicationData& customData);
|
||||
void draw(DrawData& drawData, ApplicationData& customData);
|
||||
ImVec2 menuBar(ApplicationData& appData);
|
||||
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
||||
void drawCircle(float radius, ImU32 color);
|
||||
|
||||
Reference in New Issue
Block a user