OpenTTD: Scrollbar Class Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

Public Types | Public Member Functions | Private Attributes
Scrollbar Class Reference

Scrollbar data structure. More...

`#include <widget_type.h>`

Inheritance diagram for Scrollbar:

## 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.

## Detailed Description

Scrollbar data structure.

Definition at line 589 of file widget_type.h.

## Member Enumeration Documentation

enum Scrollbar::ScrollbarStepping

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 599 of file widget_type.h.

## Member Function Documentation

uint16 Scrollbar::GetCapacity | ( |  | ) | const
| inline

Gets the number of visible elements of the scrollbar.

Returns
  the number of visible elements

Definition at line 622 of file widget_type.h.

References cap.

Referenced by DispatchMouseWheelEvent(), GoalListWindow::DrawListColumn(), NetworkContentListWindow::DrawMatrix(), BaseVehicleListWindow::DrawVehicleListItems(), SubsidyListWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), SavePresetWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), OrdersWindow::GetOrderFromPt(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), NetworkGameWindow::OnKeyPress(), NewGRFWindow::OnKeyPress(), AIDebugWindow::OnPaint(), StationViewWindow::OnPaint(), and ScrollTowards().

uint16 Scrollbar::GetCount | ( |  | ) | const
| inline

Gets the number of elements in the list.

Returns
  the number of elements

Definition at line 613 of file widget_type.h.

References count.

Referenced by DispatchMouseWheelEvent(), SignListWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), GetScrolledRowFromWidget(), HandleScrollbarHittest(), HandleScrollbarScrolling(), NewGRFParametersWindow::OnClick(), BuildAirportWindow::OnClick(), NewGRFWindow::OnDragDrop(), AIListWindow::OnInvalidateData(), NewGRFParametersWindow::OnInvalidateData(), NewGRFWindow::OnMouseDrag(), StoryBookWindow::OnPaint(), AIDebugWindow::OnPaint(), GameSettingsWindow::OnPaint(), SignListWindow::SetStringParameters(), NewGRFParametersWindow::SetStringParameters(), and VehicleListWindow::SetStringParameters().

uint16 Scrollbar::GetPosition | ( |  | ) | const
| inline

Gets the position of the first visible element in the list.

Returns
  the position of the element

Definition at line 631 of file widget_type.h.

References pos.

Referenced by IndustryCargoesWindow::CalculatePositionInWidget(), AIDebugWindow::ChangeToAI(), GoalListWindow::DrawListColumn(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), TextfileWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), SignListWindow::DrawWidget(), DropdownWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), DepotWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), TimetableWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), StoryBookWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), AIConfigWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), OrdersWindow::DrawWidget(), AIDebugWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), SavePresetWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), IndustryCargoesWindow::DrawWidget(), DropdownWindow::GetDropDownItem(), OrdersWindow::GetOrderFromPt(), GetScrolledRowFromWidget(), NWidgetMatrix::GetScrollOffsets(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), TownAuthorityWindow::OnClick(), BuildObjectWindow::OnClick(), AISettingsWindow::OnClick(), BuildAirportWindow::OnClick(), SpriteAlignerWindow::OnClick(), StationViewWindow::OnClick(), AIDebugWindow::OnPaint(), 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.

Parameters

  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.

Returns
  Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.

Definition at line 1958 of file widget.cpp.

References GetCount(), GetPosition(), Window::GetRowFromWidget(), and pos.

Referenced by SubsidyListWindow::OnClick(), GoalListWindow::OnClick(), AIListWindow::OnClick(), SignListWindow::OnClick(), BuildBridgeWindow::OnClick(), NewGRFParametersWindow::OnClick(), BuildIndustryWindow::OnClick(), VehicleGroupWindow::OnClick(), StoryBookWindow::OnClick(), NetworkGameWindow::OnClick(), AIConfigWindow::OnClick(), TownDirectoryWindow::OnClick(), RefitWindow::OnClick(), NewGRFWindow::OnClick(), MessageHistoryWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildVehicleWindow::OnClick(), IndustryDirectoryWindow::OnClick(), NetworkLobbyWindow::OnClick(), VehicleListWindow::OnClick(), StationViewWindow::OnClick(), GameSettingsWindow::OnClick(), SavePresetWindow::OnClick(), SelectStationWindow< T >::OnClick(), NewGRFWindow::OnDragDrop(), VehicleGroupWindow::OnMouseDrag(), and NewGRFWindow::OnMouseDrag().

bool Scrollbar::IsVertical | ( |  | ) | const
| inline

Is the scrollbar vertical or not?

Returns
  True iff the scrollbar is vertical.

Definition at line 650 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.

Parameters

  item | to check

Returns
  true iff the item is visible

Definition at line 641 of file widget_type.h.

References GetCapacity(), GetPosition(), and IsInsideBS().

Referenced by AIListWindow::DrawWidget(), SignListWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), TimetableWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIConfigWindow::DrawWidget(), NewGRFWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), AIDebugWindow::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.

Parameters

  position | the position to scroll towards.

Definition at line 731 of file widget_type.h.

References GetCapacity(), GetPosition(), and SetPosition().

Referenced by BuildObjectWindow::EnsureSelectedObjectClassIsVisible(), ReplaceVehicleWindow::GenerateLists(), AIConfigWindow::OnClick(), NewGRFWindow::OnClick(), NewGRFWindow::OnDragDrop(), OrdersWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), NewGRFWindow::OnKeyPress(), RefitWindow::RefreshScrollbar(), NetworkContentListWindow::ScrollToSelected(), NetworkGameWindow::ScrollToSelectedServer(), and NWidgetMatrix::SetClicked().

void Scrollbar::SetCapacity | ( | int | capacity | ) |
| inline

Set the capacity of visible elements.

Parameters

  capacity | the new capacity

Note
  updates the position if needed

Definition at line 686 of file widget_type.h.

References cap, count, max(), MAX_UVALUE, and pos.

Referenced by DropdownWindow::DropdownWindow(), 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.

Parameters

  w | Window.
  widget | Widget with size and resize properties.
  padding | Padding to subtract from the size.

Note
  Updates the position if needed.

Definition at line 1972 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(), BuildBridgeWindow::OnResize(), GoalListWindow::OnResize(), BuildObjectWindow::OnResize(), NewGRFParametersWindow::OnResize(), BuildIndustryWindow::OnResize(), AISettingsWindow::OnResize(), StoryBookWindow::OnResize(), TimetableWindow::OnResize(), VehicleGroupWindow::OnResize(), NewGRFWindow::OnResize(), NetworkGameWindow::OnResize(), TownDirectoryWindow::OnResize(), DepotWindow::OnResize(), RefitWindow::OnResize(), SpriteAlignerWindow::OnResize(), MessageHistoryWindow::OnResize(), BuildRailStationWindow::OnResize(), IndustryDirectoryWindow::OnResize(), AIDebugWindow::OnResize(), BuildVehicleWindow::OnResize(), OrdersWindow::OnResize(), NetworkLobbyWindow::OnResize(), VehicleListWindow::OnResize(), StationViewWindow::OnResize(), SavePresetWindow::OnResize(), VehicleDetailsWindow::OnResize(), GameSettingsWindow::OnResize(), SelectStationWindow< T >::OnResize(), and IndustryCargoesWindow::OnResize().

void Scrollbar::SetCount | ( | int | num | ) |
| inline

Sets the number of elements in the list.

Parameters

  num | the number of elements in the list

Note
  updates the position if needed

Definition at line 670 of file widget_type.h.

References cap, count, MAX_UVALUE, and pos.

Referenced by AIListWindow::AIListWindow(), AISettingsWindow::AISettingsWindow(), NetworkContentListWindow::BuildContentList(), NetworkGameWindow::BuildGUINetworkGameList(), IndustryDirectoryWindow::BuildSortIndustriesList(), CompanyStationsWindow::BuildStationsList(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), DropdownWindow::DropdownWindow(), ReplaceVehicleWindow::GenerateLists(), BuildAirportWindow::OnDropdownSelect(), SubsidyListWindow::OnInvalidateData(), AIListWindow::OnInvalidateData(), GoalListWindow::OnInvalidateData(), NewGRFParametersWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), SpriteAlignerWindow::OnInvalidateData(), MessageHistoryWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), AIDebugWindow::OnInvalidateData(), GameSettingsWindow::OnInvalidateData(), SelectStationWindow< T >::OnInvalidateData(), TownAuthorityWindow::OnPaint(), TimetableWindow::OnPaint(), VehicleGroupWindow::OnPaint(), StoryBookWindow::OnPaint(), RefitWindow::OnPaint(), DepotWindow::OnPaint(), AIDebugWindow::OnPaint(), StationViewWindow::OnPaint(), NetworkLobbyWindow::OnPaint(), BuildVehicleWindow::OnPaint(), GameSettingsWindow::OnPaint(), VehicleDetailsWindow::OnPaint(), StoryBookWindow::OnResize(), RefitWindow::RefreshScrollbar(), StoryBookWindow::RefreshSelectedPage(), SavePresetWindow::SavePresetWindow(), NWidgetMatrix::SetCount(), and TextfileWindow::SetupScrollbars().

void Scrollbar::SetPosition | ( | int | position | ) |
| inline

Sets the position of the first visible element.

Parameters

  position | the position of the element

Definition at line 701 of file widget_type.h.

References cap, count, and pos.

Referenced by HandleScrollbarScrolling(), AIDebugWindow::OnPaint(), ScrollTowards(), and UpdatePosition().

void Scrollbar::SetStepSize | ( | uint16 | stepsize | ) |
| inline

Set the distance to scroll when using the buttons or the wheel.

Parameters

  stepsize | Scrolling speed.

Definition at line 659 of file widget_type.h.

References stepsize.

Referenced by 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

Parameters

  difference | the amount of change requested
  unit | The stepping unit of difference

Definition at line 714 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().

The documentation for this class was generated from the following files:

- src/widget_type.h
- src/widget.cpp