summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-05-26 19:30:31 +0000
committerfrosch <frosch@openttd.org>2013-05-26 19:30:31 +0000
commit05c472f08afdfc6d56fa45f941c17657358d0733 (patch)
tree4ea9f6b3f66eb9d9e495c48c55a642b4934ec260 /src
parent4e4e635916d7852c0da9a53edd2d510080922ed5 (diff)
downloadopenttd-05c472f08afdfc6d56fa45f941c17657358d0733.tar.xz
(svn r25295) -Feature: Allow saving window sizes as default sizes.
Diffstat (limited to 'src')
-rw-r--r--src/table/window_settings.ini14
-rw-r--r--src/window.cpp35
-rw-r--r--src/window_gui.h5
3 files changed, 40 insertions, 14 deletions
diff --git a/src/table/window_settings.ini b/src/table/window_settings.ini
index e57c1c4b0..ad77423d9 100644
--- a/src/table/window_settings.ini
+++ b/src/table/window_settings.ini
@@ -36,6 +36,20 @@ cat = SC_ADVANCED
var = pref_sticky
def = false
+[SDT_VAR]
+var = pref_width
+type = SLE_INT16
+def = 0
+min = 0
+max = 32000
+
+[SDT_VAR]
+var = pref_height
+type = SLE_INT16
+def = 0
+min = 0
+max = 32000
+
[SDT_END]
};
diff --git a/src/window.cpp b/src/window.cpp
index 74628d687..0e67c0bf8 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -96,7 +96,9 @@ WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_wi
flags(flags),
nwid_parts(nwid_parts),
nwid_length(nwid_length),
- pref_sticky(false)
+ pref_sticky(false),
+ pref_width(0),
+ pref_height(0)
{
if (_window_descs == NULL) _window_descs = new SmallVector<WindowDesc*, 16>();
*_window_descs->Append() = this;
@@ -561,16 +563,21 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
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);
+ if (_ctrl_pressed) {
+ 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);
+
+ 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);
@@ -1544,8 +1551,8 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
Point pt;
const Window *w;
- int16 default_width = max(desc->default_width, sm_width);
- int16 default_height = max(desc->default_height, sm_height);
+ int16 default_width = max(desc->GetDefaultWidth(), sm_width);
+ int16 default_height = max(desc->GetDefaultHeight(), sm_height);
if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ &&
(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
@@ -1617,7 +1624,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->default_width, this->window_desc->default_height);
+ this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight());
}
/**
diff --git a/src/window_gui.h b/src/window_gui.h
index 4055f7caf..6288aadc1 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -189,6 +189,11 @@ struct WindowDesc : ZeroedMemoryAllocator {
int16 nwid_length; ///< Length of the #nwid_parts array.
bool pref_sticky; ///< Preferred stickyness.
+ int16 pref_width; ///< User-preferred width of the window. Zero if unset.
+ int16 pref_height; ///< User-preferred height of the window. Zero if unset.
+
+ int16 GetDefaultWidth() const { return this->pref_width != 0 ? this->pref_width : this->default_width; }
+ int16 GetDefaultHeight() const { return this->pref_height != 0 ? this->pref_height : this->default_height; }
static void LoadFromConfig();
static void SaveToConfig();