diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-09 21:12:01 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-09 21:12:01 +0200 |
commit | df9f7aa2d3f33f70b7aa9fd8ac7f1b7ddece0b29 (patch) | |
tree | 1510f931cf2964a24a2b8edc3c22a2b37be5dee4 | |
parent | f790281b94d37f7ea2c2e8fc7b121266d88f93bb (diff) | |
download | mana-df9f7aa2d3f33f70b7aa9fd8ac7f1b7ddece0b29.tar.gz mana-df9f7aa2d3f33f70b7aa9fd8ac7f1b7ddece0b29.tar.bz2 mana-df9f7aa2d3f33f70b7aa9fd8ac7f1b7ddece0b29.tar.xz mana-df9f7aa2d3f33f70b7aa9fd8ac7f1b7ddece0b29.zip |
Fixed the updating of sliders/preview on changing color selection
It only worked when you clicked, not when the selection changed for any
other reason, like click+drag. Use a SelectionListener instead.
-rw-r--r-- | src/gui/setup_colors.cpp | 305 | ||||
-rw-r--r-- | src/gui/setup_colors.h | 8 |
2 files changed, 158 insertions, 155 deletions
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 86184eab..a0be62cd 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -50,8 +50,7 @@ Setup_Colors::Setup_Colors() : setName(_("Colors")); mColorBox = new ListBox(guiPalette); - mColorBox->setActionEventId("color_box"); - mColorBox->addActionListener(this); + mColorBox->addSelectionListener(this); mScroll = new ScrollArea(mColorBox); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); @@ -190,158 +189,6 @@ Setup_Colors::~Setup_Colors() void Setup_Colors::action(const gcn::ActionEvent &event) { - if (event.getId() == "color_box") - { - mSelected = mColorBox->getSelected(); - Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); - const gcn::Color *col = &guiPalette->getColor(type); - Palette::GradientType grad = guiPalette->getGradientType(type); - const int delay = guiPalette->getGradientDelay(type); - - std::string msg; - const char ch = guiPalette->getColorChar(type); - - mPreview->clearRows(); - mPreviewBox->setContent(mTextPreview); - mTextPreview->setFont(gui->getFont()); - mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT)); - mTextPreview->setTextBGColor(NULL); - mTextPreview->setOpaque(false); - mTextPreview->setShadow(true); - mTextPreview->setOutline(true); - mTextPreview->useTextAlpha(false); - - switch (type) - { - case Palette::TEXT: - case Palette::SHADOW: - case Palette::OUTLINE: - mTextPreview->setFont(gui->getFont()); - mTextPreview->setShadow(type == Palette::SHADOW); - mTextPreview->setOutline(type == Palette::OUTLINE); - break; - case Palette::PROGRESS_BAR: - mTextPreview->useTextAlpha(true); - mTextPreview->setFont(boldFont); - mTextPreview->setTextColor(col); - mTextPreview->setOutline(true); - mTextPreview->setShadow(false); - break; - case Palette::TAB_HIGHLIGHT: - mTextPreview->setFont(gui->getFont()); - mTextPreview->setTextColor(col); - mTextPreview->setOutline(false); - mTextPreview->setShadow(false); - break; - case Palette::BACKGROUND: - case Palette::SHOP_WARNING: - mTextPreview->setBGColor(col); - mTextPreview->setOpaque(true); - mTextPreview->setOutline(false); - mTextPreview->setShadow(false); - break; - case Palette::HPBAR_FULL: - case Palette::HPBAR_THREE_QUARTERS: - case Palette::HPBAR_ONE_HALF: - case Palette::HPBAR_ONE_QUARTER: - mTextPreview->setTextBGColor(col); - mTextPreview->setFont(boldFont); - mTextPreview->setTextColor(&guiPalette->getColor(Palette::PROGRESS_BAR)); - mTextPreview->setOutline(true); - mTextPreview->setShadow(false); - mPreview->addRow(rawmsg); - break; - case Palette::HIGHLIGHT: - mTextPreview->setTextBGColor(col); - mTextPreview->setOutline(false); - mTextPreview->setShadow(false); - mPreview->addRow(rawmsg); - break; - case Palette::CHAT: - case Palette::GM: - case Palette::PLAYER: - case Palette::WHISPER: - case Palette::IS: - case Palette::PARTY: - case Palette::SERVER: - case Palette::LOGGER: - case Palette::HYPERLINK: - mPreviewBox->setContent(mPreview); - mPreview->clearRows(); - - if (ch == '<') - msg = toString("@@|") + rawmsg + "@@"; - else - msg = "##" + toString(ch) + rawmsg; - - mPreview->addRow(msg); - break; - case Palette::ITEM_EQUIPPED: - mTextPreview->setTextColor(col); - mTextPreview->setOutline(false); - mTextPreview->setShadow(false); - break; - case Palette::UNKNOWN_ITEM: - case Palette::GENERIC: - case Palette::HEAD: - case Palette::USABLE: - case Palette::TORSO: - case Palette::ONEHAND: - case Palette::LEGS: - case Palette::FEET: - case Palette::TWOHAND: - case Palette::SHIELD: - case Palette::RING: - case Palette::NECKLACE: - case Palette::ARMS: - case Palette::AMMO: - mTextPreview->setFont(boldFont); - mTextPreview->setTextColor(col); - mTextPreview->setOutline(false); - mTextPreview->setShadow(false); - break; - case Palette::PARTICLE: - case Palette::EXP_INFO: - case Palette::PICKUP_INFO: - case Palette::HIT_PLAYER_MONSTER: - case Palette::HIT_MONSTER_PLAYER: - case Palette::HIT_CRITICAL: - case Palette::MISS: - mTextPreview->setShadow(false); - case Palette::BEING: - case Palette::PC: - case Palette::SELF: - case Palette::GM_NAME: - case Palette::NPC: - case Palette::MONSTER: - mTextPreview->setFont(boldFont); - mTextPreview->setTextColor(col); - case Palette::TYPE_COUNT: - break; - } - - if (grad != Palette::STATIC && grad != Palette::PULSE) - { // If nonstatic color, don't display the current, but the committed - // color at the sliders - col = &guiPalette->getCommittedColor(type); - } - else if (grad == Palette::PULSE) - { - col = &guiPalette->getTestColor(type); - } - - setEntry(mGradDelaySlider, mGradDelayText, delay); - setEntry(mRedSlider, mRedText, col->r); - setEntry(mGreenSlider, mGreenText, col->g); - setEntry(mBlueSlider, mBlueText, col->b); - - mGradTypeSlider->setValue(grad); - updateGradType(); - mGradTypeSlider->setEnabled(true); - - return; - } - if (event.getId() == "slider_grad") { updateGradType(); @@ -378,6 +225,156 @@ void Setup_Colors::action(const gcn::ActionEvent &event) } } +void Setup_Colors::valueChanged(const gcn::SelectionEvent &event) +{ + mSelected = mColorBox->getSelected(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + Palette::GradientType grad = guiPalette->getGradientType(type); + const int delay = guiPalette->getGradientDelay(type); + + std::string msg; + const char ch = guiPalette->getColorChar(type); + + mPreview->clearRows(); + mPreviewBox->setContent(mTextPreview); + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextBGColor(NULL); + mTextPreview->setOpaque(false); + mTextPreview->setShadow(true); + mTextPreview->setOutline(true); + mTextPreview->useTextAlpha(false); + + switch (type) + { + case Palette::TEXT: + case Palette::SHADOW: + case Palette::OUTLINE: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setShadow(type == Palette::SHADOW); + mTextPreview->setOutline(type == Palette::OUTLINE); + break; + case Palette::PROGRESS_BAR: + mTextPreview->useTextAlpha(true); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + break; + case Palette::TAB_HIGHLIGHT: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::BACKGROUND: + case Palette::SHOP_WARNING: + mTextPreview->setBGColor(col); + mTextPreview->setOpaque(true); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::HPBAR_FULL: + case Palette::HPBAR_THREE_QUARTERS: + case Palette::HPBAR_ONE_HALF: + case Palette::HPBAR_ONE_QUARTER: + mTextPreview->setTextBGColor(col); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::PROGRESS_BAR)); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + mPreview->addRow(rawmsg); + break; + case Palette::HIGHLIGHT: + mTextPreview->setTextBGColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + mPreview->addRow(rawmsg); + break; + case Palette::CHAT: + case Palette::GM: + case Palette::PLAYER: + case Palette::WHISPER: + case Palette::IS: + case Palette::PARTY: + case Palette::SERVER: + case Palette::LOGGER: + case Palette::HYPERLINK: + mPreviewBox->setContent(mPreview); + mPreview->clearRows(); + + if (ch == '<') + msg = toString("@@|") + rawmsg + "@@"; + else + msg = "##" + toString(ch) + rawmsg; + + mPreview->addRow(msg); + break; + case Palette::ITEM_EQUIPPED: + mTextPreview->setTextColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::UNKNOWN_ITEM: + case Palette::GENERIC: + case Palette::HEAD: + case Palette::USABLE: + case Palette::TORSO: + case Palette::ONEHAND: + case Palette::LEGS: + case Palette::FEET: + case Palette::TWOHAND: + case Palette::SHIELD: + case Palette::RING: + case Palette::NECKLACE: + case Palette::ARMS: + case Palette::AMMO: + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::PARTICLE: + case Palette::EXP_INFO: + case Palette::PICKUP_INFO: + case Palette::HIT_PLAYER_MONSTER: + case Palette::HIT_MONSTER_PLAYER: + case Palette::HIT_CRITICAL: + case Palette::MISS: + mTextPreview->setShadow(false); + case Palette::BEING: + case Palette::PC: + case Palette::SELF: + case Palette::GM_NAME: + case Palette::NPC: + case Palette::MONSTER: + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + case Palette::TYPE_COUNT: + break; + } + + if (grad != Palette::STATIC && grad != Palette::PULSE) + { // If nonstatic color, don't display the current, but the committed + // color at the sliders + col = &guiPalette->getCommittedColor(type); + } + else if (grad == Palette::PULSE) + { + col = &guiPalette->getTestColor(type); + } + + setEntry(mGradDelaySlider, mGradDelayText, delay); + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); + + mGradTypeSlider->setValue(grad); + updateGradType(); + mGradTypeSlider->setEnabled(true); +} + void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value) { s->setValue(value); diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 75c4c07c..023afc7a 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -27,6 +27,7 @@ #include "guichanfwd.h" #include <guichan/actionlistener.hpp> +#include <guichan/selectionlistener.hpp> #include <string> @@ -34,7 +35,9 @@ class BrowserBox; class TextField; class TextPreview; -class Setup_Colors : public SetupTab, public gcn::ActionListener +class Setup_Colors : public SetupTab, + public gcn::ActionListener, + public gcn::SelectionListener { public: Setup_Colors(); @@ -42,8 +45,11 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener void apply(); void cancel(); + void action(const gcn::ActionEvent &event); + void valueChanged(const gcn::SelectionEvent &event); + private: static const std::string rawmsg; |