Changeset 52


Ignore:
Timestamp:
Mar 31, 2005, 9:22:21 PM (19 years ago)
Author:
altba\rryu
Message:

Paintイベントを長々と処理していると、なんだか他のウインドウへもPaintイベントが飛ぶようで、画面中再描画の嵐になってとても使っていられないので、てきとーにダブルバッファリングするようにしてみた。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MacFaceApp.cs

    r51 r52  
    3333
    3434                private Form statusWindow;
     35                private Bitmap cpuGraph;
     36                private Bitmap memoryGraph;
    3537
    3638                private CPUUsage[] cpuHistory;
     
    106108                        this.patternWindow = new PatternWindow();
    107109
    108                         // ƒXƒe[ƒ^ƒXƒEƒCƒ“ƒhƒE         
     110                        // ƒXƒe[ƒ^ƒXƒEƒCƒ“ƒhƒE
     111                        cpuGraph = new Bitmap(5*60, 100);
     112                        memoryGraph = new Bitmap(5*60, 100);
     113
    109114                        statusWindow = new Form();
    110115                        statusWindow.ClientSize = new System.Drawing.Size(310, 215);
     
    134139                        }
    135140
     141                        drawCPUGraph();
     142                        drawMemoryGraph();
    136143                        statusWindow.Show();
    137144
     
    270277                        patternWindow.UpdatePattern(suite, pattern, markers);
    271278
     279                        drawCPUGraph();
     280                        drawMemoryGraph();
    272281                        statusWindow.Invalidate();
    273282                }
     
    317326                {
    318327                        Graphics g = e.Graphics;
     328
     329                        g.DrawImage(cpuGraph, 5,5);
     330                        g.DrawRectangle(Pens.Black, 4, 4, 301, 101);
     331
     332                        g.DrawImage(memoryGraph, 5,110);
     333                        g.DrawRectangle(Pens.Black, 4, 109, 301, 101);
     334                }
     335
     336                private void drawCPUGraph()
     337                {
     338                        Graphics g = Graphics.FromImage(cpuGraph);
     339
    319340                        g.SmoothingMode = SmoothingMode.AntiAlias;
    320341
    321                         g.FillRectangle(new SolidBrush(Color.White), 5, 5, 300, 100);
     342                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
    322343                        Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);
    323                         for (int y = 5; y < 105; y += 10)
    324                         {
    325                                 g.DrawLine(pen, 5, y, 305, y);
    326                         }
    327                         g.DrawLine(Pens.Gray, 5, 55, 305, 55);
    328 
    329                         g.DrawRectangle(Pens.Black, 4, 4, 301, 101);
    330 
    331                         g.FillRectangle(new SolidBrush(Color.White), 5, 110, 300, 100);
    332                         for (int y = 210; y > 110; y -= 7)
    333                         {
    334                                 g.DrawLine(pen, 5, y, 305, y);
    335                         }
    336                         g.DrawLine(Pens.Gray, 5, 210-5*7, 305, 210-5*7);
    337                         g.DrawRectangle(Pens.Black, 4, 109, 301, 101);
    338 
     344                        for (int y = 0; y < 100; y += 10)
     345                        {
     346                                g.DrawLine(pen, 0, y, 300, y);
     347                        }
     348                        g.DrawLine(Pens.Gray, 0, 50, 300, 50);
    339349
    340350                        if (cpuHistoryCount >= 2)
     
    343353                                Point[] sysGraph = new Point[cpuHistoryCount+2];
    344354
    345                                 userGraph[cpuHistoryCount+0].X = 305 - cpuHistoryCount * 5;
    346                                 userGraph[cpuHistoryCount+0].Y = 105 - 0;
    347                                 userGraph[cpuHistoryCount+1].X = 305 - 0 * 5;
    348                                 userGraph[cpuHistoryCount+1].Y = 105 - 0;
    349 
    350                                 sysGraph[cpuHistoryCount+0].X = 305 - cpuHistoryCount * 5;
    351                                 sysGraph[cpuHistoryCount+0].Y = 105 - 0;
    352                                 sysGraph[cpuHistoryCount+1].X = 305 - 0 * 5;
    353                                 sysGraph[cpuHistoryCount+1].Y = 105 - 0;
     355                                userGraph[cpuHistoryCount+0].X = 300 - (cpuHistoryCount-1) * 5;
     356                                userGraph[cpuHistoryCount+0].Y = 100 - 0;
     357                                userGraph[cpuHistoryCount+1].X = 300 - 0 * 5;
     358                                userGraph[cpuHistoryCount+1].Y = 100 - 0;
     359
     360                                sysGraph[cpuHistoryCount+0].X = 300 - (cpuHistoryCount-1) * 5;
     361                                sysGraph[cpuHistoryCount+0].Y = 100 - 0;
     362                                sysGraph[cpuHistoryCount+1].X = 300 - 0 * 5;
     363                                sysGraph[cpuHistoryCount+1].Y = 100 - 0;
    354364
    355365                                int pos = cpuHistoryHead - 1;
     
    358368                                        if (pos < 0) pos = cpuHistory.Length - 1;
    359369                                        CPUUsage usage = cpuHistory[pos];
    360                                         userGraph[i].X = sysGraph[i].X = 305 - i * 5;
    361                                         userGraph[i].Y = 105 - usage.Active;
    362                                         sysGraph[i].Y = 105 - usage.System;
     370                                        userGraph[i].X = sysGraph[i].X = 300 - i * 5;
     371                                        userGraph[i].Y = 100 - usage.Active;
     372                                        sysGraph[i].Y = 100 - usage.System;
    363373                                        pos--;
    364374                                }
     
    368378                                g.FillPolygon(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), sysGraph);
    369379                        }
     380
     381                        g.Dispose();
     382                }
     383
     384                private void drawMemoryGraph()
     385                {
     386                        Graphics g = Graphics.FromImage(memoryGraph);
     387
     388                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100);
     389                        Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F);
     390                        for (int y = 100; y > 0; y -= 7)
     391                        {
     392                                g.DrawLine(pen, 0, y, 300, y);
     393                        }
     394                        g.DrawLine(Pens.Gray, 0, 100-5*7, 300, 100-5*7);
    370395
    371396                        int totalMemory = (int)MemoryUsageCounter.TotalVisibleMemorySize * 1024;
     
    376401                        Brush uncommitedBrush = new SolidBrush(Color.FromArgb(180, 180, 200, 255));
    377402                        Brush availableBrush = new SolidBrush(Color.FromArgb(180, 100, 100, 255));
    378 
    379                         int posu = memHistoryHead - 1;
     403                        Brush spaceBrush = new SolidBrush(Color.FromArgb(180, 255, 255, 100));
     404
     405                        int pos = memHistoryHead - 1;
    380406                        for (int i = 0; i < memHistoryCount; i++)
    381407                        {
    382                                 if (posu < 0) posu = memHistory.Length - 1;
    383                                 MemoryUsage usage = memHistory[posu];
     408                                if (pos < 0) pos = memHistory.Length - 1;
     409                                MemoryUsage usage = memHistory[pos];
    384410
    385411                                int x, y, w, h;
    386412
    387                                 x = 305 - i * 5 - 5;
     413                                x = 300 - i * 5 - 5;
    388414                                w = 5;
    389415
     416                                h = 30;
     417                                y = 0;
     418                                g.FillRectangle(spaceBrush, x, y, w, h);
     419
    390420                                h = (int)(usage.Committed * rate);
    391                                 y = 210 - h;
     421                                y = 100 - h;
    392422                                g.FillRectangle(commitedBrush, x, y, w, h);
    393423
    394                                 if (h < 100)
    395                                 {
    396                                         h = 100 - h;
    397                                         y = 110;
     424                                if (h < 70)
     425                                {
     426                                        h = 70 - h;
     427                                        y = 30;
    398428                                        g.FillRectangle(uncommitedBrush, x, y, w, h);
    399429                                }
    400430
    401431                                h = (int)(usage.Available * rate);
    402                                 y = 210-70;
     432                                y = 100-70;
    403433                                g.FillRectangle(availableBrush, x, y, w, h);
    404434
    405                                 x = 305 - i * 5 - 5;
     435                                x = 300 - i * 5 - 5;
    406436                                w = 2;
    407437                                h = (int)(usage.Pagein);
    408                                 y = 210 - h;
     438                                y = 100 - h;
    409439                                g.FillRectangle(Brushes.LightGray, x, y, w, h);
    410440
    411                                 x = 308 - i * 5 - 5;
     441                                x = 303 - i * 5 - 5;
    412442                                w = 2;
    413443                                h = (int)(usage.Pageout);
    414                                 y = 210 - h;
     444                                y = 100 - h;
    415445                                g.FillRectangle(Brushes.Black, x, y, w, h);
    416446
    417                                 posu--;
    418                         }
    419                         g.DrawLine(Pens.Black, 5, 210-70, 305, 210-70);
     447                                pos--;
     448                        }
     449                        g.DrawLine(Pens.Black, 0, 100-70, 300, 100-70);
     450
     451                        g.Dispose();
    420452                }
    421453        }
Note: See TracChangeset for help on using the changeset viewer.