summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-11-11 10:12:00 +0000
committerDarkvater <darkvater@openttd.org>2006-11-11 10:12:00 +0000
commit47e7ad7771fc361962fdc169caf7c1a3ed875a1d (patch)
tree6e47823efb2a0ac2553e9bcd1acebfe6c7e7744f
parent21db9ebb8e5692245e1e6d68a045649f6a37166a (diff)
downloadopenttd-47e7ad7771fc361962fdc169caf7c1a3ed875a1d.tar.xz
(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.
-rw-r--r--airport_gui.c2
-rw-r--r--dock_gui.c2
-rw-r--r--rail_gui.c2
-rw-r--r--road_gui.c2
-rw-r--r--terraform_gui.c2
-rw-r--r--window.c54
-rw-r--r--window.h6
7 files changed, 43 insertions, 27 deletions
diff --git a/airport_gui.c b/airport_gui.c
index 73bd77868..33e6ad96e 100644
--- a/airport_gui.c
+++ b/airport_gui.c
@@ -124,7 +124,7 @@ static const Widget _air_toolbar_widgets[] = {
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,
diff --git a/dock_gui.c b/dock_gui.c
index 97a1a9d4d..534af3ddf 100644
--- a/dock_gui.c
+++ b/dock_gui.c
@@ -205,7 +205,7 @@ static const Widget _build_docks_toolb_widgets[] = {
};
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,
diff --git a/rail_gui.c b/rail_gui.c
index 548ad88b4..722579002 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -544,7 +544,7 @@ static const Widget _build_rail_widgets[] = {
};
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,
diff --git a/road_gui.c b/road_gui.c
index 9f6e1fb24..47238b5b5 100644
--- a/road_gui.c
+++ b/road_gui.c
@@ -309,7 +309,7 @@ static const Widget _build_road_widgets[] = {
};
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,
diff --git a/terraform_gui.c b/terraform_gui.c
index 0d6c9ccd6..f07a2b3aa 100644
--- a/terraform_gui.c
+++ b/terraform_gui.c
@@ -265,7 +265,7 @@ static const Widget _terraform_widgets[] = {
};
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,
diff --git a/window.c b/window.c
index efd1ca53e..d6eaa16da 100644
--- a/window.c
+++ b/window.c
@@ -694,30 +694,44 @@ static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number
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;
- }
- 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->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
+ }
+
+ 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;
diff --git a/window.h b/window.h
index b87d81795..3252bcfaf 100644
--- a/window.h
+++ b/window.h
@@ -275,8 +275,10 @@ enum {
/* 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 {