diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-14 17:39:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-14 20:37:31 +0300 |
commit | 9fc07b15f1b051eecd662802162772804dc77b8e (patch) | |
tree | d100d50693fc19edb32d01b9189603bdd3254bd2 /src/gui/widgets/button.cpp | |
parent | 78ae06d2c7b565afe67c5032c872d68a74ea210a (diff) | |
download | manaplus-9fc07b15f1b051eecd662802162772804dc77b8e.tar.gz manaplus-9fc07b15f1b051eecd662802162772804dc77b8e.tar.bz2 manaplus-9fc07b15f1b051eecd662802162772804dc77b8e.tar.xz manaplus-9fc07b15f1b051eecd662802162772804dc77b8e.zip |
Rename class InventoryFilter to RadioGroup.
Add WidgetGroup and TabStrip classes for grouping controls.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r-- | src/gui/widgets/button.cpp | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 9519c144f..88d9311b9 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -79,7 +79,9 @@ Button::Button() : mXOffset(0), mYOffset(0), mImages(nullptr), - mImageSet(nullptr) + mImageSet(nullptr), + mStick(false), + mPressed(false) { init(); adjustSize(); @@ -99,7 +101,9 @@ Button::Button(const std::string &caption, const std::string &actionEventId, mImages(nullptr), mImageSet(nullptr), mImageWidth(0), - mImageHeight(0) + mImageHeight(0), + mStick(false), + mPressed(false) { init(); adjustSize(); @@ -125,7 +129,9 @@ Button::Button(const std::string &caption, const std::string &imageName, mImages(nullptr), mImageSet(nullptr), mImageWidth(imageWidth), - mImageHeight(imageHeight) + mImageHeight(imageHeight), + mStick(false), + mPressed(false) { init(); loadImage(imageName); @@ -151,7 +157,9 @@ Button::Button(const std::string &imageName, int imageWidth, int imageHeight, mImages(nullptr), mImageSet(nullptr), mImageWidth(imageWidth), - mImageHeight(imageHeight) + mImageHeight(imageHeight), + mStick(false), + mPressed(false) { init(); loadImage(imageName); @@ -286,7 +294,7 @@ void Button::draw(gcn::Graphics *graphics) if (!isEnabled()) mode = BUTTON_DISABLED; - else if (isPressed()) + else if (isPressed2()) mode = BUTTON_PRESSED; else if (mHasMouse || isFocused()) mode = BUTTON_HIGHLIGHTED; @@ -399,18 +407,22 @@ void Button::draw(gcn::Graphics *graphics) void Button::mouseReleased(gcn::MouseEvent& mouseEvent) { - if (mouseEvent.getButton() == gcn::MouseEvent::LEFT - && mMousePressed && mHasMouse) - { - mMousePressed = false; - mClickCount = mouseEvent.getClickCount(); - distributeActionEvent(); - mouseEvent.consume(); - } - else if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) + if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { - mMousePressed = false; - mClickCount = 0; + if (mStick) + mPressed = !mPressed; + + if (mMousePressed && mHasMouse) + { + mMousePressed = false; + mClickCount = mouseEvent.getClickCount(); + distributeActionEvent(); + } + else + { + mMousePressed = false; + mClickCount = 0; + } mouseEvent.consume(); } } @@ -446,7 +458,6 @@ void Button::adjustSize() void Button::setCaption(const std::string& caption) { mCaption = caption; -// adjustSize(); } void Button::keyPressed(gcn::KeyEvent& keyEvent) @@ -467,7 +478,15 @@ void Button::keyReleased(gcn::KeyEvent& keyEvent) if (key.getValue() == gcn::Key::SPACE && mKeyPressed) { mKeyPressed = false; + if (mStick) + mPressed = !mPressed; distributeActionEvent(); keyEvent.consume(); } } + + +bool Button::isPressed2() +{ + return (mPressed || isPressed()); +} |