Changeset 13 for trunk/MacFaceFloat/MainForm.cs
- Timestamp:
- Nov 15, 2004, 2:12:03 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceFloat/MainForm.cs
r10 r13 17 17 using System.Threading; 18 18 19 namespace MacFace 19 namespace MacFace.FloatApp 20 20 { 21 21 public class MainForm : Misuzilla.Windows.Forms.AlphaForm … … 23 23 private System.Windows.Forms.ContextMenu contextMenu; 24 24 private System.Windows.Forms.MenuItem menuItemPatternSelect; 25 private System.Windows.Forms.MenuItem menuItemConfigure; 25 26 private System.Windows.Forms.MenuItem menuItemExit; 26 private Hashtable _property;27 private ArrayList _parts;28 27 private String _facePath; 29 28 private System.Windows.Forms.Timer _updateTimer; 29 30 private FaceDef _currentFaceDef; 31 private Configuration _config; 30 32 31 33 Int32 prevUsage; … … 62 64 } 63 65 64 // THIS METHOD IS MAINTAINED BY THE FORM DESIGNER65 // DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST66 66 void InitializeComponent() { 67 67 this.menuItemPatternSelect = new System.Windows.Forms.MenuItem(); 68 this.menuItemConfigure = new System.Windows.Forms.MenuItem(); 68 69 this.menuItemExit = new System.Windows.Forms.MenuItem(); 69 70 this.contextMenu = new System.Windows.Forms.ContextMenu(); … … 71 72 // menuItemPatternSelect 72 73 // 73 this.menuItemPatternSelect.Index = 0;74 74 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); 77 82 // 78 83 // menuItemExit … … 81 86 this.menuItemExit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ; 82 87 this.menuItemExit.Text = "I¹(&X)"; 83 this.menuItemExit.Click += new System.EventHandler(this. doQuit);88 this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click); 84 89 // 85 90 // contextMenu 86 91 // 87 92 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}); 89 94 // 90 95 // MainForm … … 102 107 this.TopMost = true; 103 108 this.Load += new EventHandler(MainForm_Load); 109 this.Closing += new CancelEventHandler(MainForm_Closing); 110 this.Move += new EventHandler(MainForm_Move); 104 111 } 105 112 … … 143 150 144 151 145 bool LoadFaceDefine(string path) 146 { 152 public bool LoadFaceDefine(string path) 153 { 154 FaceDef newFaceDef = null; 147 155 string plistPath = Path.Combine(path, "faceDef.plist"); 148 156 … … 155 163 } 156 164 157 Hashtable property;158 165 try 159 166 { 160 property = PropertyList.Load(plistPath);167 newFaceDef = MacFace.FaceDef.CreateFaceDefFromFile(path); 161 168 } 162 169 catch (System.IO.IOException ie) … … 180 187 if (_updateTimer != null) _updateTimer.Stop(); 181 188 182 _property = property; 183 _facePath = path; 184 _parts = (ArrayList)_property["parts"]; 189 _currentFaceDef = newFaceDef; 190 _facePath = _currentFaceDef.Path; 185 191 prevUsage = -10; 186 192 … … 205 211 206 212 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 211 213 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); 221 219 } 222 220 this.Update(); … … 227 225 228 226 227 // 228 // N® 229 // 229 230 public void MainForm_Load(object sender, System.EventArgs e) 230 231 { 231 string faceDefPath = Path.Combine(Application.StartupPath, "default.mcface"); 232 // Ýè 233 _config = Configuration.GetInstance(); 234 _config.Load(); 235 236 ApplyConfiguration(); 237 238 // çp^[ÇÝÝ 232 239 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); 237 243 } 238 244 … … 241 247 if (!SelectFaceDefine(Application.StartupPath)) 242 248 { 243 Application.Exit();249 this.Close(); 244 250 return; 245 251 } … … 247 253 } 248 254 } 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 249 270 250 271 /* … … 252 273 [NbNCxg 253 274 */ 254 public void PatternSelect_Click(object sender, System.EventArgs e)275 public void menuItemPatternSelect_Click(object sender, System.EventArgs e) 255 276 { 256 277 SelectFaceDefine(_facePath); 257 278 } 258 279 259 public void doQuit(object sender, System.EventArgs e)280 public void menuItemExit_Click(object sender, System.EventArgs e) 260 281 { 261 282 _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 } 265 306 } 266 307 }
Note: See TracChangeset
for help on using the changeset viewer.