diff options
author | Ira Rice <irarice@gmail.com> | 2009-02-07 12:18:52 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-02-07 12:18:52 -0700 |
commit | 1b8c088a48822641b53c2a304372471a128c2841 (patch) | |
tree | 4f2fbb68a2fb011a572bb5d0d69deb3a16780d92 /src | |
parent | 074ca287804a56f776d641826b1ecfc1454b6c72 (diff) | |
download | mana-1b8c088a48822641b53c2a304372471a128c2841.tar.gz mana-1b8c088a48822641b53c2a304372471a128c2841.tar.bz2 mana-1b8c088a48822641b53c2a304372471a128c2841.tar.xz mana-1b8c088a48822641b53c2a304372471a128c2841.zip |
Added a text color preview to the setup color tab.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/browserbox.cpp | 4 | ||||
-rw-r--r-- | src/gui/browserbox.h | 2 | ||||
-rw-r--r-- | src/gui/chat.cpp | 2 | ||||
-rw-r--r-- | src/gui/colour.cpp | 9 | ||||
-rw-r--r-- | src/gui/colour.h | 6 | ||||
-rw-r--r-- | src/gui/scrollarea.cpp | 15 | ||||
-rw-r--r-- | src/gui/scrollarea.h | 4 | ||||
-rw-r--r-- | src/gui/setup_colours.cpp | 52 | ||||
-rw-r--r-- | src/gui/setup_colours.h | 16 |
9 files changed, 79 insertions, 31 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index ecc22e5f..5895d557 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -28,10 +28,10 @@ #include "linkhandler.h" #include "truetypefont.h" -BrowserBox::BrowserBox(unsigned int mode): +BrowserBox::BrowserBox(unsigned int mode, bool opaque): gcn::Widget(), mMode(mode), mHighMode(UNDERLINE | BACKGROUND), - mOpaque(true), + mOpaque(opaque), mUseLinksAndUserColors(true), mSelectedLink(-1), mMaxRows(0) diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 15c2ab89..5dde402e 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -46,7 +46,7 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener /** * Constructor. */ - BrowserBox(unsigned int mode = AUTO_SIZE); + BrowserBox(unsigned int mode = AUTO_SIZE, bool opaque = true); /** * Destructor. diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 067c9e08..2363fc50 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -71,8 +71,6 @@ Window(""), mNetwork(network), mTmpVisible(false) mTextOutput->setLinkHandler(mItemLinkHandler); mScrollArea = new ScrollArea(mTextOutput); - mScrollArea->setPosition(mScrollArea->getFrameSize(), - mScrollArea->getFrameSize()); mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); mScrollArea->setScrollAmount(0, 1); diff --git a/src/gui/colour.cpp b/src/gui/colour.cpp index 58d9d1c6..c4505c2f 100644 --- a/src/gui/colour.cpp +++ b/src/gui/colour.cpp @@ -93,6 +93,15 @@ std::string Colour::getElementAt(int i) return mColVector[i].text; } +char Colour::getColourCharAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return 'C'; + } + return mColVector[i].ch; +} + void Colour::addColour(const char c, const int rgb, const std::string &text) { int trueRgb = config.getValue("Colour" + text, rgb); diff --git a/src/gui/colour.h b/src/gui/colour.h index 1648e1e8..d0349b7d 100644 --- a/src/gui/colour.h +++ b/src/gui/colour.h @@ -88,6 +88,12 @@ class Colour : public gcn::ListModel int getColourAt(int i); /** + * Get the character used by the colour for the element at index i in + * the current colour model + */ + char getColourCharAt(int i); + + /** * Set the colour for the element at index i */ void setColourAt(int i, int rgb); diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index e69b681c..09f7c5e7 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -35,15 +35,17 @@ ImageRect ScrollArea::background; ImageRect ScrollArea::vMarker; Image *ScrollArea::buttons[4][2]; -ScrollArea::ScrollArea(bool gc): +ScrollArea::ScrollArea(bool gc, bool opaque): gcn::ScrollArea(), + mOpaque(opaque), mGC(gc) { init(); } -ScrollArea::ScrollArea(gcn::Widget *widget, bool gc): +ScrollArea::ScrollArea(gcn::Widget *widget, bool gc, bool opaque): gcn::ScrollArea(widget), + mOpaque(opaque), mGC(gc) { init(); @@ -52,9 +54,8 @@ ScrollArea::ScrollArea(gcn::Widget *widget, bool gc): ScrollArea::~ScrollArea() { // Garbage collection - if (mGC) { + if (mGC) delete getContent(); - } instances--; @@ -88,8 +89,10 @@ void ScrollArea::init() const int bggridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { background.grid[a] = textbox->getSubImage( bggridx[x], bggridy[y], bggridx[x + 1] - bggridx[x] + 1, diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h index ccc1e178..33ebc692 100644 --- a/src/gui/scrollarea.h +++ b/src/gui/scrollarea.h @@ -38,12 +38,12 @@ class ScrollArea : public gcn::ScrollArea /** * Constructor. */ - ScrollArea(bool gc = true); + ScrollArea(bool gc = true, bool opaque = true); /** * Constructor. */ - ScrollArea(gcn::Widget *content, bool gc = true); + ScrollArea(gcn::Widget *content, bool gc = true, bool opaque = true); /** * Destructor. diff --git a/src/gui/setup_colours.cpp b/src/gui/setup_colours.cpp index d0ab426a..acc28b1f 100644 --- a/src/gui/setup_colours.cpp +++ b/src/gui/setup_colours.cpp @@ -19,11 +19,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include <string> + #include <guichan/listmodel.hpp> #include <guichan/widgets/label.hpp> #include <guichan/widgets/slider.hpp> +#include "browserbox.h" #include "colour.h" +#include "itemlinkhandler.h" #include "listbox.h" #include "scrollarea.h" #include "setup_colours.h" @@ -35,6 +39,7 @@ #include "../configuration.h" #include "../utils/gettext.h" +#include "../utils/tostring.h" Setup_Colours::Setup_Colours() : mSelected(-1) @@ -48,6 +53,18 @@ Setup_Colours::Setup_Colours() : mScroll = new ScrollArea(mColourBox); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); + mPreview->setOpaque(false); + + // Replace this later with a more appropriate link handler. For now, this'll + // do, as it'll do nothing when clicked on. + mPreview->setLinkHandler(new ItemLinkHandler()); + + mPreviewBox = new ScrollArea(mPreview); + mPreviewBox->setHeight(20); + mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, + gcn::ScrollArea::SHOW_NEVER); + mRedLabel = new gcn::Label(_("Red: ")); mRedText = new TextField(); @@ -96,16 +113,17 @@ Setup_Colours::Setup_Colours() : LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mScroll, 4, 3).setPadding(2); - place(0, 3, mRedLabel, 2); - place(2, 3, mRedSlider); - place(3, 3, mRedText).setPadding(1); - place(0, 4, mGreenLabel, 2); - place(2, 4, mGreenSlider); - place(3, 4, mGreenText).setPadding(1); - place(0, 5, mBlueLabel, 2); - place(2, 5, mBlueSlider); - place(3, 5, mBlueText).setPadding(1); + place(0, 0, mScroll, 4, 7).setPadding(2); + place(0, 7, mPreviewBox, 4).setPadding(2); + place(0, 8, mRedLabel, 2); + place(2, 8, mRedSlider); + place(3, 8, mRedText).setPadding(1); + place(0, 9, mGreenLabel, 2); + place(2, 9, mGreenSlider); + place(3, 9, mGreenText).setPadding(1); + place(0, 10, mBlueLabel, 2); + place(2, 10, mBlueSlider); + place(3, 10, mBlueText).setPadding(1); setDimension(gcn::Rectangle(0, 0, 290, 250)); } @@ -133,6 +151,18 @@ void Setup_Colours::action(const gcn::ActionEvent &event) { mSelected = mColourBox->getSelected(); int col = textColour->getColourAt(mSelected); + char ch = textColour->getColourCharAt(mSelected); + std::string msg; + + if (ch == '<') + msg = toString("@@|") + + _("This is what the color looks like") + "@@"; + else + msg = "##" + toString(ch) + + _("This is what the color looks like"); + + mPreview->clearRows(); + mPreview->addRow(msg); setEntry(mRedSlider, mRedText, col >> 16); setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); setEntry(mBlueSlider, mBlueText, col & 0xff); @@ -167,7 +197,7 @@ void Setup_Colours::action(const gcn::ActionEvent &event) } } -void Setup_Colours::setEntry(Slider *s, TextField *t, int value) +void Setup_Colours::setEntry(gcn::Slider *s, TextField *t, int value) { s->setValue(value); char buffer[100]; diff --git a/src/gui/setup_colours.h b/src/gui/setup_colours.h index f7984dd5..f56daa60 100644 --- a/src/gui/setup_colours.h +++ b/src/gui/setup_colours.h @@ -29,13 +29,13 @@ #include <guichan/widgets/label.hpp> #include <guichan/widgets/listbox.hpp> -#include "scrollarea.h" #include "setuptab.h" -#include "slider.h" #include "textfield.h" #include "../guichanfwd.h" +class BrowserBox; + class Setup_Colours : public SetupTab, public gcn::ActionListener, public TextFieldListener { @@ -49,25 +49,27 @@ class Setup_Colours : public SetupTab, public gcn::ActionListener, void listen(const TextField *tf); private: gcn::ListBox *mColourBox; - ScrollArea *mScroll; + gcn::ScrollArea *mScroll; + BrowserBox *mPreview; + gcn::ScrollArea *mPreviewBox; int mSelected; gcn::Label *mRedLabel; - Slider *mRedSlider; + gcn::Slider *mRedSlider; TextField *mRedText; int mRedValue; gcn::Label *mGreenLabel; - Slider *mGreenSlider; + gcn::Slider *mGreenSlider; TextField *mGreenText; int mGreenValue; gcn::Label *mBlueLabel; - Slider *mBlueSlider; + gcn::Slider *mBlueSlider; TextField *mBlueText; int mBlueValue; - void setEntry(Slider *s, TextField *t, int value); + void setEntry(gcn::Slider *s, TextField *t, int value); void updateColour(); }; #endif |