summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorMajin Sniper <majinsniper@gmx.de>2009-03-12 16:48:03 +0100
committerIra Rice <irarice@gmail.com>2009-03-12 21:38:36 -0600
commit5207b4cbb462cfa962a6f566897a6affd92eef94 (patch)
treec9129fbf894b7756f5c4c5e1180492433ca11ee2 /src/gui
parent7d20381b7b9abdf0934ee0fbbb196c788ea93a0d (diff)
downloadmana-5207b4cbb462cfa962a6f566897a6affd92eef94.tar.gz
mana-5207b4cbb462cfa962a6f566897a6affd92eef94.tar.bz2
mana-5207b4cbb462cfa962a6f566897a6affd92eef94.tar.xz
mana-5207b4cbb462cfa962a6f566897a6affd92eef94.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.cpp8
-rw-r--r--src/gui/palette.h26
-rw-r--r--src/gui/setup_colors.cpp185
-rw-r--r--src/gui/setup_colors.h8
-rw-r--r--src/gui/widgets/textpreview.cpp58
-rw-r--r--src/gui/widgets/textpreview.h115
6 files changed, 356 insertions, 44 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2c0ddee9..434fc1e1 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -26,6 +26,7 @@
#include "focushandler.h"
#include "gui.h"
+#include "palette.h"
#include "sdlinput.h"
#include "skin.h"
#include "truetypefont.h"
@@ -48,11 +49,6 @@ 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;
-
// Bolded font
gcn::Font *boldFont = 0;
@@ -177,6 +173,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 a372d6cd..02489686 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -109,7 +109,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
@@ -125,12 +125,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 4f017e15..5019a61a 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);
// Replace this later with a more appropriate link handler. For now, this'll
// do, as it'll do nothing when clicked on.
@@ -68,6 +71,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();
@@ -75,12 +89,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: "));
@@ -89,12 +105,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: "));
@@ -103,12 +121,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);
@@ -116,8 +136,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);
@@ -133,23 +156,10 @@ Setup_Colors::Setup_Colors() :
Setup_Colors::~Setup_Colors()
{
- delete mPreview;
- delete mPreviewBox;
-
- delete mRedLabel;
- delete mRedSlider;
- delete mRedText;
-
- delete mGreenLabel;
- delete mGreenSlider;
- delete mGreenText;
-
- delete mBlueLabel;
- delete mBlueSlider;
- delete mBlueText;
-
- delete mColorBox;
- delete mScroll;
+ if (mPreviewBox->getContent() == mPreview)
+ delete mTextPreview;
+ else
+ delete mPreview;
}
void Setup_Colors::action(const gcn::ActionEvent &event)
@@ -159,20 +169,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;
}
@@ -216,6 +309,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);
@@ -243,16 +337,43 @@ 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)
- {
return;
- }
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 6cf59b6d..00f77d57 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,14 @@ 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;
+
gcn::Label *mRedLabel;
gcn::Slider *mRedSlider;
TextField *mRedText;
@@ -73,5 +80,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..f77657c2
--- /dev/null
+++ b/src/gui/widgets/textpreview.cpp
@@ -0,0 +1,58 @@
+/*
+ * 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 <typeinfo>
+
+#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()));
+
+ const std::string ttf = "TrueTypeFont";
+
+ if (mTextBGColor && typeid(*mFont).name() == ttf)
+ {
+ 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..12db9f3f
--- /dev/null
+++ b/src/gui/widgets/textpreview.h
@@ -0,0 +1,115 @@
+/*
+ * 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