Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MainForm.cs

    r30 r20  
    2121        public class MainForm : Misuzilla.Windows.Forms.AlphaForm
    2222        {
    23                 private System.Windows.Forms.NotifyIcon notifyIcon;
    2423                private System.Windows.Forms.ContextMenu contextMenu;
    2524                private System.Windows.Forms.MenuItem menuItemPatternSelect;
     
    3130                private FaceDef _currentFaceDef;
    3231                private Configuration _config;
    33                 private float _patternSize;
    34 
    35                 private int prevPattern;
    36                 private FaceDef.PatternSuite prevSuite;
    37                 private int prevMarkers;
    38 
    39                 private CPUUsageCounter cpuCounter;
    40                 private MemoryUsageCounter memoryCounter;
     32               
     33                Int32 prevUsage;
     34                PerformanceCounter cpuCount;
     35                PerformanceCounter pageoutCount;
     36                PerformanceCounter pageinCount;
    4137
    4238                // ƒRƒ“ƒXƒgƒ‰ƒNƒ^
     
    4743                        this.MoveAtFormDrag = true;
    4844
    49                         prevPattern = -1;
    50                         prevSuite   = FaceDef.PatternSuite.Normal;
    51                         prevMarkers = -1;
    52 
    53                         cpuCounter = new CPUUsageCounter();
    54                         memoryCounter = new MemoryUsageCounter();
     45                        prevUsage = -10;
     46
     47                        cpuCount = new PerformanceCounter();
     48                        cpuCount.CategoryName = "Processor";
     49                        cpuCount.CounterName  = "% Processor Time";
     50                        cpuCount.InstanceName = "_Total";
     51
     52                        pageoutCount = new PerformanceCounter();
     53                        pageoutCount.CategoryName = "Memory";
     54                        pageoutCount.CounterName  = "Pages Output/sec";
     55
     56                        pageinCount = new PerformanceCounter();
     57                        pageinCount.CategoryName = "Memory";
     58                        pageinCount.CounterName  = "Pages Input/sec";
    5559
    5660                        _updateTimer = new System.Windows.Forms.Timer();
     
    6165
    6266                void InitializeComponent() {
    63                         this.notifyIcon = new System.Windows.Forms.NotifyIcon();
    6467                        this.menuItemPatternSelect = new System.Windows.Forms.MenuItem();
    6568                        this.menuItemConfigure = new System.Windows.Forms.MenuItem();
    6669                        this.menuItemExit = new System.Windows.Forms.MenuItem();
    6770                        this.contextMenu = new System.Windows.Forms.ContextMenu();
    68 
    69                         //
    70                         // notifyIcon
    71                         //
    72                         this.notifyIcon.Text = "MacFace";
    73                         this.notifyIcon.Icon = this.Icon;
    74                         this.notifyIcon.Visible = true;
    75                         this.notifyIcon.ContextMenu = this.contextMenu;
    76 
    7771                        //
    7872                        // menuItemPatternSelect
     
    195189                        _currentFaceDef = newFaceDef;
    196190                        _facePath = _currentFaceDef.Path;
    197                         notifyIcon.Text = "MacFace - " + _currentFaceDef.Title;
    198                         prevPattern = -1;
    199                         prevMarkers = -1;
     191                        prevUsage = -10;
    200192
    201193                        // XVÄŠJ
     
    207199                public void CountProcessorUsage(object sender, EventArgs e)
    208200                {
    209                         CPUUsage cpuUsage = cpuCounter.CurrentUsage();
    210                         MemoryUsage memUsage = memoryCounter.CurrentUsage();
    211 
    212                         int pattern = cpuUsage.Active / 10;
    213 
    214                         FaceDef.PatternSuite suite = FaceDef.PatternSuite.Normal;
    215                         if (memUsage.Available < (10 * 1024 *1024))
    216                         {
    217                                 suite = FaceDef.PatternSuite.MemoryInsufficient;
    218                         }
    219                         else if (memUsage.Available < (30 * 1024 *1024))
    220                         {
    221                                 suite = FaceDef.PatternSuite.MemoryDecline;
     201                        int usage = (int)cpuCount.NextValue();
     202                        int pagein = (int)pageinCount.NextValue();
     203                        int pageout = (int)pageoutCount.NextValue();
     204
     205                        usage /= 10;
     206                        if (usage > 10) {
     207                                usage = 10;
     208                        } else if (usage < 0) {
     209                                usage = 0;
    222210                        }
    223211
    224212                        int markers = FaceDef.MarkerNone;
    225                         if (memUsage.Pagein > 0) markers += FaceDef.MarkerPageIn;
    226                         if (memUsage.Pageout > 0) markers += FaceDef.MarkerPageOut;
    227 
    228                         if (prevPattern != pattern || prevSuite != suite || prevMarkers != markers)
     213                        if (pagein > 0) markers += FaceDef.MarkerPageIn;
     214                        if (pageout > 0) markers += FaceDef.MarkerPageOut;
     215
     216                        if (prevUsage != usage)
    229217                        {
    230218                                Graphics g = this.Graphics;
    231219                                g.Clear(Color.FromArgb(0, 0, 0, 0));
    232                                 _currentFaceDef.DrawPatternImage(g, suite, pattern, markers, _patternSize);
     220                                _currentFaceDef.DrawPatternImage(g, FaceDef.PatternSuite.Normal, usage, markers);
    233221                                this.Update();
    234222                        }
    235223                               
    236                         prevPattern = pattern;
    237                         prevSuite   = suite;
    238                         prevMarkers = markers;
    239                 }
    240 
    241                 public float PatternSize
    242                 {
    243                         get { return _patternSize; }
    244                         set { _patternSize = value; }
    245                 }
     224                        prevUsage = usage;                     
     225                }
     226               
    246227
    247228                //
     
    279260                private void MainForm_Closing(object sender, CancelEventArgs e)
    280261                {
    281                         notifyIcon.Visible = false;
    282 
    283262                        // •Û‘¶
    284263                        _config.Opacity = (int) (this.Opacity * 100);
     
    318297                {
    319298                        this.Opacity = (float)_config.Opacity / 100;
    320                         this.PatternSize = (float)_config.PatternSize / 100;
    321299                        this.Location = _config.Location;
    322300                        this.TransparentMouseMessage = _config.TransparentMouseMessage;
Note: See TracChangeset for help on using the changeset viewer.