Merge remote-tracking branch 'upstream/master'
This commit is contained in:
184
src/window.cpp
184
src/window.cpp
@@ -94,7 +94,7 @@ Point _cursorpos_drag_start;
|
||||
|
||||
int _scrollbar_start_pos;
|
||||
int _scrollbar_size;
|
||||
byte _scroller_click_timeout = 0;
|
||||
uint8_t _scroller_click_timeout = 0;
|
||||
|
||||
bool _scrolling_viewport; ///< A viewport is being scrolled with the mouse.
|
||||
bool _mouse_hovering; ///< The mouse is hovering over the same point.
|
||||
@@ -111,18 +111,17 @@ std::vector<WindowDesc*> *_window_descs = nullptr;
|
||||
std::string _windows_file;
|
||||
|
||||
/** Window description constructor. */
|
||||
WindowDesc::WindowDesc(const char * const file, const int line, WindowPosition def_pos, const char *ini_key, int16_t def_width_trad, int16_t def_height_trad,
|
||||
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,
|
||||
const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, HotkeyList *hotkeys) :
|
||||
file(file),
|
||||
line(line),
|
||||
const std::span<const NWidgetPart> nwid_parts, HotkeyList *hotkeys,
|
||||
const std::source_location location) :
|
||||
source_location(location),
|
||||
default_pos(def_pos),
|
||||
cls(window_class),
|
||||
parent_cls(parent_class),
|
||||
ini_key(ini_key),
|
||||
flags(flags),
|
||||
nwid_begin(nwid_begin),
|
||||
nwid_end(nwid_end),
|
||||
nwid_parts(nwid_parts),
|
||||
hotkeys(hotkeys),
|
||||
pref_sticky(false),
|
||||
pref_width(0),
|
||||
@@ -136,7 +135,7 @@ WindowDesc::WindowDesc(const char * const file, const int line, WindowPosition d
|
||||
|
||||
WindowDesc::~WindowDesc()
|
||||
{
|
||||
_window_descs->erase(std::find(_window_descs->begin(), _window_descs->end(), this));
|
||||
_window_descs->erase(std::ranges::find(*_window_descs, this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,10 +203,10 @@ 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 |= WF_STICKY;
|
||||
} else {
|
||||
/* There is no stickybox; clear the preference in case someone tried to be funny */
|
||||
this->window_desc->pref_sticky = false;
|
||||
this->window_desc.pref_sticky = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,7 +624,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
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 & WDF_NO_FOCUS) == 0 && // 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);
|
||||
@@ -690,11 +689,11 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
|
||||
case WWT_DEFSIZEBOX: {
|
||||
if (citymania::_fn_mod) {
|
||||
w->window_desc->pref_width = w->width;
|
||||
w->window_desc->pref_height = w->height;
|
||||
w->window_desc.pref_width = w->width;
|
||||
w->window_desc.pref_height = w->height;
|
||||
} else {
|
||||
int16_t def_width = std::max<int16_t>(std::min<int16_t>(w->window_desc->GetDefaultWidth(), _screen.width), w->nested_root->smallest_x);
|
||||
int16_t def_height = std::max<int16_t>(std::min<int16_t>(w->window_desc->GetDefaultHeight(), _screen.height - 50), w->nested_root->smallest_y);
|
||||
int16_t def_width = std::max<int16_t>(std::min<int16_t>(w->window_desc.GetDefaultWidth(), _screen.width), w->nested_root->smallest_x);
|
||||
int16_t def_height = std::max<int16_t>(std::min<int16_t>(w->window_desc.GetDefaultHeight(), _screen.height - 50), w->nested_root->smallest_y);
|
||||
|
||||
int dx = (w->resize.step_width == 0) ? 0 : def_width - w->width;
|
||||
int dy = (w->resize.step_height == 0) ? 0 : def_height - w->height;
|
||||
@@ -723,7 +722,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||
case WWT_STICKYBOX:
|
||||
w->flags ^= WF_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 & WF_STICKY) != 0;
|
||||
return;
|
||||
|
||||
default:
|
||||
@@ -761,9 +760,9 @@ static void DispatchRightClickEvent(Window *w, int x, int y)
|
||||
}
|
||||
|
||||
/* 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 & WDF_NO_CLOSE) == 0) {
|
||||
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 & WF_STICKY) == 0 && (w->window_desc.flags & WDF_NO_CLOSE) == 0) {
|
||||
/* 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) {
|
||||
@@ -894,7 +893,7 @@ void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom, D
|
||||
dp->top = top - w->top;
|
||||
dp->pitch = _screen.pitch;
|
||||
dp->dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
|
||||
dp->zoom = ZOOM_LVL_NORMAL;
|
||||
dp->zoom = ZOOM_LVL_MIN;
|
||||
w->OnPaint();
|
||||
if (flags & DOWF_SHOW_DEBUG) [[ unlikely ]] {
|
||||
extern void ViewportDrawDirtyBlocks();
|
||||
@@ -993,7 +992,7 @@ void Window::ReInit(int rx, int ry, bool reposition)
|
||||
if (reposition) {
|
||||
Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
|
||||
this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
|
||||
this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
|
||||
this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight());
|
||||
}
|
||||
|
||||
ResizeWindow(this, dx, dy, true, false);
|
||||
@@ -1378,9 +1377,9 @@ static void BringWindowToFront(Window *w, bool dirty)
|
||||
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->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 |= WF_CENTERED;
|
||||
this->owner = INVALID_OWNER;
|
||||
this->nested_focus = nullptr;
|
||||
this->window_number = window_number;
|
||||
@@ -1663,17 +1662,17 @@ Point GetToolbarAlignedWindowPosition(int window_width)
|
||||
*
|
||||
* @return Coordinate of the top-left corner of the new window.
|
||||
*/
|
||||
static Point LocalGetWindowPlacement(const WindowDesc *desc, int16_t sm_width, int16_t sm_height, int window_number)
|
||||
static Point LocalGetWindowPlacement(const WindowDesc &desc, int16_t sm_width, int16_t sm_height, int window_number)
|
||||
{
|
||||
Point pt;
|
||||
const Window *w;
|
||||
|
||||
int16_t default_width = std::max(desc->GetDefaultWidth(), sm_width);
|
||||
int16_t default_height = std::max(desc->GetDefaultHeight(), sm_height);
|
||||
int16_t default_width = std::max(desc.GetDefaultWidth(), sm_width);
|
||||
int16_t default_height = std::max(desc.GetDefaultHeight(), sm_height);
|
||||
|
||||
if (desc->parent_cls != WC_NONE && (w = FindWindowById(desc->parent_cls, window_number)) != nullptr) {
|
||||
if (desc.parent_cls != WC_NONE && (w = FindWindowById(desc.parent_cls, window_number)) != nullptr) {
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
if (desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) {
|
||||
if (desc.parent_cls == WC_BUILD_TOOLBAR || desc.parent_cls == WC_SCEN_LAND_GEN) {
|
||||
pt.x = w->left + (rtl ? w->width - default_width : 0);
|
||||
pt.y = w->top + w->height;
|
||||
return pt;
|
||||
@@ -1696,11 +1695,11 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16_t sm_width, i
|
||||
}
|
||||
}
|
||||
}
|
||||
pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? w->height : 10);
|
||||
pt.y = w->top + ((desc.parent_cls == WC_BUILD_TOOLBAR || desc.parent_cls == WC_SCEN_LAND_GEN) ? w->height : 10);
|
||||
return pt;
|
||||
}
|
||||
|
||||
switch (desc->default_pos) {
|
||||
switch (desc.default_pos) {
|
||||
case WDP_ALIGN_TOOLBAR: // Align to the toolbar
|
||||
return GetToolbarAlignedWindowPosition(default_width);
|
||||
|
||||
@@ -1738,7 +1737,7 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16_t sm_width, i
|
||||
*/
|
||||
void Window::CreateNestedTree()
|
||||
{
|
||||
this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_begin, this->window_desc->nwid_end, &this->shade_select);
|
||||
this->nested_root = MakeWindowNWidgetTree(this->window_desc.nwid_parts, &this->shade_select);
|
||||
this->nested_root->FillWidgetLookup(this->widget_lookup);
|
||||
}
|
||||
|
||||
@@ -1752,7 +1751,7 @@ void Window::FinishInitNested(WindowNumber window_number)
|
||||
this->ApplyDefaults();
|
||||
Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number);
|
||||
this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
|
||||
this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
|
||||
this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1769,7 +1768,7 @@ void Window::InitNested(WindowNumber window_number)
|
||||
* Empty constructor, initialization has been moved to #InitNested() called from the constructor of the derived class.
|
||||
* @param desc The description of the window.
|
||||
*/
|
||||
Window::Window(WindowDesc *desc) : window_desc(desc), scale(_gui_scale), mouse_capture_widget(-1)
|
||||
Window::Window(WindowDesc &desc) : window_desc(desc), scale(_gui_scale), mouse_capture_widget(-1)
|
||||
{
|
||||
this->z_position = _z_windows.insert(_z_windows.end(), this);
|
||||
}
|
||||
@@ -1942,9 +1941,6 @@ static void HandleMouseOver()
|
||||
}
|
||||
}
|
||||
|
||||
/** The minimum number of pixels of the title bar must be visible in both the X or Y direction */
|
||||
static const int MIN_VISIBLE_TITLE_BAR = 13;
|
||||
|
||||
/** Direction for moving the window. */
|
||||
enum PreventHideDirection {
|
||||
PHD_UP, ///< Above v is a safe position.
|
||||
@@ -1956,7 +1952,7 @@ enum PreventHideDirection {
|
||||
* If needed, move the window base coordinates to keep it visible.
|
||||
* @param nx Base horizontal coordinate of the rectangle.
|
||||
* @param ny Base vertical coordinate of the rectangle.
|
||||
* @param rect Rectangle that must stay visible for #MIN_VISIBLE_TITLE_BAR pixels (horizontally, vertically, or both)
|
||||
* @param rect Rectangle that must stay visible (horizontally, vertically, or both)
|
||||
* @param v Window lying in front of the rectangle.
|
||||
* @param px Previous horizontal base coordinate.
|
||||
* @param dir If no room horizontally, move the rectangle to the indicated position.
|
||||
@@ -1965,10 +1961,10 @@ static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, i
|
||||
{
|
||||
if (v == nullptr) return;
|
||||
|
||||
const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
|
||||
const int min_visible = rect.Height();
|
||||
|
||||
int v_bottom = v->top + v->height;
|
||||
int v_right = v->left + v->width;
|
||||
int v_bottom = v->top + v->height - 1;
|
||||
int v_right = v->left + v->width - 1;
|
||||
int safe_y = (dir == PHD_UP) ? (v->top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom); // Compute safe vertical position.
|
||||
|
||||
if (*ny + rect.top <= v->top - min_visible) return; // Above v is enough space
|
||||
@@ -2004,12 +2000,11 @@ static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, i
|
||||
static void EnsureVisibleCaption(Window *w, int nx, int ny)
|
||||
{
|
||||
/* Search for the title bar rectangle. */
|
||||
Rect caption_rect;
|
||||
const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION);
|
||||
if (caption != nullptr) {
|
||||
caption_rect = caption->GetCurrentRect();
|
||||
const Rect caption_rect = caption->GetCurrentRect();
|
||||
|
||||
const int min_visible = ScaleGUITrad(MIN_VISIBLE_TITLE_BAR);
|
||||
const int min_visible = caption_rect.Height();
|
||||
|
||||
/* Make sure the window doesn't leave the screen */
|
||||
nx = Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left);
|
||||
@@ -2339,8 +2334,11 @@ static void HandleScrollbarScrolling(Window *w)
|
||||
}
|
||||
|
||||
/* Find the item we want to move to. SetPosition will make sure it's inside bounds. */
|
||||
int pos = RoundDivSU((i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size);
|
||||
if (rtl) pos = sb->GetCount() - sb->GetCapacity() - pos;
|
||||
int range = sb->GetCount() - sb->GetCapacity();
|
||||
if (range <= 0) return;
|
||||
|
||||
int pos = RoundDivSU((i + _scrollbar_start_pos) * range, _scrollbar_size);
|
||||
if (rtl) pos = range - pos;
|
||||
if (sb->SetPosition(pos)) w->SetDirty();
|
||||
}
|
||||
|
||||
@@ -2383,7 +2381,7 @@ static EventState HandleActiveWidget()
|
||||
*/
|
||||
static EventState HandleViewportScroll()
|
||||
{
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && _cursor.wheel_moved;
|
||||
|
||||
if (!_scrolling_viewport) return ES_NOT_HANDLED;
|
||||
|
||||
@@ -2409,10 +2407,13 @@ static EventState HandleViewportScroll()
|
||||
Point delta;
|
||||
if (scrollwheel_scrolling) {
|
||||
/* We are using scrollwheels for scrolling */
|
||||
delta.x = _cursor.h_wheel;
|
||||
delta.y = _cursor.v_wheel;
|
||||
_cursor.v_wheel = 0;
|
||||
_cursor.h_wheel = 0;
|
||||
/* Use the integer part for movement */
|
||||
delta.x = static_cast<int>(_cursor.h_wheel);
|
||||
delta.y = static_cast<int>(_cursor.v_wheel);
|
||||
/* Keep the fractional part so that subtle movement is accumulated */
|
||||
float temp;
|
||||
_cursor.v_wheel = std::modf(_cursor.v_wheel, &temp);
|
||||
_cursor.h_wheel = std::modf(_cursor.h_wheel, &temp);
|
||||
} else {
|
||||
if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) {
|
||||
delta.x = -_cursor.delta.x;
|
||||
@@ -2428,6 +2429,7 @@ static EventState HandleViewportScroll()
|
||||
|
||||
_cursor.delta.x = 0;
|
||||
_cursor.delta.y = 0;
|
||||
_cursor.wheel_moved = false;
|
||||
return ES_HANDLED;
|
||||
}
|
||||
|
||||
@@ -2465,7 +2467,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 & WDF_MODAL)) {
|
||||
u->SetWhiteBorder();
|
||||
u->SetDirty();
|
||||
return false;
|
||||
@@ -2579,7 +2581,7 @@ void HandleToolbarHotkey(int hotkey)
|
||||
|
||||
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
||||
if (w != nullptr) {
|
||||
if (w->window_desc->hotkeys != nullptr) {
|
||||
if (w->window_desc.hotkeys != nullptr) {
|
||||
if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
|
||||
}
|
||||
}
|
||||
@@ -2623,10 +2625,10 @@ void HandleKeypress(uint keycode, char32_t key)
|
||||
/* Call the event, start with the uppermost window, but ignore the toolbar. */
|
||||
for (Window *w : Window::IterateFromFront()) {
|
||||
if (w->window_class == WC_MAIN_TOOLBAR) continue;
|
||||
if (w->window_desc->hotkeys != nullptr) {
|
||||
int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
|
||||
if (w->window_desc.hotkeys != nullptr) {
|
||||
int hotkey = w->window_desc.hotkeys->CheckMatch(keycode);
|
||||
if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) {
|
||||
citymania::CountHotkeyStats(w->window_desc->hotkeys, hotkey);
|
||||
citymania::CountHotkeyStats(w->window_desc.hotkeys, hotkey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2636,10 +2638,10 @@ void HandleKeypress(uint keycode, char32_t key)
|
||||
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
||||
/* When there is no toolbar w is null, check for that */
|
||||
if (w != nullptr) {
|
||||
if (w->window_desc->hotkeys != nullptr) {
|
||||
int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
|
||||
if (w->window_desc.hotkeys != nullptr) {
|
||||
int hotkey = w->window_desc.hotkeys->CheckMatch(keycode);
|
||||
if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) {
|
||||
citymania::CountHotkeyStats(w->window_desc->hotkeys, hotkey);
|
||||
citymania::CountHotkeyStats(w->window_desc.hotkeys, hotkey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2721,15 +2723,20 @@ static void HandleAutoscroll()
|
||||
y -= vp->top;
|
||||
|
||||
/* here allows scrolling in both x and y axis */
|
||||
/* 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->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom);
|
||||
} else if (15 - (vp->width - x) > 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
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->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom);
|
||||
} else if (15 - (vp->height - y) > 0) {
|
||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom);
|
||||
}
|
||||
}
|
||||
@@ -2740,17 +2747,18 @@ enum MouseClick {
|
||||
MC_RIGHT,
|
||||
MC_DOUBLE_LEFT,
|
||||
MC_HOVER,
|
||||
|
||||
MAX_OFFSET_DOUBLE_CLICK = 5, ///< How much the mouse is allowed to move to call it a double click
|
||||
MAX_OFFSET_HOVER = 5, ///< Maximum mouse movement before stopping a hover event.
|
||||
};
|
||||
|
||||
static constexpr int MAX_OFFSET_DOUBLE_CLICK = 5; ///< How much the mouse is allowed to move to call it a double click
|
||||
static constexpr int MAX_OFFSET_HOVER = 5; ///< Maximum mouse movement before stopping a hover event.
|
||||
|
||||
extern EventState VpHandlePlaceSizingDrag();
|
||||
|
||||
const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK(500); ///< Time between 2 left clicks before it becoming a double click.
|
||||
|
||||
static void ScrollMainViewport(int x, int y)
|
||||
{
|
||||
if (_game_mode != GM_MENU) {
|
||||
if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
|
||||
Window *w = GetMainWindow();
|
||||
w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
|
||||
w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
|
||||
@@ -2793,6 +2801,12 @@ static void HandleKeyScrolling()
|
||||
*/
|
||||
if (_dirkeys && !EditBoxInGlobalFocus()) {
|
||||
int factor = _shift_pressed ? 50 : 10;
|
||||
|
||||
if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
|
||||
/* Key scrolling stops following a vehicle. */
|
||||
GetMainWindow()->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||
}
|
||||
|
||||
ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
|
||||
}
|
||||
}
|
||||
@@ -2815,7 +2829,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||
if (citymania::HandleMouseMove()) return;
|
||||
HandleMouseOver();
|
||||
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
|
||||
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && _cursor.wheel_moved;
|
||||
if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
|
||||
|
||||
int x = _cursor.pos.x;
|
||||
@@ -2895,8 +2909,9 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||
}
|
||||
|
||||
/* We're not doing anything with 2D scrolling, so reset the value. */
|
||||
_cursor.h_wheel = 0;
|
||||
_cursor.v_wheel = 0;
|
||||
_cursor.h_wheel = 0.0f;
|
||||
_cursor.v_wheel = 0.0f;
|
||||
_cursor.wheel_moved = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3283,7 +3298,7 @@ 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 &&
|
||||
if ((w->window_desc.flags & WDF_NO_CLOSE) == 0 &&
|
||||
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
|
||||
|
||||
w->Close();
|
||||
@@ -3302,7 +3317,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 & WDF_NO_CLOSE) == 0) {
|
||||
w->Close();
|
||||
}
|
||||
}
|
||||
@@ -3327,7 +3342,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 & WDF_CONSTRUCTION) {
|
||||
w->Close();
|
||||
}
|
||||
}
|
||||
@@ -3370,6 +3385,7 @@ void ReInitAllWindows(bool zoom_changed)
|
||||
ReInitWindow(w, zoom_changed);
|
||||
}
|
||||
|
||||
if (_networking) NetworkUndrawChatMessage();
|
||||
NetworkReInitChatBoxSize();
|
||||
|
||||
/* Make sure essential parts of all windows are visible */
|
||||
@@ -3472,6 +3488,18 @@ void RelocateAllWindows(int neww, int newh)
|
||||
{
|
||||
CloseWindowByClass(WC_DROPDOWN_MENU);
|
||||
|
||||
/* Reposition toolbar then status bar before other all windows. */
|
||||
if (Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); wt != nullptr) {
|
||||
ResizeWindow(wt, std::min<uint>(neww, _toolbar_width) - wt->width, 0, false);
|
||||
wt->left = PositionMainToolbar(wt);
|
||||
}
|
||||
|
||||
if (Window *ws = FindWindowById(WC_STATUS_BAR, 0); ws != nullptr) {
|
||||
ResizeWindow(ws, std::min<uint>(neww, _toolbar_width) - ws->width, 0, false);
|
||||
ws->top = newh - ws->height;
|
||||
ws->left = PositionStatusbar(ws);
|
||||
}
|
||||
|
||||
for (Window *w : Window::Iterate()) {
|
||||
int left, top;
|
||||
/* XXX - this probably needs something more sane. For example specifying
|
||||
@@ -3479,28 +3507,20 @@ void RelocateAllWindows(int neww, int newh)
|
||||
switch (w->window_class) {
|
||||
case WC_MAIN_WINDOW:
|
||||
case WC_BOOTSTRAP:
|
||||
case WC_HIGHSCORE:
|
||||
case WC_ENDSCREEN:
|
||||
ResizeWindow(w, neww, newh);
|
||||
continue;
|
||||
|
||||
case WC_MAIN_TOOLBAR:
|
||||
ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
|
||||
|
||||
top = w->top;
|
||||
left = PositionMainToolbar(w); // changes toolbar orientation
|
||||
break;
|
||||
case WC_STATUS_BAR:
|
||||
continue;
|
||||
|
||||
case WC_NEWS_WINDOW:
|
||||
top = newh - w->height;
|
||||
left = PositionNewsMessage(w);
|
||||
break;
|
||||
|
||||
case WC_STATUS_BAR:
|
||||
ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
|
||||
|
||||
top = newh - w->height;
|
||||
left = PositionStatusbar(w);
|
||||
break;
|
||||
|
||||
case WC_SEND_NETWORK_MSG:
|
||||
ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
|
||||
|
||||
@@ -3547,7 +3567,7 @@ void PickerWindowBase::Close([[maybe_unused]] int data)
|
||||
* Sets safe-initial values.
|
||||
* @param t The type of positioning desired.
|
||||
*/
|
||||
WindowPopup::WindowPopup(WindowDesc *desc, WindowPopupType t): Window(desc)
|
||||
WindowPopup::WindowPopup(WindowDesc &desc, WindowPopupType t): Window(desc)
|
||||
{
|
||||
this->type = t;
|
||||
this->wpu_mod_x = -5;
|
||||
@@ -3571,7 +3591,7 @@ WindowPopup::WindowPopup(WindowDesc *desc, WindowPopupType t): Window(desc)
|
||||
switch (this->type) {
|
||||
case WPUT_CENTERED:
|
||||
x = _cursor.pos.x - sm_width / 2;
|
||||
y = _cursor.pos.y - this->window_desc->GetDefaultHeight() / 2;
|
||||
y = _cursor.pos.y - this->window_desc.GetDefaultHeight() / 2;
|
||||
break;
|
||||
case WPUT_WIDGET_RELATIVE:
|
||||
if (this->wpu_widget != std::numeric_limits<uint>::max()) {
|
||||
@@ -3590,6 +3610,6 @@ WindowPopup::WindowPopup(WindowDesc *desc, WindowPopupType t): Window(desc)
|
||||
|
||||
Point rv;
|
||||
rv.x = Clamp(x, 0, _screen.width - sm_width);
|
||||
rv.y = Clamp(y, GetMainViewTop(), GetMainViewBottom() - this->window_desc->GetDefaultHeight());
|
||||
rv.y = Clamp(y, GetMainViewTop(), GetMainViewBottom() - this->window_desc.GetDefaultHeight());
|
||||
return rv;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user