Add class BatteryGraph
This commit is contained in:
parent
2242ee4df6
commit
c93e039234
56
BatteryWidget/BatteryGraph.cs
Normal file
56
BatteryWidget/BatteryGraph.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BatteryWidget {
|
||||||
|
|
||||||
|
public class BatteryGraph {
|
||||||
|
|
||||||
|
private const int MAX_GRAPH_POINTS = 50;
|
||||||
|
|
||||||
|
private bool isShowing;
|
||||||
|
private List<int> percentage;
|
||||||
|
|
||||||
|
public BatteryGraph() {
|
||||||
|
isShowing = false;
|
||||||
|
|
||||||
|
percentage = new List<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool graphIsShowing() {
|
||||||
|
return isShowing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool revertShowState() {
|
||||||
|
isShowing = !isShowing;
|
||||||
|
return isShowing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPercent(int currentPercentage) {
|
||||||
|
percentage.Add(currentPercentage);
|
||||||
|
|
||||||
|
while (percentage.Count >= MAX_GRAPH_POINTS) {
|
||||||
|
percentage.RemoveAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawGraph(Graphics g) {
|
||||||
|
float width = g.VisibleClipBounds.Width;
|
||||||
|
float height = g.VisibleClipBounds.Height;
|
||||||
|
|
||||||
|
float deltaX = width / MAX_GRAPH_POINTS;
|
||||||
|
float x1 = 0;
|
||||||
|
float y1 = (100 - percentage[0]) * height / 100;
|
||||||
|
for (int i = 1; i < percentage.Count; i++) {
|
||||||
|
float x2 = x1 + deltaX;
|
||||||
|
float y2 = (100 - percentage[i]) * height / 100;
|
||||||
|
|
||||||
|
g.DrawLine(Pens.Silver, x1, y1, x2, y2);
|
||||||
|
|
||||||
|
x1 = x2;
|
||||||
|
y1 = y2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,6 +41,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Battery.cs" />
|
<Compile Include="Battery.cs" />
|
||||||
|
<Compile Include="BatteryGraph.cs" />
|
||||||
<Compile Include="WidgetForm.cs">
|
<Compile Include="WidgetForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
Loading…
Reference in New Issue
Block a user