Merge remote-tracking branch 'upstream/master'
This commit is contained in:
165
src/window.cpp
165
src/window.cpp
@@ -39,6 +39,8 @@
|
||||
#include "timer/timer.h"
|
||||
#include "timer/timer_window.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
/* CityMania code start */
|
||||
#include <limits>
|
||||
#include "window_gui.h"
|
||||
@@ -51,7 +53,7 @@
|
||||
#include "safeguards.h"
|
||||
|
||||
/** Values for _settings_client.gui.auto_scrolling */
|
||||
enum ViewportAutoscrolling {
|
||||
enum ViewportAutoscrolling : uint8_t {
|
||||
VA_DISABLED, //!< Do not autoscroll when mouse is at edge of viewport.
|
||||
VA_MAIN_VIEWPORT_FULLSCREEN, //!< Scroll main viewport at edge when using fullscreen.
|
||||
VA_MAIN_VIEWPORT, //!< Scroll main viewport at edge.
|
||||
@@ -112,7 +114,7 @@ std::string _windows_file;
|
||||
|
||||
/** Window description constructor. */
|
||||
WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16_t def_width_trad, int16_t def_height_trad,
|
||||
WindowClass window_class, WindowClass parent_class, uint32_t flags,
|
||||
WindowClass window_class, WindowClass parent_class, WindowDefaultFlags flags,
|
||||
const std::span<const NWidgetPart> nwid_parts, HotkeyList *hotkeys,
|
||||
const std::source_location location) :
|
||||
source_location(location),
|
||||
@@ -123,9 +125,6 @@ WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16_t def_
|
||||
flags(flags),
|
||||
nwid_parts(nwid_parts),
|
||||
hotkeys(hotkeys),
|
||||
pref_sticky(false),
|
||||
pref_width(0),
|
||||
pref_height(0),
|
||||
default_width_trad(def_width_trad),
|
||||
default_height_trad(def_height_trad)
|
||||
{
|
||||
@@ -203,7 +202,7 @@ void WindowDesc::SaveToConfig()
|
||||
void Window::ApplyDefaults()
|
||||
{
|
||||
if (this->nested_root != nullptr && this->nested_root->GetWidgetOfType(WWT_STICKYBOX) != nullptr) {
|
||||
if (this->window_desc.pref_sticky) this->flags |= WF_STICKY;
|
||||
if (this->window_desc.pref_sticky) this->flags.Set(WindowFlag::Sticky);
|
||||
} else {
|
||||
/* There is no stickybox; clear the preference in case someone tried to be funny */
|
||||
this->window_desc.pref_sticky = false;
|
||||
@@ -240,7 +239,7 @@ void Window::DisableAllWidgetHighlight()
|
||||
}
|
||||
}
|
||||
|
||||
CLRBITS(this->flags, WF_HIGHLIGHTED);
|
||||
this->flags.Reset(WindowFlag::Highlighted);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +257,7 @@ void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_co
|
||||
|
||||
if (highlighted_colour != TC_INVALID) {
|
||||
/* If we set a highlight, the window has a highlight */
|
||||
this->flags |= WF_HIGHLIGHTED;
|
||||
this->flags.Set(WindowFlag::Highlighted);
|
||||
} else {
|
||||
/* If we disable a highlight, check all widgets if anyone still has a highlight */
|
||||
bool valid = false;
|
||||
@@ -269,7 +268,7 @@ void Window::SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_co
|
||||
valid = true;
|
||||
}
|
||||
/* If nobody has a highlight, disable the flag on the window */
|
||||
if (!valid) CLRBITS(this->flags, WF_HIGHLIGHTED);
|
||||
if (!valid) this->flags.Reset(WindowFlag::Highlighted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +307,7 @@ void Window::OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_
|
||||
/* Raise the dropdown button */
|
||||
NWidgetCore *nwi2 = this->GetWidget<NWidgetCore>(widget);
|
||||
if ((nwi2->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
|
||||
nwi2->disp_flags &= ~ND_DROPDOWN_ACTIVE;
|
||||
nwi2->disp_flags.Reset(NWidgetDisplayFlag::DropdownActive);
|
||||
} else {
|
||||
this->RaiseWidget(widget);
|
||||
}
|
||||
@@ -374,7 +373,7 @@ void Window::UpdateQueryStringSize()
|
||||
/* virtual */ const Textbuf *Window::GetFocusedTextbuf() const
|
||||
{
|
||||
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
|
||||
return &this->GetQueryString(this->nested_focus->index)->text;
|
||||
return &this->GetQueryString(this->nested_focus->GetIndex())->text;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -387,7 +386,7 @@ void Window::UpdateQueryStringSize()
|
||||
/* virtual */ Point Window::GetCaretPosition() const
|
||||
{
|
||||
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX && !this->querystrings.empty()) {
|
||||
return this->GetQueryString(this->nested_focus->index)->GetCaretPosition(this, this->nested_focus->index);
|
||||
return this->GetQueryString(this->nested_focus->GetIndex())->GetCaretPosition(this, this->nested_focus->GetIndex());
|
||||
}
|
||||
|
||||
Point pt = {0, 0};
|
||||
@@ -403,7 +402,7 @@ void Window::UpdateQueryStringSize()
|
||||
/* virtual */ Rect Window::GetTextBoundingRect(const char *from, const char *to) const
|
||||
{
|
||||
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
|
||||
return this->GetQueryString(this->nested_focus->index)->GetBoundingRect(this, this->nested_focus->index, from, to);
|
||||
return this->GetQueryString(this->nested_focus->GetIndex())->GetBoundingRect(this, this->nested_focus->GetIndex(), from, to);
|
||||
}
|
||||
|
||||
Rect r = {0, 0, 0, 0};
|
||||
@@ -418,7 +417,7 @@ void Window::UpdateQueryStringSize()
|
||||
/* virtual */ ptrdiff_t Window::GetTextCharacterAtPosition(const Point &pt) const
|
||||
{
|
||||
if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) {
|
||||
return this->GetQueryString(this->nested_focus->index)->GetCharAtPosition(this, this->nested_focus->index, pt);
|
||||
return this->GetQueryString(this->nested_focus->GetIndex())->GetCharAtPosition(this, this->nested_focus->GetIndex(), pt);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -511,6 +510,12 @@ bool Window::SetFocusedWidget(WidgetID widget_index)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Window::GetWidgetString([[maybe_unused]] WidgetID widget, StringID stringid) const
|
||||
{
|
||||
if (stringid == STR_NULL) return {};
|
||||
return GetString(stringid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when window gains focus
|
||||
*/
|
||||
@@ -536,7 +541,7 @@ void Window::RaiseButtons(bool autoraise)
|
||||
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) &&
|
||||
if (wid != nullptr && ((type & ~WWB_PUSHBUTTON) < WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
|
||||
(!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && wid->IsLowered()) {
|
||||
wid->SetLowered(false);
|
||||
wid->SetDirty(this);
|
||||
@@ -619,12 +624,12 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
WidgetType widget_type = (nw != nullptr) ? nw->type : WWT_EMPTY;
|
||||
|
||||
/* Allow dropdown close flag detection to work. */
|
||||
if (nw != nullptr) ClrBit(nw->disp_flags, NDB_DROPDOWN_CLOSED);
|
||||
if (nw != nullptr) nw->disp_flags.Reset(NWidgetDisplayFlag::DropdownClosed);
|
||||
|
||||
bool focused_widget_changed = false;
|
||||
/* If clicked on a window that previously did not have focus */
|
||||
if (_focused_window != w && // We already have focus, right?
|
||||
(w->window_desc.flags & WDF_NO_FOCUS) == 0 && // Don't lose focus to toolbars
|
||||
!w->window_desc.flags.Test(WindowDefaultFlag::NoFocus) && // Don't lose focus to toolbars
|
||||
widget_type != WWT_CLOSEBOX) { // Don't change focused window if 'X' (close button) was clicked
|
||||
focused_widget_changed = true;
|
||||
SetFocusedWindow(w);
|
||||
@@ -635,7 +640,7 @@ 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;
|
||||
|
||||
WidgetID widget_index = nw->index; ///< Index of the widget
|
||||
WidgetID widget_index = nw->GetIndex(); ///< 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.
|
||||
@@ -654,7 +659,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
}
|
||||
|
||||
/* Dropdown window of this widget was closed so don't process click this time. */
|
||||
if (HasBit(nw->disp_flags, NDB_DROPDOWN_CLOSED)) return;
|
||||
if (nw->disp_flags.Test(NWidgetDisplayFlag::DropdownClosed)) return;
|
||||
|
||||
if ((widget_type & ~WWB_PUSHBUTTON) < WWT_LAST && (widget_type & WWB_PUSHBUTTON)) w->HandleButtonClick(widget_index);
|
||||
|
||||
@@ -720,9 +725,9 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
return;
|
||||
|
||||
case WWT_STICKYBOX:
|
||||
w->flags ^= WF_STICKY;
|
||||
w->flags.Flip(WindowFlag::Sticky);
|
||||
nw->SetDirty(w);
|
||||
if (citymania::_fn_mod) w->window_desc.pref_sticky = (w->flags & WF_STICKY) != 0;
|
||||
if (citymania::_fn_mod) w->window_desc.pref_sticky = w->flags.Test(WindowFlag::Sticky);
|
||||
return;
|
||||
|
||||
default:
|
||||
@@ -755,18 +760,18 @@ static void DispatchRightClickEvent(Window *w, int x, int y)
|
||||
Point pt = { x, y };
|
||||
|
||||
/* No widget to handle, or the window is not interested in it. */
|
||||
if (wid->index >= 0) {
|
||||
if (w->OnRightClick(pt, wid->index)) return;
|
||||
if (wid->GetIndex() >= 0) {
|
||||
if (w->OnRightClick(pt, wid->GetIndex())) return;
|
||||
}
|
||||
|
||||
/* Right-click close is enabled and there is a closebox. */
|
||||
if (_settings_client.gui.right_click_wnd_close == RCC_YES && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
|
||||
if (_settings_client.gui.right_click_wnd_close == RCC_YES && !w->window_desc.flags.Test(WindowDefaultFlag::NoClose)) {
|
||||
w->Close();
|
||||
} else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && (w->flags & WF_STICKY) == 0 && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
|
||||
} else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && !w->flags.Test(WindowFlag::Sticky) && !w->window_desc.flags.Test(WindowDefaultFlag::NoClose)) {
|
||||
/* Right-click close is enabled, but excluding sticky windows. */
|
||||
w->Close();
|
||||
} else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->tool_tip != 0) {
|
||||
GuiShowTooltips(w, wid->tool_tip, TCC_RIGHT_CLICK);
|
||||
} else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->GetIndex(), TCC_RIGHT_CLICK) && wid->GetToolTip() != STR_NULL) {
|
||||
GuiShowTooltips(w, GetEncodedString(wid->GetToolTip()), TCC_RIGHT_CLICK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,15 +791,15 @@ static void DispatchHoverEvent(Window *w, int x, int y)
|
||||
Point pt = { x, y };
|
||||
|
||||
/* Show the tooltip if there is any */
|
||||
if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) {
|
||||
GuiShowTooltips(w, wid->tool_tip, TCC_HOVER);
|
||||
if (!w->OnTooltip(pt, wid->GetIndex(), TCC_HOVER) && wid->GetToolTip() != STR_NULL) {
|
||||
GuiShowTooltips(w, GetEncodedString(wid->GetToolTip()), TCC_HOVER);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Widget has no index, so the window is not interested in it. */
|
||||
if (wid->index < 0) return;
|
||||
if (wid->GetIndex() < 0) return;
|
||||
|
||||
w->OnHover(pt, wid->index);
|
||||
w->OnHover(pt, wid->GetIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -824,7 +829,7 @@ static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
|
||||
}
|
||||
|
||||
/* Scroll the widget attached to the scrollbar. */
|
||||
Scrollbar *sb = (nwid->scrollbar_index >= 0 ? w->GetScrollbar(nwid->scrollbar_index) : nullptr);
|
||||
Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr);
|
||||
if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) {
|
||||
if (sb->UpdatePosition(wheel)) w->SetDirty();
|
||||
}
|
||||
@@ -1097,8 +1102,6 @@ Window::~Window()
|
||||
{
|
||||
/* Make sure the window is closed, deletion is allowed only in Window::DeleteClosedWindows(). */
|
||||
assert(*this->z_position == nullptr);
|
||||
|
||||
if (this->viewport != nullptr) DeleteWindowViewport(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1152,7 +1155,7 @@ Window *GetMainWindow()
|
||||
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
|
||||
{
|
||||
Window *w = FindWindowById(cls, number);
|
||||
if (w != nullptr && (force || (w->flags & WF_STICKY) == 0)) {
|
||||
if (w != nullptr && (force || !w->flags.Test(WindowFlag::Sticky))) {
|
||||
w->Close(data);
|
||||
}
|
||||
}
|
||||
@@ -1379,7 +1382,7 @@ void Window::InitializeData(WindowNumber window_number)
|
||||
/* Set up window properties; some of them are needed to set up smallest size below */
|
||||
this->window_class = this->window_desc.cls;
|
||||
this->SetWhiteBorder();
|
||||
if (this->window_desc.default_pos == WDP_CENTER) this->flags |= WF_CENTERED;
|
||||
if (this->window_desc.default_pos == WDP_CENTER) this->flags.Set(WindowFlag::Centred);
|
||||
this->owner = INVALID_OWNER;
|
||||
this->nested_focus = nullptr;
|
||||
this->window_number = window_number;
|
||||
@@ -1848,8 +1851,8 @@ static void DecreaseWindowCounters()
|
||||
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);
|
||||
if (sb->disp_flags.Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) {
|
||||
sb->disp_flags.Reset(NWidgetDisplayFlag::ScrollbarUp).Reset(NWidgetDisplayFlag::ScrollbarDown);
|
||||
w->mouse_capture_widget = -1;
|
||||
sb->SetDirty(w);
|
||||
}
|
||||
@@ -1866,8 +1869,8 @@ static void DecreaseWindowCounters()
|
||||
}
|
||||
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if ((w->flags & WF_TIMEOUT) && --w->timeout_timer == 0) {
|
||||
CLRBITS(w->flags, WF_TIMEOUT);
|
||||
if (w->flags.Test(WindowFlag::Timeout) && --w->timeout_timer == 0) {
|
||||
w->flags.Reset(WindowFlag::Timeout);
|
||||
|
||||
w->OnTimeout();
|
||||
w->RaiseButtons(true);
|
||||
@@ -1937,12 +1940,12 @@ static void HandleMouseOver()
|
||||
/* send an event in client coordinates. */
|
||||
Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
|
||||
const NWidgetCore *widget = w->nested_root->GetWidgetFromPos(pt.x, pt.y);
|
||||
if (widget != nullptr) w->OnMouseOver(pt, widget->index);
|
||||
if (widget != nullptr) w->OnMouseOver(pt, widget->GetIndex());
|
||||
}
|
||||
}
|
||||
|
||||
/** Direction for moving the window. */
|
||||
enum PreventHideDirection {
|
||||
enum PreventHideDirection : uint8_t {
|
||||
PHD_UP, ///< Above v is a safe position.
|
||||
PHD_DOWN, ///< Below v is a safe position.
|
||||
};
|
||||
@@ -2115,10 +2118,10 @@ static EventState HandleWindowDragging()
|
||||
|
||||
/* Otherwise find the window... */
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if (w->flags & WF_DRAGGING) {
|
||||
if (w->flags.Test(WindowFlag::Dragging)) {
|
||||
/* Stop the dragging if the left mouse button was released */
|
||||
if (!_left_button_down) {
|
||||
w->flags &= ~WF_DRAGGING;
|
||||
w->flags.Reset(WindowFlag::Dragging);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2210,10 +2213,11 @@ static EventState HandleWindowDragging()
|
||||
|
||||
w->SetDirty();
|
||||
return ES_HANDLED;
|
||||
} else if (w->flags & WF_SIZING) {
|
||||
} else if (w->flags.Test(WindowFlag::SizingLeft) || w->flags.Test(WindowFlag::SizingRight)) {
|
||||
/* Stop the sizing if the left mouse button was released */
|
||||
if (!_left_button_down) {
|
||||
w->flags &= ~WF_SIZING;
|
||||
w->flags.Reset(WindowFlag::SizingLeft);
|
||||
w->flags.Reset(WindowFlag::SizingRight);
|
||||
w->SetDirty();
|
||||
break;
|
||||
}
|
||||
@@ -2222,7 +2226,7 @@ static EventState HandleWindowDragging()
|
||||
* If resizing the left edge of the window, moving to the left makes the window bigger not smaller.
|
||||
*/
|
||||
int x, y = _cursor.pos.y - _drag_delta.y;
|
||||
if (w->flags & WF_SIZING_LEFT) {
|
||||
if (w->flags.Test(WindowFlag::SizingLeft)) {
|
||||
x = _drag_delta.x - _cursor.pos.x;
|
||||
} else {
|
||||
x = _cursor.pos.x - _drag_delta.x;
|
||||
@@ -2256,7 +2260,7 @@ static EventState HandleWindowDragging()
|
||||
|
||||
/* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
|
||||
_drag_delta.y += y;
|
||||
if ((w->flags & WF_SIZING_LEFT) && x != 0) {
|
||||
if (w->flags.Test(WindowFlag::SizingLeft) && x != 0) {
|
||||
_drag_delta.x -= x; // x > 0 -> window gets longer -> left-edge moves to left -> subtract x to get new position.
|
||||
w->SetDirtyAsBlocks();
|
||||
w->left -= x; // If dragging left edge, move left window edge in opposite direction by the same amount.
|
||||
@@ -2281,8 +2285,8 @@ static EventState HandleWindowDragging()
|
||||
*/
|
||||
static void StartWindowDrag(Window *w)
|
||||
{
|
||||
w->flags |= WF_DRAGGING;
|
||||
w->flags &= ~WF_CENTERED;
|
||||
w->flags.Set(WindowFlag::Dragging);
|
||||
w->flags.Reset(WindowFlag::Centred);
|
||||
_dragging_window = true;
|
||||
|
||||
_drag_delta.x = w->left - _cursor.pos.x;
|
||||
@@ -2298,8 +2302,8 @@ static void StartWindowDrag(Window *w)
|
||||
*/
|
||||
static void StartWindowSizing(Window *w, bool to_left)
|
||||
{
|
||||
w->flags |= to_left ? WF_SIZING_LEFT : WF_SIZING_RIGHT;
|
||||
w->flags &= ~WF_CENTERED;
|
||||
w->flags.Set(to_left ? WindowFlag::SizingLeft : WindowFlag::SizingRight);
|
||||
w->flags.Reset(WindowFlag::Centred);
|
||||
_dragging_window = true;
|
||||
|
||||
_drag_delta.x = _cursor.pos.x;
|
||||
@@ -2325,10 +2329,10 @@ static void HandleScrollbarScrolling(Window *w)
|
||||
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
||||
}
|
||||
|
||||
if (sb->disp_flags & ND_SCROLLBAR_BTN) {
|
||||
if (sb->disp_flags.Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) {
|
||||
if (_scroller_click_timeout == 1) {
|
||||
_scroller_click_timeout = 3;
|
||||
if (sb->UpdatePosition(rtl == HasBit(sb->disp_flags, NDB_SCROLLBAR_UP) ? 1 : -1)) w->SetDirty();
|
||||
if (sb->UpdatePosition(rtl == sb->disp_flags.Test(NWidgetDisplayFlag::ScrollbarUp) ? 1 : -1)) w->SetDirty();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -2397,7 +2401,7 @@ static EventState HandleViewportScroll()
|
||||
return ES_NOT_HANDLED;
|
||||
}
|
||||
|
||||
if (_last_scroll_window == GetMainWindow() && _last_scroll_window->viewport->follow_vehicle != INVALID_VEHICLE) {
|
||||
if (_last_scroll_window == GetMainWindow() && _last_scroll_window->viewport->follow_vehicle != VehicleID::Invalid()) {
|
||||
/* If the main window is following a vehicle, then first let go of it! */
|
||||
const Vehicle *veh = Vehicle::Get(_last_scroll_window->viewport->follow_vehicle);
|
||||
ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
|
||||
@@ -2467,7 +2471,7 @@ static bool MaybeBringWindowToFront(Window *w)
|
||||
for (; !it.IsEnd(); ++it) {
|
||||
Window *u = *it;
|
||||
/* A modal child will prevent the activation of the parent window */
|
||||
if (u->parent == w && (u->window_desc.flags & WDF_MODAL)) {
|
||||
if (u->parent == w && u->window_desc.flags.Test(WindowDefaultFlag::Modal)) {
|
||||
u->SetWhiteBorder();
|
||||
u->SetDirty();
|
||||
return false;
|
||||
@@ -2554,7 +2558,7 @@ EventState Window::HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode
|
||||
break;
|
||||
|
||||
case QueryString::ACTION_CLEAR:
|
||||
if (query->text.bytes <= 1) {
|
||||
if (StrEmpty(query->text.GetText())) {
|
||||
/* If already empty, unfocus instead */
|
||||
this->UnfocusFocusedWidget();
|
||||
} else {
|
||||
@@ -2618,7 +2622,7 @@ void HandleKeypress(uint keycode, char32_t key)
|
||||
if (_focused_window->window_class == WC_CONSOLE) {
|
||||
if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
||||
} else {
|
||||
if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
|
||||
if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->GetIndex(), key, keycode) == ES_HANDLED) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2689,7 +2693,7 @@ void HandleTextInput(const char *str, bool marked, const char *caret, const char
|
||||
{
|
||||
if (!EditBoxInGlobalFocus()) return;
|
||||
|
||||
_focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->index, str, marked, caret, insert_location, replacement_end);
|
||||
_focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->GetIndex(), str, marked, caret, insert_location, replacement_end);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2713,7 +2717,7 @@ static void HandleAutoscroll()
|
||||
int x = _cursor.pos.x;
|
||||
int y = _cursor.pos.y;
|
||||
Window *w = FindWindowFromPt(x, y);
|
||||
if (w == nullptr || w->flags & WF_DISABLE_VP_SCROLL) return;
|
||||
if (w == nullptr || w->flags.Test(WindowFlag::DisableVpScroll)) return;
|
||||
if (_settings_client.gui.auto_scrolling != VA_EVERY_VIEWPORT && w->window_class != WC_MAIN_WINDOW) return;
|
||||
|
||||
Viewport *vp = IsPtInWindowViewport(w, x, y);
|
||||
@@ -2726,22 +2730,22 @@ static void HandleAutoscroll()
|
||||
/* If we succeed at scrolling in any direction, stop following a vehicle. */
|
||||
static const int SCROLLSPEED = 3;
|
||||
if (x - 15 < 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->CancelFollow(*w);
|
||||
w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom);
|
||||
} else if (15 - (vp->width - x) > 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->CancelFollow(*w);
|
||||
w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * SCROLLSPEED, vp->zoom);
|
||||
}
|
||||
if (y - 15 < 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->CancelFollow(*w);
|
||||
w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom);
|
||||
} else if (15 - (vp->height - y) > 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->CancelFollow(*w);
|
||||
w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom);
|
||||
}
|
||||
}
|
||||
|
||||
enum MouseClick {
|
||||
enum MouseClick : uint8_t {
|
||||
MC_NONE = 0,
|
||||
MC_LEFT,
|
||||
MC_RIGHT,
|
||||
@@ -2804,7 +2808,8 @@ static void HandleKeyScrolling()
|
||||
|
||||
if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
|
||||
/* Key scrolling stops following a vehicle. */
|
||||
GetMainWindow()->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
Window *main_window = GetMainWindow();
|
||||
main_window->viewport->CancelFollow(*main_window);
|
||||
}
|
||||
|
||||
ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
|
||||
@@ -2852,7 +2857,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||
}
|
||||
|
||||
if (vp != nullptr) {
|
||||
if (scrollwheel_scrolling && !(w->flags & WF_DISABLE_VP_SCROLL)) {
|
||||
if (scrollwheel_scrolling && !w->flags.Test(WindowFlag::DisableVpScroll)) {
|
||||
_scrolling_viewport = true;
|
||||
_cursor.fix_at = true;
|
||||
return;
|
||||
@@ -2861,9 +2866,9 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||
switch (click) {
|
||||
case MC_DOUBLE_LEFT:
|
||||
case MC_LEFT:
|
||||
if (citymania::HandleMouseClick(vp, click == MC_DOUBLE_LEFT)) return;
|
||||
if (HandleViewportClicked(vp, x, y, click == MC_DOUBLE_LEFT)) return;
|
||||
if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
|
||||
if (citymania::HandleMouseClick(vp, click == MC_DOUBLE_LEFT)) return;
|
||||
if (HandleViewportClicked(*vp, x, y, click == MC_DOUBLE_LEFT)) return;
|
||||
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
|
||||
_settings_client.gui.scroll_mode == VSM_MAP_LMB) {
|
||||
_scrolling_viewport = true;
|
||||
_cursor.fix_at = false;
|
||||
@@ -2872,7 +2877,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||
break;
|
||||
|
||||
case MC_RIGHT:
|
||||
if (!(w->flags & WF_DISABLE_VP_SCROLL) &&
|
||||
if (!w->flags.Test(WindowFlag::DisableVpScroll) &&
|
||||
_settings_client.gui.scroll_mode != VSM_MAP_LMB) {
|
||||
_scrolling_viewport = true;
|
||||
_cursor.fix_at = (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED ||
|
||||
@@ -3008,7 +3013,7 @@ static void CheckSoftLimit()
|
||||
uint deletable_count = 0;
|
||||
Window *last_deletable = nullptr;
|
||||
for (Window *w : Window::IterateFromFront()) {
|
||||
if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || (w->flags & WF_STICKY)) continue;
|
||||
if (w->window_class == WC_MAIN_WINDOW || IsVitalWindow(w) || w->flags.Test(WindowFlag::Sticky)) continue;
|
||||
|
||||
last_deletable = w;
|
||||
deletable_count++;
|
||||
@@ -3078,8 +3083,8 @@ static IntervalTimer<TimerWindow> white_border_interval(std::chrono::millisecond
|
||||
if (_network_dedicated) return;
|
||||
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) {
|
||||
CLRBITS(w->flags, WF_WHITE_BORDER);
|
||||
if (w->flags.Test(WindowFlag::WhiteBorder) && --w->white_border_timer == 0) {
|
||||
w->flags.Reset(WindowFlag::WhiteBorder);
|
||||
w->SetDirty();
|
||||
}
|
||||
}
|
||||
@@ -3219,7 +3224,7 @@ void Window::ProcessScheduledInvalidations()
|
||||
*/
|
||||
void Window::ProcessHighlightedInvalidations()
|
||||
{
|
||||
if ((this->flags & WF_HIGHLIGHTED) == 0) return;
|
||||
if (!this->flags.Test(WindowFlag::Highlighted)) return;
|
||||
|
||||
for (const auto &pair : this->widget_lookup) {
|
||||
if (pair.second->IsHighlighted()) pair.second->SetDirty(this);
|
||||
@@ -3298,8 +3303,8 @@ void CloseNonVitalWindows()
|
||||
{
|
||||
/* Note: the container remains stable, even when deleting windows. */
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if ((w->window_desc.flags & WDF_NO_CLOSE) == 0 &&
|
||||
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
|
||||
if (!w->window_desc.flags.Test(WindowDefaultFlag::NoClose) &&
|
||||
!w->flags.Test(WindowFlag::Sticky)) { // do not delete windows which are 'pinned'
|
||||
|
||||
w->Close();
|
||||
}
|
||||
@@ -3317,7 +3322,7 @@ void CloseAllNonVitalWindows()
|
||||
{
|
||||
/* Note: the container remains stable, even when closing windows. */
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if ((w->window_desc.flags & WDF_NO_CLOSE) == 0) {
|
||||
if (!w->window_desc.flags.Test(WindowDefaultFlag::NoClose)) {
|
||||
w->Close();
|
||||
}
|
||||
}
|
||||
@@ -3342,7 +3347,7 @@ void CloseConstructionWindows()
|
||||
{
|
||||
/* Note: the container remains stable, even when deleting windows. */
|
||||
for (Window *w : Window::Iterate()) {
|
||||
if (w->window_desc.flags & WDF_CONSTRUCTION) {
|
||||
if (w->window_desc.flags.Test(WindowDefaultFlag::Construction)) {
|
||||
w->Close();
|
||||
}
|
||||
}
|
||||
@@ -3533,7 +3538,7 @@ void RelocateAllWindows(int neww, int newh)
|
||||
continue;
|
||||
|
||||
default: {
|
||||
if (w->flags & WF_CENTERED) {
|
||||
if (w->flags.Test(WindowFlag::Centred)) {
|
||||
top = (newh - w->height) >> 1;
|
||||
left = (neww - w->width) >> 1;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user