Changeset 39
- Timestamp:
- Feb 26, 2005, 2:55:18 AM (19 years ago)
- Location:
- trunk/MacFaceFloat
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MacFaceFloat/ConfigurationForm.cs
r32 r39 3 3 using System.Collections; 4 4 using System.ComponentModel; 5 using System.Diagnostics; 5 6 using System.Windows.Forms; 6 7 using System.IO; … … 14 15 public class ConfigurationForm : System.Windows.Forms.Form 15 16 { 16 private Ma inForm _mainForm;17 private MacFaceApp _app; 17 18 private Configuration _config; 18 19 … … 42 43 private System.ComponentModel.IContainer components; 43 44 44 public ConfigurationForm(Ma inForm mainForm)45 public ConfigurationForm(MacFaceApp app) 45 46 { 46 47 // … … 49 50 InitializeComponent(); 50 51 51 _mainForm = mainForm;52 52 _config = Configuration.GetInstance(); 53 53 _app = app; 54 54 } 55 55 … … 371 371 private void ConfigurationForm_Load(object sender, System.EventArgs e) 372 372 { 373 // SÊð\¦B 373 // úlÌZbg 374 trackBarOpacity.Value = _config.Opacity; 375 trackBarPatternSize.Value = _config.PatternSize; 376 checkMouseMessage.Checked = _config.TransparentMouseMessage; 377 378 // êx·×ÄÌplðñ\¦É·é 374 379 foreach (Panel pane in panelContainer.Controls) 375 380 { … … 378 383 } 379 384 385 // SÊÌÝðÂÉ·é 380 386 panelAppearance.Show(); 381 382 // úlðZbgB383 trackBarOpacity.Value = (int) (_mainForm.Opacity * 100);384 trackBarPatternSize.Value = (int)(_mainForm.PatternSize * 100);385 checkMouseMessage.Checked = Configuration.GetInstance().TransparentMouseMessage;386 387 } 387 388 388 389 private void buttonOK_Click(object sender, System.EventArgs e) 389 390 { 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; 394 394 395 395 this.Close(); … … 514 514 if (item != null) 515 515 { 516 _mainForm.LoadFaceDefine(item.SubItems[1].Text); 516 // TODO: ±±¾¯A^CÉÝèàeª½f³êéÌͽ¥ÁÛ¢ 517 _app.LoadFaceDefine(item.SubItems[1].Text); 517 518 } 518 519 } … … 533 534 try 534 535 { 535 System.Diagnostics.Process.Start(linkWebSite.Text);536 Process.Start(linkWebSite.Text); 536 537 } 537 538 catch (Win32Exception) {} -
trunk/MacFaceFloat/MacFaceFloat.csproj
r37 r39 144 144 /> 145 145 <File 146 RelPath = "MacFaceApp.cs" 147 SubType = "Code" 148 BuildAction = "Compile" 149 /> 150 <File 146 151 RelPath = "MainForm.cs" 147 152 SubType = "Form" -
trunk/MacFaceFloat/MainForm.cs
r38 r39 1 1 /* 2 * MainForm.cs 2 * MacFace p^[EChENX 3 * 3 4 * $Id$ 4 *5 * project created on 2004/06/02 at 2:436 5 * 7 6 */ … … 10 9 using System.Windows.Forms; 11 10 using 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;19 11 20 12 namespace MacFace.FloatApp … … 22 14 public class MainForm : Misuzilla.Windows.Forms.AlphaForm 23 15 { 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; 29 18 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;38 19 private FaceDef.PatternSuite curSuite; 39 20 private int curPattern; 40 21 private int curMarkers; 41 42 [STAThread]43 public static void Main(string[] args)44 {45 MainForm form = new MainForm();46 form.StartApplication();47 }48 22 49 23 // RXgN^ … … 51 25 { 52 26 InitializeComponent(); 53 54 Assembly asm = Assembly.GetExecutingAssembly();55 this.notifyIcon.Icon = new Icon(asm.GetManifestResourceStream("MacFace.FloatApp.App.ico"));56 27 57 28 this.TransparentMouseMessage = false; … … 61 32 curPattern = 0; 62 33 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;71 34 } 72 35 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 { 114 38 this.AutoScaleBaseSize = new System.Drawing.Size(5, 12); 115 39 this.ClientSize = new System.Drawing.Size(120, 101); 116 this.ContextMenu = this.contextMenu;117 40 this.ControlBox = false; 118 41 this.MaximizeBox = false; … … 125 48 } 126 49 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^[è`tH_IðB174 */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̶ݷétH_ðIðµÄ¾³¢B";187 if (folderBrowser.ShowDialog() == DialogResult.OK)188 {189 if (LoadFaceDefine(folderBrowser.SelectedPath))190 {191 return true;192 }193 }194 else195 {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è³ê½tH_Éçp^[è`XMLt@C \"faceDef.plist\" ª¶ÝµÜ¹ñB\n\ntH_:\n{0}", path),212 "MacFace for Windows", MessageBoxButtons.OK, MessageBoxIcon.Error);213 return false;214 }215 216 try217 {218 newFaceDef = new MacFace.FaceDef(path);219 }220 catch (System.IO.IOException ie)221 {222 System.Windows.Forms.MessageBox.Show(223 String.Format("çp^[è`XMLt@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^[è`XMLt@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^[·µÖ¦ÍXVð~ßĨ238 if (_updateTimer != null) _updateTimer.Stop();239 240 this.FaceDef = newFaceDef;241 RefreshPattern();242 243 notifyIcon.Text = "MacFace - " + _currentFaceDef.Title;244 245 // XVÄJ246 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 284 50 public float PatternSize 285 51 { 286 get { return _patternSize; }287 set { _patternSize = value; }52 get { return patternSize; } 53 set { patternSize = value; } 288 54 } 289 55 290 56 public FaceDef FaceDef 291 57 { 292 get { return _currentFaceDef; }293 set { _currentFaceDef = value; }58 get { return curFaceDef; } 59 set { curFaceDef = value; } 294 60 } 295 61 … … 309 75 Graphics g = this.Graphics; 310 76 g.Clear(Color.FromArgb(0, 0, 0, 0)); 311 _currentFaceDef.DrawPatternImage(g, curSuite, curPattern, curMarkers, _patternSize);77 curFaceDef.DrawPatternImage(g, curSuite, curPattern, curMarkers, patternSize); 312 78 this.Update(); 313 }314 315 /*316 * j317 [NbNCxg318 */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 }337 79 } 338 80 }
Note: See TracChangeset
for help on using the changeset viewer.