Skip to content

Commit d510239

Browse files
committed
UI: fix TextEditInput use as form widget
1 parent 50e921d commit d510239

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/platform/sdl/runtime.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#define PAUSE_DEBUG_LAUNCH 750
3838
#define PAUSE_DEBUG_STEP 50
3939
#define MAIN_BAS "__main_bas__"
40-
#define AMPLITUDE 22000
41-
#define FREQUENCY 44100
4240
#define OPTIONS_BOX_WIDTH_EXTRA 1
4341
#define OPTIONS_BOX_BG 0xd2d1d0
4442
#define OPTIONS_BOX_FG 0x3e3f3e

src/ui/inputs.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ void FormEditInput::setFocus(bool focus) {
486486
}
487487
}
488488

489+
void FormEditInput::clicked(int x, int y, bool pressed) {
490+
if (pressed && g_system->isRunning()) {
491+
dev_clrkb();
492+
setFocus(true);
493+
focusEdit = this;
494+
}
495+
}
496+
489497
//
490498
// FormLineInput
491499
//
@@ -515,11 +523,9 @@ FormLineInput::~FormLineInput() {
515523
}
516524

517525
void FormLineInput::clicked(int x, int y, bool pressed) {
526+
FormEditInput::clicked(x, y, pressed);
518527
if (pressed && g_system->isRunning()) {
519528
AnsiWidget *out = g_system->getOutput();
520-
dev_clrkb();
521-
setFocus(true);
522-
focusEdit = this;
523529
int charWidth = out->getCharWidth();
524530
int selected = (x - _x) / charWidth;
525531
int len = strlen(_buffer);

src/ui/inputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ struct FormEditInput : public FormInput {
213213
virtual const char *completeKeyword(int index) = 0;
214214
virtual int getCompletions(StringList *list, int max) = 0;
215215

216+
void clicked(int x, int y, bool pressed);
216217
void setFocus(bool focus);
217218
int getControlKey(int key);
218219
bool getControlMode() const { return _controlMode; }

src/ui/textedit.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ void TextEditInput::setCursorRow(int row) {
10721072
}
10731073

10741074
void TextEditInput::clicked(int x, int y, bool pressed) {
1075+
FormEditInput::clicked(x, y, pressed);
10751076
if (x < _marginWidth) {
10761077
_ptY = -1;
10771078
} else if (pressed) {
@@ -1080,7 +1081,7 @@ void TextEditInput::clicked(int x, int y, bool pressed) {
10801081
_state.select_start = wordStart();
10811082
_state.select_end = wordEnd();
10821083
} else {
1083-
stb_textedit_click(&_buf, &_state, x - _marginWidth, y + (_scroll * _charHeight));
1084+
stb_textedit_click(&_buf, &_state, (x - _x) - _marginWidth, (y - _y) + (_scroll * _charHeight));
10841085
}
10851086
_pressTick = tick;
10861087
}
@@ -1106,17 +1107,17 @@ bool TextEditInput::updateUI(var_p_t form, var_p_t field) {
11061107
}
11071108

11081109
bool TextEditInput::selected(MAPoint2d pt, int scrollX, int scrollY, bool &redraw) {
1109-
bool focus = hasFocus();
1110-
if (focus) {
1110+
bool result = FormEditInput::selected(pt, scrollX, scrollY, redraw);
1111+
if (hasFocus()) {
11111112
if (pt.x < _marginWidth) {
11121113
dragPage(pt.y, redraw);
11131114
} else {
1114-
stb_textedit_drag(&_buf, &_state, pt.x - _marginWidth,
1115-
pt.y + scrollY + (_scroll * _charHeight));
1115+
stb_textedit_drag(&_buf, &_state, (pt.x - _x) - _marginWidth,
1116+
(pt.y - _y) + scrollY + (_scroll * _charHeight));
11161117
redraw = true;
11171118
}
11181119
}
1119-
return focus;
1120+
return result;
11201121
}
11211122

11221123
void TextEditInput::selectNavigate(bool up) {
@@ -2043,8 +2044,8 @@ void TextEditHelpWidget::completeWord(int pos) {
20432044
void TextEditHelpWidget::clicked(int x, int y, bool pressed) {
20442045
_ptY = -1;
20452046
if (pressed) {
2046-
stb_textedit_click(&_buf, &_state, 0, y + (_scroll * _charHeight));
2047-
if (_mode == kHelpKeyword && x - _x <= _charWidth * 3) {
2047+
stb_textedit_click(&_buf, &_state, 0, (y - _y) + (_scroll * _charHeight));
2048+
if (_mode == kHelpKeyword && (x - _x) <= _charWidth * 3) {
20482049
toggleKeyword();
20492050
}
20502051
}

0 commit comments

Comments
 (0)