History

#19437 Adjust bandwith meter to be fixed width, not rescaling

stojce committed 13 years ago

Commit 112ae2b1 parent 75ccd3b1 file · +13 −6Browse files

Showing the changes to interface/src/BandwidthMeter.cpp (1 of 1 file). Show all

Unified · Split

interface/src/BandwidthMeter.cpp+13−6
@@ -13,7 +13,7 @@ · 12 unmodified lines
1313
1414 namespace { // .cpp-local
1515
16− int const AREA_WIDTH = -400; // Width of the area used. Aligned to the right when negative.
16+ int const AREA_WIDTH = -280; // Width of the area used. Aligned to the right when negative.
1717 int const AREA_HEIGHT = 40; // Height of the area used. Aligned to the bottom when negative.
1818 int const BORDER_DISTANCE_HORIZ = -20; // Distance to edge of screen (use negative value when width is negative).
1919 int const BORDER_DISTANCE_VERT = 40; // Distance to edge of screen (use negative value when height is negative).
@@ -33,6 +33,8 @@ namespace { // .cpp-local · 13 unmodified lines
3333
3434 double const UNIT_SCALE = 8000.0 / (1024.0 * 1024.0); // Bytes/ms -> Mbps
3535 int const INITIAL_SCALE_MAXIMUM_INDEX = 250; // / 9: exponent, % 9: mantissa - 2, 0 o--o 2 * 10^-10
36+ int const MIN_METER_SCALE = 10; // 10Mbps
37+ int const NUMBER_OF_MARKERS = 10;
3638 }
3739
3840 BandwidthMeter::ChannelInfo BandwidthMeter::_CHANNELS[] = {
@@ -182,7 +184,7 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { · 143 unmodified lines
182184 break;
183185 }
184186 if (totalMax < scaleMax * 0.5) {
185− _scaleMaxIndex = glm::max(0, _scaleMaxIndex-1);
187+ _scaleMaxIndex = glm::max(0, _scaleMaxIndex - 1);
186188 commit = true;
187189 } else if (totalMax > scaleMax) {
188190 _scaleMaxIndex += 1;
@@ -190,10 +192,15 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { · 1 unmodified line
190192 }
191193 } while (commit);
192194
195+ step = scaleMax / NUMBER_OF_MARKERS;
196+ if (scaleMax < MIN_METER_SCALE) {
197+ scaleMax = MIN_METER_SCALE;
198+ }
199+
193200 // Render scale indicators
194201 setColorRGBA(COLOR_INDICATOR);
195− for (int j = int((scaleMax + step - 0.000001) / step); --j > 0;) {
196− renderVerticalLine(int(barWidth * j * step / scaleMax), 0, h);
202+ for (int j = NUMBER_OF_MARKERS; --j > 0;) {
203+ renderVerticalLine(int(barWidth * j / NUMBER_OF_MARKERS), 0, h);
197204 }
198205
199206 // Render bars
@@ -220,11 +227,11 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { · 20 unmodified lines
220227 // Render numbers
221228 char fmtBuf[8];
222229 setColorRGBA(COLOR_TEXT);
223− sprintf(fmtBuf, "%0.2f", totalIn);
230+ sprintf(fmtBuf, "%0.1f", totalIn);
224231 _textRenderer.draw(glm::max(xIn - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE,
225232 PADDING_HORIZ_VALUE),
226233 textYupperLine, fmtBuf);
227− sprintf(fmtBuf, "%0.2f", totalOut);
234+ sprintf(fmtBuf, "%0.1f", totalOut);
228235 _textRenderer.draw(glm::max(xOut - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE,
229236 PADDING_HORIZ_VALUE),
230237 textYlowerLine, fmtBuf);