]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - winsrc/gui.cpp
Added a way to overlay a grid to graph window
[proxmark3-svn] / winsrc / gui.cpp
index da83c865e7e82108e01d70cf803c9fde7921100a..bcc0cbb65958cbda97c9c392e765d92a34adc18c 100644 (file)
@@ -34,12 +34,13 @@ void dbp(char *str, ...)
 int GraphBuffer[MAX_GRAPH_TRACE_LEN];\r
 int GraphTraceLen;\r
 \r
-HPEN GreyPen, GreenPen, WhitePen, YellowPen;\r
+HPEN GreyPenLite, GreyPen, GreenPen, WhitePen, YellowPen;\r
 HBRUSH GreenBrush, YellowBrush;\r
 \r
 static int GraphStart = 0;\r
 static double GraphPixelsPerPoint = 1;\r
 \r
+static int PlotGridX = 0, PlotGridY = 0;\r
 static int CursorAPos;\r
 static int CursorBPos;\r
 double CursorScaleFactor = 1.0;\r
@@ -61,11 +62,17 @@ static HFONT MyFixedFont;
 \r
 void ExecCmd(char *cmd)\r
 {\r
-\r
 }\r
+\r
 int CommandFinished;\r
 int offset = 64;\r
 \r
+void SetGraphGrid(int x, int y)\r
+{\r
+       PlotGridX = x;\r
+       PlotGridY = y;\r
+}\r
+\r
 static void ResizeCommandWindow(void)\r
 {\r
        int w, h;\r
@@ -108,43 +115,63 @@ static LRESULT CALLBACK
 \r
 static void PaintGraph(HDC hdc)\r
 {\r
+       RECT r;\r
        HBRUSH brush;\r
        HPEN pen;\r
+       char str[250];\r
+       int yMin = INT_MAX;\r
+       int yMax = INT_MIN;\r
+       int yMean = 0;\r
+       int startMax = 0;\r
+       int absYMax = 1;\r
+       int n = 0, i = 0;\r
 \r
        brush = GreenBrush;\r
        pen = GreenPen;\r
 \r
-       if(GraphStart < 0) {\r
-               GraphStart = 0;\r
-       }\r
-\r
-       RECT r;\r
        GetClientRect(GraphWindow, &r);\r
+       int zeroHeight = (r.top + r.bottom) >> 1;\r
+\r
+       // plot X and Y grid lines\r
+       if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {\r
+               for(i = offset; i < r.right; i += (int)(PlotGridX * GraphPixelsPerPoint)) {\r
+                       SelectObject(hdc, GreyPenLite);\r
+                       MoveToEx(hdc, r.left + i, r.top, NULL);\r
+                       LineTo(hdc, r.left + i, r.bottom);\r
+               }\r
+  }\r
+\r
+       if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){\r
+               for(i = 0; i < ((r.top + r.bottom)>>1); i += (int)(PlotGridY * GraphPixelsPerPoint)) {\r
+                       SelectObject(hdc, GreyPenLite);\r
+                       MoveToEx(hdc, r.left, zeroHeight + i, NULL);\r
+                       LineTo(hdc, r.right, zeroHeight + i);\r
+                       MoveToEx(hdc, r.left, zeroHeight - i, NULL);\r
+                       LineTo(hdc, r.right, zeroHeight - i);\r
+               }\r
+  }\r
 \r
+       // print vertical separator white line on the left of the window\r
        SelectObject(hdc, WhitePen);\r
-\r
        MoveToEx(hdc, r.left + offset, r.top, NULL);\r
        LineTo(hdc, r.left + offset, r.bottom);\r
 \r
-       int zeroHeight = r.top + (r.bottom - r.top) / 2;\r
+       // print horizontal grey zero axis line\r
        SelectObject(hdc, GreyPen);\r
        MoveToEx(hdc, r.left, zeroHeight, NULL);\r
        LineTo(hdc, r.right, zeroHeight);\r
 \r
-       int startMax =\r
-               (GraphTraceLen - (int)((r.right - r.left - offset) / GraphPixelsPerPoint));\r
-       if(startMax < 0) {\r
-               startMax = 0;\r
-       }\r
-       if(GraphStart > startMax) {\r
-               GraphStart = startMax;\r
-       }\r
+       startMax = (GraphTraceLen - (int)((r.right - r.left - offset) / GraphPixelsPerPoint));\r
+       // check boundaries\r
+       if(startMax < 0) startMax = 0;\r
+       if(GraphStart > startMax) GraphStart = startMax;\r
+       if(GraphStart < 0) GraphStart = 0;\r
 \r
-       int absYMax = 1;\r
 \r
        SelectObject(hdc, pen);\r
 \r
-       int i;\r
+       // go over the portion of the graph to be displayed and find the largest\r
+       // absolute value which will be used to auto scale the graph when displayed\r
        for(i = GraphStart; ; i++) {\r
                if(i >= GraphTraceLen) {\r
                        break;\r
@@ -174,11 +201,7 @@ static void PaintGraph(HDC hdc)
        if(pointsPerLabel <= 0) pointsPerLabel = 1;\r
        pointsPerLabel = (int)pow(2.0,pointsPerLabel);\r
 \r
-       int yMin = INT_MAX;\r
-       int yMax = INT_MIN;\r
-       int yMean = 0;\r
-       int n = 0;\r
-\r
+       // go over the graph and plot samples and labels\r
        for(i = GraphStart; ; i++) {\r
                if(i >= GraphTraceLen) {\r
                        break;\r
@@ -189,12 +212,8 @@ static void PaintGraph(HDC hdc)
                }\r
 \r
                int y = GraphBuffer[i];\r
-               if(y < yMin) {\r
-                       yMin = y;\r
-               }\r
-               if(y > yMax) {\r
-                       yMax = y;\r
-               }\r
+               if(y < yMin) yMin = y;\r
+               if(y > yMax) yMax = y;\r
                yMean += y;\r
                n++;\r
 \r
@@ -214,13 +233,13 @@ static void PaintGraph(HDC hdc)
                        FillRect(hdc, &f, brush);\r
                }\r
 \r
+               // plot labels\r
                if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) {\r
                        SelectObject(hdc, WhitePen);\r
                        MoveToEx(hdc, x, zeroHeight - 8, NULL);\r
                        LineTo(hdc, x, zeroHeight + 8);\r
 \r
-                       char str[100];\r
-                       sprintf(str, "+%d", (i - GraphStart));\r
+                       sprintf(str, "+%d", i);\r
                        SIZE size;\r
                        GetTextExtentPoint32(hdc, str, strlen(str), &size);\r
                        TextOut(hdc, x - size.cx, zeroHeight + 8, str, strlen(str));\r
@@ -229,6 +248,7 @@ static void PaintGraph(HDC hdc)
                        MoveToEx(hdc, x, y, NULL);\r
                }\r
 \r
+               // plot measurement cursors\r
                if(i == CursorAPos || i == CursorBPos) {\r
                        if(i == CursorAPos) {\r
                                SelectObject(hdc, CursorAPen);\r
@@ -247,8 +267,7 @@ static void PaintGraph(HDC hdc)
                yMean /= n;\r
        }\r
 \r
-       char str[200];\r
-\r
+       // print misc information at bottom of graph window\r
        sprintf(str, "@%d   max=%d min=%d mean=%d n=%d/%d    dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]",\r
                GraphStart, yMax, yMin, yMean, n, GraphTraceLen,\r
                CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, GraphPixelsPerPoint,\r
@@ -438,6 +457,7 @@ void ShowGui()
        PrintToScrollback(">> Started prox, built " __DATE__ " " __TIME__);\r
        PrintToScrollback(">> Connected to device");\r
 \r
+       GreyPenLite = CreatePen(PS_SOLID, 1, RGB(50, 50, 50));\r
        GreyPen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));\r
        GreenPen = CreatePen(PS_SOLID, 1, RGB(100, 255, 100));\r
        YellowPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 0));\r
Impressum, Datenschutz