From 4a41ce55224ad7b54c6b5ea78126d8d314f5ef41 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 10 Feb 2009 16:56:05 +0100 Subject: Changed spelling from colour to color. --- aethyra.cbp | 8 +- po/POTFILES.in | 4 +- src/CMakeLists.txt | 8 +- src/Makefile.am | 8 +- src/gui/browserbox.cpp | 8 +- src/gui/color.cpp | 146 +++++++++++++++++++++++++ src/gui/color.h | 136 +++++++++++++++++++++++ src/gui/colour.cpp | 146 ------------------------- src/gui/colour.h | 136 ----------------------- src/gui/gui.cpp | 2 +- src/gui/listbox.cpp | 8 +- src/gui/setup.cpp | 4 +- src/gui/setup_colors.cpp | 249 +++++++++++++++++++++++++++++++++++++++++++ src/gui/setup_colors.h | 75 +++++++++++++ src/gui/setup_colours.cpp | 249 ------------------------------------------- src/gui/setup_colours.h | 75 ------------- src/gui/shoplistbox.cpp | 8 +- src/gui/table.cpp | 14 +-- src/gui/widgets/dropdown.cpp | 4 +- src/main.cpp | 8 +- src/text.cpp | 10 +- src/text.h | 6 +- 22 files changed, 656 insertions(+), 656 deletions(-) create mode 100644 src/gui/color.cpp create mode 100644 src/gui/color.h delete mode 100644 src/gui/colour.cpp delete mode 100644 src/gui/colour.h create mode 100644 src/gui/setup_colors.cpp create mode 100644 src/gui/setup_colors.h delete mode 100644 src/gui/setup_colours.cpp delete mode 100644 src/gui/setup_colours.h diff --git a/aethyra.cbp b/aethyra.cbp index 795e179a..08ec74fd 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -132,8 +132,8 @@ - - + + @@ -215,8 +215,8 @@ - - + + diff --git a/po/POTFILES.in b/po/POTFILES.in index 295a6127..1b3dea84 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,7 +5,7 @@ src/gui/buysell.cpp src/gui/char_select.cpp src/gui/char_server.cpp src/gui/chat.cpp -src/gui/colour.cpp +src/gui/color.cpp src/gui/confirm_dialog.cpp src/gui/connection.cpp src/gui/emotecontainer.cpp @@ -31,7 +31,7 @@ src/gui/register.cpp src/gui/sell.cpp src/gui/setup_audio.cpp src/gui/setup.cpp -src/gui/setup_colours.cpp +src/gui/setup_colors.cpp src/gui/setup_joystick.cpp src/gui/setup_keyboard.cpp src/gui/setup_players.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e26ff97..25bcbfb0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,8 +81,8 @@ SET(SRCS gui/chatinput.h gui/checkbox.cpp gui/checkbox.h - gui/colour.cpp - gui/colour.h + gui/color.cpp + gui/color.h gui/confirm_dialog.cpp gui/confirm_dialog.h gui/connection.cpp @@ -164,8 +164,8 @@ SET(SRCS gui/setup.h gui/setup_audio.cpp gui/setup_audio.h - gui/setup_colours.cpp - gui/setup_colours.h + gui/setup_colors.cpp + gui/setup_colors.h gui/setup_joystick.cpp gui/setup_joystick.h gui/setup_keyboard.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b6b052f4..71862994 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,8 +31,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/chatinput.h \ gui/checkbox.cpp \ gui/checkbox.h \ - gui/colour.cpp \ - gui/colour.h \ + gui/color.cpp \ + gui/color.h \ gui/confirm_dialog.cpp \ gui/confirm_dialog.h \ gui/connection.cpp \ @@ -114,8 +114,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/setup.h \ gui/setup_audio.cpp \ gui/setup_audio.h \ - gui/setup_colours.cpp \ - gui/setup_colours.h \ + gui/setup_colors.cpp \ + gui/setup_colors.h \ gui/setup_joystick.cpp \ gui/setup_joystick.h \ gui/setup_keyboard.cpp \ diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 37480415..18fa2ad4 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -25,7 +25,7 @@ #include #include "browserbox.h" -#include "colour.h" +#include "color.h" #include "linkhandler.h" #include "truetypefont.h" @@ -255,7 +255,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) bool valid; if ((mHighMode & BACKGROUND)) { - graphics->setColor(gcn::Color(textColour->getColour('H', valid))); + graphics->setColor(gcn::Color(textColor->getColor('H', valid))); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -266,7 +266,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - graphics->setColor(gcn::Color(textColour->getColour('<', valid))); + graphics->setColor(gcn::Color(textColor->getColor('<', valid))); graphics->drawLine( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y2, @@ -332,7 +332,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) else { bool valid; - int rgb = textColour->getColour(c, valid); + int rgb = textColor->getColor(c, valid); if (c == '<') { const int size = mLinks[link].x2 - mLinks[link].x1; diff --git a/src/gui/color.cpp b/src/gui/color.cpp new file mode 100644 index 00000000..62537191 --- /dev/null +++ b/src/gui/color.cpp @@ -0,0 +1,146 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * + * This file is part of Aethyra. + * + * 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 "color.h" + +#include "../configuration.h" + +#include "../utils/gettext.h" +#include "../utils/tostring.h" + +Color::Color() +{ + addColor('C', 0x000000, _("Chat")); + addColor('G', 0xff0000, _("GM")); + addColor('H', 0xebc873, _("Highlight")); + addColor('Y', 0x1fa052, _("Player")); + addColor('W', 0x0000ff, _("Whisper")); + addColor('I', 0xf1dc27, _("Is")); + addColor('P', 0xff00d8, _("Party")); + addColor('S', 0x8415e2, _("Server")); + addColor('L', 0x919191, _("Logger")); + addColor('<', 0xe50d0d, _("Hyperlink")); + commit(); +} + +Color::~Color() +{ + for (ColVector::iterator col = mColVector.begin(), + colEnd = mColVector.end(); + col != colEnd; + ++col) + { + config.setValue("Color" + col->text, toString(col->rgb)); + } +} + +void Color::setColor(const char c, const int rgb) +{ + for (ColVector::iterator col = mColVector.begin(), + colEnd = mColVector.end(); + col != colEnd; + ++col) + { + if (col->ch == c) + { + col->rgb = rgb; + return; + } + } +} + +int Color::getColor(const char c, bool &valid) const +{ + for (ColVector::const_iterator col = mColVector.begin(), + colEnd = mColVector.end(); + col != colEnd; + ++col) + { + if (col->ch == c) + { + valid = true; + return col->rgb; + } + } + valid = false; + return 0x000000; +} + +std::string Color::getElementAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return mColVector[i].text; +} + +char Color::getColorCharAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return 'C'; + } + return mColVector[i].ch; +} + +void Color::addColor(const char c, const int rgb, const std::string &text) +{ + int trueRgb = config.getValue("Color" + text, rgb); + mColVector.push_back(ColorElem(c, trueRgb, text)); +} + +int Color::getColorAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return 0; + } + return mColVector[i].rgb; +} + +void Color::setColorAt(int i, int rgb) +{ + if (i >= 0 && i < getNumberOfElements()) + { + mColVector[i].rgb = rgb; + } +} + +void Color::commit() +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; + ++i) + { + i->committedRgb = i->rgb; + } +} + +void Color::rollback() +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; + ++i) + { + i->rgb = i->committedRgb; + } +} diff --git a/src/gui/color.h b/src/gui/color.h new file mode 100644 index 00000000..aca3d045 --- /dev/null +++ b/src/gui/color.h @@ -0,0 +1,136 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * + * This file is part of Aethyra. + * + * 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 COLOR_H +#define COLOR_H + +#include +#include + +#include + +class Color : public gcn::ListModel +{ + public: + /** + * Constructor + */ + Color(); + + /** + * Destructor + */ + ~Color(); + + /** + * Define the color replacement for a character + * + * @param c charater to be replaced + * @param rgb color to replace character + */ + void setColor(const char c, const int rgb); + + /** + * Define the color replacement for a character + * + * @param c character to be replaced + * @param r red component + * @param g green component + * @param b blue component + */ + void setColor(const char c, const int r, const int g, const int b) + { + setColor(c, (r << 16) | (g << 8) | b); + } + + /** + * Return the color associated with a character, if exists + * + * @param c character requested + * @param valid indicate whether character is known + */ + int getColor(const char c, bool &valid) const; + + /** + * Return the number of colors known + */ + int getNumberOfElements() {return mColVector.size(); } + + /** + * Return the name of the ith color + * + * @param i index of color interested in + */ + std::string getElementAt(int i); + + /** + * Get the color for the element at index i in the current color + * model + */ + int getColorAt(int i); + + /** + * Get the character used by the color for the element at index i in + * the current color model + */ + char getColorCharAt(int i); + + /** + * Set the color for the element at index i + */ + void setColorAt(int i, int rgb); + + /** + * Commit the colors + */ + void commit(); + + /** + * Rollback the colors + */ + void rollback(); + + private: + struct ColorElem + { + ColorElem(const char c, const int rgb, const std::string &text) : + ch(c), rgb(rgb), text(text) {} + char ch; + int rgb; + int committedRgb; + std::string text; + }; + typedef std::vector ColVector; + ColVector mColVector; + + /** + * Initialise color + * + * @param c character that needs initialising + * @param rgb default color if not found in config + * @param text identifier of color + */ + void addColor(const char c, const int rgb, const std::string &text); +}; + +extern Color *textColor; + +#endif diff --git a/src/gui/colour.cpp b/src/gui/colour.cpp deleted file mode 100644 index 095662ef..00000000 --- a/src/gui/colour.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * 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 "colour.h" - -#include "../configuration.h" - -#include "../utils/gettext.h" -#include "../utils/tostring.h" - -Colour::Colour() -{ - addColour('C', 0x000000, _("Chat")); - addColour('G', 0xff0000, _("GM")); - addColour('H', 0xebc873, _("Highlight")); - addColour('Y', 0x1fa052, _("Player")); - addColour('W', 0x0000ff, _("Whisper")); - addColour('I', 0xf1dc27, _("Is")); - addColour('P', 0xff00d8, _("Party")); - addColour('S', 0x8415e2, _("Server")); - addColour('L', 0x919191, _("Logger")); - addColour('<', 0xe50d0d, _("Hyperlink")); - commit(); -} - -Colour::~Colour() -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - config.setValue("Colour" + col->text, toString(col->rgb)); - } -} - -void Colour::setColour(const char c, const int rgb) -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - col->rgb = rgb; - return; - } - } -} - -int Colour::getColour(const char c, bool &valid) const -{ - for (ColVector::const_iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - valid = true; - return col->rgb; - } - } - valid = false; - return 0x000000; -} - -std::string Colour::getElementAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return ""; - } - 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); - mColVector.push_back(ColourElem(c, trueRgb, text)); -} - -int Colour::getColourAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 0; - } - return mColVector[i].rgb; -} - -void Colour::setColourAt(int i, int rgb) -{ - if (i >= 0 && i < getNumberOfElements()) - { - mColVector[i].rgb = rgb; - } -} - -void Colour::commit() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->committedRgb = i->rgb; - } -} - -void Colour::rollback() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->rgb = i->committedRgb; - } -} diff --git a/src/gui/colour.h b/src/gui/colour.h deleted file mode 100644 index 820c319d..00000000 --- a/src/gui/colour.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * 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 COLOUR_H -#define COLOUR_H - -#include -#include - -#include - -class Colour : public gcn::ListModel -{ - public: - /** - * Constructor - */ - Colour(); - - /** - * Destructor - */ - ~Colour(); - - /** - * Define the colour replacement for a character - * - * @param c charater to be replaced - * @param rgb colour to replace character - */ - void setColour(const char c, const int rgb); - - /** - * Define the colour replacement for a character - * - * @param c character to be replaced - * @param r red component - * @param g green component - * @param b blue component - */ - void setColour(const char c, const int r, const int g, const int b) - { - setColour(c, (r << 16) | (g << 8) | b); - } - - /** - * Return the colour associated with a character, if exists - * - * @param c character requested - * @param valid indicate whether character is known - */ - int getColour(const char c, bool &valid) const; - - /** - * Return the number of colours known - */ - int getNumberOfElements() {return mColVector.size(); } - - /** - * Return the name of the ith colour - * - * @param i index of colour interested in - */ - std::string getElementAt(int i); - - /** - * Get the colour for the element at index i in the current colour - * model - */ - 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); - - /** - * Commit the colours - */ - void commit(); - - /** - * Rollback the colours - */ - void rollback(); - - private: - struct ColourElem - { - ColourElem(const char c, const int rgb, const std::string &text) : - ch(c), rgb(rgb), text(text) {} - char ch; - int rgb; - int committedRgb; - std::string text; - }; - typedef std::vector ColVector; - ColVector mColVector; - - /** - * Initialise colour - * - * @param c character that needs initialising - * @param rgb default colour if not found in config - * @param text identifier of colour - */ - void addColour(const char c, const int rgb, const std::string &text); -}; - -extern Colour *textColour; - -#endif diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index a8a2a72f..f8901119 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -135,7 +135,7 @@ Gui::Gui(Graphics *graphics): gcn::Widget::setGlobalFont(mGuiFont); - // Load hits' colourful fonts + // Load hits' colorful fonts try { hitRedFont = new gcn::ImageFont("graphics/gui/hits_red.png", diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 97b3bbd0..12bb2c02 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -24,7 +24,7 @@ #include #include -#include "colour.h" +#include "color.h" #include "listbox.h" #include "../configuration.h" @@ -45,9 +45,9 @@ void ListBox::draw(gcn::Graphics *graphics) mAlpha = config.getValue("guialpha", 0.8); bool valid; - const int red = (textColour->getColour('H', valid) >> 16) & 0xFF; - const int green = (textColour->getColour('H', valid) >> 8) & 0xFF; - const int blue = textColour->getColour('H', valid) & 0xFF; + const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; + const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; + const int blue = textColor->getColor('H', valid) & 0xFF; const int alpha = mAlpha * 255; graphics->setColor(gcn::Color(red, green, blue, alpha)); diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 2c187f94..4798f598 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -23,7 +23,7 @@ #include "button.h" #include "setup.h" #include "setup_audio.h" -#include "setup_colours.h" +#include "setup_colors.h" #include "setup_joystick.h" #include "setup_keyboard.h" #include "setup_players.h" @@ -91,7 +91,7 @@ Setup::Setup(): panel->addTab(_("Keyboard"), tab); mTabs.push_back(tab); - tab = new Setup_Colours(); + tab = new Setup_Colors(); panel->addTab(_("Colors"), tab); mTabs.push_back(tab); diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp new file mode 100644 index 00000000..f3fa3c65 --- /dev/null +++ b/src/gui/setup_colors.cpp @@ -0,0 +1,249 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * + * This file is part of Aethyra. + * + * 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 +#include + +#include +#include +#include + +#include "browserbox.h" +#include "color.h" +#include "itemlinkhandler.h" +#include "listbox.h" +#include "scrollarea.h" +#include "setup_colors.h" +#include "slider.h" +#include "textfield.h" + +#include "widgets/layouthelper.h" + +#include "../configuration.h" + +#include "../utils/gettext.h" +#include "../utils/tostring.h" + +Setup_Colors::Setup_Colors() : + mSelected(-1) +{ + setOpaque(false); + + mColorBox = new ListBox(textColor); + mColorBox->setActionEventId("color_box"); + mColorBox->addActionListener(this); + + mScroll = new ScrollArea(mColorBox); + 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(); + mRedText->setWidth(40); + mRedText->setRange(0, 255); + mRedText->setNumeric(true); + mRedText->addListener(this); + + mRedSlider = new Slider(0, 255); + mRedSlider->setWidth(160); + mRedSlider->setValue(mRedText->getValue()); + mRedSlider->setActionEventId("slider_red"); + mRedSlider->addActionListener(this); + + mGreenLabel = new gcn::Label(_("Green: ")); + + mGreenText = new TextField(); + mGreenText->setWidth(40); + mGreenText->setRange(0, 255); + mGreenText->setNumeric(true); + mGreenText->addListener(this); + + mGreenSlider = new Slider(0, 255); + mGreenSlider->setWidth(160); + mGreenSlider->setValue(mGreenText->getValue()); + mGreenSlider->setActionEventId("slider_green"); + mGreenSlider->addActionListener(this); + + mBlueLabel = new gcn::Label(_("Blue: ")); + + mBlueText = new TextField(); + mBlueText->setWidth(40); + mBlueText->setRange(0, 255); + mBlueText->setNumeric(true); + mBlueText->addListener(this); + + mBlueSlider = new Slider(0, 255); + mBlueSlider->setWidth(160); + mBlueSlider->setValue(mBlueText->getValue()); + mBlueSlider->setActionEventId("slider_blue"); + mBlueSlider->addActionListener(this); + + setOpaque(false); + + // Do the layout + 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, 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, 325, 280)); +} + +Setup_Colors::~Setup_Colors() +{ + delete mRedLabel; + delete mRedSlider; + delete mRedText; + + delete mGreenLabel; + delete mGreenSlider; + delete mGreenText; + + delete mBlueLabel; + delete mBlueSlider; + delete mBlueText; + + delete mScroll; +} + +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); + 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); + return; + } + + if (event.getId() == "slider_red") + { + mRedText->setText(toString(std::floor(mRedSlider->getValue()))); + updateColor(); + return; + } + + if (event.getId() == "slider_green") + { + mGreenText->setText(toString(std::floor(mGreenSlider->getValue()))); + updateColor(); + return; + } + + if (event.getId() == "slider_blue") + { + mBlueText->setText(toString(std::floor(mBlueSlider->getValue()))); + updateColor(); + return; + } +} + +void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value) +{ + s->setValue(value); + char buffer[100]; + sprintf(buffer, "%d", value); + t->setText(buffer); +} + +void Setup_Colors::apply() +{ + textColor->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); +} + +void Setup_Colors::listen(const TextField *tf) +{ + if (tf == mRedText) + { + mRedSlider->setValue(tf->getValue()); + updateColor(); + return; + } + if (tf == mGreenText) + { + mGreenSlider->setValue(tf->getValue()); + updateColor(); + return; + } + if (tf == mBlueText) + { + mBlueSlider->setValue(tf->getValue()); + updateColor(); + return; + } +} + +void Setup_Colors::updateColor() +{ + if (mSelected == -1) + { + return; + } + int rgb = static_cast(mRedSlider->getValue()) << 16 | + static_cast(mGreenSlider->getValue()) << 8 | + static_cast(mBlueSlider->getValue()); + textColor->setColorAt(mSelected, rgb); +} diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h new file mode 100644 index 00000000..98a2d18b --- /dev/null +++ b/src/gui/setup_colors.h @@ -0,0 +1,75 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * + * This file is part of Aethyra. + * + * 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 SETUP_COLORS_H +#define SETUP_COLORS_H + +#include + +#include + +#include +#include + +#include "setuptab.h" +#include "textfield.h" + +#include "../guichanfwd.h" + +class BrowserBox; + +class Setup_Colors : public SetupTab, public gcn::ActionListener, + public TextFieldListener +{ + public: + Setup_Colors(); + ~Setup_Colors(); + void apply(); + void cancel(); + void action(const gcn::ActionEvent &event); + + void listen(const TextField *tf); + private: + gcn::ListBox *mColorBox; + gcn::ScrollArea *mScroll; + BrowserBox *mPreview; + gcn::ScrollArea *mPreviewBox; + int mSelected; + + gcn::Label *mRedLabel; + gcn::Slider *mRedSlider; + TextField *mRedText; + int mRedValue; + + gcn::Label *mGreenLabel; + gcn::Slider *mGreenSlider; + TextField *mGreenText; + int mGreenValue; + + gcn::Label *mBlueLabel; + gcn::Slider *mBlueSlider; + TextField *mBlueText; + int mBlueValue; + + void setEntry(gcn::Slider *s, TextField *t, int value); + void updateColor(); +}; +#endif diff --git a/src/gui/setup_colours.cpp b/src/gui/setup_colours.cpp deleted file mode 100644 index 03fdcfec..00000000 --- a/src/gui/setup_colours.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * 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 -#include - -#include -#include -#include - -#include "browserbox.h" -#include "colour.h" -#include "itemlinkhandler.h" -#include "listbox.h" -#include "scrollarea.h" -#include "setup_colours.h" -#include "slider.h" -#include "textfield.h" - -#include "widgets/layouthelper.h" - -#include "../configuration.h" - -#include "../utils/gettext.h" -#include "../utils/tostring.h" - -Setup_Colours::Setup_Colours() : - mSelected(-1) -{ - setOpaque(false); - - mColourBox = new ListBox(textColour); - mColourBox->setActionEventId("colour_box"); - mColourBox->addActionListener(this); - - 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(); - mRedText->setWidth(40); - mRedText->setRange(0, 255); - mRedText->setNumeric(true); - mRedText->addListener(this); - - mRedSlider = new Slider(0, 255); - mRedSlider->setWidth(160); - mRedSlider->setValue(mRedText->getValue()); - mRedSlider->setActionEventId("slider_red"); - mRedSlider->addActionListener(this); - - mGreenLabel = new gcn::Label(_("Green: ")); - - mGreenText = new TextField(); - mGreenText->setWidth(40); - mGreenText->setRange(0, 255); - mGreenText->setNumeric(true); - mGreenText->addListener(this); - - mGreenSlider = new Slider(0, 255); - mGreenSlider->setWidth(160); - mGreenSlider->setValue(mGreenText->getValue()); - mGreenSlider->setActionEventId("slider_green"); - mGreenSlider->addActionListener(this); - - mBlueLabel = new gcn::Label(_("Blue: ")); - - mBlueText = new TextField(); - mBlueText->setWidth(40); - mBlueText->setRange(0, 255); - mBlueText->setNumeric(true); - mBlueText->addListener(this); - - mBlueSlider = new Slider(0, 255); - mBlueSlider->setWidth(160); - mBlueSlider->setValue(mBlueText->getValue()); - mBlueSlider->setActionEventId("slider_blue"); - mBlueSlider->addActionListener(this); - - setOpaque(false); - - // Do the layout - 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, 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, 325, 280)); -} - -Setup_Colours::~Setup_Colours() -{ - delete mRedLabel; - delete mRedSlider; - delete mRedText; - - delete mGreenLabel; - delete mGreenSlider; - delete mGreenText; - - delete mBlueLabel; - delete mBlueSlider; - delete mBlueText; - - delete mScroll; -} - -void Setup_Colours::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "colour_box") - { - 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); - return; - } - - if (event.getId() == "slider_red") - { - mRedText->setText(toString(std::floor(mRedSlider->getValue()))); - updateColour(); - return; - } - - if (event.getId() == "slider_green") - { - mGreenText->setText(toString(std::floor(mGreenSlider->getValue()))); - updateColour(); - return; - } - - if (event.getId() == "slider_blue") - { - mBlueText->setText(toString(std::floor(mBlueSlider->getValue()))); - updateColour(); - return; - } -} - -void Setup_Colours::setEntry(gcn::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(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); -} - -void Setup_Colours::listen(const TextField *tf) -{ - if (tf == mRedText) - { - mRedSlider->setValue(tf->getValue()); - updateColour(); - return; - } - if (tf == mGreenText) - { - mGreenSlider->setValue(tf->getValue()); - updateColour(); - return; - } - if (tf == mBlueText) - { - mBlueSlider->setValue(tf->getValue()); - updateColour(); - return; - } -} - -void Setup_Colours::updateColour() -{ - if (mSelected == -1) - { - return; - } - int rgb = static_cast(mRedSlider->getValue()) << 16 | - static_cast(mGreenSlider->getValue()) << 8 | - static_cast(mBlueSlider->getValue()); - textColour->setColourAt(mSelected, rgb); -} diff --git a/src/gui/setup_colours.h b/src/gui/setup_colours.h deleted file mode 100644 index ac06c178..00000000 --- a/src/gui/setup_colours.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * 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 SETUP_COLOURS_H -#define SETUP_COLOURS_H - -#include - -#include - -#include -#include - -#include "setuptab.h" -#include "textfield.h" - -#include "../guichanfwd.h" - -class BrowserBox; - -class Setup_Colours : public SetupTab, public gcn::ActionListener, - public TextFieldListener -{ - public: - Setup_Colours(); - ~Setup_Colours(); - void apply(); - void cancel(); - void action(const gcn::ActionEvent &event); - - void listen(const TextField *tf); - private: - gcn::ListBox *mColourBox; - gcn::ScrollArea *mScroll; - BrowserBox *mPreview; - gcn::ScrollArea *mPreviewBox; - int mSelected; - - gcn::Label *mRedLabel; - gcn::Slider *mRedSlider; - TextField *mRedText; - int mRedValue; - - gcn::Label *mGreenLabel; - gcn::Slider *mGreenSlider; - TextField *mGreenText; - int mGreenValue; - - gcn::Label *mBlueLabel; - gcn::Slider *mBlueSlider; - TextField *mBlueText; - int mBlueValue; - - void setEntry(gcn::Slider *s, TextField *t, int value); - void updateColour(); -}; -#endif diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 9e53dff7..4f9f9024 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -23,7 +23,7 @@ #include #include -#include "colour.h" +#include "color.h" #include "shop.h" #include "shoplistbox.h" @@ -65,9 +65,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) mAlpha = config.getValue("guialpha", 0.8); bool valid; - const int red = (textColour->getColour('H', valid) >> 16) & 0xFF; - const int green = (textColour->getColour('H', valid) >> 8) & 0xFF; - const int blue = textColour->getColour('H', valid) & 0xFF; + const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; + const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; + const int blue = textColor->getColor('H', valid) & 0xFF; const int alpha = mAlpha * 255; Graphics *graphics = static_cast(gcnGraphics); diff --git a/src/gui/table.cpp b/src/gui/table.cpp index b79d43cf..de7f11b2 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -24,7 +24,7 @@ #include #include -#include "colour.h" +#include "color.h" #include "table.h" #include "../configuration.h" @@ -326,10 +326,10 @@ void GuiTable::draw(gcn::Graphics* graphics) { bool valid; const int red = - (textColour->getColour('H', valid) >> 16) & 0xFF; + (textColor->getColor('H', valid) >> 16) & 0xFF; const int green = - (textColour->getColour('H', valid) >> 8) & 0xFF; - const int blue = textColour->getColour('H', valid) & 0xFF; + (textColor->getColor('H', valid) >> 8) & 0xFF; + const int blue = textColor->getColor('H', valid) & 0xFF; const int alpha = mAlpha * 127; graphics->setColor(gcn::Color(red, green, blue, alpha)); @@ -348,10 +348,10 @@ void GuiTable::draw(gcn::Graphics* graphics) { bool valid; const int red = - (textColour->getColour('H', valid) >> 16) & 0xFF; + (textColor->getColor('H', valid) >> 16) & 0xFF; const int green = - (textColour->getColour('H', valid) >> 8) & 0xFF; - const int blue = textColour->getColour('H', valid) & 0xFF; + (textColor->getColor('H', valid) >> 8) & 0xFF; + const int blue = textColor->getColor('H', valid) & 0xFF; const int alpha = mAlpha * 127; graphics->setColor(gcn::Color(red, green, blue, alpha)); diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index a292edd5..5d1b8d4f 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -23,7 +23,7 @@ #include "dropdown.h" -#include "../colour.h" +#include "../color.h" #include "../listbox.h" #include "../scrollarea.h" @@ -138,7 +138,7 @@ void DropDown::draw(gcn::Graphics* graphics) const int alpha = mAlpha * 255; gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = textColour->getColour('H', valid); + gcn::Color highlightColor = textColor->getColor('H', valid); highlightColor.a = alpha; gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; diff --git a/src/main.cpp b/src/main.cpp index c68c02d8..80cff8d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,7 +56,7 @@ #include "gui/button.h" #include "gui/char_server.h" #include "gui/char_select.h" -#include "gui/colour.h" +#include "gui/color.h" #include "gui/gui.h" #include "gui/login.h" #include "gui/ok_dialog.h" @@ -136,7 +136,7 @@ CharServerHandler charServerHandler; LoginData loginData; LockedArray charInfo(MAX_SLOT + 1); -Colour *textColour; +Color *textColor; // This anonymous namespace hides whatever is inside from other modules. namespace { @@ -764,7 +764,7 @@ int main(int argc, char *argv[]) unsigned int oldstate = !state; // We start with a status change. // Needs to be created in main, as the updater uses it - textColour = new Colour(); + textColor = new Color(); Game *game = NULL; Window *currentDialog = NULL; @@ -1097,7 +1097,7 @@ int main(int argc, char *argv[]) usleep(50000); } - delete textColour; + delete textColor; #ifdef PACKAGE_VERSION delete versionLabel; #endif diff --git a/src/text.cpp b/src/text.cpp index 5a015139..e5e40235 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -30,8 +30,8 @@ int Text::mInstances = 0; Text::Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color colour) : - mText(text), mColour(colour) + gcn::Graphics::Alignment alignment, gcn::Color color) : + mText(text), mColor(color) { if (textManager == 0) { @@ -91,13 +91,13 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) graphics->drawText(mText, mX - xOff, mY - yOff - 1, gcn::Graphics::LEFT); - graphics->setColor(mColour); + graphics->setColor(mColor); graphics->drawText(mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT); } FlashText::FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color colour) : - Text(text, x, y, alignment, colour), + gcn::Graphics::Alignment alignment, gcn::Color color) : + Text(text, x, y, alignment, color), mTime(0) { } diff --git a/src/text.h b/src/text.h index d62a125d..0b53dd48 100644 --- a/src/text.h +++ b/src/text.h @@ -39,7 +39,7 @@ class Text * Constructor creates a text object to display on the screen. */ Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color colour); + gcn::Graphics::Alignment alignment, gcn::Color color); /** * Destructor. The text is removed from the screen. @@ -64,14 +64,14 @@ class Text int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - gcn::Color mColour; /**< The colour of the text. */ + gcn::Color mColor; /**< The color of the text. */ }; class FlashText : public Text { public: FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color colour); + gcn::Graphics::Alignment alignment, gcn::Color color); /** * Remove the text from the screen -- cgit v1.2.3-60-g2f50