summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-05-26 19:30:07 +0000
committerfrosch <frosch@openttd.org>2013-05-26 19:30:07 +0000
commit4e4e635916d7852c0da9a53edd2d510080922ed5 (patch)
tree3131851c69f879767d377c68d8e7c8a3f9910a9a /src/window.cpp
parent559b7ef35eb4896e4f2e35d2dc8afb3d86519c3e (diff)
downloadopenttd-4e4e635916d7852c0da9a53edd2d510080922ed5.tar.xz
(svn r25294) -Feature: Add another button to window title bars to resize the window to its default size.
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 86702842d..74628d687 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -444,6 +444,13 @@ void Window::RaiseButtons(bool autoraise)
this->SetWidgetDirty(i);
}
}
+
+ /* Special widgets without widget index */
+ NWidgetCore *wid = this->nested_root != NULL ? (NWidgetCore*)this->nested_root->GetWidgetOfType(WWT_DEFSIZEBOX) : NULL;
+ if (wid != NULL) {
+ wid->SetLowered(false);
+ wid->SetDirty(this);
+ }
}
/**
@@ -553,6 +560,24 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
nw->SetDirty(w);
return;
+ case WWT_DEFSIZEBOX: {
+ int16 def_width = max<int16>(min(w->window_desc->default_width, _screen.width), w->nested_root->smallest_x);
+ int16 def_height = max<int16>(min(w->window_desc->default_height, _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;
+ /* dx and dy has to go by step.. calculate it.
+ * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
+ if (w->resize.step_width > 1) dx -= dx % (int)w->resize.step_width;
+ if (w->resize.step_height > 1) dy -= dy % (int)w->resize.step_height;
+ ResizeWindow(w, dx, dy, false);
+
+ nw->SetLowered(true);
+ nw->SetDirty(w);
+ w->SetTimeout();
+ break;
+ }
+
case WWT_DEBUGBOX:
w->ShowNewGRFInspectWindow();
break;