added option to type text into valueselector

This commit is contained in:
H-M-H 2015-03-30 03:20:35 +02:00
parent 87471f752b
commit 68db1c1113

View file

@ -1,5 +1,6 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <iostream>
#include <base/tl/array.h> #include <base/tl/array.h>
@ -665,8 +666,42 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
{ {
// logic // logic
static float s_Value; static float s_Value;
static char s_NumStr[64];
static bool s_TextMode = false;
static void* s_LastTextpID = pID;
int Inside = UI()->MouseInside(pRect); int Inside = UI()->MouseInside(pRect);
if(UI()->MouseButton(1) && UI()->HotItem() == pID)
{
s_LastTextpID = pID;
s_TextMode = true;
str_format(s_NumStr, sizeof(s_NumStr), "%d", Current);
}
if(s_TextMode && s_LastTextpID == pID)
{
m_pTooltip = "Type your number";
static float s_NumberBoxID = 0;
DoEditBox(&s_NumberBoxID, pRect, s_NumStr, sizeof(s_NumStr), 10.0f, &s_NumberBoxID);
UI()->SetActiveItem(&s_NumberBoxID);
if(Input()->KeyPressed(KEY_RETURN) || Input()->KeyPressed(KEY_KP_ENTER))
{
Current = clamp(str_toint(s_NumStr), Min, Max);
UI()->SetActiveItem(0);
s_TextMode = false;
}
if(Input()->KeyPressed(KEY_ESCAPE))
{
UI()->SetActiveItem(0);
s_TextMode = false;
}
}
else
{
if(UI()->ActiveItem() == pID) if(UI()->ActiveItem() == pID)
{ {
if(!UI()->MouseButton(0)) if(!UI()->MouseButton(0))
@ -686,13 +721,10 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
int Count = (int)(s_Value/Scale); int Count = (int)(s_Value/Scale);
s_Value = fmod(s_Value, Scale); s_Value = fmod(s_Value, Scale);
Current += Step*Count; Current += Step*Count;
if(Current < Min) Current = clamp(Current, Min, Max);
Current = Min;
if(Current > Max)
Current = Max;
} }
} }
if(pToolTip) if(pToolTip && !s_TextMode)
m_pTooltip = pToolTip; m_pTooltip = pToolTip;
} }
else if(UI()->HotItem() == pID) else if(UI()->HotItem() == pID)
@ -703,8 +735,14 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
s_Value = 0; s_Value = 0;
UI()->SetActiveItem(pID); UI()->SetActiveItem(pID);
} }
if(pToolTip) if(pToolTip && !s_TextMode)
m_pTooltip = pToolTip; m_pTooltip = pToolTip;
if(!Inside)
{
UI()->SetActiveItem(0);
s_TextMode = false;
}
} }
if(Inside) if(Inside)
@ -716,6 +754,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, 0), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(pRect, GetButtonColor(pID, 0), CUI::CORNER_ALL, 5.0f);
pRect->y += pRect->h/2.0f-7.0f; pRect->y += pRect->h/2.0f-7.0f;
UI()->DoLabel(pRect, aBuf, 10, 0, -1); UI()->DoLabel(pRect, aBuf, 10, 0, -1);
}
return Current; return Current;
} }