summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-05-01 18:50:27 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-05-01 18:50:27 +0200
commit5d4c9b511e3feef507549384816a45a962fc9df4 (patch)
treedbb35fa03edee2cb09572fce86eee31719725bef
parentf40de463adc75ff53d968b0a8d0154b022007e45 (diff)
Rotate y-axis label.
-rw-r--r--plugingui/painter.cc43
-rw-r--r--plugingui/painter.h2
-rw-r--r--plugingui/powerwidget.cc4
3 files changed, 44 insertions, 5 deletions
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index bc4abc3..f2fc66a 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -175,11 +175,14 @@ void Painter::clear()
}
void Painter::drawText(int x0, int y0, const Font& font,
- const std::string& text, bool nocolour)
+ const std::string& text, bool nocolour, bool rotate)
{
PixelBufferAlpha* textbuf = font.render(text);
- y0 -= textbuf->height; // The y0 offset (baseline) is the bottom of the text.
+ if(!rotate)
+ {
+ y0 -= textbuf->height; // The y0 offset (baseline) is the bottom of the text.
+ }
// If the text offset is outside the buffer; skip it.
if((x0 > (int)pixbuf.width) || (y0 > (int)pixbuf.height))
@@ -222,6 +225,42 @@ void Painter::drawText(int x0, int y0, const Font& font,
pixbuf.blendLine(x + x0, y + y0, c, renderWidth - x);
}
}
+ else if(rotate)
+ {
+ int renderWidth = textbuf->height;
+ if(renderWidth > (int)(pixbuf.width - x0))
+ {
+ renderWidth = pixbuf.width - x0;
+ }
+
+ int renderHeight = textbuf->width;
+ if(renderHeight > ((int)pixbuf.height - y0))
+ {
+ renderHeight = ((int)pixbuf.height - y0);
+ }
+
+ for(int y = -1 * std::min(0, y0); y < renderHeight; ++y)
+ {
+ for(int x = -1 * std::min(0, x0); x < renderWidth; ++x)
+ {
+ assert(x >= 0);
+ assert(y >= 0);
+ assert(x < (int)textbuf->height);
+ assert(y < (int)textbuf->width);
+
+ auto c = textbuf->pixel(textbuf->width - y - 1, x);
+
+ assert(x + x0 >= 0);
+ assert(y + y0 >= 0);
+ assert(x + x0 < (int)pixbuf.width);
+ assert(y + y0 < (int)pixbuf.height);
+
+ Colour col(colour.red(), colour.green(),
+ colour.blue(), (int)(colour.alpha() * c.alpha()) / 255);
+ pixbuf.addPixel(x + x0, y + y0, col);
+ }
+ }
+ }
else
{
for(int y = -1 * std::min(0, y0); y < renderHeight; ++y)
diff --git a/plugingui/painter.h b/plugingui/painter.h
index b38bf88..9bf7fbf 100644
--- a/plugingui/painter.h
+++ b/plugingui/painter.h
@@ -49,7 +49,7 @@ public:
void drawLine(int x1, int y1, int x2, int y2);
void drawText(int x, int y, const Font& font, const std::string& text,
- bool nocolour = false);
+ bool nocolour = false, bool rotate = false);
void drawRectangle(int x1, int y1, int x2, int y2);
void drawFilledRectangle(int x1, int y1, int x2, int y2);
void drawPoint(int x, int y);
diff --git a/plugingui/powerwidget.cc b/plugingui/powerwidget.cc
index 3ea787c..3cb289a 100644
--- a/plugingui/powerwidget.cc
+++ b/plugingui/powerwidget.cc
@@ -205,8 +205,8 @@ void PowerWidget::Canvas::repaintEvent(GUI::RepaintEvent *repaintEvent)
y0 + height0 - std::round(power_map.getFixed2().out * height0), rad + 1);
p.setColour(GUI::Colour(1.0f, 1.0f, 1.0f, 0.2f));
- p.drawText(width() / 2, height() - 8, font, "in");
- p.drawText(16, height() / 2 + 8, font, "out");
+ p.drawText(width() / 2 - (font.textWidth("in") / 2), height() - 8, font, "in");
+ p.drawText(8, height() / 2 - (font.textWidth("out") / 2), font, "out", false, true);
}
void PowerWidget::Canvas::buttonEvent(GUI::ButtonEvent* buttonEvent)