diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-18 02:00:19 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-18 02:00:19 +0300 |
commit | 43f84a5a22423b831b1d3a4b3572546803324dd4 (patch) | |
tree | 187459d3c84abae3d9001238b8314e577b68b107 /src | |
parent | 213bc274d777946f7c39e5f5ccd859e766aef4ae (diff) | |
download | plus-43f84a5a22423b831b1d3a4b3572546803324dd4.tar.gz plus-43f84a5a22423b831b1d3a4b3572546803324dd4.tar.bz2 plus-43f84a5a22423b831b1d3a4b3572546803324dd4.tar.xz plus-43f84a5a22423b831b1d3a4b3572546803324dd4.zip |
Extend dropdown theming.
New options in dropdown.xml:
padding - text padding from all sides
imagePadding - image padding from right
frameSize - frame size
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/chatwindow.h | 8 | ||||
-rw-r--r-- | src/gui/itemamountwindow.h | 4 | ||||
-rw-r--r-- | src/gui/setup_relations.cpp | 4 | ||||
-rw-r--r-- | src/gui/setup_relations.h | 4 | ||||
-rw-r--r-- | src/gui/setup_theme.h | 4 | ||||
-rw-r--r-- | src/gui/setup_video.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 99 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.h | 10 | ||||
-rw-r--r-- | src/guichan/widgets/dropdown.cpp | 36 |
9 files changed, 108 insertions, 65 deletions
diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index 1d21b248e..911b1b1ff 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -45,17 +45,13 @@ class ChatTab; class Channel; class ChatInput; class ColorListModel; +class DropDown; class ScrollArea; class TabbedArea; class ItemLinkHandler; class Tab; class WhisperTab; -namespace gcn -{ - class DropDown; -} - const int DEFAULT_CHAT_WINDOW_SCROLL = 7; enum Own @@ -354,7 +350,7 @@ class ChatWindow final : public Window, StringVect mTradeFilter; ColorListModel *mColorListModel; - gcn::DropDown *mColorPicker; + DropDown *mColorPicker; int mChatColor; unsigned int mChatHistoryIndex; std::list<std::string> mAwayLog; diff --git a/src/gui/itemamountwindow.h b/src/gui/itemamountwindow.h index 53c7ea23f..9db74c692 100644 --- a/src/gui/itemamountwindow.h +++ b/src/gui/itemamountwindow.h @@ -28,6 +28,7 @@ #include <guichan/keylistener.hpp> #include <guichan/actionlistener.hpp> +class DropDown; class Icon; class IntTextField; class Item; @@ -37,7 +38,6 @@ class Label; namespace gcn { - class DropDown; class Slider; } @@ -118,7 +118,7 @@ class ItemAmountWindow final : public Window, gcn::Slider *mItemPriceSlide; - gcn::DropDown *mItemDropDown; + DropDown *mItemDropDown; ItemsModal *mItemsModal; diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index e57a74561..05f6ecb26 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -160,7 +160,7 @@ public: gcn::Widget *const widget = new Label(name); mWidgets.push_back(widget); - gcn::DropDown *const choicebox = new DropDown(mListModel); + DropDown *const choicebox = new DropDown(mListModel); choicebox->setSelected(player_relations.getRelation(name)); mWidgets.push_back(choicebox); } @@ -170,7 +170,7 @@ public: virtual void updateModelInRow(const int row) { - const gcn::DropDown *const choicebox = static_cast<gcn::DropDown *>( + const DropDown *const choicebox = static_cast<DropDown *>( getElementAt(row, RELATION_CHOICE_COLUMN)); player_relations.setRelation(getPlayerAt(row), static_cast<PlayerRelation::Relation>( diff --git a/src/gui/setup_relations.h b/src/gui/setup_relations.h index 8564c8ab7..8e83cf22c 100644 --- a/src/gui/setup_relations.h +++ b/src/gui/setup_relations.h @@ -31,6 +31,7 @@ class Button; class CheckBox; +class DropDown; class EditDialog; class GuiTable; class PlayerTableModel; @@ -38,7 +39,6 @@ class StaticTableModel; namespace gcn { - class DropDown; class ListModel; class ScrollArea; } @@ -80,7 +80,7 @@ private: Button *mDeleteButton; gcn::ListModel *mIgnoreActionChoicesModel; - gcn::DropDown *mIgnoreActionChoicesBox; + DropDown *mIgnoreActionChoicesBox; }; #endif diff --git a/src/gui/setup_theme.h b/src/gui/setup_theme.h index 31588c9c2..9754b7915 100644 --- a/src/gui/setup_theme.h +++ b/src/gui/setup_theme.h @@ -95,12 +95,12 @@ class Setup_Theme final : public SetupTab FontSizeChoiceListModel *mFontSizeListModel; Label *mFontSizeLabel; int mFontSize; - gcn::DropDown *mFontSizeDropDown; + DropDown *mFontSizeDropDown; FontSizeChoiceListModel *mNpcFontSizeListModel; Label *mNpcFontSizeLabel; int mNpcFontSize; - gcn::DropDown *mNpcFontSizeDropDown; + DropDown *mNpcFontSizeDropDown; // EditDialog *mEditDialog; }; diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 6144de8d8..0955910da 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -32,6 +32,7 @@ class Button; class CheckBox; +class DropDown; class Label; class ListBox; class ModeListModel; @@ -40,7 +41,6 @@ class TextDialog; namespace gcn { - class DropDown; class Slider; } @@ -79,7 +79,7 @@ class Setup_Video final : public SetupTab, public gcn::KeyListener ListBox *mModeList; CheckBox *mFsCheckBox; - gcn::DropDown *mOpenGLDropDown; + DropDown *mOpenGLDropDown; CheckBox *mCustomCursorCheckBox; CheckBox *mEnableResizeCheckBox; diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 5cb624772..31f69c8a3 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -39,6 +39,8 @@ #include "utils/dtor.h" +#include <guichan/font.hpp> + #include <algorithm> #include "debug.h" @@ -47,6 +49,7 @@ int DropDown::instances = 0; Image *DropDown::buttons[2][2]; ImageRect DropDown::skinRect; float DropDown::mAlpha = 1.0; +Skin *DropDown::mSkin = nullptr; static std::string const dropdownFiles[2] = { @@ -60,9 +63,11 @@ DropDown::DropDown(gcn::ListModel *const listModel, gcn::DropDown::DropDown(listModel, new ScrollArea, new ListBox(listModel)), mShadowColor(Theme::getThemeColor(Theme::DROPDOWN_SHADOW)), - mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)) + mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)), + mPadding(1), + mImagePadding(2) { - setFrameSize(2); + mFrameSize = 2; // Initialize graphics if (instances == 0) @@ -70,10 +75,12 @@ DropDown::DropDown(gcn::ListModel *const listModel, // Load the background skin for (int i = 0; i < 2; i ++) { - Skin *const skin = Theme::instance()->load( + Skin *skin = Theme::instance()->load( dropdownFiles[i], "dropdown.xml"); if (skin) { + if (!i) + mSkin = skin; const ImageRect &rect = skin->getBorder(); for (int f = 0; f < 2; f ++) { @@ -88,13 +95,14 @@ DropDown::DropDown(gcn::ListModel *const listModel, buttons[f][i] = nullptr; } } + if (i) + Theme::instance()->unload(skin); } else { for (int f = 0; f < 2; f ++) buttons[f][i] = nullptr; } - Theme::instance()->unload(skin); } // get the border skin @@ -115,6 +123,17 @@ DropDown::DropDown(gcn::ListModel *const listModel, if (listener) addActionListener(listener); + + if (mListBox) + mListBox->adjustSize(); + + if (mSkin) + { + mFrameSize = mSkin->getOption("frameSize"); + mPadding = mSkin->getPadding(); + mImagePadding = mSkin->getOption("imagePadding"); + } + adjustHeight(); } DropDown::~DropDown() @@ -130,8 +149,12 @@ DropDown::~DropDown() buttons[f][i]->decRef(); } } - if (Theme::instance()) - Theme::instance()->unloadRect(skinRect); + Theme *const theme = Theme::instance(); + if (theme) + { + theme->unload(mSkin); + theme->unloadRect(skinRect); + } } delete mScrollArea; mScrollArea = nullptr; @@ -175,6 +198,7 @@ void DropDown::draw(gcn::Graphics* graphics) updateAlpha(); const int alpha = static_cast<int>(mAlpha * 255.0f); + const int pad = 2 * mPadding; mHighlightColor.a = alpha; mShadowColor.a = alpha; @@ -183,13 +207,14 @@ void DropDown::draw(gcn::Graphics* graphics) graphics->setFont(getFont()); graphics->setColor(mForegroundColor); graphics->drawText(mListBox->getListModel()->getElementAt( - mListBox->getSelected()), 1, 0); + mListBox->getSelected()), mPadding, mPadding); } if (isFocused()) { graphics->setColor(mHighlightColor); - graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); + graphics->drawRectangle(gcn::Rectangle(mPadding, mPadding, + getWidth() - h - pad, h - pad)); } drawButton(graphics); @@ -197,7 +222,6 @@ void DropDown::draw(gcn::Graphics* graphics) if (mDroppedDown) { drawChildren(graphics); - // Draw two lines separating the ListBox with selected // element view. graphics->setColor(mHighlightColor); @@ -220,11 +244,12 @@ void DropDown::drawButton(gcn::Graphics *graphics) { const int height = mDroppedDown ? mFoldedUpHeight : getHeight(); - if (buttons[mDroppedDown][mPushed]) + Image *image = buttons[mDroppedDown][mPushed]; + if (image) { - static_cast<Graphics*>(graphics)-> - drawImage(buttons[mDroppedDown][mPushed], - getWidth() - height + 2, 1); + static_cast<Graphics*>(graphics)->drawImage(image, + getWidth() - image->getWidth() - mImagePadding, + (height - image->getHeight()) / 2); } } @@ -328,3 +353,51 @@ std::string DropDown::getSelectedString() const return listModel->getElementAt(getSelected()); } + +void DropDown::adjustHeight() +{ + if (!mScrollArea || !mListBox) + return; + + const int listBoxHeight = mListBox->getHeight(); + const int h2 = getFont()->getHeight() + 2 * mPadding; + int newHeight = h2; + + if (mDroppedDown && getParent()) + { + const int h = getParent()->getChildrenArea().height - getY(); + const int h0 = h - h2; + if (listBoxHeight > h0) + { + mScrollArea->setHeight(h0); + newHeight = h; + } + else + { + newHeight = listBoxHeight + h2; + mScrollArea->setHeight(listBoxHeight); + } + } + + setHeight(newHeight); + + mScrollArea->setWidth(getWidth()); + mListBox->setWidth(mScrollArea->getChildrenArea().width); + mScrollArea->setPosition(0, 0); +} + +void DropDown::dropDown() +{ + const bool dropped = mDroppedDown; + gcn::DropDown::dropDown(); + if (!dropped) + adjustHeight(); +} + +void DropDown::foldUp() +{ + const bool dropped = mDroppedDown; + gcn::DropDown::foldUp(); + if (dropped) + adjustHeight(); +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 1dd2f5a35..9e9851f24 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -29,6 +29,7 @@ class Image; class ImageRect; +class Skin; /** * A drop down box from which you can select different values. @@ -85,6 +86,12 @@ class DropDown final : public gcn::DropDown std::string getSelectedString() const; + void adjustHeight(); + + void dropDown() override; + + void foldUp() override; + protected: /** * Draws the button with the little down arrow. @@ -95,12 +102,15 @@ class DropDown final : public gcn::DropDown gcn::Color mShadowColor; gcn::Color mHighlightColor; + int mPadding; + int mImagePadding; // Add own Images. static int instances; static Image *buttons[2][2]; static ImageRect skinRect; static float mAlpha; + static Skin *mSkin; }; #endif // end DROPDOWN_H diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp index 39248ab73..bb470fdeb 100644 --- a/src/guichan/widgets/dropdown.cpp +++ b/src/guichan/widgets/dropdown.cpp @@ -221,42 +221,6 @@ namespace gcn void DropDown::adjustHeight() { - if (!mScrollArea) - throw GCN_EXCEPTION("Scroll area has been deleted."); - - if (!mListBox) - throw GCN_EXCEPTION("List box has been deleted."); - - const int listBoxHeight = mListBox->getHeight(); - - // We add 2 for the border - const int h2 = getFont()->getHeight() + 2; - - setHeight(h2); - - // The addition/subtraction of 2 compensates for the seperation lines - // seperating the selected element view and the scroll area. - - if (mDroppedDown && getParent()) - { - const int h = getParent()->getChildrenArea().height - getY(); - - if (listBoxHeight > h - h2 - 2) - { - mScrollArea->setHeight(h - h2 - 2); - setHeight(h); - } - else - { - setHeight(listBoxHeight + h2 + 2); - mScrollArea->setHeight(listBoxHeight); - } - } - - mScrollArea->setWidth(getWidth()); - // Resize the ListBox to exactly fit the ScrollArea. - mListBox->setWidth(mScrollArea->getChildrenArea().width); - mScrollArea->setPosition(0, 0); } void DropDown::dropDown() |