(svn r22135) -Fix [FS#4523]: When commands need to invalidate windows, process these events asynchronously before the next redraw. Calling window code directly from command scope uses wrong _current_company and might issue nested DoCommands() which interfer with the running command.

This commit is contained in:
frosch
2011-02-23 20:54:55 +00:00
parent 40cc3324fa
commit 19b7249ade
9 changed files with 60 additions and 12 deletions

View File

@@ -17,6 +17,7 @@
#include "company_type.h"
#include "tile_type.h"
#include "widget_type.h"
#include "core/smallvec_type.hpp"
/** State of handling an event. */
enum EventState {
@@ -221,6 +222,8 @@ protected:
void InitializePositionSize(int x, int y, int min_width, int min_height);
void FindWindowPlacementAndResize(int def_width, int def_height);
SmallVector<int, 4> scheduled_invalidation_data; ///< Data of scheduled OnInvalidateData() calls.
public:
Window();
@@ -438,6 +441,28 @@ public:
this->OnInvalidateData(data);
}
/**
* Schedule a invalidation call for next redraw.
* Important for asynchronous invalidation from commands.
* @param data The data to invalidate with
*/
void ScheduleInvalidateData(int data = 0)
{
this->SetDirty();
*this->scheduled_invalidation_data.Append() = data;
}
/**
* Process all scheduled invalidations.
*/
void ProcessScheduledInvalidations()
{
for (int *data = this->scheduled_invalidation_data.Begin(); this->window_class != WC_INVALID && data != this->scheduled_invalidation_data.End(); data++) {
this->OnInvalidateData(*data);
}
this->scheduled_invalidation_data.Clear();
}
/*** Event handling ***/
/**