summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/slider.cc17
-rw-r--r--plugingui/slider.h37
2 files changed, 32 insertions, 22 deletions
diff --git a/plugingui/slider.cc b/plugingui/slider.cc
index 439e104..78877b2 100644
--- a/plugingui/slider.cc
+++ b/plugingui/slider.cc
@@ -62,14 +62,15 @@ void Slider::repaintEvent(RepaintEvent* repaintEvent)
auto inner_offset = (current_value / maximum) * getControlWidth();
auto button_x = button_offset + inner_offset - (button.width() / 2);
- auto button_y = (height() - button.height())/2;
+ auto button_y = (height() - button.height()) / 2;
// draw bar
bar.setSize(width(), height());
p.drawImage(0, 0, bar);
// draw inner bar
- inner_bar_green.setSize(button_x - bar_boundary, height() - 2*bar_boundary);
+ inner_bar_green.setSize(
+ button_x - bar_boundary, height() - 2 * bar_boundary);
p.drawImage(bar_boundary, bar_boundary, inner_bar_green);
// draw button
@@ -146,22 +147,24 @@ void Slider::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent)
std::size_t Slider::getControlWidth() const
{
- if (width() < 2*button_offset) {
+ if(width() < 2 * button_offset)
+ {
return 0;
}
- return width() - 2*button_offset;
+ return width() - 2 * button_offset;
}
void Slider::recomputeCurrentValue(float x)
{
- if (x < button_offset) {
+ if(x < button_offset)
+ {
current_value = 0;
}
- else {
+ else
+ {
current_value = (maximum / getControlWidth()) * (x - button_offset);
}
-
}
} // GUI::
diff --git a/plugingui/slider.h b/plugingui/slider.h
index 22d162d..26e82ba 100644
--- a/plugingui/slider.h
+++ b/plugingui/slider.h
@@ -26,22 +26,29 @@
*/
#pragma once
-#include "widget.h"
#include "texture.h"
#include "texturedbox.h"
+#include "widget.h"
namespace GUI
{
-class Slider : public Widget
+class Slider
+ : public Widget
{
public:
Slider(Widget* parent);
virtual ~Slider() = default;
// From Widget:
- bool catchMouse() override { return true; }
- bool isFocusable() override { return true; }
+ bool catchMouse() override
+ {
+ return true;
+ }
+ bool isFocusable() override
+ {
+ return true;
+ }
void setValue(float new_value);
float value() const;
@@ -66,15 +73,15 @@ private:
State state;
- TexturedBox bar{getImageCache(), ":slider.png",
- 0, 0, // atlas offset (x, y)
- 7, 1, 7, // dx1, dx2, dx3
- 7, 1, 7 // dy1, dy2, dy3
+ TexturedBox bar{
+ getImageCache(), ":slider.png", 0, 0, // atlas offset (x, y)
+ 7, 1, 7, // dx1, dx2, dx3
+ 7, 1, 7 // dy1, dy2, dy3
};
- TexturedBox inner_bar_green{getImageCache(), ":slider.png",
- 30, 0, // atlas offset (x, y)
- 2, 1, 2, // dx1, dx2, dx3
- 2, 1, 2 // dy1, dy2, dy3
+ TexturedBox inner_bar_green{
+ getImageCache(), ":slider.png", 30, 0, // atlas offset (x, y)
+ 2, 1, 2, // dx1, dx2, dx3
+ 2, 1, 2 // dy1, dy2, dy3
};
// TexturedBox inner_bar_red{getImageCache(), ":slider.png",
// 30, 5, // atlas offset (x, y)
@@ -86,9 +93,9 @@ private:
// 2, 1, 2, // dx1, dx2, dx3
// 2, 1, 2 // dy1, dy2, dy3
// };
- Texture button{getImageCache(), ":slider.png",
- 15, 0, // atlas offset (x, y)
- 15, 15 // width, height
+ Texture button{
+ getImageCache(), ":slider.png", 15, 0, // atlas offset (x, y)
+ 15, 15 // width, height
};
std::size_t bar_boundary{5};