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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.