Ignore:
Timestamp:
Nov 15, 2004, 2:12:03 AM (19 years ago)
Author:
altba\tomoyo
Message:

MacFaceFloat?

  • %USERPROFILE%\Application Data\MacFace\ に設定を保存するようにした。
  • 設定ダイアログを作成した。

MacFaceLibrary?

  • パターンをクラスとして扱えるようにした(FacePattern?)。
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MainForm.cs

    r10 r13  
    1717using System.Threading;
    1818
    19 namespace MacFace
     19namespace MacFace.FloatApp
    2020{
    2121        public class MainForm : Misuzilla.Windows.Forms.AlphaForm
     
    2323                private System.Windows.Forms.ContextMenu contextMenu;
    2424                private System.Windows.Forms.MenuItem menuItemPatternSelect;
     25                private System.Windows.Forms.MenuItem menuItemConfigure;
    2526                private System.Windows.Forms.MenuItem menuItemExit;
    26                 private Hashtable _property;
    27                 private ArrayList _parts;
    2827                private String _facePath;
    2928                private System.Windows.Forms.Timer _updateTimer;
     29
     30                private FaceDef _currentFaceDef;
     31                private Configuration _config;
    3032               
    3133                Int32 prevUsage;
     
    6264                }
    6365
    64                 // THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
    65                 // DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
    6666                void InitializeComponent() {
    6767                        this.menuItemPatternSelect = new System.Windows.Forms.MenuItem();
     68                        this.menuItemConfigure = new System.Windows.Forms.MenuItem();
    6869                        this.menuItemExit = new System.Windows.Forms.MenuItem();
    6970                        this.contextMenu = new System.Windows.Forms.ContextMenu();
     
    7172                        // menuItemPatternSelect
    7273                        //
    73                         this.menuItemPatternSelect.Index = 0;
    7474                        this.menuItemPatternSelect.Text = "Šçƒpƒ^[ƒ“‚Ì‘I‘ð(&S)";
    75                         this.menuItemPatternSelect.Click += new System.EventHandler(this.PatternSelect_Click);
    76 
     75                        this.menuItemPatternSelect.Click += new System.EventHandler(this.menuItemPatternSelect_Click);
     76
     77                        //
     78                        // menuItemConfigure
     79                        //
     80                        this.menuItemConfigure.Text = "MacFace ‚̐ݒè(&C)...";
     81                        this.menuItemConfigure.Click +=new EventHandler(menuItemConfigure_Click);
    7782                        //
    7883                        // menuItemExit
     
    8186                        this.menuItemExit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
    8287                        this.menuItemExit.Text = "I—¹(&X)";
    83                         this.menuItemExit.Click += new System.EventHandler(this.doQuit);
     88                        this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
    8489                        //
    8590                        // contextMenu
    8691                        //
    8792                        this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    88                                                 this.menuItemPatternSelect, new MenuItem("-"), this.menuItemExit});
     93                                                this.menuItemPatternSelect, this.menuItemConfigure, new MenuItem("-"), this.menuItemExit});
    8994                        //
    9095                        // MainForm
     
    102107                        this.TopMost = true;
    103108                        this.Load += new EventHandler(MainForm_Load);
     109                        this.Closing += new CancelEventHandler(MainForm_Closing);
     110                        this.Move += new EventHandler(MainForm_Move);
    104111                }
    105112                       
     
    143150
    144151
    145                 bool LoadFaceDefine(string path)
    146                 {
     152                public bool LoadFaceDefine(string path)
     153                {
     154                        FaceDef newFaceDef = null;
    147155                        string plistPath = Path.Combine(path, "faceDef.plist");
    148156
     
    155163                        }
    156164                       
    157                         Hashtable property;
    158165                        try
    159166                        {
    160                                 property = PropertyList.Load(plistPath);
     167                                newFaceDef = MacFace.FaceDef.CreateFaceDefFromFile(path);
    161168                        }
    162169                        catch (System.IO.IOException ie)
     
    180187                        if (_updateTimer != null) _updateTimer.Stop();
    181188
    182                         _property = property;
    183                         _facePath = path;
    184                         _parts = (ArrayList)_property["parts"];
     189                        _currentFaceDef = newFaceDef;
     190                        _facePath = _currentFaceDef.Path;
    185191                        prevUsage = -10;
    186192
     
    205211                               
    206212                        if (prevUsage/10 != usage/10) {
    207                                 ArrayList patterns = (ArrayList)_property["pattern"];
    208                                 ArrayList patternCpu = (ArrayList)patterns[0];
    209                                 ArrayList facePattern = (ArrayList)patternCpu[usage/10];
    210                                
    211213                                this.Graphics.Clear(Color.FromArgb(0, 0, 0, 0));
    212                                 foreach (Int32 i in facePattern) {
    213                                         Hashtable part = _parts[i] as Hashtable;
    214                                         string filename = (string)part["filename"];
    215                                         string imgPath = Path.Combine(_facePath, filename);
    216                                         using (Bitmap bitmap = new Bitmap(imgPath)) {
    217                                                 int x = (int)part["pos x"];
    218                                                 int y = 128 - (int)part["pos y"] - bitmap.Size.Height;
    219                                                 this.Graphics.DrawImage(bitmap,x,y,bitmap.Size.Width,bitmap.Size.Height);
    220                                         }
     214                                foreach (Part part in _currentFaceDef.FacePattern.GetPartList(usage, PageOutFlag.Normal))
     215                                {
     216                                        this.Graphics.DrawImage(part.Image,
     217                                                part.Point.X, part.Point.Y,
     218                                                part.Image.Size.Width, part.Image.Size.Height);
    221219                                }
    222220                                this.Update();
     
    227225               
    228226
     227                //
     228                // ‹N“®
     229                //
    229230                public void MainForm_Load(object sender, System.EventArgs e)
    230231                {
    231                         string faceDefPath = Path.Combine(Application.StartupPath, "default.mcface");
     232                        // Ý’è
     233                        _config = Configuration.GetInstance();
     234                        _config.Load();
     235
     236                        ApplyConfiguration();
     237
     238                        // Šçƒpƒ^[ƒ““ǂݍž‚Ý
    232239                        bool result = false;
    233 
    234                         if (Directory.Exists(faceDefPath))
    235                         {
    236                                 result = LoadFaceDefine(faceDefPath);
     240                        if (Directory.Exists(_config.FaceDefPath))
     241                        {
     242                                result = LoadFaceDefine(_config.FaceDefPath);
    237243                        }
    238244
     
    241247                                if (!SelectFaceDefine(Application.StartupPath))
    242248                                {
    243                                         Application.Exit();
     249                                        this.Close();
    244250                                        return;
    245251                                }
     
    247253                        }
    248254                }
     255
     256                //
     257                // I—¹
     258                //
     259                private void MainForm_Closing(object sender, CancelEventArgs e)
     260                {
     261                        // •Û‘¶
     262                        _config.Opacity = (int) (this.Opacity * 100);
     263                        _config.FaceDefPath = (_currentFaceDef != null ? _currentFaceDef.Path : Path.Combine(Application.StartupPath, "default.mcface"));
     264                        _config.Location = this.Location;
     265                        _config.TransparentMouseMessage = this.TransparentMouseMessage;
     266
     267                        _config.Save();
     268                }
     269
    249270
    250271                /*
     
    252273[ƒNƒŠƒbƒNƒCƒxƒ“ƒg
    253274                 */
    254                 public void PatternSelect_Click(object sender, System.EventArgs e)
     275                public void menuItemPatternSelect_Click(object sender, System.EventArgs e)
    255276                {
    256277                        SelectFaceDefine(_facePath);   
    257278                }
    258279
    259                 public void doQuit(object sender, System.EventArgs e)
     280                public void menuItemExit_Click(object sender, System.EventArgs e)
    260281                {
    261282                        _updateTimer.Stop();
    262                         Application.Exit();
    263                 }
    264                
     283                        this.Close();
     284                }
     285
     286                private void menuItemConfigure_Click(object sender, EventArgs e)
     287                {
     288                        ConfigurationForm configForm = new ConfigurationForm(this);
     289                        if (configForm.ShowDialog() == DialogResult.OK)
     290                        {
     291                                ApplyConfiguration();
     292                        }
     293                }
     294
     295                private void ApplyConfiguration()
     296                {
     297                        this.Opacity = (float)_config.Opacity / 100;
     298                        this.Location = _config.Location;
     299                        this.TransparentMouseMessage = _config.TransparentMouseMessage;
     300                }
     301
     302                private void MainForm_Move(object sender, EventArgs e)
     303                {
     304                        _config.Location = this.Location;
     305                }
    265306        }
    266307}
Note: See TracChangeset for help on using the changeset viewer.