MCPcopy Create free account
hub / github.com/ddnet/ddnet / DoEditBox

Method DoEditBox

src/game/client/ui.cpp:904–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

902}
903
904bool CUi::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners, const std::vector<STextColorSplit> &vColorSplits)
905{
906 const bool Inside = MouseHovered(pRect);
907 const bool Active = m_pLastActiveItem == pLineInput;
908 const bool Changed = pLineInput->WasChanged();
909 const bool CursorChanged = pLineInput->WasCursorChanged();
910
911 const float VSpacing = 2.0f;
912 CUIRect Textbox;
913 pRect->VMargin(VSpacing, &Textbox);
914
915 bool JustGotActive = false;
916 if(CheckActiveItem(pLineInput))
917 {
918 if(MouseButton(0))
919 {
920 if(pLineInput->IsActive() && (Input()->HasComposition() || Input()->GetCandidateCount()))
921 {
922 // Clear IME composition/candidates on mouse press
923 Input()->StopTextInput();
924 Input()->StartTextInput();
925 }
926 }
927 else
928 {
929 SetActiveItem(nullptr);
930 }
931 }
932 else if(HotItem() == pLineInput)
933 {
934 if(MouseButton(0))
935 {
936 if(!Active)
937 JustGotActive = true;
938 SetActiveItem(pLineInput);
939 }
940 }
941
942 if(Inside && !MouseButton(0))
943 SetHotItem(pLineInput);
944
945 if(Enabled() && Active && !JustGotActive)
946 pLineInput->Activate(EInputPriority::UI);
947 else
948 pLineInput->Deactivate();
949
950 float ScrollOffset = pLineInput->GetScrollOffset();
951 float ScrollOffsetChange = pLineInput->GetScrollOffsetChange();
952
953 // Update mouse selection information
954 CLineInput::SMouseSelection *pMouseSelection = pLineInput->GetMouseSelection();
955 if(Inside)
956 {
957 if(!pMouseSelection->m_Selecting && MouseButtonClicked(0))
958 {
959 pMouseSelection->m_Selecting = true;
960 pMouseSelection->m_PressMouse = MousePos();
961 pMouseSelection->m_Offset.x = ScrollOffset;

Calls 15

InputFunction · 0.85
WasChangedMethod · 0.80
WasCursorChangedMethod · 0.80
VMarginMethod · 0.80
HasCompositionMethod · 0.80
GetCandidateCountMethod · 0.80
StopTextInputMethod · 0.80
StartTextInputMethod · 0.80
ActivateMethod · 0.80
DeactivateMethod · 0.80
GetScrollOffsetMethod · 0.80
GetScrollOffsetChangeMethod · 0.80

Tested by

no test coverage detected