Scrollbar Class Reference

Scrollbar data structure. More...

#include <widget_type.h>

Inheritance diagram for Scrollbar:
NWidgetScrollbar

Public Types

enum  ScrollbarStepping { SS_RAW, SS_SMALL, SS_BIG }
 

Stepping sizes when scrolling.

More...

Public Member Functions

 Scrollbar (bool is_vertical)
FORCEINLINE uint16 GetCount () const
 Gets the number of elements in the list.
FORCEINLINE uint16 GetCapacity () const
 Gets the number of visible elements of the scrollbar.
FORCEINLINE uint16 GetPosition () const
 Gets the position of the first visible element in the list.
FORCEINLINE bool IsVisible (uint16 item) const
 Checks whether given current item is visible in the list.
FORCEINLINE 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 553 of file widget_type.h.


Member Enumeration Documentation

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


Member Function Documentation

FORCEINLINE uint16 Scrollbar::GetCapacity (  )  const [inline]

Gets the number of visible elements of the scrollbar.

Returns:
the number of visible elements

Definition at line 586 of file widget_type.h.

References cap.

Referenced by DispatchMouseWheelEvent(), BaseVehicleListWindow::DrawVehicleListItems(), StationViewWindow::DrawWaitingCargo(), VehicleDetailsWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), GameSettingsWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), OrdersWindow::GetOrderFromPt(), NWidgetMatrix::GetScrollOffsets(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), NewGRFWindow::OnKeyPress(), NetworkGameWindow::OnKeyPress(), NetworkContentListWindow::OnKeyPress(), AIDebugWindow::OnPaint(), VehicleDetailsWindow::OnResize(), VehicleListWindow::OnResize(), RefitWindow::OnResize(), BuildRailStationWindow::OnResize(), BuildObjectWindow::OnResize(), NewGRFParametersWindow::OnResize(), SpriteAlignerWindow::OnResize(), NetworkLobbyWindow::OnResize(), NetworkGameWindow::OnResize(), NetworkContentListWindow::OnResize(), BuildIndustryWindow::OnResize(), VehicleGroupWindow::OnResize(), DepotWindow::OnResize(), BuildVehicleWindow::OnResize(), BuildBridgeWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::OnResize(), ScrollTowards(), BuildObjectWindow::UpdateWidgetSize(), and BuildAirportWindow::UpdateWidgetSize().

FORCEINLINE uint16 Scrollbar::GetCount (  )  const [inline]
FORCEINLINE 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 595 of file widget_type.h.

References pos.

Referenced by IndustryCargoesWindow::CalculatePositionInWidget(), DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), StationViewWindow::DrawWaitingCargo(), DropdownWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TimetableWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), SignListWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), OrdersWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), NewGRFWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), SpriteAlignerWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), IndustryCargoesWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), DepotWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), BuildAirportWindow::DrawWidget(), AIDebugWindow::DrawWidget(), AIConfigWindow::DrawWidget(), DropdownWindow::GetDropDownItem(), OrdersWindow::GetOrderFromPt(), GetScrolledRowFromWidget(), NWidgetMatrix::GetScrollOffsets(), HandleScrollbarHittest(), HandleScrollbarScrolling(), IsVisible(), TownAuthorityWindow::OnClick(), BuildObjectWindow::OnClick(), SpriteAlignerWindow::OnClick(), BuildAirportWindow::OnClick(), AISettingsWindow::OnClick(), AIDebugWindow::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).
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 1841 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(), SignListWindow::OnClick(), GameSettingsWindow::OnClick(), BuildRailStationWindow::OnClick(), MessageHistoryWindow::OnClick(), NewGRFWindow::OnClick(), NewGRFParametersWindow::OnClick(), NetworkLobbyWindow::OnClick(), NetworkGameWindow::OnClick(), NetworkContentListWindow::OnClick(), IndustryDirectoryWindow::OnClick(), BuildIndustryWindow::OnClick(), VehicleGroupWindow::OnClick(), SaveLoadWindow::OnClick(), BuildVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), AIConfigWindow::OnClick(), AIListWindow::OnClick(), and VehicleGroupWindow::OnDragDrop().

FORCEINLINE bool Scrollbar::IsVertical (  )  const [inline]

Is the scrollbar vertical or not?

Returns:
True iff the scrollbar is vertical.

Definition at line 614 of file widget_type.h.

References is_vertical.

Referenced by NWidgetMatrix::GetScrollOffsets(), SetCapacityFromWidget(), and NWidgetMatrix::SetCount().

FORCEINLINE bool Scrollbar::IsVisible ( uint16  item  )  const [inline]
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 695 of file widget_type.h.

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

Referenced by NewGRFWindow::OnClick(), AIConfigWindow::OnClick(), RefitWindow::OnInit(), OrdersWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), NewGRFWindow::OnKeyPress(), 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 650 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 
)
void Scrollbar::SetCount ( int  num  )  [inline]
void Scrollbar::SetPosition ( int  position  )  [inline]

Sets the position of the first visible element.

Parameters:
position the position of the element

Definition at line 665 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 623 of file widget_type.h.

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 678 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:

Generated on Fri Mar 18 23:19:00 2011 for OpenTTD by  doxygen 1.6.1