ImGuiTest/src/menus/test_menu2.cpp
kelson8 5e6d5f0cfc Add a random number generator in test_menu2.
Add minimum and maximum for random number generator.
Add open current directory button to test_menu2.
Add some new functions for directories in imgui_functions.
Comment more code in imgui_functions, clean it up a bit.
Add some new items into imgui_defines.h
Add float to string, address to string, generate random number to misc_util.
Add template to convert all values that work with it to a string.
2025-03-31 16:11:48 -04:00

124 lines
2.9 KiB
C++

#include "pch.h"
#include "imgui.h"
#ifdef _WIN32
#include <Windows.h>
#include "directx9_test.h"
#include "keystates.h"
#endif
#include "text_functions.h"
#include "test_menu2.h"
#include "imgui_defines.h"
// New for random numbers and other util
#include "misc_util.h"
// Functions for clamping the inputs for values and other stuff
#include "imgui_functions.h"
void TestMenu2::TestMenu()
{
// Init the random number to 0 by default
static int randomNumber = 0;
// Set defualt min and max values
static int testMin = 0;
static int min = 0;
static int max = 1000;
MiscUtil miscUtil = MiscUtil();
const int vsprintBufferSize = 1024;
char* vsPrintBuffer = new char[vsprintBufferSize];
if (ImGui::CollapsingHeader("test2"))
{
// Disabled, doesn't work.
#ifdef _TEST1
if (ImGui::Button("Test"))
{
char format[] = "Hello %s";
std::cout << "Hello" << std::endl;
call_vsprintf_s(vsPrintBuffer, 15, format);
}
#endif //_TEST1
//ImGui::SliderInt("Min/Max", &testMin, min, max);
// From ReVC
//ImGui::Text("Minimum number: 23, Maximum number: 59");
// TODO Come up with a better solution for this.
//ImGuiFunctions::Input::InputIntMax("Minimum", &min, 1, 10, 23);
//ImGuiFunctions::Input::InputIntClamp("Maximum", &max, 1, 10, 0, 59);
IMGUITEXT("Random Number Generator");
IMGUI_INPUT_INT("Minimum", &min);
IMGUI_INPUT_INT("Maximum", &max);
// This works outputting to a message box, I switched to using ImGui text.
if (IMGUIBUTTON("Generate random number"))
{
// Some random value
//int value = miscUtil.GenerateRandomNumber(1, 1000);
//randomNumber = miscUtil.GenerateRandomNumber(1, 1000);
randomNumber = miscUtil.GenerateRandomNumber(min, max);
//#ifdef _WIN32
// // Convert the integer to a string
// std::stringstream ss;
// //ss << "Random number: " << value;
// ss << "Random number: " << randomNumber;
// std::string strValue = ss.str();
// std::wstring wStrValue(strValue.begin(), strValue.end());
//
// // Switch to using MessageBoxW
// MessageBoxW(NULL, wStrValue.c_str(),
// L"KCNet-ImGuiTest", MB_OK);
//
//
// //MessageBox(NULL, TEXT("Hello From ImGui, a MessageBox"),
// //MessageBox(NULL, TEXT("Random number: " + value),
// // TEXT("KCNet-ImGuiTest"), MB_OK);
//#endif
}
std::string randomNumberText = "Random number: " + MiscUtil::toString(randomNumber);
IMGUITEXT(randomNumberText.c_str());
// End random number generator
IMGUI_SEPERATOR();
IMGUITEXT("Folder utils");
ImGuiFunctions::Folders::OpenCurrentDirectoryButton("Open current directory");
IMGUI_SEPERATOR();
// End directory testing
//if (IMGUIBUTTON("Open Current Directory"))
//{
//
//}
}
// End test2 header
// Disabled, these are just for testing.
// This works for a column, having multiple items on the same row.
//ImGui::Columns(2);
//ImGui::Text("Hello");
//ImGui::NextColumn();
//ImGui::Text("World");
//ImGui::Columns(1);
//}
}