summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2021-01-08 10:16:18 +0000
committerGitHub <noreply@github.com>2021-01-08 11:16:18 +0100
commit9b800a96ed32720ff60b74e498a0e0a6351004f9 (patch)
tree3f287d339e15c4902ee415556475fd9b2918d33c /src/window.cpp
parentc1fddb9a6ae5c3af6865461a7295788a341011a2 (diff)
downloadopenttd-9b800a96ed32720ff60b74e498a0e0a6351004f9.tar.xz
Codechange: Remove min/max functions in favour of STL variants (#8502)
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/window.cpp b/src/window.cpp
index feabbfdd2..f67cda90f 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -726,8 +726,8 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
w->window_desc->pref_width = w->width;
w->window_desc->pref_height = w->height;
} else {
- int16 def_width = max<int16>(min(w->window_desc->GetDefaultWidth(), _screen.width), w->nested_root->smallest_x);
- int16 def_height = max<int16>(min(w->window_desc->GetDefaultHeight(), _screen.height - 50), w->nested_root->smallest_y);
+ int16 def_width = std::max<int16>(std::min<int16>(w->window_desc->GetDefaultWidth(), _screen.width), w->nested_root->smallest_x);
+ int16 def_height = std::max<int16>(std::min<int16>(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;
@@ -971,7 +971,7 @@ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
left < w->left + w->width &&
top < w->top + w->height) {
/* Window w intersects with the rectangle => needs repaint */
- DrawOverlappedWindow(w, max(left, w->left), max(top, w->top), min(right, w->left + w->width), min(bottom, w->top + w->height));
+ DrawOverlappedWindow(w, std::max(left, w->left), std::max(top, w->top), std::min(right, w->left + w->width), std::min(bottom, w->top + w->height));
}
}
_cur_dpi = old_dpi;
@@ -1010,8 +1010,8 @@ void Window::ReInit(int rx, int ry)
this->resize.step_height = this->nested_root->resize_y;
/* Resize as close to the original size + requested resize as possible. */
- window_width = max(window_width + rx, this->width);
- window_height = max(window_height + ry, this->height);
+ window_width = std::max(window_width + rx, this->width);
+ window_height = std::max(window_height + ry, this->height);
int dx = (this->resize.step_width == 0) ? 0 : window_width - this->width;
int dy = (this->resize.step_height == 0) ? 0 : window_height - this->height;
/* dx and dy has to go by step.. calculate it.
@@ -1525,8 +1525,8 @@ void Window::InitializePositionSize(int x, int y, int sm_width, int sm_height)
*/
void Window::FindWindowPlacementAndResize(int def_width, int def_height)
{
- def_width = max(def_width, this->width); // Don't allow default size to be smaller than smallest size
- def_height = max(def_height, this->height);
+ def_width = std::max(def_width, this->width); // Don't allow default size to be smaller than smallest size
+ def_height = std::max(def_height, this->height);
/* Try to make windows smaller when our window is too small.
* w->(width|height) is normally the same as min_(width|height),
* but this way the GUIs can be made a little more dynamic;
@@ -1540,8 +1540,8 @@ void Window::FindWindowPlacementAndResize(int def_width, int def_height)
wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
if (wt != nullptr) free_height -= wt->height;
- int enlarge_x = max(min(def_width - this->width, _screen.width - this->width), 0);
- int enlarge_y = max(min(def_height - this->height, free_height - this->height), 0);
+ int enlarge_x = std::max(std::min(def_width - this->width, _screen.width - this->width), 0);
+ int enlarge_y = std::max(std::min(def_height - this->height, free_height - this->height), 0);
/* X and Y has to go by step.. calculate it.
* The cast to int is necessary else x/y are implicitly casted to
@@ -1562,8 +1562,8 @@ void Window::FindWindowPlacementAndResize(int def_width, int def_height)
if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
- ny = max(ny, (wt == nullptr || this == wt || this->top == 0) ? 0 : wt->height);
- nx = max(nx, 0);
+ ny = std::max(ny, (wt == nullptr || this == wt || this->top == 0) ? 0 : wt->height);
+ nx = std::max(nx, 0);
if (this->viewport != nullptr) {
this->viewport->left += nx - this->left;
@@ -1711,7 +1711,7 @@ static Point GetAutoPlacePosition(int width, int height)
*/
int left = rtl ? _screen.width - width : 0, top = toolbar_y;
int offset_x = rtl ? -(int)NWidgetLeaf::closebox_dimension.width : (int)NWidgetLeaf::closebox_dimension.width;
- int offset_y = max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
+ int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
restart:
FOR_ALL_WINDOWS_FROM_BACK(w) {
@@ -1763,8 +1763,8 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
Point pt;
const Window *w;
- int16 default_width = max(desc->GetDefaultWidth(), sm_width);
- int16 default_height = max(desc->GetDefaultHeight(), sm_height);
+ int16 default_width = std::max(desc->GetDefaultWidth(), sm_width);
+ int16 default_height = std::max(desc->GetDefaultHeight(), sm_height);
if (desc->parent_cls != WC_NONE && (w = FindWindowById(desc->parent_cls, window_number)) != nullptr) {
bool rtl = _current_text_dir == TD_RTL;
@@ -1777,16 +1777,16 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
* - Y position: closebox of parent + closebox of child + statusbar
* - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl)
*/
- int indent_y = max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
+ int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM);
if (w->top + 3 * indent_y < _screen.height) {
pt.y = w->top + indent_y;
int indent_close = NWidgetLeaf::closebox_dimension.width;
int indent_resize = NWidgetLeaf::resizebox_dimension.width;
if (_current_text_dir == TD_RTL) {
- pt.x = max(w->left + w->width - default_width - indent_close, 0);
+ pt.x = std::max(w->left + w->width - default_width - indent_close, 0);
if (pt.x + default_width >= indent_close && pt.x + indent_resize <= _screen.width) return pt;
} else {
- pt.x = min(w->left + indent_close, _screen.width - default_width);
+ pt.x = std::min(w->left + indent_close, _screen.width - default_width);
if (pt.x + default_width >= indent_resize && pt.x + indent_close <= _screen.width) return pt;
}
}
@@ -2151,14 +2151,14 @@ void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
* the resolution clamp it in such a manner that it stays within the bounds. */
int new_right = w->left + w->width + delta_x;
int new_bottom = w->top + w->height + delta_y;
- if (new_right >= (int)_cur_resolution.width) delta_x -= Ceil(new_right - _cur_resolution.width, max(1U, w->nested_root->resize_x));
- if (new_bottom >= (int)_cur_resolution.height) delta_y -= Ceil(new_bottom - _cur_resolution.height, max(1U, w->nested_root->resize_y));
+ if (new_right >= (int)_cur_resolution.width) delta_x -= Ceil(new_right - _cur_resolution.width, std::max(1U, w->nested_root->resize_x));
+ if (new_bottom >= (int)_cur_resolution.height) delta_y -= Ceil(new_bottom - _cur_resolution.height, std::max(1U, w->nested_root->resize_y));
}
w->SetDirty();
- uint new_xinc = max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
- uint new_yinc = max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
+ uint new_xinc = std::max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
+ uint new_yinc = std::max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
@@ -2434,8 +2434,8 @@ static void HandleScrollbarScrolling(Window *w)
}
/* Find the item we want to move to and make sure it's inside bounds. */
- int pos = min(RoundDivSU(max(0, i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size), max(0, sb->GetCount() - sb->GetCapacity()));
- if (rtl) pos = max(0, sb->GetCount() - sb->GetCapacity() - pos);
+ int pos = std::min(RoundDivSU(std::max(0, i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size), std::max(0, sb->GetCount() - sb->GetCapacity()));
+ if (rtl) pos = std::max(0, sb->GetCount() - sb->GetCapacity() - pos);
if (pos != sb->GetPosition()) {
sb->SetPosition(pos);
w->SetDirty();
@@ -3581,7 +3581,7 @@ void RelocateAllWindows(int neww, int newh)
continue;
case WC_MAIN_TOOLBAR:
- ResizeWindow(w, min(neww, _toolbar_width) - w->width, 0, false);
+ ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
top = w->top;
left = PositionMainToolbar(w); // changes toolbar orientation
@@ -3593,14 +3593,14 @@ void RelocateAllWindows(int neww, int newh)
break;
case WC_STATUS_BAR:
- ResizeWindow(w, min(neww, _toolbar_width) - w->width, 0, false);
+ 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, min(neww, _toolbar_width) - w->width, 0, false);
+ ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
top = newh - w->height - FindWindowById(WC_STATUS_BAR, 0)->height;
left = PositionNetworkChatWindow(w);