BAGEL: Fixes for edit text field in savegame dialog

This commit is contained in:
Paul Gilbert 2024-03-20 20:45:09 -07:00 committed by Eugene Sandulenko
parent f6cc0269e0
commit 347a8021dd
5 changed files with 26 additions and 3 deletions

@ -454,7 +454,6 @@ CBofRect CalculateTextRect(CBofWindow *pWnd, const CBofString *pStr, INT nSize,
for (uint i = 0; i < lines.size(); ++i)
maxWidth = MAX(maxWidth, font->getStringWidth(lines[i]));
delete font;
return CBofRect(0, 0, maxWidth, (int)lines.size() * font->getFontHeight());
}

@ -103,7 +103,9 @@ VOID CBofEditText::OnPaint(CBofRect *pRect) {
// Draw the text, if any
if (!_text.IsEmpty()) {
PaintText(this, &m_cRect, _text.GetBuffer(),
CBofString tmp = _text + "|";
PaintText(this, &m_cRect, tmp.GetBuffer(),
12, 0, CTEXT_COLOR,
JUSTIFY_LEFT,
FORMAT_TOP_LEFT | FORMAT_SINGLE_LINE);
@ -122,7 +124,19 @@ VOID CBofEditText::OnLButtonDown(UINT nFlags, CBofPoint *pPoint, void *) {
}
VOID CBofEditText::OnKeyHit(ULONG lKey, ULONG lRepCount) {
// TODO: Handle keypresses in textbox
if (lKey >= 32 && lKey <= 127) {
CBofString tmp = _text + lKey;
CBofRect rect = CalculateTextRect(this, &tmp, 12, 0);
if ((m_cRect.Width() - rect.Width()) > 10) {
_text = tmp;
UpdateWindow();
}
} else if (lKey == BKEY_BACK && !_text.IsEmpty()) {
_text.DeleteLastChar();
UpdateWindow();
}
}
} // namespace Bagel

@ -1253,6 +1253,7 @@ ULONG CBofWindow::TranslateKey(const Common::Event &event) const {
case Common::KEYCODE_UP: nCode = BKEY_UP; break;
case Common::KEYCODE_DOWN: nCode = BKEY_DOWN; break;
case Common::KEYCODE_INSERT: nCode = BKEY_INS; break;
case Common::KEYCODE_BACKSPACE: nCode = BKEY_BACK; break;
case Common::KEYCODE_DELETE: nCode = BKEY_DEL; break;
case Common::KEYCODE_SCROLLOCK: nCode = BKEY_SCRL_LOCK; break;
case Common::KEYCODE_PAGEUP: nCode = BKEY_PAGEUP; break;

@ -533,6 +533,13 @@ VOID CBofString::Left(INT nCount, CBofString *lStr) const {
lStr->m_nLength = (USHORT)nCount;
}
void CBofString::DeleteLastChar() {
if (!IsEmpty()) {
*(m_pszData + m_nLength - 1) = '\0';
--m_nLength;
}
}
// strspn equivalent
CBofString CBofString::SpanIncluding(const CHAR *lpszCharSet) const {
Assert(IsValidObject(this));

@ -152,6 +152,8 @@ public:
VOID Left(INT nCount, CBofString *) const;
VOID Right(INT nCount, CBofString *) const;
void DeleteLastChar();
CBofString SpanIncluding(const CHAR *lpszCharSet) const;
CBofString SpanExcluding(const CHAR *lpszCharSet) const;