changing components

This commit is contained in:
noffie 2025-01-07 19:14:45 +01:00
parent 5c8504288b
commit f02f77d5df
7 changed files with 88 additions and 10 deletions

View file

@ -26,7 +26,7 @@ int SafeClosePopup::draw()
if (m_WindowOpen)
{
GuiUnlock();
anchor03 = { .x = m_WndRect.x + 168, .y = m_WndRect.y + 88 };
anchor03 = { .x = m_WndRect.x + (168 * m_WndScalar), .y = m_WndRect.y + (88 * m_WndScalar) };
m_WindowOpen = !GuiWindowBox(m_WndRect, "#191# Are you sure you want to close this program?");
{ // Drawing in different colours
@ -36,14 +36,14 @@ int SafeClosePopup::draw()
GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, 0x7192C2FF);
GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, 0xBBCDD3FF);
m_CQB_YesButton = GuiButton({ anchor03.x + -152, anchor03.y + 32, 120, 24 }, "#112#Yes");
m_CQB_YesButton = GuiButton({ anchor03.x + (-152 * m_WndScalar), anchor03.y + (32 * m_WndScalar), 120 * m_WndScalar, 24 * m_WndScalar }, "#112#Yes");
GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, border_color);
GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, base_color);
}
m_CQB_NoButton = GuiButton({ anchor03.x + 24, anchor03.y + 32, 120, 24 }, "#113#No");
GuiLabel({ anchor03.x + -104, anchor03.y + -40, 208, 24 }, "Are you sure you want to close this?");
GuiLabel({ anchor03.x + -56, anchor03.y + -8, 120, 24 }, "Press \"Yes\" to close");
m_CQB_NoButton = GuiButton({ anchor03.x + (24 * m_WndScalar), anchor03.y + (32 * m_WndScalar), 120 * m_WndScalar, 24 * m_WndScalar }, "#113#No");
GuiLabel({ anchor03.x + (-104 * m_WndScalar), anchor03.y + (-40 * m_WndScalar), 208 * m_WndScalar, 24 * m_WndScalar }, "Are you sure you want to close this?");
GuiLabel({ anchor03.x + (-56 * m_WndScalar), anchor03.y + (-8 * m_WndScalar), 120 * m_WndScalar, 24 * m_WndScalar }, "Press \"Yes\" to close");
if (m_CQB_YesButton)
{
*m_WndRunning = false;
@ -68,6 +68,7 @@ void SafeClosePopup::onResize()
{
anchor03 = { static_cast<float>(m_WndWidth) / 2 , static_cast<float>(m_WndHeight) / 2 };
m_WndRect = { anchor03.x + -168, anchor03.y + -88, 328, 160 };
scale(m_WndScalar);
}
void SafeClosePopup::OpenWindow()
@ -80,4 +81,4 @@ void SafeClosePopup::CloseWindow()
{
m_WindowOpen = false;
GuiUnlock();
}
}

View file

@ -26,7 +26,6 @@ public:
int rinput(Vector2& mouse_position) override;
void onResize() override;
public:

View file

@ -10,6 +10,8 @@ class ComponentStack final
public:
inline static bool* s_WndRunning;
inline static size_t s_WndWidth, s_WndHeight;
inline static float s_WndScalar = 1.f;
template<typename T, typename ...Args> requires std::is_base_of_v<sva::GuiComponent, T>
static std::shared_ptr<T> push(Args&&... args)
@ -19,6 +21,7 @@ public:
s_Components.push_back(comp);
comp->wndrsize(s_WndWidth, s_WndHeight);
comp->attach(s_WndRunning);
comp->scale(s_WndScalar);
return comp;
}
@ -42,4 +45,13 @@ public:
comp->wndrsize(s_WndWidth, s_WndHeight);
}
}
static void scale_all(float scalar)
{
s_WndScalar = scalar;
for (const auto& comp : s_Components)
{
comp->scale(scalar);
}
}
};

View file

@ -1,7 +1,10 @@
#include "./CoreComponents.hpp"
namespace sva {
GuiMovableWindow::GuiMovableWindow()
/*
* GuiMovableWindow
*/
GuiMovableWindow::GuiMovableWindow() : m_WndRect({ 20,20, 200, 100 })
{
m_Title = "Example movable Window";
}
@ -48,6 +51,16 @@ namespace sva {
return rdraw();
}
void GuiMovableWindow::scale(float scale)
{
GuiComponent::scale(scale);
m_WndRect.width *= scale;
m_WndRect.height *= scale;
}
/*
* Error Window
*/
void ErrorWindow::onAttach()
{

View file

@ -10,7 +10,7 @@ namespace sva {
bool m_DragWindow = false;
Vector2 m_PanOffset = { 0,0 };
protected:
Rectangle m_WndRect = { 20,20, 200, 100 };
Rectangle m_WndRect;
bool m_WindowOpen = true;
std::string m_Title;
public:
@ -22,6 +22,8 @@ namespace sva {
virtual int rdraw();
virtual int draw() override;
virtual void scale(float scale) override;
};
class ErrorWindow : public GuiMovableWindow

View file

@ -14,9 +14,13 @@ namespace sva {
void attach(bool* wnd_running) { m_WndRunning = wnd_running; onAttach(); }
virtual void onAttach() {}
virtual void scale(float scale) { m_WndScalar = scale; }
protected:
bool* m_WndRunning = nullptr;
size_t m_WndWidth = 0;
size_t m_WndHeight = 0;
float m_WndScalar = 1;
};
}

View file

@ -40,16 +40,32 @@ enum class logerr_level
SVA,
};
struct AppArgsConfig {
// every value has to have a default assigned at init.
float scalar = 1;
const char* path; // this is an exception as it can not, not be passed
};
AppArgsConfig sva_parse_args(int argc, char** argv);
int main(int argc, char** argv)
{
#ifdef _DEBUG
spdlog::set_level(spdlog::level::debug);
spdlog::set_pattern("\n\t%^%v%$\n");
#endif
spdlog::set_pattern("\n\t%^%v%$\n");
spdlog::debug("Darling, I'm Home");
spdlog::set_pattern("[%T %z] [%^%l%$] [thread %t] %v");
/*
* Parsing args...
*/
AppArgsConfig acnf = sva_parse_args(argc, argv);
/* Window and rendering */
InitWindow(window_width, window_height, window_title);
@ -68,6 +84,9 @@ int main(int argc, char** argv)
spdlog::debug("Window created successfully.");
int font_size = static_cast<int>(static_cast<float>(GuiGetStyle(DEFAULT, TEXT_SIZE)) * acnf.scalar);
GuiSetStyle(DEFAULT, TEXT_SIZE, font_size);
spdlog::debug("New Text size is: %d", font_size);
bool is_running = true;
ComponentStack::s_WndRunning = &is_running;
@ -78,11 +97,13 @@ int main(int argc, char** argv)
int run_result = 0;
ComponentStack::push<BigSortComponent>();
ComponentStack::scale_all(acnf.scalar);
// always on top...
SafeClosePopup safe_close_popup;
safe_close_popup.attach(&is_running);
safe_close_popup.wndrsize(ComponentStack::s_WndWidth, ComponentStack::s_WndHeight);
safe_close_popup.scale(acnf.scalar);
while (is_running) {
@ -127,3 +148,29 @@ int main(int argc, char** argv)
return run_result;
}
AppArgsConfig sva_parse_args(int argc, char** argv)
{
// created with defaults
AppArgsConfig config;
printf("argc: %d\n", argc);
config.path = argv[0];
if (argc > 1)
{
if (!strcmp(argv[1], "--scale"))
{
spdlog::warn("The Scale mode is not fully supported");
if (argc < 3)
{
spdlog::error("No argument passed to --scale option");
exit(1);
}
config.scalar = std::stof(argv[2]);
}
}
return config;
}