mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-11 07:49:42 +00:00
Add RmlUi: SettingsUIMenu. And the other menus that already use RmlUi have been cleaned up.
This commit is contained in:
99
Minecraft.Client/Common/UI/UIScene_RmlBase.cpp
Normal file
99
Minecraft.Client/Common/UI/UIScene_RmlBase.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user