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. | |
uint16 | GetCapacity () const |
Gets the number of visible elements of the scrollbar. | |
uint16 | GetPosition () const |
Gets the position of the first visible element in the list. | |
bool | IsVisible (uint16 item) const |
Checks whether given current item is visible in the list. | |
bool | IsVertical () const |
Is the scrollbar vertical or not? | |
void | SetStepSize (uint16 stepsize) |
Set the distance to scroll when using the buttons or the wheel. | |
void | SetCount (int num) |
Sets the number of elements in the list. | |
void | SetCapacity (int capacity) |
Set the capacity of visible elements. | |
void | SetCapacityFromWidget (Window *w, int widget, int padding=0) |
Set capacity of visible elements from the size and resize properties of a widget. | |
void | SetPosition (int position) |
Sets the position of the first visible element. | |
void | UpdatePosition (int difference, ScrollbarStepping unit=SS_SMALL) |
Updates the position of the first visible element by the given amount. | |
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. | |
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. | |
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 587 of file widget_type.h.
Stepping sizes when scrolling.
Definition at line 597 of file widget_type.h.
uint16 Scrollbar::GetCapacity | ( | ) | const [inline] |
Gets the number of visible elements of the scrollbar.
Definition at line 620 of file widget_type.h.
References cap.
Referenced by DispatchMouseWheelEvent(), NetworkContentListWindow::DrawMatrix(), BaseVehicleListWindow::DrawVehicleListItems(), VehicleDetailsWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), GameSettingsWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), GoalListWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), OrdersWindow::GetOrderFromPt(), NWidgetMatrix::GetScrollOffsets(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), StationViewWindow::OnPaint(), VehicleDetailsWindow::OnResize(), VehicleListWindow::OnResize(), RefitWindow::OnResize(), BuildRailStationWindow::OnResize(), BuildObjectWindow::OnResize(), NewGRFParametersWindow::OnResize(), SpriteAlignerWindow::OnResize(), NetworkLobbyWindow::OnResize(), BuildIndustryWindow::OnResize(), VehicleGroupWindow::OnResize(), DepotWindow::OnResize(), BuildVehicleWindow::OnResize(), BuildBridgeWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::OnResize(), ScrollTowards(), BuildObjectWindow::UpdateWidgetSize(), and BuildAirportWindow::UpdateWidgetSize().
uint16 Scrollbar::GetCount | ( | ) | const [inline] |
Gets the number of elements in the list.
Definition at line 611 of file widget_type.h.
References count.
Referenced by DispatchMouseWheelEvent(), NewGRFParametersWindow::DrawWidget(), GetScrolledRowFromWidget(), HandleScrollbarHittest(), HandleScrollbarScrolling(), NewGRFParametersWindow::OnClick(), BuildAirportWindow::OnClick(), NewGRFParametersWindow::OnInvalidateData(), AIListWindow::OnInvalidateData(), VehicleListWindow::SetStringParameters(), and NewGRFParametersWindow::SetStringParameters().
uint16 Scrollbar::GetPosition | ( | ) | const [inline] |
Gets the position of the first visible element in the list.
Definition at line 629 of file widget_type.h.
References pos.
Referenced by IndustryCargoesWindow::CalculatePositionInWidget(), AIDebugWindow::ChangeToAI(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), DropdownWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TimetableWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), GameSettingsWindow::DrawWidget(), OrdersWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), GoalListWindow::DrawWidget(), DepotWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIConfigWindow::DrawWidget(), DropdownWindow::GetDropDownItem(), OrdersWindow::GetOrderFromPt(), GetScrolledRowFromWidget(), NWidgetMatrix::GetScrollOffsets(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), TownAuthorityWindow::OnClick(), StationViewWindow::OnClick(), BuildObjectWindow::OnClick(), SpriteAlignerWindow::OnClick(), BuildAirportWindow::OnClick(), AISettingsWindow::OnClick(), StationViewWindow::OnPaint(), DropdownWindow::OnTick(), 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 1884 of file widget.cpp.
References GetCount(), GetPosition(), Window::GetRowFromWidget(), and pos.
Referenced by VehicleListWindow::OnClick(), RefitWindow::OnClick(), TownDirectoryWindow::OnClick(), SubsidyListWindow::OnClick(), SelectStationWindow< T >::OnClick(), StationViewWindow::OnClick(), GameSettingsWindow::OnClick(), BuildRailStationWindow::OnClick(), MessageHistoryWindow::OnClick(), NewGRFParametersWindow::OnClick(), NetworkLobbyWindow::OnClick(), IndustryDirectoryWindow::OnClick(), BuildIndustryWindow::OnClick(), VehicleGroupWindow::OnClick(), GoalListWindow::OnClick(), BuildVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), AIConfigWindow::OnClick(), AIListWindow::OnClick(), VehicleGroupWindow::OnDragDrop(), and VehicleGroupWindow::OnMouseDrag().
bool Scrollbar::IsVertical | ( | ) | const [inline] |
Is the scrollbar vertical or not?
Definition at line 648 of file widget_type.h.
References is_vertical.
Referenced by NWidgetMatrix::GetScrollOffsets(), SetCapacityFromWidget(), and NWidgetMatrix::SetCount().
bool Scrollbar::IsVisible | ( | uint16 | item | ) | const [inline] |
Checks whether given current item is visible in the list.
item | to check |
Definition at line 639 of file widget_type.h.
References GetCapacity(), GetPosition(), and IsInsideBS().
Referenced by TimetableWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIListWindow::DrawWidget(), and OrdersWindow::OnInvalidateData().
void Scrollbar::ScrollTowards | ( | int | position | ) | [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 729 of file widget_type.h.
References GetCapacity(), GetPosition(), and SetPosition().
Referenced by AIConfigWindow::OnClick(), RefitWindow::OnInit(), OrdersWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), NetworkContentListWindow::ScrollToSelected(), NetworkGameWindow::ScrollToSelectedServer(), and NWidgetMatrix::SetClicked().
void Scrollbar::SetCapacity | ( | int | capacity | ) | [inline] |
Set the capacity of visible elements.
capacity | the new capacity |
Definition at line 684 of file widget_type.h.
References cap, count, max(), MAX_UVALUE, and pos.
Referenced by DropdownWindow::DropdownWindow(), MessageHistoryWindow::OnResize(), NewGRFParametersWindow::OnResize(), VehicleGroupWindow::OnResize(), DepotWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::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 1898 of file widget.cpp.
References NWidgetBase::current_x, NWidgetBase::current_y, Window::GetWidget(), IsVertical(), NWidgetBase::resize_x, NWidgetBase::resize_y, and SetCapacity().
Referenced by NewGRFWindow::OnInvalidateData(), VehicleDetailsWindow::OnResize(), VehicleListWindow::OnResize(), RefitWindow::OnResize(), TownDirectoryWindow::OnResize(), TimetableWindow::OnResize(), SubsidyListWindow::OnResize(), SelectStationWindow< T >::OnResize(), StationViewWindow::OnResize(), GameSettingsWindow::OnResize(), BuildRailStationWindow::OnResize(), OrdersWindow::OnResize(), BuildObjectWindow::OnResize(), SpriteAlignerWindow::OnResize(), NetworkLobbyWindow::OnResize(), IndustryCargoesWindow::OnResize(), IndustryDirectoryWindow::OnResize(), BuildIndustryWindow::OnResize(), VehicleGroupWindow::OnResize(), GoalListWindow::OnResize(), DepotWindow::OnResize(), BuildVehicleWindow::OnResize(), and BuildBridgeWindow::OnResize().
void Scrollbar::SetCount | ( | int | num | ) | [inline] |
Sets the number of elements in the list.
num | the number of elements in the list |
Definition at line 668 of file widget_type.h.
References cap, count, MAX_UVALUE, and pos.
Referenced by AIListWindow::AIListWindow(), AISettingsWindow::AISettingsWindow(), NetworkContentListWindow::BuildContentList(), NetworkGameWindow::BuildNetworkGameList(), RefitWindow::BuildRefitList(), IndustryDirectoryWindow::BuildSortIndustriesList(), CompanyStationsWindow::BuildStationsList(), AIDebugWindow::ChangeToAI(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), DropdownWindow::DropdownWindow(), ReplaceVehicleWindow::GenerateLists(), TextfileWindow::LoadTextfile(), GameSettingsWindow::OnClick(), BuildAirportWindow::OnDropdownSelect(), SubsidyListWindow::OnInvalidateData(), SelectStationWindow< T >::OnInvalidateData(), OrdersWindow::OnInvalidateData(), MessageHistoryWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), NewGRFParametersWindow::OnInvalidateData(), SpriteAlignerWindow::OnInvalidateData(), GoalListWindow::OnInvalidateData(), AIListWindow::OnInvalidateData(), VehicleDetailsWindow::OnPaint(), RefitWindow::OnPaint(), TownAuthorityWindow::OnPaint(), TimetableWindow::OnPaint(), StationViewWindow::OnPaint(), NetworkLobbyWindow::OnPaint(), VehicleGroupWindow::OnPaint(), DepotWindow::OnPaint(), BuildVehicleWindow::OnPaint(), and NWidgetMatrix::SetCount().
void Scrollbar::SetPosition | ( | int | position | ) | [inline] |
Sets the position of the first visible element.
position | the position of the element |
Definition at line 699 of file widget_type.h.
References cap, count, and pos.
Referenced by HandleScrollbarScrolling(), ScrollTowards(), and UpdatePosition().
void Scrollbar::SetStepSize | ( | uint16 | stepsize | ) | [inline] |
Set the distance to scroll when using the buttons or the wheel.
stepsize | Scrolling speed. |
Definition at line 657 of file widget_type.h.
Referenced by TextfileWindow::LoadTextfile(), and NWidgetMatrix::SetCount().
void Scrollbar::UpdatePosition | ( | int | difference, | |
ScrollbarStepping | unit = SS_SMALL | |||
) | [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 712 of file widget_type.h.
References cap, Clamp(), count, max(), pos, SetPosition(), SS_BIG, SS_SMALL, and stepsize.
Referenced by DispatchMouseWheelEvent(), HandleScrollbarScrolling(), DropdownWindow::OnTick(), and ScrollbarClickPositioning().