mirror of https://github.com/OpenTTD/OpenTTD
(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.release/0.5
parent
21db9ebb8e
commit
47e7ad7771
|
@ -124,7 +124,7 @@ static const Widget _air_toolbar_widgets[] = {
|
||||||
|
|
||||||
|
|
||||||
static const WindowDesc _air_toolbar_desc = {
|
static const WindowDesc _air_toolbar_desc = {
|
||||||
0, 22, 86, 36,
|
WDP_ALIGN_TBR, 22, 86, 36,
|
||||||
WC_BUILD_TOOLBAR, 0,
|
WC_BUILD_TOOLBAR, 0,
|
||||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
||||||
_air_toolbar_widgets,
|
_air_toolbar_widgets,
|
||||||
|
|
|
@ -205,7 +205,7 @@ static const Widget _build_docks_toolb_widgets[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const WindowDesc _build_docks_toolbar_desc = {
|
static const WindowDesc _build_docks_toolbar_desc = {
|
||||||
0, 22, 158, 36,
|
WDP_ALIGN_TBR, 22, 158, 36,
|
||||||
WC_BUILD_TOOLBAR, 0,
|
WC_BUILD_TOOLBAR, 0,
|
||||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
||||||
_build_docks_toolb_widgets,
|
_build_docks_toolb_widgets,
|
||||||
|
|
|
@ -544,7 +544,7 @@ static const Widget _build_rail_widgets[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const WindowDesc _build_rail_desc = {
|
static const WindowDesc _build_rail_desc = {
|
||||||
0, 22, 372, 36,
|
WDP_ALIGN_TBR, 22, 372, 36,
|
||||||
WC_BUILD_TOOLBAR, 0,
|
WC_BUILD_TOOLBAR, 0,
|
||||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
||||||
_build_rail_widgets,
|
_build_rail_widgets,
|
||||||
|
|
|
@ -309,7 +309,7 @@ static const Widget _build_road_widgets[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const WindowDesc _build_road_desc = {
|
static const WindowDesc _build_road_desc = {
|
||||||
0, 22, 240, 36,
|
WDP_ALIGN_TBR, 22, 240, 36,
|
||||||
WC_BUILD_TOOLBAR, 0,
|
WC_BUILD_TOOLBAR, 0,
|
||||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
||||||
_build_road_widgets,
|
_build_road_widgets,
|
||||||
|
|
|
@ -265,7 +265,7 @@ static const Widget _terraform_widgets[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const WindowDesc _terraform_desc = {
|
static const WindowDesc _terraform_desc = {
|
||||||
640-157, 22+36, 158, 36,
|
WDP_ALIGN_TBR, 22+36, 158, 36,
|
||||||
WC_SCEN_LAND_GEN, 0,
|
WC_SCEN_LAND_GEN, 0,
|
||||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
||||||
_terraform_widgets,
|
_terraform_widgets,
|
||||||
|
|
50
window.c
50
window.c
|
@ -694,30 +694,44 @@ static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number
|
||||||
pt.x = (_screen.width + 10 - desc->width) - 20;
|
pt.x = (_screen.width + 10 - desc->width) - 20;
|
||||||
}
|
}
|
||||||
pt.y = w->top + 10;
|
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;
|
|
||||||
}
|
|
||||||
pt.y = desc->top;
|
|
||||||
} else {
|
} else {
|
||||||
pt.x = desc->left;
|
switch (desc->left) {
|
||||||
pt.y = desc->top;
|
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
|
||||||
if (pt.x == WDP_AUTO) {
|
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);
|
pt = GetAutoPlacePosition(desc->width, desc->height);
|
||||||
} else {
|
goto allocate_window;
|
||||||
if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1;
|
case WDP_CENTER: /* Centre the window horizontally */
|
||||||
if (pt.y == WDP_CENTER) {
|
pt.x = (_screen.width - desc->width) / 2;
|
||||||
pt.y = (_screen.height - desc->height) >> 1;
|
break;
|
||||||
} else if (pt.y < 0) {
|
default:
|
||||||
pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen
|
pt.x = desc->left;
|
||||||
|
if (pt.x < 0) pt.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->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 = LocalAllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets, window_number);
|
||||||
w->desc_flags = desc->flags;
|
w->desc_flags = desc->flags;
|
||||||
return w;
|
return w;
|
||||||
|
|
6
window.h
6
window.h
|
@ -275,8 +275,10 @@ enum {
|
||||||
|
|
||||||
/* can be used as x or y coordinates to cause a specific placement */
|
/* can be used as x or y coordinates to cause a specific placement */
|
||||||
enum {
|
enum {
|
||||||
WDP_AUTO = -1,
|
WDP_AUTO = -1, ///< Find a place automatically
|
||||||
WDP_CENTER = -2,
|
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 {
|
typedef struct Textbuf {
|
||||||
|
|
Loading…
Reference in New Issue