Changeset 39


Ignore:
Timestamp:
Feb 26, 2005, 2:55:18 AM (19 years ago)
Author:
altba\rryu
Message:

アプリケーション的な処理をMainFormクラスからMacFaceAppクラスに分離した。

Location:
trunk/MacFaceFloat
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/ConfigurationForm.cs

    r32 r39  
    33using System.Collections;
    44using System.ComponentModel;
     5using System.Diagnostics;
    56using System.Windows.Forms;
    67using System.IO;
     
    1415        public class ConfigurationForm : System.Windows.Forms.Form
    1516        {
    16                 private MainForm _mainForm;
     17                private MacFaceApp _app;
    1718                private Configuration _config;
    1819
     
    4243                private System.ComponentModel.IContainer components;
    4344
    44                 public ConfigurationForm(MainForm mainForm)
     45                public ConfigurationForm(MacFaceApp app)
    4546                {
    4647                        //
     
    4950                        InitializeComponent();
    5051
    51                         _mainForm = mainForm;
    5252                        _config = Configuration.GetInstance();
    53 
     53                        _app = app;
    5454                }
    5555
     
    371371                private void ConfigurationForm_Load(object sender, System.EventArgs e)
    372372                {
    373                         // ‘S”Ê‚ð•\Ž¦B
     373                        // ‰Šú’l‚̃Zƒbƒg
     374                        trackBarOpacity.Value = _config.Opacity;
     375                        trackBarPatternSize.Value = _config.PatternSize;
     376                        checkMouseMessage.Checked = _config.TransparentMouseMessage;
     377
     378                        // ˆê“x‚·‚ׂẴpƒlƒ‹‚ð”ñ•\Ž¦‚É‚·‚é
    374379                        foreach (Panel pane in panelContainer.Controls)
    375380                        {
     
    378383                        }
    379384
     385                        // ‘S”Ê‚Ì‚Ý‚ð‰ÂŽ‹‚É‚·‚é
    380386                        panelAppearance.Show();
    381 
    382                         // ‰Šú’l‚ðƒZƒbƒgB
    383                         trackBarOpacity.Value = (int) (_mainForm.Opacity * 100);
    384                         trackBarPatternSize.Value = (int)(_mainForm.PatternSize * 100);
    385                         checkMouseMessage.Checked = Configuration.GetInstance().TransparentMouseMessage;
    386387                }
    387388
    388389                private void buttonOK_Click(object sender, System.EventArgs e)
    389390                {
    390                         Configuration config = Configuration.GetInstance();
    391                         config.Opacity = trackBarOpacity.Value;
    392                         config.PatternSize = trackBarPatternSize.Value;
    393                         config.TransparentMouseMessage = checkMouseMessage.Checked;
     391                        _config.Opacity = trackBarOpacity.Value;
     392                        _config.PatternSize = trackBarPatternSize.Value;
     393                        _config.TransparentMouseMessage = checkMouseMessage.Checked;
    394394
    395395                        this.Close();
     
    514514                        if (item != null)
    515515                        {
    516                                 _mainForm.LoadFaceDefine(item.SubItems[1].Text);
     516                                // TODO: ‚±‚±‚¾‚¯ƒŠƒAƒ‹ƒ^ƒCƒ€‚ɐݒè“à—e‚ª”½‰f‚³‚ê‚é‚Ì‚Í”½‘¥‚Á‚Û‚¢
     517                                _app.LoadFaceDefine(item.SubItems[1].Text);
    517518                        }
    518519                }
     
    533534                        try
    534535                        {
    535                                 System.Diagnostics.Process.Start(linkWebSite.Text);
     536                                Process.Start(linkWebSite.Text);
    536537                        }
    537538                        catch (Win32Exception) {}
  • trunk/MacFaceFloat/MacFaceFloat.csproj

    r37 r39  
    144144                />
    145145                <File
     146                    RelPath = "MacFaceApp.cs"
     147                    SubType = "Code"
     148                    BuildAction = "Compile"
     149                />
     150                <File
    146151                    RelPath = "MainForm.cs"
    147152                    SubType = "Form"
  • trunk/MacFaceFloat/MainForm.cs

    r38 r39  
    11/*
    2  * MainForm.cs
     2 * MacFace ƒpƒ^[ƒ“ƒEƒCƒ“ƒhƒEƒNƒ‰ƒX
     3 *
    34 * $Id$
    4  *
    5  * project created on 2004/06/02 at 2:43
    65 *
    76 */
     
    109using System.Windows.Forms;
    1110using System.Drawing;
    12 using System.Collections;
    13 using System.ComponentModel;
    14 using System.Data;
    15 using System.IO;
    16 using System.Diagnostics;
    17 using System.Threading;
    18 using System.Reflection;
    1911
    2012namespace MacFace.FloatApp
     
    2214        public class MainForm : Misuzilla.Windows.Forms.AlphaForm
    2315        {
    24                 private System.Windows.Forms.NotifyIcon notifyIcon;
    25                 private System.Windows.Forms.ContextMenu contextMenu;
    26                 private System.Windows.Forms.MenuItem menuItemPatternSelect;
    27                 private System.Windows.Forms.MenuItem menuItemConfigure;
    28                 private System.Windows.Forms.MenuItem menuItemExit;
     16                private FaceDef curFaceDef;
     17                private float patternSize;
    2918
    30                 private Configuration _config;
    31 
    32                 private System.Windows.Forms.Timer _updateTimer;
    33                 private CPUUsageCounter cpuCounter;
    34                 private MemoryUsageCounter memoryCounter;
    35 
    36                 private FaceDef _currentFaceDef;
    37                 private float _patternSize;
    3819                private FaceDef.PatternSuite curSuite;
    3920                private int curPattern;
    4021                private int curMarkers;
    41 
    42                 [STAThread]
    43                 public static void Main(string[] args)
    44                 {
    45                         MainForm form = new MainForm();
    46                         form.StartApplication();
    47                 }
    4822
    4923                // ƒRƒ“ƒXƒgƒ‰ƒNƒ^
     
    5125                {
    5226                        InitializeComponent();
    53 
    54                         Assembly asm = Assembly.GetExecutingAssembly();
    55                         this.notifyIcon.Icon = new Icon(asm.GetManifestResourceStream("MacFace.FloatApp.App.ico"));
    5627
    5728                        this.TransparentMouseMessage = false;
     
    6132                        curPattern = 0;
    6233                        curMarkers = 0;
    63 
    64                         cpuCounter = new CPUUsageCounter();
    65                         memoryCounter = new MemoryUsageCounter();
    66 
    67                         _updateTimer = new System.Windows.Forms.Timer();
    68                         _updateTimer.Tick += new EventHandler(this.CountProcessorUsage);
    69                         _updateTimer.Enabled = false;
    70                         _updateTimer.Interval = 1000;
    7134                }
    7235
    73                 void InitializeComponent() {
    74                         this.notifyIcon = new System.Windows.Forms.NotifyIcon();
    75                         this.menuItemPatternSelect = new System.Windows.Forms.MenuItem();
    76                         this.menuItemConfigure = new System.Windows.Forms.MenuItem();
    77                         this.menuItemExit = new System.Windows.Forms.MenuItem();
    78                         this.contextMenu = new System.Windows.Forms.ContextMenu();
    79 
    80                         //
    81                         // notifyIcon
    82                         //
    83                         this.notifyIcon.Text = "MacFace";
    84                         this.notifyIcon.Icon = this.Icon;
    85                         this.notifyIcon.Visible = true;
    86                         this.notifyIcon.ContextMenu = this.contextMenu;
    87 
    88                         //
    89                         // menuItemPatternSelect
    90                         //
    91                         this.menuItemPatternSelect.Text = "Šçƒpƒ^[ƒ“‚Ì‘I‘ð(&S)";
    92                         this.menuItemPatternSelect.Click += new System.EventHandler(this.menuItemPatternSelect_Click);
    93 
    94                         //
    95                         // menuItemConfigure
    96                         //
    97                         this.menuItemConfigure.Text = "MacFace ‚̐ݒè(&C)...";
    98                         this.menuItemConfigure.Click +=new EventHandler(menuItemConfigure_Click);
    99                         //
    100                         // menuItemExit
    101                         //
    102                         this.menuItemExit.Index = 0;
    103                         this.menuItemExit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
    104                         this.menuItemExit.Text = "I—¹(&X)";
    105                         this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
    106                         //
    107                         // contextMenu
    108                         //
    109                         this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    110                                                 this.menuItemPatternSelect, this.menuItemConfigure, new MenuItem("-"), this.menuItemExit});
    111                         //
    112                         // MainForm
    113                         //
     36                void InitializeComponent()
     37                {
    11438                        this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
    11539                        this.ClientSize = new System.Drawing.Size(120, 101);
    116                         this.ContextMenu = this.contextMenu;
    11740                        this.ControlBox = false;
    11841                        this.MaximizeBox = false;
     
    12548                }
    12649
    127                 public void StartApplication()
    128                 {
    129                         // Ý’è
    130                         _config = Configuration.GetInstance();
    131                         _config.Load();
    132 
    133 
    134                         // Šçƒpƒ^[ƒ““ǂݍž‚Ý
    135                         bool result = false;
    136                         if (Directory.Exists(_config.FaceDefPath))
    137                         {
    138                                 result = LoadFaceDefine(_config.FaceDefPath);
    139                         }
    140 
    141                         if (!result)
    142                         {
    143                                 if (!SelectFaceDefine(Application.StartupPath))
    144                                 {
    145                                         Application.Exit();
    146                                         return;
    147                                 }
    148                         }
    149 
    150                         Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
    151 
    152                         this.Location = _config.Location;
    153                         ApplyConfiguration();
    154 
    155                         _updateTimer.Start();
    156                         Application.Run(this);
    157                 }
    158 
    159                 void Application_ApplicationExit(object sender, EventArgs e)
    160                 {
    161                         notifyIcon.Visible = false;
    162 
    163                         // •Û‘¶
    164                         _config.Opacity = (int)(this.Opacity * 100);
    165                         _config.FaceDefPath = (_currentFaceDef != null ? _currentFaceDef.Path : Path.Combine(Application.StartupPath, "default.mcface"));
    166                         _config.Location = this.Location;
    167                         _config.TransparentMouseMessage = this.TransparentMouseMessage;
    168 
    169                         _config.Save();
    170                 }
    171 
    172                 /*
    173                  * Šçƒpƒ^[ƒ“’è‹`ƒtƒHƒ‹ƒ_‘I‘ðB
    174                  */
    175                 public bool SelectFaceDefine()
    176                 {
    177                         return SelectFaceDefine(Application.StartupPath);
    178                 }
    179 
    180                 public bool SelectFaceDefine(string defaultPath)
    181                 {
    182                         while (true)
    183                         {
    184                                 FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
    185                                 folderBrowser.SelectedPath = defaultPath;
    186                                 folderBrowser.Description = "Šçƒpƒ^[ƒ“ƒtƒ@ƒCƒ‹‚Ì‘¶Ý‚·‚éƒtƒHƒ‹ƒ_‚ð‘I‘ð‚µ‚Ä‚­‚¾‚³‚¢B";
    187                                 if (folderBrowser.ShowDialog() == DialogResult.OK)
    188                                 {
    189                                         if (LoadFaceDefine(folderBrowser.SelectedPath))
    190                                         {
    191                                                 return true;
    192                                         }
    193                                 }
    194                                 else
    195                                 {
    196                                         return false;
    197                                 }
    198                         }
    199 
    200                 }
    201 
    202 
    203                 public bool LoadFaceDefine(string path)
    204                 {
    205                         FaceDef newFaceDef = null;
    206                         string plistPath = Path.Combine(path, "faceDef.plist");
    207 
    208                         if (!File.Exists(plistPath))
    209                         {
    210                                 System.Windows.Forms.MessageBox.Show(
    211                                         String.Format("Žw’肳‚ꂽƒtƒHƒ‹ƒ_‚ÉŠçƒpƒ^[ƒ“’è‹`XMLƒtƒ@ƒCƒ‹ \"faceDef.plist\" ‚ª‘¶Ý‚µ‚Ü‚¹‚ñB\n\nƒtƒHƒ‹ƒ_:\n{0}", path),
    212                                         "MacFace for Windows", MessageBoxButtons.OK, MessageBoxIcon.Error);
    213                                 return false;
    214                         }
    215                        
    216                         try
    217                         {
    218                                 newFaceDef = new MacFace.FaceDef(path);
    219                         }
    220                         catch (System.IO.IOException ie)
    221                         {
    222                                 System.Windows.Forms.MessageBox.Show(
    223                                         String.Format("Šçƒpƒ^[ƒ“’è‹`XMLƒtƒ@ƒCƒ‹‚ð“ǂݍž‚ލۂɃGƒ‰[‚ª”­¶‚µ‚Ü‚µ‚½B\n\nŒ´ˆö:\n{0}",
    224                                         ie.ToString()), "MacFace for Windows", MessageBoxButtons.OK, MessageBoxIcon.Error);
    225                                
    226                                 return false;
    227                         }
    228                         catch (System.Xml.XmlException xe)
    229                         {
    230                                 System.Windows.Forms.MessageBox.Show(
    231                                         String.Format("Šçƒpƒ^[ƒ“’è‹`XMLƒtƒ@ƒCƒ‹‚ð“Ǎž‚Ý’†‚ɃGƒ‰[‚ª”­¶‚µ‚Ü‚µ‚½B\n\nŒ´ˆö:\n{0}",
    232                                         xe.ToString()), "MacFace for Windows", MessageBoxButtons.OK, MessageBoxIcon.Error);
    233                                
    234                                 return false;
    235                         }
    236 
    237                         // Šçƒpƒ^[ƒ“·‚µ‘Ö‚¦’†‚͍XV‚ðŽ~‚ß‚Ä‚¨‚­
    238                         if (_updateTimer != null) _updateTimer.Stop();
    239 
    240                         this.FaceDef = newFaceDef;
    241                         RefreshPattern();
    242 
    243                         notifyIcon.Text = "MacFace - " + _currentFaceDef.Title;
    244 
    245                         // XVÄŠJ
    246                         if (_updateTimer != null) _updateTimer.Start();
    247 
    248                         return true;
    249                 }
    250 
    251                 public void CountProcessorUsage(object sender, EventArgs e)
    252                 {
    253                         CPUUsage cpuUsage = cpuCounter.CurrentUsage();
    254                         MemoryUsage memUsage = memoryCounter.CurrentUsage();
    255 
    256                         int pattern = cpuUsage.Active / 10;
    257 
    258                         FaceDef.PatternSuite suite = FaceDef.PatternSuite.Normal;
    259                         if (memUsage.Available < (10 * 1024 *1024))
    260                         {
    261                                 suite = FaceDef.PatternSuite.MemoryInsufficient;
    262                         }
    263                         else if (memUsage.Available < (30 * 1024 *1024))
    264                         {
    265                                 suite = FaceDef.PatternSuite.MemoryDecline;
    266                         }
    267 
    268                         int markers = FaceDef.MarkerNone;
    269                         if (memUsage.Pagein > 0) markers += FaceDef.MarkerPageIn;
    270                         if (memUsage.Pageout > 0) markers += FaceDef.MarkerPageOut;
    271 
    272                         UpdatePattern(suite, pattern, markers);
    273                 }
    274 
    275                 private void ApplyConfiguration()
    276                 {
    277                         this.Opacity = (float)_config.Opacity / 100;
    278                         this.PatternSize = (float)_config.PatternSize / 100;
    279                         this.TransparentMouseMessage = _config.TransparentMouseMessage;
    280 
    281                         RefreshPattern();
    282                 }
    283 
    28450                public float PatternSize
    28551                {
    286                         get { return _patternSize; }
    287                         set { _patternSize = value; }
     52                        get { return patternSize; }
     53                        set { patternSize = value; }
    28854                }
    28955
    29056                public FaceDef FaceDef
    29157                {
    292                         get { return _currentFaceDef; }
    293                         set { _currentFaceDef = value; }
     58                        get { return curFaceDef; }
     59                        set { curFaceDef = value; }
    29460                }
    29561
     
    30975                        Graphics g = this.Graphics;
    31076                        g.Clear(Color.FromArgb(0, 0, 0, 0));
    311                         _currentFaceDef.DrawPatternImage(g, curSuite, curPattern, curMarkers, _patternSize);
     77                        curFaceDef.DrawPatternImage(g, curSuite, curPattern, curMarkers, patternSize);
    31278                        this.Update();
    313                 }
    314 
    315                 /*
    316                  * ƒƒjƒ
    317 [ƒNƒŠƒbƒNƒCƒxƒ“ƒg
    318                  */
    319                 public void menuItemPatternSelect_Click(object sender, System.EventArgs e)
    320                 {
    321                         SelectFaceDefine(FaceDef.Path);
    322                 }
    323 
    324                 public void menuItemExit_Click(object sender, System.EventArgs e)
    325                 {
    326                         _updateTimer.Stop();
    327                         this.Close();
    328                 }
    329 
    330                 private void menuItemConfigure_Click(object sender, EventArgs e)
    331                 {
    332                         ConfigurationForm configForm = new ConfigurationForm(this);
    333                         if (configForm.ShowDialog() == DialogResult.OK)
    334                         {
    335                                 ApplyConfiguration();
    336                         }
    33779                }
    33880        }
Note: See TracChangeset for help on using the changeset viewer.