Changeset 471
- Timestamp:
- 11/7/2008 8:09:08 AM (5 years ago)
- Location:
- branches/eraser6/Eraser
- Files:
-
- 3 edited
-
AboutForm.Designer.cs (modified) (3 diffs)
-
AboutForm.cs (modified) (7 diffs)
-
AboutForm.resx (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Eraser/AboutForm.Designer.cs
r470 r471 52 52 this.components = new System.ComponentModel.Container(); 53 53 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm)); 54 this.aboutPicBox = new System.Windows.Forms.PictureBox(); 55 this.fadeTimer = new System.Windows.Forms.Timer(this.components); 56 this.scrollTimer = new System.Windows.Forms.Timer(this.components); 57 ((System.ComponentModel.ISupportInitialize)(this.aboutPicBox)).BeginInit(); 54 this.animationTimer = new System.Windows.Forms.Timer(this.components); 58 55 this.SuspendLayout(); 59 56 // 60 // a boutPicBox57 // animationTimer 61 58 // 62 resources.ApplyResources(this.aboutPicBox, "aboutPicBox"); 63 this.aboutPicBox.Image = global::Eraser.Properties.Resources.AboutDialog; 64 this.aboutPicBox.Name = "aboutPicBox"; 65 this.aboutPicBox.TabStop = false; 66 this.aboutPicBox.Click += new System.EventHandler(this.AboutForm_Click); 67 // 68 // fadeTimer 69 // 70 this.fadeTimer.Enabled = true; 71 this.fadeTimer.Interval = 10; 72 this.fadeTimer.Tick += new System.EventHandler(this.fadeTimer_Tick); 73 // 74 // scrollTimer 75 // 76 this.scrollTimer.Interval = 50; 77 this.scrollTimer.Tick += new System.EventHandler(this.scrollTimer_Tick); 59 this.animationTimer.Enabled = true; 60 this.animationTimer.Interval = 50; 61 this.animationTimer.Tick += new System.EventHandler(this.animationTimer_Tick); 78 62 // 79 63 // AboutForm … … 81 65 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 82 66 resources.ApplyResources(this, "$this"); 83 this.Controls.Add(this.aboutPicBox);84 67 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 85 68 this.Name = "AboutForm"; 86 69 this.ShowInTaskbar = false; 87 ((System.ComponentModel.ISupportInitialize)(this.aboutPicBox)).EndInit();70 this.Click += new System.EventHandler(this.AboutForm_Click); 88 71 this.ResumeLayout(false); 89 72 … … 92 75 #endregion 93 76 94 private System.Windows.Forms.PictureBox aboutPicBox; 95 private System.Windows.Forms.Timer fadeTimer; 96 private System.Windows.Forms.Timer scrollTimer; 77 private System.Windows.Forms.Timer animationTimer; 97 78 } 98 79 } -
branches/eraser6/Eraser/AboutForm.cs
r470 r471 25 25 using System.Data; 26 26 using System.Drawing; 27 using System.Drawing.Imaging; 27 28 using System.Text; 28 29 using System.Windows.Forms; 29 using Eraser.Util;30 30 using System.Runtime.InteropServices; 31 31 using System.Reflection; 32 using Eraser.Util; 32 33 33 34 namespace Eraser … … 35 36 public partial class AboutForm : Form 36 37 { 37 private Bitmap ParentBitmap; 38 private int ParentBitmapOpacity; 39 private Bitmap BaseBitmap; 38 private Bitmap AboutBitmap; 39 private Point AboutBitmapPos; 40 40 private readonly string AboutText = "The Gutmann method used for overwriting is based on Peter " + 41 41 "Gutmann's paper \"Secure Deletion of Data from Magnetic and Solid-State Memory\".\n" + … … 51 51 "\u2022 Kasra Nasiri: Developer\n" + 52 52 "\u2022 Garrett Trant: Mentor\n"; 53 private Bitmap AboutBitmap; 54 private SizeF AboutBitmapSize; 53 private Bitmap AboutTextBitmap; 54 private Rectangle AboutTextRect; 55 56 private Bitmap ParentBitmap; 57 private int ParentOpacity; 58 private int AboutTextScrollTop; 59 60 private Bitmap DoubleBufferBitmap; 55 61 56 62 public AboutForm(Control parent) 57 63 { 58 //Get the parent dialog's screen buffer. 59 ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height); 60 using (Graphics dest = Graphics.FromImage(ParentBitmap)) 61 using (Graphics g = parent.CreateGraphics()) 62 { 63 Point parentPos = parent.PointToScreen(new Point(0, 0)); 64 dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize); 65 } 66 67 //Create the dialog 64 //Create and position the dialog 68 65 InitializeComponent(); 69 66 ClientSize = new Size(parent.ClientSize.Width, parent.ClientSize.Height); … … 72 69 Top = point.Y; 73 70 74 ParentBitmapOpacity = 0; 75 BaseBitmap = null; 76 fadeTimer_Tick(null, null); 77 } 78 79 private void fadeTimer_Tick(object sender, EventArgs e) 80 { 81 //Darken the thing. 82 Rectangle rect = new Rectangle(0, 0, ParentBitmap.Width, ParentBitmap.Height); 83 Bitmap newBmp = ParentBitmap.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare); 84 using (Graphics g = Graphics.FromImage(newBmp)) 71 //Create the About bitmap localised for the current version (sans scrolling 72 //text) so it can be drawn quickly later. 73 AboutBitmap = Properties.Resources.AboutDialog; 74 AboutBitmap = AboutBitmap.Clone(new Rectangle(0, 0, AboutBitmap.Width, 75 AboutBitmap.Height), PixelFormat.DontCare); 76 using (Graphics g = Graphics.FromImage(AboutBitmap)) 85 77 { 86 Brush brush = new SolidBrush(Color.FromArgb(ParentBitmapOpacity += 8, 0, 0, 0));87 g.FillRectangle(brush, rect);88 89 //Draw the background bitmap90 Point boxPos = new Point((ClientSize.Width - Properties.Resources.AboutDialog.Width) / 2,91 (ClientSize.Height - Properties.Resources.AboutDialog.Height) / 2);92 g.DrawImage(Properties.Resources.AboutDialog, boxPos.X, boxPos.Y);93 boxPos.Offset(19, 20);94 95 78 //Version number 96 79 Font boldFont = new Font(Font, FontStyle.Bold); 97 80 Brush textBrush = new SolidBrush(Color.White); 98 PointF eraserPos = new PointF( boxPos.X + 149, boxPos.Y + 60);81 PointF eraserPos = new PointF(168, 80); 99 82 SizeF eraserSize = g.MeasureString(S._("Eraser"), boldFont); 100 83 g.DrawString(S._("Eraser"), boldFont, textBrush, eraserPos); … … 119 102 g.DrawString(disclaimerText, Font, textBrush, disclaimerPos); 120 103 121 //About text: Break it up into managable chunks.122 if (AboutBitmap == null)123 {124 Size textMaxSize = Properties.Resources.AboutDialog.Size;125 textMaxSize.Width -= (int)eraserPos.X - 42; //The left alignment and the padding126 AboutBitmap = new Bitmap(textMaxSize.Width, 500);127 using (Graphics aboutTextGraphics = Graphics.FromImage(AboutBitmap))128 {129 aboutTextGraphics.Clear(Color.FromArgb(0, 0, 0, 0));130 AboutBitmapSize = DrawMultilineString(aboutTextGraphics, AboutText, Font,131 textBrush, new PointF(0, 0), textMaxSize.Width);132 }133 }134 135 104 //Donation statement 136 105 string donationText = S._("Please help us continue develop Eraser, donate some coffee..."); … … 140 109 } 141 110 142 aboutPicBox.Image = newBmp; 143 if (ParentBitmapOpacity >= 128) 111 //Calculate the position of the About bitmap 112 AboutBitmapPos = new Point((ClientSize.Width - AboutBitmap.Width) / 2, 113 (ClientSize.Height - AboutBitmap.Height) / 2); 114 115 //And calculate the bounds of the About Text. 116 AboutTextRect = new Rectangle(AboutBitmapPos.X + 19 + 149, AboutBitmapPos.Y + 20 + 147, 117 AboutBitmap.Width - 19 - 149 - 20, 130); 118 119 //Create the About Text laid out on screen. 120 SizeF aboutTextSize = SizeF.Empty; 121 using (Bitmap b = new Bitmap(1, 1)) 122 using (Graphics g = Graphics.FromImage(b)) 123 aboutTextSize = g.MeasureString(AboutText, Font, AboutTextRect.Width); 124 AboutTextBitmap = new Bitmap(AboutTextRect.Width, (int)aboutTextSize.Height); 125 using (Graphics g = Graphics.FromImage(AboutTextBitmap)) 144 126 { 145 //We are at the end of the fading animation. Duplicate the backing bitmap 146 //so that we can start text scrolling. 147 BaseBitmap = newBmp; 148 fadeTimer.Enabled = false; 149 scrollTimer.Enabled = true; 150 GC.Collect(); 127 g.Clear(Color.FromArgb(0, 0, 0, 0)); 128 g.DrawString(AboutText, Font, new SolidBrush(Color.White), new RectangleF( 129 0.0f, 0.0f, AboutTextRect.Width, aboutTextSize.Height)); 151 130 } 152 }153 131 154 private int top = 0; 155 private void scrollTimer_Tick(object sender, EventArgs e) 156 { 157 Bitmap workingBitmap = BaseBitmap.Clone(new Rectangle(0, 0, BaseBitmap.Width, 158 BaseBitmap.Height), System.Drawing.Imaging.PixelFormat.DontCare); 159 using (Graphics g = Graphics.FromImage(workingBitmap)) 132 //Get the parent dialog's screen buffer. 133 ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height); 134 using (Graphics dest = Graphics.FromImage(ParentBitmap)) 160 135 { 161 Point boxPos = new Point((ClientSize.Width - Properties.Resources.AboutDialog.Width) / 2,162 (ClientSize.Height - Properties.Resources.AboutDialog.Height) / 2);163 boxPos.Offset(19, 20);164 boxPos.Offset(149, 147);136 parent.Refresh(); 137 Point parentPos = parent.PointToScreen(new Point(0, 0)); 138 dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize); 139 } 165 140 166 g.Clip = new Region(new Rectangle(new Point(boxPos.X, boxPos.Y + 4), new Size(400, 130))); 167 if (AboutBitmapSize.Height < -top) 168 boxPos.Offset(0, top = 130); 169 else 170 boxPos.Offset(0, top -= 1); 171 g.DrawImage(AboutBitmap, boxPos); 172 } 173 aboutPicBox.Image = workingBitmap; 141 ParentOpacity = 0; 142 AboutTextScrollTop = AboutTextRect.Height / 2; 143 animationTimer_Tick(null, null); 174 144 } 175 145 … … 181 151 } 182 152 183 private static SizeF DrawMultilineString(Graphics g, string s, Font font, 184 Brush brush, PointF pos, float wrapWidth) 153 private void animationTimer_Tick(object sender, EventArgs e) 185 154 { 186 List<string> aboutTexts = new List<string>(); 187 for (int i = 0, lastStart = 0; ; ) 155 if (ParentOpacity <= 128) 156 ParentOpacity += 8; 157 if (AboutTextBitmap.Height < -AboutTextScrollTop) 188 158 { 189 if (i >= s.Length) 190 { 191 if (lastStart < s.Length) 192 aboutTexts.Add(s.Substring(lastStart)); 193 break; 194 } 195 else if (Environment.NewLine.IndexOf(s[i]) != -1) 196 { 197 aboutTexts.Add(s.Substring(lastStart, i - lastStart)); 198 lastStart = ++i; 199 } 200 else 201 ++i; 159 AboutTextScrollTop = AboutTextRect.Height; 160 GC.Collect(); 161 } 162 else 163 AboutTextScrollTop -= 1; 164 165 DrawComposite(); 166 } 167 168 private void DrawComposite() 169 { 170 if (DoubleBufferBitmap == null) 171 DoubleBufferBitmap = new Bitmap(ClientSize.Width, ClientSize.Height); 172 using (Graphics g = Graphics.FromImage(DoubleBufferBitmap)) 173 { 174 //Draw the parent image with a fading out effect 175 Brush brush = new SolidBrush(Color.FromArgb(ParentOpacity, 0, 0, 0)); 176 g.DrawImageUnscaled(ParentBitmap, 0, 0); 177 g.FillRectangle(brush, ClientRectangle); 178 179 //Then draw the About bitmap (which we cached in the constructor) 180 g.DrawImageUnscaled(AboutBitmap, AboutBitmapPos); 181 182 //And the scrolling text 183 g.Clip = new Region(AboutTextRect); 184 g.DrawImageUnscaled(AboutTextBitmap, AboutTextRect.Left, 185 AboutTextRect.Top + AboutTextScrollTop); 186 g.ResetClip(); 202 187 } 203 188 204 //Draw each line, one at a time, wrapping it as we go. 205 foreach (string line in aboutTexts) 206 { 207 //Determine where we can wrap. 208 List<int> wrapPos = new List<int>(); 209 for (int last = 0; last != -1; ) 210 { 211 int wrap = line.IndexOfAny(new char[] { ' ', '\t' }, last); 212 if (wrap != -1) 213 wrapPos.Insert(0, wrap++); 214 last = wrap; 215 } 216 217 List<string> wrapLines = new List<string>(); 218 List<int> reuseIndices = new List<int>(); 219 int lastIndex = 0; 220 do 221 { 222 string thisLine = line.Substring(lastIndex); 223 SizeF textSize = g.MeasureString(thisLine, font); 224 while (textSize.Width > wrapWidth) 225 { 226 reuseIndices.Add(wrapPos[0]); 227 thisLine = thisLine.Remove(wrapPos[0] - lastIndex); 228 textSize = g.MeasureString(thisLine, font); 229 wrapPos.RemoveAt(0); 230 } 231 wrapLines.Add(thisLine); 232 lastIndex += thisLine.Length + 1; 233 wrapPos.Clear(); 234 wrapPos.AddRange(reuseIndices); 235 reuseIndices.Clear(); 236 } 237 while (lastIndex < line.Length); 238 239 //Then write the strings to screen. 240 foreach (string wrapLine in wrapLines) 241 { 242 SizeF wrapLineSize = g.MeasureString(wrapLine == string.Empty ? 243 " " : wrapLine, font); 244 g.DrawString(wrapLine, font, brush, pos); 245 pos.Y += wrapLineSize.Height; 246 } 247 } 248 249 return new SizeF(wrapWidth, pos.Y); 189 using (Graphics g = CreateGraphics()) 190 g.DrawImageUnscaled(DoubleBufferBitmap, 0, 0); 250 191 } 251 192 } -
branches/eraser6/Eraser/AboutForm.resx
r470 r471 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 121 <data name="aboutPicBox.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms"> 122 <value>Fill</value> 123 </data> 124 <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 125 <data name="aboutPicBox.Location" type="System.Drawing.Point, System.Drawing"> 126 <value>0, 0</value> 127 </data> 128 <data name="aboutPicBox.Size" type="System.Drawing.Size, System.Drawing"> 129 <value>568, 326</value> 130 </data> 131 <assembly alias="mscorlib" name="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 132 <data name="aboutPicBox.TabIndex" type="System.Int32, mscorlib"> 133 <value>0</value> 134 </data> 135 <data name=">>aboutPicBox.Name" xml:space="preserve"> 136 <value>aboutPicBox</value> 137 </data> 138 <data name=">>aboutPicBox.Type" xml:space="preserve"> 139 <value>System.Windows.Forms.PictureBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 140 </data> 141 <data name=">>aboutPicBox.Parent" xml:space="preserve"> 142 <value>$this</value> 143 </data> 144 <data name=">>aboutPicBox.ZOrder" xml:space="preserve"> 145 <value>0</value> 146 </data> 147 <metadata name="fadeTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 120 <metadata name="animationTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 148 121 <value>17, 17</value> 149 </metadata>150 <metadata name="scrollTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">151 <value>120, 17</value>152 122 </metadata> 153 123 <metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 154 124 <value>True</value> 155 125 </metadata> 126 <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 156 127 <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing"> 157 128 <value>568, 326</value> … … 159 130 <data name="$this.Font" type="System.Drawing.Font, System.Drawing"> 160 131 <value>Segoe UI, 9pt</value> 132 </data> 133 <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 134 <data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms"> 135 <value>NoControl</value> 161 136 </data> 162 137 <data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms"> … … 166 141 <value>AboutForm</value> 167 142 </data> 168 <data name=">> fadeTimer.Name" xml:space="preserve">169 <value> fadeTimer</value>143 <data name=">>animationTimer.Name" xml:space="preserve"> 144 <value>animationTimer</value> 170 145 </data> 171 <data name=">>fadeTimer.Type" xml:space="preserve"> 172 <value>System.Windows.Forms.Timer, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 173 </data> 174 <data name=">>scrollTimer.Name" xml:space="preserve"> 175 <value>scrollTimer</value> 176 </data> 177 <data name=">>scrollTimer.Type" xml:space="preserve"> 146 <data name=">>animationTimer.Type" xml:space="preserve"> 178 147 <value>System.Windows.Forms.Timer, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 179 148 </data>
Note: See TracChangeset
for help on using the changeset viewer.
