| 1196 | } |
| 1197 | |
| 1198 | SEditResult<int64_t> CUi::DoValueSelectorWithState(const void *pId, const CUIRect *pRect, const char *pLabel, int64_t Current, int64_t Min, int64_t Max, const SValueSelectorProperties &Props) |
| 1199 | { |
| 1200 | // logic |
| 1201 | const bool Inside = MouseInside(pRect); |
| 1202 | const int Base = Props.m_IsHex ? 16 : 10; |
| 1203 | |
| 1204 | if(HotItem() == pId && m_ActiveValueSelectorState.m_Button >= 0 && !MouseButton(m_ActiveValueSelectorState.m_Button)) |
| 1205 | { |
| 1206 | DisableMouseLock(); |
| 1207 | if(CheckActiveItem(pId)) |
| 1208 | { |
| 1209 | SetActiveItem(nullptr); |
| 1210 | } |
| 1211 | if(Inside && ((m_ActiveValueSelectorState.m_Button == 0 && !m_ActiveValueSelectorState.m_DidScroll && DoDoubleClickLogic(pId)) || m_ActiveValueSelectorState.m_Button == 1)) |
| 1212 | { |
| 1213 | m_ActiveValueSelectorState.m_pLastTextId = pId; |
| 1214 | m_ActiveValueSelectorState.m_NumberInput.SetInteger64(Current, Base, Props.m_HexPrefix); |
| 1215 | m_ActiveValueSelectorState.m_NumberInput.SelectAll(); |
| 1216 | } |
| 1217 | m_ActiveValueSelectorState.m_Button = -1; |
| 1218 | } |
| 1219 | |
| 1220 | if(m_ActiveValueSelectorState.m_pLastTextId == pId) |
| 1221 | { |
| 1222 | SetActiveItem(&m_ActiveValueSelectorState.m_NumberInput); |
| 1223 | DoEditBox(&m_ActiveValueSelectorState.m_NumberInput, pRect, 10.0f); |
| 1224 | |
| 1225 | if(ConsumeHotkey(HOTKEY_ENTER) || ((MouseButtonClicked(1) || MouseButtonClicked(0)) && !Inside)) |
| 1226 | { |
| 1227 | Current = std::clamp(m_ActiveValueSelectorState.m_NumberInput.GetInteger64(Base), Min, Max); |
| 1228 | DisableMouseLock(); |
| 1229 | SetActiveItem(nullptr); |
| 1230 | m_ActiveValueSelectorState.m_pLastTextId = nullptr; |
| 1231 | } |
| 1232 | |
| 1233 | if(ConsumeHotkey(HOTKEY_ESCAPE)) |
| 1234 | { |
| 1235 | DisableMouseLock(); |
| 1236 | SetActiveItem(nullptr); |
| 1237 | m_ActiveValueSelectorState.m_pLastTextId = nullptr; |
| 1238 | } |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | if(CheckActiveItem(pId)) |
| 1243 | { |
| 1244 | dbg_assert(m_ActiveValueSelectorState.m_Button >= 0, "m_ActiveValueSelectorState.m_Button invalid"); |
| 1245 | if(Props.m_UseScroll && m_ActiveValueSelectorState.m_Button == 0 && MouseButton(0)) |
| 1246 | { |
| 1247 | m_ActiveValueSelectorState.m_ScrollValue += MouseDeltaX() * (Input()->ShiftIsPressed() ? 0.05f : 1.0f); |
| 1248 | |
| 1249 | if(absolute(m_ActiveValueSelectorState.m_ScrollValue) > Props.m_Scale) |
| 1250 | { |
| 1251 | const int64_t Count = (int64_t)(m_ActiveValueSelectorState.m_ScrollValue / Props.m_Scale); |
| 1252 | m_ActiveValueSelectorState.m_ScrollValue = std::fmod(m_ActiveValueSelectorState.m_ScrollValue, Props.m_Scale); |
| 1253 | Current += Props.m_Step * Count; |
| 1254 | Current = std::clamp(Current, Min, Max); |
| 1255 | m_ActiveValueSelectorState.m_DidScroll = true; |
no test coverage detected