129 lines
No EOL
4 KiB
C++
129 lines
No EOL
4 KiB
C++
#include "BigSortComponent.hpp"
|
|
#include <raylibs/raygui.h>
|
|
#include "raylibs/raygui.h"
|
|
|
|
BigSortComponent::BigSortComponent() : m_Sorter(2000)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
int BigSortComponent::draw()
|
|
{
|
|
// raygui: controls drawing
|
|
//----------------------------------------------------------------------------------
|
|
if (m_FunctionDropdown_EditMode)
|
|
GuiLock();
|
|
|
|
GuiGroupBox({ anchor01.x + 0, anchor01.y + 8, 456, 304 }, "Run Sorting");
|
|
{
|
|
if (GuiTextBox({ anchor02.x + 8, anchor02.y + 8, 216, 24 }, m_FunctionTextBox_Text, 128, m_FunctionTextBox_EditMode)) m_FunctionTextBox_EditMode = !m_FunctionTextBox_EditMode;
|
|
|
|
|
|
GuiGroupBox({ anchor02.x + 0, anchor02.y + 0, 232, 72 }, "Add & Check Function");
|
|
{
|
|
if (GuiButton({ anchor02.x + 72, anchor02.y + 40, 72, 24 }, "Check"))
|
|
{
|
|
// FATAL: asserts
|
|
sol::optional<sol::protected_function> func = m_LuaState[m_FunctionTextBox_Text];
|
|
if (!func)
|
|
{
|
|
m_ErrorWindow.error("Function does not exits", "A function was selected, that does not exist.");
|
|
// TODO: formating works differently
|
|
spdlog::error("BigSortComponent: Function does not exist %s", m_FunctionTextBox_Text);
|
|
repack_function_list();
|
|
}
|
|
}
|
|
|
|
if (GuiButton({ anchor02.x + 152, anchor02.y + 40, 72, 24 }, "Add"))
|
|
{
|
|
// TODO: Check for validity
|
|
add_function(m_FunctionTextBox_Text);
|
|
}
|
|
}
|
|
|
|
if (GuiButton({ anchor01.x + 8, anchor01.y + 48, 56, 24 }, "Run"))
|
|
{
|
|
// TODO: Run Test
|
|
}
|
|
|
|
GuiLine({ anchor01.x + 8, anchor01.y + 96, 440, 12 }, nullptr);
|
|
|
|
// TODO: format infos into strings;
|
|
GuiLabel({ anchor01.x + 8, anchor01.y + 176, 144, 24 }, "Is Sorted: <bool>");
|
|
GuiLabel({ anchor01.x + 8, anchor01.y + 200, 144, 24 }, "Time elapsed: <double>: ");
|
|
GuiGroupBox({ anchor03.x + 0, anchor03.y + 0, 288, 104 }, "Calls");
|
|
GuiLabel({ anchor03.x + 8, anchor03.y + 8, 120, 24 }, "Swap: <size_t>");
|
|
GuiLabel({ anchor03.x + 8, anchor03.y + 32, 120, 24 }, "Size: <size_t>");
|
|
GuiLabel({ anchor03.x + 136, anchor03.y + 8, 120, 24 }, "Greater: <size_t>");
|
|
GuiLabel({ anchor03.x + 136, anchor03.y + 32, 120, 24 }, "Lesser: <size_t>");
|
|
GuiLabel({ anchor03.x + 136, anchor03.y + 56, 120, 24 }, "Equal: <size_t>");
|
|
GuiLabel({ anchor01.x + 8, anchor01.y + 152, 144, 24 }, "Array size: <size_t>");
|
|
GuiLabel({ anchor01.x + 8, anchor01.y + 112, 144, 24 }, "Tests ran: <size_t>");
|
|
GuiLabel({ anchor01.x + 152, anchor01.y + 112, 144, 24 }, "Test number: <size_t>");
|
|
|
|
if (GuiButton({ anchor01.x + 112, anchor01.y + 264, 88, 24 }, "Next"))
|
|
{
|
|
// TODO: implement Test result stack movement
|
|
}
|
|
if (GuiButton({ anchor01.x + 8, anchor01.y + 264, 88, 24 }, "Previous"))
|
|
{
|
|
// TODO: Display previous result
|
|
}
|
|
|
|
if (GuiButton({ anchor01.x + 320, anchor01.y + 264, 120, 24 }, "Clear All Test"))
|
|
{
|
|
m_SortResults.clear();
|
|
}
|
|
|
|
if (GuiDropdownBox({ anchor01.x + 8, anchor01.y + 16, 184, 24 }, m_FunctionList.c_str(), &m_FunctionDropdown_Active, m_FunctionDropdown_EditMode)) m_FunctionDropdown_EditMode = !m_FunctionDropdown_EditMode;
|
|
}
|
|
GuiUnlock();
|
|
//----------------------------------------------------------------------------------
|
|
|
|
return m_ErrorWindow.draw();
|
|
}
|
|
|
|
int BigSortComponent::input()
|
|
{
|
|
return m_ErrorWindow.input();
|
|
}
|
|
|
|
void BigSortComponent::onAttach()
|
|
{
|
|
sva::Sorter::setup(m_LuaState);
|
|
m_LuaState["list"] = m_Sorter;
|
|
}
|
|
|
|
void BigSortComponent::run_test()
|
|
{
|
|
std::string function_name = m_FunctionNames[m_FunctionDropdown_Active];
|
|
spdlog::debug("%s: Running sorting function: %s", function_name.c_str(), function_name.c_str());
|
|
m_SortResults.push_back(m_Sorter.run(m_LuaState[function_name]));
|
|
|
|
if (!m_SortResults.back().is_sorted)
|
|
{
|
|
spdlog::debug("%s: Could not sort the array", function_name.c_str());
|
|
}
|
|
}
|
|
|
|
void BigSortComponent::add_function(const std::string& function_name)
|
|
{
|
|
m_FunctionNames.push_back(function_name);
|
|
if (m_FunctionList.empty())
|
|
{
|
|
m_FunctionList = function_name;
|
|
return;
|
|
}
|
|
m_FunctionList += ';' + function_name;
|
|
}
|
|
|
|
void BigSortComponent::repack_function_list()
|
|
{
|
|
m_FunctionList.clear();
|
|
for (const auto& fn : m_FunctionNames)
|
|
{
|
|
m_FunctionList += fn + ';';
|
|
}
|
|
m_FunctionList.pop_back();
|
|
} |