diff --git a/src/console_gui.cpp b/src/console_gui.cpp index baa5373228..d068338204 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -153,7 +153,7 @@ struct IConsoleWindow : Window IConsoleWindow(const WindowDesc *desc) : Window(desc) { _iconsole_mode = ICONSOLE_OPENED; - SetBit(_no_scroll, SCROLL_CON); // override cursor arrows; the gamefield will not scroll + _no_scroll++; // override cursor arrows; the gamefield will not scroll this->height = _screen.height / 3; this->width = _screen.width; @@ -162,7 +162,7 @@ struct IConsoleWindow : Window ~IConsoleWindow() { _iconsole_mode = ICONSOLE_CLOSED; - ClrBit(_no_scroll, SCROLL_CON); + _no_scroll--; } virtual void OnPaint() diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 57ead63b2b..ac1f24d165 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1068,7 +1068,6 @@ struct QueryStringWindow : public QueryStringBaseWindow QueryStringWindow(uint16 size, const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(size, desc) { this->parent = parent; - SetBit(_no_scroll, SCROLL_EDIT); this->FindWindowPlacementAndResize(desc); } @@ -1142,7 +1141,6 @@ struct QueryStringWindow : public QueryStringBaseWindow this->parent = NULL; // so parent doesn't try to delete us again parent->OnQueryTextFinished(NULL); } - ClrBit(_no_scroll, SCROLL_EDIT); } }; @@ -1443,7 +1441,6 @@ struct SaveLoadWindow : public QueryStringBaseWindow { }; SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0); - SetBit(_no_scroll, SCROLL_SAVE); /* Use an array to define what will be the current file type being handled * by current file mode */ @@ -1505,7 +1502,6 @@ struct SaveLoadWindow : public QueryStringBaseWindow { if (_pause_game >= 0) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); } FiosFreeSavegameList(); - ClrBit(_no_scroll, SCROLL_SAVE); } virtual void OnPaint() diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index c2ce73a84c..02aec095a6 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -277,7 +277,6 @@ struct NetworkChatWindow : public QueryStringBaseWindow { InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 0); InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height); - SetBit(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys _chat_tab_completion_active = false; @@ -287,7 +286,6 @@ struct NetworkChatWindow : public QueryStringBaseWindow { ~NetworkChatWindow () { InvalidateWindowData(WC_NEWS_WINDOW, 0, 0); - ClrBit(_no_scroll, SCROLL_CHAT); } /** diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp index ad75776302..1dfce4cfbc 100644 --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -66,7 +66,6 @@ struct OskWindow : public Window { /* make a copy in case we need to reset later */ this->orig_str_buf = strdup(this->qs->text.buf); - SetBit(_no_scroll, SCROLL_EDIT); /* Not needed by default. */ this->DisableWidget(OSK_WIDGET_SPECIAL); diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index e57c4bfaf5..07ab6904b2 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -199,7 +199,6 @@ struct SignWindow : QueryStringBaseWindow, SignList { SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES, desc) { - SetBit(_no_scroll, SCROLL_EDIT); this->caption = STR_280B_EDIT_SIGN_TEXT; this->afilter = CS_ALPHANUMERAL; this->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT); @@ -208,11 +207,6 @@ struct SignWindow : QueryStringBaseWindow, SignList { this->FindWindowPlacementAndResize(desc); } - ~SignWindow() - { - ClrBit(_no_scroll, SCROLL_EDIT); - } - void UpdateSignEditWindow(const Sign *si) { char *last_of = &this->edit_str_buf[this->edit_str_size - 1]; // points to terminating '\0' diff --git a/src/window.cpp b/src/window.cpp index f12cd573f7..f28d4dbdd1 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -461,7 +461,13 @@ Window::~Window() if (this->viewport != NULL) DeleteWindowViewport(this); this->SetDirty(); - free(this->widget); + + if (this->widget != NULL) { + for (const Widget *wi = this->widget; wi->type != WWT_LAST; wi++) { + if (wi->type == WWT_EDITBOX) _no_scroll--; + } + free(this->widget); + } } /** @@ -690,6 +696,10 @@ static void AssignWidgetToWindow(Window *w, const Widget *widget) w->widget = MallocT(index); memcpy(w->widget, widget, sizeof(*w->widget) * index); w->widget_count = index - 1; + + for (const Widget *wi = w->widget; wi->type != WWT_LAST; wi++) { + if (wi->type == WWT_EDITBOX) _no_scroll++; + } } else { w->widget = NULL; w->widget_count = 0; diff --git a/src/window_gui.h b/src/window_gui.h index 0a3755380c..0fbd4c1a58 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -544,18 +544,9 @@ extern Window **_last_z_window; #define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++) /** - * In certain windows you navigate with the arrow keys. Do not scroll the - * gameview when here. Bitencoded variable that only allows scrolling if all - * elements are zero + * Disable scrolling of the main viewport when an input-window is active. + * This contains the count of windows with a textbox in them. */ -enum { - SCROLL_CON = 0, - SCROLL_EDIT = 1, - SCROLL_SAVE = 2, - SCROLL_CHAT = 4, -}; - -/** Disable scrolling of the main viewport when an input-window is active. */ extern byte _no_scroll; extern Point _cursorpos_drag_start;