Mercurial > hg > openttd
changeset 5072:8f45a0d1985b draft
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
some special values (WDP_) instead of checking window-class. This also fixes FS#172
now that we can position windows arbitrarily and are not restricted to window-classes.
author | Darkvater <Darkvater@openttd.org> |
---|---|
date | Sat, 11 Nov 2006 10:12:00 +0000 |
parents | de738162cd68 |
children | ce18ef652042 |
files | airport_gui.c dock_gui.c rail_gui.c road_gui.c terraform_gui.c window.c window.h |
diffstat | 7 files changed, 43 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/airport_gui.c +++ b/airport_gui.c @@ -124,7 +124,7 @@ static const WindowDesc _air_toolbar_desc = { - 0, 22, 86, 36, + WDP_ALIGN_TBR, 22, 86, 36, WC_BUILD_TOOLBAR, 0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, _air_toolbar_widgets,
--- a/dock_gui.c +++ b/dock_gui.c @@ -205,7 +205,7 @@ }; static const WindowDesc _build_docks_toolbar_desc = { - 0, 22, 158, 36, + WDP_ALIGN_TBR, 22, 158, 36, WC_BUILD_TOOLBAR, 0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, _build_docks_toolb_widgets,
--- a/rail_gui.c +++ b/rail_gui.c @@ -544,7 +544,7 @@ }; static const WindowDesc _build_rail_desc = { - 0, 22, 372, 36, + WDP_ALIGN_TBR, 22, 372, 36, WC_BUILD_TOOLBAR, 0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, _build_rail_widgets,
--- a/road_gui.c +++ b/road_gui.c @@ -309,7 +309,7 @@ }; static const WindowDesc _build_road_desc = { - 0, 22, 240, 36, + WDP_ALIGN_TBR, 22, 240, 36, WC_BUILD_TOOLBAR, 0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, _build_road_widgets,
--- a/terraform_gui.c +++ b/terraform_gui.c @@ -265,7 +265,7 @@ }; static const WindowDesc _terraform_desc = { - 640-157, 22+36, 158, 36, + WDP_ALIGN_TBR, 22+36, 158, 36, WC_SCEN_LAND_GEN, 0, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, _terraform_widgets,
--- a/window.c +++ b/window.c @@ -694,30 +694,44 @@ pt.x = (_screen.width + 10 - desc->width) - 20; } pt.y = w->top + 10; - } else if (desc->cls == WC_BUILD_TOOLBAR) { // open Build Toolbars aligned - /* Override the position if a toolbar is opened according to the place of the maintoolbar - * The main toolbar (WC_MAIN_TOOLBAR) is 640px in width */ - switch (_patches.toolbar_pos) { - case 1: pt.x = ((_screen.width + 640) >> 1) - desc->width; break; - case 2: pt.x = _screen.width - desc->width; break; - default: pt.x = 640 - desc->width; + } 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->width; + } break; + case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */ + pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left; + break; + case WDP_AUTO: /* Find a good automatic position for the window */ + pt = GetAutoPlacePosition(desc->width, desc->height); + goto allocate_window; + case WDP_CENTER: /* Centre the window horizontally */ + pt.x = (_screen.width - desc->width) / 2; + break; + default: + pt.x = desc->left; + if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen } - pt.y = desc->top; - } else { - pt.x = desc->left; - pt.y = desc->top; - if (pt.x == WDP_AUTO) { - pt = GetAutoPlacePosition(desc->width, desc->height); - } else { - if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1; - if (pt.y == WDP_CENTER) { - pt.y = (_screen.height - desc->height) >> 1; - } else if (pt.y < 0) { - pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen - } + + switch (desc->top) { + case WDP_CENTER: /* Centre the window vertically */ + pt.y = (_screen.height - desc->height) / 2; + break; + /* WDP_AUTO sets the position at once and is controlled by desc->left. + * Both left and top must be set to WDP_AUTO */ + case WDP_AUTO: + NOT_REACHED(); + assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO); + /* fallthrough */ + default: + pt.y = desc->top; + if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen + break; } } +allocate_window: w = LocalAllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets, window_number); w->desc_flags = desc->flags; return w;
--- a/window.h +++ b/window.h @@ -275,8 +275,10 @@ /* can be used as x or y coordinates to cause a specific placement */ enum { - WDP_AUTO = -1, - WDP_CENTER = -2, + WDP_AUTO = -1, ///< Find a place automatically + WDP_CENTER = -2, ///< Center the window (left/right or top/bottom) + WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar + WDP_ALIGN_TBL = -4, ///< Align the left side of the window with the left side of the main toolbar }; typedef struct Textbuf {