changeset 83:4ca44dd25a6a

Merge
author Ivo Smits <Ivo@UCIS.nl>
date Sun, 23 Feb 2014 16:59:47 +0100
parents 0d389692be32 (diff) 3352f89cf6f5 (current diff)
children 146a8d224d86 c9da306e06c9
files FBGUI/FBGUI.cs
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/FBGUI/FBGUI.cs	Sun Feb 23 16:56:42 2014 +0100
+++ b/FBGUI/FBGUI.cs	Sun Feb 23 16:59:47 2014 +0100
@@ -631,6 +631,7 @@
 		public IFramebuffer Framebuffer { get; private set; }
 		private Bitmap Frontbuffer = null;
 		protected Object RenderLock = new object();
+		private Object StatusLock = new object();
 		public event EventHandler<InvalidateEventArgs> Painted;
 		protected Size size = Size.Empty;
 		private ThreadingTimer PaintTimer = null;
@@ -639,29 +640,28 @@
 		public Boolean SuspendDrawing {
 			get { return suspenddrawing; }
 			set {
+				lock (StatusLock) suspenddrawing = value;
+				if (value) return;
 				lock (RenderLock) {
-					suspenddrawing = value;
-					if (!value) {
-						Refresh(DirtyRectangle);
-						DirtyRectangle = Rectangle.Empty;
-					}
+					Refresh(DirtyRectangle);
+					DirtyRectangle = Rectangle.Empty;
 				}
 			}
 		}
 		public int RedrawDelay {
 			get { return PaintDelay; }
 			set {
-				lock (RenderLock) {
+				lock (StatusLock) {
 					if (value < 0) throw new ArgumentOutOfRangeException("value");
 					PaintDelay = value;
 					if (PaintDelay == 0) {
 						if (PaintTimer != null) PaintTimer.Dispose();
 						PaintTimer = null;
-						if (PaintScheduled) PaintTimerCallback(null);
 					} else {
 						PaintTimer = new ThreadingTimer(PaintTimerCallback);
 					}
 				}
+				if (PaintScheduled) PaintTimerCallback(null);
 			}
 		}
 		private Boolean suspenddrawing = false;
@@ -710,7 +710,8 @@
 		}
 		public override void Invalidate(Rectangle rect) {
 			if (rect.Width == 0 || rect.Height == 0) return;
-			lock (RenderLock) {
+			Boolean drawDirect = false;
+			lock (StatusLock) {
 				if (SuspendDrawing || PaintTimer != null) {
 					DirtyRectangle = DirtyRectangle.IsEmpty ? rect : Rectangle.Union(DirtyRectangle, rect);
 					if (!SuspendDrawing && !PaintScheduled) {
@@ -718,17 +719,20 @@
 						PaintTimer.Change(PaintDelay, Timeout.Infinite);
 					}
 				} else {
-					Refresh(rect);
+					drawDirect = true;
 				}
 			}
+			if (drawDirect) Refresh(rect);
 		}
 		private void PaintTimerCallback(Object state) {
 			try {
-				lock (RenderLock) {
+				Rectangle rect;
+				lock (StatusLock) {
 					PaintScheduled = false;
-					Refresh(DirtyRectangle);
+					rect = DirtyRectangle;
 					DirtyRectangle = Rectangle.Empty;
 				}
+				Refresh(rect);
 			} catch (Exception ex) {
 				Debug.WriteLine(ex);
 				Console.Error.WriteLine(ex);
@@ -777,7 +781,7 @@
 			return true;
 		}
 		public virtual void Dispose() {
-			lock (RenderLock) {
+			lock (StatusLock) {
 				if (PaintTimer != null) PaintTimer.Dispose();
 				PaintTimer = null;
 			}