mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-09 23:18:30 +00:00
100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
#include "UI.h"
|
|
|
|
#pragma push_macro("byte")
|
|
#pragma push_macro("GetNextSibling")
|
|
#pragma push_macro("GetFirstChild")
|
|
#undef byte
|
|
#undef GetNextSibling
|
|
#undef GetFirstChild
|
|
|
|
#include "UIScene_RmlBase.h"
|
|
#include "RmlManager.h"
|
|
#include "../../Windows64/KeyboardMouseInput.h"
|
|
#include <RmlUi/Core/Input.h>
|
|
#include <RmlUi/Core/Context.h>
|
|
|
|
#pragma pop_macro("GetFirstChild")
|
|
#pragma pop_macro("GetNextSibling")
|
|
#pragma pop_macro("byte")
|
|
|
|
UIScene_RmlBase::UIScene_RmlBase(int iPad, UILayer *parentLayer)
|
|
: UIScene(iPad, parentLayer)
|
|
{
|
|
}
|
|
|
|
UIScene_RmlBase::~UIScene_RmlBase()
|
|
{
|
|
}
|
|
|
|
void UIScene_RmlBase::tick()
|
|
{
|
|
m_hasTickedOnce = true;
|
|
UIScene::tick();
|
|
|
|
Rml::Context* ctx = RmlManager::Get().GetContext();
|
|
if (!ctx || !bHasFocus)
|
|
return;
|
|
|
|
ForwardRmlInput(ctx);
|
|
ctx->Update();
|
|
}
|
|
|
|
void UIScene_RmlBase::gainFocus()
|
|
{
|
|
if (!bHasFocus && stealsFocus())
|
|
{
|
|
bHasFocus = true;
|
|
updateTooltips();
|
|
updateComponents();
|
|
handleGainFocus(m_bFocussedOnce);
|
|
if (bHasFocus)
|
|
m_bFocussedOnce = true;
|
|
if (m_document)
|
|
m_document->Show();
|
|
}
|
|
}
|
|
|
|
void UIScene_RmlBase::handleLoseFocus()
|
|
{
|
|
if (m_document)
|
|
m_document->Hide();
|
|
}
|
|
|
|
void UIScene_RmlBase::ForwardRmlInput(Rml::Context* ctx)
|
|
{
|
|
ctx->ProcessMouseMove(g_KBMInput.GetMouseX(), g_KBMInput.GetMouseY(), 0);
|
|
|
|
if (g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_LEFT))
|
|
ctx->ProcessMouseButtonDown(0, 0);
|
|
if (g_KBMInput.IsMouseButtonReleased(KeyboardMouseInput::MOUSE_LEFT))
|
|
ctx->ProcessMouseButtonUp(0, 0);
|
|
if (g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_RIGHT))
|
|
ctx->ProcessMouseButtonDown(1, 0);
|
|
if (g_KBMInput.IsMouseButtonReleased(KeyboardMouseInput::MOUSE_RIGHT))
|
|
ctx->ProcessMouseButtonUp(1, 0);
|
|
|
|
int wheelDelta = g_KBMInput.GetMouseWheel();
|
|
if (wheelDelta != 0)
|
|
ctx->ProcessMouseWheel(wheelDelta / -120, 0);
|
|
}
|
|
|
|
void UIScene_RmlBase::RegisterEvents(std::initializer_list<const char*> ids)
|
|
{
|
|
if (!m_document) return;
|
|
for (const char* id : ids)
|
|
{
|
|
auto* el = m_document->GetElementById(id);
|
|
if (el) el->AddEventListener(Rml::EventId::Click, this);
|
|
}
|
|
}
|
|
|
|
void UIScene_RmlBase::UnregisterEvents(std::initializer_list<const char*> ids)
|
|
{
|
|
if (!m_document) return;
|
|
for (const char* id : ids)
|
|
{
|
|
auto* el = m_document->GetElementById(id);
|
|
if (el) el->RemoveEventListener(Rml::EventId::Click, this);
|
|
}
|
|
}
|