rodecomp/Source/UI/Edit/EditTextState.cpp
ragnarok-clanker bcaf506c7d Maintenance: [forced, user-approved] CLanguage step 7 (follow-up to #10185): the remaining edit-input methods move onto the real obje
Batch #10186 by ragnarok-clanker: forced by an admin (9 lower score(s), 41 changed function(s)); checked with 110 compiled unit(s), including every includer of Source/Client/Input/Language.h, Source/UI/Edit/EditTextState.h, Source/UI/Edit/EditViewport.h, Source/UI/Edit/UIEditCtrl.h.
2026-11-02 19:58:55 +00:00

60 lines
1.5 KiB
C++

#include "Client/Input/InputCharset.h"
#include "Client/Input/Language.h"
#include "UI/Edit/EditTextState.h"
#include <cstring>
// INLINED
void EditTextState::SetText(const char* value) {
this->text.assign(value, std::strlen(value));
this->Trim();
if (this->focused) {
g_serverLanguage->ResetInput();
g_serverLanguage->ResetInput();
g_serverLanguage->Insert(this->text.c_str());
}
this->SelectAll();
}
// OFFSET: 0x00868450
// FUNCTION: fn_10959
void EditTextState::Trim() {
const auto length = this->text.size();
if (static_cast<int>(length) <= this->maximum) {
return;
}
const auto codePage = static_cast<WORD>(this->codePage);
const char* start = this->text.c_str();
const char* next = CharNextExA(codePage, start, 0);
while (length - std::strlen(next) <= static_cast<unsigned>(this->maximum)) {
next = CharNextExA(codePage, next, 0);
}
const char* previous = CharPrevExA(codePage, start, next, 0);
this->text.resize(length - std::strlen(previous));
while (this->text.size() < static_cast<unsigned>(this->maximum)) {
this->text.push_back(' ');
}
}
// OFFSET: 0x0085A590
// FUNCTION: fn_10778
void EditTextState::SelectAll() {
if (this->focused) {
g_serverLanguage->Select(0, static_cast<int>(g_serverLanguage->text.size()));
} else {
this->anchor = 0;
this->cursor = static_cast<int>(this->text.size());
}
}
// OFFSET: 0x00858D50
int EditTextState::Length() const {
return static_cast<int>(this->focused ? g_serverLanguage->text.size() : this->text.size());
}