diff --git a/BatteryWidget/BatteryGraph.cs b/BatteryWidget/BatteryGraph.cs new file mode 100644 index 0000000..e011ce5 --- /dev/null +++ b/BatteryWidget/BatteryGraph.cs @@ -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 percentage; + + public BatteryGraph() { + isShowing = false; + + percentage = new List(); + } + + 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; + } + } + } +} \ No newline at end of file diff --git a/BatteryWidget/BatteryWidget.csproj b/BatteryWidget/BatteryWidget.csproj index a09e55e..7e8e129 100644 --- a/BatteryWidget/BatteryWidget.csproj +++ b/BatteryWidget/BatteryWidget.csproj @@ -41,6 +41,7 @@ + Form