Changeset 62


Ignore:
Timestamp:
Sep 9, 2005, 2:46:06 AM (19 years ago)
Author:
rryu
Message:

ステータスウインドウのグラフ描画処理をアプリケーションクラスからStatusWindowsクラスに移動した。
ついでにツールウインドウスタイルだったのを普通のウインドウスタイルにした。

Location:
trunk/MacFaceFloat
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MacFaceApp.cs

    r61 r62  
    1010using System.Windows.Forms;
    1111using System.Drawing;
    12 using System.Drawing.Drawing2D;
    1312using System.Data;
    1413using System.IO;
     
    2524                private Configuration config;
    2625
     26                private CPUStatistics cpuStats;
     27                private MemoryStatistics memStats;
     28
     29                private System.Windows.Forms.Timer updateTimer;
     30
    2731                private NotifyIcon notifyIcon;
    2832                private PatternWindow patternWindow;
     33                private StatusWindow statusWindow;
    2934               
    30                 private System.Windows.Forms.Timer updateTimer;
    31 
    32                 private StatusWindow statusWindow;
    33                 private Bitmap cpuGraph;
    34                 private Bitmap memoryGraph;
    35 
    36                 private CPUStatistics cpuStats;
    37                 private MemoryStatistics memStats;
    38 
    3935                [STAThread]
    4036                public static void Main(string[] args)
     
    5854
    5955                        patternWindow = null;
    60 
    61                         cpuGraph = null;
    62                         memoryGraph = null;
    6356                        statusWindow = null;
    6457
     
    219212                        if (statusWindow != null)
    220213                        {
    221                                 drawCPUGraph();
    222                                 drawMemoryGraph();
    223                                 statusWindow.cpuGraphPicBox.Invalidate();
    224                                 statusWindow.memoryGraphPicBox.Invalidate();
     214                                statusWindow.UpdateGraph();
    225215                        }
    226216                }
     
    245235                public void openStatusWindow()
    246236                {
    247                         statusWindow = new StatusWindow();
     237                        statusWindow = new StatusWindow(cpuStats, memStats);
    248238                        statusWindow.Closed += new EventHandler(statusWindow_Closed);
    249239                        statusWindow.Move +=new EventHandler(statusWindow_Move);
    250240
    251                         FormBorderStyle orgStyle = statusWindow.FormBorderStyle;
    252                         statusWindow.FormBorderStyle = FormBorderStyle.Sizable;
    253241                        statusWindow.StartPosition = FormStartPosition.Manual;
    254242                        statusWindow.Location = config.StatusWindowLocation;
    255                         statusWindow.FormBorderStyle = orgStyle;
    256 
    257                         cpuGraph = new Bitmap(5*60, 100);
    258                         memoryGraph = new Bitmap(5*60, 100);
    259                         statusWindow.cpuGraphPicBox.Image = cpuGraph;
    260                         statusWindow.memoryGraphPicBox.Image = memoryGraph;
    261                         drawCPUGraph();
    262                         drawMemoryGraph();
    263 
     243
     244                        statusWindow.UpdateGraph();
    264245                        statusWindow.Show();
    265246                }
     
    315296                }
    316297
    317                 private void statusWindow_Paint(object sender, PaintEventArgs e)
    318                 {
    319                         Graphics g = e.Graphics;
    320 
    321                         g.DrawImage(cpuGraph, 5,5);
    322                         g.DrawRectangle(Pens.Black, 4, 4, 301, 101);
    323 
    324                         g.DrawImage(memoryGraph, 5,110);
    325                         g.DrawRectangle(Pens.Black, 4, 109, 301, 101);
    326                 }
    327 
    328                 private void drawCPUGraph()
    329                 {
    330                         Graphics g = Graphics.FromImage(cpuGraph);
    331 
    332                         g.SmoothingMode = SmoothingMode.AntiAlias;
    333 
    334                         g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
    335                         Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);
    336                         for (int y = 0; y < 100; y += 10)
    337                         {
    338                                 g.DrawLine(pen, 0, y, 300, y);
    339                         }
    340                         g.DrawLine(Pens.Gray, 0, 50, 300, 50);
    341 
    342                         int count = cpuStats.Count;
    343 
    344                         if (count >= 2)
    345                         {
    346                                 Point[] userGraph = new Point[count+2];
    347                                 Point[] sysGraph = new Point[count+2];
    348 
    349                                 userGraph[count+0].X = 300 - (count-1) * 5;
    350                                 userGraph[count+0].Y = 100 - 0;
    351                                 userGraph[count+1].X = 300 - 0 * 5;
    352                                 userGraph[count+1].Y = 100 - 0;
    353 
    354                                 sysGraph[count+0].X = 300 - (count-1) * 5;
    355                                 sysGraph[count+0].Y = 100 - 0;
    356                                 sysGraph[count+1].X = 300 - 0 * 5;
    357                                 sysGraph[count+1].Y = 100 - 0;
    358 
    359                                 for (int i = 0; i < count; i++)
    360                                 {
    361                                         CPUUsage usage = cpuStats[i];
    362                                         userGraph[i].X = sysGraph[i].X = 300 - i * 5;
    363                                         userGraph[i].Y = 100 - usage.Active;
    364                                         sysGraph[i].Y = 100 - usage.System;
    365                                 }
    366 
    367                                 g.FillPolygon(new SolidBrush(Color.FromArgb(50, 0, 0, 255)), userGraph);
    368                                 g.DrawPolygon(new Pen(Color.FromArgb(0, 0, 255), 1F), userGraph);
    369                                 g.FillPolygon(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), sysGraph);
    370                         }
    371 
    372                         g.Dispose();
    373                 }
    374 
    375                 private void drawMemoryGraph()
    376                 {
    377                         Graphics g = Graphics.FromImage(memoryGraph);
    378 
    379                         int totalMemory = (int)memStats.TotalVisibleMemorySize * 1024;
    380                         double rate = 100.0 / memStats.CommitLimit;
    381                         int border = (int)(totalMemory * rate);
    382 
    383                         g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
    384                         Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);
    385                         for (int y = 100; y > 0; y -= (int)(128*1024*1024 * rate))
    386                         {
    387                                 g.DrawLine(pen, 0, y, 300, y);
    388                         }
    389 
    390                         g.SmoothingMode = SmoothingMode.None;
    391                         Brush availableBrush = new SolidBrush(Color.FromArgb(180, 100, 100, 255));
    392                         Brush kernelBrush = new SolidBrush(Color.FromArgb(180, 255, 0, 0));
    393                         Brush commitedBrush = new SolidBrush(Color.FromArgb(180, 255, 145, 0));
    394                         Brush systemCacheBrush = new SolidBrush(Color.FromArgb(50, 255, 0, 0));
    395 //                      Brush spaceBrush = new SolidBrush(Color.FromArgb(180, 240, 230, 255));
    396                         Brush spaceBrush = new SolidBrush(Color.FromArgb(100, 100, 100, 255));
    397 
    398                         int count = memStats.Count;
    399 
    400                         for (int i = 0; i < count; i++)
    401                         {
    402                                 MemoryUsage usage = memStats[i];
    403 
    404                                 int x = 300 - i * 5 - 5;
    405                                 int y = 100;
    406                                 int w = 5;
    407                                 int h = 0;
    408 
    409                                 int kernelTotal = usage.KernelNonPaged + usage.KernelPaged + usage.DriverTotal + usage.SystemCodeTotal;
    410                                 h = (int)((kernelTotal) * rate);
    411                                 y -= h;
    412                                 g.FillRectangle(kernelBrush, x, y, w, h);
    413 
    414                                 h = (int)(usage.SystemCache * rate);
    415                                 y -= h;
    416                                 g.FillRectangle(systemCacheBrush, x, y, w, h);
    417 
    418                                 h = (int)(usage.Committed * rate);
    419                                 y -= h;
    420                                 g.FillRectangle(commitedBrush, x, y, w, h);
    421 
    422                                 h = (int)(usage.Available * rate);
    423                                 y -= h;
    424                                 g.FillRectangle(availableBrush, x, y, w, h);
    425 
    426                                 h = y;
    427                                 y = 0;
    428                                 g.FillRectangle(spaceBrush, x, y, w, h);
    429 
    430 
    431                                 x = 300 - i * 5 - 5;
    432                                 w = 2;
    433                                 h = (int)(usage.Pagein);
    434                                 y = 100 - h;
    435                                 g.FillRectangle(Brushes.LightGray, x, y, w, h);
    436 
    437                                 x = 303 - i * 5 - 5;
    438                                 w = 2;
    439                                 h = (int)(usage.Pageout);
    440                                 y = 100 - h;
    441                                 g.FillRectangle(Brushes.Black, x, y, w, h);
    442                         }
    443                         Pen borderPen = new Pen(Color.Blue);
    444                         borderPen.DashStyle = DashStyle.Dash;
    445                         g.DrawLine(borderPen, 0, 100-border, 300, 100-border);
    446 
    447                         g.Dispose();
    448                 }
    449 
    450298                private void patternWindow_Closed(object sender, EventArgs e)
    451299                {
     
    456304                private void statusWindow_Closed(object sender, EventArgs e)
    457305                {
    458                         cpuGraph.Dispose();
    459                         cpuGraph = null;
    460                         memoryGraph.Dispose();
    461                         memoryGraph = null;
    462306                        statusWindow.Dispose();
    463307                        statusWindow = null;
  • trunk/MacFaceFloat/StatusWindow.cs

    r58 r62  
    11using System;
    22using System.Drawing;
     3using System.Drawing.Drawing2D;
    34using System.Collections;
    45using System.ComponentModel;
     
    1920                private System.ComponentModel.Container components = null;
    2021
    21                 public StatusWindow()
     22                private CPUStatistics cpuStats;
     23                private MemoryStatistics memStats;
     24
     25                private Bitmap cpuGraph;
     26                private Bitmap memoryGraph;
     27
     28                public StatusWindow(CPUStatistics cpuStats, MemoryStatistics memStats)
    2229                {
    2330                        //
     
    2633                        InitializeComponent();
    2734
    28                         //
    29                         // TODO: InitializeComponent ŒÄ‚яo‚µ‚ÌŒã‚ɁAƒRƒ“ƒXƒgƒ‰ƒNƒ^ ƒR[ƒh‚ð’ljÁ‚µ‚Ä‚­‚¾‚³‚¢B
    30                         //
     35                        this.cpuStats = cpuStats;
     36                        this.memStats = memStats;
     37
     38                        cpuGraph = new Bitmap(5*60, 100);
     39                        memoryGraph = new Bitmap(5*60, 100);
     40                        cpuGraphPicBox.Image = cpuGraph;
     41                        memoryGraphPicBox.Image = memoryGraph;
    3142                }
    3243
     
    4051                                if(components != null)
    4152                                {
     53                                        cpuGraph.Dispose();
     54                                        memoryGraph.Dispose();
    4255                                        components.Dispose();
    4356                                }
    4457                        }
    4558                        base.Dispose( disposing );
     59                }
     60
     61                public void UpdateGraph()
     62                {
     63                        drawCPUGraph();
     64                        drawMemoryGraph();
     65                        cpuGraphPicBox.Invalidate();
     66                        memoryGraphPicBox.Invalidate();
     67                }
     68
     69                private void drawCPUGraph()
     70                {
     71                        Graphics g = Graphics.FromImage(cpuGraph);
     72
     73                        g.SmoothingMode = SmoothingMode.AntiAlias;
     74
     75                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
     76                        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);
     82
     83                        int count = cpuStats.Count;
     84
     85                        if (count >= 2)
     86                        {
     87                                Point[] userGraph = new Point[count+2];
     88                                Point[] sysGraph = new Point[count+2];
     89
     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;
     99
     100                                for (int i = 0; i < count; i++)
     101                                {
     102                                        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;
     106                                }
     107
     108                                g.FillPolygon(new SolidBrush(Color.FromArgb(50, 0, 0, 255)), userGraph);
     109                                g.DrawPolygon(new Pen(Color.FromArgb(0, 0, 255), 1F), userGraph);
     110                                g.FillPolygon(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), sysGraph);
     111                        }
     112
     113                        g.Dispose();
     114                }
     115
     116                private void drawMemoryGraph()
     117                {
     118                        Graphics g = Graphics.FromImage(memoryGraph);
     119
     120                        int totalMemory = (int)memStats.TotalVisibleMemorySize * 1024;
     121                        double rate = 100.0 / memStats.CommitLimit;
     122                        int border = (int)(totalMemory * rate);
     123
     124                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
     125                        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);
     129                        }
     130
     131                        g.SmoothingMode = SmoothingMode.None;
     132                        Brush availableBrush = new SolidBrush(Color.FromArgb(180, 100, 100, 255));
     133                        Brush kernelBrush = new SolidBrush(Color.FromArgb(180, 255, 0, 0));
     134                        Brush commitedBrush = new SolidBrush(Color.FromArgb(180, 255, 145, 0));
     135                        Brush systemCacheBrush = new SolidBrush(Color.FromArgb(50, 255, 0, 0));
     136                        //                      Brush spaceBrush = new SolidBrush(Color.FromArgb(180, 240, 230, 255));
     137                        Brush spaceBrush = new SolidBrush(Color.FromArgb(100, 100, 100, 255));
     138
     139                        int count = memStats.Count;
     140
     141                        for (int i = 0; i < count; i++)
     142                        {
     143                                MemoryUsage usage = memStats[i];
     144
     145                                int x = 300 - i * 5 - 5;
     146                                int y = 100;
     147                                int w = 5;
     148                                int h = 0;
     149
     150                                int kernelTotal = usage.KernelNonPaged + usage.KernelPaged + usage.DriverTotal + usage.SystemCodeTotal;
     151                                h = (int)((kernelTotal) * rate);
     152                                y -= h;
     153                                g.FillRectangle(kernelBrush, x, y, w, h);
     154
     155                                h = (int)(usage.SystemCache * rate);
     156                                y -= h;
     157                                g.FillRectangle(systemCacheBrush, x, y, w, h);
     158
     159                                h = (int)(usage.Committed * rate);
     160                                y -= h;
     161                                g.FillRectangle(commitedBrush, x, y, w, h);
     162
     163                                h = (int)(usage.Available * rate);
     164                                y -= h;
     165                                g.FillRectangle(availableBrush, x, y, w, h);
     166
     167                                h = y;
     168                                y = 0;
     169                                g.FillRectangle(spaceBrush, x, y, w, h);
     170
     171
     172                                x = 300 - i * 5 - 5;
     173                                w = 2;
     174                                h = (int)(usage.Pagein);
     175                                y = 100 - h;
     176                                g.FillRectangle(Brushes.LightGray, x, y, w, h);
     177
     178                                x = 303 - i * 5 - 5;
     179                                w = 2;
     180                                h = (int)(usage.Pageout);
     181                                y = 100 - h;
     182                                g.FillRectangle(Brushes.Black, x, y, w, h);
     183                        }
     184                        Pen borderPen = new Pen(Color.Blue);
     185                        borderPen.DashStyle = DashStyle.Dash;
     186                        g.DrawLine(borderPen, 0, 100-border, 300, 100-border);
     187
     188                        g.Dispose();
    46189                }
    47190
     
    82225                        this.Controls.Add(this.cpuGraphPicBox);
    83226                        this.Controls.Add(this.memoryGraphPicBox);
    84                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
     227                        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    85228                        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
    86229                        this.MaximizeBox = false;
  • trunk/MacFaceFloat/StatusWindow.resx

    r55 r62  
    122122    <value>(Default)</value>
    123123  </data>
     124  <data name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     125    <value>False</value>
     126  </data>
    124127  <data name="$this.Name">
    125128    <value>StatusWindow</value>
     
    142145  <data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    143146    <value>Private</value>
    144   </data>
    145   <data name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    146     <value>False</value>
    147147  </data>
    148148  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
Note: See TracChangeset for help on using the changeset viewer.