Changeset 2245 for trunk/eraser


Ignore:
Timestamp:
9/24/2010 2:21:27 AM (4 years ago)
Author:
lowjoel
Message:

Added a DPI-aware version of the about dialog. There are some hacks here (notably the scale-down of the font size) but it works... Maybe we can review this when we rewrite the code to use DirectWrite??

Location:
trunk/eraser/Eraser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser/AboutForm.Designer.cs

    r1675 r2245  
    6868            // AboutForm 
    6969            //  
    70             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 
    7170            resources.ApplyResources(this, "$this"); 
     71            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 
    7272            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
    7373            this.Name = "AboutForm"; 
    7474            this.ShowInTaskbar = false; 
     75            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.AboutForm_MouseUp); 
     76            this.Paint += new System.Windows.Forms.PaintEventHandler(this.AboutForm_Paint); 
    7577            this.Click += new System.EventHandler(this.AboutForm_Click); 
    76             this.Paint += new System.Windows.Forms.PaintEventHandler(this.AboutForm_Paint); 
    7778            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.AboutForm_MouseDown); 
    7879            this.MouseLeave += new System.EventHandler(this.AboutForm_MouseLeave); 
    7980            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.AboutForm_MouseMove); 
    80             this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.AboutForm_MouseUp); 
    8181            this.ResumeLayout(false); 
    8282 
  • trunk/eraser/Eraser/AboutForm.cs

    r2135 r2245  
    6262            Left = point.X; 
    6363            Top = point.Y; 
     64 
     65            //Get the parent dialog's screen buffer. 
     66            ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height); 
     67            using (Graphics dest = Graphics.FromImage(ParentBitmap)) 
     68            { 
     69                parent.Refresh(); 
     70                Point parentPos = parent.PointToScreen(new Point(0, 0)); 
     71                dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize); 
     72            } 
    6473 
    6574            //Load the localised About Text 
     
    100109            //Create the About bitmap localised for the current version (sans scrolling 
    101110            //text) so it can be drawn quickly later. 
    102             AboutBitmap = Properties.Resources.AboutDialog; 
    103             AboutBitmap = AboutBitmap.Clone(new Rectangle(0, 0, AboutBitmap.Width, 
    104                 AboutBitmap.Height), PixelFormat.DontCare); 
     111            //First, duplicate the bitmap and scale it according to the resolution of the 
     112            //monitor. 
     113            float dpiScale = 0f; 
     114            using (Graphics controlDC = CreateGraphics()) 
     115            { 
     116                Debug.Assert(controlDC.DpiX == controlDC.DpiY); 
     117                dpiScale = controlDC.DpiX / 96.0f; 
     118            } 
     119 
     120            Bitmap sourceBitmap = Properties.Resources.AboutDialog; 
     121            AboutBitmap = new Bitmap((int)(sourceBitmap.Width * dpiScale), 
     122                (int)(sourceBitmap.Height * dpiScale)); 
    105123            using (Graphics g = Graphics.FromImage(AboutBitmap)) 
    106124            { 
     125                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
     126                g.ScaleTransform(dpiScale, dpiScale); 
     127                g.DrawImage(sourceBitmap, Point.Empty); 
     128 
     129                //Scale the font down since we will be using a scale transform later. 
     130                Font = new Font(Font.FontFamily, Font.SizeInPoints / dpiScale); 
     131 
    107132                //Version number 
    108133                Font boldFont = new Font(Font, FontStyle.Bold); 
     
    152177            AboutBitmapPos = new Point((ClientSize.Width - AboutBitmap.Width) / 2, 
    153178                (ClientSize.Height - AboutBitmap.Height) / 2); 
    154             WebsiteRect.X += AboutBitmapPos.X; 
    155             WebsiteRect.Y += AboutBitmapPos.Y; 
    156             DonateRect.X += AboutBitmapPos.X; 
    157             DonateRect.Y += AboutBitmapPos.Y; 
     179            WebsiteRect.X = (int)(WebsiteRect.X * dpiScale + AboutBitmapPos.X); 
     180            WebsiteRect.Y = (int)(WebsiteRect.Y * dpiScale + AboutBitmapPos.Y); 
     181            WebsiteRect.Width = (int)(WebsiteRect.Width * dpiScale); 
     182            WebsiteRect.Height = (int)(WebsiteRect.Height * dpiScale); 
     183            DonateRect.X = (int)(DonateRect.X * dpiScale + AboutBitmapPos.X); 
     184            DonateRect.Y = (int)(DonateRect.Y * dpiScale + AboutBitmapPos.Y); 
     185            DonateRect.Width = (int)(DonateRect.Width * dpiScale); 
     186            DonateRect.Height = (int)(DonateRect.Height * dpiScale); 
    158187 
    159188            //And calculate the bounds of the About Text. 
    160             AboutTextRect = new Rectangle(AboutBitmapPos.X + 19 + 149, AboutBitmapPos.Y + 20 + 147, 
    161                 AboutBitmap.Width - 19 - 149 - 20, 130); 
     189            AboutTextRect = Rectangle.Truncate(new RectangleF( 
     190                AboutBitmapPos.X + (19 + 149) * dpiScale, 
     191                AboutBitmapPos.Y + (20 + 147) * dpiScale, 
     192                AboutBitmap.Width - (19 + 149 + 20) * dpiScale, 
     193                130 * dpiScale)); 
    162194 
    163195            //Create the About Text laid out on screen. 
     
    165197            using (Bitmap b = new Bitmap(1, 1)) 
    166198            using (Graphics g = Graphics.FromImage(b)) 
     199            { 
     200                g.ScaleTransform(dpiScale, dpiScale); 
    167201                aboutTextSize = g.MeasureString(AboutText, Font, AboutTextRect.Width); 
     202            } 
    168203            AboutTextBitmap = new Bitmap(AboutTextRect.Width, (int)aboutTextSize.Height); 
    169204            using (Graphics g = Graphics.FromImage(AboutTextBitmap)) 
    170205            { 
    171206                g.Clear(Color.FromArgb(0, 0, 0, 0)); 
    172                 g.DrawString(AboutText, Font, new SolidBrush(Color.White), new RectangleF( 
    173                     0.0f, 0.0f, AboutTextRect.Width, aboutTextSize.Height)); 
    174             } 
    175  
    176             //Get the parent dialog's screen buffer. 
    177             ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height); 
    178             using (Graphics dest = Graphics.FromImage(ParentBitmap)) 
    179             { 
    180                 parent.Refresh(); 
    181                 Point parentPos = parent.PointToScreen(new Point(0, 0)); 
    182                 dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize); 
     207                g.ScaleTransform(dpiScale, dpiScale); 
     208                g.DrawString(AboutText, Font, new SolidBrush(Color.White), 
     209                    new RectangleF(0.0f, 0.0f, AboutTextBitmap.Width / dpiScale, 
     210                        AboutTextBitmap.Height / dpiScale)); 
    183211            } 
    184212 
  • trunk/eraser/Eraser/AboutForm.resx

    r474 r2245  
    125125  </metadata> 
    126126  <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     127  <data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing"> 
     128    <value>96, 96</value> 
     129  </data> 
    127130  <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing"> 
    128131    <value>568, 326</value> 
Note: See TracChangeset for help on using the changeset viewer.