# NewGRFWindow Struct Reference

Window for showing NewGRF files. More...

Inheritance diagram for NewGRFWindow:

## Public Types
typedef GUIList< const GRFConfig * > | GUIGRFConfigList
## Public Member Functions
| NewGRFWindow (const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list)
virtual void | UpdateWidgetSize (int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
| Update size and resize step of a widget in the window.
virtual void | OnResize ()
| Called after the window got resized.
virtual void | SetStringParameters (int widget) const
| Initialize string parameters for a widget.
virtual void | OnPaint ()
| The window must be repainted.
FORCEINLINE PaletteID | GetPalette (const GRFConfig *c) const
| Pick the palette for the sprite of the grf to display.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
virtual void | OnClick (Point pt, int widget, int click_count)
| A click with the left mouse button has been made on the window.
virtual void | OnDropdownSelect (int widget, int index)
| A dropdown option associated to this window has been selected.
virtual void | OnQueryTextFinished (char *str)
| The query window opened from this window has closed.
virtual void | OnInvalidateData (int data=0, bool gui_scope=true)
| Some data on this window has become invalid.
virtual void | OnMouseLoop ()
| Called for every mouse loop run, which is at least once per (game) tick.
virtual EventState | OnKeyPress (uint16 key, uint16 keycode)
| A key has been pressed.
virtual void | OnOSKInput (int wid)
## Data Fields
GUIGRFConfigList | avails
| Available (non-active) grfs.
const GRFConfig * | avail_sel
| Currently selected available grf. `NULL` is none is selected.
int | avail_pos
| Index of avail_sel if existing, else `-1`.
GRFConfig * | actives
| Temporary active grf list to which changes are made.
GRFConfig * | active_sel
| Selected active grf item.
GRFConfig ** | orig_list
| List active grfs in the game. Used as initial value, may be updated by the window.
bool | editable
| Is the window editable?
bool | show_params
| Are the grf-parameters shown in the info-panel?
bool | execute
| On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
int | preset
| Selected preset.
Scrollbar * | vscroll
Scrollbar * | vscroll2
## Static Public Attributes
static const uint | EDITBOX_MAX_SIZE = 50
static const uint | EDITBOX_MAX_LENGTH = 300
static Listing | last_sorting = {false, 0}
| Default sorting of GUIGRFConfigList.
static Filtering | last_filtering = {false, 0}
| Default filtering of GUIGRFConfigList.
static GUIGRFConfigList::SortFunction *const | sorter_funcs []
| Sort functions of the GUIGRFConfigList.
static GUIGRFConfigList::FilterFunction *const | filter_funcs []
| Filter functions of the GUIGRFConfigList.
## Private Member Functions
void | BuildAvailables ()
## Static Private Member Functions
static int CDECL | NameSorter (const GRFConfig *const *a, const GRFConfig *const *b)
| Sort grfs by name.
static bool CDECL | TagNameFilter (const GRFConfig *const *a, const char *filter_string)
| Filter grfs by tags/name.

## Detailed Description

Window for showing NewGRF files.

Definition at line 509 of file newgrf_gui.cpp.

## Member Function Documentation

virtual void NewGRFWindow::DrawWidget | ( | const Rect & | r,
|  | int | widget |
| ) |  |  | const`[inline, virtual]`

Draw the contents of a nested widget.

Parameters:

  | r | Rectangle occupied by the widget.
  | widget | Number of the widget to draw.

Note:
  This method may not change any state, it may only use drawing functions.

Reimplemented from Window.

Definition at line 695 of file newgrf_gui.cpp.

References _current_text_dir, active_sel, actives, avail_sel, avails, DrawSprite(), DrawString(), GRFConfig::error, FONT_HEIGHT_NORMAL, Scrollbar::GetCapacity(), GRFConfig::GetName(), GetPalette(), Scrollbar::GetPosition(), GfxFillRect(), Scrollbar::IsVisible(), SmallVector< T, S >::Length(), min(), GRFConfig::next, SA_HOR_CENTER, TD_RTL, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, and WD_FRAMERECT_TOP.

FORCEINLINE PaletteID NewGRFWindow::GetPalette | ( | const GRFConfig * | c | ) | const`[inline]`

Pick the palette for the sprite of the grf to display.

Parameters:

  | c | grf to display.

Returns:
  Palette for the sprite.

Definition at line 665 of file newgrf_gui.cpp.

References GRFConfig::flags, GCF_COMPATIBLE, GCF_STATIC, GCS_ACTIVATED, GCS_DISABLED, GCS_NOT_FOUND, HasBit(), and GRFConfig::status.

Referenced by DrawWidget().

static int CDECL NewGRFWindow::NameSorter | ( | const GRFConfig *const * | a,
|  | const GRFConfig *const * | b |
| ) |  |  | `[inline, static, private]`

Sort grfs by name.

Definition at line 1212 of file newgrf_gui.cpp.

References lengthof, and strnatcmp().

virtual void NewGRFWindow::OnClick | ( | Point | pt,
|  | int | widget,
|  | int | click_count |
| ) |  |  | `[inline, virtual]`

A click with the left mouse button has been made on the window.

Parameters:

  | pt | the point inside the window that has been clicked.
  | widget | the clicked widget.
  | click_count | Number of fast consecutive clicks at same position

Reimplemented from Window.

Definition at line 768 of file newgrf_gui.cpp.

References _network_available, active_sel, actives, SmallVector< T, S >::Append(), avail_pos, avail_sel, avails, BSWAP32(), CONTENT_TYPE_NEWGRF, CopyGRFConfigList(), CS_ALPHANUMERAL, Window::DeleteChildWindows(), DeleteGRFPresetFromConfig(), DeleteWindowByClass(), ContentInfo::DOES_NOT_EXIST, TarScanner::DoScan(), editable, execute, GRFConfig::flags, GUIList< T, F >::ForceRebuild(), GCF_COMPATIBLE, GCF_INVALID, GCS_NOT_FOUND, GetGRFPresetList(), GRFConfig::GetName(), Scrollbar::GetScrolledRowFromWidget(), GRFIdentifier::grfid, GRFP_USE_MASK, HasBit(), GRFConfig::ident, INVALID_STRING_ID, Window::InvalidateData(), InvalidateWindowClassesData(), SmallVector< T, S >::Length(), lengthof, GRFIdentifier::md5sum, ContentInfo::md5sum, ContentInfo::name, NewGRFConfirmationCallback(), GRFConfig::next, orig_list, GRFConfig::original_md5sum, GRFConfig::palette, preset, ReloadNewGRFData(), ResetGRFConfig(), ScanNewGRFFiles(), Scrollbar::ScrollTowards(), Window::SetDirty(), GRFConfig::SetParameterDefaults(), ShowDropDownList(), ShowErrorMessage(), ShowNetworkContentListWindow(), ShowQuery(), ShowQueryString(), ContentInfo::state, GRFConfig::status, ttd_strlcpy(), ContentInfo::type, ContentInfo::unique_id, WL_ERROR, and WL_INFO.

virtual void NewGRFWindow::OnDropdownSelect | ( | int | widget,
|  | int | index |
| ) |  |  | `[inline, virtual]`

A dropdown option associated to this window has been selected.

Parameters:

  | widget | the widget (button) that the dropdown is associated with.
  | index | the element in the dropdown that is selected.

Reimplemented from Window.

Definition at line 995 of file newgrf_gui.cpp.

References active_sel, actives, avails, ClearGRFConfigList(), DeleteWindowByClass(), editable, GUIList< T, F >::ForceRebuild(), Window::InvalidateData(), LoadGRFPresetFromConfig(), and preset.

virtual void NewGRFWindow::OnInvalidateData | ( | int | data = `0`,
|  | bool | gui_scope = `true` |
| ) |  |  | `[inline, virtual]`

Some data on this window has become invalid.

Parameters:

  | data | Information about the changed data. 0: (optionally) build availables, update button status. 1: build availables, Add newly found grfs, update button status. 2: (optionally) build availables, Reset preset, + 3 3: (optionally) build availables, Update active scrollbar, update button status. 4: Force a rebuild of the availables, + 2
  | gui_scope | Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See InvalidateWindowData() for details.

Reimplemented from Window.

Definition at line 1043 of file newgrf_gui.cpp.

References active_sel, actives, avail_pos, avail_sel, avails, Window::DisableWidget(), editable, FGCM_EXACT, FindGRFConfig(), GRFConfig::flags, GUIList< T, F >::ForceRebuild(), GCF_COMPATIBLE, GCF_INVALID, GCS_NOT_FOUND, GRFIdentifier::grfid, HasBit(), GRFConfig::ident, GRFConfig::IsOpenTTDBaseGRF(), GRFIdentifier::md5sum, GRFConfig::next, GRFConfig::original_md5sum, preset, Scrollbar::ScrollTowards(), Scrollbar::SetCapacityFromWidget(), Scrollbar::SetCount(), Window::SetWidgetDisabledState(), Window::SetWidgetsDisabledState(), GRFConfig::status, and WIDGET_LIST_END.

virtual EventState NewGRFWindow::OnKeyPress | ( | uint16 | key,
|  | uint16 | keycode |
| ) |  |  | `[inline, virtual]`

A key has been pressed.

Parameters:

  | key | the Unicode value of the key.
  | keycode | the untranslated key code including shift state.

Returns:
  ES_HANDLED if the key press has been handled and no other window should receive the event.

Reimplemented from Window.

Definition at line 1146 of file newgrf_gui.cpp.

References avail_pos, avail_sel, avails, editable, ES_HANDLED, ES_NOT_HANDLED, Scrollbar::GetCapacity(), Window::InvalidateData(), SmallVector< T, S >::Length(), min(), and Scrollbar::ScrollTowards().

virtual void NewGRFWindow::OnPaint | ( |  | ) | `[inline, virtual]`

The window must be repainted.

Note:
  This method should not change any state, it should only use drawing functions.

Reimplemented from Window.

Definition at line 654 of file newgrf_gui.cpp.

References Window::DrawWidgets(), and editable.

virtual void NewGRFWindow::OnQueryTextFinished | ( | char * | str | ) | `[inline, virtual]`

The query window opened from this window has closed.

Parameters:

  | str | the new value of the string, NULL if the window was cancelled or an empty string when the default button was pressed, i.e. StrEmpty(str).

Reimplemented from Window.

Definition at line 1015 of file newgrf_gui.cpp.

References actives, GetGRFPresetList(), Window::InvalidateData(), SmallVector< T, S >::Length(), preset, and SaveGRFPresetToConfig().

virtual void NewGRFWindow::OnResize | ( |  | ) | `[inline, virtual]`

Called after the window got resized.

For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.

Reimplemented from Window.

Definition at line 634 of file newgrf_gui.cpp.

References Scrollbar::SetCapacityFromWidget().

virtual void NewGRFWindow::SetStringParameters | ( | int | widget | ) | const`[inline, virtual]`

Initialize string parameters for a widget.

Calls to this function are made during initialization to measure the size (that is as part of InitNested()), during drawing, and while re-initializing the window. Only for widgets that render text initializing is requested.

Parameters:

  | widget | Widget number.

Reimplemented from Window.

Definition at line 640 of file newgrf_gui.cpp.

References preset, SetDParam(), and SetDParamStr().

virtual void NewGRFWindow::UpdateWidgetSize | ( | int | widget,
|  | Dimension * | size,
|  | const Dimension & | padding,
|  | Dimension * | fill,
|  | Dimension * | resize |
| ) |  |  | `[inline, virtual]`

Update size and resize step of a widget in the window.

After retrieval of the minimal size and the resize-steps of a widget, this function is called to allow further refinement, typically by computing the real maximal size of the content. Afterwards, size is taken to be the minimal size of the widget and resize is taken to contain the resize steps. For the convenience of the callee, padding contains the amount of padding between the content and the edge of the widget. This should be added to the returned size.

Parameters:

  | widget | Widget number.
  | size | Size of the widget.
  | padding | Recommended amount of space between the widget content and the widget edge.
  | fill | Fill step of the widget.
  | resize | Resize step of the widget.

Reimplemented from Window.

Definition at line 586 of file newgrf_gui.cpp.

References FONT_HEIGHT_NORMAL, GetStringBoundingBox(), SmallVector< T, S >::Length(), max(), maxdim(), SetDParamStr(), WD_FRAMERECT_BOTTOM, WD_FRAMERECT_TOP, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, and WD_FRAMETEXT_TOP.

## Field Documentation

NewGRFWindow::GUIGRFConfigList::FilterFunction *const NewGRFWindow::filter_funcs`[static]`

Initial value:

     {
      &TagNameFilter,
    }

Filter functions of the GUIGRFConfigList.

Definition at line 518 of file newgrf_gui.cpp.

NewGRFWindow::GUIGRFConfigList::SortFunction *const NewGRFWindow::sorter_funcs`[static]`

Initial value:

     {
      &NameSorter,
    }

Sort functions of the GUIGRFConfigList.

Definition at line 517 of file newgrf_gui.cpp.

The documentation for this struct was generated from the following file:

- src/newgrf_gui.cpp