]> git.sesse.net Git - nageru/commitdiff
Simplify draw_vu_meter().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Aug 2016 21:33:38 +0000 (23:33 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Aug 2016 21:34:11 +0000 (23:34 +0200)
lrameter.cpp
vu_common.cpp
vu_common.h
vumeter.cpp

index d0304e1a9e5a05082938ae817b4b21b9df5840b0..9ca7b016000d4170ef887d11f8e79ff74f366895 100644 (file)
@@ -21,12 +21,12 @@ void LRAMeter::resizeEvent(QResizeEvent *event)
        on_pixmap = QPixmap(width(), height());
        QPainter on_painter(&on_pixmap);
        on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
-       draw_vu_meter(on_painter, -HUGE_VAL, HUGE_VAL, width(), height(), margin);
+       draw_vu_meter(on_painter, width(), height(), margin, true);
 
        off_pixmap = QPixmap(width(), height());
        QPainter off_painter(&off_pixmap);
        off_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
-       draw_vu_meter(off_painter, -HUGE_VAL, -HUGE_VAL, width(), height(), margin);
+       draw_vu_meter(off_painter, width(), height(), margin, false);
 }
 
 void LRAMeter::paintEvent(QPaintEvent *event)
index d16b732e0625e88ee3183ef830c4a993c3c89658..50249699e62b77e0ac60c51faf019806058f93e4 100644 (file)
@@ -25,7 +25,7 @@ int lufs_to_pos(float level_lu, int height)
        return y;
 }
 
-void draw_vu_meter(QPainter &painter, float range_low_lu, float range_high_lu, int width, int height, int margin)
+void draw_vu_meter(QPainter &painter, int width, int height, int margin, bool is_on)
 {
        painter.fillRect(margin, 0, width - 2 * margin, height, Qt::black);
 
@@ -36,19 +36,15 @@ void draw_vu_meter(QPainter &painter, float range_low_lu, float range_high_lu, i
        on.setColorAt(1.0f, QColor(0, 255, 0));
        QColor off(80, 80, 80);
 
-       int min_on_y = lufs_to_pos(range_high_lu, height);
-       int max_on_y = lufs_to_pos(range_low_lu, height);
-
        // Draw bars colored up until the level, then gray from there.
        for (int level = -18; level < 9; ++level) {
                int min_y = lufs_to_pos(level + 1.0f, height) + 1;
                int max_y = lufs_to_pos(level, height) - 1;
 
-               painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off);
-               int min_draw_y = max(min_y, min_on_y);
-               int max_draw_y = min(max_y, max_on_y);
-               if (min_draw_y < max_draw_y) {
-                       painter.fillRect(margin, min_draw_y, width - 2 * margin, max_draw_y - min_draw_y, on);
+               if (is_on) {
+                       painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, on);
+               } else {
+                       painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off);
                }
        }
 }
index aa577214b191287b0c0d032a335d005c63bf8fe6..5df149ef94ea4cc3dfcdcfcf9f218fa72a0f4157 100644 (file)
@@ -5,8 +5,6 @@
 
 int lufs_to_pos(float level_lu, int height);
 
-// TODO: Now that we precalculate these as pixmaps, perhaps we don't need the
-// high/low range anymore, just a yes/no.
-void draw_vu_meter(QPainter &painter, float range_low_lu, float range_high_lu, int width, int height, int margin);
+void draw_vu_meter(QPainter &painter, int width, int height, int margin, bool is_on);
 
 #endif // !defined(_VU_COMMON_H)
index 9fca7ddc1c8712e5c214ff9b4bda313caf73018d..2e2d1c468c7e1fa434bb19e588d128ad999d3542 100644 (file)
@@ -14,11 +14,11 @@ void VUMeter::resizeEvent(QResizeEvent *event)
 {
        on_pixmap = QPixmap(width(), height());
        QPainter on_painter(&on_pixmap);
-       draw_vu_meter(on_painter, -HUGE_VAL, HUGE_VAL, width(), height(), 0);
+       draw_vu_meter(on_painter, width(), height(), 0, true);
 
        off_pixmap = QPixmap(width(), height());
        QPainter off_painter(&off_pixmap);
-       draw_vu_meter(off_painter, -HUGE_VAL, -HUGE_VAL, width(), height(), 0);
+       draw_vu_meter(off_painter, width(), height(), 0, false);
 }
 
 void VUMeter::paintEvent(QPaintEvent *event)