Merge commit 'a8b575671894ffe1329ef37dca4989c0e60d70f5'
These merges are becoming more awful every time Conflicts: src/ai/ai_gui.cpp src/build_vehicle_gui.cpp src/cheat_gui.cpp src/company_gui.cpp src/depot_gui.cpp src/dock_gui.cpp src/error_gui.cpp src/genworld_gui.cpp src/misc_gui.cpp src/network/network_content_gui.cpp src/network/network_gui.cpp src/newgrf_gui.cpp src/news_gui.cpp src/rail_gui.cpp src/rev.cpp.in src/road_gui.cpp src/settings_gui.cpp src/settings_gui.h src/signs_gui.cpp src/station_gui.cpp src/table/settings.ini src/terraform_gui.cpp src/toolbar_gui.cpp src/toolbar_gui.h src/vehicle_gui.cpp src/video/sdl_v.cpp src/viewport.cpp src/widget.cpp src/widgets/settings_widget.h
This commit is contained in:
174
src/widget.cpp
174
src/widget.cpp
@@ -22,13 +22,10 @@
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
#include "table/palettes.h"
|
||||
#include "table/string_colours.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
static const char *UPARROW = "\xEE\x8A\xA0"; ///< String containing an upwards pointing arrow.
|
||||
static const char *DOWNARROW = "\xEE\x8A\xAA"; ///< String containing a downwards pointing arrow.
|
||||
|
||||
/**
|
||||
* Compute the vertical position of the draggable part of scrollbar
|
||||
* @param sb Scrollbar list data
|
||||
@@ -353,10 +350,10 @@ static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_
|
||||
|
||||
/* draw up/down buttons */
|
||||
DrawFrameRect(r.left, r.top, r.right, r.top + height - 1, colour, (up_clicked) ? FR_LOWERED : FR_NONE);
|
||||
DrawString(r.left + up_clicked, r.right + up_clicked, r.top + height / 2 + up_clicked, UPARROW, TC_BLACK, SA_CENTER);
|
||||
DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
|
||||
|
||||
DrawFrameRect(r.left, r.bottom - (height - 1), r.right, r.bottom, colour, (down_clicked) ? FR_LOWERED : FR_NONE);
|
||||
DrawString(r.left + down_clicked, r.right + down_clicked, r.bottom - height / 2 + down_clicked, DOWNARROW, TC_BLACK, SA_CENTER);
|
||||
DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (height - 2) + down_clicked);
|
||||
|
||||
int c1 = _colour_gradient[colour & 0xF][3];
|
||||
int c2 = _colour_gradient[colour & 0xF][7];
|
||||
@@ -488,13 +485,11 @@ static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bo
|
||||
* Draw a close box.
|
||||
* @param r Rectangle of the box.
|
||||
* @param colour Colour of the close box.
|
||||
* @param str Cross to draw (#STR_BLACK_CROSS or #STR_SILVER_CROSS).
|
||||
*/
|
||||
static inline void DrawCloseBox(const Rect &r, Colours colour, StringID str)
|
||||
static inline void DrawCloseBox(const Rect &r, Colours colour)
|
||||
{
|
||||
assert(str == STR_BLACK_CROSS || str == STR_SILVER_CROSS); // black or silver cross
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
|
||||
DrawString(r.left, r.right, (r.top + r.bottom) / 2 - WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_CENTER);
|
||||
if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
|
||||
DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1 << PALETTE_TEXT_RECOLOUR), r.left + WD_CLOSEBOX_LEFT, r.top + WD_CLOSEBOX_TOP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,10 +501,12 @@ static inline void DrawCloseBox(const Rect &r, Colours colour, StringID str)
|
||||
*/
|
||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
|
||||
{
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_BORDERONLY);
|
||||
DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour, (owner == INVALID_OWNER) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
|
||||
bool company_owned = owner < MAX_COMPANIES;
|
||||
|
||||
if (owner != INVALID_OWNER) {
|
||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_BORDERONLY);
|
||||
DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour, company_owned ? FR_LOWERED | FR_DARKENED | FR_BORDERONLY : FR_LOWERED | FR_DARKENED);
|
||||
|
||||
if (company_owned) {
|
||||
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[owner]][4]);
|
||||
}
|
||||
|
||||
@@ -534,17 +531,19 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
|
||||
{
|
||||
int text_offset = max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
|
||||
|
||||
int dd_width = GetMinSizing(NWST_STEP, NWidgetLeaf::dropdown_dimension.width);
|
||||
int dd_width = GetMinSizing(NWST_STEP, NWidgetLeaf::dropdown_dimension.width);
|
||||
int dd_height = GetMinSizing(NWST_STEP, NWidgetLeaf::dropdown_dimension.height);
|
||||
int image_offset = max(0, ((int)(r.bottom - r.top + 1) - dd_height) / 2);
|
||||
|
||||
if (_current_text_dir == TD_LTR) {
|
||||
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);
|
||||
DrawString(r.right - dd_width + (clicked_dropdown ? 2 : 1), r.right, (r.top + r.bottom) / 2 + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_CENTER);
|
||||
DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown, r.top + image_offset + clicked_dropdown);
|
||||
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);
|
||||
} 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);
|
||||
DrawString(r.left + (clicked_dropdown ? 2 : 1), r.left + dd_width, (r.top + r.bottom) / 2 + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_CENTER);
|
||||
DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown, r.top + image_offset + clicked_dropdown);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -605,11 +604,22 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
|
||||
assert(this->nested_array != NULL);
|
||||
const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
|
||||
|
||||
/* Sort button uses the same sprites as vertical scrollbar */
|
||||
Dimension dim = NWidgetScrollbar::GetVerticalDimension();
|
||||
int offset = this->IsWidgetLowered(widget) ? 1 : 0;
|
||||
int base = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - WD_SORTBUTTON_ARROW_WIDTH : 0);
|
||||
int top = nwid->pos_y;
|
||||
int x = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - dim.width : 0);
|
||||
int y = offset + nwid->pos_y + (nwid->current_y - dim.height) / 2;
|
||||
|
||||
DrawString(base, base + WD_SORTBUTTON_ARROW_WIDTH, top + nwid->current_y / 2 + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK, SA_HOR_CENTER);
|
||||
DrawSprite(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get width of up/down arrow of sort button state.
|
||||
* @return Width of space required by sort button arrow.
|
||||
*/
|
||||
int Window::SortButtonWidth()
|
||||
{
|
||||
return NWidgetScrollbar::GetVerticalDimension().width + 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -769,27 +779,8 @@ NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) :
|
||||
*/
|
||||
void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
|
||||
{
|
||||
uint min_size = 0;
|
||||
switch (this->sizing_type) {
|
||||
case NWST_NONE:
|
||||
case NWST_OVERRIDE:
|
||||
min_size = 0;
|
||||
break;
|
||||
case NWST_BUTTON:
|
||||
min_size = _settings_client.gui.min_button;
|
||||
break;
|
||||
case NWST_STEP:
|
||||
min_size = _settings_client.gui.min_step;
|
||||
break;
|
||||
case NWST_VIEWPORT:
|
||||
min_size = 3 * _settings_client.gui.min_button;
|
||||
break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
min_size = RescaleFrom854x480(min_size);
|
||||
|
||||
this->min_x = max(min_x, min_size);
|
||||
this->min_y = max(min_y, min_size);
|
||||
this->min_x = max(this->min_x, min_x);
|
||||
this->min_y = max(this->min_y, min_y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1519,7 +1510,7 @@ void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
|
||||
SB(nw->index, 16, 16, 0);
|
||||
this->head->SetupSmallestSize(w, init_array);
|
||||
|
||||
Dimension padding = {this->pip_pre + this->pip_post, this->pip_pre + this->pip_post};
|
||||
Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
|
||||
Dimension size = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
|
||||
Dimension fill = {0, 0};
|
||||
Dimension resize = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
|
||||
@@ -1964,24 +1955,6 @@ 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->SetMinimalSize(0, NWidgetScrollbar::GetHorizontalDimension().height);
|
||||
this->SetResize(1, 0);
|
||||
this->SetFill(1, 0);
|
||||
this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
|
||||
break;
|
||||
|
||||
case NWID_VSCROLLBAR:
|
||||
this->SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, 0);
|
||||
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)
|
||||
@@ -1990,6 +1963,27 @@ void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
|
||||
assert(w->nested_array_size > (uint)this->index);
|
||||
w->nested_array[this->index] = this;
|
||||
}
|
||||
this->min_x = 0;
|
||||
this->min_y = 0;
|
||||
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
this->smallest_x = this->min_x;
|
||||
this->smallest_y = this->min_y;
|
||||
}
|
||||
@@ -2085,43 +2079,13 @@ Dimension NWidgetLeaf::dropdown_dimension = {0, 0};
|
||||
* @param data Data of the widget.
|
||||
* @param tip Tooltip of the widget.
|
||||
*/
|
||||
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
|
||||
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
|
||||
{
|
||||
assert(this->sizing_type < NWST_END);
|
||||
assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEFSIZEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
|
||||
if (index >= 0) this->SetIndex(index);
|
||||
|
||||
if (this->sizing_type == NWST_NONE) {
|
||||
switch (tp) {
|
||||
case WWT_PUSHBTN:
|
||||
case WWT_IMGBTN:
|
||||
case WWT_PUSHIMGBTN:
|
||||
case WWT_IMGBTN_2:
|
||||
case WWT_TEXTBTN:
|
||||
case WWT_PUSHTXTBTN:
|
||||
case WWT_TEXTBTN_2:
|
||||
case WWT_PUSHARROWBTN:
|
||||
case WWT_EDITBOX:
|
||||
case WWT_CAPTION:
|
||||
case WWT_STICKYBOX:
|
||||
case WWT_SHADEBOX:
|
||||
case WWT_DEBUGBOX:
|
||||
case WWT_DEFSIZEBOX:
|
||||
case WWT_RESIZEBOX:
|
||||
case WWT_CLOSEBOX:
|
||||
this->sizing_type = NWST_BUTTON;
|
||||
break;
|
||||
case NWID_PUSHBUTTON_DROPDOWN:
|
||||
case NWID_BUTTON_DROPDOWN:
|
||||
case WWT_DROPDOWN:
|
||||
this->sizing_type = NWST_STEP;
|
||||
break;
|
||||
default:
|
||||
this->sizing_type = NWST_OVERRIDE;
|
||||
}
|
||||
}
|
||||
|
||||
this->SetMinimalSize(0, 0);
|
||||
this->min_x = 0;
|
||||
this->min_y = 0;
|
||||
this->SetResize(0, 0);
|
||||
|
||||
switch (tp) {
|
||||
@@ -2145,12 +2109,9 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data,
|
||||
this->SetFill(0, 0);
|
||||
break;
|
||||
|
||||
case WWT_EDITBOX: {
|
||||
Dimension sprite_size = GetSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
|
||||
this->SetMinimalSize(30 + GetMinSizing(NWST_BUTTON, sprite_size.width), sprite_size.height);
|
||||
case WWT_EDITBOX:
|
||||
this->SetFill(0, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case WWT_CAPTION:
|
||||
this->SetFill(1, 0);
|
||||
@@ -2192,7 +2153,7 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data,
|
||||
case WWT_CLOSEBOX:
|
||||
this->SetFill(0, 0);
|
||||
this->SetMinimalSize(WD_CLOSEBOX_WIDTH, WD_CAPTION_HEIGHT);
|
||||
this->SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW);
|
||||
this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
|
||||
break;
|
||||
|
||||
case WWT_DROPDOWN:
|
||||
@@ -2292,9 +2253,12 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
||||
size = maxdim(size, NWidgetLeaf::resizebox_dimension);
|
||||
break;
|
||||
}
|
||||
case WWT_EDITBOX:
|
||||
size.height = max(size.height, GetStringBoundingBox("_").height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
|
||||
case WWT_EDITBOX: {
|
||||
Dimension sprite_size = GetSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
|
||||
size.width = max(size.width, 30 + sprite_size.width);
|
||||
size.height = max(sprite_size.height, GetStringBoundingBox("_").height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
|
||||
/* FALL THROUGH */
|
||||
}
|
||||
case WWT_PUSHBTN: {
|
||||
static const Dimension extra = {WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM};
|
||||
padding = &extra;
|
||||
@@ -2327,7 +2291,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
||||
static const Dimension extra = {WD_CLOSEBOX_LEFT + WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_TOP + WD_CLOSEBOX_BOTTOM};
|
||||
padding = &extra;
|
||||
if (NWidgetLeaf::closebox_dimension.width == 0) {
|
||||
NWidgetLeaf::closebox_dimension = maxdim(GetStringBoundingBox(STR_BLACK_CROSS), GetStringBoundingBox(STR_SILVER_CROSS));
|
||||
NWidgetLeaf::closebox_dimension = GetSpriteSize(SPR_CLOSEBOX);
|
||||
NWidgetLeaf::closebox_dimension.width += extra.width;
|
||||
NWidgetLeaf::closebox_dimension.height += extra.height;
|
||||
}
|
||||
@@ -2378,7 +2342,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||
Dimension d2 = GetStringBoundingBox(this->widget_data);
|
||||
d2.width += extra.width;
|
||||
d2.height += extra.height;
|
||||
d2.height = max(d2.height, NWidgetLeaf::dropdown_dimension.height) + extra.height;
|
||||
size = maxdim(size, d2);
|
||||
break;
|
||||
}
|
||||
@@ -2499,7 +2463,7 @@ void NWidgetLeaf::Draw(const Window *w)
|
||||
break;
|
||||
|
||||
case WWT_CLOSEBOX:
|
||||
DrawCloseBox(r, this->colour, this->widget_data);
|
||||
DrawCloseBox(r, this->colour);
|
||||
break;
|
||||
|
||||
case WWT_DROPDOWN:
|
||||
@@ -2534,10 +2498,10 @@ bool NWidgetLeaf::ButtonHit(const Point &pt)
|
||||
{
|
||||
uint button_size = GetMinSizing(NWST_STEP, 12);
|
||||
if (_current_text_dir == TD_LTR) {
|
||||
int button_width = this->pos_x + this->current_x - button_size;
|
||||
int button_width = this->pos_x + this->current_x - NWidgetLeaf::dropdown_dimension.width;
|
||||
return pt.x < button_width;
|
||||
} else {
|
||||
int button_left = this->pos_x + button_size;
|
||||
int button_left = this->pos_x + NWidgetLeaf::dropdown_dimension.width;
|
||||
return pt.x >= button_left;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user