mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
GUI桌面环境
This commit is contained in:
71
Gui/Apps/MemoryStatistics.cs
Normal file
71
Gui/Apps/MemoryStatistics.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using CMLeonOS;
|
||||
using CMLeonOS.Utils;
|
||||
using CMLeonOS.Gui.SmoothMono;
|
||||
using CMLeonOS.Gui.UILib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CMLeonOS.Gui.Apps
|
||||
{
|
||||
internal class MemoryStatistics : Process
|
||||
{
|
||||
internal MemoryStatistics() : base("MemoryStatistics", ProcessType.Application) { }
|
||||
|
||||
AppWindow window;
|
||||
|
||||
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
|
||||
|
||||
private int lastSecond;
|
||||
|
||||
private static int padding = 12;
|
||||
private static int barHeight = 12;
|
||||
private static Color barColour = Color.FromArgb(0, 155, 254);
|
||||
|
||||
private void Update()
|
||||
{
|
||||
window.Clear(Color.LightGray);
|
||||
|
||||
var statistics = MemoryStatisticsProvider.GetMemoryStatistics();
|
||||
|
||||
window.DrawString("Memory Statistics", Color.DarkBlue, padding, padding);
|
||||
|
||||
window.DrawString(string.Format(@"Total: {0} MB
|
||||
Unavailable: {1} MB
|
||||
Used: {2:d1} MB
|
||||
Free: {3} MB
|
||||
Percentage Used: {4:d1}%",
|
||||
statistics.TotalMB,
|
||||
statistics.UnavailableMB,
|
||||
statistics.UsedMB,
|
||||
statistics.FreeMB,
|
||||
statistics.PercentUsed), Color.Black, padding, padding + FontData.Height + padding);
|
||||
|
||||
window.DrawFilledRectangle(0, window.Height - barHeight, window.Width, barHeight, Color.Black);
|
||||
window.DrawFilledRectangle(0, window.Height - barHeight, (int)(window.Width * ((float)statistics.PercentUsed / 100f)), barHeight, barColour);
|
||||
|
||||
wm.Update(window);
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
window = new AppWindow(this, 256, 256, 256, 192);
|
||||
wm.AddWindow(window);
|
||||
window.Title = "Memory Statistics";
|
||||
window.Icon = AppManager.GetAppMetadata("Memory Statistics").Icon;
|
||||
window.Closing = TryStop;
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
int second = DateTime.Now.Second;
|
||||
if (lastSecond != second)
|
||||
{
|
||||
lastSecond = second;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user