Merge commit '73bed054b87399484e39f6972d30f91a404daba8'

This commit is contained in:
2024-04-03 19:37:54 +01:00
1355 changed files with 153174 additions and 81531 deletions

View File

@@ -24,6 +24,7 @@ add_files(
goal_widget.h
graph_widget.h
group_widget.h
help_widget.h
highscore_widget.h
industry_widget.h
intro_widget.h
@@ -44,6 +45,7 @@ add_files(
rail_widget.h
road_widget.h
screenshot_widget.h
script_widget.h
settings_widget.h
sign_widget.h
slider.cpp

View File

@@ -10,61 +10,26 @@
#ifndef WIDGETS_AI_WIDGET_H
#define WIDGETS_AI_WIDGET_H
#include "../company_type.h"
#include "../textfile_type.h"
/** Widgets of the #AIListWindow class. */
enum AIListWidgets {
WID_AIL_CAPTION, ///< Caption of the window.
WID_AIL_LIST, ///< The matrix with all available AIs.
WID_AIL_SCROLLBAR, ///< Scrollbar next to the AI list.
WID_AIL_INFO_BG, ///< Panel to draw some AI information on.
WID_AIL_ACCEPT, ///< Accept button.
WID_AIL_CANCEL, ///< Cancel button.
};
/** Widgets of the #AISettingsWindow class. */
enum AISettingsWidgets {
WID_AIS_CAPTION, ///< Caption of the window.
WID_AIS_BACKGROUND, ///< Panel to draw the settings on.
WID_AIS_SCROLLBAR, ///< Scrollbar to scroll through all settings.
WID_AIS_ACCEPT, ///< Accept button.
WID_AIS_RESET, ///< Reset button.
};
/** Widgets of the #AIConfigWindow class. */
enum AIConfigWidgets {
enum AIConfigWidgets : WidgetID {
WID_AIC_BACKGROUND, ///< Window background.
WID_AIC_DECREASE, ///< Decrease the number of AIs.
WID_AIC_INCREASE, ///< Increase the number of AIs.
WID_AIC_DECREASE_NUMBER, ///< Decrease the number of AIs.
WID_AIC_INCREASE_NUMBER, ///< Increase the number of AIs.
WID_AIC_NUMBER, ///< Number of AIs.
WID_AIC_DECREASE_INTERVAL,///< Decrease the interval.
WID_AIC_INCREASE_INTERVAL,///< Increase the interval.
WID_AIC_INTERVAL, ///< Interval between time AIs start.
WID_AIC_LIST, ///< List with currently selected AIs.
WID_AIC_SCROLLBAR, ///< Scrollbar to scroll through the selected AIs.
WID_AIC_MOVE_UP, ///< Move up button.
WID_AIC_MOVE_DOWN, ///< Move down button.
WID_AIC_CHANGE, ///< Select another AI button.
WID_AIC_CONFIGURE, ///< Change AI settings button.
WID_AIC_CLOSE, ///< Close window button.
WID_AIC_OPEN_URL, ///< Open AI URL.
WID_AIC_TEXTFILE, ///< Open AI readme, changelog (+1) or license (+2).
WID_AIC_CONTENT_DOWNLOAD = WID_AIC_TEXTFILE + TFT_END, ///< Download content button.
};
/** Widgets of the #AIDebugWindow class. */
enum AIDebugWidgets {
WID_AID_VIEW, ///< The row of company buttons.
WID_AID_NAME_TEXT, ///< Name of the current selected.
WID_AID_SETTINGS, ///< Settings button.
WID_AID_SCRIPT_GAME, ///< Game Script button.
WID_AID_RELOAD_TOGGLE, ///< Reload button.
WID_AID_LOG_PANEL, ///< Panel where the log is in.
WID_AID_SCROLLBAR, ///< Scrollbar of the log panel.
WID_AID_COMPANY_BUTTON_START, ///< Buttons in the VIEW.
WID_AID_COMPANY_BUTTON_END = WID_AID_COMPANY_BUTTON_START + MAX_COMPANIES - 1, ///< Last possible button in the VIEW.
WID_AID_BREAK_STRING_WIDGETS, ///< The panel to handle the breaking on string.
WID_AID_BREAK_STR_ON_OFF_BTN, ///< Enable breaking on string.
WID_AID_BREAK_STR_EDIT_BOX, ///< Edit box for the string to break on.
WID_AID_MATCH_CASE_BTN, ///< Checkbox to use match caching or not.
WID_AID_CONTINUE_BTN, ///< Continue button.
WID_AIC_CONTENT_DOWNLOAD = WID_AIC_TEXTFILE + TFT_CONTENT_END, ///< Download content button.
};
#endif /* WIDGETS_AI_WIDGET_H */

View File

@@ -11,13 +11,15 @@
#define WIDGETS_AIRPORT_WIDGET_H
/** Widgets of the #BuildAirToolbarWindow class. */
enum AirportToolbarWidgets {
enum AirportToolbarWidgets : WidgetID {
WID_AT_AIRPORT, ///< Build airport button.
WID_AT_DEMOLISH, ///< Demolish button.
INVALID_WID_AT = -1,
};
/** Widgets of the #BuildAirportWindow class. */
enum AirportPickerWidgets {
enum AirportPickerWidgets : WidgetID {
WID_AP_CLASS_DROPDOWN, ///< Dropdown of airport classes.
WID_AP_AIRPORT_LIST, ///< List of airports.
WID_AP_SCROLLBAR, ///< Scrollbar of the list.
@@ -26,7 +28,6 @@ enum AirportPickerWidgets {
WID_AP_LAYOUT_INCREASE, ///< Increase the layout number.
WID_AP_AIRPORT_SPRITE, ///< A visual display of the airport currently selected.
WID_AP_EXTRA_TEXT, ///< Additional text about the airport.
WID_AP_BOTTOMPANEL, ///< Panel at the bottom.
WID_AP_COVERAGE_LABEL, ///< Label if you want to see the coverage.
WID_AP_BTN_DONTHILIGHT, ///< Don't show the coverage button.
WID_AP_BTN_DOHILIGHT, ///< Show the coverage button.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_AUTOREPLACE_WIDGET_H
/** Widgets of the #ReplaceVehicleWindow class. */
enum ReplaceVehicleWidgets {
enum ReplaceVehicleWidgets : WidgetID {
WID_RV_CAPTION, ///< Caption of the window.
/* Sort dropdown at the right. */
@@ -32,12 +32,13 @@ enum ReplaceVehicleWidgets {
WID_RV_INFO_TAB, ///< Info tab.
WID_RV_STOP_REPLACE, ///< Stop Replacing button.
/* Train/road only widgets */
WID_RV_RAIL_ROAD_TYPE_DROPDOWN, ///< Dropdown menu about the rail/roadtype.
/* Train only widgets. */
WID_RV_RAIL_TYPE_DROPDOWN, ///< Dropdown to select railtype.
WID_RV_TRAIN_ENGINEWAGON_DROPDOWN, ///< Dropdown to select engines and/or wagons.
WID_RV_TRAIN_WAGONREMOVE_TOGGLE, ///< Button to toggle removing wagons.
/* Road only widgets. */
WID_RV_ROAD_TYPE_DROPDOWN, ///< Dropdown to select roadtype.
};
#endif /* WIDGETS_AUTOREPLACE_WIDGET_H */

View File

@@ -11,19 +11,19 @@
#define WIDGETS_BOOTSTRAP_WIDGET_H
/** Widgets of the #BootstrapBackground class. */
enum BootstrapBackgroundWidgets {
enum BootstrapBackgroundWidgets : WidgetID {
WID_BB_BACKGROUND, ///< Background of the window.
};
/** Widgets of the #BootstrapErrmsgWindow class. */
enum BootstrapErrorMessageWidgets {
enum BootstrapErrorMessageWidgets : WidgetID {
WID_BEM_CAPTION, ///< Caption of the window.
WID_BEM_MESSAGE, ///< Error message.
WID_BEM_QUIT, ///< Quit button.
};
/** Widgets of the #BootstrapContentDownloadStatusWindow class. */
enum BootstrapAskForDownloadWidgets {
enum BootstrapAskForDownloadWidgets : WidgetID {
WID_BAFD_QUESTION, ///< The question whether to download.
WID_BAFD_YES, ///< An affirmative answer to the question.
WID_BAFD_NO, ///< An negative answer to the question.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_BRIDGE_WIDGET_H
/** Widgets of the #BuildBridgeWindow class. */
enum BuildBridgeSelectionWidgets {
enum BuildBridgeSelectionWidgets : WidgetID {
WID_BBS_CAPTION, ///< Caption of the window.
WID_BBS_DROPDOWN_ORDER, ///< Direction of sort dropdown.
WID_BBS_DROPDOWN_CRITERIA, ///< Criteria of sort dropdown.

View File

@@ -11,11 +11,12 @@
#define WIDGETS_BUILD_VEHICLE_WIDGET_H
/** Widgets of the #BuildVehicleWindow class. */
enum BuildVehicleWidgets {
enum BuildVehicleWidgets : WidgetID {
WID_BV_CAPTION, ///< Caption of window.
WID_BV_SORT_ASCENDING_DESCENDING, ///< Sort direction.
WID_BV_SORT_DROPDOWN, ///< Criteria of sorting dropdown.
WID_BV_CARGO_FILTER_DROPDOWN, ///< Cargo filter dropdown.
WID_BV_FILTER, ///< Filter by name.
WID_BV_SHOW_HIDDEN_ENGINES, ///< Toggle whether to display the hidden vehicles.
WID_BV_LIST, ///< List of vehicles.
WID_BV_SCROLLBAR, ///< Scrollbar of list.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_CHEAT_WIDGET_H
/** Widgets of the #CheatWindow class. */
enum CheatWidgets {
enum CheatWidgets : WidgetID {
WID_C_NOTE, ///< Note on top of panel for use of cheat.
WID_C_PANEL, ///< Panel where all cheats are shown in.
};

View File

@@ -11,7 +11,7 @@
#define WIDGETS_COMPANY_WIDGET_H
/** Widgets of the #CompanyWindow class. */
enum CompanyWidgets {
enum CompanyWidgets : WidgetID {
WID_C_CAPTION, ///< Caption of the window.
WID_C_FACE, ///< View of the face.
@@ -26,16 +26,11 @@ enum CompanyWidgets {
WID_C_DESC_INFRASTRUCTURE, ///< Infrastructure.
WID_C_DESC_INFRASTRUCTURE_COUNTS, ///< Infrastructure count.
WID_C_SELECT_DESC_OWNERS, ///< Owners.
WID_C_DESC_OWNERS, ///< Owner in Owners.
WID_C_SELECT_BUTTONS, ///< Selection widget for the button bar.
WID_C_NEW_FACE, ///< Button to make new face.
WID_C_COLOUR_SCHEME, ///< Button to change colour scheme.
WID_C_PRESIDENT_NAME, ///< Button to change president name.
WID_C_COMPANY_NAME, ///< Button to change company name.
WID_C_BUY_SHARE, ///< Button to buy a share.
WID_C_SELL_SHARE, ///< Button to sell a share.
WID_C_SELECT_VIEW_BUILD_HQ, ///< Panel about HQ.
WID_C_VIEW_HQ, ///< Button to view the HQ.
@@ -49,6 +44,9 @@ enum CompanyWidgets {
WID_C_SELECT_GIVE_MONEY, ///< Selection widget for the give money button.
WID_C_GIVE_MONEY, ///< Button to give money.
WID_C_SELECT_HOSTILE_TAKEOVER, ///< Selection widget for the hostile takeover button.
WID_C_HOSTILE_TAKEOVER, ///< Button to hostile takeover another company.
WID_C_HAS_PASSWORD, ///< Has company password lock.
WID_C_SELECT_MULTIPLAYER, ///< Multiplayer selection panel.
WID_C_COMPANY_PASSWORD, ///< Button to set company password.
@@ -56,7 +54,7 @@ enum CompanyWidgets {
};
/** Widgets of the #CompanyFinancesWindow class. */
enum CompanyFinancesWidgets {
enum CompanyFinancesWidgets : WidgetID {
WID_CF_CAPTION, ///< Caption of the window.
WID_CF_TOGGLE_SIZE, ///< Toggle windows size.
WID_CF_SEL_PANEL, ///< Select panel or nothing.
@@ -80,7 +78,7 @@ enum CompanyFinancesWidgets {
/** Widgets of the #SelectCompanyLiveryWindow class. */
enum SelectCompanyLiveryWidgets {
enum SelectCompanyLiveryWidgets : WidgetID {
WID_SCL_CAPTION, ///< Caption of window.
WID_SCL_CLASS_GENERAL, ///< Class general.
WID_SCL_CLASS_RAIL, ///< Class rail.
@@ -104,7 +102,7 @@ enum SelectCompanyLiveryWidgets {
* Do not change the order of the widgets from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R,
* this order is needed for the WE_CLICK event of DrawFaceStringLabel().
*/
enum SelectCompanyManagerFaceWidgets {
enum SelectCompanyManagerFaceWidgets : WidgetID {
WID_SCMF_CAPTION, ///< Caption of window.
WID_SCMF_TOGGLE_LARGE_SMALL, ///< Toggle for large or small.
WID_SCMF_SELECT_FACE, ///< Select face.
@@ -172,7 +170,7 @@ enum SelectCompanyManagerFaceWidgets {
};
/** Widgets of the #CompanyInfrastructureWindow class. */
enum CompanyInfrastructureWidgets {
enum CompanyInfrastructureWidgets : WidgetID {
WID_CI_CAPTION, ///< Caption of window.
WID_CI_RAIL_DESC, ///< Description of rail.
WID_CI_RAIL_COUNT, ///< Count of rail.
@@ -189,7 +187,7 @@ enum CompanyInfrastructureWidgets {
};
/** Widgets of the #BuyCompanyWindow class. */
enum BuyCompanyWidgets {
enum BuyCompanyWidgets : WidgetID {
WID_BC_CAPTION, ///< Caption of window.
WID_BC_FACE, ///< Face button.
WID_BC_QUESTION, ///< Question text.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_CONSOLE_WIDGET_H
/** Widgets of the #IConsoleWindow class. */
enum ConsoleWidgets {
enum ConsoleWidgets : WidgetID {
WID_C_BACKGROUND, ///< Background of the console.
};

View File

@@ -11,7 +11,7 @@
#define WIDGETS_DATE_WIDGET_H
/** Widgets of the #SetDateWindow class. */
enum SetDateWidgets {
enum SetDateWidgets : WidgetID {
WID_SD_DAY, ///< Dropdown for the day.
WID_SD_MONTH, ///< Dropdown for the month.
WID_SD_YEAR, ///< Dropdown for the year.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_DEPOT_WIDGET_H
/** Widgets of the #DepotWindow class. */
enum DepotWidgets {
enum DepotWidgets : WidgetID {
WID_D_CAPTION, ///< Caption of window.
WID_D_SELL, ///< Sell button.
WID_D_SHOW_SELL_CHAIN, ///< Show sell chain panel.

View File

@@ -11,14 +11,14 @@
#define WIDGETS_DOCK_WIDGET_H
/** Widgets of the #BuildDocksDepotWindow class. */
enum BuildDockDepotWidgets {
enum BuildDockDepotWidgets : WidgetID {
WID_BDD_BACKGROUND, ///< Background of the window.
WID_BDD_X, ///< X-direction button.
WID_BDD_Y, ///< Y-direction button.
};
/** Widgets of the #BuildDocksToolbarWindow class. */
enum DockToolbarWidgets {
enum DockToolbarWidgets : WidgetID {
WID_DT_CANAL, ///< Build canal button.
WID_DT_LOCK, ///< Build lock button.
WID_DT_DEMOLISH, ///< Demolish aka dynamite button.

View File

@@ -12,8 +12,9 @@
#include "../string_func.h"
#include "../strings_func.h"
#include "../window_func.h"
#include "../guitimer_func.h"
#include "../zoom_func.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "dropdown_type.h"
#include "dropdown_widget.h"
@@ -21,202 +22,168 @@
#include "../safeguards.h"
void DropDownListItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
int c1 = _colour_gradient[bg_colour][3];
int c2 = _colour_gradient[bg_colour][7];
int mid = CenterBounds(r.top, r.bottom, 0);
GfxFillRect(r.left, mid - WidgetDimensions::scaled.bevel.bottom, r.right, mid - 1, c1);
GfxFillRect(r.left, mid, r.right, mid + WidgetDimensions::scaled.bevel.top - 1, c2);
}
uint DropDownListStringItem::Width() const
{
char buffer[512];
GetString(buffer, this->String(), lastof(buffer));
return GetStringBoundingBox(buffer).width + WidgetDimensions::scaled.dropdowntext.Horizontal();
}
void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
DrawString(ir.left, ir.right, r.top, this->String(), sel ? TC_WHITE : TC_BLACK);
}
/**
* Natural sorting comparator function for DropDownList::sort().
* @param first Left side of comparison.
* @param second Right side of comparison.
* @return true if \a first precedes \a second.
* @warning All items in the list need to be derivates of DropDownListStringItem.
*/
/* static */ bool DropDownListStringItem::NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second)
{
char buffer1[512], buffer2[512];
GetString(buffer1, static_cast<const DropDownListStringItem*>(first.get())->String(), lastof(buffer1));
GetString(buffer2, static_cast<const DropDownListStringItem*>(second.get())->String(), lastof(buffer2));
return strnatcmp(buffer1, buffer2) < 0;
}
StringID DropDownListParamStringItem::String() const
{
for (uint i = 0; i < lengthof(this->decode_params); i++) SetDParam(i, this->decode_params[i]);
return this->string;
}
StringID DropDownListCharStringItem::String() const
{
SetDParamStr(0, this->raw_string);
return this->string;
}
DropDownListIconItem::DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked) : DropDownListParamStringItem(string, result, masked), sprite(sprite), pal(pal)
{
this->dim = GetSpriteSize(sprite);
this->sprite_y = dim.height;
}
uint DropDownListIconItem::Height(uint width) const
{
return std::max(this->dim.height, (uint)FONT_HEIGHT_NORMAL);
}
uint DropDownListIconItem::Width() const
{
return DropDownListParamStringItem::Width() + this->dim.width + WidgetDimensions::scaled.hsep_wide;
}
void DropDownListIconItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
Rect tr = ir.Indent(this->dim.width + WidgetDimensions::scaled.hsep_normal, rtl);
DrawSprite(this->sprite, this->pal, ir.WithWidth(this->dim.width, rtl).left, CenterBounds(r.top, r.bottom, this->sprite_y));
DrawString(tr.left, tr.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK);
}
void DropDownListIconItem::SetDimension(Dimension d)
{
this->dim = d;
}
static const NWidgetPart _nested_dropdown_menu_widgets[] = {
static constexpr NWidgetPart _nested_dropdown_menu_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetMinimalSize(1, 1), SetScrollbar(WID_DM_SCROLL), EndContainer(),
NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetScrollbar(WID_DM_SCROLL), EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
EndContainer(),
EndContainer(),
};
static WindowDesc _dropdown_desc(
static WindowDesc _dropdown_desc(__FILE__, __LINE__,
WDP_MANUAL, nullptr, 0, 0,
WC_DROPDOWN_MENU, WC_NONE,
WDF_NO_FOCUS,
_nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets)
std::begin(_nested_dropdown_menu_widgets), std::end(_nested_dropdown_menu_widgets)
);
/** Drop-down menu window */
struct DropdownWindow : Window {
WindowClass parent_wnd_class; ///< Parent window class.
WindowNumber parent_wnd_num; ///< Parent window number.
int parent_button; ///< Parent widget number where the window is dropped from.
const DropDownList list; ///< List with dropdown menu items.
int selected_index; ///< Index of the selected item in the list.
byte click_delay; ///< Timer to delay selection.
bool drag_mode;
WidgetID parent_button; ///< Parent widget number where the window is dropped from.
Rect wi_rect; ///< Rect of the button that opened the dropdown.
DropDownList list; ///< List with dropdown menu items.
int selected_result; ///< Result value of the selected item in the list.
byte click_delay = 0; ///< Timer to delay selection.
bool drag_mode = true;
bool instant_close; ///< Close the window when the mouse button is raised.
bool left_button_state; ///< Close the window when the mouse button is clicked outside the window.
int scrolling; ///< If non-zero, auto-scroll the item list (one time).
GUITimer scrolling_timer; ///< Timer for auto-scroll of the item list.
bool persist; ///< Persist dropdown menu.
int scrolling = 0; ///< If non-zero, auto-scroll the item list (one time).
bool left_button_scrolling; ///< The list is scrolled with left mouse button
int left_button_scroll_pos; ///< Initial mouse position for left button scrolling
Point position; ///< Position of the topleft corner of the window.
Scrollbar *vscroll;
Dimension items_dim; ///< Calculated cropped and padded dimension for the items widget.
/**
* Create a dropdown menu.
* @param parent Parent window.
* @param list Dropdown item list.
* @param selected Index of the selected item in the list.
* @param selected Initial selected result of the list.
* @param button Widget of the parent window doing the dropdown.
* @param wi_rect Rect of the button that opened the dropdown.
* @param instant_close Close the window when the mouse button is raised.
* @param position Topleft position of the dropdown menu window.
* @param size Size of the dropdown menu window.
* @param wi_colour Colour of the parent widget.
* @param scroll Dropdown menu has a scrollbar.
* @param persist Dropdown menu will persist.
*/
DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
: Window(&_dropdown_desc), list(std::move(list))
DropdownWindow(Window *parent, DropDownList &&list, int selected, WidgetID button, const Rect wi_rect, bool instant_close, Colours wi_colour, bool persist)
: Window(&_dropdown_desc)
, parent_button(button)
, wi_rect(wi_rect)
, list(std::move(list))
, selected_result(selected)
, instant_close(instant_close)
, persist(persist)
{
assert(this->list.size() > 0);
assert(!this->list.empty());
this->position = position;
this->parent = parent;
this->CreateNestedTree();
this->GetWidget<NWidgetCore>(WID_DM_ITEMS)->colour = wi_colour;
this->GetWidget<NWidgetCore>(WID_DM_SCROLL)->colour = wi_colour;
this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
nwi->SetMinimalSizeAbsolute(items_width, size.height + WidgetDimensions::scaled.fullbevel.Vertical() * 2);
nwi->colour = wi_colour;
nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
nwi->colour = wi_colour;
this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
this->UpdateSizeAndPosition();
this->FinishInitNested(0);
CLRBITS(this->flags, WF_WHITE_BORDER);
/* Total length of list */
int list_height = 0;
int scroll_pos = 0;
int count = 0;
for (const auto &item : this->list) {
list_height += item->Height(items_width);
if (item->result == selected) scroll_pos = count;
count++;
}
/* Capacity is the average number of items visible */
this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height);
this->vscroll->SetCount((uint16)this->list.size());
scroll_pos = std::min(scroll_pos, std::max(0, this->vscroll->GetCount() - this->vscroll->GetCapacity()));
this->vscroll->SetPosition(scroll_pos);
this->vscroll->UpdatePosition(0);
this->parent_wnd_class = parent->window_class;
this->parent_wnd_num = parent->window_number;
this->parent_button = button;
this->selected_index = selected;
this->click_delay = 0;
this->drag_mode = instant_close;
this->instant_close = instant_close;
this->scrolling = 0;
this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
this->left_button_scrolling = false;
this->left_button_scroll_pos = -1;
this->left_button_state = _left_button_down;
}
void Close() override
void Close([[maybe_unused]] int data = 0) override
{
/* Finish closing the dropdown, so it doesn't affect new window placement.
* Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
this->Window::Close();
Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
if (w2 != nullptr) {
Point pt = _cursor.pos;
pt.x -= w2->left;
pt.y -= w2->top;
w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
Point pt = _cursor.pos;
pt.x -= this->parent->left;
pt.y -= this->parent->top;
this->parent->OnDropdownClose(pt, this->parent_button, this->selected_result, this->instant_close);
/* Set flag on parent widget to indicate that we have just closed. */
NWidgetCore *nwc = this->parent->GetWidget<NWidgetCore>(this->parent_button);
if (nwc != nullptr) SetBit(nwc->disp_flags, NDB_DROPDOWN_CLOSED);
}
void OnFocusLost(bool closing) override
{
if (!closing) {
this->instant_close = false;
this->Close();
}
}
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
/**
* Fit dropdown list into available height, rounding to average item size. Width is adjusted if scrollbar is present.
* @param[in,out] desired Desired dimensions of dropdown list.
* @param list Dimensions of the list itself, without padding or cropping.
* @param available_height Available height to fit list within.
*/
void FitAvailableHeight(Dimension &desired, const Dimension &list, uint available_height)
{
if (desired.height < available_height) return;
/* If the dropdown doesn't fully fit, we a need a dropdown. */
uint avg_height = list.height / (uint)this->list.size();
uint rows = std::max((available_height - WidgetDimensions::scaled.dropdownlist.Vertical()) / avg_height, 1U);
desired.width = std::max(list.width, desired.width - NWidgetScrollbar::GetVerticalDimension().width);
desired.height = rows * avg_height + WidgetDimensions::scaled.dropdownlist.Vertical();
}
/**
* Update size and position of window to fit dropdown list into available space.
*/
void UpdateSizeAndPosition()
{
Rect button_rect = this->wi_rect.Translate(this->parent->left, this->parent->top);
/* Get the dimensions required for the list. */
Dimension list_dim = GetDropDownListDimension(this->list);
/* Set up dimensions for the items widget. */
Dimension widget_dim = list_dim;
widget_dim.width += WidgetDimensions::scaled.dropdownlist.Horizontal();
widget_dim.height += WidgetDimensions::scaled.dropdownlist.Vertical();
/* Width should match at least the width of the parent widget. */
widget_dim.width = std::max<uint>(widget_dim.width, button_rect.Width());
/* Available height below (or above, if the dropdown is placed above the widget). */
uint available_height_below = std::max(GetMainViewBottom() - button_rect.bottom - 1, 0);
uint available_height_above = std::max(button_rect.top - 1 - GetMainViewTop(), 0);
/* Is it better to place the dropdown above the widget? */
if (widget_dim.height > available_height_below && available_height_above > available_height_below) {
FitAvailableHeight(widget_dim, list_dim, available_height_above);
this->position.y = button_rect.top - widget_dim.height;
} else {
FitAvailableHeight(widget_dim, list_dim, available_height_below);
this->position.y = button_rect.bottom + 1;
}
this->position.x = (_current_text_dir == TD_RTL) ? button_rect.right + 1 - (int)widget_dim.width : button_rect.left;
this->items_dim = widget_dim;
this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(list_dim.height > widget_dim.height ? 0 : SZSP_NONE);
/* Capacity is the average number of items visible */
this->vscroll->SetCapacity((widget_dim.height - WidgetDimensions::scaled.dropdownlist.Vertical()) * this->list.size() / list_dim.height);
this->vscroll->SetCount(this->list.size());
/* If the dropdown is positioned above the parent widget, start selection at the bottom. */
if (this->position.y < button_rect.top && list_dim.height > widget_dim.height) this->vscroll->UpdatePosition(INT_MAX);
}
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
if (widget == WID_DM_ITEMS) *size = this->items_dim;
}
Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
{
return this->position;
}
@@ -230,16 +197,15 @@ struct DropdownWindow : Window {
{
if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.fullbevel);
int y = _cursor.pos.y - this->top - r.top - WidgetDimensions::scaled.fullbevel.top;
int width = r.Width();
const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.dropdownlist);
int y = _cursor.pos.y - this->top - r.top;
int pos = this->vscroll->GetPosition();
for (const auto &item : this->list) {
/* Skip items that are scrolled up */
if (--pos >= 0) continue;
int item_height = item->Height(width);
int item_height = item->Height();
if (y < item_height) {
if (item->masked || !item->Selectable()) return false;
@@ -253,77 +219,61 @@ struct DropdownWindow : Window {
return false;
}
void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget != WID_DM_ITEMS) return;
Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
Rect ir = r.Shrink(WidgetDimensions::scaled.fullbevel).Shrink(RectPadding::zero, WidgetDimensions::scaled.fullbevel);
Rect ir = r.Shrink(WidgetDimensions::scaled.dropdownlist);
int y = ir.top;
int pos = this->vscroll->GetPosition();
for (const auto &item : this->list) {
int item_height = item->Height(ir.Width());
int item_height = item->Height();
/* Skip items that are scrolled up */
if (--pos >= 0) continue;
if (y + item_height - 1 <= ir.bottom) {
bool selected = (this->selected_index == item->result);
if (selected) GfxFillRect(ir.left, y, ir.right, y + item_height - 1, PC_BLACK);
Rect full{ir.left, y, ir.right, y + item_height - 1};
item->Draw({ir.left, y, ir.right, y + item_height - 1}, selected, colour);
bool selected = (this->selected_result == item->result) && item->Selectable();
if (selected) GfxFillRect(full, PC_BLACK);
if (item->masked) {
GfxFillRect(ir.left, y, ir.right, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
}
item->Draw(full, full.Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero), selected, colour);
}
y += item_height;
}
}
void OnClick(Point pt, int widget, int click_count) override
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
if (this->left_button_scrolling) return;
if (widget != WID_DM_ITEMS) return;
int item;
if (this->GetDropDownItem(item)) {
this->click_delay = 4;
this->selected_index = item;
this->selected_result = item;
this->SetDirty();
}
}
void OnRealtimeTick(uint delta_ms) override
{
if (!this->scrolling_timer.Elapsed(delta_ms)) return;
this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK);
/** Rate limit how fast scrolling happens. */
IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(30), [this](auto) {
if (this->scrolling == 0) return;
if (this->scrolling != 0) {
int pos = this->vscroll->GetPosition();
if (this->vscroll->UpdatePosition(this->scrolling)) this->SetDirty();
this->vscroll->UpdatePosition(this->scrolling);
this->scrolling = 0;
if (pos != this->vscroll->GetPosition()) {
this->SetDirty();
}
}
}
this->scrolling = 0;
}};
void OnMouseLoop() override
{
Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
if (w2 == nullptr) {
this->Close();
return;
}
if (this->click_delay != 0 && --this->click_delay == 0) {
/* Close the dropdown, so it doesn't affect new window placement.
* Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
this->Close();
w2->OnDropdownSelect(this->parent_button, this->selected_index);
if (!this->persist) this->Close();
this->parent->OnDropdownSelect(this->parent_button, this->selected_result);
return;
}
@@ -351,8 +301,8 @@ struct DropdownWindow : Window {
if (!this->GetDropDownItem(item)) return;
}
if (this->selected_index != item) {
this->selected_index = item;
if (this->selected_result != item) {
this->selected_result = item;
this->SetDirty();
}
}
@@ -396,8 +346,39 @@ struct DropdownWindow : Window {
}
}
}
void ReplaceList(DropDownList &&list)
{
this->list = std::move(list);
this->UpdateSizeAndPosition();
this->ReInit(0, 0);
this->InitializePositionSize(this->position.x, this->position.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
this->SetDirty();
}
};
void ReplaceDropDownList(Window *parent, DropDownList &&list)
{
DropdownWindow *ddw = dynamic_cast<DropdownWindow *>(parent->FindChildWindow(WC_DROPDOWN_MENU));
if (ddw != nullptr) ddw->ReplaceList(std::move(list));
}
/**
* Determine width and height required to fully display a DropDownList
* @param list The list.
* @return Dimension required to display the list.
*/
Dimension GetDropDownListDimension(const DropDownList &list)
{
Dimension dim{};
for (const auto &item : list) {
dim.height += item->Height();
dim.width = std::max(dim.width, item->Width());
}
dim.width += WidgetDimensions::scaled.dropdowntext.Horizontal();
return dim;
}
/**
* Show a drop down list.
* @param w Parent window for the list.
@@ -406,87 +387,14 @@ struct DropdownWindow : Window {
* @param button The widget which is passed to Window::OnDropdownSelect and OnDropdownClose.
* Unless you override those functions, this should be then widget index of the dropdown button.
* @param wi_rect Coord of the parent drop down button, used to position the dropdown menu.
* @param auto_width The width is determined by the widest item in the list,
* in this case only one of \a left or \a right is used (depending on text direction).
* @param instant_close Set to true if releasing mouse button should close the
* list regardless of where the cursor is.
* @param persist Set if this dropdown should stay open after an option is selected.
*/
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
{
CloseWindowById(WC_DROPDOWN_MENU, 0);
/* The preferred position is just below the dropdown calling widget */
int top = w->top + wi_rect.bottom + 1;
/* The preferred width equals the calling widget */
uint width = wi_rect.Width();
/* Longest item in the list, if auto_width is enabled */
uint max_item_width = 0;
/* Total height of list */
uint height = 0;
for (const auto &item : list) {
height += item->Height(width);
if (auto_width) max_item_width = std::max(max_item_width, item->Width());
}
if (auto_width) max_item_width += WidgetDimensions::scaled.fullbevel.Horizontal();
/* Scrollbar needed? */
bool scroll = false;
/* Is it better to place the dropdown above the widget? */
bool above = false;
/* Available height below (or above, if the dropdown is placed above the widget). */
uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
/* If the dropdown doesn't fully fit below the widget... */
if (height > available_height) {
uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
/* Put the dropdown above if there is more available space. */
if (available_height_above > available_height) {
above = true;
available_height = available_height_above;
}
/* If the dropdown doesn't fully fit, we need a dropdown. */
if (height > available_height) {
scroll = true;
uint avg_height = height / (uint)list.size();
/* Check at least there is space for one item. */
assert(available_height >= avg_height);
/* Fit the list. */
uint rows = available_height / avg_height;
height = rows * avg_height;
/* Add space for the scrollbar. */
max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
}
/* Set the top position if needed. */
if (above) {
top = w->top + wi_rect.top - height - WidgetDimensions::scaled.fullbevel.Vertical() * 2;
}
}
if (auto_width) width = std::max(width, max_item_width);
width = GetMinButtonSize(width);
Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
Dimension dw_size = {width, height};
DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
/* The dropdown starts scrolling downwards when opening it towards
* the top and holding down the mouse button. It can be fooled by
* opening the dropdown scrolled to the very bottom. */
//if (above && scroll) dropdown->vscroll->UpdatePosition(INT_MAX);
CloseWindowByClass(WC_DROPDOWN_MENU);
new DropdownWindow(w, std::move(list), selected, button, wi_rect, instant_close, wi_colour, persist);
}
/**
@@ -496,12 +404,12 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
* @param selected The initially selected list item.
* @param button The widget within the parent window that is used to determine
* the list's location.
* @param width Override the width determined by the selected widget.
* @param auto_width Maximum width is determined by the widest item in the list.
* @param width Override the minimum width determined by the selected widget and list contents.
* @param instant_close Set to true if releasing mouse button should close the
* list regardless of where the cursor is.
* @param persist Set if this dropdown should stay open after an option is selected.
*/
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
{
/* Our parent's button widget is used to determine where to place the drop
* down list window. */
@@ -512,9 +420,9 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button,
if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
} else {
w->LowerWidget(button);
nwi->SetLowered(true);
}
w->SetWidgetDirty(button);
nwi->SetDirty(w);
if (width != 0) {
if (_current_text_dir == TD_RTL) {
@@ -524,7 +432,7 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button,
}
}
ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close);
ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, instant_close, persist);
}
/**
@@ -536,41 +444,17 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button,
* @param button Button widget number of the parent window \a w that wants the dropdown menu.
* @param disabled_mask Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list).
* @param hidden_mask Bitmask for hidden items (items with their bit set are not copied to the dropdown list).
* @param width Width of the dropdown menu. If \c 0, use the width of parent widget \a button.
* @param width Minimum width of the dropdown menu.
*/
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
{
DropDownList list;
for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
if (!HasBit(hidden_mask, i)) {
list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
list.push_back(std::make_unique<DropDownListStringItem>(strings[i], i, HasBit(disabled_mask, i)));
}
}
if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
}
/**
* Delete the drop-down menu from window \a pw
* @param pw Parent window of the drop-down menu window
* @return Parent widget number if the drop-down was found and closed, \c -1 if the window was not found.
*/
int HideDropDownMenu(Window *pw)
{
for (Window *w : Window::Iterate()) {
if (w->window_class != WC_DROPDOWN_MENU) continue;
DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
assert(dw != nullptr);
if (pw->window_class == dw->parent_wnd_class &&
pw->window_number == dw->parent_wnd_num) {
int parent_button = dw->parent_button;
dw->Close();
return parent_button;
}
}
return -1;
}

View File

@@ -13,9 +13,6 @@
#include "../window_gui.h"
/* Show drop down menu containing a fixed list of strings */
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width = 0);
/* Hide drop down menu of a parent window */
int HideDropDownMenu(Window *pw);
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width = 0);
#endif /* WIDGETS_DROPDOWN_FUNC_H */

View File

@@ -13,94 +13,209 @@
#include "../window_type.h"
#include "../widget_type.h"
#include "../gfx_func.h"
#include "../core/smallvec_type.hpp"
#include "table/strings.h"
#include "../gfx_type.h"
#include "../palette_func.h"
#include "../string_func.h"
#include "../strings_func.h"
#include "../table/strings.h"
#include "../window_gui.h"
/**
* Base list item class from which others are derived. If placed in a list it
* will appear as a horizontal line in the menu.
* Base list item class from which others are derived.
*/
class DropDownListItem {
public:
int result; ///< Result code to return to window on selection
bool masked; ///< Masked and unselectable item
int result; ///< Result value to return to window on selection.
bool masked; ///< Masked and unselectable item.
bool shaded; ///< Shaded item, affects text colour.
DropDownListItem(int result, bool masked) : result(result), masked(masked) {}
virtual ~DropDownListItem() {}
explicit DropDownListItem(int result, bool masked = false, bool shaded = false) : result(result), masked(masked), shaded(shaded) {}
virtual ~DropDownListItem() = default;
virtual bool Selectable() const { return false; }
virtual uint Height(uint width) const { return GetMinButtonSize(FONT_HEIGHT_NORMAL); }
virtual bool Selectable() const { return true; }
virtual uint Height() const { return 0; }
virtual uint Width() const { return 0; }
virtual void Draw(const Rect &r, bool sel, Colours bg_colour) const;
virtual void Draw(const Rect &full, const Rect &, bool, Colours bg_colour) const
{
if (this->masked) GfxFillRect(full, _colour_gradient[bg_colour][5], FILLRECT_CHECKER);
}
TextColour GetColour(bool sel) const
{
if (this->shaded) return (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
return sel ? TC_WHITE : TC_BLACK;
}
};
/**
* Common string list item.
* Drop down divider component.
* @tparam TBase Base component.
* @tparam TFs Font size -- used to determine height.
*/
class DropDownListStringItem : public DropDownListItem {
template<class TBase, FontSize TFs = FS_NORMAL>
class DropDownDivider : public TBase {
public:
StringID string; ///< String ID of item
template <typename... Args>
explicit DropDownDivider(Args&&... args) : TBase(std::forward<Args>(args)...) {}
DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
bool Selectable() const override { return false; }
uint Height() const override { return std::max<uint>(GetCharacterHeight(TFs), this->TBase::Height()); }
bool Selectable() const override { return true; }
uint Width() const override;
void Draw(const Rect &r, bool sel, Colours bg_colour) const override;
virtual StringID String() const { return this->string; }
void Draw(const Rect &full, const Rect &, bool, Colours bg_colour) const override
{
uint8_t c1 = _colour_gradient[bg_colour][3];
uint8_t c2 = _colour_gradient[bg_colour][7];
static bool NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second);
int mid = CenterBounds(full.top, full.bottom, 0);
GfxFillRect(full.left, mid - WidgetDimensions::scaled.bevel.bottom, full.right, mid - 1, c1);
GfxFillRect(full.left, mid, full.right, mid + WidgetDimensions::scaled.bevel.top - 1, c2);
}
};
/**
* String list item with parameters.
* Drop down string component.
* @tparam TBase Base component.
* @tparam TFs Font size.
* @tparam TEnd Position string at end if true, or start if false.
*/
class DropDownListParamStringItem : public DropDownListStringItem {
template<class TBase, FontSize TFs = FS_NORMAL, bool TEnd = false>
class DropDownString : public TBase {
std::string string; ///< String to be drawn.
Dimension dim; ///< Dimensions of string.
public:
uint64 decode_params[10]; ///< Parameters of the string
template <typename... Args>
explicit DropDownString(StringID string, Args&&... args) : TBase(std::forward<Args>(args)...)
{
this->SetString(GetString(string));
}
DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
template <typename... Args>
explicit DropDownString(const std::string &string, Args&&... args) : TBase(std::forward<Args>(args)...)
{
SetDParamStr(0, string);
this->SetString(GetString(STR_JUST_RAW_STRING));
}
StringID String() const override;
void SetParam(uint index, uint64 value) { decode_params[index] = value; }
void SetParamStr(uint index, const char *str) { this->SetParam(index, (uint64)(size_t)str); }
void SetString(std::string &&string)
{
this->string = std::move(string);
this->dim = GetStringBoundingBox(this->string, TFs);
}
uint Height() const override
{
return std::max<uint>(this->dim.height, this->TBase::Height());
}
uint Width() const override { return this->dim.width + this->TBase::Width(); }
void Draw(const Rect &full, const Rect &r, bool sel, Colours bg_colour) const override
{
bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
DrawStringMultiLine(r.WithWidth(this->dim.width, rtl), this->string, this->GetColour(sel), SA_CENTER, false, TFs);
this->TBase::Draw(full, r.Indent(this->dim.width, rtl), sel, bg_colour);
}
/**
* Natural sorting comparator function for DropDownList::sort().
* @param first Left side of comparison.
* @param second Right side of comparison.
* @return true if \a first precedes \a second.
* @warning All items in the list need to be derivates of DropDownListStringItem.
*/
static bool NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second)
{
const std::string &str1 = static_cast<const DropDownString*>(first.get())->string;
const std::string &str2 = static_cast<const DropDownString*>(second.get())->string;
return StrNaturalCompare(str1, str2) < 0;
}
};
/**
* List item containing a C char string.
* Drop down icon component.
* @tparam TBase Base component.
* @tparam TEnd Position icon at end if true, or start if false.
*/
class DropDownListCharStringItem : public DropDownListStringItem {
template<class TBase, bool TEnd = false>
class DropDownIcon : public TBase {
SpriteID sprite; ///< Sprite ID to be drawn.
PaletteID palette; ///< Palette ID to use.
Dimension dsprite; ///< Bounding box dimensions of sprite.
Dimension dbounds; ///< Bounding box dimensions of bounds.
public:
std::string raw_string;
template <typename... Args>
explicit DropDownIcon(SpriteID sprite, PaletteID palette, Args&&... args) : TBase(std::forward<Args>(args)...), sprite(sprite), palette(palette)
{
this->dsprite = GetSpriteSize(this->sprite);
this->dbounds = this->dsprite;
}
DropDownListCharStringItem(const std::string &raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
template <typename... Args>
explicit DropDownIcon(const Dimension &dim, SpriteID sprite, PaletteID palette, Args&&... args) : TBase(std::forward<Args>(args)...), sprite(sprite), palette(palette), dbounds(dim)
{
this->dsprite = GetSpriteSize(this->sprite);
}
StringID String() const override;
uint Height() const override { return std::max(this->dbounds.height, this->TBase::Height()); }
uint Width() const override { return this->dbounds.width + WidgetDimensions::scaled.hsep_normal + this->TBase::Width(); }
void Draw(const Rect &full, const Rect &r, bool sel, Colours bg_colour) const override
{
bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
Rect ir = r.WithWidth(this->dbounds.width, rtl);
DrawSprite(this->sprite, this->palette, CenterBounds(ir.left, ir.right, this->dsprite.width), CenterBounds(r.top, r.bottom, this->dsprite.height));
this->TBase::Draw(full, r.Indent(this->dbounds.width + WidgetDimensions::scaled.hsep_normal, rtl), sel, bg_colour);
}
};
/**
* List item with icon and string.
* Drop down checkmark component.
* @tparam TBase Base component.
* @tparam TFs Font size.
* @tparam TEnd Position checkmark at end if true, or start if false.
*/
class DropDownListIconItem : public DropDownListParamStringItem {
SpriteID sprite;
PaletteID pal;
Dimension dim;
uint sprite_y;
template<class TBase, bool TEnd = false, FontSize TFs = FS_NORMAL>
class DropDownCheck : public TBase {
bool checked; ///< Is item checked.
Dimension dim; ///< Dimension of checkmark.
public:
DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked);
template <typename... Args>
explicit DropDownCheck(bool checked, Args&&... args) : TBase(std::forward<Args>(args)...), checked(checked)
{
this->dim = GetStringBoundingBox(STR_JUST_CHECKMARK, TFs);
}
uint Height(uint width) const override;
uint Width() const override;
void Draw(const Rect &r, bool sel, Colours bg_colour) const override;
void SetDimension(Dimension d);
uint Height() const override { return std::max<uint>(this->dim.height, this->TBase::Height()); }
uint Width() const override { return this->dim.width + WidgetDimensions::scaled.hsep_wide + this->TBase::Width(); }
void Draw(const Rect &full, const Rect &r, bool sel, Colours bg_colour) const override
{
bool rtl = TEnd ^ (_current_text_dir == TD_RTL);
if (this->checked) {
DrawStringMultiLine(r.WithWidth(this->dim.width, rtl), STR_JUST_CHECKMARK, this->GetColour(sel), SA_CENTER, false, TFs);
}
this->TBase::Draw(full, r.Indent(this->dim.width + WidgetDimensions::scaled.hsep_wide, rtl), sel, bg_colour);
}
};
/* Commonly used drop down list items. */
using DropDownListDividerItem = DropDownDivider<DropDownListItem>;
using DropDownListStringItem = DropDownString<DropDownListItem>;
using DropDownListIconItem = DropDownIcon<DropDownString<DropDownListItem>>;
using DropDownListCheckedItem = DropDownCheck<DropDownString<DropDownListItem>>;
/**
* A drop down list is a collection of drop down list items.
*/
typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false);
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close = false, bool persist = false);
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width = 0, bool instant_close = false, bool persist = false);
Dimension GetDropDownListDimension(const DropDownList &list);
void ReplaceDropDownList(Window *parent, DropDownList &&list);
#endif /* WIDGETS_DROPDOWN_TYPE_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_DROPDOWN_WIDGET_H
/** Widgets of the #DropdownWindow class. */
enum DropdownMenuWidgets {
enum DropdownMenuWidgets : WidgetID {
WID_DM_ITEMS, ///< Panel showing the dropdown items.
WID_DM_SHOW_SCROLL, ///< Hide scrollbar if too few items.
WID_DM_SCROLL, ///< Scrollbar.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_ENGINE_WIDGET_H
/** Widgets of the #EnginePreviewWindow class. */
enum EnginePreviewWidgets {
enum EnginePreviewWidgets : WidgetID {
WID_EP_QUESTION, ///< The container for the question.
WID_EP_NO, ///< No button.
WID_EP_YES, ///< Yes button.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_ERROR_WIDGET_H
/** Widgets of the #ErrmsgWindow class. */
enum ErrorMessageWidgets {
enum ErrorMessageWidgets : WidgetID {
WID_EM_CAPTION, ///< Caption of the window.
WID_EM_FACE, ///< Error title.
WID_EM_MESSAGE, ///< Error message.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_FIOS_WIDGET_H
/** Widgets of the #SaveLoadWindow class. */
enum SaveLoadWidgets {
enum SaveLoadWidgets : WidgetID {
WID_SL_CAPTION, ///< Caption of the window.
WID_SL_SORT_BYNAME, ///< Sort by name button.
WID_SL_SORT_BYDATE, ///< Sort by date button.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_FRAMERATE_WIDGET_H
/** Widgets of the #FramerateWindow class. */
enum FramerateWindowWidgets {
enum FramerateWindowWidgets : WidgetID {
WID_FRW_CAPTION,
WID_FRW_RATE_GAMELOOP,
WID_FRW_RATE_DRAWING,
@@ -26,7 +26,7 @@ enum FramerateWindowWidgets {
};
/** Widgets of the #FrametimeGraphWindow class. */
enum FrametimeGraphWindowWidgets {
enum FrametimeGraphWindowWidgets : WidgetID {
WID_FGW_CAPTION,
WID_FGW_GRAPH,
};

View File

@@ -5,7 +5,7 @@
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file ai_widget.h Types related to the ai widgets. */
/** @file game_widget.h Types related to the GS widgets. */
#ifndef WIDGETS_GS_WIDGET_H
#define WIDGETS_GS_WIDGET_H
@@ -13,16 +13,18 @@
#include "../textfile_type.h"
/** Widgets of the #GSConfigWindow class. */
enum GSConfigWidgets {
enum GSConfigWidgets : WidgetID {
WID_GSC_BACKGROUND, ///< Window background.
WID_GSC_GSLIST, ///< List with current selected Game Script.
WID_GSC_SETTINGS, ///< Panel to draw the Game Script settings on
WID_GSC_SCROLLBAR, ///< Scrollbar to scroll through the selected AIs.
WID_GSC_CHANGE, ///< Select another Game Script button.
WID_GSC_OPEN_URL, ///< Open GS URL.
WID_GSC_TEXTFILE, ///< Open GS readme, changelog (+1) or license (+2).
WID_GSC_CONTENT_DOWNLOAD = WID_GSC_TEXTFILE + TFT_END, ///< Download content button.
WID_GSC_ACCEPT, ///< Accept ("Close") button
WID_GSC_CONTENT_DOWNLOAD = WID_GSC_TEXTFILE + TFT_CONTENT_END, ///< Download content button.
WID_GSC_RESET, ///< Reset button.
WID_GSC_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
#endif /* WIDGETS_GS_WIDGET_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_GENWORLD_WIDGET_H
/** Widgets of the #GenerateLandscapeWindow class. */
enum GenerateLandscapeWidgets {
enum GenerateLandscapeWidgets : WidgetID {
WID_GL_TEMPERATE, ///< Button with icon "Temperate".
WID_GL_ARCTIC, ///< Button with icon "Arctic".
WID_GL_TROPICAL, ///< Button with icon "Tropical".
@@ -69,7 +69,7 @@ enum GenerateLandscapeWidgets {
};
/** Widgets of the #CreateScenarioWindow class. */
enum CreateScenarioWidgets {
enum CreateScenarioWidgets : WidgetID {
WID_CS_TEMPERATE, ///< Select temperate landscape style.
WID_CS_ARCTIC, ///< Select arctic landscape style.
WID_CS_TROPICAL, ///< Select tropical landscape style.
@@ -87,7 +87,7 @@ enum CreateScenarioWidgets {
};
/** Widgets of the #GenerateProgressWindow class. */
enum GenerationProgressWidgets {
enum GenerationProgressWidgets : WidgetID {
WID_GP_PROGRESS_BAR, ///< Progress bar.
WID_GP_PROGRESS_TEXT, ///< Text with the progress bar.
WID_GP_ABORT, ///< Abort button.

View File

@@ -12,7 +12,7 @@
#define WIDGETS_GOAL_WIDGET_H
/** Widgets of the #GoalListWindow class. */
enum GoalListWidgets {
enum GoalListWidgets : WidgetID {
WID_GOAL_CAPTION, ///< Caption of the window.
WID_GOAL_SELECT_BUTTONS, ///< Selection widget for the title bar button.
WID_GOAL_GLOBAL_BUTTON, ///< Button to show global goals.
@@ -22,14 +22,13 @@ enum GoalListWidgets {
};
/** Widgets of the #GoalQuestionWindow class. */
enum GoalQuestionWidgets {
enum GoalQuestionWidgets : WidgetID {
WID_GQ_CAPTION, ///< Caption of the window.
WID_GQ_QUESTION, ///< Question text.
WID_GQ_BUTTONS, ///< Buttons selection (between 1, 2 or 3).
WID_GQ_BUTTON_1, ///< First button.
WID_GQ_BUTTON_2, ///< Second button.
WID_GQ_BUTTON_3, ///< Third button.
WID_GQ_BUTTON_SPACER, ///< Selection to hide extra padding if there are no buttons
};
#endif /* WIDGETS_GOAL_WIDGET_H */

View File

@@ -14,37 +14,24 @@
#include "../company_type.h"
/** Widgets of the #GraphLegendWindow class. */
enum GraphLegendWidgets {
enum GraphLegendWidgets : WidgetID {
WID_GL_BACKGROUND, ///< Background of the window.
WID_GL_FIRST_COMPANY, ///< First company in the legend.
WID_GL_LAST_COMPANY = WID_GL_FIRST_COMPANY + MAX_COMPANIES - 1, ///< Last company in the legend.
};
/** Widgets of the #OperatingProfitGraphWindow class, #IncomeGraphWindow class, #DeliveredCargoGraphWindow class, and #CompanyValueGraphWindow class. */
enum CompanyValueWidgets {
WID_CV_KEY_BUTTON, ///< Key button.
WID_CV_BACKGROUND, ///< Background of the window.
WID_CV_GRAPH, ///< Graph itself.
WID_CV_RESIZE, ///< Resize button.
};
/** Widgets of the #BaseGraphWindow class and derived classes. */
enum GraphWidgets : WidgetID {
WID_GRAPH_KEY_BUTTON, ///< Key button.
WID_GRAPH_BACKGROUND, ///< Background of the window.
WID_GRAPH_GRAPH, ///< Graph itself.
WID_GRAPH_RESIZE, ///< Resize button.
WID_GRAPH_HEADER, ///< Header.
WID_GRAPH_FOOTER, ///< Footer.
/** Widget of the #PerformanceHistoryGraphWindow class. */
enum PerformanceHistoryGraphWidgets {
WID_PHG_KEY, ///< Key button.
WID_PHG_DETAILED_PERFORMANCE, ///< Detailed performance.
WID_PHG_BACKGROUND, ///< Background of the window.
WID_PHG_GRAPH, ///< Graph itself.
WID_PHG_RESIZE, ///< Resize button.
};
/** Widget of the #PaymentRatesGraphWindow class. */
enum CargoPaymentRatesWidgets {
WID_CPR_BACKGROUND, ///< Background of the window.
WID_CPR_HEADER, ///< Header.
WID_CPR_GRAPH, ///< Graph itself.
WID_CPR_RESIZE, ///< Resize button.
WID_CPR_FOOTER, ///< Footer.
WID_CPR_ENABLE_CARGOES, ///< Enable cargoes button.
WID_CPR_DISABLE_CARGOES, ///< Disable cargoes button.
WID_CPR_MATRIX, ///< Cargo list.
@@ -52,7 +39,7 @@ enum CargoPaymentRatesWidgets {
};
/** Widget of the #PerformanceRatingDetailWindow class. */
enum PerformanceRatingDetailsWidgets {
enum PerformanceRatingDetailsWidgets : WidgetID {
WID_PRD_SCORE_FIRST, ///< First entry in the score list.
WID_PRD_SCORE_LAST = WID_PRD_SCORE_FIRST + (SCORE_END - SCORE_BEGIN) - 1, ///< Last entry in the score list.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_GROUP_WIDGET_H
/** Widgets of the #VehicleGroupWindow class. */
enum GroupListWidgets {
enum GroupListWidgets : WidgetID {
WID_GL_CAPTION, ///< Caption of the window.
WID_GL_GROUP_BY_ORDER, ///< Group order.
WID_GL_GROUP_BY_DROPDOWN, ///< Group by dropdown list.

25
src/widgets/help_widget.h Normal file
View File

@@ -0,0 +1,25 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file help_widget.h Types related to the help window widgets. */
#ifndef WIDGETS_HELP_WIDGET_H
#define WIDGETS_HELP_WIDGET_H
/** Widgets of the #HelpWindow class. */
enum HelpWindowWidgets : WidgetID {
WID_HW_README,
WID_HW_CHANGELOG,
WID_HW_KNOWN_BUGS,
WID_HW_LICENSE,
WID_HW_WEBSITE,
WID_HW_WIKI,
WID_HW_BUGTRACKER,
WID_HW_COMMUNITY,
};
#endif /* WIDGETS_HELP_WIDGET_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_HIGHSCORE_WIDGET_H
/** Widgets of the #EndGameHighScoreBaseWindow class and #HighScoreWindow class. */
enum HighscoreWidgets {
enum HighscoreWidgets : WidgetID {
WID_H_BACKGROUND, ///< Background of the window.
};

View File

@@ -11,7 +11,7 @@
#define WIDGETS_INDUSTRY_WIDGET_H
/** Widgets of the #BuildIndustryWindow class. */
enum DynamicPlaceIndustriesWidgets {
enum DynamicPlaceIndustriesWidgets : WidgetID {
WID_DPI_SCENARIO_EDITOR_PANE, ///< Pane containing SE-only widgets.
WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET, ///< Remove all industries button.
WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET, ///< Create random industries button.
@@ -23,7 +23,7 @@ enum DynamicPlaceIndustriesWidgets {
};
/** Widgets of the #IndustryViewWindow class. */
enum IndustryViewWidgets {
enum IndustryViewWidgets : WidgetID {
WID_IV_CAPTION, ///< Caption of the window.
WID_IV_VIEWPORT, ///< Viewport of the industry.
WID_IV_INFO, ///< Info of the industry.
@@ -32,17 +32,19 @@ enum IndustryViewWidgets {
};
/** Widgets of the #IndustryDirectoryWindow class. */
enum IndustryDirectoryWidgets {
enum IndustryDirectoryWidgets : WidgetID {
WID_ID_DROPDOWN_ORDER, ///< Dropdown for the order of the sort.
WID_ID_DROPDOWN_CRITERIA, ///< Dropdown for the criteria of the sort.
WID_ID_FILTER_BY_ACC_CARGO, ///< Accepted cargo filter dropdown list.
WID_ID_FILTER_BY_PROD_CARGO, ///< Produced cargo filter dropdown list.
WID_ID_FILTER, ///< Textbox to filter industry name.
WID_ID_INDUSTRY_LIST, ///< Industry list.
WID_ID_SCROLLBAR, ///< Scrollbar of the list.
WID_ID_HSCROLLBAR, ///< Horizontal scrollbar of the list.
WID_ID_VSCROLLBAR, ///< Vertical scrollbar of the list.
};
/** Widgets of the #IndustryCargoesWindow class */
enum IndustryCargoesWidgets {
enum IndustryCargoesWidgets : WidgetID {
WID_IC_CAPTION, ///< Caption of the window.
WID_IC_NOTIFY, ///< Row of buttons at the bottom.
WID_IC_PANEL, ///< Panel that shows the chain.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_INTRO_WIDGET_H
/** Widgets of the #SelectGameWindow class. */
enum SelectGameIntroWidgets {
enum SelectGameIntroWidgets : WidgetID {
WID_SGI_GENERATE_GAME, ///< Generate game button.
WID_SGI_LOAD_GAME, ///< Load game button.
WID_SGI_PLAY_SCENARIO, ///< Play scenario button.
@@ -28,6 +28,7 @@ enum SelectGameIntroWidgets {
WID_SGI_TRANSLATION, ///< Translation errors.
WID_SGI_OPTIONS, ///< Options button.
WID_SGI_HIGHSCORE, ///< Highscore button.
WID_SGI_HELP, ///< Help and manuals button.
WID_SGI_SETTINGS_OPTIONS, ///< Settings button.
WID_SGI_GRF_SETTINGS, ///< NewGRF button.
WID_SGI_CONTENT_DOWNLOAD, ///< Content Download button.

View File

@@ -11,12 +11,12 @@
#define WIDGETS_LEAGUE_WIDGET_H
/** Widget of the #PerformanceLeagueWindow class. */
enum PerformanceLeagueWidgets {
enum PerformanceLeagueWidgets : WidgetID {
WID_PLT_BACKGROUND, ///< Background of the window.
};
/** Widget of the #ScriptLeagueWindow class. */
enum ScriptLeagueWidgets {
enum ScriptLeagueWidgets : WidgetID {
WID_SLT_CAPTION, ///< Caption of the window.
WID_SLT_BACKGROUND, ///< Background of the window.
};

View File

@@ -14,7 +14,7 @@
/** Widgets of the WC_LINKGRAPH_LEGEND. */
enum LinkGraphLegendWidgets {
enum LinkGraphLegendWidgets : WidgetID {
WID_LGL_CAPTION, ///< Caption widget.
WID_LGL_SATURATION, ///< Saturation legend.
WID_LGL_SATURATION_FIRST,

View File

@@ -11,7 +11,7 @@
#define WIDGETS_MAIN_WIDGET_H
/** Widgets of the #MainWindow class. */
enum MainWidgets {
enum MainWidgets : WidgetID {
WID_M_VIEWPORT, ///< Main window viewport.
};

View File

@@ -11,25 +11,25 @@
#define WIDGETS_MISC_WIDGET_H
/** Widgets of the #LandInfoWindow class. */
enum LandInfoWidgets {
enum LandInfoWidgets : WidgetID {
WID_LI_LOCATION, ///< Scroll to location.
WID_LI_BACKGROUND, ///< Background of the window.
};
/** Widgets of the #TooltipsWindow class. */
enum ToolTipsWidgets {
enum ToolTipsWidgets : WidgetID {
WID_TT_BACKGROUND, ///< Background of the window.
};
/** Widgets of the #AboutWindow class. */
enum AboutWidgets {
enum AboutWidgets : WidgetID {
WID_A_SCROLLING_TEXT, ///< The actually scrolling text.
WID_A_WEBSITE, ///< URL of OpenTTD website.
WID_A_COPYRIGHT, ///< Copyright string
};
/** Widgets of the #QueryStringWindow class. */
enum QueryStringWidgets {
enum QueryStringWidgets : WidgetID {
WID_QS_CAPTION, ///< Caption of the window.
WID_QS_TEXT, ///< Text of the query.
WID_QS_WARNING, ///< Warning label about password security
@@ -39,7 +39,7 @@ enum QueryStringWidgets {
};
/** Widgets of the #QueryWindow class. */
enum QueryWidgets {
enum QueryWidgets : WidgetID {
WID_Q_CAPTION, ///< Caption of the window.
WID_Q_TEXT, ///< Text of the query.
WID_Q_NO, ///< Yes button.
@@ -47,12 +47,16 @@ enum QueryWidgets {
};
/** Widgets of the #TextfileWindow class. */
enum TextfileWidgets {
WID_TF_CAPTION, ///< The caption of the window.
WID_TF_WRAPTEXT, ///< Whether or not to wrap the text.
WID_TF_BACKGROUND, ///< Panel to draw the textfile on.
WID_TF_VSCROLLBAR, ///< Vertical scrollbar to scroll through the textfile up-and-down.
WID_TF_HSCROLLBAR, ///< Horizontal scrollbar to scroll through the textfile left-to-right.
enum TextfileWidgets : WidgetID {
WID_TF_CAPTION, ///< The caption of the window.
WID_TF_NAVBACK, ///< Navigate back button.
WID_TF_NAVFORWARD, ///< Navigate forward button.
WID_TF_WRAPTEXT, ///< Whether or not to wrap the text.
WID_TF_JUMPLIST, ///< List to jump around the file.
WID_TF_SEL_JUMPLIST, ///< Selection to display the jump list or not.
WID_TF_BACKGROUND, ///< Panel to draw the textfile on.
WID_TF_VSCROLLBAR, ///< Vertical scrollbar to scroll through the textfile up-and-down.
WID_TF_HSCROLLBAR, ///< Horizontal scrollbar to scroll through the textfile left-to-right.
};
#endif /* WIDGETS_MISC_WIDGET_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_MUSIC_WIDGET_H
/** Widgets of the #MusicTrackSelectionWindow class. */
enum MusicTrackSelectionWidgets {
enum MusicTrackSelectionWidgets : WidgetID {
WID_MTS_CAPTION, ///< Window caption.
WID_MTS_LIST_LEFT, ///< Left button.
WID_MTS_LEFT_SCROLLBAR, ///< Scrollbar of left list.
@@ -29,7 +29,7 @@ enum MusicTrackSelectionWidgets {
};
/** Widgets of the #MusicWindow class. */
enum MusicWidgets {
enum MusicWidgets : WidgetID {
WID_M_PREV, ///< Previous button.
WID_M_NEXT, ///< Next button.
WID_M_STOP, ///< Stop button.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_NETWORK_CHAT_WIDGET_H
/** Widgets of the #NetworkChatWindow class. */
enum NetWorkChatWidgets {
enum NetWorkChatWidgets : WidgetID {
WID_NC_CLOSE, ///< Close button.
WID_NC_BACKGROUND, ///< Background of the window.
WID_NC_DESTINATION, ///< Destination.

View File

@@ -13,14 +13,14 @@
#include "../textfile_type.h"
/** Widgets of the #NetworkContentDownloadStatusWindow class. */
enum NetworkContentDownloadStatusWidgets {
enum NetworkContentDownloadStatusWidgets : WidgetID {
WID_NCDS_PROGRESS_BAR, ///< Simple progress bar.
WID_NCDS_PROGRESS_TEXT, ///< Text explaining what is happening.
WID_NCDS_CANCELOK, ///< (Optional) Cancel/OK button.
};
/** Widgets of the #NetworkContentListWindow class. */
enum NetworkContentListWidgets {
enum NetworkContentListWidgets : WidgetID {
WID_NCL_BACKGROUND, ///< Resize button.
WID_NCL_FILTER_CAPT, ///< Caption for the filter editbox.
@@ -36,7 +36,7 @@ enum NetworkContentListWidgets {
WID_NCL_DETAILS, ///< Panel with content details.
WID_NCL_TEXTFILE, ///< Open readme, changelog (+1) or license (+2) of a file in the content window.
WID_NCL_SELECT_ALL = WID_NCL_TEXTFILE + TFT_END, ///< 'Select all' button.
WID_NCL_SELECT_ALL = WID_NCL_TEXTFILE + TFT_CONTENT_END, ///< 'Select all' button.
WID_NCL_SELECT_UPDATE, ///< 'Select updates' button.
WID_NCL_UNSELECT, ///< 'Unselect all' button.
WID_NCL_OPEN_URL, ///< 'Open url' button.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_NETWORK_WIDGET_H
/** Widgets of the #NetworkGameWindow class. */
enum NetworkGameWidgets {
enum NetworkGameWidgets : WidgetID {
WID_NG_MAIN, ///< Main panel.
WID_NG_CLIENT_LABEL, ///< Label in front of client name edit box.
@@ -19,7 +19,6 @@ enum NetworkGameWidgets {
WID_NG_FILTER_LABEL, ///< Label in front of the filter/search edit box.
WID_NG_FILTER, ///< Panel with the edit box to enter the search text.
WID_NG_HEADER, ///< Header container of the matrix.
WID_NG_NAME, ///< 'Name' button.
WID_NG_CLIENTS, ///< 'Clients' button.
WID_NG_MAPSIZE, ///< 'Map size' button.
@@ -35,7 +34,6 @@ enum NetworkGameWidgets {
WID_NG_LASTJOINED_SPACER, ///< Spacer after last joined server panel.
WID_NG_DETAILS, ///< Panel with game details.
WID_NG_DETAILS_SPACER, ///< Spacer for game actual details.
WID_NG_JOIN, ///< 'Join game' button.
WID_NG_REFRESH, ///< 'Refresh server' button.
WID_NG_NEWGRF, ///< 'NewGRF Settings' button.
@@ -51,7 +49,7 @@ enum NetworkGameWidgets {
};
/** Widgets of the #NetworkStartServerWindow class. */
enum NetworkStartServerWidgets {
enum NetworkStartServerWidgets : WidgetID {
WID_NSS_BACKGROUND, ///< Background of the window.
WID_NSS_GAMENAME_LABEL, ///< Label for the game name.
WID_NSS_GAMENAME, ///< Background for editbox to set game name.
@@ -76,7 +74,7 @@ enum NetworkStartServerWidgets {
};
/** Widgets of the #NetworkClientListWindow class. */
enum ClientListWidgets {
enum ClientListWidgets : WidgetID {
WID_CL_PANEL, ///< Panel of the window.
WID_CL_SERVER_SELECTOR, ///< Selector to hide the server frame.
WID_CL_SERVER_NAME, ///< Server name.
@@ -94,14 +92,14 @@ enum ClientListWidgets {
};
/** Widgets of the #NetworkJoinStatusWindow class. */
enum NetworkJoinStatusWidgets {
enum NetworkJoinStatusWidgets : WidgetID {
WID_NJS_PROGRESS_BAR, ///< Simple progress bar.
WID_NJS_PROGRESS_TEXT, ///< Text explaining what is happening.
WID_NJS_CANCELOK, ///< Cancel / OK button.
};
/** Widgets of the #NetworkCompanyPasswordWindow class. */
enum NetworkCompanyPasswordWidgets {
enum NetworkCompanyPasswordWidgets : WidgetID {
WID_NCP_BACKGROUND, ///< Background of the window.
WID_NCP_LABEL, ///< Label in front of the password field.
WID_NCP_PASSWORD, ///< Input field for the password.
@@ -112,7 +110,7 @@ enum NetworkCompanyPasswordWidgets {
};
/** Widgets of the #NetworkAskRelayWindow class. */
enum NetworkAskRelayWidgets {
enum NetworkAskRelayWidgets : WidgetID {
WID_NAR_CAPTION, ///< Caption of the window.
WID_NAR_TEXT, ///< Text in the window.
WID_NAR_NO, ///< "No" button.
@@ -120,4 +118,14 @@ enum NetworkAskRelayWidgets {
WID_NAR_YES_ALWAYS, ///< "Yes, always" button.
};
/** Widgets of the #NetworkAskSurveyWindow class. */
enum NetworkAskSurveyWidgets : WidgetID {
WID_NAS_CAPTION, ///< Caption of the window.
WID_NAS_TEXT, ///< Text in the window.
WID_NAS_PREVIEW, ///< "Preview" button.
WID_NAS_LINK, ///< "Details & Privacy" button.
WID_NAS_NO, ///< "No" button.
WID_NAS_YES, ///< "Yes" button.
};
#endif /* WIDGETS_NETWORK_WIDGET_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_NEWGRF_DEBUG_WIDGET_H
/** Widgets of the #NewGRFInspectWindow class. */
enum NewGRFInspectWidgets {
enum NewGRFInspectWidgets : WidgetID {
WID_NGRFI_CAPTION, ///< The caption bar of course.
WID_NGRFI_PARENT, ///< Inspect the parent.
WID_NGRFI_VEH_PREV, ///< Go to previous vehicle in chain.
@@ -22,7 +22,7 @@ enum NewGRFInspectWidgets {
};
/** Widgets of the #SpriteAlignerWindow class. */
enum SpriteAlignerWidgets {
enum SpriteAlignerWidgets : WidgetID {
WID_SA_CAPTION, ///< Caption of the window.
WID_SA_PREVIOUS, ///< Skip to the previous sprite.
WID_SA_GOTO, ///< Go to a given sprite.
@@ -37,6 +37,8 @@ enum SpriteAlignerWidgets {
WID_SA_PICKER, ///< Sprite picker.
WID_SA_LIST, ///< Queried sprite list.
WID_SA_SCROLLBAR, ///< Scrollbar for sprite list.
WID_SA_ZOOM, ///< Zoom level buttons (from ZOOM_LVL_BEGIN to ZOOM_LVL_END).
WID_SA_ZOOM_LAST = WID_SA_ZOOM + ZOOM_LVL_END - 1, ///< Marker for last zoom level button.
WID_SA_RESET_REL, ///< Reset relative sprite offset
WID_SA_CENTRE, ///< Toggle centre sprite.
WID_SA_CROSSHAIR, ///< Toggle crosshair.

View File

@@ -14,7 +14,8 @@
#include "../textfile_type.h"
/** Widgets of the #NewGRFParametersWindow class. */
enum NewGRFParametersWidgets {
enum NewGRFParametersWidgets : WidgetID {
WID_NP_CAPTION, ///< Caption of the window.
WID_NP_SHOW_NUMPAR, ///< #NWID_SELECTION to optionally display #WID_NP_NUMPAR.
WID_NP_NUMPAR_DEC, ///< Button to decrease number of parameters.
WID_NP_NUMPAR_INC, ///< Button to increase number of parameters.
@@ -26,10 +27,12 @@ enum NewGRFParametersWidgets {
WID_NP_RESET, ///< Reset button.
WID_NP_SHOW_DESCRIPTION, ///< #NWID_SELECTION to optionally display parameter descriptions.
WID_NP_DESCRIPTION, ///< Multi-line description of a parameter.
WID_NP_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
/** Widgets of the #NewGRFWindow class. */
enum NewGRFStateWidgets {
enum NewGRFStateWidgets : WidgetID {
WID_NS_PRESET_LIST, ///< Active NewGRF preset.
WID_NS_PRESET_SAVE, ///< Save list of active NewGRFs as presets.
WID_NS_PRESET_DELETE, ///< Delete active preset.
@@ -47,7 +50,7 @@ enum NewGRFStateWidgets {
WID_NS_NEWGRF_INFO, ///< Panel for Info on selected NewGRF.
WID_NS_OPEN_URL, ///< Open URL of NewGRF.
WID_NS_NEWGRF_TEXTFILE, ///< Open NewGRF readme, changelog (+1) or license (+2).
WID_NS_SET_PARAMETERS = WID_NS_NEWGRF_TEXTFILE + TFT_END, ///< Open Parameters Window for selected NewGRF for editing parameters.
WID_NS_SET_PARAMETERS = WID_NS_NEWGRF_TEXTFILE + TFT_CONTENT_END, ///< Open Parameters Window for selected NewGRF for editing parameters.
WID_NS_VIEW_PARAMETERS, ///< Open Parameters Window for selected NewGRF for viewing parameters.
WID_NS_TOGGLE_PALETTE, ///< Toggle Palette of selected, active NewGRF.
WID_NS_APPLY_CHANGES, ///< Apply changes to NewGRF config.
@@ -60,7 +63,7 @@ enum NewGRFStateWidgets {
};
/** Widgets of the #SavePresetWindow class. */
enum SavePresetWidgets {
enum SavePresetWidgets : WidgetID {
WID_SVP_PRESET_LIST, ///< List with available preset names.
WID_SVP_SCROLLBAR, ///< Scrollbar for the list available preset names.
WID_SVP_EDITBOX, ///< Edit box for changing the preset name.
@@ -69,7 +72,7 @@ enum SavePresetWidgets {
};
/** Widgets of the #ScanProgressWindow class. */
enum ScanProgressWidgets {
enum ScanProgressWidgets : WidgetID {
WID_SP_PROGRESS_BAR, ///< Simple progress bar.
WID_SP_PROGRESS_TEXT, ///< Text explaining what is happening.
};

View File

@@ -13,7 +13,7 @@
#include "../news_type.h"
/** Widgets of the #NewsWindow class. */
enum NewsWidgets {
enum NewsWidgets : WidgetID {
WID_N_PANEL, ///< Panel of the window.
WID_N_TITLE, ///< Title of the company news.
WID_N_HEADLINE, ///< The news headline.
@@ -35,7 +35,7 @@ enum NewsWidgets {
};
/** Widgets of the #MessageHistoryWindow class. */
enum MessageHistoryWidgets {
enum MessageHistoryWidgets : WidgetID {
WID_MH_STICKYBOX, ///< Stickybox.
WID_MH_BACKGROUND, ///< Background of the window.
WID_MH_SCROLLBAR, ///< Scrollbar for the list.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_OBJECT_WIDGET_H
/** Widgets of the #BuildObjectWindow class. */
enum BuildObjectWidgets {
enum BuildObjectWidgets : WidgetID {
WID_BO_FILTER, ///< The filter text box for the object list.
WID_BO_CLASS_LIST, ///< The list with classes.
WID_BO_SCROLLBAR, ///< The scrollbar associated with the list.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_ORDER_WIDGET_H
/** Widgets of the #OrdersWindow class. */
enum OrderWidgets {
enum OrderWidgets : WidgetID {
WID_O_CAPTION, ///< Caption of the window.
WID_O_TIMETABLE_VIEW, ///< Toggle timetable view.
WID_O_ORDER_LIST, ///< Order list panel.
@@ -20,12 +20,12 @@ enum OrderWidgets {
WID_O_DELETE, ///< Delete selected order.
WID_O_STOP_SHARING, ///< Stop sharing orders.
WID_O_NON_STOP, ///< Goto non-stop to destination.
WID_O_DEPOT_UNBUNCHING, ///< Toggle unbunching.
WID_O_GOTO, ///< Goto destination.
WID_O_FULL_LOAD, ///< Select full load.
WID_O_UNLOAD, ///< Select unload.
WID_O_REFIT, ///< Select refit.
WID_O_SERVICE, ///< Select service (at depot).
WID_O_EMPTY, ///< Placeholder for refit dropdown when not owner.
WID_O_DEPOT_ACTION, ///< Dropdown to select the depot action (stop, service if needed, unbunch).
WID_O_REFIT_DROPDOWN, ///< Open refit options.
WID_O_COND_VARIABLE, ///< Choose condition variable.
WID_O_COND_COMPARATOR, ///< Choose condition type.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_OSK_WIDGET_H
/** Widgets of the #OskWindow class. */
enum OnScreenKeyboardWidgets {
enum OnScreenKeyboardWidgets : WidgetID {
WID_OSK_CAPTION, ///< Caption of window.
WID_OSK_TEXT, ///< Edit box.
WID_OSK_CANCEL, ///< Cancel key.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_RAIL_WIDGET_H
/** Widgets of the #BuildRailToolbarWindow class. */
enum RailToolbarWidgets {
enum RailToolbarWidgets : WidgetID {
/* Name starts with RA instead of R, because of collision with RoadToolbarWidgets */
WID_RAT_CAPTION, ///< Caption of the window.
WID_RAT_BUILD_NS, ///< Build rail along the game view Y axis.
@@ -28,10 +28,12 @@ enum RailToolbarWidgets {
WID_RAT_BUILD_TUNNEL, ///< Build a tunnel.
WID_RAT_REMOVE, ///< Bulldozer to remove rail.
WID_RAT_CONVERT_RAIL, ///< Convert other rail to this type.
INVALID_WID_RAT = -1,
};
/** Widgets of the #BuildRailStationWindow class. */
enum BuildRailStationWidgets {
enum BuildRailStationWidgets : WidgetID {
/* Name starts with BRA instead of BR, because of collision with BuildRoadStationWidgets */
WID_BRAS_PLATFORM_DIR_X, ///< Button to select '/' view.
WID_BRAS_PLATFORM_DIR_Y, ///< Button to select '\' view.
@@ -78,7 +80,7 @@ enum BuildRailStationWidgets {
};
/** Widgets of the #BuildSignalWindow class. */
enum BuildSignalWidgets {
enum BuildSignalWidgets : WidgetID {
WID_BS_CAPTION, ///< Caption for the Signal Selection window.
WID_BS_TOGGLE_SIZE, ///< Toggle showing advanced signal types.
WID_BS_SEMAPHORE_NORM, ///< Build a semaphore normal block signal.
@@ -97,18 +99,12 @@ enum BuildSignalWidgets {
WID_BS_DRAG_SIGNALS_DENSITY_LABEL, ///< The current signal density.
WID_BS_DRAG_SIGNALS_DENSITY_DECREASE, ///< Decrease the signal density.
WID_BS_DRAG_SIGNALS_DENSITY_INCREASE, ///< Increase the signal density.
WID_BS_SEMAPHORE_NORM_SEL, ///< NWID_SELECTION for WID_BS_SEMAPHORE_NORM.
WID_BS_ELECTRIC_NORM_SEL, ///< NWID_SELECTION for WID_BS_ELECTRIC_NORM.
WID_BS_SEMAPHORE_ENTRY_SEL, ///< NWID_SELECTION for WID_BS_SEMAPHORE_ENTRY.
WID_BS_ELECTRIC_ENTRY_SEL, ///< NWID_SELECTION for WID_BS_ELECTRIC_ENTRY.
WID_BS_SEMAPHORE_EXIT_SEL, ///< NWID_SELECTION for WID_BS_SEMAPHORE_EXIT.
WID_BS_ELECTRIC_EXIT_SEL, ///< NWID_SELECTION for WID_BS_ELECTRIC_EXIT.
WID_BS_SEMAPHORE_COMBO_SEL, ///< NWID_SELECTION for WID_BS_SEMAPHORE_COMBO.
WID_BS_ELECTRIC_COMBO_SEL, ///< NWID_SELECTION for WID_BS_ELECTRIC_COMBO.
WID_BS_BLOCK_SEL, ///< Container for the block signal group, which can be hidden.
WID_BS_BLOCK_SPACER_SEL, ///< Container for the spacer between block and path signal groups, which can be hidden.
};
/** Widgets of the #BuildRailDepotWindow class. */
enum BuildRailDepotWidgets {
enum BuildRailDepotWidgets : WidgetID {
/* Name starts with BRA instead of BR, because of collision with BuildRoadDepotWidgets */
WID_BRAD_DEPOT_NE, ///< Build a depot with the entrance in the north east.
WID_BRAD_DEPOT_SE, ///< Build a depot with the entrance in the south east.
@@ -117,10 +113,12 @@ enum BuildRailDepotWidgets {
};
/** Widgets of the #BuildRailWaypointWindow class. */
enum BuildRailWaypointWidgets {
enum BuildRailWaypointWidgets : WidgetID {
WID_BRW_FILTER, ///< Text filter.
WID_BRW_WAYPOINT_MATRIX, ///< Matrix with waypoints.
WID_BRW_WAYPOINT, ///< A single waypoint.
WID_BRW_SCROLL, ///< Scrollbar for the matrix.
WID_BRW_NAME, ///< Name of selected waypoint.
};
#endif /* WIDGETS_RAIL_WIDGET_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_ROAD_WIDGET_H
/** Widgets of the #BuildRoadToolbarWindow class. */
enum RoadToolbarWidgets {
enum RoadToolbarWidgets : WidgetID {
/* Name starts with RO instead of R, because of collision with RailToolbarWidgets */
WID_ROT_CAPTION, ///< Caption of the window
WID_ROT_ROAD_X, ///< Build road in x-direction.
@@ -26,10 +26,12 @@ enum RoadToolbarWidgets {
WID_ROT_BUILD_TUNNEL, ///< Build tunnel.
WID_ROT_REMOVE, ///< Remove road.
WID_ROT_CONVERT_ROAD, ///< Convert road.
INVALID_WID_ROT = -1,
};
/** Widgets of the #BuildRoadDepotWindow class. */
enum BuildRoadDepotWidgets {
enum BuildRoadDepotWidgets : WidgetID {
/* Name starts with BRO instead of BR, because of collision with BuildRailDepotWidgets */
WID_BROD_CAPTION, ///< Caption of the window.
WID_BROD_DEPOT_NE, ///< Depot with NE entry.
@@ -39,20 +41,33 @@ enum BuildRoadDepotWidgets {
};
/** Widgets of the #BuildRoadStationWindow class. */
enum BuildRoadStationWidgets {
enum BuildRoadStationWidgets : WidgetID {
/* Name starts with BRO instead of BR, because of collision with BuildRailStationWidgets */
WID_BROS_CAPTION, ///< Caption of the window.
WID_BROS_BACKGROUND, ///< Background of the window.
WID_BROS_STATION_NE, ///< Terminal station with NE entry.
WID_BROS_STATION_SE, ///< Terminal station with SE entry.
WID_BROS_STATION_SW, ///< Terminal station with SW entry.
WID_BROS_STATION_NW, ///< Terminal station with NW entry.
WID_BROS_STATION_X, ///< Drive-through station in x-direction.
WID_BROS_STATION_Y, ///< Drive-through station in y-direction.
WID_BROS_LT_OFF, ///< Turn off area highlight.
WID_BROS_LT_ON, ///< Turn on area highlight.
WID_BROS_INFO, ///< Station acceptance toggle.
WID_BROS_ACCEPTANCE, ///< Station acceptance.
WID_BROS_CAPTION, ///< Caption of the window.
WID_BROS_STATION_NE, ///< Terminal station with NE entry.
WID_BROS_STATION_SE, ///< Terminal station with SE entry.
WID_BROS_STATION_SW, ///< Terminal station with SW entry.
WID_BROS_STATION_NW, ///< Terminal station with NW entry.
WID_BROS_STATION_X, ///< Drive-through station in x-direction.
WID_BROS_STATION_Y, ///< Drive-through station in y-direction.
WID_BROS_LT_OFF, ///< Turn off area highlight.
WID_BROS_LT_ON, ///< Turn on area highlight.
WID_BROS_ACCEPTANCE, ///< Station acceptance info.
WID_BROS_MATRIX, ///< Matrix widget displaying all available road stops.
WID_BROS_IMAGE, ///< Panel used for each image of the matrix.
WID_BROS_MATRIX_SCROLL, ///< Scrollbar of the #WID_BROS_SHOW_NEWST_ADDITIONS.
WID_BROS_FILTER_CONTAINER, ///< Container for the filter text box for the road stop class list.
WID_BROS_FILTER_EDITBOX, ///< Filter text box for the road stop class list.
WID_BROS_AVAILABLE_ORIENTATIONS, ///< Selection for selecting 6 or 2 orientations.
WID_BROS_SHOW_NEWST_DEFSIZE, ///< Selection for default-size button for new road stops.
WID_BROS_SHOW_NEWST_ADDITIONS, ///< Selection for new class selection list.
WID_BROS_SHOW_NEWST_MATRIX, ///< Selection for new stop image matrix.
WID_BROS_SHOW_NEWST_RESIZE, ///< Selection for panel and resize at bottom right for new stops.
WID_BROS_SHOW_NEWST_ORIENTATION, ///< Selection for the orientation string for new stops.
WID_BROS_SHOW_NEWST_TYPE_SEL, ///< Selection for the type name.
WID_BROS_SHOW_NEWST_TYPE, ///< Display of selected stop type.
WID_BROS_NEWST_LIST, ///< List with new road stops.
WID_BROS_NEWST_SCROLL, ///< Scrollbar of the #WID_BROS_NEWST_LIST.
};
#endif /* WIDGETS_ROAD_WIDGET_H */

View File

@@ -12,7 +12,7 @@
/** Widgets of the #ScreenshotWindow class. */
enum ScreenshotWindowWidgets {
enum ScreenshotWindowWidgets : WidgetID {
WID_SC_TAKE, ///< Button for taking a normal screenshot
WID_SC_TAKE_ZOOMIN, ///< Button for taking a zoomed in screenshot
WID_SC_TAKE_DEFAULTZOOM, ///< Button for taking a screenshot at normal zoom

View File

@@ -0,0 +1,55 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_widget.h Types related to the script widgets. */
#ifndef WIDGETS_SCRIPT_WIDGET_H
#define WIDGETS_SCRIPT_WIDGET_H
#include "../company_type.h"
/** Widgets of the #ScriptListWindow class. */
enum ScriptListWidgets : WidgetID {
WID_SCRL_CAPTION, ///< Caption of the window.
WID_SCRL_LIST, ///< The matrix with all available Scripts.
WID_SCRL_SCROLLBAR, ///< Scrollbar next to the Script list.
WID_SCRL_INFO_BG, ///< Panel to draw some Script information on.
WID_SCRL_ACCEPT, ///< Accept button.
WID_SCRL_CANCEL, ///< Cancel button.
};
/** Widgets of the #ScriptSettingsWindow class. */
enum ScriptSettingsWidgets : WidgetID {
WID_SCRS_CAPTION, ///< Caption of the window.
WID_SCRS_BACKGROUND, ///< Panel to draw the settings on.
WID_SCRS_SCROLLBAR, ///< Scrollbar to scroll through all settings.
WID_SCRS_ACCEPT, ///< Accept button.
WID_SCRS_RESET, ///< Reset button.
WID_SCRS_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
/** Widgets of the #ScriptDebugWindow class. */
enum ScriptDebugWidgets : WidgetID {
WID_SCRD_VIEW, ///< The row of company buttons.
WID_SCRD_NAME_TEXT, ///< Name of the current selected.
WID_SCRD_SETTINGS, ///< Settings button.
WID_SCRD_SCRIPT_GAME, ///< Game Script button.
WID_SCRD_RELOAD_TOGGLE, ///< Reload button.
WID_SCRD_LOG_PANEL, ///< Panel where the log is in.
WID_SCRD_VSCROLLBAR, ///< Vertical scrollbar of the log panel.
WID_SCRD_COMPANY_BUTTON_START, ///< Buttons in the VIEW.
WID_SCRD_COMPANY_BUTTON_END = WID_SCRD_COMPANY_BUTTON_START + MAX_COMPANIES - 1, ///< Last possible button in the VIEW.
WID_SCRD_BREAK_STRING_WIDGETS, ///< The panel to handle the breaking on string.
WID_SCRD_BREAK_STR_ON_OFF_BTN, ///< Enable breaking on string.
WID_SCRD_BREAK_STR_EDIT_BOX, ///< Edit box for the string to break on.
WID_SCRD_MATCH_CASE_BTN, ///< Checkbox to use match caching or not.
WID_SCRD_CONTINUE_BTN, ///< Continue button.
WID_SCRD_HSCROLLBAR, ///< Horizontal scrollbar of the log panel.
};
#endif /* WIDGETS_SCRIPT_WIDGET_H */

View File

@@ -11,8 +11,12 @@
#define WIDGETS_SETTINGS_WIDGET_H
/** Widgets of the #GameOptionsWindow class. */
enum GameOptionsWidgets {
WID_GO_BACKGROUND, ///< Background of the window.
enum GameOptionsWidgets : WidgetID {
WID_GO_TAB_GENERAL, ///< General tab.
WID_GO_TAB_GRAPHICS, ///< Graphics tab.
WID_GO_TAB_SOUND, ///< Sound tab.
WID_GO_TAB_SOCIAL, ///< Social tab.
WID_GO_TAB_SELECTION, ///< Background of the tab selection.
WID_GO_CURRENCY_DROPDOWN, ///< Currency dropdown.
WID_GO_DISTANCE_DROPDOWN, ///< Measuring unit dropdown.
WID_GO_AUTOSAVE_DROPDOWN, ///< Dropdown to say how often to autosave.
@@ -28,28 +32,42 @@ enum GameOptionsWidgets {
WID_GO_GUI_SCALE, ///< GUI Scale slider.
WID_GO_GUI_SCALE_AUTO, ///< Autodetect GUI scale button.
WID_GO_GUI_SCALE_BEVEL_BUTTON, ///< Toggle for chunky bevels.
WID_GO_GUI_FONT_SPRITE, ///< Toggle whether to prefer the sprite font over TTF fonts.
WID_GO_GUI_FONT_AA, ///< Toggle whether to anti-alias fonts.
WID_GO_BASE_GRF_DROPDOWN, ///< Use to select a base GRF.
WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc.
WID_GO_BASE_GRF_PARAMETERS, ///< Base GRF parameters.
WID_GO_BASE_GRF_OPEN_URL, ///< Open base GRF URL.
WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2).
WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_END, ///< Description of selected base GRF.
WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base GRF.
WID_GO_BASE_SFX_DROPDOWN, ///< Use to select a base SFX.
WID_GO_TEXT_SFX_VOLUME, ///< Sound effects volume label.
WID_GO_BASE_SFX_VOLUME, ///< Change sound effects volume.
WID_GO_BASE_SFX_OPEN_URL, ///< Open base SFX URL.
WID_GO_BASE_SFX_TEXTFILE, ///< Open base SFX readme, changelog (+1) or license (+2).
WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + TFT_END, ///< Description of selected base SFX.
WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base SFX.
WID_GO_BASE_MUSIC_DROPDOWN, ///< Use to select a base music set.
WID_GO_TEXT_MUSIC_VOLUME, ///< Music volume label.
WID_GO_BASE_MUSIC_VOLUME, ///< Change music volume.
WID_GO_BASE_MUSIC_JUKEBOX, ///< Open the jukebox.
WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc.
WID_GO_BASE_MUSIC_OPEN_URL, ///< Open base music URL.
WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2).
WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_END, ///< Description of selected base music set.
WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base music set.
WID_GO_VIDEO_ACCEL_BUTTON, ///< Toggle for video acceleration.
WID_GO_VIDEO_VSYNC_BUTTON, ///< Toggle for video vsync.
WID_GO_REFRESH_RATE_DROPDOWN, ///< Dropdown for all available refresh rates.
WID_GO_VIDEO_DRIVER_INFO, ///< Label showing details about the current video driver.
WID_GO_SURVEY_SEL, ///< Selection to hide survey if no JSON library is compiled in.
WID_GO_SURVEY_PARTICIPATE_BUTTON, ///< Toggle for participating in the automated survey.
WID_GO_SURVEY_LINK_BUTTON, ///< Button to open browser to go to the survey website.
WID_GO_SURVEY_PREVIEW_BUTTON, ///< Button to open a preview window with the survey results
WID_GO_SOCIAL_PLUGINS, ///< Main widget handling the social plugins.
WID_GO_SOCIAL_PLUGIN_TITLE, ///< Title of the frame of the social plugin.
WID_GO_SOCIAL_PLUGIN_PLATFORM, ///< Platform of the social plugin.
WID_GO_SOCIAL_PLUGIN_STATE, ///< State of the social plugin.
};
/** Widgets of the #GameSettingsWindow class. */
enum GameSettingsWidgets {
enum GameSettingsWidgets : WidgetID {
WID_GS_FILTER, ///< Text filter.
WID_GS_OPTIONSPANEL, ///< Panel widget containing the option lists.
WID_GS_SCROLLBAR, ///< Scrollbar.
@@ -61,15 +79,15 @@ enum GameSettingsWidgets {
WID_GS_RESTRICT_TYPE, ///< Label upfront to the type drop-down box to restrict the list of settings to show
WID_GS_RESTRICT_DROPDOWN, ///< The drop down box to restrict the list of settings
WID_GS_TYPE_DROPDOWN, ///< The drop down box to choose client/game/company/all settings
WID_GS_SETTING_DROPDOWN = -1, ///< Dynamically created dropdown for changing setting value.
};
/** Widgets of the #CustomCurrencyWindow class. */
enum CustomCurrencyWidgets {
enum CustomCurrencyWidgets : WidgetID {
WID_CC_RATE_DOWN, ///< Down button.
WID_CC_RATE_UP, ///< Up button.
WID_CC_RATE, ///< Rate of currency.
WID_CC_SEPARATOR_EDIT, ///< Separator edit button.
WID_CC_SEPARATOR, ///< Current separator.
WID_CC_PREFIX_EDIT, ///< Prefix edit button.
WID_CC_PREFIX, ///< Current prefix.
WID_CC_SUFFIX_EDIT, ///< Suffix edit button.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_SIGN_WIDGET_H
/** Widgets of the #SignListWindow class. */
enum SignListWidgets {
enum SignListWidgets : WidgetID {
/* Name starts with SI instead of S, because of collision with SaveLoadWidgets */
WID_SIL_CAPTION, ///< Caption of the window.
WID_SIL_LIST, ///< List of signs.
@@ -22,7 +22,7 @@ enum SignListWidgets {
};
/** Widgets of the #SignWindow class. */
enum QueryEditSignWidgets {
enum QueryEditSignWidgets : WidgetID {
WID_QES_CAPTION, ///< Caption of the window.
WID_QES_LOCATION, ///< Scroll to sign location.
WID_QES_TEXT, ///< Text of the query.

View File

@@ -8,6 +8,7 @@
/** @file slider.cpp Implementation of the horizontal slider widget. */
#include "../stdafx.h"
#include "../palette_func.h"
#include "../window_gui.h"
#include "../window_func.h"
#include "../strings_func.h"
@@ -29,7 +30,7 @@ static const int SLIDER_WIDTH = 3;
void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map<int, StringID> &labels)
{
/* Allow space for labels. We assume they are in the small font. */
if (labels.size() > 0) r.bottom -= FONT_HEIGHT_SMALL + WidgetDimensions::scaled.hsep_normal;
if (!labels.empty()) r.bottom -= GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.hsep_normal;
max_value -= min_value;

View File

@@ -13,8 +13,6 @@
#include "../window_type.h"
#include "../gfx_func.h"
#include <map>
void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map<int, StringID> &labels);
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &value);

View File

@@ -11,7 +11,7 @@
#define WIDGETS_SMALLMAP_WIDGET_H
/** Widgets of the #SmallMapWindow class. */
enum SmallMapWidgets {
enum SmallMapWidgets : WidgetID {
WID_SM_CAPTION, ///< Caption of the window.
WID_SM_MAP_BORDER, ///< Border around the smallmap.
WID_SM_MAP, ///< Panel containing the smallmap.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_STATION_WIDGET_H
/** Widgets of the #StationViewWindow class. */
enum StationViewWidgets {
enum StationViewWidgets : WidgetID {
WID_SV_CAPTION, ///< Caption of the window.
WID_SV_GROUP, ///< label for "group by"
WID_SV_GROUP_BY, ///< 'Group by' button
@@ -32,7 +32,7 @@ enum StationViewWidgets {
};
/** Widgets of the #CompanyStationsWindow class. */
enum StationListWidgets {
enum StationListWidgets : WidgetID {
/* Name starts with ST instead of S, because of collision with SaveLoadWidgets */
WID_STL_CAPTION, ///< Caption of the window.
WID_STL_LIST, ///< The main panel, list of stations.
@@ -46,17 +46,14 @@ enum StationListWidgets {
WID_STL_SHIP, ///< 'SHIP' button - list only facilities where is a dock.
WID_STL_FACILALL, ///< 'ALL' button - list all facilities.
WID_STL_NOCARGOWAITING, ///< 'NO' button - list stations where no cargo is waiting.
WID_STL_CARGOALL, ///< 'ALL' button - list all stations.
WID_STL_SORTBY, ///< 'Sort by' button - reverse sort direction.
WID_STL_SORTDROPBTN, ///< Dropdown button.
WID_STL_CARGOSTART, ///< Widget numbers used for list of cargo types (not present in _company_stations_widgets).
WID_STL_CARGODROPDOWN, ///< Cargo type dropdown list.
};
/** Widgets of the #SelectStationWindow class. */
enum JoinStationWidgets {
enum JoinStationWidgets : WidgetID {
WID_JS_CAPTION, // Caption of the window.
WID_JS_PANEL, // Main panel.
WID_JS_SCROLLBAR, // Scrollbar of the panel.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_STATUSBAR_WIDGET_H
/** Widgets of the #StatusBarWindow class. */
enum StatusbarWidgets {
enum StatusbarWidgets : WidgetID {
WID_S_LEFT, ///< Left part of the statusbar; date is shown there.
WID_S_MIDDLE, ///< Middle part; current news or company name or *** SAVING *** or *** PAUSED ***.
WID_S_RIGHT, ///< Right part; bank balance.

View File

@@ -12,7 +12,7 @@
#define WIDGETS_STORY_WIDGET_H
/** Widgets of the #GoalListWindow class. */
enum StoryBookWidgets {
enum StoryBookWidgets : WidgetID {
WID_SB_CAPTION, ///< Caption of the window.
WID_SB_SEL_PAGE, ///< Page selector.
WID_SB_PAGE_PANEL,///< Page body.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_SUBSIDY_WIDGET_H
/** Widgets of the #SubsidyListWindow class. */
enum SubsidyListWidgets {
enum SubsidyListWidgets : WidgetID {
/* Name starts with SU instead of S, because of collision with SaveLoadWidgets. */
WID_SUL_PANEL, ///< Main panel of window.
WID_SUL_SCROLLBAR, ///< Scrollbar of panel.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_TERRAFORM_WIDGET_H
/** Widgets of the #TerraformToolbarWindow class. */
enum TerraformToolbarWidgets {
enum TerraformToolbarWidgets : WidgetID {
WID_TT_SHOW_PLACE_OBJECT, ///< Should the place object button be shown?
WID_TT_BUTTONS_START, ///< Start of pushable buttons.
WID_TT_LOWER_LAND = WID_TT_BUTTONS_START, ///< Lower land button.
@@ -22,10 +22,12 @@ enum TerraformToolbarWidgets {
WID_TT_PLANT_TREES, ///< Plant trees button (note: opens separate window, no place-push-button).
WID_TT_PLACE_SIGN, ///< Place sign button.
WID_TT_PLACE_OBJECT, ///< Place object button.
INVALID_WID_TT = -1,
};
/** Widgets of the #ScenarioEditorLandscapeGenerationWindow class. */
enum EditorTerraformToolbarWidgets {
enum EditorTerraformToolbarWidgets : WidgetID {
WID_ETT_SHOW_PLACE_DESERT, ///< Should the place desert button be shown?
WID_ETT_START, ///< Used for iterations.
WID_ETT_DOTS = WID_ETT_START, ///< Invisible widget for rendering the terraform size on.
@@ -42,6 +44,8 @@ enum EditorTerraformToolbarWidgets {
WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size.
WID_ETT_NEW_SCENARIO, ///< Button for generating a new scenario.
WID_ETT_RESET_LANDSCAPE, ///< Button for removing all company-owned property.
INVALID_WID_ETT = -1,
};
#endif /* WIDGETS_TERRAFORM_WIDGET_H */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_TIMETABLE_WIDGET_H
/** Widgets of the #TimetableWindow class. */
enum VehicleTimetableWidgets {
enum VehicleTimetableWidgets : WidgetID {
WID_VT_CAPTION, ///< Caption of the window.
WID_VT_ORDER_VIEW, ///< Order view.
WID_VT_TIMETABLE_PANEL, ///< Timetable panel.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_TOOLBAR_WIDGET_H
/** Widgets of the #MainToolbarWindow class. */
enum ToolbarNormalWidgets {
enum ToolbarNormalWidgets : WidgetID {
WID_TN_PAUSE, ///< Pause the game.
WID_TN_FAST_FORWARD, ///< Fast forward the game.
WID_TN_SETTINGS, ///< Settings menu.
@@ -52,7 +52,7 @@ enum ToolbarNormalWidgets {
};
/** Widgets of the #ScenarioEditorToolbarWindow class. */
enum ToolbarEditorWidgets {
enum ToolbarEditorWidgets : WidgetID {
WID_TE_PAUSE, ///< Pause the game.
WID_TE_FAST_FORWARD, ///< Fast forward the game.
WID_TE_SETTINGS, ///< Settings menu.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_TOWN_WIDGET_H
/** Widgets of the #TownDirectoryWindow class. */
enum TownDirectoryWidgets {
enum TownDirectoryWidgets : WidgetID {
WID_TD_SORT_ORDER, ///< Direction of sort dropdown.
WID_TD_SORT_CRITERIA, ///< Criteria of sort dropdown.
WID_TD_FILTER, ///< Filter of name.
@@ -21,7 +21,7 @@ enum TownDirectoryWidgets {
};
/** Widgets of the #TownAuthorityWindow class. */
enum TownAuthorityWidgets {
enum TownAuthorityWidgets : WidgetID {
WID_TA_CAPTION, ///< Caption of window.
WID_TA_ZONE_BUTTON, ///< Turn on/off showing local authority zone.
WID_TA_RATING_INFO, ///< Overview with ratings for each company.
@@ -32,7 +32,7 @@ enum TownAuthorityWidgets {
};
/** Widgets of the #TownViewWindow class. */
enum TownViewWidgets {
enum TownViewWidgets : WidgetID {
WID_TV_CAPTION, ///< Caption of window.
WID_TV_VIEWPORT, ///< View of the center of the town.
WID_TV_INFO, ///< General information about the town.
@@ -45,7 +45,7 @@ enum TownViewWidgets {
};
/** Widgets of the #FoundTownWindow class. */
enum TownFoundingWidgets {
enum TownFoundingWidgets : WidgetID {
WID_TF_NEW_TOWN, ///< Create a new town.
WID_TF_RANDOM_TOWN, ///< Randomly place a town.
WID_TF_MANY_RANDOM_TOWNS, ///< Randomly place many towns.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_TRANSPARENCY_WIDGET_H
/** Widgets of the #TransparenciesWindow class. */
enum TransparencyToolbarWidgets {
enum TransparencyToolbarWidgets : WidgetID {
/* Button row. */
WID_TT_BEGIN, ///< First toggle button.
WID_TT_SIGNS = WID_TT_BEGIN, ///< Signs background transparency toggle button.
@@ -22,7 +22,7 @@ enum TransparencyToolbarWidgets {
WID_TT_BRIDGES, ///< Bridges transparency toggle button.
WID_TT_STRUCTURES, ///< Object structure transparency toggle button.
WID_TT_CATENARY, ///< Catenary transparency toggle button.
WID_TT_LOADING, ///< Loading indicators transparency toggle button.
WID_TT_TEXT, ///< Loading and cost/income text transparency toggle button.
WID_TT_END, ///< End of toggle buttons.
/* Panel with buttons for invisibility */

View File

@@ -11,7 +11,7 @@
#define WIDGETS_TREE_WIDGET_H
/** Widgets of the #BuildTreesWindow class. */
enum BuildTreesWidgets {
enum BuildTreesWidgets : WidgetID {
WID_BT_TYPE_RANDOM, ///< Button to build random type of tree.
WID_BT_SE_PANE, ///< Selection pane to show/hide scenario editor tools.
WID_BT_MODE_NORMAL, ///< Select normal/rectangle planting mode.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_VEHICLE_WIDGET_H
/** Widgets of the #VehicleViewWindow class. */
enum VehicleViewWidgets {
enum VehicleViewWidgets : WidgetID {
WID_VV_CAPTION, ///< Caption of window.
WID_VV_VIEWPORT, ///< Viewport widget.
WID_VV_START_STOP, ///< Start or stop this vehicle, and show information about the current state.
@@ -31,7 +31,7 @@ enum VehicleViewWidgets {
};
/** Widgets of the #RefitWindow class. */
enum VehicleRefitWidgets {
enum VehicleRefitWidgets : WidgetID {
WID_VR_CAPTION, ///< Caption of window.
WID_VR_VEHICLE_PANEL_DISPLAY, ///< Display with a representation of the vehicle to refit.
WID_VR_SHOW_HSCROLLBAR, ///< Selection widget for the horizontal scrollbar.
@@ -44,7 +44,7 @@ enum VehicleRefitWidgets {
};
/** Widgets of the #VehicleDetailsWindow class. */
enum VehicleDetailsWidgets {
enum VehicleDetailsWidgets : WidgetID {
WID_VD_CAPTION, ///< Caption of window.
WID_VD_TOP_DETAILS, ///< Panel with generic details.
WID_VD_INCREASE_SERVICING_INTERVAL, ///< Increase the servicing interval.
@@ -61,7 +61,7 @@ enum VehicleDetailsWidgets {
};
/** Widgets of the #VehicleListWindow class. */
enum VehicleListWidgets {
enum VehicleListWidgets : WidgetID {
WID_VL_CAPTION, ///< Caption of window (for non shared orders windows).
WID_VL_CAPTION_SHARED_ORDERS, ///< Caption of window (for shared orders windows).
WID_VL_CAPTION_SELECTION, ///< Selection for caption.

View File

@@ -11,7 +11,7 @@
#define WIDGETS_VIEWPORT_WIDGET_H
/** Widgets of the #ExtraViewportWindow class. */
enum ExtraViewportWidgets {
enum ExtraViewportWidgets : WidgetID {
WID_EV_CAPTION, ///< Caption of window.
WID_EV_VIEWPORT, ///< The viewport.
WID_EV_ZOOM_IN, ///< Zoom in.

View File

@@ -11,12 +11,13 @@
#define WIDGETS_WAYPOINT_WIDGET_H
/** Widgets of the #WaypointWindow class. */
enum WaypointWidgets {
enum WaypointWidgets : WidgetID {
WID_W_CAPTION, ///< Caption of window.
WID_W_VIEWPORT, ///< The viewport on this waypoint.
WID_W_CENTER_VIEW, ///< Center the main view on this waypoint.
WID_W_RENAME, ///< Rename this waypoint.
WID_W_SHOW_VEHICLES, ///< Show the vehicles visiting this waypoint.
WID_W_CATCHMENT, ///< Coverage button.
};
#endif /* WIDGETS_WAYPOINT_WIDGET_H */