Merge branch upstream/master
This commit is contained in:
375
src/widget.cpp
375
src/widget.cpp
@@ -27,6 +27,33 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
/**
|
||||
* Calculate x and y coordinates for an aligned object within a window.
|
||||
* @param r Rectangle of the widget to be drawn in.
|
||||
* @param d Dimension of the object to be drawn.
|
||||
* @param align Alignment of the object.
|
||||
* @return A point containing the position at which to draw.
|
||||
*/
|
||||
static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, StringAlignment align)
|
||||
{
|
||||
Point p;
|
||||
/* In case we have a RTL language we swap the alignment. */
|
||||
if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
|
||||
switch (align & SA_HOR_MASK) {
|
||||
case SA_LEFT: p.x = r.left; break;
|
||||
case SA_HOR_CENTER: p.x = CenterBounds(r.left, r.right, d.width); break;
|
||||
case SA_RIGHT: p.x = r.right - d.width; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
switch (align & SA_VERT_MASK) {
|
||||
case SA_TOP: p.y = r.top; break;
|
||||
case SA_VERT_CENTER: p.y = CenterBounds(r.top, r.bottom, d.height); break;
|
||||
case SA_BOTTOM: p.y = r.bottom - d.height; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the vertical position of the draggable part of scrollbar
|
||||
* @param sb Scrollbar list data
|
||||
@@ -234,15 +261,17 @@ void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, Fra
|
||||
* @param colour Colour of the button.
|
||||
* @param clicked Button is lowered.
|
||||
* @param img Sprite to draw.
|
||||
* @param align Alignment of the sprite.
|
||||
*/
|
||||
static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img)
|
||||
static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
|
||||
{
|
||||
assert(img != 0);
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
||||
|
||||
if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
|
||||
Dimension d = GetSpriteSize(img);
|
||||
DrawSprite(img, PAL_NONE, CenterBounds(r.left, r.right, d.width) + clicked, CenterBounds(r.top, r.bottom, d.height) + clicked);
|
||||
Point p = GetAlignedPosition(r, d, align);
|
||||
DrawSprite(img, PAL_NONE, p.x + clicked, p.y + clicked);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,15 +279,17 @@ static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colo
|
||||
* @param r Rectangle of the label background.
|
||||
* @param type Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL).
|
||||
* @param clicked Label is rendered lowered.
|
||||
* @param colour Colour of the text.
|
||||
* @param str Text to draw.
|
||||
* @param align Alignment of the text.
|
||||
*/
|
||||
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str)
|
||||
static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
|
||||
{
|
||||
if (str == STR_NULL) return;
|
||||
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
|
||||
Dimension d = GetStringBoundingBox(str);
|
||||
int offset = std::max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
|
||||
DrawString(r.left + clicked, r.right + clicked, r.top + offset + clicked, str, TC_FROMSTRING, SA_HOR_CENTER);
|
||||
Point p = GetAlignedPosition(r, d, align);
|
||||
DrawString(r.left + clicked, r.right + clicked, p.y + clicked, str, colour, align);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,24 +297,27 @@ static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, Strin
|
||||
* @param r Rectangle of the background.
|
||||
* @param colour Colour of the text.
|
||||
* @param str Text to draw.
|
||||
* @param align Alignment of the text.
|
||||
*/
|
||||
static inline void DrawText(const Rect &r, TextColour colour, StringID str)
|
||||
static inline void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align)
|
||||
{
|
||||
Dimension d = GetStringBoundingBox(str);
|
||||
int offset = std::max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
|
||||
if (str != STR_NULL) DrawString(r.left, r.right, r.top + offset, str, colour);
|
||||
Point p = GetAlignedPosition(r, d, align);
|
||||
if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an inset widget.
|
||||
* @param r Rectangle of the background.
|
||||
* @param colour Colour of the inset.
|
||||
* @param str Text to draw.
|
||||
* @param r Rectangle of the background.
|
||||
* @param colour Colour of the inset.
|
||||
* @param text_colour Colour of the text.
|
||||
* @param str Text to draw.
|
||||
* @param align Alignment of the text.
|
||||
*/
|
||||
static inline void DrawInset(const Rect &r, Colours colour, StringID str)
|
||||
static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
|
||||
{
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
|
||||
if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str);
|
||||
if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str, text_colour, align);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,15 +459,17 @@ static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool l
|
||||
|
||||
/**
|
||||
* Draw a frame widget.
|
||||
* @param r Rectangle of the frame.
|
||||
* @param colour Colour of the frame.
|
||||
* @param str Text of the frame.
|
||||
* @param r Rectangle of the frame.
|
||||
* @param colour Colour of the frame.
|
||||
* @param text_colour Colour of the text.
|
||||
* @param str Text of the frame.
|
||||
* @param align Alignment of the text in the frame.
|
||||
*/
|
||||
static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
|
||||
static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
|
||||
{
|
||||
int x2 = r.left; // by default the left side is the left side of the widget
|
||||
|
||||
if (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str);
|
||||
if (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str, text_colour, align);
|
||||
|
||||
int c1 = _colour_gradient[colour][3];
|
||||
int c2 = _colour_gradient[colour][7];
|
||||
@@ -481,7 +517,7 @@ static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
|
||||
*/
|
||||
static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
|
||||
{
|
||||
DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE);
|
||||
DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE, SA_CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -492,7 +528,7 @@ static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
|
||||
*/
|
||||
static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
|
||||
{
|
||||
DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN);
|
||||
DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN, SA_CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -503,7 +539,7 @@ static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
|
||||
*/
|
||||
static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
|
||||
{
|
||||
DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE);
|
||||
DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE, SA_CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,7 +550,7 @@ static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
|
||||
*/
|
||||
static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
|
||||
{
|
||||
DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG);
|
||||
DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG, SA_CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,12 +589,14 @@ static inline void DrawCloseBox(const Rect &r, Colours colour)
|
||||
|
||||
/**
|
||||
* Draw a caption bar.
|
||||
* @param r Rectangle of the bar.
|
||||
* @param colour Colour of the window.
|
||||
* @param owner 'Owner' of the window.
|
||||
* @param str Text to draw in the bar.
|
||||
* @param r Rectangle of the bar.
|
||||
* @param colour Colour of the window.
|
||||
* @param owner 'Owner' of the window.
|
||||
* @param text_colour Colour of the text.
|
||||
* @param str Text to draw in the bar.
|
||||
* @param align Alignment of the text.
|
||||
*/
|
||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str, const NWidgetCore *widget, const Window *window)
|
||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, const NWidgetCore *widget, const Window *window)
|
||||
{
|
||||
bool company_owned = owner < MAX_COMPANIES;
|
||||
|
||||
@@ -569,8 +607,8 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str, const
|
||||
|
||||
if (str != STR_NULL) {
|
||||
Dimension d = GetStringBoundingBox(str);
|
||||
int offset = std::max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
|
||||
DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, r.top + offset, str, TC_FROMSTRING, SA_HOR_CENTER);
|
||||
Point p = GetAlignedPosition(r, d, align);
|
||||
DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, p.y, str, text_colour, align);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,10 +619,11 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str, const
|
||||
* @param clicked_button The button-part is lowered.
|
||||
* @param clicked_dropdown The drop-down part is lowered.
|
||||
* @param str Text of the button.
|
||||
* @param align Alignment of the text within the dropdown.
|
||||
*
|
||||
* @note Magic constants are also used in #NWidgetLeaf::ButtonHit.
|
||||
*/
|
||||
static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str)
|
||||
static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
|
||||
{
|
||||
int text_offset = std::max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
|
||||
|
||||
@@ -596,27 +635,15 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
|
||||
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
|
||||
DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
|
||||
DrawSpriteCenteredRect(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown * 2, r.top + image_offset + clicked_dropdown * 2, r.right, r.bottom);
|
||||
if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - dd_width - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK);
|
||||
if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - dd_width - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK, align);
|
||||
} else {
|
||||
DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
|
||||
DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
|
||||
DrawSpriteCenteredRect(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown * 2, r.top + image_offset + clicked_dropdown * 2, r.left + dd_width, r.bottom);
|
||||
if (str != STR_NULL) DrawString(r.left + dd_width + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK);
|
||||
if (str != STR_NULL) DrawString(r.left + dd_width + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK, align);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a dropdown #WWT_DROPDOWN widget.
|
||||
* @param r Rectangle containing the widget.
|
||||
* @param colour Background colour of the widget.
|
||||
* @param clicked The widget is lowered.
|
||||
* @param str Text of the button.
|
||||
*/
|
||||
static inline void DrawDropdown(const Rect &r, Colours colour, bool clicked, StringID str)
|
||||
{
|
||||
DrawButtonDropdown(r, colour, false, clicked, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint all widgets of a window.
|
||||
*/
|
||||
@@ -820,6 +847,14 @@ NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
|
||||
return (this->type == tp) ? this : nullptr;
|
||||
}
|
||||
|
||||
void NWidgetBase::AdjustPaddingForZoom()
|
||||
{
|
||||
this->padding_top = ScaleGUITrad(this->uz_padding_top);
|
||||
this->padding_right = ScaleGUITrad(this->uz_padding_right);
|
||||
this->padding_bottom = ScaleGUITrad(this->uz_padding_bottom);
|
||||
this->padding_left = ScaleGUITrad(this->uz_padding_left);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for resizable nested widgets.
|
||||
* @param tp Nested widget type.
|
||||
@@ -833,6 +868,15 @@ NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) :
|
||||
this->fill_y = fill_y;
|
||||
}
|
||||
|
||||
void NWidgetResizeBase::AdjustPaddingForZoom()
|
||||
{
|
||||
if (!this->absolute) {
|
||||
this->min_x = ScaleGUITrad(this->uz_min_x);
|
||||
this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
|
||||
}
|
||||
NWidgetBase::AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimal size of the widget.
|
||||
* @param min_x Horizontal minimal size of the widget.
|
||||
@@ -840,6 +884,20 @@ NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) :
|
||||
*/
|
||||
void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
|
||||
{
|
||||
this->uz_min_x = std::max(this->uz_min_x, min_x);
|
||||
this->uz_min_y = std::max(this->uz_min_y, min_y);
|
||||
this->min_x = ScaleGUITrad(this->uz_min_x);
|
||||
this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set absolute (post-scaling) minimal size of the widget.
|
||||
* @param min_x Horizontal minimal size of the widget.
|
||||
* @param min_y Vertical minimal size of the widget.
|
||||
*/
|
||||
void NWidgetResizeBase::SetMinimalSizeAbsolute(uint min_x, uint min_y)
|
||||
{
|
||||
this->absolute = true;
|
||||
this->min_x = std::max(this->min_x, min_x);
|
||||
this->min_y = std::max(this->min_y, min_y);
|
||||
uint min_size = 0;
|
||||
@@ -873,7 +931,10 @@ void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
|
||||
*/
|
||||
void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
|
||||
{
|
||||
this->min_y = min_lines * GetCharacterHeight(size) + spacing;
|
||||
this->uz_text_lines = min_lines;
|
||||
this->uz_text_spacing = spacing;
|
||||
this->uz_text_size = size;
|
||||
this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -920,6 +981,8 @@ NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y
|
||||
this->widget_data = widget_data;
|
||||
this->tool_tip = tool_tip;
|
||||
this->scrollbar_index = -1;
|
||||
this->text_colour = TC_FROMSTRING;
|
||||
this->align = SA_CENTER;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -943,6 +1006,15 @@ void NWidgetCore::SetDataTip(uint32 widget_data, StringID tool_tip)
|
||||
this->tool_tip = tool_tip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text colour of the nested widget.
|
||||
* @param colour TextColour to use.
|
||||
*/
|
||||
void NWidgetCore::SetTextColour(TextColour colour)
|
||||
{
|
||||
this->text_colour = colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tool tip of the nested widget.
|
||||
* @param tool_tip Tool tip string to use.
|
||||
@@ -952,6 +1024,15 @@ void NWidgetCore::SetToolTip(StringID tool_tip)
|
||||
this->tool_tip = tool_tip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text/image alignment of the nested widget.
|
||||
* @param align Alignment to use.
|
||||
*/
|
||||
void NWidgetCore::SetAlignment(StringAlignment align)
|
||||
{
|
||||
this->align = align;
|
||||
}
|
||||
|
||||
void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length)
|
||||
{
|
||||
if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
|
||||
@@ -1178,6 +1259,14 @@ NWidgetBase *NWidgetContainer::GetWidgetOfType(WidgetType tp)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NWidgetContainer::AdjustPaddingForZoom()
|
||||
{
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->AdjustPaddingForZoom();
|
||||
}
|
||||
NWidgetBase::AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Append widget \a wid to container.
|
||||
* @param wid Widget to append.
|
||||
@@ -1219,6 +1308,14 @@ void NWidgetStacked::SetIndex(int index)
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
void NWidgetStacked::AdjustPaddingForZoom()
|
||||
{
|
||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
||||
child_wid->AdjustPaddingForZoom();
|
||||
}
|
||||
NWidgetContainer::AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
|
||||
{
|
||||
if (this->index >= 0 && init_array) { // Fill w->nested_array[]
|
||||
@@ -1332,6 +1429,14 @@ NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags
|
||||
this->flags = flags;
|
||||
}
|
||||
|
||||
void NWidgetPIPContainer::AdjustPaddingForZoom()
|
||||
{
|
||||
this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
|
||||
this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
|
||||
this->pip_post = ScaleGUITrad(this->uz_pip_post);
|
||||
NWidgetContainer::AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set additional pre/inter/post space for the container.
|
||||
*
|
||||
@@ -1343,9 +1448,13 @@ NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags
|
||||
*/
|
||||
void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
|
||||
{
|
||||
this->pip_pre = pip_pre;
|
||||
this->pip_inter = pip_inter;
|
||||
this->pip_post = pip_post;
|
||||
this->uz_pip_pre = pip_pre;
|
||||
this->uz_pip_inter = pip_inter;
|
||||
this->uz_pip_post = pip_post;
|
||||
|
||||
this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
|
||||
this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
|
||||
this->pip_post = ScaleGUITrad(this->uz_pip_post);
|
||||
}
|
||||
|
||||
void NWidgetPIPContainer::Draw(const Window *w)
|
||||
@@ -1677,12 +1786,12 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint
|
||||
|
||||
/**
|
||||
* Generic spacer widget.
|
||||
* @param length Horizontal size of the spacer widget.
|
||||
* @param width Horizontal size of the spacer widget.
|
||||
* @param height Vertical size of the spacer widget.
|
||||
*/
|
||||
NWidgetSpacer::NWidgetSpacer(int length, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0)
|
||||
NWidgetSpacer::NWidgetSpacer(int width, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0)
|
||||
{
|
||||
this->SetMinimalSize(length, height);
|
||||
this->SetMinimalSize(width, height);
|
||||
this->SetResize(0, 0);
|
||||
}
|
||||
|
||||
@@ -1970,6 +2079,7 @@ NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, N
|
||||
assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
|
||||
if (index >= 0) this->SetIndex(index);
|
||||
this->child = child;
|
||||
this->SetAlignment(SA_TOP | SA_LEFT);
|
||||
}
|
||||
|
||||
NWidgetBackground::~NWidgetBackground()
|
||||
@@ -2010,6 +2120,12 @@ void NWidgetBackground::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
|
||||
this->child->SetPIP(pip_pre, pip_inter, pip_post);
|
||||
}
|
||||
|
||||
void NWidgetBackground::AdjustPaddingForZoom()
|
||||
{
|
||||
if (child != nullptr) child->AdjustPaddingForZoom();
|
||||
NWidgetCore::AdjustPaddingForZoom();
|
||||
}
|
||||
|
||||
void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
|
||||
{
|
||||
if (init_array && this->index >= 0) {
|
||||
@@ -2103,12 +2219,12 @@ void NWidgetBackground::Draw(const Window *w)
|
||||
|
||||
case WWT_FRAME:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawFrame(r, this->colour, this->widget_data);
|
||||
DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
case WWT_INSET:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawInset(r, this->colour, this->widget_data);
|
||||
DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2161,6 +2277,8 @@ void NWidgetViewport::SetupSmallestSize(Window *w, bool init_array)
|
||||
|
||||
void NWidgetViewport::Draw(const Window *w)
|
||||
{
|
||||
if (this->current_x == 0 || this->current_y == 0) return;
|
||||
|
||||
if (this->disp_flags & ND_NO_TRANSPARENCY) {
|
||||
TransparencyOptionBits to_backup = _transparency_opt;
|
||||
_transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff
|
||||
@@ -2212,16 +2330,75 @@ void NWidgetViewport::UpdateViewportCoordinates(Window *w)
|
||||
* @param w The window the click was in.
|
||||
* @param widget Widget number of the widget clicked in.
|
||||
* @param padding Amount of empty space between the widget edge and the top of the first row. Default value is \c 0.
|
||||
* @param line_height Height of a single row. A negative value means using the vertical resize step of the widget.
|
||||
* @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
|
||||
*/
|
||||
int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding, int line_height) const
|
||||
int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding) const
|
||||
{
|
||||
uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height);
|
||||
uint pos = w->GetRowFromWidget(clickpos, widget, padding, -1);
|
||||
if (pos != INT_MAX) pos += this->GetPosition();
|
||||
return (pos >= this->GetCount()) ? INT_MAX : pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the given list position as if it were on this scroll bar when the given keycode was pressed.
|
||||
* This does not update the actual position of this scroll bar, that is left to the caller. It does,
|
||||
* however use the capacity and count of the scroll bar for the bounds and amount to scroll.
|
||||
*
|
||||
* When the count is 0 or the return is ES_NOT_HANDLED, then the position is not updated.
|
||||
* With WKC_UP and WKC_DOWN the position goes one up or down respectively.
|
||||
* With WKC_PAGEUP and WKC_PAGEDOWN the position goes one capacity up or down respectively.
|
||||
* With WKC_HOME the first position is selected and with WKC_END the last position is selected.
|
||||
* This function ensures that pos is in the range [0..count).
|
||||
* @param list_position The current position in the list.
|
||||
* @param key_code The pressed key code.
|
||||
* @return ES_NOT_HANDLED when another key than the 6 specific keys was pressed, otherwise ES_HANDLED.
|
||||
*/
|
||||
EventState Scrollbar::UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const
|
||||
{
|
||||
int new_pos = list_position;
|
||||
switch (keycode) {
|
||||
case WKC_UP:
|
||||
/* scroll up by one */
|
||||
new_pos--;
|
||||
break;
|
||||
|
||||
case WKC_DOWN:
|
||||
/* scroll down by one */
|
||||
new_pos++;
|
||||
break;
|
||||
|
||||
case WKC_PAGEUP:
|
||||
/* scroll up a page */
|
||||
new_pos -= this->GetCapacity();
|
||||
break;
|
||||
|
||||
case WKC_PAGEDOWN:
|
||||
/* scroll down a page */
|
||||
new_pos += this->GetCapacity();
|
||||
break;
|
||||
|
||||
case WKC_HOME:
|
||||
/* jump to beginning */
|
||||
new_pos = 0;
|
||||
break;
|
||||
|
||||
case WKC_END:
|
||||
/* jump to end */
|
||||
new_pos = this->GetCount() - 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return ES_NOT_HANDLED;
|
||||
}
|
||||
|
||||
/* If there are no elements, there is nothing to scroll/update. */
|
||||
if (this->GetCount() != 0) {
|
||||
list_position = Clamp(new_pos, 0, this->GetCount() - 1);
|
||||
}
|
||||
return ES_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set capacity of visible elements from the size and resize properties of a widget.
|
||||
* @param w Window.
|
||||
@@ -2250,6 +2427,22 @@ NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : N
|
||||
assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
|
||||
this->sizing_type = NWST_STEP;
|
||||
this->SetIndex(index);
|
||||
|
||||
switch (this->type) {
|
||||
case NWID_HSCROLLBAR:
|
||||
this->SetResize(1, 0);
|
||||
this->SetFill(1, 0);
|
||||
this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
||||
break;
|
||||
|
||||
case NWID_VSCROLLBAR:
|
||||
this->SetResize(0, 1);
|
||||
this->SetFill(0, 1);
|
||||
this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
|
||||
@@ -2263,17 +2456,11 @@ void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
|
||||
|
||||
switch (this->type) {
|
||||
case NWID_HSCROLLBAR:
|
||||
this->SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
|
||||
this->SetResize(1, 0);
|
||||
this->SetFill(1, 0);
|
||||
this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
||||
this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
|
||||
break;
|
||||
|
||||
case NWID_VSCROLLBAR:
|
||||
this->SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
|
||||
this->SetResize(0, 1);
|
||||
this->SetFill(0, 1);
|
||||
this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
|
||||
this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
@@ -2420,6 +2607,11 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
|
||||
case WWT_EMPTY:
|
||||
break;
|
||||
|
||||
case WWT_TEXT:
|
||||
this->SetFill(0, 0);
|
||||
this->SetAlignment(SA_LEFT | SA_VERT_CENTER);
|
||||
break;
|
||||
|
||||
case WWT_PUSHBTN:
|
||||
case WWT_IMGBTN:
|
||||
case WWT_PUSHIMGBTN:
|
||||
@@ -2428,7 +2620,6 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
|
||||
case WWT_PUSHTXTBTN:
|
||||
case WWT_TEXTBTN_2:
|
||||
case WWT_LABEL:
|
||||
case WWT_TEXT:
|
||||
case WWT_MATRIX:
|
||||
case NWID_BUTTON_DROPDOWN:
|
||||
case NWID_PUSHBUTTON_DROPDOWN:
|
||||
@@ -2444,7 +2635,8 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
|
||||
case WWT_CAPTION:
|
||||
this->SetFill(1, 0);
|
||||
this->SetResize(1, 0);
|
||||
//this->min_y = WD_CAPTION_HEIGHT;
|
||||
//this->SetMinimalSize(0, WD_CAPTION_HEIGHT);
|
||||
//this->SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, FS_NORMAL);
|
||||
this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
|
||||
break;
|
||||
|
||||
@@ -2456,19 +2648,19 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
|
||||
|
||||
case WWT_SHADEBOX:
|
||||
this->SetFill(0, 0);
|
||||
this->SetMinimalSize(WD_SHADEBOX_TOP, WD_CAPTION_HEIGHT);
|
||||
this->SetMinimalSize(WD_SHADEBOX_WIDTH, WD_CAPTION_HEIGHT);
|
||||
this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
|
||||
break;
|
||||
|
||||
case WWT_DEBUGBOX:
|
||||
this->SetFill(0, 0);
|
||||
this->SetMinimalSize(WD_DEBUGBOX_TOP, WD_CAPTION_HEIGHT);
|
||||
this->SetMinimalSize(WD_DEBUGBOX_WIDTH, WD_CAPTION_HEIGHT);
|
||||
this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
|
||||
break;
|
||||
|
||||
case WWT_DEFSIZEBOX:
|
||||
this->SetFill(0, 0);
|
||||
this->SetMinimalSize(WD_DEFSIZEBOX_TOP, WD_CAPTION_HEIGHT);
|
||||
this->SetMinimalSize(WD_DEFSIZEBOX_WIDTH, WD_CAPTION_HEIGHT);
|
||||
this->SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
|
||||
break;
|
||||
|
||||
@@ -2486,7 +2678,8 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
|
||||
|
||||
case WWT_DROPDOWN:
|
||||
this->SetFill(0, 0);
|
||||
//this->min_y = WD_DROPDOWN_HEIGHT;
|
||||
//this->SetMinimalSize(0, WD_DROPDOWN_HEIGHT);
|
||||
this->SetAlignment(SA_TOP | SA_LEFT);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2736,7 +2929,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||
case WWT_IMGBTN:
|
||||
case WWT_PUSHIMGBTN:
|
||||
case WWT_IMGBTN_2:
|
||||
DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data);
|
||||
DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
case WWT_TEXTBTN:
|
||||
@@ -2744,7 +2937,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||
case WWT_TEXTBTN_2:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
|
||||
DrawLabel(r, this->type, clicked, this->widget_data);
|
||||
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
case WWT_ARROWBTN:
|
||||
@@ -2757,18 +2950,18 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||
case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite);
|
||||
DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite, this->align);
|
||||
break;
|
||||
}
|
||||
|
||||
case WWT_LABEL:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawLabel(r, this->type, clicked, this->widget_data);
|
||||
DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
case WWT_TEXT:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawText(r, (TextColour)this->colour, this->widget_data);
|
||||
DrawText(r, this->text_colour, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
case WWT_MATRIX:
|
||||
@@ -2783,7 +2976,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||
|
||||
case WWT_CAPTION:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawCaption(r, this->colour, w->owner, this->widget_data, this, w);
|
||||
DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align, this, w);
|
||||
break;
|
||||
|
||||
case WWT_SHADEBOX:
|
||||
@@ -2818,13 +3011,13 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||
|
||||
case WWT_DROPDOWN:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawDropdown(r, this->colour, clicked, this->widget_data);
|
||||
DrawButtonDropdown(r, this->colour, false, clicked, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
case NWID_BUTTON_DROPDOWN:
|
||||
case NWID_PUSHBUTTON_DROPDOWN:
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data);
|
||||
DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data, this->align);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2960,7 +3153,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
|
||||
NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
|
||||
if (nwrb != nullptr) {
|
||||
assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
|
||||
nwrb->SetMinimalSize(ScaleGUITrad(parts->u.xy.x), ScaleGUITrad(parts->u.xy.y));
|
||||
nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2974,6 +3167,22 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
|
||||
break;
|
||||
}
|
||||
|
||||
case WPT_TEXTCOLOUR: {
|
||||
NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
|
||||
if (nwc != nullptr) {
|
||||
nwc->SetTextColour(parts->u.colour.colour);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WPT_ALIGNMENT: {
|
||||
NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
|
||||
if (nwc != nullptr) {
|
||||
nwc->SetAlignment(parts->u.align.align);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WPT_FILL: {
|
||||
NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
|
||||
if (nwrb != nullptr) nwrb->SetFill(parts->u.xy.x, parts->u.xy.y);
|
||||
@@ -2990,15 +3199,15 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest,
|
||||
}
|
||||
|
||||
case WPT_PADDING:
|
||||
if (*dest != nullptr) (*dest)->SetPadding(ScaleGUITrad(parts->u.padding.top), ScaleGUITrad(parts->u.padding.right), ScaleGUITrad(parts->u.padding.bottom), ScaleGUITrad(parts->u.padding.left));
|
||||
if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left);
|
||||
break;
|
||||
|
||||
case WPT_PIPSPACE: {
|
||||
NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest);
|
||||
if (nwc != nullptr) nwc->SetPIP(ScaleGUITrad(parts->u.pip.pre), ScaleGUITrad(parts->u.pip.inter), ScaleGUITrad(parts->u.pip.post));
|
||||
if (nwc != nullptr) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
|
||||
|
||||
NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest);
|
||||
if (nwb != nullptr) nwb->SetPIP(ScaleGUITrad(parts->u.pip.pre), ScaleGUITrad(parts->u.pip.inter), ScaleGUITrad(parts->u.pip.post));
|
||||
if (nwb != nullptr) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3195,7 +3404,7 @@ NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int wid
|
||||
NWidgetHorizontal *hor = nullptr; // Storage for buttons in one row.
|
||||
int hor_length = 0;
|
||||
|
||||
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
|
||||
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X);
|
||||
sprite_size.width += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
|
||||
sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
|
||||
|
||||
|
||||
Reference in New Issue
Block a user