diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-17 18:31:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-17 18:31:26 +0300 |
commit | 3ae7d2eff3d20c3042ddac4fd4f205812079b94e (patch) | |
tree | f4fb1bc99383c05457e1958e4c825e285f2097ab /src | |
parent | d0827ddf1686bdb97fab96f9f26dc95388919011 (diff) | |
download | manaverse-3ae7d2eff3d20c3042ddac4fd4f205812079b94e.tar.gz manaverse-3ae7d2eff3d20c3042ddac4fd4f205812079b94e.tar.bz2 manaverse-3ae7d2eff3d20c3042ddac4fd4f205812079b94e.tar.xz manaverse-3ae7d2eff3d20c3042ddac4fd4f205812079b94e.zip |
Extend checkbox theming.
New options:
padding - padding from all sides except left
imagePadding - padding from left before image
imageSize - image size for computation width
spacing - space between image and text
width = imagePadding + imageSize + spacing + text width + padding
height = padding + text height + padding
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/logindialog.h | 6 | ||||
-rw-r--r-- | src/gui/setup_joystick.h | 10 | ||||
-rw-r--r-- | src/gui/setup_relations.h | 6 | ||||
-rw-r--r-- | src/gui/setup_video.h | 12 | ||||
-rw-r--r-- | src/gui/shopwindow.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/checkbox.cpp | 144 | ||||
-rw-r--r-- | src/gui/widgets/checkbox.h | 17 | ||||
-rw-r--r-- | src/guichan/widgets/checkbox.cpp | 4 |
8 files changed, 80 insertions, 121 deletions
diff --git a/src/gui/logindialog.h b/src/gui/logindialog.h index 8cc94df04..d08eade5e 100644 --- a/src/gui/logindialog.h +++ b/src/gui/logindialog.h @@ -33,6 +33,7 @@ #include <vector> class Button; +class CheckBox; class DropDown; class Label; class LoginData; @@ -41,7 +42,6 @@ class UpdateTypeModel; namespace gcn { - class CheckBox; class TextField; } @@ -90,7 +90,7 @@ class LoginDialog final : public Window, public gcn::ActionListener, gcn::TextField *mUserField; gcn::TextField *mPassField; - gcn::CheckBox *mKeepCheck; + CheckBox *mKeepCheck; Label *mUpdateTypeLabel; Label *mUpdateHostLabel; UpdateTypeModel *mUpdateTypeModel; @@ -98,7 +98,7 @@ class LoginDialog final : public Window, public gcn::ActionListener, Button *mServerButton; Button *mLoginButton; Button *mRegisterButton; - gcn::CheckBox *mCustomUpdateHost; + CheckBox *mCustomUpdateHost; gcn::TextField *mUpdateHostText; UpdateListModel *mUpdateListModel; DropDown *mUpdateHostDropDown; diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index 2082414dc..17b8f6df1 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -28,15 +28,11 @@ #include <guichan/actionlistener.hpp> class Button; +class CheckBox; class DropDown; class Label; class NamesModel; -namespace gcn -{ - class CheckBox; -} - class Setup_Joystick final : public SetupTab { public: @@ -58,10 +54,10 @@ class Setup_Joystick final : public SetupTab Label *mCalibrateLabel; Button *mCalibrateButton; bool mOriginalJoystickEnabled; - gcn::CheckBox *mJoystickEnabled; + CheckBox *mJoystickEnabled; NamesModel *mNamesModel; DropDown *mNamesDropDown; - gcn::CheckBox *mUseInactiveCheckBox; + CheckBox *mUseInactiveCheckBox; }; #endif diff --git a/src/gui/setup_relations.h b/src/gui/setup_relations.h index 0e663aed6..8564c8ab7 100644 --- a/src/gui/setup_relations.h +++ b/src/gui/setup_relations.h @@ -30,6 +30,7 @@ #include <guichan/actionlistener.hpp> class Button; +class CheckBox; class EditDialog; class GuiTable; class PlayerTableModel; @@ -37,7 +38,6 @@ class StaticTableModel; namespace gcn { - class CheckBox; class DropDown; class ListModel; class ScrollArea; @@ -74,8 +74,8 @@ private: GuiTable *mPlayerTitleTable; gcn::ScrollArea *mPlayerScrollArea; - gcn::CheckBox *mDefaultTrading; - gcn::CheckBox *mDefaultWhisper; + CheckBox *mDefaultTrading; + CheckBox *mDefaultWhisper; Button *mDeleteButton; diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 6ae5af1d6..6144de8d8 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -31,6 +31,7 @@ #include <guichan/keylistener.hpp> class Button; +class CheckBox; class Label; class ListBox; class ModeListModel; @@ -39,7 +40,6 @@ class TextDialog; namespace gcn { - class CheckBox; class DropDown; class Slider; } @@ -78,14 +78,14 @@ class Setup_Video final : public SetupTab, public gcn::KeyListener Label *scrollLazinessLabel; ListBox *mModeList; - gcn::CheckBox *mFsCheckBox; + CheckBox *mFsCheckBox; gcn::DropDown *mOpenGLDropDown; - gcn::CheckBox *mCustomCursorCheckBox; + CheckBox *mCustomCursorCheckBox; - gcn::CheckBox *mEnableResizeCheckBox; - gcn::CheckBox *mNoFrameCheckBox; + CheckBox *mEnableResizeCheckBox; + CheckBox *mNoFrameCheckBox; - gcn::CheckBox *mFpsCheckBox; + CheckBox *mFpsCheckBox; gcn::Slider *mFpsSlider; Label *mFpsLabel; gcn::Slider *mAltFpsSlider; diff --git a/src/gui/shopwindow.h b/src/gui/shopwindow.h index 11e7f5e69..dbf102f85 100644 --- a/src/gui/shopwindow.h +++ b/src/gui/shopwindow.h @@ -164,7 +164,7 @@ class ShopWindow final : public Window, public gcn::ActionListener, Button *mSellDeleteButton; Button *mSellAnnounceButton; Button *mSellAuctionButton; - gcn::CheckBox *mAnnounceLinks; + CheckBox *mAnnounceLinks; int mSelectedItem; int mAnnonceTime; diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 44d504d2c..8349247a4 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -34,58 +34,30 @@ #include "resources/image.h" #include <guichan/actionlistener.hpp> +#include <guichan/font.hpp> #include "debug.h" int CheckBox::instances = 0; +Skin *CheckBox::mSkin = nullptr; float CheckBox::mAlpha = 1.0; -Image *CheckBox::checkBoxNormal; -Image *CheckBox::checkBoxChecked; -Image *CheckBox::checkBoxDisabled; -Image *CheckBox::checkBoxDisabledChecked; -Image *CheckBox::checkBoxNormalHi; -Image *CheckBox::checkBoxCheckedHi; CheckBox::CheckBox(const std::string &caption, const bool selected, gcn::ActionListener *const listener, const std::string &eventId) : gcn::CheckBox(caption, selected), - mHasMouse(false) + mHasMouse(false), + mPadding(0), + mImagePadding(0), + mImageSize(9), + mSpacing(2) { if (instances == 0) { if (Theme::instance()) { - ImageRect rect; - Theme::instance()->loadRect(rect, "checkbox.xml", "", 0, 5); - checkBoxNormal = rect.grid[0]; - checkBoxChecked = rect.grid[1]; - checkBoxDisabled = rect.grid[2]; - checkBoxDisabledChecked = rect.grid[3]; - checkBoxNormalHi = rect.grid[4]; - checkBoxCheckedHi = rect.grid[5]; - - if (checkBoxNormal) - checkBoxNormal->setAlpha(mAlpha); - if (checkBoxChecked) - checkBoxChecked->setAlpha(mAlpha); - if (checkBoxDisabled) - checkBoxDisabled->setAlpha(mAlpha); - if (checkBoxDisabledChecked) - checkBoxDisabledChecked->setAlpha(mAlpha); - if (checkBoxNormalHi) - checkBoxNormalHi->setAlpha(mAlpha); - if (checkBoxCheckedHi) - checkBoxCheckedHi->setAlpha(mAlpha); - } - else - { - checkBoxNormal = nullptr; - checkBoxChecked = nullptr; - checkBoxDisabled = nullptr; - checkBoxDisabledChecked = nullptr; - checkBoxNormalHi = nullptr; - checkBoxCheckedHi = nullptr; + mSkin = Theme::instance()->load("checkbox.xml", ""); + updateAlpha(); } } @@ -98,6 +70,14 @@ CheckBox::CheckBox(const std::string &caption, const bool selected, addActionListener(listener); mForegroundColor = Theme::getThemeColor(Theme::CHECKBOX); + if (mSkin) + { + mPadding = mSkin->getPadding(); + mImagePadding = mSkin->getOption("imagePadding"); + mImageSize = mSkin->getOption("imageSize"); + mSpacing = mSkin->getOption("spacing"); + } + adjustSize(); } CheckBox::~CheckBox() @@ -106,36 +86,8 @@ CheckBox::~CheckBox() if (instances == 0) { - if (checkBoxNormal) - { - checkBoxNormal->decRef(); - checkBoxNormal = nullptr; - } - if (checkBoxChecked) - { - checkBoxChecked->decRef(); - checkBoxChecked = nullptr; - } - if (checkBoxDisabled) - { - checkBoxDisabled->decRef(); - checkBoxDisabled = nullptr; - } - if (checkBoxDisabledChecked) - { - checkBoxDisabledChecked->decRef(); - checkBoxDisabledChecked = nullptr; - } - if (checkBoxNormalHi) - { - checkBoxNormalHi->decRef(); - checkBoxNormalHi = nullptr; - } - if (checkBoxCheckedHi) - { - checkBoxCheckedHi->decRef(); - checkBoxCheckedHi = nullptr; - } + if (Theme::instance()) + Theme::instance()->unload(mSkin); } } @@ -146,9 +98,8 @@ void CheckBox::draw(gcn::Graphics* graphics) graphics->setFont(getFont()); graphics->setColor(mForegroundColor); - const int h = getHeight() + getHeight() / 2; - - graphics->drawText(getCaption(), h - 2, 0); + graphics->drawText(getCaption(), mPadding + mImageSize + mSpacing, + mPadding); } void CheckBox::updateAlpha() @@ -159,54 +110,60 @@ void CheckBox::updateAlpha() if (mAlpha != alpha) { mAlpha = alpha; - if (checkBoxNormal) - checkBoxNormal->setAlpha(mAlpha); - if (checkBoxChecked) - checkBoxChecked->setAlpha(mAlpha); - if (checkBoxDisabled) - checkBoxDisabled->setAlpha(mAlpha); - if (checkBoxDisabledChecked) - checkBoxDisabledChecked->setAlpha(mAlpha); - if (checkBoxNormal) - checkBoxNormal->setAlpha(mAlpha); - if (checkBoxCheckedHi) - checkBoxCheckedHi->setAlpha(mAlpha); + if (mSkin) + { + ImageRect &rect = mSkin->getBorder(); + for (int a = 0; a < 6; a ++) + { + Image *const image = rect.grid[a]; + if (image) + image->setAlpha(mAlpha); + } + } } } void CheckBox::drawBox(gcn::Graphics *const graphics) { - const Image *box; + if (!mSkin) + return; + + ImageRect &rect = mSkin->getBorder(); + int index = 0; if (mEnabled && isVisible()) { if (mSelected) { if (mHasMouse) - box = checkBoxCheckedHi; + index = 5; else - box = checkBoxChecked; + index = 1; } else { if (mHasMouse) - box = checkBoxNormalHi; + index = 4; else - box = checkBoxNormal; + index = 0; } } else { if (mSelected) - box = checkBoxDisabledChecked; + index = 3; else - box = checkBoxDisabled; + index = 2; } + const Image *const box = rect.grid[index]; updateAlpha(); if (box) - static_cast<Graphics*>(graphics)->drawImage(box, 2, 2); + { + static_cast<Graphics*>(graphics)->drawImage( + box, mImagePadding, (getHeight() - mImageSize) / 2); + } } void CheckBox::mouseEntered(gcn::MouseEvent& event A_UNUSED) @@ -229,3 +186,10 @@ void CheckBox::keyPressed(gcn::KeyEvent& keyEvent) keyEvent.consume(); } } + +void CheckBox::adjustSize() +{ + setHeight(getFont()->getHeight() + 2 * mPadding); + setWidth(mImagePadding + mImageSize + mSpacing + + getFont()->getWidth(mCaption) + mPadding); +} diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h index 654c48d62..0ca579d3b 100644 --- a/src/gui/widgets/checkbox.h +++ b/src/gui/widgets/checkbox.h @@ -28,6 +28,7 @@ #include "localconsts.h" class Image; +class Skin; /** * Check box widget. Same as the Guichan check box but with custom look. @@ -78,16 +79,18 @@ class CheckBox final : public gcn::CheckBox void keyPressed(gcn::KeyEvent& keyEvent) override; + void adjustSize(); + private: + bool mHasMouse; + int mPadding; + int mImagePadding; + int mImageSize; + int mSpacing; + static int instances; + static Skin *mSkin; static float mAlpha; - bool mHasMouse; - static Image *checkBoxNormal; - static Image *checkBoxChecked; - static Image *checkBoxDisabled; - static Image *checkBoxDisabledChecked; - static Image *checkBoxNormalHi; - static Image *checkBoxCheckedHi; }; #endif diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp index 58710409b..dcac59d17 100644 --- a/src/guichan/widgets/checkbox.cpp +++ b/src/guichan/widgets/checkbox.cpp @@ -123,10 +123,6 @@ namespace gcn void CheckBox::adjustSize() { - const int height = getFont()->getHeight(); - - setHeight(height); - setWidth(getFont()->getWidth(mCaption) + height + height / 2); } void CheckBox::toggleSelected() |