1
0
Fork 0

Codechange: use accessor for (scrollbar_)index as they are read only

pull/13279/head
Rubidium 2025-01-04 07:56:01 +01:00 committed by rubidium42
parent b653f875b0
commit bfc8ae6c52
6 changed files with 43 additions and 23 deletions

View File

@ -414,9 +414,9 @@ EventState PickerWindow::OnHotkey(int hotkey)
switch (hotkey) { switch (hotkey) {
case PCWHK_FOCUS_FILTER_BOX: case PCWHK_FOCUS_FILTER_BOX:
/* Cycle between the two edit boxes. */ /* Cycle between the two edit boxes. */
if (this->has_type_picker && (this->nested_focus == nullptr || this->nested_focus->index != WID_PW_TYPE_FILTER)) { if (this->has_type_picker && (this->nested_focus == nullptr || this->nested_focus->GetIndex() != WID_PW_TYPE_FILTER)) {
this->SetFocusedWidget(WID_PW_TYPE_FILTER); this->SetFocusedWidget(WID_PW_TYPE_FILTER);
} else if (this->has_class_picker && (this->nested_focus == nullptr || this->nested_focus->index != WID_PW_CLASS_FILTER)) { } else if (this->has_class_picker && (this->nested_focus == nullptr || this->nested_focus->GetIndex() != WID_PW_CLASS_FILTER)) {
this->SetFocusedWidget(WID_PW_CLASS_FILTER); this->SetFocusedWidget(WID_PW_CLASS_FILTER);
} }
SetFocusedWindow(this); SetFocusedWindow(this);

View File

@ -1410,7 +1410,7 @@ public:
NWidgetBase *nwid = it->get(); NWidgetBase *nwid = it->get();
nwid->current_x = 0; /* Hide widget, it will be revealed in the next step. */ nwid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
if (nwid->type == NWID_SPACER) continue; if (nwid->type == NWID_SPACER) continue;
lookup[dynamic_cast<NWidgetCore *>(nwid)->index] = std::distance(this->children.begin(), it); lookup[dynamic_cast<NWidgetCore *>(nwid)->GetIndex()] = std::distance(this->children.begin(), it);
} }
/* Now assign the widgets to their rightful place */ /* Now assign the widgets to their rightful place */

View File

@ -199,7 +199,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
_scroller_click_timeout = 3; _scroller_click_timeout = 3;
changed = sb->UpdatePosition(rtl ? 1 : -1); changed = sb->UpdatePosition(rtl ? 1 : -1);
} }
w->mouse_capture_widget = sb->index; w->mouse_capture_widget = sb->GetIndex();
} else if (pos >= ma - button_size) { } else if (pos >= ma - button_size) {
/* Pressing the lower button? */ /* Pressing the lower button? */
SetBit(sb->disp_flags, NDB_SCROLLBAR_DOWN); SetBit(sb->disp_flags, NDB_SCROLLBAR_DOWN);
@ -208,7 +208,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
_scroller_click_timeout = 3; _scroller_click_timeout = 3;
changed = sb->UpdatePosition(rtl ? -1 : 1); changed = sb->UpdatePosition(rtl ? -1 : 1);
} }
w->mouse_capture_widget = sb->index; w->mouse_capture_widget = sb->GetIndex();
} else { } else {
Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR); Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
@ -219,7 +219,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
} else { } else {
_scrollbar_start_pos = pt.x - mi - button_size; _scrollbar_start_pos = pt.x - mi - button_size;
_scrollbar_size = ma - mi - button_size * 2 - (pt.y - pt.x); _scrollbar_size = ma - mi - button_size * 2 - (pt.y - pt.x);
w->mouse_capture_widget = sb->index; w->mouse_capture_widget = sb->GetIndex();
_cursorpos_drag_start = _cursor.pos; _cursorpos_drag_start = _cursor.pos;
} }
} }
@ -268,7 +268,7 @@ void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
WidgetID GetWidgetFromPos(const Window *w, int x, int y) WidgetID GetWidgetFromPos(const Window *w, int x, int y)
{ {
NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y); NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
return (nw != nullptr) ? nw->index : -1; return (nw != nullptr) ? nw->GetIndex() : -1;
} }
/** /**
@ -1228,6 +1228,24 @@ StringID NWidgetCore::GetString() const
return this->widget_data.string; return this->widget_data.string;
} }
/**
* Get the \c WidgetID of this nested widget.
* @return The \c WidgetID.
*/
WidgetID NWidgetCore::GetIndex() const
{
return this->index;
}
/**
* Get the \c WidgetID of this nested widget's scrollbar.
* @return The \c WidgetID.
*/
WidgetID NWidgetCore::GetScrollbarIndex() const
{
return this->scrollbar_index;
}
void NWidgetCore::FillWidgetLookup(WidgetLookup &widget_lookup) void NWidgetCore::FillWidgetLookup(WidgetLookup &widget_lookup)
{ {
if (this->index >= 0) widget_lookup[this->index] = this; if (this->index >= 0) widget_lookup[this->index] = this;

View File

@ -384,6 +384,8 @@ public:
void SetAlignment(StringAlignment align); void SetAlignment(StringAlignment align);
StringID GetString() const; StringID GetString() const;
WidgetID GetIndex() const;
WidgetID GetScrollbarIndex() const;
inline void SetLowered(bool lowered); inline void SetLowered(bool lowered);
inline bool IsLowered() const; inline bool IsLowered() const;

View File

@ -365,7 +365,7 @@ void Window::UpdateQueryStringSize()
/* virtual */ const Textbuf *Window::GetFocusedTextbuf() const /* virtual */ const Textbuf *Window::GetFocusedTextbuf() const
{ {
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) { if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
return &this->GetQueryString(this->nested_focus->index)->text; return &this->GetQueryString(this->nested_focus->GetIndex())->text;
} }
return nullptr; return nullptr;
@ -378,7 +378,7 @@ void Window::UpdateQueryStringSize()
/* virtual */ Point Window::GetCaretPosition() const /* virtual */ Point Window::GetCaretPosition() const
{ {
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX && !this->querystrings.empty()) { if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX && !this->querystrings.empty()) {
return this->GetQueryString(this->nested_focus->index)->GetCaretPosition(this, this->nested_focus->index); return this->GetQueryString(this->nested_focus->GetIndex())->GetCaretPosition(this, this->nested_focus->GetIndex());
} }
Point pt = {0, 0}; Point pt = {0, 0};
@ -394,7 +394,7 @@ void Window::UpdateQueryStringSize()
/* virtual */ Rect Window::GetTextBoundingRect(const char *from, const char *to) const /* virtual */ Rect Window::GetTextBoundingRect(const char *from, const char *to) const
{ {
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) { if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
return this->GetQueryString(this->nested_focus->index)->GetBoundingRect(this, this->nested_focus->index, from, to); return this->GetQueryString(this->nested_focus->GetIndex())->GetBoundingRect(this, this->nested_focus->GetIndex(), from, to);
} }
Rect r = {0, 0, 0, 0}; Rect r = {0, 0, 0, 0};
@ -409,7 +409,7 @@ void Window::UpdateQueryStringSize()
/* virtual */ ptrdiff_t Window::GetTextCharacterAtPosition(const Point &pt) const /* virtual */ ptrdiff_t Window::GetTextCharacterAtPosition(const Point &pt) const
{ {
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) { if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
return this->GetQueryString(this->nested_focus->index)->GetCharAtPosition(this, this->nested_focus->index, pt); return this->GetQueryString(this->nested_focus->GetIndex())->GetCharAtPosition(this, this->nested_focus->GetIndex(), pt);
} }
return -1; return -1;
@ -626,7 +626,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
/* don't allow any interaction if the button has been disabled */ /* don't allow any interaction if the button has been disabled */
if (nw->IsDisabled()) return; if (nw->IsDisabled()) return;
WidgetID widget_index = nw->index; ///< Index of the widget WidgetID widget_index = nw->GetIndex(); ///< Index of the widget
/* Clicked on a widget that is not disabled. /* Clicked on a widget that is not disabled.
* So unless the clicked widget is the caption bar, change focus to this widget. * So unless the clicked widget is the caption bar, change focus to this widget.
@ -746,8 +746,8 @@ static void DispatchRightClickEvent(Window *w, int x, int y)
Point pt = { x, y }; Point pt = { x, y };
/* No widget to handle, or the window is not interested in it. */ /* No widget to handle, or the window is not interested in it. */
if (wid->index >= 0) { if (wid->GetIndex() >= 0) {
if (w->OnRightClick(pt, wid->index)) return; if (w->OnRightClick(pt, wid->GetIndex())) return;
} }
/* Right-click close is enabled and there is a closebox. */ /* Right-click close is enabled and there is a closebox. */
@ -756,7 +756,7 @@ static void DispatchRightClickEvent(Window *w, int x, int y)
} else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && (w->flags & WF_STICKY) == 0 && (w->window_desc.flags & WDF_NO_CLOSE) == 0) { } else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && (w->flags & WF_STICKY) == 0 && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
/* Right-click close is enabled, but excluding sticky windows. */ /* Right-click close is enabled, but excluding sticky windows. */
w->Close(); w->Close();
} else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->GetToolTip() != STR_NULL) { } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->GetIndex(), TCC_RIGHT_CLICK) && wid->GetToolTip() != STR_NULL) {
GuiShowTooltips(w, wid->GetToolTip(), TCC_RIGHT_CLICK); GuiShowTooltips(w, wid->GetToolTip(), TCC_RIGHT_CLICK);
} }
} }
@ -777,15 +777,15 @@ static void DispatchHoverEvent(Window *w, int x, int y)
Point pt = { x, y }; Point pt = { x, y };
/* Show the tooltip if there is any */ /* Show the tooltip if there is any */
if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->GetToolTip() != STR_NULL) { if (!w->OnTooltip(pt, wid->GetIndex(), TCC_HOVER) && wid->GetToolTip() != STR_NULL) {
GuiShowTooltips(w, wid->GetToolTip(), TCC_HOVER); GuiShowTooltips(w, wid->GetToolTip(), TCC_HOVER);
return; return;
} }
/* Widget has no index, so the window is not interested in it. */ /* Widget has no index, so the window is not interested in it. */
if (wid->index < 0) return; if (wid->GetIndex() < 0) return;
w->OnHover(pt, wid->index); w->OnHover(pt, wid->GetIndex());
} }
/** /**
@ -815,7 +815,7 @@ static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
} }
/* Scroll the widget attached to the scrollbar. */ /* Scroll the widget attached to the scrollbar. */
Scrollbar *sb = (nwid->scrollbar_index >= 0 ? w->GetScrollbar(nwid->scrollbar_index) : nullptr); Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr);
if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) { if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) {
if (sb->UpdatePosition(wheel)) w->SetDirty(); if (sb->UpdatePosition(wheel)) w->SetDirty();
} }
@ -1922,7 +1922,7 @@ static void HandleMouseOver()
/* send an event in client coordinates. */ /* send an event in client coordinates. */
Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top }; Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
const NWidgetCore *widget = w->nested_root->GetWidgetFromPos(pt.x, pt.y); const NWidgetCore *widget = w->nested_root->GetWidgetFromPos(pt.x, pt.y);
if (widget != nullptr) w->OnMouseOver(pt, widget->index); if (widget != nullptr) w->OnMouseOver(pt, widget->GetIndex());
} }
} }
@ -2592,7 +2592,7 @@ void HandleKeypress(uint keycode, char32_t key)
if (_focused_window->window_class == WC_CONSOLE) { if (_focused_window->window_class == WC_CONSOLE) {
if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return; if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
} else { } else {
if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return; if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->GetIndex(), key, keycode) == ES_HANDLED) return;
} }
} }
@ -2656,7 +2656,7 @@ void HandleTextInput(const char *str, bool marked, const char *caret, const char
{ {
if (!EditBoxInGlobalFocus()) return; if (!EditBoxInGlobalFocus()) return;
_focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->index, str, marked, caret, insert_location, replacement_end); _focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->GetIndex(), str, marked, caret, insert_location, replacement_end);
} }
/** /**

View File

@ -425,7 +425,7 @@ public:
*/ */
inline bool IsWidgetFocused(WidgetID widget_index) const inline bool IsWidgetFocused(WidgetID widget_index) const
{ {
return this->nested_focus != nullptr && this->nested_focus->index == widget_index; return this->nested_focus != nullptr && this->nested_focus->GetIndex() == widget_index;
} }
/** /**