Mercurial > hg > openttd
changeset 15777:b7e37b045c86 draft
(svn r20451) -Codechange: Add helper function Window::GetScrollbar() to get the Scrollbar belonging to a scrollbar widget.
author | frosch <frosch@openttd.org> |
---|---|
date | Thu, 12 Aug 2010 06:40:28 +0000 |
parents | dcbb01a539ea |
children | 4f4c3160cca8 |
files | src/window.cpp src/window_gui.h |
diffstat | 2 files changed, 35 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/window.cpp +++ b/src/window.cpp @@ -131,6 +131,39 @@ } /** + * Return the Scrollbar to a widget index. + * @param widnum Scrollbar widget index + * @return Scrollbar to the widget + */ +const Scrollbar *Window::GetScrollbar(uint widnum) const +{ + const NWidgetLeaf *wid = this->GetWidget<NWidgetLeaf>(widnum); + switch (wid->type) { + case WWT_HSCROLLBAR: return &this->hscroll; + case WWT_SCROLLBAR: return &this->vscroll; + case WWT_SCROLL2BAR: return &this->vscroll2; + default: NOT_REACHED(); + } +} + +/** + * Return the Scrollbar to a widget index. + * @param widnum Scrollbar widget index + * @return Scrollbar to the widget + */ +Scrollbar *Window::GetScrollbar(uint widnum) +{ + NWidgetLeaf *wid = this->GetWidget<NWidgetLeaf>(widnum); + switch (wid->type) { + case WWT_HSCROLLBAR: return &this->hscroll; + case WWT_SCROLLBAR: return &this->vscroll; + case WWT_SCROLL2BAR: return &this->vscroll2; + default: NOT_REACHED(); + } +} + + +/** * Set the window that has the focus * @param w The window to set the focus on */
--- a/src/window_gui.h +++ b/src/window_gui.h @@ -407,6 +407,8 @@ template <class NWID> inline NWID *GetWidget(uint widnum); + const Scrollbar *GetScrollbar(uint widnum) const; + Scrollbar *GetScrollbar(uint widnum); void InitNested(const WindowDesc *desc, WindowNumber number = 0); void CreateNestedTree(const WindowDesc *desc, bool fill_nested = true);