=== modified file 'src/window.cpp' --- src/window.cpp 2008-05-09 17:01:51 +0000 +++ src/window.cpp 2008-05-10 12:43:37 +0000 @@ -818,7 +818,7 @@ } -static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos) +static bool IsGoodAutoPlace1(int left, int top, int width, int height, PointDimension &pos) { Window* const *wz; @@ -842,10 +842,12 @@ pos.x = left; pos.y = top; + pos.width = width; + pos.height = height; return true; } -static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos) +static bool IsGoodAutoPlace2(int left, int top, int width, int height, PointDimension &pos) { Window* const *wz; @@ -867,38 +869,40 @@ pos.x = left; pos.y = top; + pos.width = width; + pos.height = height; return true; } -static Point GetAutoPlacePosition(int width, int height) +static PointDimension GetAutoPlacePosition(int width, int height) { Window* const *wz; - Point pt; + PointDimension pd; - if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt; + if (IsGoodAutoPlace1(0, 24, width, height, pd)) return pd; FOR_ALL_WINDOWS(wz) { const Window *w = *wz; if (w->window_class == WC_MAIN_WINDOW) continue; - if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left - width - 2, w->top, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left, w->top - height - 2, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left - width - 2, w->top + w->height - height, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt; - if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2, width, height, pt)) return pt; + if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left - width - 2, w->top, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left, w->top - height - 2, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left - width - 2, w->top + w->height - height, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pd)) return pd; + if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2, width, height, pd)) return pd; } FOR_ALL_WINDOWS(wz) { const Window *w = *wz; if (w->window_class == WC_MAIN_WINDOW) continue; - if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt; - if (IsGoodAutoPlace2(w->left - width - 2, w->top, width, height, pt)) return pt; - if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt; - if (IsGoodAutoPlace2(w->left, w->top - height - 2, width, height, pt)) return pt; + if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pd)) return pd; + if (IsGoodAutoPlace2(w->left - width - 2, w->top, width, height, pd)) return pd; + if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pd)) return pd; + if (IsGoodAutoPlace2(w->left, w->top - height - 2, width, height, pd)) return pd; } { @@ -915,14 +919,16 @@ } } - pt.x = left; - pt.y = top; - return pt; + pd.x = left; + pd.y = top; + pd.width = width; + pd.height = height; + return pd; } } /** - * Compute the position of the top-left corner of a new window that is opened. + * Compute the position and size of a new window that is being opened. * * By default position a child window at an offset of 10/10 of its parent. * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports) @@ -934,48 +940,48 @@ * @param *desc The pointer to the WindowDesc to be created * @param window_number the window number of the new window * - * @return Coordinate of the top-left corner of the new window + * @return Position and size of the new window */ -static Point LocalGetWindowPlacement(const WindowDesc *desc, int window_number) +static PointDimension LocalGetWindowPlacement(const WindowDesc *desc, int window_number) { - Point pt; + PointDimension pd; Window *w; if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ && (w = FindWindowById(desc->parent_cls, window_number)) != NULL && w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) { - pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10); - if (pt.x > _screen.width + 10 - desc->default_width) { - pt.x = (_screen.width + 10 - desc->default_width) - 20; + pd.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10); + if (pd.x > _screen.width + 10 - desc->default_width) { + pd.x = (_screen.width + 10 - desc->default_width) - 20; } - pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10); + pd.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10); } else { switch (desc->left) { case WDP_ALIGN_TBR: // Align the right side with the top toolbar w = FindWindowById(WC_MAIN_TOOLBAR, 0); - pt.x = (w->left + w->width) - desc->default_width; + pd.x = (w->left + w->width) - desc->default_width; break; case WDP_ALIGN_TBL: // Align the left side with the top toolbar - pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left; + pd.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left; break; case WDP_AUTO: // Find a good automatic position for the window return GetAutoPlacePosition(desc->default_width, desc->default_height); case WDP_CENTER: // Centre the window horizontally - pt.x = (_screen.width - desc->default_width) / 2; + pd.x = (_screen.width - desc->default_width) / 2; break; default: - pt.x = desc->left; - if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen + pd.x = desc->left; + if (pd.x < 0) pd.x += _screen.width; // negative is from right of the screen } switch (desc->top) { case WDP_CENTER: // Centre the window vertically - pt.y = (_screen.height - desc->default_height) / 2; + pd.y = (_screen.height - desc->default_height) / 2; break; /* WDP_AUTO sets the position at once and is controlled by desc->left. @@ -986,13 +992,15 @@ /* fallthrough */ default: - pt.y = desc->top; - if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen + pd.y = desc->top; + if (pd.y < 0) pd.y += _screen.height; // negative is from bottom of the screen break; } } - return pt; + pd.width = desc->default_width; + pd.height = desc->default_height; + return pd; } /** @@ -1006,8 +1014,8 @@ */ Window::Window(const WindowDesc *desc, void *data, WindowNumber window_number) { - Point pt = LocalGetWindowPlacement(desc, window_number); - this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data); + PointDimension pd = LocalGetWindowPlacement(desc, window_number); + this->Initialize(pd.x, pd.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data); this->desc_flags = desc->flags; }