(svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
This commit is contained in:
@@ -188,6 +188,9 @@ public:
|
||||
inline uint GetHorizontalStepSize(SizingType sizing) const;
|
||||
inline uint GetVerticalStepSize(SizingType sizing) const;
|
||||
|
||||
virtual void Draw(const Window *w) = 0;
|
||||
virtual void Invalidate(const Window *w) const;
|
||||
|
||||
WidgetType type; ///< Type of the widget / nested widget.
|
||||
bool fill_x; ///< Allow horizontal filling from initial size.
|
||||
bool fill_y; ///< Allow vertical filling from initial size.
|
||||
@@ -253,6 +256,16 @@ public:
|
||||
uint min_y; ///< Minimal vertical size of only this widget.
|
||||
};
|
||||
|
||||
/** Nested widget flags that affect display and interaction withe 'real' widgets. */
|
||||
enum NWidgetDisplay {
|
||||
NDB_LOWERED = 0, ///< Widget is lowered (pressed down) bit.
|
||||
NDB_DISABLED = 1, ///< Widget is disabled (greyed out) bit.
|
||||
|
||||
ND_LOWERED = 1 << NDB_LOWERED, ///< Bit value of the lowered flag.
|
||||
ND_DISABLED = 1 << NDB_DISABLED, ///< Bit value of the disabled flag.
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay);
|
||||
|
||||
/** Base class for a 'real' widget.
|
||||
* @ingroup NestedWidgets */
|
||||
class NWidgetCore : public NWidgetResizeBase {
|
||||
@@ -262,16 +275,53 @@ public:
|
||||
void SetIndex(int index);
|
||||
void SetDataTip(uint16 widget_data, StringID tool_tip);
|
||||
|
||||
inline void SetLowered(bool lowered);
|
||||
inline bool IsLowered();
|
||||
inline void SetDisabled(bool disabled);
|
||||
inline bool IsDisabled();
|
||||
|
||||
int SetupSmallestSize();
|
||||
void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl);
|
||||
/* virtual */ void FillNestedArray(NWidgetCore **array, uint length);
|
||||
|
||||
Colours colour; ///< Colour of this widget.
|
||||
int index; ///< Index of the nested widget in the widget array of the window (\c -1 means 'not used').
|
||||
uint16 widget_data; ///< Data of the widget. @see Widget::data
|
||||
StringID tool_tip; ///< Tooltip of the widget. @see Widget::tootips
|
||||
NWidgetDisplay disp_flags; ///< Flags that affect display and interaction with the widget.
|
||||
Colours colour; ///< Colour of this widget.
|
||||
int index; ///< Index of the nested widget in the widget array of the window (\c -1 means 'not used').
|
||||
uint16 widget_data; ///< Data of the widget. @see Widget::data
|
||||
StringID tool_tip; ///< Tooltip of the widget. @see Widget::tootips
|
||||
};
|
||||
|
||||
/**
|
||||
* Lower or raise the widget.
|
||||
* @param lowered Widget must be lowered (drawn pressed down).
|
||||
*/
|
||||
inline void NWidgetCore::SetLowered(bool lowered)
|
||||
{
|
||||
this->disp_flags = lowered ? SETBITS(this->disp_flags, ND_LOWERED) : CLRBITS(this->disp_flags, ND_LOWERED);
|
||||
}
|
||||
|
||||
/** Return whether the widget is lowered. */
|
||||
inline bool NWidgetCore::IsLowered()
|
||||
{
|
||||
return HasBit(this->disp_flags, NDB_LOWERED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable (grey-out) or enable the widget.
|
||||
* @param disabled Widget must be disabled.
|
||||
*/
|
||||
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()
|
||||
{
|
||||
return HasBit(this->disp_flags, NDB_DISABLED);
|
||||
}
|
||||
|
||||
|
||||
/** Baseclass for container widgets.
|
||||
* @ingroup NestedWidgets */
|
||||
class NWidgetContainer : public NWidgetBase {
|
||||
@@ -300,6 +350,8 @@ public:
|
||||
int SetupSmallestSize();
|
||||
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl);
|
||||
void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl);
|
||||
|
||||
/* virtual */ void Draw(const Window *w);
|
||||
};
|
||||
|
||||
/** Container with pre/inter/post child space. */
|
||||
@@ -309,6 +361,7 @@ public:
|
||||
|
||||
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
|
||||
|
||||
/* virtual */ void Draw(const Window *w);
|
||||
protected:
|
||||
uint8 pip_pre; ///< Amount of space before first widget.
|
||||
uint8 pip_inter; ///< Amount of space between widgets.
|
||||
@@ -360,6 +413,9 @@ public:
|
||||
int SetupSmallestSize();
|
||||
void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl);
|
||||
/* virtual */ void FillNestedArray(NWidgetCore **array, uint length);
|
||||
|
||||
/* virtual */ void Draw(const Window *w);
|
||||
/* virtual */ void Invalidate(const Window *w) const;
|
||||
};
|
||||
|
||||
/** Nested widget with a child.
|
||||
@@ -378,6 +434,8 @@ public:
|
||||
void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl);
|
||||
/* virtual */ void FillNestedArray(NWidgetCore **array, uint length);
|
||||
|
||||
/* virtual */ void Draw(const Window *w);
|
||||
|
||||
private:
|
||||
NWidgetPIPContainer *child; ///< Child widget.
|
||||
};
|
||||
@@ -387,6 +445,9 @@ private:
|
||||
class NWidgetLeaf : public NWidgetCore {
|
||||
public:
|
||||
NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip);
|
||||
|
||||
/* virtual */ void Draw(const Window *w);
|
||||
/* virtual */ void Invalidate(const Window *w) const;
|
||||
};
|
||||
|
||||
Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl = false);
|
||||
|
Reference in New Issue
Block a user