summaryrefslogtreecommitdiff
path: root/src/window_gui.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-02-23 20:54:55 +0000
committerfrosch <frosch@openttd.org>2011-02-23 20:54:55 +0000
commit19b7249adee1dba623ba4ee69266cd13888deb3d (patch)
tree4f399e2587ff32b008c60b8f6211e1f7021f5210 /src/window_gui.h
parent40cc3324fadce60522e97791604ae3a6643f4c2e (diff)
downloadopenttd-19b7249adee1dba623ba4ee69266cd13888deb3d.tar.xz
(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.
Diffstat (limited to 'src/window_gui.h')
-rw-r--r--src/window_gui.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/window_gui.h b/src/window_gui.h
index 724d77880..3254ee8c4 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -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 ***/
/**