source: branches/eraser6/Eraser/AboutForm.cs @ 856

Revision 856, 9.8 KB checked in by lowjoel, 6 years ago (diff)

Implemented a slightly (performance increase by 200%) faster about box drawing algorithm. Fixes #136.

  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By: Kasra Nassiri <cjax@users.sourceforge.net>
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Drawing.Imaging;
28using System.Text;
29using System.Windows.Forms;
30using System.Runtime.InteropServices;
31using System.Reflection;
32using Eraser.Util;
33using System.Diagnostics;
34
35namespace Eraser
36{
37    public partial class AboutForm : Form
38    {
39        private Bitmap AboutBitmap;
40        private Point AboutBitmapPos;
41        private string AboutText;
42        private Bitmap AboutTextBitmap;
43        private Rectangle AboutTextRect;
44
45        private Bitmap ParentBitmap;
46        private int ParentOpacity;
47        private int AboutTextScrollTop;
48
49        private Rectangle WebsiteRect;
50        private Rectangle DonateRect;
51
52        private Bitmap DoubleBufferBitmap;
53
54        public AboutForm(Control parent)
55        {
56            //Create and position the dialog
57            InitializeComponent();
58            ClientSize = new Size(parent.ClientSize.Width, parent.ClientSize.Height);
59            Point point = parent.PointToScreen(new Point(0, 0));
60            Left = point.X;
61            Top = point.Y;
62
63            //Load the localised About Text
64            AboutText = S._(@"Eraser is an advanced security tool for Windows, which allows you to completely remove sensitive data from your hard drive by overwriting it several times with carefully selected patterns. Eraser is Free software and its source code is released under GNU General Public License.
65
66Erasure Method Credits:
67Gutmann (35 Pass):      Copyright Peter Gutmann & Colin Plumb
68Gutmann Lite (10 pass):         Copyright Peter Gutmann & Colin Plumb
69US DoD (7 pass):            Copyright United States Department of
70                Defense
71US DoD (3 pass):            Copyright United States Department of
72                Defense
73US Air Force 5020 (3 pass): Copyright United States Department of
74                Defense
75US Army AR380-19 (3 pass):  Copyright United States Department of
76                Defense
77RCMP TSSIT OPS-II (7 pass): Copyright Government of Canada,
78                Royal Canadian Mounted Police
79Schneier's Method (7 pass): Copyright Bruce Schneier
80German VSITR (7 pass):      Copyright Germany BSI Verschlusssachen
81                -IT-Richtlinien
82British HMG IS5 (3 pass):       Copyright British Government
83British HMG IS5 (1 pass):       Copyright British Government
84Russian GOST P50739-95 (2 pass):    Copyright Government of the Soviet
85                Union
86Pseudorandom data (1 pass): Public Domain
87First/Last 16Kb:            Copyright The Eraser Project
88
89Eraser Copyright " + "\u00A9" + @" The Eraser Project
90
91Eraser Project Members:
92" + "\u2022" + @" Sami Tolvanen:        Mentor/Initiator
93" + "\u2022" + @" Garrett Trant:        Mentor/Researcher
94" + "\u2022" + @" Joel Low:     Lead Developer
95" + "\u2022" + @" Kasra Nassiri:        Developer/Security Researcher
96" + "\u2022" + @" Dennis van Lith:      Designer");
97
98            //Create the About bitmap localised for the current version (sans scrolling
99            //text) so it can be drawn quickly later.
100            AboutBitmap = Properties.Resources.AboutDialog;
101            AboutBitmap = AboutBitmap.Clone(new Rectangle(0, 0, AboutBitmap.Width,
102                AboutBitmap.Height), PixelFormat.DontCare);
103            using (Graphics g = Graphics.FromImage(AboutBitmap))
104            {
105                //Version number
106                Font boldFont = new Font(Font, FontStyle.Bold);
107                Font underlineFont = new Font(Font, FontStyle.Underline);
108                Brush textBrush = new SolidBrush(Color.White);
109                PointF eraserPos = new PointF(168, 80);
110                SizeF eraserSize = g.MeasureString(S._("Eraser"), boldFont);
111                g.DrawString(S._("Eraser"), boldFont, textBrush, eraserPos);
112                g.DrawString(Assembly.GetExecutingAssembly().GetName().Version.ToString(),
113                    Font, textBrush, new PointF(eraserPos.X + eraserSize.Width + 3, eraserPos.Y));
114
115                //Copyright and Website
116                string copyrightText = S._("copyright \u00a9 2008 The Eraser Project");
117                PointF copyrightPos = new PointF(eraserPos.X, eraserPos.Y + eraserSize.Height);
118                SizeF copyrightSize = g.MeasureString(copyrightText, Font);
119                g.DrawString(copyrightText, Font, textBrush, copyrightPos);
120
121                string websiteText = "http://eraser.sourceforge.net/";
122                PointF websitePos = new PointF(copyrightPos.X, copyrightPos.Y + copyrightSize.Height);
123                SizeF websiteSize = g.MeasureString(websiteText, Font);
124                g.DrawString(websiteText, underlineFont, textBrush, websitePos);
125                WebsiteRect = new Rectangle((int)websitePos.X, (int)websitePos.Y,
126                    (int)websiteSize.Width, (int)websiteSize.Height);
127
128                //Open source disclaimer.
129                string disclaimerText = S._("Eraser is free open-source software!");
130                PointF disclaimerPos = new PointF(websitePos.X, websitePos.Y + websiteSize.Height * 1.5f);
131                SizeF disclaimerSize = g.MeasureString(disclaimerText, Font);
132                g.DrawString(disclaimerText, Font, textBrush, disclaimerPos);
133
134                //Donation statement
135                string donationText = S._("Please help us to continue developing Eraser - donate some coffee!");
136                PointF donationPos = new PointF(disclaimerPos.X, disclaimerPos.Y + 170);
137                SizeF donationSize = g.MeasureString(donationText, Font);
138                g.DrawString(donationText, Font, textBrush, donationPos);
139                DonateRect = new Rectangle((int)donationPos.X, (int)donationPos.Y,
140                    (int)donationSize.Width, (int)donationSize.Height);
141            }
142
143            //Calculate the position of the About bitmap
144            AboutBitmapPos = new Point((ClientSize.Width - AboutBitmap.Width) / 2,
145                (ClientSize.Height - AboutBitmap.Height) / 2);
146            WebsiteRect.X += AboutBitmapPos.X;
147            WebsiteRect.Y += AboutBitmapPos.Y;
148            DonateRect.X += AboutBitmapPos.X;
149            DonateRect.Y += AboutBitmapPos.Y;
150
151            //And calculate the bounds of the About Text.
152            AboutTextRect = new Rectangle(AboutBitmapPos.X + 19 + 149, AboutBitmapPos.Y + 20 + 147,
153                AboutBitmap.Width - 19 - 149 - 20, 130);
154
155            //Create the About Text laid out on screen.
156            SizeF aboutTextSize = SizeF.Empty;
157            using (Bitmap b = new Bitmap(1, 1))
158            using (Graphics g = Graphics.FromImage(b))
159                aboutTextSize = g.MeasureString(AboutText, Font, AboutTextRect.Width);
160            AboutTextBitmap = new Bitmap(AboutTextRect.Width, (int)aboutTextSize.Height);
161            using (Graphics g = Graphics.FromImage(AboutTextBitmap))
162            {
163                g.Clear(Color.FromArgb(0, 0, 0, 0));
164                g.DrawString(AboutText, Font, new SolidBrush(Color.White), new RectangleF(
165                    0.0f, 0.0f, AboutTextRect.Width, aboutTextSize.Height));
166            }
167
168            //Get the parent dialog's screen buffer.
169            ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height);
170            using (Graphics dest = Graphics.FromImage(ParentBitmap))
171            {
172                parent.Refresh();
173                Point parentPos = parent.PointToScreen(new Point(0, 0));
174                dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize);
175            }
176
177            ParentOpacity = 0;
178            AboutTextScrollTop = AboutTextRect.Height / 2;
179            animationTimer_Tick(null, null);
180        }
181
182        private void AboutForm_Click(object sender, EventArgs e)
183        {
184            Point cursorPos = PointToClient(Cursor.Position);
185            if (WebsiteRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
186                Process.Start("http://eraser.heidi.ie/");
187            else if (DonateRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
188                Process.Start("https://euro.swreg.org/cgi-bin/s.cgi?r=1&s=80181&db_key=1512312&x=0&lang=&lnk=");
189            else
190                //Dismiss the dialog.
191                Close();
192        }
193
194        private void AboutForm_Paint(object sender, PaintEventArgs e)
195        {
196            DrawComposite(e.Graphics);
197        }
198
199        private void AboutForm_MouseMove(object sender, MouseEventArgs e)
200        {
201            Cursor.Current = Cursors.Default;
202            if (WebsiteRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))) ||
203                DonateRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
204                Cursor.Current = Cursors.Hand;
205        }
206
207        private void AboutForm_MouseLeave(object sender, EventArgs e)
208        {
209            Cursor.Current = Cursors.Default;
210        }
211
212        private void animationTimer_Tick(object sender, EventArgs e)
213        {
214            if (ParentOpacity <= 128)
215                ParentOpacity += 8;
216            if (AboutTextBitmap.Height < -AboutTextScrollTop)
217            {
218                AboutTextScrollTop = AboutTextRect.Height;
219                GC.Collect();
220            }
221            else
222                AboutTextScrollTop -= 1;
223
224            using (Graphics g = CreateGraphics())
225                DrawComposite(g);
226        }
227
228        private void DrawComposite(Graphics g)
229        {
230            if (DoubleBufferBitmap == null)
231                DoubleBufferBitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
232            using (Graphics bg = Graphics.FromImage(DoubleBufferBitmap))
233            {
234                //Draw the parent image with a fading out effect
235                if (ParentOpacity > 128)
236                    bg.Clip = new Region(AboutTextRect);
237
238                Brush brush = new SolidBrush(Color.FromArgb(ParentOpacity, 0, 0, 0));
239                bg.DrawImageUnscaled(ParentBitmap, 0, 0);
240                bg.FillRectangle(brush, ClientRectangle);
241
242                //Then draw the About bitmap (which we cached in the constructor)
243                bg.DrawImageUnscaled(AboutBitmap, AboutBitmapPos);
244
245                //And the scrolling text
246                bg.Clip = new Region(AboutTextRect);
247                bg.DrawImageUnscaled(AboutTextBitmap, AboutTextRect.Left,
248                    AboutTextRect.Top + AboutTextScrollTop);
249                bg.ResetClip();
250            }
251
252            if (ParentOpacity > 128)
253                if (g.Clip != null)
254                    g.Clip.Complement(new Region(AboutTextRect));
255                else
256                    g.Clip = new Region(AboutTextRect);
257            g.DrawImageUnscaled(DoubleBufferBitmap, 0, 0);
258        }
259    }
260}
Note: See TracBrowser for help on using the repository browser.