1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 23:57:26 -04:00

PlotDigitalEx optimization

This commit is contained in:
ozlb 2020-05-04 14:17:39 +02:00 committed by GitHub
parent 9b157783c7
commit 52ae8ff8cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2314,6 +2314,15 @@ inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int of
// render digital signals as "pixel bases" rectangles // render digital signals as "pixel bases" rectangles
if (count > 1 && rend_line) { if (count > 1 && rend_line) {
//
const float mx = (gp.PixelRange.Max.x - gp.PixelRange.Min.x) / (gp.CurrentPlot->XAxis.Max - gp.CurrentPlot->XAxis.Min);
int pixY_0 = line_weight;
int pixY_1 = gp.Style.DigitalBitHeight;
int pixY_Offset = 20;//20 pixel from bottom due to mouse cursor label
int pixY_chOffset = pixY_1 + 3; //3 pixels between channels
ImVec2 pMin, pMax;
float y0 = (gp.PixelRange.Min.y) + ((-pixY_chOffset * gp.DigitalPlotItemCnt) - pixY_0 - pixY_Offset);
float y1 = (gp.PixelRange.Min.y) + ((-pixY_chOffset * gp.DigitalPlotItemCnt) - pixY_1 - pixY_Offset);
const int segments = count - 1; const int segments = count - 1;
int i1 = offset; int i1 = offset;
for (int s = 0; s < segments; ++s) { for (int s = 0; s < segments; ++s) {
@ -2321,26 +2330,22 @@ inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int of
ImVec2 itemData1 = getter(i1); ImVec2 itemData1 = getter(i1);
ImVec2 itemData2 = getter(i2); ImVec2 itemData2 = getter(i2);
i1 = i2; i1 = i2;
const float mx = (gp.PixelRange.Max.x - gp.PixelRange.Min.x) / (gp.CurrentPlot->XAxis.Max - gp.CurrentPlot->XAxis.Min); pMin.x = gp.PixelRange.Min.x + mx * (itemData1.x - gp.CurrentPlot->XAxis.Min);
int pixY_0 = line_weight; pMin.y = (gp.PixelRange.Min.y) + ((-pixY_chOffset * gp.DigitalPlotItemCnt) - pixY_Offset);
int pixY_1 = gp.Style.DigitalBitHeight; pMax.x = gp.PixelRange.Min.x + mx * (itemData2.x - gp.CurrentPlot->XAxis.Min);
int pixY_Offset = 20;//20 pixel from bottom due to mouse cursor label pMax.y = (itemData1.y == 0.0) ? y0 : y1;
int pixY_chOffset = pixY_1 + 3; //3 pixels between channels while (((s+1) < segments) && (round(pMin.x) == round(pMax.x))) {
const int i2 = (i1 + 1) % count;
float y1 = (gp.PixelRange.Min.y) + ((-pixY_chOffset * gp.DigitalPlotItemCnt) - ((itemData1.y == 0.0) ? pixY_0 : pixY_1) - pixY_Offset); ImVec2 itemData2 = getter(i2);
float y2 = (gp.PixelRange.Min.y) + ((-pixY_chOffset * gp.DigitalPlotItemCnt) - pixY_Offset); pMax.x = gp.PixelRange.Min.x + mx * (itemData2.x - gp.CurrentPlot->XAxis.Min);
float l = gp.PixelRange.Min.x + mx * (itemData2.x - gp.CurrentPlot->XAxis.Min); pMax.y = (itemData1.y == 0.0) ? y0 : y1;
float r = gp.PixelRange.Min.x + mx * (itemData1.x - gp.CurrentPlot->XAxis.Min); i1 = i2;
s++;
ImVec2 cl, cr; }
cl.x = l; if (!cull || gp.BB_Grid.Contains(pMin) || gp.BB_Grid.Contains(pMax)) {
cl.y = y1;
cr.x = r;
cr.y = y2;
if (!cull || gp.BB_Grid.Contains(cl) || gp.BB_Grid.Contains(cr)) {
auto colAlpha = item->Color; auto colAlpha = item->Color;
colAlpha.w = item->Highlight ? 1.0 : 0.9; colAlpha.w = item->Highlight ? 1.0 : 0.9;
DrawList.AddRectFilled({l, y1}, {r, y2}, GetColorU32(colAlpha)); DrawList.AddRectFilled(pMin, pMax, GetColorU32(colAlpha));
} }
} }
gp.DigitalPlotItemCnt++; gp.DigitalPlotItemCnt++;