src/window.cpp
changeset 8217 ce7255c36b9e
parent 7960 af0f10d86051
child 8255 ba58769915ac
equal deleted inserted replaced
8216:12d1cff88d38 8217:ce7255c36b9e
   841 		pt.y = top;
   841 		pt.y = top;
   842 		return pt;
   842 		return pt;
   843 	}
   843 	}
   844 }
   844 }
   845 
   845 
       
   846 /**
       
   847  * Set the x and y coordinates of a new window.
       
   848  *
       
   849  * @param *desc         The pointer to the WindowDesc to be created
       
   850  * @param window_number the window number of the new window
       
   851  * @param data          arbitrary data that is send with the WE_CREATE message
       
   852  *
       
   853  * @return see Window pointer of the newly created window
       
   854  */
   846 static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data)
   855 static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data)
   847 {
   856 {
   848 	Point pt;
   857 	Point pt;
   849 	Window *w;
   858 	Window *w;
   850 
   859 
   851 	/* By default position a child window at an offset of 10/10 of its parent.
   860 	/* By default position a child window at an offset of 10/10 of its parent.
       
   861 	 * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports)
       
   862 	 * and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of
       
   863 	 * its parent. So it's exactly under the parent toolbar and no buttons will be covered.
   852 	 * However if it falls too extremely outside window positions, reposition
   864 	 * However if it falls too extremely outside window positions, reposition
   853 	 * it to an automatic place */
   865 	 * it to an automatic place */
   854 	if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ &&
   866 	if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ &&
   855 			(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
   867 			(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
   856 			w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
   868 			w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
   857 
   869 
   858 		pt.x = w->left + 10;
   870 		pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10);
   859 		if (pt.x > _screen.width + 10 - desc->default_width) {
   871 		if (pt.x > _screen.width + 10 - desc->default_width) {
   860 			pt.x = (_screen.width + 10 - desc->default_width) - 20;
   872 			pt.x = (_screen.width + 10 - desc->default_width) - 20;
   861 		}
   873 		}
   862 		pt.y = w->top + 10;
   874 		pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10);
   863 	} else {
   875 	} else {
   864 		switch (desc->left) {
   876 		switch (desc->left) {
   865 			case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
   877 			case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
   866 				w = FindWindowById(WC_MAIN_TOOLBAR, 0);
   878 				w = FindWindowById(WC_MAIN_TOOLBAR, 0);
   867 				pt.x = (w->left + w->width) - desc->default_width;
   879 				pt.x = (w->left + w->width) - desc->default_width;