Changeset 69


Ignore:
Timestamp:
Sep 20, 2005, 11:26:29 PM (19 years ago)
Author:
rryu
Message:

とりあえずステータスウインドウを大きさ可変にしてみた(整数演算の誤差でグラフの端に隙間ができる)。

Location:
trunk/MacFaceFloat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/StatusWindow.cs

    • Property svn:keywords set to id
    r62 r69  
     1/*
     2 * $Id$
     3 */
    14using System;
    25using System.Drawing;
     
    1316        public class StatusWindow : System.Windows.Forms.Form
    1417        {
    15                 internal System.Windows.Forms.PictureBox memoryGraphPicBox;
    16                 internal System.Windows.Forms.PictureBox cpuGraphPicBox;
    1718                /// <summary>
    1819                /// •K—v‚ȃfƒUƒCƒi•Ï”‚Å‚·B
     
    2021                private System.ComponentModel.Container components = null;
    2122
     23                internal System.Windows.Forms.PictureBox memoryGraphPicBox;
     24                internal System.Windows.Forms.PictureBox cpuGraphPicBox;
     25
    2226                private CPUStatistics cpuStats;
    2327                private MemoryStatistics memStats;
     
    3640                        this.memStats = memStats;
    3741
    38                         cpuGraph = new Bitmap(5*60, 100);
    39                         memoryGraph = new Bitmap(5*60, 100);
     42                        cpuGraph = new Bitmap(cpuGraphPicBox.Width, cpuGraphPicBox.Height);
     43                        memoryGraph = new Bitmap(memoryGraphPicBox.Width, memoryGraphPicBox.Height);
    4044                        cpuGraphPicBox.Image = cpuGraph;
    4145                        memoryGraphPicBox.Image = memoryGraph;
     
    7074                {
    7175                        Graphics g = Graphics.FromImage(cpuGraph);
    72 
    7376                        g.SmoothingMode = SmoothingMode.AntiAlias;
    7477
    75                         g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
     78                        int fw = cpuGraph.Width;
     79                        int fh = cpuGraph.Height;
     80                        int m = fh / 10;
     81
     82                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, fw, fh);
    7683                        Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);
    77                         for (int y = 0; y < 100; y += 10)
    78                         {
    79                                 g.DrawLine(pen, 0, y, 300, y);
    80                         }
    81                         g.DrawLine(Pens.Gray, 0, 50, 300, 50);
     84                        for (int y = 0; y < fh; y += m)
     85                        {
     86                                g.DrawLine(pen, 0, y, fw, y);
     87                        }
     88                        g.DrawLine(Pens.Gray, 0, fh/2, fw, fh/2);
    8289
    8390                        int count = cpuStats.Count;
     
    8592                        if (count >= 2)
    8693                        {
     94                                int bw = fw / 60;
    8795                                Point[] userGraph = new Point[count+2];
    8896                                Point[] sysGraph = new Point[count+2];
    8997
    90                                 userGraph[count+0].X = 300 - (count-1) * 5;
    91                                 userGraph[count+0].Y = 100 - 0;
    92                                 userGraph[count+1].X = 300 - 0 * 5;
    93                                 userGraph[count+1].Y = 100 - 0;
    94 
    95                                 sysGraph[count+0].X = 300 - (count-1) * 5;
    96                                 sysGraph[count+0].Y = 100 - 0;
    97                                 sysGraph[count+1].X = 300 - 0 * 5;
    98                                 sysGraph[count+1].Y = 100 - 0;
     98                                userGraph[count+0].X = fw - (count-1) * bw;
     99                                userGraph[count+0].Y = fh - 0;
     100                                userGraph[count+1].X = fw - 0 * bw;
     101                                userGraph[count+1].Y = fh - 0;
     102
     103                                sysGraph[count+0].X = fw - (count-1) * bw;
     104                                sysGraph[count+0].Y = fh - 0;
     105                                sysGraph[count+1].X = fw - 0 * bw;
     106                                sysGraph[count+1].Y = fh - 0;
    99107
    100108                                for (int i = 0; i < count; i++)
    101109                                {
    102110                                        CPUUsage usage = cpuStats[i];
    103                                         userGraph[i].X = sysGraph[i].X = 300 - i * 5;
    104                                         userGraph[i].Y = 100 - usage.Active;
    105                                         sysGraph[i].Y = 100 - usage.System;
     111                                        userGraph[i].X = sysGraph[i].X = fw - i * bw;
     112                                        userGraph[i].Y = fh - usage.Active;
     113                                        sysGraph[i].Y = fh - usage.System;
    106114                                }
    107115
     
    118126                        Graphics g = Graphics.FromImage(memoryGraph);
    119127
     128                        int fw = memoryGraph.Width;
     129                        int fh = memoryGraph.Height;
     130
    120131                        int totalMemory = (int)memStats.TotalVisibleMemorySize * 1024;
    121                         double rate = 100.0 / memStats.CommitLimit;
     132                        double rate = (double)fh / memStats.CommitLimit;
    122133                        int border = (int)(totalMemory * rate);
    123134
    124                         g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
     135                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, fw, fh);
    125136                        Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);
    126                         for (int y = 100; y > 0; y -= (int)(128*1024*1024 * rate))
    127                         {
    128                                 g.DrawLine(pen, 0, y, 300, y);
     137                        for (int y = fh; y > 0; y -= (int)(128*1024*1024 * rate))
     138                        {
     139                                g.DrawLine(pen, 0, y, fw, y);
    129140                        }
    130141
     
    138149
    139150                        int count = memStats.Count;
     151                        int bw = fw / 60;
    140152
    141153                        for (int i = 0; i < count; i++)
     
    143155                                MemoryUsage usage = memStats[i];
    144156
    145                                 int x = 300 - i * 5 - 5;
    146                                 int y = 100;
    147                                 int w = 5;
     157                                int x = fw - i * bw - bw;
     158                                int y = fh;
     159                                int w = bw;
    148160                                int h = 0;
    149161
     
    170182
    171183
    172                                 x = 300 - i * 5 - 5;
    173                                 w = 2;
     184                                x = fw - i * bw - bw;
     185                                w = bw/2;
    174186                                h = (int)(usage.Pagein);
    175                                 y = 100 - h;
     187                                y = fh - h;
    176188                                g.FillRectangle(Brushes.LightGray, x, y, w, h);
    177189
    178                                 x = 303 - i * 5 - 5;
    179                                 w = 2;
     190                                x = fw + bw/2 - i * bw - bw;
     191                                w = bw/2;
    180192                                h = (int)(usage.Pageout);
    181                                 y = 100 - h;
     193                                y = fh - h;
    182194                                g.FillRectangle(Brushes.Black, x, y, w, h);
    183195                        }
    184196                        Pen borderPen = new Pen(Color.Blue);
    185197                        borderPen.DashStyle = DashStyle.Dash;
    186                         g.DrawLine(borderPen, 0, 100-border, 300, 100-border);
     198                        g.DrawLine(borderPen, 0, fh-border, fw, fh-border);
    187199
    188200                        g.Dispose();
     
    203215                        // memoryGraphPicBox
    204216                        //
     217                        this.memoryGraphPicBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     218                                | System.Windows.Forms.AnchorStyles.Left)
     219                                | System.Windows.Forms.AnchorStyles.Right)));
    205220                        this.memoryGraphPicBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    206                         this.memoryGraphPicBox.Location = new System.Drawing.Point(6, 8);
     221                        this.memoryGraphPicBox.Location = new System.Drawing.Point(8, 8);
    207222                        this.memoryGraphPicBox.Name = "memoryGraphPicBox";
    208                         this.memoryGraphPicBox.Size = new System.Drawing.Size(302, 102);
     223                        this.memoryGraphPicBox.Size = new System.Drawing.Size(296, 104);
    209224                        this.memoryGraphPicBox.TabIndex = 0;
    210225                        this.memoryGraphPicBox.TabStop = false;
     
    212227                        // cpuGraphPicBox
    213228                        //
     229                        this.cpuGraphPicBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
     230                                | System.Windows.Forms.AnchorStyles.Right)));
    214231                        this.cpuGraphPicBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    215                         this.cpuGraphPicBox.Location = new System.Drawing.Point(6, 120);
     232                        this.cpuGraphPicBox.Location = new System.Drawing.Point(8, 120);
    216233                        this.cpuGraphPicBox.Name = "cpuGraphPicBox";
    217                         this.cpuGraphPicBox.Size = new System.Drawing.Size(302, 102);
     234                        this.cpuGraphPicBox.Size = new System.Drawing.Size(296, 104);
    218235                        this.cpuGraphPicBox.TabIndex = 1;
    219236                        this.cpuGraphPicBox.TabStop = false;
     
    225242                        this.Controls.Add(this.cpuGraphPicBox);
    226243                        this.Controls.Add(this.memoryGraphPicBox);
    227                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    228244                        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
    229245                        this.MaximizeBox = false;
    230246                        this.MinimizeBox = false;
     247                        this.MinimumSize = new System.Drawing.Size(322, 261);
    231248                        this.Name = "StatusWindow";
    232249                        this.Text = "ƒXƒe[ƒ^ƒX";
     250                        this.SizeChanged += new System.EventHandler(this.StatusWindow_SizeChanged);
    233251                        this.ResumeLayout(false);
    234252
    235253                }
    236254                #endregion
     255
     256                private void StatusWindow_SizeChanged(object sender, System.EventArgs e)
     257                {
     258                        cpuGraph.Dispose();
     259                        memoryGraph.Dispose();
     260                        cpuGraph = new Bitmap(cpuGraphPicBox.Width, cpuGraphPicBox.Height);
     261                        memoryGraph = new Bitmap(memoryGraphPicBox.Width, memoryGraphPicBox.Height);
     262                        cpuGraphPicBox.Image = cpuGraph;
     263                        memoryGraphPicBox.Image = memoryGraph;
     264                }
    237265        }
    238266}
  • trunk/MacFaceFloat/StatusWindow.resx

    r62 r69  
    110110    <value>False</value>
    111111  </data>
     112  <data name="cpuGraphPicBox.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     113    <value>Assembly</value>
     114  </data>
    112115  <data name="cpuGraphPicBox.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    113116    <value>Private</value>
    114117  </data>
    115   <data name="cpuGraphPicBox.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    116     <value>Assembly</value>
    117   </data>
    118118  <data name="$this.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    119119    <value>False</value>
     
    125125    <value>False</value>
    126126  </data>
     127  <data name="$this.Localizable" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     128    <value>False</value>
     129  </data>
     130  <data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     131    <value>8, 8</value>
     132  </data>
    127133  <data name="$this.Name">
    128134    <value>StatusWindow</value>
    129   </data>
    130   <data name="$this.Localizable" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    131     <value>False</value>
    132   </data>
    133   <data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    134     <value>8, 8</value>
    135135  </data>
    136136  <data name="$this.DrawGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Note: See TracChangeset for help on using the changeset viewer.