JD2022-TU1/main/tools/legacy/MemoryViewer/SlotViewer.cs

137 lines
4.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MemoryViewer
{
public partial class SlotViewer : Form
{
ContinuousProgressBar[] progressBarSlot = null;
Label[] labelSlot = null;
Label[] labelSlotSize = null;
public SlotViewer()
{
InitializeComponent();
}
public string convertByte(UInt32 value)
{
if (value > 1024*1024)
return (value/(1024*1024)).ToString() +" Mb";
else if (value > 1024)
return (value / 1024).ToString() + " Kb";
return value.ToString();
}
public void updateCommon(UInt32 _memoryUsage)
{
memoryPhysicalLabel.Text = "Memory Physical allocated: " + convertByte(_memoryUsage).ToString();
}
public void updateSlot(UInt32 index, UInt32 slotSize, UInt32 maxSlot, UInt32 freeSlot, UInt32 alignment, UInt32 flags, UInt32 globalMemorySize)
{
int percentUsage = (int)(((maxSlot - freeSlot)*100) / maxSlot);
progressBarSlot[index].Value = percentUsage;
if (percentUsage>80)
progressBarSlot[index].ForeColor = Color.Red;
else
if (percentUsage>50)
progressBarSlot[index].ForeColor = Color.Orange;
else
progressBarSlot[index].ForeColor = Color.Green;
labelSlot[index].Text = "Usage: " + (maxSlot - freeSlot).ToString() + "/" + maxSlot.ToString() +
" Al:" + alignment.ToString() + " Fl:" + flags.ToString() + " Mem: " + convertByte(globalMemorySize);
if (slotSize<1024)
labelSlotSize[index].Text = slotSize.ToString();
else if (slotSize<1024*1024)
labelSlotSize[index].Text = (slotSize/1024).ToString() + "Kb";
else
labelSlotSize[index].Text = (slotSize/(1024*1024)).ToString() + "Mb";
}
public void updateWarnings(String warnings)
{
warningsText.Text += warnings;
}
public void createSlot(UInt32 _count)
{
if (progressBarSlot != null)
return;
this.SuspendLayout();
progressBarSlot = new ContinuousProgressBar[_count];
labelSlot = new Label[_count];
labelSlotSize = new Label[_count];
for (int index = 0;index<_count;index++)
{
progressBarSlot[index] = new ContinuousProgressBar();
ProgressBar progressBar = progressBarSlot[index];
progressBar.Location = new System.Drawing.Point(100, 10 + index*26);
progressBar.Name = "progressBarSlot" + index;
progressBar.Size = new System.Drawing.Size(100, 18);
progressBar.TabIndex = index;
progressBar.Visible = true;
progressBar.Value = 20 + index * 3;
progressBar.BackColor = Color.White;
progressBar.ForeColor = Color.Red;
this.Controls.Add(progressBar);
labelSlot[index] = new Label();
Label label = labelSlot[index];
label.AutoSize = true;
label.Location = new System.Drawing.Point(220, 10+index*26);
label.Name = "labelSlot" + index.ToString();
label.Size = new System.Drawing.Size(35, 13);
label.TabIndex = 1;
label.Text = "";
this.Controls.Add(label);
labelSlotSize[index] = new Label();
label = labelSlotSize[index];
label.AutoSize = true;
label.Location = new System.Drawing.Point(20, 10 + index * 26);
label.Name = "labelSlotSize" + index.ToString();
label.Size = new System.Drawing.Size(35, 13);
label.TabIndex = 1;
label.Text = "";
this.Controls.Add(label);
}
this.ResumeLayout(false);
}
}
public class ContinuousProgressBar : ProgressBar
{
public ContinuousProgressBar()
{
this.Style = ProgressBarStyle.Continuous;
}
protected override void CreateHandle()
{
base.CreateHandle();
try { SetWindowTheme(this.Handle, "", ""); }
catch { }
}
[System.Runtime.InteropServices.DllImport("uxtheme.dll")]
private static extern int SetWindowTheme(IntPtr hwnd, string appname, string idlist);
}
}