OpenTTD Source
1.11.2
|
Scrollbar data structure. More...
#include <widget_type.h>
Public Types | |
enum | ScrollbarStepping { SS_RAW, SS_SMALL, SS_BIG } |
Stepping sizes when scrolling. More... | |
Public Member Functions | |
Scrollbar (bool is_vertical) | |
uint16 | GetCount () const |
Gets the number of elements in the list. More... | |
uint16 | GetCapacity () const |
Gets the number of visible elements of the scrollbar. More... | |
uint16 | GetPosition () const |
Gets the position of the first visible element in the list. More... | |
bool | IsVisible (uint16 item) const |
Checks whether given current item is visible in the list. More... | |
bool | IsVertical () const |
Is the scrollbar vertical or not? More... | |
void | SetStepSize (uint16 stepsize) |
Set the distance to scroll when using the buttons or the wheel. More... | |
void | SetCount (int num) |
Sets the number of elements in the list. More... | |
void | SetCapacity (int capacity) |
Set the capacity of visible elements. More... | |
void | SetCapacityFromWidget (Window *w, int widget, int padding=0) |
Set capacity of visible elements from the size and resize properties of a widget. More... | |
void | SetPosition (int position) |
Sets the position of the first visible element. More... | |
void | UpdatePosition (int difference, ScrollbarStepping unit=SS_SMALL) |
Updates the position of the first visible element by the given amount. More... | |
void | ScrollTowards (int 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. More... | |
int | GetScrolledRowFromWidget (int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const |
Compute the row of a scrolled widget that a user clicked in. More... | |
Private Attributes | |
const bool | is_vertical |
Scrollbar has vertical orientation. | |
uint16 | count |
Number of elements in the list. | |
uint16 | cap |
Number of visible elements of the scroll bar. | |
uint16 | pos |
Index of first visible item of the list. | |
uint16 | stepsize |
Distance to scroll, when pressing the buttons or using the wheel. | |
Scrollbar data structure.
Definition at line 598 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 608 of file widget_type.h.
|
inline |
Gets the number of visible elements of the scrollbar.
Definition at line 631 of file widget_type.h.
References cap.
Referenced by DispatchMouseWheelEvent(), BuildIndustryWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), HandleScrollbarHittest(), IsVisible(), AIDebugWindow::OnPaint(), and ScrollTowards().
|
inline |
Gets the number of elements in the list.
Definition at line 622 of file widget_type.h.
References count.
Referenced by DispatchMouseWheelEvent(), GetScrolledRowFromWidget(), HandleScrollbarHittest(), NewGRFParametersWindow::OnClick(), BuildAirportWindow::OnClick(), NewGRFParametersWindow::OnInvalidateData(), NewGRFWindow::OnMouseDrag(), StoryBookWindow::OnPaint(), AIDebugWindow::OnPaint(), SignListWindow::SetStringParameters(), NewGRFParametersWindow::SetStringParameters(), and CompanyStationsWindow::SetStringParameters().
|
inline |
Gets the position of the first visible element in the list.
Definition at line 640 of file widget_type.h.
References pos.
Referenced by IndustryCargoesWindow::CalculatePositionInWidget(), AIDebugWindow::ChangeToAI(), DepotWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), GetScrolledRowFromWidget(), NWidgetMatrix::GetScrollOffsets(), HandleScrollbarHittest(), IsVisible(), AISettingsWindow::OnClick(), BuildAirportWindow::OnClick(), BuildObjectWindow::OnClick(), AIDebugWindow::OnPaint(), DropdownWindow::OnRealtimeTick(), ScrollTowards(), and NWidgetMatrix::SetClicked().
int Scrollbar::GetScrolledRowFromWidget | ( | int | clickpos, |
const Window *const | w, | ||
int | 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 1972 of file widget.cpp.
References GetCount(), GetPosition(), Window::GetRowFromWidget(), and pos.
Referenced by AIListWindow::OnClick(), SignListWindow::OnClick(), BuildBridgeWindow::OnClick(), NewGRFParametersWindow::OnClick(), CompanyStationsWindow::OnClick(), NewGRFInspectWindow::OnClick(), StoryBookWindow::OnClick(), TownDirectoryWindow::OnClick(), MessageHistoryWindow::OnClick(), BuildVehicleWindow::OnClick(), IndustryDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), StationViewWindow::OnClick(), GameSettingsWindow::OnClick(), SavePresetWindow::OnClick(), NewGRFWindow::OnDragDrop(), VehicleGroupWindow::OnMouseDrag(), and NewGRFWindow::OnMouseDrag().
|
inline |
Is the scrollbar vertical or not?
Definition at line 659 of file widget_type.h.
References is_vertical.
Referenced by NWidgetMatrix::GetScrollOffsets(), SetCapacityFromWidget(), and NWidgetMatrix::SetCount().
|
inline |
Checks whether given current item is visible in the list.
item | to check |
Definition at line 650 of file widget_type.h.
References GetCapacity(), GetPosition(), and IsInsideBS().
Referenced by AISettingsWindow::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 740 of file widget_type.h.
References GetCapacity(), GetPosition(), and SetPosition().
Referenced by BuildObjectWindow::EnsureSelectedObjectClassIsVisible(), BuildRailStationWindow::EnsureSelectedStationClassIsVisible(), ReplaceVehicleWindow::GenerateLists(), NewGRFWindow::OnDragDrop(), OrdersWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), RefitWindow::RefreshScrollbar(), NetworkContentListWindow::ScrollToSelected(), VehicleGroupWindow::SelectGroup(), and NWidgetMatrix::SetClicked().
|
inline |
Set the capacity of visible elements.
capacity | the new capacity |
Definition at line 695 of file widget_type.h.
References MAX_UVALUE.
Referenced by DepotWindow::OnResize(), SetCapacityFromWidget(), and NWidgetMatrix::SetCount().
void Scrollbar::SetCapacityFromWidget | ( | Window * | w, |
int | widget, | ||
int | padding = 0 |
||
) |
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 1986 of file widget.cpp.
References NWidgetBase::current_x, NWidgetBase::current_y, Window::GetWidget(), IsVertical(), NWidgetBase::resize_x, NWidgetBase::resize_y, and SetCapacity().
Referenced by TextfileWindow::OnResize(), SubsidyListWindow::OnResize(), AIListWindow::OnResize(), SignListWindow::OnResize(), GoalListWindow::OnResize(), BuildBridgeWindow::OnResize(), NewGRFParametersWindow::OnResize(), BuildObjectWindow::OnResize(), AISettingsWindow::OnResize(), NewGRFInspectWindow::OnResize(), ReplaceVehicleWindow::OnResize(), TimetableWindow::OnResize(), CompanyStationsWindow::OnResize(), BuildIndustryWindow::OnResize(), NewGRFWindow::OnResize(), SaveLoadWindow::OnResize(), StoryBookWindow::OnResize(), NetworkGameWindow::OnResize(), VehicleGroupWindow::OnResize(), TownDirectoryWindow::OnResize(), NetworkContentListWindow::OnResize(), SelectCompanyLiveryWindow::OnResize(), PaymentRatesGraphWindow::OnResize(), SpriteAlignerWindow::OnResize(), DepotWindow::OnResize(), RefitWindow::OnResize(), MessageHistoryWindow::OnResize(), BuildRailStationWindow::OnResize(), AIDebugWindow::OnResize(), OrdersWindow::OnResize(), NetworkLobbyWindow::OnResize(), BuildVehicleWindow::OnResize(), IndustryDirectoryWindow::OnResize(), VehicleListWindow::OnResize(), StationViewWindow::OnResize(), SavePresetWindow::OnResize(), SelectStationWindow< T >::OnResize(), GameSettingsWindow::OnResize(), VehicleDetailsWindow::OnResize(), and IndustryCargoesWindow::OnResize().
|
inline |
Sets the number of elements in the list.
num | the number of elements in the list |
Definition at line 679 of file widget_type.h.
References cap, MAX_UVALUE, and pos.
Referenced by AIListWindow::AIListWindow(), NetworkContentListWindow::BuildContentList(), NetworkGameWindow::BuildGUINetworkGameList(), BuildObjectWindow::BuildObjectClassesAvailable(), IndustryDirectoryWindow::BuildSortIndustriesList(), BuildRailStationWindow::BuildStationClassesAvailable(), CompanyStationsWindow::BuildStationsList(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), BuildRailStationWindow::EnsureSelectedStationClassIsVisible(), ReplaceVehicleWindow::GenerateLists(), BuildAirportWindow::OnDropdownSelect(), SubsidyListWindow::OnInvalidateData(), GoalListWindow::OnInvalidateData(), NewGRFParametersWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), SpriteAlignerWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), MessageHistoryWindow::OnInvalidateData(), AIDebugWindow::OnInvalidateData(), GameSettingsWindow::OnInvalidateData(), SelectStationWindow< T >::OnInvalidateData(), TownAuthorityWindow::OnPaint(), TimetableWindow::OnPaint(), VehicleGroupWindow::OnPaint(), StoryBookWindow::OnPaint(), RefitWindow::OnPaint(), AIDebugWindow::OnPaint(), NetworkLobbyWindow::OnPaint(), StationViewWindow::OnPaint(), BuildVehicleWindow::OnPaint(), VehicleDetailsWindow::OnPaint(), StoryBookWindow::OnResize(), AISettingsWindow::RebuildVisibleSettings(), RefitWindow::RefreshScrollbar(), SavePresetWindow::SavePresetWindow(), VehicleGroupWindow::SelectGroup(), NWidgetMatrix::SetCount(), and TextfileWindow::SetupScrollbars().
|
inline |
Sets the position of the first visible element.
position | the position of the element |
Definition at line 710 of file widget_type.h.
Referenced by AIDebugWindow::OnPaint(), ScrollTowards(), and UpdatePosition().
|
inline |
Set the distance to scroll when using the buttons or the wheel.
stepsize | Scrolling speed. |
Definition at line 668 of file widget_type.h.
References stepsize.
Referenced by NWidgetMatrix::SetCount().
|
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 723 of file widget_type.h.
References cap, Clamp(), SetPosition(), SS_BIG, SS_SMALL, and stepsize.
Referenced by DispatchMouseWheelEvent(), and DropdownWindow::OnRealtimeTick().