Changeset - r8924:b5c89d2d57c4
[Not reviewed]
master
0 1 0
rubidium - 16 years ago 2008-04-13 19:06:30
rubidium@openttd.org
(svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
1 file changed with 12 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/window.cpp
Show inline comments
 
@@ -19,13 +19,14 @@
 
#include "map_func.h"
 
#include "vehicle_base.h"
 
#include "settings_type.h"
 

	
 
#include "table/sprites.h"
 

	
 
static Point _drag_delta; //< delta between mouse cursor and upper left corner of dragged window
 
static Point _drag_delta; ///< delta between mouse cursor and upper left corner of dragged window
 
static Window *_mouseover_last_w = NULL; ///< Window of the last MOUSEOVER event
 

	
 
static Window _windows[MAX_NUMBER_OF_WINDOWS];
 

	
 
/**
 
 * List of windows opened at the screen.
 
 * Uppermost window is at  _z_windows[_last_z_window - 1],
 
@@ -420,12 +421,15 @@ void DeleteWindow(Window *w)
 
	SetWindowDirty(w);
 
	free(w->widget);
 
	w->widget = NULL;
 
	w->widget_count = 0;
 
	w->parent = NULL;
 

	
 
	/* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
 
	if (_mouseover_last_w == w) _mouseover_last_w = NULL;
 

	
 
	/* Find the window in the z-array, and effectively remove it
 
	 * by moving all windows after it one to the left */
 
	Window **wz = FindWindowZPosition(w);
 
	if (wz == NULL) return;
 
	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
 
	_last_z_window--;
 
@@ -1194,26 +1198,27 @@ static bool HandlePopupMenu()
 

	
 
	return false;
 
}
 

	
 
static bool HandleMouseOver()
 
{
 
	Window *w;
 
	WindowEvent e;
 
	static Window *last_w = NULL;
 

	
 
	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
 
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
 

	
 
	/* We changed window, put a MOUSEOVER event to the last window */
 
	if (last_w != NULL && last_w != w) {
 
	if (_mouseover_last_w != NULL && _mouseover_last_w != w) {
 
		/* Reset mouse-over coordinates of previous window */
 
		e.event = WE_MOUSEOVER;
 
		e.we.mouseover.pt.x = -1;
 
		e.we.mouseover.pt.y = -1;
 
		if (last_w->wndproc) last_w->wndproc(last_w, &e);
 
		if (_mouseover_last_w->wndproc != NULL) _mouseover_last_w->wndproc(_mouseover_last_w, &e);
 
	}
 
	last_w = w;
 

	
 
	/* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
 
	_mouseover_last_w = w;
 

	
 
	if (w != NULL) {
 
		/* send an event in client coordinates. */
 
		e.event = WE_MOUSEOVER;
 
		e.we.mouseover.pt.x = _cursor.pos.x - w->left;
 
		e.we.mouseover.pt.y = _cursor.pos.y - w->top;
0 comments (0 inline, 0 general)