File diff r13425:301cfe36afd4 → r13426:509a5e9dc661
src/misc_gui.cpp
Show inline comments
 
@@ -584,27 +584,27 @@ public:
 
	virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
 
	{
 
		/* Position (0, 0) given, center the window. */
 
		if (this->position.x == 0 && this->position.y == 0) {
 
			Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
 
			return pt;
 
		}
 

	
 
		/* Find the screen part between the main toolbar at the top, and the statusbar at the bottom.
 
		 * Add a fixed distance 20 to make it less cluttered.
 
		 */
 
		const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
		int scr_top = w->top + w->height + 20;
 
		int scr_top = ((w != NULL) ? w->top + w->height : 0) + 20;
 
		w = FindWindowById(WC_STATUS_BAR, 0);
 
		int scr_bot = w->top - 20;
 
		int scr_bot = ((w != NULL) ? w->top : _screen.height) - 20;
 

	
 
		Point pt = RemapCoords2(this->position.x, this->position.y);
 
		const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
 
		if (this->detailed_msg != STR_ERROR_OWNED_BY || GetDParamX(this->decode_params, 2) >= MAX_COMPANIES) {
 
			/* move x pos to opposite corner */
 
			pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left;
 
			pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - sm_width - 20 : 20; // Stay 20 pixels away from the edge of the screen.
 

	
 
			/* move y pos to opposite corner */
 
			pt.y = UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top;
 
			pt.y = (pt.y < (_screen.height >> 1)) ? scr_bot - sm_height : scr_top;
 
		} else {
 
@@ -801,27 +801,27 @@ struct TooltipsWindow : public Window
 

	
 
		this->InitNested(&_tool_tips_desc);
 

	
 
		this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip
 
	}
 

	
 
	virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
 
	{
 
		/* Find the screen part between the main toolbar at the top, and the statusbar at the bottom.
 
		 * Add a fixed distance 2 so the tooltip floats free from both bars.
 
		 */
 
		const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
		int scr_top = w->top + w->height + 2;
 
		int scr_top = ((w != NULL) ? w->top + w->height : 0) + 2;
 
		w = FindWindowById(WC_STATUS_BAR, 0);
 
		int scr_bot = w->top - 2;
 
		int scr_bot = ((w != NULL) ? w->top : _screen.height) - 2;
 

	
 
		Point pt;
 

	
 
		/* Correctly position the tooltip position, watch out for window and cursor size
 
		 * Clamp value to below main toolbar and above statusbar. If tooltip would
 
		 * go below window, flip it so it is shown above the cursor */
 
		pt.y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, scr_top, scr_bot);
 
		if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.offs.y - 5, scr_bot) - sm_height;
 
		pt.x = Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
 

	
 
		return pt;
 
	}