# NWidgetViewport Class Reference
[Hierarchical widgets]

Nested widget to display a viewport in a window. More...

`#include <widget_type.h>`

Inheritance diagram for NWidgetViewport:

## Public Member Functions

| NWidgetViewport (int index)
void | SetupSmallestSize (Window *w, bool init_array)
| Compute smallest size needed by the widget.
void | Draw (const Window *w)
| Draw the widgets of the tree.
Scrollbar * | FindScrollbar (Window *w, bool allow_next=true) const
| Find the scrollbar of the widget through the Window::nested_array.
void | InitializeViewport (Window *w, uint32 follow_flags, ZoomLevel zoom)
| Initialize the viewport of the window.
void | UpdateViewportCoordinates (Window *w)
| Update the position and size of the viewport (after eg a resize).

## Detailed Description

Nested widget to display a viewport in a window.

After initializing the nested widget tree, call InitializeViewport(). After changing the window size, call UpdateViewportCoordinates() eg from Window::OnResize(). If the display_flags field contains the ND_NO_TRANSPARENCY bit, the viewport will disable transparency. Shading to grey-scale is controlled with the ND_SHADE_GREY bit (used for B&W news papers), the ND_SHADE_DIMMED gives dimmed colours (for colour news papers).

Todo:
  Class derives from NWidgetCore, but does not use colour, widget_data, or tool_tip.

Definition at line 456 of file widget_type.h.

## Member Function Documentation

void NWidgetViewport::Draw | ( | const Window * | w | ) | `[virtual]`

Draw the widgets of the tree.

The function calls Window::DrawWidget for each widget with a non-negative index, after the widget itself is painted.

Parameters:

  | w | Window that owns the tree.

Implements NWidgetBase.

Definition at line 1637 of file widget.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, NWidgetCore::disp_flags, Window::DrawViewport(), FILLRECT_RECOLOUR, GfxFillRect(), ND_NO_TRANSPARENCY, ND_SHADE_DIMMED, ND_SHADE_GREY, NWidgetBase::pos_x, and NWidgetBase::pos_y.

Scrollbar * NWidgetViewport::FindScrollbar | ( | Window * | w,
|  | bool | allow_next = `true` |
| ) |  |  | const`[virtual]`

Find the scrollbar of the widget through the Window::nested_array.

Parameters:

  | w | Window containing the widgets and the scrollbar,
  | allow_next | Search may be extended to the next widget.

Todo:
  This implementation uses the constraint that a scrollbar must be the next item in the Window::nested_array, and the scrollbar data is stored in the Window structure (Window::vscroll, Window::vscroll2, and Window::hscroll). Alternative light-weight implementations may be considered, eg by sub-classing a canvas-like widget, and/or by having an explicit link between the scrollbar and the widget being scrolled.

Implements NWidgetCore.

Definition at line 1655 of file widget.cpp.

void NWidgetViewport::InitializeViewport | ( | Window * | w,
|  | uint32 | follow_flags,
|  | ZoomLevel | zoom |
| ) |  |  |

Initialize the viewport of the window.

Parameters:

  | w | Window owning the viewport.
  | follow_flags | Type of viewport, see InitializeViewport().
  | zoom | Zoom level.

Definition at line 1666 of file widget.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, InitializeWindowViewport(), NWidgetBase::pos_x, and NWidgetBase::pos_y.

void NWidgetViewport::SetupSmallestSize | ( | Window * | w,
|  | bool | init_array |
| ) |  |  | `[virtual]`

Compute smallest size needed by the widget.

The smallest size of a widget is the smallest size that a widget needs to display itself properly. In addition, filling and resizing of the widget are computed. The function calls Window::UpdateWidgetSize for each leaf widget and background widget without child with a non-negative index.

Parameters:

  | w | Window owning the widget.
  | init_array | Initialize the `w->nested_array`.

Note:
  After the computation, the results can be queried by accessing the smallest_x and smallest_y data members of the widget.

Implements NWidgetBase.

Definition at line 1627 of file widget.cpp.

References NWidgetCore::index, NWidgetResizeBase::min_x, NWidgetResizeBase::min_y, Window::nested_array, Window::nested_array_size, NWidgetBase::smallest_x, and NWidgetBase::smallest_y.

void NWidgetViewport::UpdateViewportCoordinates | ( | Window * | w | ) |

Update the position and size of the viewport (after eg a resize).

Parameters:

  | w | Window owning the viewport.

Definition at line 1675 of file widget.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, ViewPort::height, Window::left, ViewPort::left, NWidgetBase::pos_x, NWidgetBase::pos_y, ScaleByZoom(), Window::top, ViewPort::top, Window::viewport, ViewPort::virtual_height, ViewPort::virtual_width, and ViewPort::width.

Referenced by WaypointWindow::OnResize(), ExtraViewportWindow::OnResize(), VehicleViewWindow::OnResize(), TownViewWindow::OnResize(), MainWindow::OnResize(), and IndustryViewWindow::OnResize().

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

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