mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #3866
3866: Add Input handling to UI Ex initialization r=def- a=Jupeyy fixes #3865 - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
593ce122e6
|
@ -58,6 +58,9 @@ public:
|
|||
return m_aInputEvents[Index];
|
||||
}
|
||||
|
||||
CEvent *GetEventsRaw() { return m_aInputEvents; }
|
||||
int *GetEventCountRaw() { return &m_NumEvents; }
|
||||
|
||||
// keys
|
||||
virtual bool KeyIsPressed(int Key) const = 0;
|
||||
virtual bool KeyPress(int Key, bool CheckCounter = false) const = 0;
|
||||
|
|
|
@ -1188,7 +1188,7 @@ void CMenus::OnInit()
|
|||
if(g_Config.m_ClSkipStartMenu)
|
||||
m_ShowStart = false;
|
||||
|
||||
m_UIEx.Init(UI(), Kernel(), RenderTools());
|
||||
m_UIEx.Init(UI(), Kernel(), RenderTools(), m_aInputEvents, &m_NumInputEvents);
|
||||
|
||||
m_RefreshButton.Init(UI());
|
||||
m_ConnectButton.Init(UI());
|
||||
|
|
|
@ -8,16 +8,18 @@
|
|||
|
||||
#include <limits>
|
||||
|
||||
CUIEx::CUIEx(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools)
|
||||
CUIEx::CUIEx(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools, IInput::CEvent *pInputEventsArray, int *pInputEventCount)
|
||||
{
|
||||
Init(pUI, pKernel, pRenderTools);
|
||||
Init(pUI, pKernel, pRenderTools, pInputEventsArray, pInputEventCount);
|
||||
}
|
||||
|
||||
void CUIEx::Init(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools)
|
||||
void CUIEx::Init(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools, IInput::CEvent *pInputEventsArray, int *pInputEventCount)
|
||||
{
|
||||
m_pUI = pUI;
|
||||
m_pKernel = pKernel;
|
||||
m_pRenderTools = pRenderTools;
|
||||
m_pInputEventsArray = pInputEventsArray;
|
||||
m_pInputEventCount = pInputEventCount;
|
||||
|
||||
m_pInput = Kernel()->RequestInterface<IInput>();
|
||||
m_pGraphics = Kernel()->RequestInterface<IGraphics>();
|
||||
|
@ -123,11 +125,11 @@ int CUIEx::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSi
|
|||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < Input()->NumEvents(); i++)
|
||||
for(int i = 0; i < *m_pInputEventCount; i++)
|
||||
{
|
||||
Len = str_length(pStr);
|
||||
int NumChars = Len;
|
||||
ReturnValue |= CLineInput::Manipulate(Input()->GetEvent(i), pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars);
|
||||
ReturnValue |= CLineInput::Manipulate(m_pInputEventsArray[i], pStr, StrSize, StrSize, &Len, &s_AtIndex, &NumChars);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +216,7 @@ int CUIEx::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSi
|
|||
DispCursorPos = minimum(DispCursorPos, str_length(pDisplayStr));
|
||||
|
||||
// check if the text has to be moved
|
||||
if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || Input()->NumEvents()))
|
||||
if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || *m_pInputEventCount))
|
||||
{
|
||||
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, DispCursorPos, std::numeric_limits<float>::max());
|
||||
if(w - *Offset > Textbox.w)
|
||||
|
@ -257,10 +259,11 @@ int CUIEx::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSi
|
|||
Graphics()->TextureClear();
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(0, 0, 0, 0.3f);
|
||||
IGraphics::CQuadItem CursorTBack(Textbox.x - (OnePixelWidth * 2.0f) / 2.0f, Textbox.y, OnePixelWidth * 2 * 2.0f, Textbox.h);
|
||||
float PosToMid = (Textbox.h - FontSize) / 2.0f;
|
||||
IGraphics::CQuadItem CursorTBack(Textbox.x - (OnePixelWidth * 2.0f) / 2.0f, Textbox.y + PosToMid, OnePixelWidth * 2 * 2.0f, FontSize);
|
||||
Graphics()->QuadsDrawTL(&CursorTBack, 1);
|
||||
Graphics()->SetColor(1, 1, 1, 1);
|
||||
IGraphics::CQuadItem CursorT(Textbox.x, Textbox.y + OnePixelWidth * 1.5f, OnePixelWidth * 2.0f, Textbox.h - OnePixelWidth * 1.5f * 2);
|
||||
IGraphics::CQuadItem CursorT(Textbox.x, Textbox.y + PosToMid + OnePixelWidth * 1.5f, OnePixelWidth * 2.0f, FontSize - OnePixelWidth * 1.5f * 2);
|
||||
Graphics()->QuadsDrawTL(&CursorT, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef GAME_CLIENT_UI_EX_H
|
||||
#define GAME_CLIENT_UI_EX_H
|
||||
|
||||
#include "engine/kernel.h"
|
||||
#include <base/system.h>
|
||||
#include <engine/input.h>
|
||||
#include <engine/kernel.h>
|
||||
#include <game/client/ui.h>
|
||||
|
||||
class IInput;
|
||||
|
@ -21,6 +22,9 @@ class CUIEx
|
|||
IGraphics *m_pGraphics;
|
||||
CRenderTools *m_pRenderTools;
|
||||
|
||||
IInput::CEvent *m_pInputEventsArray;
|
||||
int *m_pInputEventCount;
|
||||
|
||||
protected:
|
||||
CUI *UI() { return m_pUI; }
|
||||
IInput *Input() { return m_pInput; }
|
||||
|
@ -30,10 +34,10 @@ protected:
|
|||
CRenderTools *RenderTools() { return m_pRenderTools; }
|
||||
|
||||
public:
|
||||
CUIEx(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools);
|
||||
CUIEx(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools, IInput::CEvent *pInputEventsArray, int *pInputEventCount);
|
||||
CUIEx() {}
|
||||
|
||||
void Init(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools);
|
||||
void Init(CUI *pUI, IKernel *pKernel, CRenderTools *pRenderTools, IInput::CEvent *pInputEventsArray, int *pInputEventCount);
|
||||
|
||||
int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden = false, int Corners = CUI::CORNER_ALL, const char *pEmptyText = "");
|
||||
};
|
||||
|
|
|
@ -6205,7 +6205,7 @@ void CEditor::Init()
|
|||
m_UI.SetGraphics(m_pGraphics, m_pTextRender);
|
||||
m_Map.m_pEditor = this;
|
||||
|
||||
m_UIEx.Init(UI(), Kernel(), RenderTools());
|
||||
m_UIEx.Init(UI(), Kernel(), RenderTools(), Input()->GetEventsRaw(), Input()->GetEventCountRaw());
|
||||
|
||||
m_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||
m_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
|
||||
|
|
Loading…
Reference in a new issue