# widget.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "core/math_func.hpp"`
`#include "player_func.h"`
`#include "gfx_func.h"`
`#include "window_gui.h"`
`#include "window_func.h"`
`#include "widgets/dropdown_func.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Functions
static Point | HandleScrollbarHittest (const Scrollbar *sb, int top, int bottom)
void | ScrollbarClickHandler (Window *w, const Widget *wi, int x, int y)
| Special handling for the scrollbar widget type.
int | GetWidgetFromPos (const Window *w, int x, int y)
| Returns the index for the widget located at the given position relative to the window.
void | DrawFrameRect (int left, int top, int right, int bottom, int ctab, FrameFlags flags)
void | DrawWindowWidgets (const Window *w)
static void | ResizeWidgets (Window *w, byte a, byte b)
static void | ResizeWidgets (Window *w, byte a, byte b, byte c)
void | ResizeButtons (Window *w, byte left, byte right)
| Evenly distribute some widgets when resizing horizontally (often a button row) When only two arguments are given, the widgets are presumed to be on a line and only the ends are given.
void | ResizeWindowForWidget (Window *w, int widget, int delta_x, int delta_y)
| Resize a widget an shuffle other widgets around to fit.
void | DrawSortButtonState (const Window *w, int widget, SortButtonState state)
| Draw a sort button's up or down arrow symbol.
## Variables
static const char * | UPARROW = "\xEE\x8A\xA0"
static const char * | DOWNARROW = "\xEE\x8A\xAA"

## Detailed Description

Definition in file widget.cpp.

## Function Documentation

void DrawSortButtonState | ( | const Window * | w,
|  | int | widget,
|  | SortButtonState | state |
| ) |  |  |

Draw a sort button's up or down arrow symbol.

Parameters:

  | w | Window of widget
  | widget | Sort button widget
  | state | State of sort button

Definition at line 609 of file widget.cpp.

References DoDrawString().

Referenced by GroupWndProc().

int GetWidgetFromPos | ( | const Window * | w,
|  | int | x,
|  | int | y |
| ) |  |  |

Returns the index for the widget located at the given position relative to the window.

It includes all widget-corner pixels as well.

Parameters:

  | *w | Window to look inside
  | x | The Window client X coordinate
  | y | The Window client y coordinate

Returns:
  A widget index, or -1 if no widget was found.

Definition at line 136 of file widget.cpp.

References WWT_FRAME.

void ResizeButtons | ( | Window * | w,
|  | byte | left,
|  | byte | right |
| ) |  |  |

Evenly distribute some widgets when resizing horizontally (often a button row) When only two arguments are given, the widgets are presumed to be on a line and only the ends are given.

Evenly distribute some widgets when resizing horizontally (often a button row) The widgets are presumed to be in a line and numberef from left to right (without gaps).

Parameters:

  | w | Window to modify
  | left | The leftmost widget to resize
  | right | The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT

Definition at line 546 of file widget.cpp.

References ResizeButtons().

Referenced by ResizeButtons(), StationViewWndProc(), and VehicleDetailsWndProc().

void ScrollbarClickHandler | ( | Window * | w,
|  | const Widget * | wi,
|  | int | x,
|  | int | y |
| ) |  |  |

Special handling for the scrollbar widget type.

Handles the special scrolling buttons and other scrolling.

Parameters:

  | w | Window on which a scroll was performed.
  | wi | Pointer to the scrollbar widget.
  | x | The X coordinate of the mouse click.
  | y | The Y coordinate of the mouse click.

Definition at line 51 of file widget.cpp.

References max(), min(), SetWindowDirty(), and WWT_SCROLL2BAR.