OpenTTD Source 20241224-master-gee860a5c8e
|
Scrollbar data structure. More...
#include <widget_type.h>
Public Types | |
enum | ScrollbarStepping { SS_RAW , SS_SMALL , SS_BIG } |
Stepping sizes when scrolling. More... | |
using | size_type = int32_t |
Public Member Functions | |
Scrollbar (bool is_vertical) | |
size_type | GetCount () const |
Gets the number of elements in the list. | |
size_type | GetCapacity () const |
Gets the number of visible elements of the scrollbar. | |
size_type | GetPosition () const |
Gets the position of the first visible element in the list. | |
bool | IsVisible (size_type item) const |
Checks whether given current item is visible in the list. | |
bool | IsVertical () const |
Is the scrollbar vertical or not? | |
void | SetStepSize (size_t stepsize) |
Set the distance to scroll when using the buttons or the wheel. | |
void | SetCount (size_t num) |
Sets the number of elements in the list. | |
void | SetCapacity (size_t capacity) |
Set the capacity of visible elements. | |
void | SetCapacityFromWidget (Window *w, WidgetID widget, int padding=0) |
Set capacity of visible elements from the size and resize properties of a widget. | |
bool | SetPosition (size_type position) |
Sets the position of the first visible element. | |
bool | UpdatePosition (int difference, ScrollbarStepping unit=SS_SMALL) |
Updates the position of the first visible element by the given amount. | |
void | ScrollTowards (size_type position) |
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown either at the bottom or top of the window depending on where in the list it was. | |
size_type | GetScrolledRowFromWidget (int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const |
Compute the row of a scrolled widget that a user clicked in. | |
template<typename Tcontainer > | |
auto | GetVisibleRangeIterators (Tcontainer &container) const |
Get a pair of iterators for the range of visible elements in a container. | |
template<typename Tcontainer > | |
auto | GetScrolledItemFromWidget (Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const |
Return an iterator pointing to the element of a scrolled widget that a user clicked in. | |
EventState | UpdateListPositionOnKeyPress (int &list_position, uint16_t keycode) const |
Update the given list position as if it were on this scroll bar when the given keycode was pressed. | |
Static Public Attributes | |
static constexpr size_type | max_size_type = std::numeric_limits<size_type>::max() |
static constexpr size_type | npos = max_size_type |
Private Attributes | |
const bool | is_vertical |
Scrollbar has vertical orientation. | |
size_type | count |
Number of elements in the list. | |
size_type | cap |
Number of visible elements of the scroll bar. | |
size_type | pos |
Index of first visible item of the list. | |
size_type | stepsize |
Distance to scroll, when pressing the buttons or using the wheel. | |
Scrollbar data structure.
Definition at line 694 of file widget_type.h.
using Scrollbar::size_type = int32_t |
Definition at line 696 of file widget_type.h.
Stepping sizes when scrolling.
Enumerator | |
---|---|
SS_RAW | Step in single units. |
SS_SMALL | Step in stepsize units. |
SS_BIG | Step in cap units. |
Definition at line 708 of file widget_type.h.
|
inline |
Definition at line 714 of file widget_type.h.
|
inline |
Gets the number of visible elements of the scrollbar.
Definition at line 731 of file widget_type.h.
References cap.
Referenced by DispatchMouseWheelEvent(), NetworkClientListWindow::DrawCompany(), GoalListWindow::DrawListColumn(), NewGRFInspectWindow::DrawString(), IndustryProductionGraphWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), GetVisibleRangeIterators(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), StationViewWindow::OnPaint(), ScrollTowards(), UpdateListPositionOnKeyPress(), and ScriptDebugWindow::UpdateLogScroll().
|
inline |
Gets the number of elements in the list.
Definition at line 722 of file widget_type.h.
References count.
Referenced by DispatchMouseWheelEvent(), SelectCompanyLiveryWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), SignListWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), IndustryDirectoryWindow::GetIndustryListWidth(), GetScrolledItemFromWidget(), GetScrolledRowFromWidget(), GetVisibleRangeIterators(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IndustryProductionGraphWindow::OnClick(), NewGRFParametersWindow::OnClick(), NewGRFParametersWindow::OnInvalidateData(), ScriptListWindow::OnInvalidateData(), NewGRFWindow::OnMouseDrag(), GameSettingsWindow::OnPaint(), StoryBookWindow::OnPaint(), ScrollRect(), IndustryDirectoryWindow::SetStringParameters(), NewGRFParametersWindow::SetStringParameters(), SignListWindow::SetStringParameters(), CompanyStationsWindow::SetStringParameters(), TownDirectoryWindow::SetStringParameters(), UpdateListPositionOnKeyPress(), and ScriptDebugWindow::UpdateLogScroll().
|
inline |
Gets the position of the first visible element in the list.
Definition at line 740 of file widget_type.h.
References pos.
Referenced by IndustryCargoesWindow::CalculatePositionInWidget(), ScriptDebugWindow::ChangeToScript(), TextfileWindow::CheckHyperlinkClick(), TimetableWindow::DrawArrivalDeparturePanel(), NetworkClientListWindow::DrawCompany(), FramerateWindow::DrawElementTimesColumn(), GoalListWindow::DrawListColumn(), NewGRFInspectWindow::DrawString(), TimetableWindow::DrawTimetablePanel(), DepotWindow::DrawVehicleInDepot(), AIConfigWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), DepotWindow::DrawWidget(), DropdownWindow::DrawWidget(), FramerateWindow::DrawWidget(), IndustryProductionGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), OrdersWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), StoryBookWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TextfileWindow::DrawWidget(), RefitWindow::DrawWidget(), DropdownWindow::GetDropDownItem(), GetScrolledRowFromWidget(), NWidgetMatrix::GetScrollOffsets(), GetVisibleRangeIterators(), HandleScrollbarHittest(), IsVisible(), StationViewWindow::OnPaint(), ScrollRect(), ScrollTowards(), NWidgetMatrix::SetClicked(), TextfileWindow::UpdateHistoryScrollpos(), and ScriptDebugWindow::UpdateLogScroll().
|
inline |
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
container | Container of elements represented by the scrollbar. |
clickpos | Vertical position of the mouse click (without taking scrolling into account). |
w | The window the click was in. |
widget | Widget number of the widget clicked in. |
padding | Amount of empty space between the widget edge and the top of the first row. Default value is 0 . |
line_height | Height of a single row. A negative value means using the vertical resize step of the widget. |
Definition at line 879 of file widget_type.h.
References GetCount(), and GetScrolledRowFromWidget().
Referenced by ReplaceVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), BuildVehicleWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), SaveLoadWindow::OnClick(), GSConfigWindow::OnClick(), PaymentRatesGraphWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildIndustryWindow::OnClick(), IndustryDirectoryWindow::OnClick(), NetworkContentListWindow::OnClick(), NetworkGameWindow::OnClick(), SpriteAlignerWindow::OnClick(), NewGRFWindow::OnClick(), SavePresetWindow::OnClick(), MessageHistoryWindow::OnClick(), ScriptSettingsWindow::OnClick(), SignListWindow::OnClick(), CompanyStationsWindow::OnClick(), SelectStationWindow< T >::OnClick(), TownDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), VehicleGroupWindow::OnMouseDrag(), SaveLoadWindow::OnMouseOver(), and SelectStationWindow< T >::OnMouseOver().
Scrollbar::size_type Scrollbar::GetScrolledRowFromWidget | ( | int | clickpos, |
const Window *const | w, | ||
WidgetID | widget, | ||
int | padding = 0 , |
||
int | line_height = -1 |
||
) | const |
Compute the row of a scrolled widget that a user clicked in.
clickpos | Vertical position of the mouse click (without taking scrolling into account). |
w | The window the click was in. |
widget | Widget number of the widget clicked in. |
padding | Amount of empty space between the widget edge and the top of the first row. Default value is 0 . |
line_height | Height of a single row. A negative value means using the vertical resize step of the widget. |
Definition at line 2377 of file widget.cpp.
References GetCount(), GetPosition(), Window::GetRowFromWidget(), and pos.
Referenced by NetworkClientListWindow::GetButtonAtPoint(), OrdersWindow::GetOrderFromPt(), GetScrolledItemFromWidget(), AIConfigWindow::OnClick(), BuildAirportWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), FramerateWindow::OnClick(), GoalListWindow::OnClick(), IndustryProductionGraphWindow::OnClick(), NewGRFInspectWindow::OnClick(), NewGRFParametersWindow::OnClick(), NewGRFWindow::OnClick(), ScriptListWindow::OnClick(), GameSettingsWindow::OnClick(), StationViewWindow::OnClick(), StoryBookWindow::OnClick(), SubsidyListWindow::OnClick(), RefitWindow::OnClick(), NewGRFWindow::OnDragDrop(), NewGRFWindow::OnMouseDrag(), and NetworkClientListWindow::OnTooltip().
|
inline |
Get a pair of iterators for the range of visible elements in a container.
container | Container of elements represented by the scrollbar. |
Definition at line 860 of file widget_type.h.
References GetCapacity(), GetCount(), and GetPosition().
Referenced by DrawEngineList(), NetworkContentListWindow::DrawMatrix(), BaseVehicleListWindow::DrawVehicleListItems(), BuildAirportWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), GSConfigWindow::DrawWidget(), PaymentRatesGraphWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SavePresetWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), SignListWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), TownDirectoryWindow::DrawWidget(), ScriptDebugWindow::DrawWidgetLog(), and IndustryDirectoryWindow::GetIndustryListWidth().
|
inline |
Is the scrollbar vertical or not?
Definition at line 759 of file widget_type.h.
References is_vertical.
Referenced by NWidgetMatrix::GetScrollOffsets(), ScrollRect(), SetCapacityFromWidget(), and NWidgetMatrix::SetCount().
|
inline |
Checks whether given current item is visible in the list.
item | to check |
Definition at line 750 of file widget_type.h.
References GetCapacity(), GetPosition(), and IsInsideBS().
Referenced by TimetableWindow::DrawArrivalDeparturePanel(), TimetableWindow::DrawTimetablePanel(), AIConfigWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), OrdersWindow::DrawWidget(), ScriptListWindow::DrawWidget(), and OrdersWindow::OnInvalidateData().
|
inline |
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown either at the bottom or top of the window depending on where in the list it was.
position | the position to scroll towards. |
Definition at line 841 of file widget_type.h.
References GetCapacity(), GetPosition(), and SetPosition().
Referenced by ReplaceVehicleWindow::GenerateLists(), AIConfigWindow::OnClick(), NewGRFWindow::OnClick(), NewGRFWindow::OnDragDrop(), OrdersWindow::OnInvalidateData(), NewGRFWindow::OnKeyPress(), RefitWindow::RefreshScrollbar(), NetworkContentListWindow::ScrollToSelected(), NetworkGameWindow::ScrollToSelectedServer(), VehicleGroupWindow::SelectGroup(), NWidgetMatrix::SetClicked(), and NewGRFWindow::UpdateScrollBars().
|
inline |
Set the capacity of visible elements.
capacity | the new capacity |
Definition at line 794 of file widget_type.h.
References SetPosition().
Referenced by DepotWindow::OnResize(), FramerateWindow::OnResize(), SetCapacityFromWidget(), NWidgetMatrix::SetCount(), and DropdownWindow::UpdateSizeAndPosition().
Set capacity of visible elements from the size and resize properties of a widget.
w | Window. |
widget | Widget with size and resize properties. |
padding | Padding to subtract from the size. |
Definition at line 2451 of file widget.cpp.
References NWidgetBase::current_x, NWidgetBase::current_y, Window::GetWidget(), IsVertical(), NWidgetBase::resize_x, NWidgetBase::resize_y, and SetCapacity().
Referenced by ReplaceVehicleWindow::OnResize(), BuildBridgeWindow::OnResize(), BuildVehicleWindow::OnResize(), SelectCompanyLiveryWindow::OnResize(), DepotWindow::OnResize(), SaveLoadWindow::OnResize(), GSConfigWindow::OnResize(), GoalListWindow::OnResize(), PaymentRatesGraphWindow::OnResize(), IndustryProductionGraphWindow::OnResize(), VehicleGroupWindow::OnResize(), BuildIndustryWindow::OnResize(), IndustryDirectoryWindow::OnResize(), IndustryCargoesWindow::OnResize(), NetworkContentListWindow::OnResize(), NetworkGameWindow::OnResize(), NetworkClientListWindow::OnResize(), NewGRFInspectWindow::OnResize(), SpriteAlignerWindow::OnResize(), NewGRFParametersWindow::OnResize(), NewGRFWindow::OnResize(), SavePresetWindow::OnResize(), MessageHistoryWindow::OnResize(), OrdersWindow::OnResize(), PickerWindow::OnResize(), ScriptListWindow::OnResize(), ScriptSettingsWindow::OnResize(), ScriptDebugWindow::OnResize(), GameSettingsWindow::OnResize(), SignListWindow::OnResize(), CompanyStationsWindow::OnResize(), StationViewWindow::OnResize(), SelectStationWindow< T >::OnResize(), StoryBookWindow::OnResize(), SubsidyListWindow::OnResize(), TextfileWindow::OnResize(), TimetableWindow::OnResize(), TownDirectoryWindow::OnResize(), RefitWindow::OnResize(), VehicleListWindow::OnResize(), and VehicleDetailsWindow::OnResize().
|
inline |
Sets the number of elements in the list.
num | the number of elements in the list |
Definition at line 780 of file widget_type.h.
References SetPosition().
Referenced by NetworkContentListWindow::BuildContentList(), NetworkGameWindow::BuildGUINetworkGameList(), PickerWindow::BuildPickerClassList(), IndustryDirectoryWindow::BuildSortIndustriesList(), CompanyStationsWindow::BuildStationsList(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), NewGRFInspectWindow::DrawMainPanelWidget(), ReplaceVehicleWindow::GenerateLists(), MessageHistoryWindow::OnClick(), BuildAirportWindow::OnDropdownSelect(), IndustryDirectoryWindow::OnInit(), GoalListWindow::OnInvalidateData(), SpriteAlignerWindow::OnInvalidateData(), NewGRFParametersWindow::OnInvalidateData(), MessageHistoryWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), ScriptListWindow::OnInvalidateData(), ScriptDebugWindow::OnInvalidateData(), GameSettingsWindow::OnInvalidateData(), SelectStationWindow< T >::OnInvalidateData(), SubsidyListWindow::OnInvalidateData(), BuildVehicleWindow::OnPaint(), DepotWindow::OnPaint(), VehicleGroupWindow::OnPaint(), IndustryDirectoryWindow::OnPaint(), GameSettingsWindow::OnPaint(), StationViewWindow::OnPaint(), StoryBookWindow::OnPaint(), TimetableWindow::OnPaint(), RefitWindow::OnPaint(), VehicleDetailsWindow::OnPaint(), StoryBookWindow::OnResize(), NetworkClientListWindow::RebuildList(), GSConfigWindow::RebuildVisibleSettings(), ScriptSettingsWindow::RebuildVisibleSettings(), RefitWindow::RefreshScrollbar(), StoryBookWindow::RefreshSelectedPage(), SavePresetWindow::SavePresetWindow(), ScriptListWindow::ScriptListWindow(), BuildAirportWindow::SelectFirstAvailableAirport(), VehicleGroupWindow::SelectGroup(), NWidgetMatrix::SetCount(), TextfileWindow::SetupScrollbars(), ScriptDebugWindow::UpdateLogScroll(), NewGRFWindow::UpdateScrollBars(), DropdownWindow::UpdateSizeAndPosition(), and IndustryProductionGraphWindow::UpdateStatistics().
|
inline |
Sets the position of the first visible element.
position | the position of the element |
Definition at line 810 of file widget_type.h.
Referenced by HandleScrollbarScrolling(), TextfileWindow::NavigateHistory(), TextfileWindow::NavigateToFile(), ReplaceVehicleWindow::OnRailRoadTypeChange(), ScrollTowards(), SetCapacity(), SetCount(), ScriptDebugWindow::UpdateLogScroll(), and UpdatePosition().
|
inline |
Set the distance to scroll when using the buttons or the wheel.
stepsize | Scrolling speed. |
Definition at line 768 of file widget_type.h.
References stepsize.
Referenced by ScriptDebugWindow::ScriptDebugWindow(), and NWidgetMatrix::SetCount().
EventState Scrollbar::UpdateListPositionOnKeyPress | ( | int & | list_position, |
uint16_t | keycode | ||
) | const |
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
This does not update the actual position of this scroll bar, that is left to the caller. It does, however use the capacity and count of the scroll bar for the bounds and amount to scroll.
When the count is 0 or the return is ES_NOT_HANDLED, then the position is not updated. With WKC_UP and WKC_DOWN the position goes one up or down respectively. With WKC_PAGEUP and WKC_PAGEDOWN the position goes one capacity up or down respectively. With WKC_HOME the first position is selected and with WKC_END the last position is selected. This function ensures that pos is in the range [0..count).
list_position | The current position in the list. |
key_code | The pressed key code. |
Definition at line 2398 of file widget.cpp.
References Clamp(), ES_HANDLED, ES_NOT_HANDLED, GetCapacity(), and GetCount().
Referenced by NetworkContentListWindow::OnKeyPress(), NetworkGameWindow::OnKeyPress(), and NewGRFWindow::OnKeyPress().
|
inline |
Updates the position of the first visible element by the given amount.
If the position would be too low or high it will be clamped appropriately
difference | the amount of change requested |
unit | The stepping unit of difference |
Definition at line 824 of file widget_type.h.
References cap, SetPosition(), SS_BIG, SS_SMALL, and stepsize.
Referenced by DispatchMouseWheelEvent(), HandleScrollbarScrolling(), ScrollbarClickPositioning(), and DropdownWindow::UpdateSizeAndPosition().
|
private |
Number of visible elements of the scroll bar.
Definition at line 702 of file widget_type.h.
Referenced by GetCapacity(), and UpdatePosition().
|
private |
Number of elements in the list.
Definition at line 701 of file widget_type.h.
Referenced by GetCount().
|
private |
Scrollbar has vertical orientation.
Definition at line 700 of file widget_type.h.
Referenced by IsVertical().
|
staticconstexpr |
Definition at line 697 of file widget_type.h.
|
staticconstexpr |
Definition at line 698 of file widget_type.h.
|
private |
Index of first visible item of the list.
Definition at line 703 of file widget_type.h.
Referenced by GetPosition(), GetScrolledRowFromWidget(), and SetPosition().
|
private |
Distance to scroll, when pressing the buttons or using the wheel.
Definition at line 704 of file widget_type.h.
Referenced by SetStepSize(), and UpdatePosition().