Add class BatteryGraph

This commit is contained in:
Victor 2013-10-07 18:26:27 +03:00
parent 2242ee4df6
commit c93e039234
2 changed files with 57 additions and 0 deletions

View 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;
}
}
}
}

View File

@ -41,6 +41,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Battery.cs" />
<Compile Include="BatteryGraph.cs" />
<Compile Include="WidgetForm.cs">
<SubType>Form</SubType>
</Compile>