Permalink
Browse files

Little test for invalidation. Nice for profiling.

svn path=/trunk/winforms/; revision=54257
  • Loading branch information...
1 parent 91c73ff commit e366382ede46eddff45392569e813389a4c8c89a Jackson Harper committed Dec 12, 2005
Showing with 80 additions and 0 deletions.
  1. +10 −0 invalidate/Makefile
  2. +70 −0 invalidate/swf-invalidate.cs
View
@@ -0,0 +1,10 @@
+all: mono
+
+mono: swf-invalidate.cs
+ mcs swf-invalidate.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
+
+dotnet: swf-invalidate.cs
+ csc swf-invalidate.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
+
+clean:
+ rm swf-invalidate.exe -r -f
@@ -0,0 +1,70 @@
+
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+
+
+public class InvalidateForm : Form {
+
+ private Timer timer;
+ private int width;
+ private bool region;
+
+ public InvalidateForm ()
+ {
+ timer = new Timer ();
+ timer.Interval = 500;
+ timer.Tick += new EventHandler (TimerTick);
+ timer.Enabled = true;
+
+ BackColor = Color.Blue;
+
+ Paint += new PaintEventHandler (PaintHandler);
+ Click += new EventHandler (ClickHandler);
+ }
+
+ private void TimerTick (object sender, EventArgs e)
+ {
+ width += 10;
+ if (width > Width + 11) {
+ width = 0;
+ Refresh ();
+ region = !region;
+ return;
+ }
+
+ if (!region) {
+ Invalidate (new Rectangle (0, 0, width, Height));
+ } else {
+ int half = width / 2;
+ int xmiddle = Width / 2;
+ int ymiddle = Height / 2;
+ Rectangle rect = new Rectangle (xmiddle - half, ymiddle - half, width, width);
+ Invalidate (new Region (rect));
+ }
+ }
+
+ private void ClickHandler (object sender, EventArgs e)
+ {
+ timer.Enabled = !timer.Enabled;
+ }
+
+ private void PaintHandler (object sender, PaintEventArgs pe)
+ {
+ if (pe.ClipRectangle.Width == Width && pe.ClipRectangle.Height == Height) {
+ Console.WriteLine ("Clearing Form");
+ pe.Graphics.FillRectangle (new SolidBrush (BackColor), pe.ClipRectangle);
+ return;
+ }
+
+ Console.WriteLine ("Filling: " + pe.ClipRectangle);
+ pe.Graphics.FillRectangle (new SolidBrush (Color.Red), pe.ClipRectangle);
+ }
+
+ public static void Main ()
+ {
+ Application.Run (new InvalidateForm ());
+ }
+}
+

0 comments on commit e366382

Please sign in to comment.