summaryrefslogtreecommitdiff
path: root/src/gui/setup_colors.cpp
diff options
context:
space:
mode:
authorsniper <sniper@livecd.janhome.net>2009-03-11 15:35:54 +0100
committerJared Adams <jaxad0127@gmail.com>2009-03-12 18:53:16 -0600
commit4260cb92571842c6336537bf0d0c47c4f011ac0f (patch)
tree6c9ce9d69dc6914bb9948b152171d216a801f7c9 /src/gui/setup_colors.cpp
parentf3796c231d5bcac6850fb9afc8db652361e3fceb (diff)
downloadMana-4260cb92571842c6336537bf0d0c47c4f011ac0f.tar.gz
Mana-4260cb92571842c6336537bf0d0c47c4f011ac0f.tar.bz2
Mana-4260cb92571842c6336537bf0d0c47c4f011ac0f.tar.xz
Mana-4260cb92571842c6336537bf0d0c47c4f011ac0f.zip
Extending the internal handling of colors
The internal storage for colors was in the file color.h/color.cpp. It mainly managed the colors in the chat. The Color class was extended to be more generic now and it stores gcn::Color objects instead of integers now. A lot of new colortypes are now available, though not many of them are used for now, that will come in the next patches. The Color class was renamed to Palette and color.{h,cpp} to palette.{h,cpp} to better describe its purpose. The color config gui now lists the new colors, even changes them, but the result is not displayed properly for now.
Diffstat (limited to 'src/gui/setup_colors.cpp')
-rw-r--r--src/gui/setup_colors.cpp55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp
index 2610be03..6f1da525 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -27,9 +27,9 @@
#include <guichan/widgets/slider.hpp>
#include "browserbox.h"
-#include "color.h"
#include "itemlinkhandler.h"
#include "listbox.h"
+#include "palette.h"
#include "scrollarea.h"
#include "setup_colors.h"
#include "slider.h"
@@ -42,12 +42,14 @@
#include "../utils/gettext.h"
#include "../utils/stringutils.h"
+const std::string Setup_Colors::rawmsg = _("This is what the color looks like");
+
Setup_Colors::Setup_Colors() :
mSelected(-1)
{
setOpaque(false);
- mColorBox = new ListBox(textColor);
+ mColorBox = new ListBox(guiPalette);
mColorBox->setActionEventId("color_box");
mColorBox->addActionListener(this);
@@ -130,6 +132,9 @@ Setup_Colors::Setup_Colors() :
Setup_Colors::~Setup_Colors()
{
+ delete mPreview;
+ delete mPreviewBox;
+
delete mRedLabel;
delete mRedSlider;
delete mRedText;
@@ -142,6 +147,7 @@ Setup_Colors::~Setup_Colors()
delete mBlueSlider;
delete mBlueText;
+ delete mColorBox;
delete mScroll;
}
@@ -150,22 +156,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
if (event.getId() == "color_box")
{
mSelected = mColorBox->getSelected();
- int col = textColor->getColorAt(mSelected);
- char ch = textColor->getColorCharAt(mSelected);
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &guiPalette->getColor(type);
+
std::string msg;
+ mPreview->clearRows();
+ char ch = guiPalette->getColorChar(type);
if (ch == '<')
- msg = toString("@@|") +
- _("This is what the color looks like") + "@@";
+ msg = toString("@@|") + rawmsg + "@@";
else
- msg = "##" + toString(ch) +
- _("This is what the color looks like");
-
- mPreview->clearRows();
+ msg = "##" + toString(ch) + rawmsg;
mPreview->addRow(msg);
- setEntry(mRedSlider, mRedText, col >> 16);
- setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff);
- setEntry(mBlueSlider, mBlueText, col & 0xff);
+
+ setEntry(mRedSlider, mRedText, col->r);
+ setEntry(mGreenSlider, mGreenText, col->g);
+ setEntry(mBlueSlider, mBlueText, col->b);
return;
}
@@ -201,16 +207,17 @@ void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value)
void Setup_Colors::apply()
{
- textColor->commit();
+ guiPalette->commit();
}
void Setup_Colors::cancel()
{
- textColor->rollback();
- int col = textColor->getColorAt(mSelected);
- setEntry(mRedSlider, mRedText, col >> 16);
- setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff);
- setEntry(mBlueSlider, mBlueText, col & 0xff);
+ guiPalette->rollback();
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &guiPalette->getColor(type);
+ setEntry(mRedSlider, mRedText, col->r);
+ setEntry(mGreenSlider, mGreenText, col->g);
+ setEntry(mBlueSlider, mBlueText, col->b);
}
void Setup_Colors::listen(const TextField *tf)
@@ -241,8 +248,10 @@ void Setup_Colors::updateColor()
{
return;
}
- int rgb = static_cast<int>(mRedSlider->getValue()) << 16 |
- static_cast<int>(mGreenSlider->getValue()) << 8 |
- static_cast<int>(mBlueSlider->getValue());
- textColor->setColorAt(mSelected, rgb);
+
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ guiPalette->setColor(type,
+ static_cast<int>(mRedSlider->getValue()),
+ static_cast<int>(mGreenSlider->getValue()),
+ static_cast<int>(mBlueSlider->getValue()));
}