diff options
author | Ira Rice <irarice@gmail.com> | 2009-02-03 16:33:18 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-02-03 16:33:18 -0700 |
commit | 7d45452187b1c2911b688bbed5fb8981a67b1934 (patch) | |
tree | 173857b19d0662837a48178739412aec908b040e /src | |
parent | 8857a59c3818c1ce6eeb6c054cb5543bfc35c087 (diff) | |
download | mana-client-7d45452187b1c2911b688bbed5fb8981a67b1934.tar.gz mana-client-7d45452187b1c2911b688bbed5fb8981a67b1934.tar.bz2 mana-client-7d45452187b1c2911b688bbed5fb8981a67b1934.tar.xz mana-client-7d45452187b1c2911b688bbed5fb8981a67b1934.zip |
Modified the dropdown class to handle opacity.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/login.cpp | 3 | ||||
-rw-r--r-- | src/gui/setup_players.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 58 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.h | 22 |
4 files changed, 81 insertions, 19 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 84e10e97..408456ef 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -63,7 +63,7 @@ LoginDialog::LoginDialog(LoginData *loginData): dfltPort.push_back("21001"); mServerList = new DropDownList("MostRecent00", dfltServer, dfltPort, MAX_SERVER_LIST_SIZE); - mServerListBox = new gcn::ListBox(mServerList); + mServerListBox = new ListBox(mServerList); mServerScrollArea = new ScrollArea(); mUserField = new TextField(mLoginData->username); @@ -73,6 +73,7 @@ LoginDialog::LoginDialog(LoginData *loginData): mServerDropDown = new DropDown(mServerList, mServerScrollArea, mServerListBox); + mServerDropDown->setOpaque(false); mKeepCheck = new CheckBox(_("Keep"), mLoginData->remember); mOkButton = new Button(_("OK"), "ok", this); diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index c8546b4b..932acee7 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -21,20 +21,20 @@ #include <vector> -#include <guichan/widgets/dropdown.hpp> #include <guichan/widgets/label.hpp> #include "button.h" #include "checkbox.h" +#include "listbox.h" #include "ok_dialog.h" #include "setup_players.h" +#include "widgets/dropdown.h" #include "widgets/layouthelper.h" #include "../configuration.h" #include "../log.h" #include "../player_relations.h" -#include "../sound.h" #include "../utils/gettext.h" @@ -135,8 +135,12 @@ public: std::string name = (*player_names)[r]; gcn::Widget *widget = new gcn::Label(name); mWidgets.push_back(widget); + gcn::ListModel *playerRelation = new PlayerRelationListModel(); - gcn::DropDown *choicebox = new gcn::DropDown(new PlayerRelationListModel()); + gcn::DropDown *choicebox = new DropDown(playerRelation, + new ScrollArea(), + new ListBox(playerRelation), + false); choicebox->setSelected(player_relations.getRelation(name)); mWidgets.push_back(choicebox); } @@ -219,8 +223,7 @@ Setup_Players::Setup_Players(): player_relations.getDefault() & PlayerRelation::TRADE)), mDefaultWhisper(new CheckBox(_("Allow whispers"), player_relations.getDefault() & PlayerRelation::WHISPER)), - mDeleteButton(new Button(_("Delete"), ACTION_DELETE, this)), - mIgnoreActionChoicesBox(new gcn::DropDown(new IgnoreChoicesListModel())) + mDeleteButton(new Button(_("Delete"), ACTION_DELETE, this)) { setOpaque(false); mPlayerTable->setOpaque(false); @@ -232,6 +235,10 @@ Setup_Players::Setup_Players(): mPlayerTitleTable->setDimension(gcn::Rectangle(10, 10, table_width - 1, 10)); mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf)); + gcn::ListModel *ignoreChoices = new IgnoreChoicesListModel(); + mIgnoreActionChoicesBox = new DropDown(ignoreChoices, new ScrollArea(), + new ListBox(ignoreChoices), false); + for (int i = 0; i < COLUMNS_NR; i++) { mPlayerTableTitleModel->set(0, i, diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 88a12d68..ac5cbaa2 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -23,6 +23,9 @@ #include "dropdown.h" +#include "../colour.h" + +#include "../../configuration.h" #include "../../graphics.h" #include "../../resources/image.h" @@ -33,12 +36,12 @@ int DropDown::instances = 0; Image *DropDown::buttons[2][2]; ImageRect DropDown::skin; +float DropDown::mAlpha = config.getValue("guialpha", 0.8); -DropDown::DropDown(gcn::ListModel *listModel, - gcn::ScrollArea *scrollArea, - gcn::ListBox *listBox): - gcn::DropDown::DropDown(listModel, - scrollArea, listBox) +DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, + gcn::ListBox *listBox, bool opacity): + gcn::DropDown::DropDown(listModel, scrollArea, listBox), + mOpaque(opacity) { setFrameSize(2); @@ -58,6 +61,11 @@ DropDown::DropDown(gcn::ListModel *listModel, buttons[0][1] = resman->getImage("graphics/gui/vscroll_down_pressed.png"); + buttons[0][0]->setAlpha(mAlpha); + buttons[0][1]->setAlpha(mAlpha); + buttons[1][0]->setAlpha(mAlpha); + buttons[1][1]->setAlpha(mAlpha); + // get the border skin Image *boxBorder = resman->getImage("graphics/gui/deepbox.png"); int gridx[4] = {0, 3, 28, 31}; @@ -70,6 +78,7 @@ DropDown::DropDown(gcn::ListModel *listModel, gridx[x], gridy[y], gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1); + skin.grid[a]->setAlpha(mAlpha); a++; } } @@ -108,19 +117,44 @@ void DropDown::draw(gcn::Graphics* graphics) h = getHeight(); } - int alpha = getBaseColor().a; + if (config.getValue("guialpha", 0.8) != mAlpha) + { + mAlpha = config.getValue("guialpha", 0.8); + + buttons[0][0]->setAlpha(mAlpha); + buttons[0][1]->setAlpha(mAlpha); + buttons[1][0]->setAlpha(mAlpha); + buttons[1][1]->setAlpha(mAlpha); + + for (int a = 0; a < 9; a++) + { + skin.grid[a]->setAlpha(mAlpha); + } + } + + bool valid; + const int alpha = mAlpha * 255; gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = faceColor + 0x303030; + gcn::Color highlightColor = textColour->getColour('H', valid); highlightColor.a = alpha; gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; + if (mOpaque) + { + int red = getBackgroundColor().r; + int green = getBackgroundColor().g; + int blue = getBackgroundColor().b; + graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); + + red = getForegroundColor().r; + green = getForegroundColor().g; + blue = getForegroundColor().b; + graphics->setColor(gcn::Color(red, green, blue, alpha)); + } - graphics->setColor(getBackgroundColor()); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - - graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); if (mListBox->getListModel() && mListBox->getSelected() >= 0) @@ -140,7 +174,7 @@ void DropDown::draw(gcn::Graphics* graphics) { drawChildren(graphics); - // Draw two lines separating the ListBox with se selected + // Draw two lines separating the ListBox with selected // element view. graphics->setColor(highlightColor); graphics->drawLine(0, h, getWidth(), h); diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 25ae05f8..bff8bd1e 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -56,7 +56,8 @@ class DropDown : public gcn::DropDown */ DropDown(gcn::ListModel *listModel = NULL, gcn::ScrollArea *scrollArea = NULL, - gcn::ListBox *listBox = NULL); + gcn::ListBox *listBox = NULL, + bool opacity = true); /** * Destructor. @@ -67,6 +68,22 @@ class DropDown : public gcn::DropDown void drawFrame(gcn::Graphics* graphics); + /** + * Sets the widget to be opaque, that is sets the widget to display its + * background. + * + * @param opaque True if the widget should be opaque, false otherwise. + */ + void setOpaque(bool opaque) {mOpaque = opaque;} + + /** + * Checks if the widget is opaque, that is if the widget area displays + * its background. + * + * @return True if the widget is opaque, false otherwise. + */ + bool isOpaque() const {return mOpaque;} + protected: /** @@ -80,6 +97,9 @@ class DropDown : public gcn::DropDown static int instances; static Image *buttons[2][2]; static ImageRect skin; + static float mAlpha; + + bool mOpaque; }; #endif // end DROPDOWN_H |