Changeset 62 for trunk/MacFaceFloat/MacFaceApp.cs
- Timestamp:
- Sep 9, 2005, 2:46:06 AM (19 years ago)
- File:
-
- 1 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;
Note: See TracChangeset
for help on using the changeset viewer.