|
@@ -210,25 +210,26 @@ FORCEINLINE void NWidgetBase::StoreSizeP
|
|
|
{
|
|
|
this->pos_x = x;
|
|
|
this->pos_y = y;
|
|
|
if (sizing == ST_SMALLEST) {
|
|
|
this->smallest_x = given_width;
|
|
|
this->smallest_y = given_height;
|
|
|
}
|
|
|
this->current_x = given_width;
|
|
|
this->current_y = given_height;
|
|
|
}
|
|
|
|
|
|
|
|
|
/** Base class for a resizable nested widget.
|
|
|
/**
|
|
|
* Base class for a resizable nested widget.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetResizeBase : public NWidgetBase {
|
|
|
public:
|
|
|
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
|
|
|
|
|
|
void SetMinimalSize(uint min_x, uint min_y);
|
|
|
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size);
|
|
|
void SetFill(uint fill_x, uint fill_y);
|
|
|
void SetResize(uint resize_x, uint resize_y);
|
|
|
|
|
|
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
|
|
|
|
|
@@ -248,25 +249,26 @@ enum NWidgetDisplay {
|
|
|
/* Button dropdown widget. */
|
|
|
NDB_DROPDOWN_ACTIVE = 5, ///< Dropdown menu of the button dropdown widget is active. @see #NWID_BUTTON_DRPDOWN
|
|
|
|
|
|
ND_LOWERED = 1 << NDB_LOWERED, ///< Bit value of the lowered flag.
|
|
|
ND_DISABLED = 1 << NDB_DISABLED, ///< Bit value of the disabled flag.
|
|
|
ND_NO_TRANSPARENCY = 1 << NDB_NO_TRANSPARENCY, ///< Bit value of the 'no transparency' flag.
|
|
|
ND_SHADE_GREY = 1 << NDB_SHADE_GREY, ///< Bit value of the 'shade to grey' flag.
|
|
|
ND_SHADE_DIMMED = 1 << NDB_SHADE_DIMMED, ///< Bit value of the 'dimmed colours' flag.
|
|
|
ND_DROPDOWN_ACTIVE = 1 << NDB_DROPDOWN_ACTIVE, ///< Bit value of the 'dropdown active' flag.
|
|
|
};
|
|
|
DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay)
|
|
|
|
|
|
/** Base class for a 'real' widget.
|
|
|
/**
|
|
|
* Base class for a 'real' widget.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetCore : public NWidgetResizeBase {
|
|
|
public:
|
|
|
NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint16 widget_data, StringID tool_tip);
|
|
|
|
|
|
void SetIndex(int index);
|
|
|
void SetDataTip(uint16 widget_data, StringID tool_tip);
|
|
|
|
|
|
inline void SetLowered(bool lowered);
|
|
|
inline bool IsLowered() const;
|
|
|
inline void SetDisabled(bool disabled);
|
|
|
inline bool IsDisabled() const;
|
|
@@ -305,25 +307,26 @@ inline bool NWidgetCore::IsLowered() con
|
|
|
inline void NWidgetCore::SetDisabled(bool disabled)
|
|
|
{
|
|
|
this->disp_flags = disabled ? SETBITS(this->disp_flags, ND_DISABLED) : CLRBITS(this->disp_flags, ND_DISABLED);
|
|
|
}
|
|
|
|
|
|
/** Return whether the widget is disabled. */
|
|
|
inline bool NWidgetCore::IsDisabled() const
|
|
|
{
|
|
|
return HasBit(this->disp_flags, NDB_DISABLED);
|
|
|
}
|
|
|
|
|
|
|
|
|
/** Baseclass for container widgets.
|
|
|
/**
|
|
|
* Baseclass for container widgets.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetContainer : public NWidgetBase {
|
|
|
public:
|
|
|
NWidgetContainer(WidgetType tp);
|
|
|
~NWidgetContainer();
|
|
|
|
|
|
void Add(NWidgetBase *wid);
|
|
|
/* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
|
|
|
|
|
|
/** Return whether the container is empty. */
|
|
|
inline bool IsEmpty() { return head == NULL; };
|
|
|
|
|
@@ -334,25 +337,26 @@ protected:
|
|
|
NWidgetBase *tail; ///< Pointer to last widget in container.
|
|
|
};
|
|
|
|
|
|
/** Display planes with zero size for #NWidgetStacked. */
|
|
|
enum StackedZeroSizePlanes {
|
|
|
SZSP_VERTICAL = INT_MAX / 2, ///< Display plane with zero size horizontally, and filling and resizing vertically.
|
|
|
SZSP_HORIZONTAL, ///< Display plane with zero size vertically, and filling and resizing horizontally.
|
|
|
SZSP_NONE, ///< Display plane with zero size in both directions (none filling and resizing).
|
|
|
|
|
|
SZSP_BEGIN = SZSP_VERTICAL, ///< First zero-size plane.
|
|
|
};
|
|
|
|
|
|
/** Stacked widgets, widgets all occupying the same space in the window.
|
|
|
/**
|
|
|
* Stacked widgets, widgets all occupying the same space in the window.
|
|
|
* #NWID_SELECTION allows for selecting one of several panels (planes) to tbe displayed. All planes must have the same size.
|
|
|
* Since all planes are also initialized, switching between different planes can be done while the window is displayed.
|
|
|
*
|
|
|
* There are also a number of special planes (defined in #StackedZeroSizePlanes) that have zero size in one direction (and are stretchable in
|
|
|
* the other direction) or have zero size in both directions. They are used to make all child planes of the widget disappear.
|
|
|
* Unlike switching between the regular display planes (that all have the same size), switching from or to one of the zero-sized planes means that
|
|
|
* a #Windows::ReInit() is needed to re-initialize the window since its size changes.
|
|
|
*/
|
|
|
class NWidgetStacked : public NWidgetContainer {
|
|
|
public:
|
|
|
NWidgetStacked();
|
|
|
|
|
@@ -388,69 +392,74 @@ public:
|
|
|
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
|
|
|
|
|
|
/* virtual */ void Draw(const Window *w);
|
|
|
/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
|
|
|
|
|
|
protected:
|
|
|
NWidContainerFlags flags; ///< Flags of the container.
|
|
|
uint8 pip_pre; ///< Amount of space before first widget.
|
|
|
uint8 pip_inter; ///< Amount of space between widgets.
|
|
|
uint8 pip_post; ///< Amount of space after last widget.
|
|
|
};
|
|
|
|
|
|
/** Horizontal container.
|
|
|
/**
|
|
|
* Horizontal container.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetHorizontal : public NWidgetPIPContainer {
|
|
|
public:
|
|
|
NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
|
|
|
|
|
|
void SetupSmallestSize(Window *w, bool init_array);
|
|
|
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
|
|
|
};
|
|
|
|
|
|
/** Horizontal container that doesn't change the direction of the widgets for RTL languages.
|
|
|
/**
|
|
|
* Horizontal container that doesn't change the direction of the widgets for RTL languages.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetHorizontalLTR : public NWidgetHorizontal {
|
|
|
public:
|
|
|
NWidgetHorizontalLTR(NWidContainerFlags flags = NC_NONE);
|
|
|
|
|
|
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
|
|
|
};
|
|
|
|
|
|
/** Vertical container.
|
|
|
/**
|
|
|
* Vertical container.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetVertical : public NWidgetPIPContainer {
|
|
|
public:
|
|
|
NWidgetVertical(NWidContainerFlags flags = NC_NONE);
|
|
|
|
|
|
void SetupSmallestSize(Window *w, bool init_array);
|
|
|
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
|
|
|
};
|
|
|
|
|
|
|
|
|
/** Spacer widget.
|
|
|
/**
|
|
|
* Spacer widget.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetSpacer : public NWidgetResizeBase {
|
|
|
public:
|
|
|
NWidgetSpacer(int length, int height);
|
|
|
|
|
|
void SetupSmallestSize(Window *w, bool init_array);
|
|
|
/* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
|
|
|
|
|
|
/* virtual */ void Draw(const Window *w);
|
|
|
/* virtual */ void SetDirty(const Window *w) const;
|
|
|
/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
|
|
|
};
|
|
|
|
|
|
/** Nested widget with a child.
|
|
|
/**
|
|
|
* Nested widget with a child.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetBackground : public NWidgetCore {
|
|
|
public:
|
|
|
NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child = NULL);
|
|
|
~NWidgetBackground();
|
|
|
|
|
|
void Add(NWidgetBase *nwid);
|
|
|
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
|
|
|
|
|
|
void SetupSmallestSize(Window *w, bool init_array);
|
|
|
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
|
|
|
|
|
@@ -476,25 +485,26 @@ private:
|
|
|
class NWidgetViewport : public NWidgetCore {
|
|
|
public:
|
|
|
NWidgetViewport(int index);
|
|
|
|
|
|
/* virtual */ void SetupSmallestSize(Window *w, bool init_array);
|
|
|
/* virtual */ void Draw(const Window *w);
|
|
|
/* virtual */ Scrollbar *FindScrollbar(Window *w, bool allow_next = true) const;
|
|
|
|
|
|
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom);
|
|
|
void UpdateViewportCoordinates(Window *w);
|
|
|
};
|
|
|
|
|
|
/** Leaf widget.
|
|
|
/**
|
|
|
* Leaf widget.
|
|
|
* @ingroup NestedWidgets */
|
|
|
class NWidgetLeaf : public NWidgetCore {
|
|
|
public:
|
|
|
NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip);
|
|
|
|
|
|
/* virtual */ void SetupSmallestSize(Window *w, bool init_array);
|
|
|
/* virtual */ void Draw(const Window *w);
|
|
|
/* virtual */ Scrollbar *FindScrollbar(Window *w, bool allow_next = true) const;
|
|
|
|
|
|
bool ButtonHit(const Point &pt);
|
|
|
|
|
|
static void InvalidateDimensionCache();
|
|
@@ -560,66 +570,73 @@ static FORCEINLINE uint ComputeMaxSize(u
|
|
|
* - Background widgets #NWidgetBackground start with a #NWidget(WidgetType tp, Colours col, int16 idx) part.
|
|
|
* What follows depends on how the widget is used.
|
|
|
* - If the widget is used as a leaf widget, that is, to create some space in the window to display a viewport or some text, use the properties of the
|
|
|
* leaf widgets to define how it behaves.
|
|
|
* - If the widget is used a background behind other widgets, it is considered to be a container widgets. Use the properties listed there to define its
|
|
|
* behaviour.
|
|
|
* .
|
|
|
* In both cases, the background widget \b MUST end with a #EndContainer widget part.
|
|
|
*
|
|
|
* @see NestedWidgets
|
|
|
*/
|
|
|
|
|
|
/** Widget part for storing data and tooltip information.
|
|
|
/**
|
|
|
* Widget part for storing data and tooltip information.
|
|
|
* @ingroup NestedWidgetParts */
|
|
|
struct NWidgetPartDataTip {
|
|
|
uint16 data; ///< Data value of the widget.
|
|
|
StringID tooltip; ///< Tooltip of the widget.
|
|
|
};
|
|
|
|
|
|
/** Widget part for storing basic widget information.
|
|
|
/**
|
|
|
* Widget part for storing basic widget information.
|
|
|
* @ingroup NestedWidgetParts */
|
|
|
struct NWidgetPartWidget {
|
|
|
Colours colour; ///< Widget colour.
|
|
|
int16 index; ///< Widget index in the widget array.
|
|
|
};
|
|
|
|
|
|
/** Widget part for storing padding.
|
|
|
/**
|
|
|
* Widget part for storing padding.
|
|
|
* @ingroup NestedWidgetParts */
|
|
|
struct NWidgetPartPaddings {
|
|
|
uint8 top, right, bottom, left; ///< Paddings for all directions.
|
|
|
};
|
|
|
|
|
|
/** Widget part for storing pre/inter/post spaces.
|
|
|
/**
|
|
|
* Widget part for storing pre/inter/post spaces.
|
|
|
* @ingroup NestedWidgetParts */
|
|
|
struct NWidgetPartPIP {
|
|
|
uint8 pre, inter, post; ///< Amount of space before/between/after child widgets.
|
|
|
};
|
|
|
|
|
|
/** Widget part for storing minimal text line data.
|
|
|
/**
|
|
|
* Widget part for storing minimal text line data.
|
|
|
* @ingroup NestedWidgetParts */
|
|
|
struct NWidgetPartTextLines {
|
|
|
uint8 lines; ///< Number of text lines.
|
|
|
uint8 spacing; ///< Extra spacing around lines.
|
|
|
FontSize size; ///< Font size of text lines.
|
|
|
};
|
|
|
|
|
|
/** Pointer to function returning a nested widget.
|
|
|
/**
|
|
|
* Pointer to function returning a nested widget.
|
|
|
* @param biggest_index Pointer to storage for collecting the biggest index used in the nested widget.
|
|
|
* @return Nested widget (tree).
|
|
|
* @post \c *biggest_index must contain the value of the biggest index in the returned tree.
|
|
|
*/
|
|
|
typedef NWidgetBase *NWidgetFunctionType(int *biggest_index);
|
|
|
|
|
|
/** Partial widget specification to allow NWidgets to be written nested.
|
|
|
/**
|
|
|
* Partial widget specification to allow NWidgets to be written nested.
|
|
|
* @ingroup NestedWidgetParts */
|
|
|
struct NWidgetPart {
|
|
|
WidgetType type; ///< Type of the part. @see NWidgetPartType.
|
|
|
union {
|
|
|
Point xy; ///< Part with an x/y size.
|
|
|
NWidgetPartDataTip data_tip; ///< Part with a data/tooltip.
|
|
|
NWidgetPartWidget widget; ///< Part with a start of a widget.
|
|
|
NWidgetPartPaddings padding; ///< Part with paddings.
|
|
|
NWidgetPartPIP pip; ///< Part with pre/inter/post spaces.
|
|
|
NWidgetPartTextLines text_lines; ///< Part with text line data.
|
|
|
NWidgetFunctionType *func_ptr; ///< Part with a function call.
|
|
|
NWidContainerFlags cont_flags; ///< Part with container flags.
|
|
@@ -701,25 +718,26 @@ static inline NWidgetPart SetFill(uint f
|
|
|
* (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
|
|
|
* @ingroup NestedWidgetParts
|
|
|
*/
|
|
|
static inline NWidgetPart EndContainer()
|
|
|
{
|
|
|
NWidgetPart part;
|
|
|
|
|
|
part.type = WPT_ENDCONTAINER;
|
|
|
|
|
|
return part;
|
|
|
}
|
|
|
|
|
|
/** Widget part function for setting the data and tooltip.
|
|
|
/**
|
|
|
* Widget part function for setting the data and tooltip.
|
|
|
* @param data Data of the widget.
|
|
|
* @param tip Tooltip of the widget.
|
|
|
* @ingroup NestedWidgetParts
|
|
|
*/
|
|
|
static inline NWidgetPart SetDataTip(uint16 data, StringID tip)
|
|
|
{
|
|
|
NWidgetPart part;
|
|
|
|
|
|
part.type = WPT_DATATIP;
|
|
|
part.u.data_tip.data = data;
|
|
|
part.u.data_tip.tooltip = tip;
|
|
|
|