diff options
author | Douglas Boffey <DougABoffey@netscape.net> | 2008-09-04 17:05:27 +0000 |
---|---|---|
committer | Douglas Boffey <DougABoffey@netscape.net> | 2008-09-04 17:05:27 +0000 |
commit | c57fdaf3c18f34678cf4753a1fae0e6d622839a7 (patch) | |
tree | 3a183f500fa8b9f1679b420e0894496fad1299f5 /src/gui/setup_colours.cpp | |
parent | 7946cd875877870e7cab002cba099d21cf9fc063 (diff) | |
download | mana-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.tar.gz mana-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.tar.bz2 mana-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.tar.xz mana-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.zip |
Added omitted files from rev 405
Diffstat (limited to 'src/gui/setup_colours.cpp')
-rw-r--r-- | src/gui/setup_colours.cpp | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/src/gui/setup_colours.cpp b/src/gui/setup_colours.cpp new file mode 100644 index 00000000..2c6d7aa9 --- /dev/null +++ b/src/gui/setup_colours.cpp @@ -0,0 +1,208 @@ +/*************************************************************************** + * Copyright (C) 2008 by Douglas Boffey * + * * + * DougABoffey@netscape.net * + * 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 * + * (at your option) any later version. * + * * + * This program is distributed with The Mana Experiment * + * 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 "setup_colours.h" + +#include <vector> + +#include <guichan/listmodel.hpp> +#include <guichan/widgets/label.hpp> +#include <guichan/widgets/slider.hpp> + +#include "colour.h" +#include "scrollarea.h" +#include "slider.h" + +#include "../configuration.h" + +Setup_Colours::Setup_Colours() : + mColourLabel("Colour:"), + mSelected(-1) +{ + mColourBox = new gcn::ListBox(textColour); + mScroll = new ScrollArea(mColourBox); + + mColourLabel.setX(5); + mColourLabel.setY(5); + + mColourBox->setDimension(gcn::Rectangle(0, 10 + mColourLabel.getHeight(), + 80, + 115 - mColourLabel.getHeight())); + mScroll->setDimension(gcn::Rectangle(5, 10 + mColourLabel.getHeight(), + 100, 115 - mColourLabel.getHeight())); + mColourBox->setSelected(-1); + mColourBox->setActionEventId("colour_box"); + mColourBox->addActionListener(this); + + setOpaque(false); + + add(&mColourLabel); + add(mScroll); + + setupPlacer(140, mLabel1, mSlider1, mText1, "R", "1"); + setupPlacer(165, mLabel2, mSlider2, mText2, "G", "2"); + setupPlacer(190, mLabel3, mSlider3, mText3, "B", "3"); + +} + +Setup_Colours::~Setup_Colours() +{ + delete mLabel1; + delete mSlider1; + delete mText1; + + delete mLabel2; + delete mSlider2; + delete mText2; + + delete mLabel3; + delete mSlider3; + delete mText3; + + delete mScroll; +} + +void Setup_Colours::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "colour_box") + { + mSelected = mColourBox->getSelected(); + int col = textColour->getColourAt(mSelected); + setEntry(mSlider1, mText1, col >> 16); + setEntry(mSlider2, mText2, (col >> 8) & 0xff); + setEntry(mSlider3, mText3, col & 0xff); + return; + } + + if (event.getId() == "slider1") + { + char buffer[30]; + std::sprintf(buffer, "%d", static_cast<int>(mSlider1->getValue())); + mText1->setText(buffer); + updateColour(); + return; + } + + if (event.getId() == "slider2") + { + char buffer[30]; + std::sprintf(buffer, "%d", static_cast<int>(mSlider2->getValue())); + mText2->setText(buffer); + updateColour(); + return; + } + + if (event.getId() == "slider3") + { + char buffer[30]; + std::sprintf(buffer, "%d", static_cast<int>(mSlider3->getValue())); + mText3->setText(buffer); + updateColour(); + return; + } +} + +void Setup_Colours::setEntry(Slider *s, TextField *t, int value) +{ + s->setValue(value); + char buffer[100]; + sprintf(buffer, "%d", value); + t->setText(buffer); +} + +void Setup_Colours::apply() +{ + textColour->commit(); +} + +void Setup_Colours::cancel() +{ + textColour->rollback(); + int col = textColour->getColourAt(mSelected); + setEntry(mSlider1, mText1, col >> 16); + setEntry(mSlider2, mText2, (col >> 8) & 0xff); + setEntry(mSlider3, mText3, col & 0xff); +} + +void Setup_Colours::setupPlacer(int v, gcn::Label *&l, Slider *&s, + TextField *&t, std::string lbl, + std::string sfx) +{ + l = new gcn::Label(lbl + ":"); + l->setX(5); + l->setY(v - l->getHeight() / 2); + + s = new Slider(0, 255); + s->setHeight(10); + s->setX(25); + s->setY(v - s->getHeight() / 2); + s->setWidth(128); + s->setScale(0, 255); + + t = new TextField(); + t->setX(165); + t->setY(v - t->getHeight() / 2); + t->setWidth(40); + t->setNumeric(true); + t->setRange(0, 255); + t->addListener(this); + + s->setActionEventId("slider" + sfx); + s->addActionListener(this); + + add(l); + add(s); + add(t); +} + +void Setup_Colours::listen(const TextField *tf) +{ + if (tf == mText1) + { + mSlider1->setValue(tf->getValue()); + updateColour(); + return; + } + if (tf == mText2) + { + mSlider2->setValue(tf->getValue()); + updateColour(); + return; + } + if (tf == mText3) + { + mSlider3->setValue(tf->getValue()); + updateColour(); + return; + } +} + +void Setup_Colours::updateColour() +{ + if (mSelected == -1) + { + return; + } + int rgb = static_cast<int>(mSlider1->getValue()) << 16 | + static_cast<int>(mSlider2->getValue()) << 8 | + static_cast<int>(mSlider3->getValue()); + textColour->setColourAt(mSelected, rgb); +} |