浏览代码

UI: Fix padding with vertical volume meters

Since Yami uses a different font, the 0 dB mark at the top of the
vertical meters would be cut off. This adds a 1px padding to the top
and bottom of the volume meters, when in vertical mode.
cg2121 3 年之前
父节点
当前提交
94189402c2
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      UI/volume-control.cpp

+ 9 - 3
UI/volume-control.cpp

@@ -20,6 +20,9 @@ using namespace std;
 // Size of the audio indicator in pixels
 #define INDICATOR_THICKNESS 3
 
+// Padding on top and bottom of vertical meters
+#define METER_PADDING 1
+
 QWeakPointer<VolumeMeterTimer> VolumeMeter::updateTimer;
 
 void VolControl::OBSVolumeChanged(void *data, float db)
@@ -1035,7 +1038,7 @@ void VolumeMeter::paintVTicks(QPainter &painter, int x, int y, int height)
 
 	// Draw major tick lines and numeric indicators.
 	for (int i = 0; i >= minimumLevel; i -= 5) {
-		int position = y + int(i * scale);
+		int position = y + int(i * scale) + METER_PADDING;
 		QString str = QString::number(i);
 
 		// Center the number on the tick, but don't overflow
@@ -1054,7 +1057,7 @@ void VolumeMeter::paintVTicks(QPainter &painter, int x, int y, int height)
 	// Draw minor tick lines.
 	painter.setPen(minorTickColor);
 	for (int i = 0; i >= minimumLevel; i--) {
-		int position = y + int(i * scale);
+		int position = y + int(i * scale) + METER_PADDING;
 		if (i % 5 != 0)
 			painter.drawLine(x, position, x + 1, position);
 	}
@@ -1304,6 +1307,9 @@ void VolumeMeter::paintEvent(QPaintEvent *event)
 
 	QPainter painter(this);
 
+	if (vertical)
+		height -= METER_PADDING * 2;
+
 	// timerEvent requests update of the bar(s) only, so we can avoid the
 	// overhead of repainting the scale and labels.
 	if (event->region().boundingRect() != getBarRect()) {
@@ -1332,7 +1338,7 @@ void VolumeMeter::paintEvent(QPaintEvent *event)
 
 	if (vertical) {
 		// Invert the Y axis to ease the math
-		painter.translate(0, height);
+		painter.translate(0, height + METER_PADDING);
 		painter.scale(1, -1);
 	}