Changeset - r9238:751acbca357b
[Not reviewed]
master
0 6 0
rubidium - 16 years ago 2008-05-15 14:41:56
rubidium@openttd.org
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
6 files changed with 29 insertions and 82 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -102,9 +102,7 @@ static void BuildAirToolbWndProc(Window 
 
		case WE_ABORT_PLACE_OBJ:
 
			w->RaiseButtons();
 

	
 
			w = FindWindowById(WC_BUILD_STATION, 0);
 
			if (w != 0)
 
				WP(w, def_d).close = true;
 
			delete FindWindowById(WC_BUILD_STATION, 0);
 
			break;
 

	
 
		case WE_DESTROY:
 
@@ -171,8 +169,6 @@ static void BuildAirportPickerWndProc(Wi
 
			uint32 avail_airports;
 
			const AirportFTAClass *airport;
 

	
 
			if (WP(w, def_d).close) return;
 

	
 
			avail_airports = GetValidAirports();
 

	
 
			w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
 
@@ -230,17 +226,12 @@ static void BuildAirportPickerWndProc(Wi
 
			}
 
		} break;
 

	
 
		case WE_TICK: {
 
			if (WP(w, def_d).close) {
 
				delete w;
 
				return;
 
			}
 

	
 
		case WE_TICK:
 
			CheckRedrawStationCoverage(w);
 
		} break;
 
			break;
 

	
 
		case WE_DESTROY:
 
			if (!WP(w, def_d).close) ResetObjectToPlace();
 
			ResetObjectToPlace();
 
			break;
 
	}
 
}
src/dock_gui.cpp
Show inline comments
 
@@ -175,11 +175,8 @@ static void BuildDocksToolbWndProc(Windo
 
	case WE_ABORT_PLACE_OBJ:
 
		w->RaiseButtons();
 

	
 
		w = FindWindowById(WC_BUILD_STATION, 0);
 
		if (w != NULL) WP(w, def_d).close = true;
 

	
 
		w = FindWindowById(WC_BUILD_DEPOT, 0);
 
		if (w != NULL) WP(w, def_d).close = true;
 
		delete FindWindowById(WC_BUILD_STATION, 0);
 
		delete FindWindowById(WC_BUILD_DEPOT, 0);
 
		break;
 

	
 
	case WE_PLACE_PRESIZE: {
 
@@ -241,7 +238,6 @@ static void BuildDockStationWndProc(Wind
 
	case WE_PAINT: {
 
		int rad = (_patches.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
 

	
 
		if (WP(w, def_d).close) return;
 
		DrawWindowWidgets(w);
 

	
 
		if (_station_show_coverage) {
 
@@ -275,16 +271,11 @@ static void BuildDockStationWndProc(Wind
 
		break;
 

	
 
	case WE_TICK:
 
		if (WP(w, def_d).close) {
 
			delete w;
 
			return;
 
		}
 

	
 
		CheckRedrawStationCoverage(w);
 
		break;
 

	
 
	case WE_DESTROY:
 
		if (!WP(w, def_d).close) ResetObjectToPlace();
 
		ResetObjectToPlace();
 
		break;
 
	}
 
}
 
@@ -349,12 +340,8 @@ static void BuildDocksDepotWndProc(Windo
 
		}
 
	} break;
 

	
 
	case WE_TICK:
 
		if (WP(w, def_d).close) delete w;
 
		break;
 

	
 
	case WE_DESTROY:
 
		if (!WP(w, def_d).close) ResetObjectToPlace();
 
		ResetObjectToPlace();
 
		break;
 
	}
 
}
src/rail_gui.cpp
Show inline comments
 
@@ -653,12 +653,9 @@ static void BuildRailToolbWndProc(Window
 
		w->DisableWidget(RTW_REMOVE);
 
		w->InvalidateWidget(RTW_REMOVE);
 

	
 
		w = FindWindowById(WC_BUILD_SIGNAL, 0);
 
		if (w != NULL) WP(w, def_d).close = true;
 
		w = FindWindowById(WC_BUILD_STATION, 0);
 
		if (w != NULL) WP(w, def_d).close = true;
 
		w = FindWindowById(WC_BUILD_DEPOT, 0);
 
		if (w != NULL) WP(w, def_d).close = true;
 
		delete FindWindowById(WC_BUILD_SIGNAL, 0);
 
		delete FindWindowById(WC_BUILD_STATION, 0);
 
		delete FindWindowById(WC_BUILD_DEPOT, 0);
 
		break;
 

	
 
	case WE_PLACE_PRESIZE: {
 
@@ -875,8 +872,6 @@ static void StationBuildWndProc(Window *
 
		DrawPixelInfo tmp_dpi, *old_dpi;
 
		const StationSpec *statspec = newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
 

	
 
		if (WP(w, def_d).close) return;
 

	
 
		if (_railstation.dragdrop) {
 
			SetTileSelectSize(1, 1);
 
		} else {
 
@@ -1123,15 +1118,11 @@ static void StationBuildWndProc(Window *
 
		break;
 

	
 
	case WE_TICK:
 
		if (WP(w, def_d).close) {
 
			delete w;
 
			return;
 
		}
 
		CheckRedrawStationCoverage(w);
 
		break;
 

	
 
	case WE_DESTROY:
 
		if (!WP(w, def_d).close) ResetObjectToPlace();
 
		ResetObjectToPlace();
 
		break;
 
	}
 
}
 
@@ -1345,12 +1336,8 @@ static void SignalBuildWndProc(Window *w
 
			w->SetDirty();
 
			break;
 

	
 
		case WE_TICK:
 
			if (WP(w, def_d).close) delete w;
 
			return;
 

	
 
		case WE_DESTROY:
 
			if (!WP(w, def_d).close) ResetObjectToPlace();
 
			ResetObjectToPlace();
 
			break;
 
		}
 
}
 
@@ -1436,12 +1423,8 @@ static void BuildTrainDepotWndProc(Windo
 
		}
 
		break;
 

	
 
	case WE_TICK:
 
		if (WP(w, def_d).close) delete w;
 
		return;
 

	
 
	case WE_DESTROY:
 
		if (!WP(w, def_d).close) ResetObjectToPlace();
 
		ResetObjectToPlace();
 
		break;
 
	}
 
}
 
@@ -1535,12 +1518,8 @@ static void BuildWaypointWndProc(Window 
 
		break;
 
	}
 

	
 
	case WE_TICK:
 
		if (WP(w, def_d).close) delete w;
 
		break;
 

	
 
	case WE_DESTROY:
 
		if (!WP(w, def_d).close) ResetObjectToPlace();
 
		ResetObjectToPlace();
 
		break;
 
	}
 
}
src/road_gui.cpp
Show inline comments
 
@@ -511,12 +511,9 @@ static void BuildRoadToolbWndProc(Window
 
			w->InvalidateWidget(RTW_REMOVE);
 
			w->InvalidateWidget(RTW_ONE_WAY);
 

	
 
			w = FindWindowById(WC_BUS_STATION, 0);
 
			if (w != NULL) WP(w, def_d).close = true;
 
			w = FindWindowById(WC_TRUCK_STATION, 0);
 
			if (w != NULL) WP(w, def_d).close = true;
 
			w = FindWindowById(WC_BUILD_DEPOT, 0);
 
			if (w != NULL) WP(w, def_d).close = true;
 
			delete FindWindowById(WC_BUS_STATION, 0);
 
			delete FindWindowById(WC_TRUCK_STATION, 0);
 
			delete FindWindowById(WC_BUILD_DEPOT, 0);
 
			break;
 

	
 
		case WE_PLACE_DRAG:
 
@@ -762,12 +759,8 @@ static void BuildRoadDepotWndProc(Window
 
			}
 
			break;
 

	
 
		case WE_TICK:
 
			if (WP(w, def_d).close) delete w;
 
			break;
 

	
 
		case WE_DESTROY:
 
			if (!WP(w, def_d).close) ResetObjectToPlace();
 
			ResetObjectToPlace();
 
			break;
 

	
 
		default:
 
@@ -856,8 +849,6 @@ static void RoadStationPickerWndProc(Win
 
			break;
 

	
 
		case WE_PAINT: {
 
			if (WP(w, def_d).close) return;
 

	
 
			DrawWindowWidgets(w);
 

	
 
			if (_station_show_coverage) {
 
@@ -920,16 +911,11 @@ static void RoadStationPickerWndProc(Win
 
			break;
 

	
 
		case WE_TICK:
 
			if (WP(w, def_d).close) {
 
				delete w;
 
				return;
 
			}
 

	
 
			CheckRedrawStationCoverage(w);
 
			break;
 

	
 
		case WE_DESTROY:
 
			if (!WP(w, def_d).close) ResetObjectToPlace();
 
			ResetObjectToPlace();
 
			break;
 

	
 
		default:
src/viewport.cpp
Show inline comments
 
@@ -2708,12 +2708,11 @@ void SetObjectToPlaceWnd(CursorID icon, 
 

	
 
void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num)
 
{
 
	Window *w;
 
	Window *w = NULL;
 

	
 
	/* undo clicking on button and drag & drop */
 
	if (_thd.place_mode != VHM_NONE || _special_mouse_mode == WSM_DRAGDROP) {
 
		w = FindWindowById(_thd.window_class, _thd.window_number);
 
		if (w != NULL) w->OnPlaceObjectAbort();
 
	}
 

	
 
	SetTileSelectSize(1, 1);
 
@@ -2734,10 +2733,16 @@ void SetObjectToPlace(CursorID icon, Spr
 
	if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode
 
		VpStartPreSizing();
 

	
 
	if ( (int)icon < 0)
 
	if ((int)icon < 0) {
 
		SetAnimatedMouseCursor(_animcursors[~icon]);
 
	else
 
	} else {
 
		SetMouseCursor(icon, pal);
 
	}
 

	
 
	/* Call the abort function only *after* the window class/number
 
	 * are reset so one doesn't get into infinite loops when someone
 
	 * resets the object to place during the abort callback. */
 
	if (w != NULL) w->OnPlaceObjectAbort();
 
}
 

	
 
void ResetObjectToPlace()
src/window_gui.h
Show inline comments
 
@@ -527,7 +527,6 @@ struct menu_d {
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
 

	
 
struct def_d {
 
	bool close;
 
	int16 data_1, data_2, data_3;
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
0 comments (0 inline, 0 general)