Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MainForm.cs

    r20 r30  
    2121        public class MainForm : Misuzilla.Windows.Forms.AlphaForm
    2222        {
     23                private System.Windows.Forms.NotifyIcon notifyIcon;
    2324                private System.Windows.Forms.ContextMenu contextMenu;
    2425                private System.Windows.Forms.MenuItem menuItemPatternSelect;
     
    3031                private FaceDef _currentFaceDef;
    3132                private Configuration _config;
    32                
    33                 Int32 prevUsage;
    34                 PerformanceCounter cpuCount;
    35                 PerformanceCounter pageoutCount;
    36                 PerformanceCounter pageinCount;
     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;
    3741
    3842                // ƒRƒ“ƒXƒgƒ‰ƒNƒ^
     
    4347                        this.MoveAtFormDrag = true;
    4448
    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";
     49                        prevPattern = -1;
     50                        prevSuite   = FaceDef.PatternSuite.Normal;
     51                        prevMarkers = -1;
     52
     53                        cpuCounter = new CPUUsageCounter();
     54                        memoryCounter = new MemoryUsageCounter();
    5955
    6056                        _updateTimer = new System.Windows.Forms.Timer();
     
    6561
    6662                void InitializeComponent() {
     63                        this.notifyIcon = new System.Windows.Forms.NotifyIcon();
    6764                        this.menuItemPatternSelect = new System.Windows.Forms.MenuItem();
    6865                        this.menuItemConfigure = new System.Windows.Forms.MenuItem();
    6966                        this.menuItemExit = new System.Windows.Forms.MenuItem();
    7067                        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
    7177                        //
    7278                        // menuItemPatternSelect
     
    189195                        _currentFaceDef = newFaceDef;
    190196                        _facePath = _currentFaceDef.Path;
    191                         prevUsage = -10;
     197                        notifyIcon.Text = "MacFace - " + _currentFaceDef.Title;
     198                        prevPattern = -1;
     199                        prevMarkers = -1;
    192200
    193201                        // XVÄŠJ
     
    199207                public void CountProcessorUsage(object sender, EventArgs e)
    200208                {
    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;
     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;
    210222                        }
    211223
    212224                        int markers = FaceDef.MarkerNone;
    213                         if (pagein > 0) markers += FaceDef.MarkerPageIn;
    214                         if (pageout > 0) markers += FaceDef.MarkerPageOut;
    215 
    216                         if (prevUsage != usage)
     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)
    217229                        {
    218230                                Graphics g = this.Graphics;
    219231                                g.Clear(Color.FromArgb(0, 0, 0, 0));
    220                                 _currentFaceDef.DrawPatternImage(g, FaceDef.PatternSuite.Normal, usage, markers);
     232                                _currentFaceDef.DrawPatternImage(g, suite, pattern, markers, _patternSize);
    221233                                this.Update();
    222234                        }
    223235                               
    224                         prevUsage = usage;                     
    225                 }
    226                
     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                }
    227246
    228247                //
     
    260279                private void MainForm_Closing(object sender, CancelEventArgs e)
    261280                {
     281                        notifyIcon.Visible = false;
     282
    262283                        // •Û‘¶
    263284                        _config.Opacity = (int) (this.Opacity * 100);
     
    297318                {
    298319                        this.Opacity = (float)_config.Opacity / 100;
     320                        this.PatternSize = (float)_config.PatternSize / 100;
    299321                        this.Location = _config.Location;
    300322                        this.TransparentMouseMessage = _config.TransparentMouseMessage;
Note: See TracChangeset for help on using the changeset viewer.