Changeset 52

Show
Ignore:
Timestamp:
03/31/05 21:22:21 (4 years ago)
Author:
altba\rryu
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MacFaceFloat/MacFaceApp.cs

    r51 r52  
    3333 
    3434                private Form statusWindow; 
     35                private Bitmap cpuGraph; 
     36                private Bitmap memoryGraph; 
    3537 
    3638                private CPUUsage[] cpuHistory; 
     
    105107                        this.patternWindow = new PatternWindow(); 
    106108 
    107                         // �X�e�[�^�X�E�C���h�E          
     109                        // �X�e�[�^�X�E�C���h�E 
     110                        cpuGraph = new Bitmap(5*60, 100); 
     111                        memoryGraph = new Bitmap(5*60, 100); 
     112 
    108113                        statusWindow = new Form(); 
    109114                        statusWindow.ClientSize = new System.Drawing.Size(310, 215); 
     
    133138                        } 
    134139 
     140                        drawCPUGraph(); 
     141                        drawMemoryGraph(); 
    135142                        statusWindow.Show(); 
    136143 
     
    268275                        patternWindow.UpdatePattern(suite, pattern, markers); 
    269276 
     277                        drawCPUGraph(); 
     278                        drawMemoryGraph(); 
    270279                        statusWindow.Invalidate(); 
    271280                } 
     
    314323                { 
    315324                        Graphics g = e.Graphics; 
     325 
     326                        g.DrawImage(cpuGraph, 5,5); 
     327                        g.DrawRectangle(Pens.Black, 4, 4, 301, 101); 
     328 
     329                        g.DrawImage(memoryGraph, 5,110); 
     330                        g.DrawRectangle(Pens.Black, 4, 109, 301, 101); 
     331                } 
     332 
     333                private void drawCPUGraph() 
     334                { 
     335                        Graphics g = Graphics.FromImage(cpuGraph); 
     336 
    316337                        g.SmoothingMode = SmoothingMode.AntiAlias; 
    317338 
    318                         g.FillRectangle(new SolidBrush(Color.White), 5, 5, 300, 100); 
     339                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100); 
    319340                        Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F); 
    320                         for (int y = 5; y < 105; y += 10)  
    321                         { 
    322                                 g.DrawLine(pen, 5, y, 305, y); 
    323                         } 
    324                         g.DrawLine(Pens.Gray, 5, 55, 305, 55); 
    325  
    326                         g.DrawRectangle(Pens.Black, 4, 4, 301, 101); 
    327  
    328                         g.FillRectangle(new SolidBrush(Color.White), 5, 110, 300, 100); 
    329                         for (int y = 210; y > 110; y -= 7)  
    330                         { 
    331                                 g.DrawLine(pen, 5, y, 305, y); 
    332                         } 
    333                         g.DrawLine(Pens.Gray, 5, 210-5*7, 305, 210-5*7); 
    334                         g.DrawRectangle(Pens.Black, 4, 109, 301, 101); 
    335  
     341                        for (int y = 0; y < 100; y += 10)  
     342                        { 
     343                                g.DrawLine(pen, 0, y, 300, y); 
     344                        } 
     345                        g.DrawLine(Pens.Gray, 0, 50, 300, 50); 
    336346 
    337347                        if (cpuHistoryCount >= 2)  
     
    340350                                Point[] sysGraph = new Point[cpuHistoryCount+2]; 
    341351 
    342                                 userGraph[cpuHistoryCount+0].X = 305 - cpuHistoryCount * 5; 
    343                                 userGraph[cpuHistoryCount+0].Y = 105 - 0; 
    344                                 userGraph[cpuHistoryCount+1].X = 305 - 0 * 5; 
    345                                 userGraph[cpuHistoryCount+1].Y = 105 - 0; 
    346  
    347                                 sysGraph[cpuHistoryCount+0].X = 305 - cpuHistoryCount * 5; 
    348                                 sysGraph[cpuHistoryCount+0].Y = 105 - 0; 
    349                                 sysGraph[cpuHistoryCount+1].X = 305 - 0 * 5; 
    350                                 sysGraph[cpuHistoryCount+1].Y = 105 - 0; 
     352                                userGraph[cpuHistoryCount+0].X = 300 - (cpuHistoryCount-1) * 5; 
     353                                userGraph[cpuHistoryCount+0].Y = 100 - 0; 
     354                                userGraph[cpuHistoryCount+1].X = 300 - 0 * 5; 
     355                                userGraph[cpuHistoryCount+1].Y = 100 - 0; 
     356 
     357                                sysGraph[cpuHistoryCount+0].X = 300 - (cpuHistoryCount-1) * 5; 
     358                                sysGraph[cpuHistoryCount+0].Y = 100 - 0; 
     359                                sysGraph[cpuHistoryCount+1].X = 300 - 0 * 5; 
     360                                sysGraph[cpuHistoryCount+1].Y = 100 - 0; 
    351361 
    352362                                int pos = cpuHistoryHead - 1; 
     
    355365                                        if (pos < 0) pos = cpuHistory.Length - 1; 
    356366                                        CPUUsage usage = cpuHistory[pos]; 
    357                                         userGraph[i].X = sysGraph[i].X = 305 - i * 5; 
    358                                         userGraph[i].Y = 105 - usage.Active; 
    359                                         sysGraph[i].Y = 105 - usage.System; 
     367                                        userGraph[i].X = sysGraph[i].X = 300 - i * 5; 
     368                                        userGraph[i].Y = 100 - usage.Active; 
     369                                        sysGraph[i].Y = 100 - usage.System; 
    360370                                        pos--; 
    361371                                } 
     
    365375                                g.FillPolygon(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), sysGraph); 
    366376                        } 
     377 
     378                        g.Dispose(); 
     379                } 
     380 
     381                private void drawMemoryGraph() 
     382                { 
     383                        Graphics g = Graphics.FromImage(memoryGraph); 
     384 
     385                        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 300, 100); 
     386                        Pen pen = new Pen(Color.FromArgb(220, 220, 220), 1F); 
     387                        for (int y = 100; y > 0; y -= 7)  
     388                        { 
     389                                g.DrawLine(pen, 0, y, 300, y); 
     390                        } 
     391                        g.DrawLine(Pens.Gray, 0, 100-5*7, 300, 100-5*7); 
    367392 
    368393                        int totalMemory = (int)MemoryUsageCounter.TotalVisibleMemorySize * 1024; 
     
    373398                        Brush uncommitedBrush = new SolidBrush(Color.FromArgb(180, 180, 200, 255)); 
    374399                        Brush availableBrush = new SolidBrush(Color.FromArgb(180, 100, 100, 255)); 
    375  
    376                         int posu = memHistoryHead - 1; 
     400                        Brush spaceBrush = new SolidBrush(Color.FromArgb(180, 255, 255, 100)); 
     401 
     402                        int pos = memHistoryHead - 1; 
    377403                        for (int i = 0; i < memHistoryCount; i++)  
    378404                        { 
    379                                 if (posu < 0) posu = memHistory.Length - 1; 
    380                                 MemoryUsage usage = memHistory[posu]; 
     405                                if (pos < 0) pos = memHistory.Length - 1; 
     406                                MemoryUsage usage = memHistory[pos]; 
    381407 
    382408                                int x, y, w, h; 
    383409 
    384                                 x = 305 - i * 5 - 5; 
     410                                x = 300 - i * 5 - 5; 
    385411                                w = 5; 
    386412 
     413                                h = 30; 
     414                                y = 0; 
     415                                g.FillRectangle(spaceBrush, x, y, w, h); 
     416 
    387417                                h = (int)(usage.Committed * rate); 
    388                                 y = 210 - h; 
     418                                y = 100 - h; 
    389419                                g.FillRectangle(commitedBrush, x, y, w, h); 
    390420 
    391                                 if (h < 100)  
    392                                 { 
    393                                         h = 100 - h; 
    394                                         y = 110; 
     421                                if (h < 70)  
     422                                { 
     423                                        h = 70 - h; 
     424                                        y = 30; 
    395425                                        g.FillRectangle(uncommitedBrush, x, y, w, h); 
    396426                                } 
    397427 
    398428                                h = (int)(usage.Available * rate); 
    399                                 y = 210-70; 
     429                                y = 100-70; 
    400430                                g.FillRectangle(availableBrush, x, y, w, h); 
    401431 
    402                                 x = 305 - i * 5 - 5; 
     432                                x = 300 - i * 5 - 5; 
    403433                                w = 2; 
    404434                                h = (int)(usage.Pagein); 
    405                                 y = 210 - h; 
     435                                y = 100 - h; 
    406436                                g.FillRectangle(Brushes.LightGray, x, y, w, h); 
    407437 
    408                                 x = 308 - i * 5 - 5; 
     438                                x = 303 - i * 5 - 5; 
    409439                                w = 2; 
    410440                                h = (int)(usage.Pageout); 
    411                                 y = 210 - h; 
     441                                y = 100 - h; 
    412442                                g.FillRectangle(Brushes.Black, x, y, w, h); 
    413443 
    414                                 posu--; 
    415                         } 
    416                         g.DrawLine(Pens.Black, 5, 210-70, 305, 210-70); 
     444                                pos--; 
     445                        } 
     446                        g.DrawLine(Pens.Black, 0, 100-70, 300, 100-70); 
     447 
     448                        g.Dispose(); 
    417449                } 
    418450        }