Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/ci-build.yml # .github/workflows/release-linux.yml # .github/workflows/release-macos.yml # .github/workflows/release-windows.yml # .gitignore # COMPILING.md # src/company_gui.cpp # src/date_gui.cpp # src/engine.cpp # src/engine_func.h # src/fileio.cpp # src/linkgraph/linkgraph_gui.h # src/newgrf_debug_gui.cpp # src/newgrf_gui.cpp # src/order_gui.cpp # src/osk_gui.cpp # src/rail_gui.cpp # src/road_gui.cpp # src/script/api/script_event_types.hpp # src/sl/oldloader_sl.cpp # src/smallmap_gui.cpp # src/station_cmd.cpp # src/toolbar_gui.cpp # src/town_gui.cpp # src/transparency_gui.cpp # src/vehicle_gui.cpp # src/widget.cpp # src/widget_type.h # src/widgets/dropdown.cpp # src/widgets/dropdown_func.h # src/widgets/dropdown_type.h # src/widgets/group_widget.h # src/widgets/vehicle_widget.h # src/window.cpp # src/window_gui.h # src/window_type.h
This commit is contained in:
116
src/window.cpp
116
src/window.cpp
@@ -216,7 +216,7 @@ void Window::ApplyDefaults()
|
||||
* @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
|
||||
* @note The widget does not know where a list printed at the widget ends, so below a list is not a wrong position.
|
||||
*/
|
||||
int Window::GetRowFromWidget(int clickpos, int widget, int padding, int line_height) const
|
||||
int Window::GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height) const
|
||||
{
|
||||
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(widget);
|
||||
if (line_height < 0) line_height = wid->resize_y;
|
||||
@@ -229,10 +229,8 @@ int Window::GetRowFromWidget(int clickpos, int widget, int padding, int line_hei
|
||||
*/
|
||||
void Window::DisableAllWidgetHighlight()
|
||||
{
|
||||
for (uint i = 0; i < this->nested_array_size; i++) {
|
||||
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
|
||||
if (nwid == nullptr) continue;
|
||||
|
||||
for (auto &pair : this->widget_lookup) {
|
||||
NWidgetBase *nwid = pair.second;
|
||||
if (nwid->IsHighlighted()) {
|
||||
nwid->SetHighlighted(TC_INVALID);
|
||||
nwid->SetDirty(this);
|
||||
@@ -247,10 +245,8 @@ void Window::DisableAllWidgetHighlight()
|
||||
* @param widget_index index of this widget in the window
|
||||
* @param highlighted_colour Colour of highlight, or TC_INVALID to disable.
|
||||
*/
|
||||
void Window::SetWidgetHighlight(byte widget_index, TextColour highlighted_colour)
|
||||
void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
|
||||
{
|
||||
dbg_assert(widget_index < this->nested_array_size);
|
||||
|
||||
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget_index);
|
||||
if (nwid == nullptr) return;
|
||||
|
||||
@@ -263,10 +259,9 @@ void Window::SetWidgetHighlight(byte widget_index, TextColour highlighted_colour
|
||||
} else {
|
||||
/* If we disable a highlight, check all widgets if anyone still has a highlight */
|
||||
bool valid = false;
|
||||
for (uint i = 0; i < this->nested_array_size; i++) {
|
||||
NWidgetBase *child_nwid = this->GetWidget<NWidgetBase>(i);
|
||||
if (child_nwid == nullptr) continue;
|
||||
if (!child_nwid->IsHighlighted()) continue;
|
||||
for (const auto &pair : this->widget_lookup) {
|
||||
nwid = pair.second;
|
||||
if (!nwid->IsHighlighted()) continue;
|
||||
|
||||
valid = true;
|
||||
}
|
||||
@@ -280,10 +275,8 @@ void Window::SetWidgetHighlight(byte widget_index, TextColour highlighted_colour
|
||||
* @param widget_index index of this widget in the window
|
||||
* @return status of the widget ie: highlighted = true, not highlighted = false
|
||||
*/
|
||||
bool Window::IsWidgetHighlighted(byte widget_index) const
|
||||
bool Window::IsWidgetHighlighted(WidgetID widget_index) const
|
||||
{
|
||||
dbg_assert(widget_index < this->nested_array_size);
|
||||
|
||||
const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget_index);
|
||||
if (nwid == nullptr) return false;
|
||||
|
||||
@@ -297,7 +290,7 @@ bool Window::IsWidgetHighlighted(byte widget_index) const
|
||||
* @param index the element in the dropdown that is selected.
|
||||
* @param instant_close whether the dropdown was configured to close on mouse up.
|
||||
*/
|
||||
void Window::OnDropdownClose(Point pt, int widget, int index, bool instant_close)
|
||||
void Window::OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close)
|
||||
{
|
||||
if (widget < 0) return;
|
||||
|
||||
@@ -324,7 +317,7 @@ void Window::OnDropdownClose(Point pt, int widget, int index, bool instant_close
|
||||
* @param widnum Scrollbar widget index
|
||||
* @return Scrollbar to the widget
|
||||
*/
|
||||
const Scrollbar *Window::GetScrollbar(uint widnum) const
|
||||
const Scrollbar *Window::GetScrollbar(WidgetID widnum) const
|
||||
{
|
||||
return this->GetWidget<NWidgetScrollbar>(widnum);
|
||||
}
|
||||
@@ -334,7 +327,7 @@ const Scrollbar *Window::GetScrollbar(uint widnum) const
|
||||
* @param widnum Scrollbar widget index
|
||||
* @return Scrollbar to the widget
|
||||
*/
|
||||
Scrollbar *Window::GetScrollbar(uint widnum)
|
||||
Scrollbar *Window::GetScrollbar(WidgetID widnum)
|
||||
{
|
||||
return this->GetWidget<NWidgetScrollbar>(widnum);
|
||||
}
|
||||
@@ -344,7 +337,7 @@ Scrollbar *Window::GetScrollbar(uint widnum)
|
||||
* @param widnum Editbox widget index
|
||||
* @return QueryString or nullptr.
|
||||
*/
|
||||
const QueryString *Window::GetQueryString(uint widnum) const
|
||||
const QueryString *Window::GetQueryString(WidgetID widnum) const
|
||||
{
|
||||
auto query = this->querystrings.find(widnum);
|
||||
return query != this->querystrings.end() ? query->second : nullptr;
|
||||
@@ -355,7 +348,7 @@ const QueryString *Window::GetQueryString(uint widnum) const
|
||||
* @param widnum Editbox widget index
|
||||
* @return QueryString or nullptr.
|
||||
*/
|
||||
QueryString *Window::GetQueryString(uint widnum)
|
||||
QueryString *Window::GetQueryString(WidgetID widnum)
|
||||
{
|
||||
auto query = this->querystrings.find(widnum);
|
||||
return query != this->querystrings.end() ? query->second : nullptr;
|
||||
@@ -508,20 +501,21 @@ void Window::UnfocusFocusedWidget()
|
||||
* @param widget_index Index of the widget in the window to set the focus to.
|
||||
* @return Focus has changed.
|
||||
*/
|
||||
bool Window::SetFocusedWidget(int widget_index)
|
||||
bool Window::SetFocusedWidget(WidgetID widget_index)
|
||||
{
|
||||
/* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */
|
||||
if ((uint)widget_index >= this->nested_array_size) return false;
|
||||
NWidgetCore *widget = this->GetWidget<NWidgetCore>(widget_index);
|
||||
dbg_assert(widget != nullptr); /* Setting focus to a non-existing widget is a bad idea. */
|
||||
|
||||
dbg_assert(this->nested_array[widget_index] != nullptr); // Setting focus to a non-existing widget is a bad idea.
|
||||
if (this->nested_focus != nullptr) {
|
||||
if (this->GetWidget<NWidgetCore>(widget_index) == this->nested_focus) return false;
|
||||
/* Do nothing if widget_index is already focused. */
|
||||
if (widget == this->nested_focus) return false;
|
||||
|
||||
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
|
||||
this->nested_focus->SetDirty(this);
|
||||
if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
}
|
||||
this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
|
||||
|
||||
this->nested_focus = widget;
|
||||
if (_focused_window == this && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
|
||||
return true;
|
||||
}
|
||||
@@ -548,21 +542,23 @@ void Window::OnFocusLost(bool closing, Window *newly_focused_window)
|
||||
*/
|
||||
void Window::RaiseButtons(bool autoraise)
|
||||
{
|
||||
for (uint i = 0; i < this->nested_array_size; i++) {
|
||||
if (this->nested_array[i] == nullptr) continue;
|
||||
WidgetType type = this->nested_array[i]->type;
|
||||
for (auto &pair : this->widget_lookup) {
|
||||
WidgetType type = pair.second->type;
|
||||
NWidgetCore *wid = dynamic_cast<NWidgetCore *>(pair.second);
|
||||
if (((type & ~WWB_PUSHBUTTON) < WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
|
||||
(!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && this->IsWidgetLowered(i)) {
|
||||
this->RaiseWidget(i);
|
||||
this->SetWidgetDirty(i);
|
||||
(!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && wid->IsLowered()) {
|
||||
wid->SetLowered(false);
|
||||
wid->SetDirty(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Special widgets without widget index */
|
||||
NWidgetCore *wid = this->nested_root != nullptr ? (NWidgetCore*)this->nested_root->GetWidgetOfType(WWT_DEFSIZEBOX) : nullptr;
|
||||
if (wid != nullptr) {
|
||||
wid->SetLowered(false);
|
||||
wid->SetDirty(this);
|
||||
{
|
||||
NWidgetCore *wid = this->nested_root != nullptr ? dynamic_cast<NWidgetCore *>(this->nested_root->GetWidgetOfType(WWT_DEFSIZEBOX)) : nullptr;
|
||||
if (wid != nullptr) {
|
||||
wid->SetLowered(false);
|
||||
wid->SetDirty(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,12 +566,13 @@ void Window::RaiseButtons(bool autoraise)
|
||||
* Invalidate a widget, i.e. mark it as being changed and in need of redraw.
|
||||
* @param widget_index the widget to redraw.
|
||||
*/
|
||||
void Window::SetWidgetDirty(byte widget_index)
|
||||
void Window::SetWidgetDirty(WidgetID widget_index)
|
||||
{
|
||||
/* Sometimes this function is called before the window is even fully initialized */
|
||||
if (this->nested_array == nullptr) return;
|
||||
auto it = this->widget_lookup.find(widget_index);
|
||||
if (it == std::end(this->widget_lookup)) return;
|
||||
|
||||
this->nested_array[widget_index]->SetDirty(this);
|
||||
it->second->SetDirty(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -608,7 +605,7 @@ EventState Window::OnHotkey(int hotkey)
|
||||
* unclicked in a few ticks.
|
||||
* @param widget the widget to "click"
|
||||
*/
|
||||
void Window::HandleButtonClick(byte widget)
|
||||
void Window::HandleButtonClick(WidgetID widget)
|
||||
{
|
||||
this->LowerWidget(widget);
|
||||
this->SetTimeout();
|
||||
@@ -644,12 +641,12 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
/* don't allow any interaction if the button has been disabled */
|
||||
if (nw->IsDisabled()) return;
|
||||
|
||||
int widget_index = nw->index; ///< Index of the widget
|
||||
WidgetID widget_index = nw->index; ///< Index of the widget
|
||||
|
||||
/* Clicked on a widget that is not disabled.
|
||||
* So unless the clicked widget is the caption bar, change focus to this widget.
|
||||
* Exception: In the OSK we always want the editbox to stay focused. */
|
||||
if (widget_type != WWT_CAPTION && w->window_class != WC_OSK) {
|
||||
if (widget_index >= 0 && widget_type != WWT_CAPTION && w->window_class != WC_OSK) {
|
||||
/* focused_widget_changed is 'now' only true if the window this widget
|
||||
* is in gained focus. In that case it must remain true, also if the
|
||||
* local widget focus did not change. As such it's the logical-or of
|
||||
@@ -1107,9 +1104,6 @@ Window::~Window()
|
||||
assert(this->window_class == WC_INVALID);
|
||||
|
||||
if (this->viewport != nullptr) DeleteWindowViewport(this);
|
||||
|
||||
free(this->nested_array); // Contents is released through deletion of #nested_root.
|
||||
delete this->nested_root;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1495,7 +1489,7 @@ void Window::ChangeWindowClass(WindowClass cls)
|
||||
* @param window_number Number being assigned to the new window
|
||||
* @return Window pointer of the newly created window
|
||||
* @pre If nested widgets are used (\a widget is \c nullptr), #nested_root and #nested_array_size must be initialized.
|
||||
* In addition, #nested_array is either \c nullptr, or already initialized.
|
||||
* In addition, #widget_lookup is either \c nullptr, or already initialized.
|
||||
*/
|
||||
void Window::InitializeData(WindowNumber window_number)
|
||||
{
|
||||
@@ -1855,19 +1849,15 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
|
||||
|
||||
/**
|
||||
* Perform the first part of the initialization of a nested widget tree.
|
||||
* Construct a nested widget tree in #nested_root, and optionally fill the #nested_array array to provide quick access to the uninitialized widgets.
|
||||
* Construct a nested widget tree in #nested_root, and optionally fill the #widget_lookup array to provide quick access to the uninitialized widgets.
|
||||
* This is mainly useful for setting very basic properties.
|
||||
* @param fill_nested Fill the #nested_array (enabling is expensive!).
|
||||
* @param fill_nested Fill the #widget_lookup (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()
|
||||
{
|
||||
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);
|
||||
|
||||
this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
|
||||
this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
|
||||
this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_begin, this->window_desc->nwid_end, &this->shade_select);
|
||||
this->nested_root->FillWidgetLookup(this->widget_lookup);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1985,9 +1975,9 @@ static void DecreaseWindowCounters()
|
||||
|
||||
if (_scroller_click_timeout == 0) {
|
||||
/* Unclick scrollbar buttons if they are pressed. */
|
||||
for (uint i = 0; i < w->nested_array_size; i++) {
|
||||
NWidgetBase *nwid = w->nested_array[i];
|
||||
if (nwid != nullptr && (nwid->type == NWID_HSCROLLBAR || nwid->type == NWID_VSCROLLBAR)) {
|
||||
for (auto &pair : w->widget_lookup) {
|
||||
NWidgetBase *nwid = pair.second;
|
||||
if (nwid->type == NWID_HSCROLLBAR || nwid->type == NWID_VSCROLLBAR) {
|
||||
NWidgetScrollbar *sb = static_cast<NWidgetScrollbar*>(nwid);
|
||||
if (sb->disp_flags & (ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN)) {
|
||||
sb->disp_flags &= ~(ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN);
|
||||
@@ -2636,7 +2626,7 @@ static bool MaybeBringWindowToFront(Window *w)
|
||||
* @return #ES_HANDLED if the key press has been handled and no other
|
||||
* window should receive the event.
|
||||
*/
|
||||
EventState Window::HandleEditBoxKey(int wid, WChar key, uint16 keycode)
|
||||
EventState Window::HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
|
||||
{
|
||||
QueryString *query = this->GetQueryString(wid);
|
||||
if (query == nullptr) return ES_NOT_HANDLED;
|
||||
@@ -2709,7 +2699,7 @@ EventState Window::HandleEditBoxKey(int wid, WChar key, uint16 keycode)
|
||||
* @param wid Editbox widget.
|
||||
* @return if the Editbox was successfully cleared
|
||||
*/
|
||||
bool Window::ClearEditBox(int wid)
|
||||
bool Window::ClearEditBox(WidgetID wid)
|
||||
{
|
||||
QueryString *query = this->GetQueryString(wid);
|
||||
if (query == nullptr) return false;
|
||||
@@ -2840,7 +2830,7 @@ void HandleShiftChanged()
|
||||
* @param wid Edit box widget.
|
||||
* @param str Text string to insert.
|
||||
*/
|
||||
/* virtual */ void Window::InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
|
||||
/* virtual */ void Window::InsertTextString(WidgetID wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
|
||||
{
|
||||
QueryString *query = this->GetQueryString(wid);
|
||||
if (query == nullptr) return;
|
||||
@@ -3360,7 +3350,7 @@ void SetWindowDirty(WindowClass cls, WindowNumber number)
|
||||
* @param number Window number in that class
|
||||
* @param widget_index Index number of the widget that needs repainting
|
||||
*/
|
||||
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
|
||||
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
|
||||
{
|
||||
if (cls < WC_END && !_present_window_types[cls]) return;
|
||||
|
||||
@@ -3420,8 +3410,8 @@ void Window::ProcessHighlightedInvalidations()
|
||||
{
|
||||
if ((this->flags & WF_HIGHLIGHTED) == 0) return;
|
||||
|
||||
for (uint i = 0; i < this->nested_array_size; i++) {
|
||||
if (this->IsWidgetHighlighted(i)) this->SetWidgetDirty(i);
|
||||
for (const auto &pair : this->widget_lookup) {
|
||||
if (pair.second->IsHighlighted()) pair.second->SetDirty(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user