diff options
author | Majin Sniper <majinsniper@gmx.de> | 2009-03-12 16:48:03 +0100 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-03-12 19:12:46 -0600 |
commit | b9191530c81595b0ad3d2faa6c4d21d75a720c29 (patch) | |
tree | a13f19443a464caa3329bb3d7d2c7ab378c70c9d /src/gui | |
parent | c7fa79ff1704d86e12e12b83e1e4745ca27a543a (diff) | |
download | mana-b9191530c81595b0ad3d2faa6c4d21d75a720c29.tar.gz mana-b9191530c81595b0ad3d2faa6c4d21d75a720c29.tar.bz2 mana-b9191530c81595b0ad3d2faa6c4d21d75a720c29.tar.xz mana-b9191530c81595b0ad3d2faa6c4d21d75a720c29.zip |
Extend color config gui to support the new colors
The new color palette supports many more colors that the browserbox can
display. So a change to the color config gui was needed.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 7 | ||||
-rw-r--r-- | src/gui/palette.h | 26 | ||||
-rw-r--r-- | src/gui/setup_colors.cpp | 182 | ||||
-rw-r--r-- | src/gui/setup_colors.h | 9 | ||||
-rw-r--r-- | src/gui/widgets/textpreview.cpp | 53 | ||||
-rw-r--r-- | src/gui/widgets/textpreview.h | 114 |
6 files changed, 366 insertions, 25 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6d6ccbdf..e14642dd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -25,6 +25,7 @@ #include "focushandler.h" #include "gui.h" +#include "palette.h" #include "sdlinput.h" #include "truetypefont.h" #include "viewport.h" @@ -45,11 +46,11 @@ Gui *gui = 0; Viewport *viewport = 0; /**< Viewport on the map. */ SDLInput *guiInput = 0; - +/* // Fonts used in showing hits gcn::Font *hitRedFont = 0; gcn::Font *hitBlueFont = 0; -gcn::Font *hitYellowFont = 0; +gcn::Font *hitYellowFont = 0;*/ // Bolded font gcn::Font *boldFont = 0; @@ -175,6 +176,8 @@ void Gui::logic() else mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f); + guiPalette->advanceGradient(); + gcn::Gui::logic(); } diff --git a/src/gui/palette.h b/src/gui/palette.h index c32fbc8a..77ead4f6 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -108,7 +108,7 @@ class Palette : public gcn::ListModel const gcn::Color& getColor(char c, bool &valid); /** - * Gets the color with the associated type. Sets the alpha channel + * Gets the color associated with the type. Sets the alpha channel * before returning. * * @param type the color type requested @@ -124,12 +124,24 @@ class Palette : public gcn::ListModel } /** - * Gets the GradientType used by the specified color. - * - * @param type the color type of the color - * - * @return the gradient type of the color with the given index - */ + * Gets the committed color associated with the specified type. + * + * @param type the color type requested + * + * @return the requested committed color + */ + inline const gcn::Color& getCommittedColor(ColorType type) + { + return mColVector[type].committedColor; + } + + /** + * Gets the GradientType associated with the specified type. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ inline GradientType getGradientType(ColorType type) { return mColVector[type].grad; diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 6f1da525..7990e217 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,6 +27,7 @@ #include <guichan/widgets/slider.hpp> #include "browserbox.h" +#include "gui.h" #include "itemlinkhandler.h" #include "listbox.h" #include "palette.h" @@ -56,8 +57,10 @@ Setup_Colors::Setup_Colors() : mScroll = new ScrollArea(mColorBox); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mTextPreview = new TextPreview(&rawmsg); + mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); - mPreview->setOpaque(false); + mPreview->setOpaque(true); // don't do anything with links mPreview->setLinkHandler(NULL); @@ -67,6 +70,17 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); + mGradTypeLabel = new gcn::Label(_("Type: ")); + + mGradTypeSlider = new Slider(0, 2); + mGradTypeSlider->setWidth(160); + mGradTypeSlider->setActionEventId("slider_grad"); + mGradTypeSlider->setValue(0); + mGradTypeSlider->addActionListener(this); + mGradTypeSlider->setEnabled(false); + + mGradTypeText = new gcn::Label(); + mRedLabel = new gcn::Label(_("Red: ")); mRedText = new TextField; @@ -74,12 +88,14 @@ Setup_Colors::Setup_Colors() : mRedText->setRange(0, 255); mRedText->setNumeric(true); mRedText->addListener(this); + mRedText->setEnabled(false); mRedSlider = new Slider(0, 255); mRedSlider->setWidth(160); mRedSlider->setValue(mRedText->getValue()); mRedSlider->setActionEventId("slider_red"); mRedSlider->addActionListener(this); + mRedSlider->setEnabled(false); mGreenLabel = new gcn::Label(_("Green: ")); @@ -88,12 +104,14 @@ Setup_Colors::Setup_Colors() : mGreenText->setRange(0, 255); mGreenText->setNumeric(true); mGreenText->addListener(this); + mGreenText->setEnabled(false); mGreenSlider = new Slider(0, 255); mGreenSlider->setWidth(160); mGreenSlider->setValue(mGreenText->getValue()); mGreenSlider->setActionEventId("slider_green"); mGreenSlider->addActionListener(this); + mGreenSlider->setEnabled(false); mBlueLabel = new gcn::Label(_("Blue: ")); @@ -102,12 +120,14 @@ Setup_Colors::Setup_Colors() : mBlueText->setRange(0, 255); mBlueText->setNumeric(true); mBlueText->addListener(this); + mBlueText->setEnabled(false); mBlueSlider = new Slider(0, 255); mBlueSlider->setWidth(160); mBlueSlider->setValue(mBlueText->getValue()); mBlueSlider->setActionEventId("slider_blue"); mBlueSlider->addActionListener(this); + mBlueSlider->setEnabled(false); setOpaque(false); @@ -115,8 +135,11 @@ Setup_Colors::Setup_Colors() : LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mScroll, 4, 7).setPadding(2); - place(0, 7, mPreviewBox, 4).setPadding(2); + place(0, 0, mScroll, 4, 6).setPadding(2); + place(0, 6, mPreviewBox, 4).setPadding(2); + place(0, 7, mGradTypeLabel, 2); + place(2, 7, mGradTypeSlider); + place(3, 7, mGradTypeText); place(0, 8, mRedLabel, 2); place(2, 8, mRedSlider); place(3, 8, mRedText).setPadding(1); @@ -132,8 +155,21 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { - delete mPreview; - delete mPreviewBox; + //delete mPreview; + if (mPreviewBox->getContent() == mPreview) + { + delete mTextPreview; + } + else + { + delete mPreview; + } + // delete mTextPreview; +// delete mPreviewBox; + +/* delete mGradTypeLabel; + delete mGradTypeSlider; + delete mGradTypeText; delete mRedLabel; delete mRedSlider; @@ -148,7 +184,7 @@ Setup_Colors::~Setup_Colors() delete mBlueText; delete mColorBox; - delete mScroll; + delete mScroll;*/ } void Setup_Colors::action(const gcn::ActionEvent &event) @@ -158,20 +194,103 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mSelected = mColorBox->getSelected(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + Palette::GradientType grad = guiPalette->getGradientType(type); std::string msg; + char ch = guiPalette->getColorChar(type); mPreview->clearRows(); - char ch = guiPalette->getColorChar(type); - if (ch == '<') - msg = toString("@@|") + rawmsg + "@@"; - else - msg = "##" + toString(ch) + rawmsg; - mPreview->addRow(msg); + mPreviewBox->setContent(mTextPreview); + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor( + &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextBGColor(NULL); + mTextPreview->setShadow(true); + mTextPreview->setOutline(true); + + switch (type) + { + case Palette::TEXT: + case Palette::SHADOW: + case Palette::OUTLINE: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setOutline(true); + mTextPreview->setShadow(type == Palette::SHADOW); + mTextPreview->setOutline(type == Palette::OUTLINE); + break; + case Palette::BACKGROUND: + case Palette::HIGHLIGHT: + case Palette::SHOP_WARNING: + 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(); + //char ch = guiPalette->getColorCharAt(mSelected); + //std::string msg; + + if (ch == '<') + { + msg = toString("@@|") + rawmsg + "@@"; + } + else + { + msg = "##" + toString(ch) + rawmsg; + } + //std::cout << msg << std::endl; + mPreview->addRow(msg); + 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); + break; + } + + if (grad != Palette::STATIC) + { // If nonstatic color, don't display the current, but the committed + // color at the sliders + col = &guiPalette->getCommittedColor(type); + } 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(); + updateColor(); return; } @@ -215,6 +334,7 @@ void Setup_Colors::cancel() guiPalette->rollback(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + mGradTypeSlider->setValue(guiPalette->getGradientType(type)); setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); @@ -242,6 +362,29 @@ void Setup_Colors::listen(const TextField *tf) } } +void Setup_Colors::updateGradType() { + if (mSelected == -1) + { + return; + } + + mSelected = mColorBox->getSelected(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + Palette::GradientType grad = guiPalette->getGradientType(type); + + mGradTypeText->setCaption( + (grad == Palette::STATIC) ? _("Static") : + (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); + + bool enable = (grad == Palette::STATIC); + mRedText->setEnabled(enable); + mRedSlider->setEnabled(enable); + mGreenText->setEnabled(enable); + mGreenSlider->setEnabled(enable); + mBlueText->setEnabled(enable); + mBlueSlider->setEnabled(enable); +} + void Setup_Colors::updateColor() { if (mSelected == -1) @@ -250,8 +393,15 @@ void Setup_Colors::updateColor() } Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); - guiPalette->setColor(type, - static_cast<int>(mRedSlider->getValue()), - static_cast<int>(mGreenSlider->getValue()), - static_cast<int>(mBlueSlider->getValue())); + Palette::GradientType grad = + static_cast<Palette::GradientType>(mGradTypeSlider->getValue()); + guiPalette->setGradient(type, grad); + + if (grad == Palette::STATIC) + { + guiPalette->setColor(type, + static_cast<int>(mRedSlider->getValue()), + static_cast<int>(mGreenSlider->getValue()), + static_cast<int>(mBlueSlider->getValue())); + } } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 050ea638..842fd6cc 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -34,6 +34,8 @@ #include "../guichanfwd.h" +#include "widgets/textpreview.h" + class BrowserBox; class Setup_Colors : public SetupTab, public gcn::ActionListener, @@ -53,9 +55,15 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; + TextPreview *mTextPreview; gcn::ScrollArea *mPreviewBox; int mSelected; + gcn::Label *mGradTypeLabel; + gcn::Slider *mGradTypeSlider; + gcn::Label *mGradTypeText; +// Palette::GradientType mGradType; + gcn::Label *mRedLabel; gcn::Slider *mRedSlider; TextField *mRedText; @@ -73,5 +81,6 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void setEntry(gcn::Slider *s, TextField *t, int value); void updateColor(); + void updateGradType(); }; #endif diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp new file mode 100644 index 00000000..28d7fd35 --- /dev/null +++ b/src/gui/widgets/textpreview.cpp @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright (C) 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "textpreview.h" + +#include "../gui.h" +#include "../palette.h" +#include "../textrenderer.h" +#include "../truetypefont.h" + +TextPreview::TextPreview(const std::string* text) +{ + mText = text; + mFont = gui->getFont(); + mTextColor = &guiPalette->getColor(Palette::TEXT); + mTextBGColor = NULL; + mBGColor = &guiPalette->getColor(Palette::BACKGROUND); +} + +void TextPreview::draw(gcn::Graphics* graphics) +{ + graphics->setColor(*mBGColor); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + + if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) { + TrueTypeFont *font = static_cast<TrueTypeFont*>(mFont); + graphics->setColor(*mTextBGColor); + int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); + int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + } + + TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, + mTextColor, mFont, mOutline, mShadow); +} diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h new file mode 100644 index 00000000..1c1fa1e4 --- /dev/null +++ b/src/gui/widgets/textpreview.h @@ -0,0 +1,114 @@ +/* + * The Mana World + * Copyright (C) 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TEXTPREVIEW_H +#define TEXTPREVIEW_H + +#include <guichan/color.hpp> +#include <guichan/font.hpp> +#include <guichan/widget.hpp> + +/** + * Preview widget for particle colors, etc. + */ +class TextPreview : public gcn::Widget { + public: + TextPreview(const std::string* text); + + /** + * Sets the color the text is printed in. + * + * @param color the color to set + */ + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + + /** + * Sets the color the text background is drawn in. This is only the + * rectangle directly behind the text, not to full widget. + * + * @param color the color to set + */ + inline void setTextBGColor(const gcn::Color* color) + { + mTextBGColor = color; + } + + /** + * Sets the background color of the widget. + * + * @param color the color to set + */ + inline void setBGColor(const gcn::Color* color) + { + mBGColor = color; + } + + /** + * Sets the font to render the text in. + * + * @param font the font to use. + */ + inline void setFont(gcn::Font *font) + { + mFont = font; + } + + /** + * Sets whether to use a shadow while rendering. + * + * @param shadow true, if a shadow is wanted, false else + */ + inline void setShadow(bool shadow) + { + mShadow = shadow; + } + + /** + * Sets whether to use an outline while rendering. + * + * @param outline true, if an outline is wanted, false else + */ + inline void setOutline(bool outline) + { + mOutline = outline; + } + + /** + * Widget's draw method. Does the actual job. + * + * @param graphics graphics to draw into + */ + void draw(gcn::Graphics *graphics); + + private: + gcn::Font *mFont; + const std::string* mText; + const gcn::Color* mTextColor; + const gcn::Color* mBGColor; + const gcn::Color* mTextBGColor; + bool mShadow; + bool mOutline; +}; + +#endif |