diff options
Diffstat (limited to 'src/gui/widgets/slider.cpp')
-rw-r--r-- | src/gui/widgets/slider.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 700d31416..e440631ad 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -76,6 +76,8 @@ #include "resources/image.h" +#include "utils/delete2.h" + #include "debug.h" ImageRect Slider::buttons[2]; @@ -130,10 +132,9 @@ Slider::~Slider() if (gui) gui->removeDragged(this); - delete mVertexes; - mVertexes = nullptr; + delete2(mVertexes); mInstances--; - if (mInstances == 0 && Theme::instance()) + if (mInstances == 0) { for (int mode = 0; mode < 2; mode ++) Theme::unloadRect(buttons[mode]); @@ -142,6 +143,7 @@ Slider::~Slider() void Slider::init() { + mAllowLogic = false; setFocusable(true); setFrameSize(1); @@ -153,7 +155,6 @@ void Slider::init() // Load resources if (mInstances == 0) { - Theme *const theme = Theme::instance(); if (theme) { for (int mode = 0; mode < 2; mode ++) @@ -171,7 +172,7 @@ void Slider::init() void Slider::updateAlpha() { const float alpha = std::max(client->getGuiAlpha(), - Theme::instance()->getMinimumOpacity()); + theme->getMinimumOpacity()); if (alpha != mAlpha) { @@ -352,16 +353,17 @@ void Slider::mouseExited(MouseEvent& event A_UNUSED) mRedraw = true; } -void Slider::mousePressed(MouseEvent &mouseEvent) +void Slider::mousePressed(MouseEvent &event) { - const int x = mouseEvent.getX(); - const int y = mouseEvent.getY(); + const int x = event.getX(); + const int y = event.getY(); const int width = mDimension.width; const int height = mDimension.height; - if (mouseEvent.getButton() == MouseEvent::LEFT + if (event.getButton() == MouseEvent::LEFT && x >= 0 && x <= width && y >= 0 && y <= height) { + event.consume(); if (mOrientation == HORIZONTAL) setValue(markerPositionToValue(x - mMarkerLength / 2)); else @@ -371,40 +373,40 @@ void Slider::mousePressed(MouseEvent &mouseEvent) } } -void Slider::mouseDragged(MouseEvent &mouseEvent) +void Slider::mouseDragged(MouseEvent &event) { if (mOrientation == HORIZONTAL) { - setValue(markerPositionToValue(mouseEvent.getX() - mMarkerLength / 2)); + setValue(markerPositionToValue(event.getX() - mMarkerLength / 2)); } else { setValue(markerPositionToValue( - mDimension.height - mouseEvent.getY() - mMarkerLength / 2)); + mDimension.height - event.getY() - mMarkerLength / 2)); } distributeActionEvent(); - mouseEvent.consume(); + event.consume(); } -void Slider::mouseWheelMovedUp(MouseEvent &mouseEvent) +void Slider::mouseWheelMovedUp(MouseEvent &event) { setValue(mValue + mStepLength); distributeActionEvent(); - mouseEvent.consume(); + event.consume(); } -void Slider::mouseWheelMovedDown(MouseEvent &mouseEvent) +void Slider::mouseWheelMovedDown(MouseEvent &event) { setValue(mValue - mStepLength); distributeActionEvent(); - mouseEvent.consume(); + event.consume(); } -void Slider::keyPressed(KeyEvent& keyEvent) +void Slider::keyPressed(KeyEvent& event) { - const int action = keyEvent.getActionId(); + const int action = event.getActionId(); if (mOrientation == HORIZONTAL) { @@ -412,13 +414,13 @@ void Slider::keyPressed(KeyEvent& keyEvent) { setValue(mValue + mStepLength); distributeActionEvent(); - keyEvent.consume(); + event.consume(); } else if (action == Input::KEY_GUI_LEFT) { setValue(mValue - mStepLength); distributeActionEvent(); - keyEvent.consume(); + event.consume(); } } else @@ -427,13 +429,13 @@ void Slider::keyPressed(KeyEvent& keyEvent) { setValue(mValue + mStepLength); distributeActionEvent(); - keyEvent.consume(); + event.consume(); } else if (action == Input::KEY_GUI_DOWN) { setValue(mValue - mStepLength); distributeActionEvent(); - keyEvent.consume(); + event.consume(); } } } |