Merge branch 'master' into jgrpp

# Conflicts:
#	src/widget.cpp
wip-string
Jonathan G Rennison 5 months ago
commit 201ddf4c08

@ -336,7 +336,7 @@ public:
this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
this->CreateNestedTree(true);
this->CreateNestedTree();
if (this->fop == SLO_LOAD && this->abstract_filetype == FT_SAVEGAME) {
this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
}

@ -16,6 +16,7 @@
#include "http.h"
#include <mutex>
#include <winhttp.h>
#include "../../safeguards.h"
@ -46,6 +47,7 @@ public:
static std::vector<NetworkHTTPRequest *> _http_requests;
static std::vector<NetworkHTTPRequest *> _new_http_requests;
static std::mutex _new_http_requests_mutex;
/**
* Create a new HTTP request.
@ -283,15 +285,20 @@ NetworkHTTPRequest::~NetworkHTTPRequest()
{
auto request = new NetworkHTTPRequest(std::wstring(uri.begin(), uri.end()), callback, data);
request->Connect();
std::lock_guard<std::mutex> lock(_new_http_requests_mutex);
_new_http_requests.push_back(request);
}
/* static */ void NetworkHTTPSocketHandler::HTTPReceive()
{
if (!_new_http_requests.empty()) {
/* We delay adding new requests, as Receive() below can cause a callback which adds a new requests. */
_http_requests.insert(_http_requests.end(), _new_http_requests.begin(), _new_http_requests.end());
_new_http_requests.clear();
{
std::lock_guard<std::mutex> lock(_new_http_requests_mutex);
if (!_new_http_requests.empty()) {
/* We delay adding new requests, as Receive() below can cause a callback which adds a new requests. */
_http_requests.insert(_http_requests.end(), _new_http_requests.begin(), _new_http_requests.end());
_new_http_requests.clear();
}
}
if (_http_requests.empty()) return;

@ -110,7 +110,7 @@ public:
this->Add(leaf);
}
void SetupSmallestSize(Window *w, bool init_array) override
void SetupSmallestSize(Window *w) override
{
this->smallest_y = 0; // Biggest child.
this->fill_x = 1;
@ -120,7 +120,7 @@ public:
/* First initialise some variables... */
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
child_wid->SetupSmallestSize(w);
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
}

@ -1645,16 +1645,16 @@ public:
this->editable = true; // Temporary setting, 'real' value is set in SetupSmallestSize().
}
void SetupSmallestSize(Window *w, bool init_array) override
void SetupSmallestSize(Window *w) override
{
/* Copy state flag from the window. */
assert(dynamic_cast<NewGRFWindow *>(w) != nullptr);
NewGRFWindow *ngw = (NewGRFWindow *)w;
this->editable = ngw->editable;
this->avs->SetupSmallestSize(w, init_array);
this->acs->SetupSmallestSize(w, init_array);
this->inf->SetupSmallestSize(w, init_array);
this->avs->SetupSmallestSize(w);
this->acs->SetupSmallestSize(w);
this->inf->SetupSmallestSize(w);
uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();

@ -169,7 +169,7 @@ public:
this->order = v->GetOrder(order_id);
this->set_to_all_dropdown_sel = 0;
this->CreateNestedTree(desc);
this->CreateNestedTree();
this->GetWidget<NWidgetCore>(WID_CTO_CAPTION)->SetDataTip(STR_CARGO_TYPE_ORDERS_LOAD_CAPTION + this->variant, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
this->GetWidget<NWidgetCore>(WID_CTO_HEADER)->SetDataTip(STR_CARGO_TYPE_ORDERS_LOAD_TITLE + this->variant, STR_NULL);
this->GetWidget<NWidgetStacked>(WID_CTO_SELECT)->SetDisplayedPlane((_sorted_standard_cargo_specs.size() >= 32) ? 0 : SZSP_NONE);

@ -257,7 +257,7 @@ public:
this->track = ref.track;
this->selected_instruction = -1;
this->CreateNestedTree(desc);
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(PROGRAM_WIDGET_SCROLLBAR);
this->GetWidget<NWidgetStacked>(PROGRAM_WIDGET_SEL_TOP_AUX)->SetDisplayedPlane(SZSP_NONE);
this->current_aux_plane = SZSP_NONE;

@ -1745,13 +1745,13 @@ public:
this->smallmap_window = nullptr;
}
void SetupSmallestSize(Window *w, bool init_array) override
void SetupSmallestSize(Window *w) override
{
NWidgetBase *display = this->head;
NWidgetBase *bar = display->next;
display->SetupSmallestSize(w, init_array);
bar->SetupSmallestSize(w, init_array);
display->SetupSmallestSize(w);
bar->SetupSmallestSize(w);
this->smallmap_window = dynamic_cast<SmallMapWindow *>(w);
assert(this->smallmap_window != nullptr);

@ -141,7 +141,7 @@ private:
public:
TemplateCreateWindow(WindowDesc* _wdesc, TemplateVehicle *to_edit, bool *window_open) : Window(_wdesc)
{
this->CreateNestedTree(_wdesc != nullptr);
this->CreateNestedTree();
this->hscroll = this->GetScrollbar(TCW_SCROLLBAR_H_NEW_TMPL);
this->vscroll = this->GetScrollbar(TCW_SCROLLBAR_V_NEW_TMPL);
this->FinishInitNested(VEH_TRAIN);

@ -230,7 +230,7 @@ public:
this->details_height = 10 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical();
this->CreateNestedTree(wdesc != nullptr);
this->CreateNestedTree();
this->vscroll[0] = this->GetScrollbar(TRW_WIDGET_TOP_SCROLLBAR);
this->vscroll[1] = this->GetScrollbar(TRW_WIDGET_MIDDLE_SCROLLBAR);
this->vscroll[2] = this->GetScrollbar(TRW_WIDGET_BOTTOM_SCROLLBAR);

@ -1483,7 +1483,7 @@ public:
return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
}
void SetupSmallestSize(Window *w, bool init_array) override
void SetupSmallestSize(Window *w) override
{
this->smallest_x = 0; // Biggest child
this->smallest_y = 0; // Biggest child
@ -1496,7 +1496,7 @@ public:
uint nbuttons = 0;
/* First initialise some variables... */
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
child_wid->SetupSmallestSize(w);
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
if (this->IsButton(child_wid->type)) {
nbuttons++;
@ -1925,9 +1925,9 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
uint panel_widths[2]; ///< The width of the two panels (the text panel and date panel)
void SetupSmallestSize(Window *w, bool init_array) override
void SetupSmallestSize(Window *w) override
{
this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
this->NWidgetToolbarContainer::SetupSmallestSize(w);
/* Find the size of panel_widths */
uint i = 0;

@ -995,7 +995,7 @@ NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator()
/* ~NWidgetContainer() takes care of #next and #prev data members. */
/**
* @fn void NWidgetBase::SetupSmallestSize(Window *w, bool init_array)
* @fn void NWidgetBase::SetupSmallestSize(Window *w)
* Compute smallest size needed by the widget.
*
* The smallest size of a widget is the smallest size that a widget needs to
@ -1004,7 +1004,6 @@ NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator()
* background widget without child with a non-negative index.
*
* @param w Window owning the widget.
* @param init_array Initialize the \c w->nested_array.
*
* @note After the computation, the results can be queried by accessing the #smallest_x and #smallest_y data members of the widget.
*/
@ -1409,13 +1408,8 @@ void NWidgetStacked::AdjustPaddingForZoom()
NWidgetContainer::AdjustPaddingForZoom();
}
void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
void NWidgetStacked::SetupSmallestSize(Window *w)
{
if (this->index >= 0 && init_array) { // Fill w->nested_array[]
assert(w->nested_array_size > (uint)this->index);
w->nested_array[this->index] = this;
}
/* Zero size plane selected */
if (this->shown_plane >= SZSP_BEGIN) {
Dimension size = {0, 0};
@ -1445,7 +1439,7 @@ void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
if (this->independent_planes && plane != this->shown_plane) continue;
child_wid->SetupSmallestSize(w, init_array);
child_wid->SetupSmallestSize(w);
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
@ -1598,7 +1592,7 @@ NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPConta
{
}
void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
void NWidgetHorizontal::SetupSmallestSize(Window *w)
{
this->smallest_x = 0; // Sum of minimal size of all children.
this->smallest_y = 0; // Biggest child.
@ -1612,7 +1606,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
uint longest = 0; // Longest child found.
uint max_vert_fill = 0; // Biggest vertical fill step.
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
child_wid->SetupSmallestSize(w);
longest = std::max(longest, child_wid->smallest_x);
max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
@ -1790,7 +1784,7 @@ NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer
{
}
void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
void NWidgetVertical::SetupSmallestSize(Window *w)
{
this->smallest_x = 0; // Biggest child.
this->smallest_y = 0; // Sum of minimal size of all children.
@ -1804,7 +1798,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
uint highest = 0; // Highest child found.
uint max_hor_fill = 0; // Biggest horizontal fill step.
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
child_wid->SetupSmallestSize(w);
highest = std::max(highest, child_wid->smallest_y);
max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
@ -1963,7 +1957,7 @@ NWidgetSpacer::NWidgetSpacer(int width, int height) : NWidgetResizeBase(NWID_SPA
this->SetResize(0, 0);
}
void NWidgetSpacer::SetupSmallestSize(Window *, bool)
void NWidgetSpacer::SetupSmallestSize(Window *)
{
this->smallest_x = this->min_x;
this->smallest_y = this->min_y;
@ -2064,21 +2058,16 @@ void NWidgetMatrix::SetScrollbar(Scrollbar *sb)
this->sb = sb;
}
void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
void NWidgetMatrix::SetupSmallestSize(Window *w)
{
assert(this->head != nullptr);
assert(this->head->next == nullptr);
if (this->index >= 0 && init_array) { // Fill w->nested_array[]
assert(w->nested_array_size > (uint)this->index);
w->nested_array[this->index] = this;
}
/* Reset the widget number. */
NWidgetCore *nw = dynamic_cast<NWidgetCore *>(this->head);
assert(nw != nullptr);
SB(nw->index, 16, 16, 0);
this->head->SetupSmallestSize(w, init_array);
this->head->SetupSmallestSize(w);
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};
@ -2324,14 +2313,10 @@ void NWidgetBackground::AdjustPaddingForZoom()
NWidgetCore::AdjustPaddingForZoom();
}
void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
void NWidgetBackground::SetupSmallestSize(Window *w)
{
if (init_array && this->index >= 0) {
assert(w->nested_array_size > (uint)this->index);
w->nested_array[this->index] = this;
}
if (this->child != nullptr) {
this->child->SetupSmallestSize(w, init_array);
this->child->SetupSmallestSize(w);
this->smallest_x = this->child->smallest_x;
this->smallest_y = this->child->smallest_y;
@ -2483,12 +2468,8 @@ NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID
this->SetIndex(index);
}
void NWidgetViewport::SetupSmallestSize(Window *w, bool init_array)
void NWidgetViewport::SetupSmallestSize(Window *)
{
if (init_array && this->index >= 0) {
assert(w->nested_array_size > (uint)this->index);
w->nested_array[this->index] = this;
}
this->smallest_x = this->min_x;
this->smallest_y = this->min_y;
}
@ -2662,12 +2643,8 @@ NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : N
}
}
void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
void NWidgetScrollbar::SetupSmallestSize(Window *)
{
if (init_array && this->index >= 0) {
assert(w->nested_array_size > (uint)this->index);
w->nested_array[this->index] = this;
}
this->min_x = 0;
this->min_y = 0;
@ -2886,13 +2863,8 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
NWidgetLeaf::closebox_dimension.height += WidgetDimensions::scaled.closebox.Vertical();
}
void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
void NWidgetLeaf::SetupSmallestSize(Window *w)
{
if (this->index >= 0 && init_array) { // Fill w->nested_array[]
assert(w->nested_array_size > (uint)this->index);
w->nested_array[this->index] = this;
}
Dimension padding = {0, 0};
Dimension size = {this->min_x, this->min_y};
Dimension fill = {this->fill_x, this->fill_y};

@ -144,7 +144,7 @@ public:
NWidgetBase(WidgetType tp);
virtual void AdjustPaddingForZoom();
virtual void SetupSmallestSize(Window *w, bool init_array) = 0;
virtual void SetupSmallestSize(Window *w) = 0;
virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
virtual void FillNestedArray(NWidgetBase **array, uint length) = 0;
@ -480,7 +480,7 @@ public:
void SetIndex(int index);
void AdjustPaddingForZoom() override;
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
void FillNestedArray(NWidgetBase **array, uint length) override;
@ -539,7 +539,7 @@ class NWidgetHorizontal : public NWidgetPIPContainer {
public:
NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
};
@ -562,7 +562,7 @@ class NWidgetVertical : public NWidgetPIPContainer {
public:
NWidgetVertical(NWidContainerFlags flags = NC_NONE);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
};
@ -584,7 +584,7 @@ public:
void SetCount(int count);
void SetScrollbar(Scrollbar *sb);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
void FillNestedArray(NWidgetBase **array, uint length) override;
@ -615,7 +615,7 @@ class NWidgetSpacer : public NWidgetResizeBase {
public:
NWidgetSpacer(int width, int height);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void FillNestedArray(NWidgetBase **array, uint length) override;
void Draw(const Window *w) override;
@ -638,7 +638,7 @@ public:
void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post);
void AdjustPaddingForZoom() override;
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
void FillNestedArray(NWidgetBase **array, uint length) override;
@ -665,7 +665,7 @@ class NWidgetViewport : public NWidgetCore {
public:
NWidgetViewport(int index);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void Draw(const Window *w) override;
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom);
@ -865,7 +865,7 @@ class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
public:
NWidgetScrollbar(WidgetType tp, Colours colour, int index);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void Draw(const Window *w) override;
static void InvalidateDimensionCache();
@ -885,7 +885,7 @@ class NWidgetLeaf : public NWidgetCore {
public:
NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip);
void SetupSmallestSize(Window *w, bool init_array) override;
void SetupSmallestSize(Window *w) override;
void Draw(const Window *w) override;
bool ButtonHit(const Point &pt);

@ -983,8 +983,8 @@ void Window::ReInit(int rx, int ry, bool reposition)
this->scale = _gui_scale;
this->OnInit();
/* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
this->nested_root->SetupSmallestSize(this, false);
/* Re-initialize window smallest size. */
this->nested_root->SetupSmallestSize(this);
this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
this->width = this->nested_root->smallest_x;
this->height = this->nested_root->smallest_y;
@ -1508,13 +1508,8 @@ void Window::InitializeData(WindowNumber window_number)
this->window_number = window_number;
this->OnInit();
/* Initialize nested widget tree. */
if (this->nested_array == nullptr) {
this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
this->nested_root->SetupSmallestSize(this, true);
} else {
this->nested_root->SetupSmallestSize(this, false);
}
/* Initialize smallest size. */
this->nested_root->SetupSmallestSize(this);
/* Initialize to smallest size. */
this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _current_text_dir == TD_RTL);
@ -1865,16 +1860,14 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
* @param fill_nested Fill the #nested_array (enabling is expensive!).
* @note Filling the nested array requires an additional traversal through the nested widget tree, and is best performed by #FinishInitNested rather than here.
*/
void Window::CreateNestedTree(bool fill_nested)
void Window::CreateNestedTree()
{
int biggest_index = -1;
this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_begin, this->window_desc->nwid_end, &biggest_index, &this->shade_select);
this->nested_array_size = (uint)(biggest_index + 1);
if (fill_nested) {
this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
}
this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
}
/**
@ -1896,7 +1889,7 @@ void Window::FinishInitNested(WindowNumber window_number)
*/
void Window::InitNested(WindowNumber window_number)
{
this->CreateNestedTree(false);
this->CreateNestedTree();
this->FinishInitNested(window_number);
}

@ -331,7 +331,7 @@ public:
virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const;
void InitNested(WindowNumber number = 0);
void CreateNestedTree(bool fill_nested = true);
void CreateNestedTree();
void FinishInitNested(WindowNumber window_number = 0);
void ChangeWindowClass(WindowClass cls);

Loading…
Cancel
Save