Changeset 62
- Timestamp:
- Sep 9, 2005, 2:46:06 AM (19 years ago)
- Location:
- trunk/MacFaceFloat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceFloat/MacFaceApp.cs
r61 r62 10 10 using System.Windows.Forms; 11 11 using System.Drawing; 12 using System.Drawing.Drawing2D;13 12 using System.Data; 14 13 using System.IO; … … 25 24 private Configuration config; 26 25 26 private CPUStatistics cpuStats; 27 private MemoryStatistics memStats; 28 29 private System.Windows.Forms.Timer updateTimer; 30 27 31 private NotifyIcon notifyIcon; 28 32 private PatternWindow patternWindow; 33 private StatusWindow statusWindow; 29 34 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 39 35 [STAThread] 40 36 public static void Main(string[] args) … … 58 54 59 55 patternWindow = null; 60 61 cpuGraph = null;62 memoryGraph = null;63 56 statusWindow = null; 64 57 … … 219 212 if (statusWindow != null) 220 213 { 221 drawCPUGraph(); 222 drawMemoryGraph(); 223 statusWindow.cpuGraphPicBox.Invalidate(); 224 statusWindow.memoryGraphPicBox.Invalidate(); 214 statusWindow.UpdateGraph(); 225 215 } 226 216 } … … 245 235 public void openStatusWindow() 246 236 { 247 statusWindow = new StatusWindow( );237 statusWindow = new StatusWindow(cpuStats, memStats); 248 238 statusWindow.Closed += new EventHandler(statusWindow_Closed); 249 239 statusWindow.Move +=new EventHandler(statusWindow_Move); 250 240 251 FormBorderStyle orgStyle = statusWindow.FormBorderStyle;252 statusWindow.FormBorderStyle = FormBorderStyle.Sizable;253 241 statusWindow.StartPosition = FormStartPosition.Manual; 254 242 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(); 264 245 statusWindow.Show(); 265 246 } … … 315 296 } 316 297 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 450 298 private void patternWindow_Closed(object sender, EventArgs e) 451 299 { … … 456 304 private void statusWindow_Closed(object sender, EventArgs e) 457 305 { 458 cpuGraph.Dispose();459 cpuGraph = null;460 memoryGraph.Dispose();461 memoryGraph = null;462 306 statusWindow.Dispose(); 463 307 statusWindow = null; -
trunk/MacFaceFloat/StatusWindow.cs
r58 r62 1 1 using System; 2 2 using System.Drawing; 3 using System.Drawing.Drawing2D; 3 4 using System.Collections; 4 5 using System.ComponentModel; … … 19 20 private System.ComponentModel.Container components = null; 20 21 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) 22 29 { 23 30 // … … 26 33 InitializeComponent(); 27 34 28 // 29 // TODO: InitializeComponent ÄÑoµÌãÉARXgN^ R[hðÇÁµÄ¾³¢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; 31 42 } 32 43 … … 40 51 if(components != null) 41 52 { 53 cpuGraph.Dispose(); 54 memoryGraph.Dispose(); 42 55 components.Dispose(); 43 56 } 44 57 } 45 58 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(); 46 189 } 47 190 … … 82 225 this.Controls.Add(this.cpuGraphPicBox); 83 226 this.Controls.Add(this.memoryGraphPicBox); 84 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed ToolWindow;227 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 85 228 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 86 229 this.MaximizeBox = false; -
trunk/MacFaceFloat/StatusWindow.resx
r55 r62 122 122 <value>(Default)</value> 123 123 </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> 124 127 <data name="$this.Name"> 125 128 <value>StatusWindow</value> … … 142 145 <data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 143 146 <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>147 147 </data> 148 148 <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.