From 269e05e71f09cac3d181f2042cde01e5541658f3 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 3 Feb 2009 12:13:16 -0700 Subject: Made highlights configurable through the color dialog. Signed-off-by: Ira Rice --- src/gui/browserbox.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/gui/browserbox.cpp') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 6fd0482a..cd5479c8 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -122,7 +122,18 @@ void BrowserBox::addRow(const std::string &row) //discard older rows when a row limit has been set if (mMaxRows > 0) { - while (mTextRows.size() > mMaxRows) mTextRows.pop_front(); + while (mTextRows.size() > mMaxRows) + { + mTextRows.pop_front(); + for (unsigned int i = 0; i < mLinks.size(); i++) + { + mLinks[i].y1 -= font->getHeight(); + mLinks[i].y2 -= font->getHeight(); + + if (mLinks[i].y1 < 0) + mLinks.erase(mLinks.begin() + i); + } + } } // Auto size mode @@ -238,9 +249,10 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mSelectedLink >= 0) { + bool valid; if ((mHighMode & BACKGROUND)) { - graphics->setColor(gcn::Color(HIGHLIGHT)); + graphics->setColor(gcn::Color(textColour->getColour('H', valid))); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -251,7 +263,6 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - bool valid; graphics->setColor(gcn::Color(textColour->getColour('<', valid))); graphics->drawLine( mLinks[mSelectedLink].x1, -- cgit v1.2.3-70-g09d2 From 9aae9a0b20f144859fc68e94b4fb9fdae6f15861 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 4 Feb 2009 12:11:00 -0700 Subject: Few more unneeded headers that weren't noticed originally in the last commit. Also, while the overall performance improved a little, it doesn't appear to be as drastic as the last commit was suggesting. Signed-off-by: Ira Rice --- src/gui/browserbox.cpp | 2 ++ src/gui/button.cpp | 3 --- src/gui/chat.cpp | 2 -- src/gui/listbox.cpp | 1 - src/gui/shoplistbox.cpp | 1 - src/gui/table.cpp | 2 +- src/gui/truetypefont.h | 1 - src/gui/window.cpp | 2 -- 8 files changed, 3 insertions(+), 11 deletions(-) (limited to 'src/gui/browserbox.cpp') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index cd5479c8..c51852bb 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -21,6 +21,8 @@ #include +#include + #include "browserbox.h" #include "colour.h" #include "linkhandler.h" diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 2e6bed0a..1d3a04e4 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -19,11 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include #include -#include #include "button.h" diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index a58600a8..f4d9763b 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -19,8 +19,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include #include "browserbox.h" diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index e56ddeeb..b63d6424 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include "colour.h" #include "listbox.h" diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index ba636112..b5761535 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -20,7 +20,6 @@ */ #include -#include #include #include "colour.h" diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 9a5c0591..af42165a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -19,8 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include +#include #include "colour.h" #include "table.h" diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 288be49a..bd338d84 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -25,7 +25,6 @@ #include #include -#include #ifndef __APPLE__ #include #else diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 36828194..934bd9b3 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -25,8 +25,6 @@ #include -#include - #include "gui.h" #include "window.h" #include "windowcontainer.h" -- cgit v1.2.3-70-g09d2 From f0d6cd5a97593003fcca3c800ede409f6c55344c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 6 Feb 2009 08:58:58 -0700 Subject: While this is not the ideal solution to the link problem, this commit at least ensures that the link will be in the correct location. Should work to fix things until a proper rewrite is figured out. Signed-off-by: Ira Rice --- src/gui/browserbox.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/gui/browserbox.cpp') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index c51852bb..ecc22e5f 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -276,6 +276,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) int x = 0, y = 0; int wrappedLines = 0; + int link = 0; TrueTypeFont *font = static_cast(getFont()); graphics->setColor(BLACK); @@ -333,6 +334,12 @@ void BrowserBox::draw(gcn::Graphics *graphics) int rgb = textColour->getColour(c, valid); if (c == '<') { + const int size = mLinks[link].x2 - mLinks[link].x1; + mLinks[link].x1 = x; + mLinks[link].y1 = y; + mLinks[link].x2 = mLinks[link].x1 + size; + mLinks[link].y2 = y + font->getHeight(); + link++; prevColor = selColor; } if (valid) -- cgit v1.2.3-70-g09d2 From 1b8c088a48822641b53c2a304372471a128c2841 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 7 Feb 2009 12:18:52 -0700 Subject: Added a text color preview to the setup color tab. Signed-off-by: Ira Rice --- src/gui/browserbox.cpp | 4 ++-- src/gui/browserbox.h | 2 +- src/gui/chat.cpp | 2 -- src/gui/colour.cpp | 9 ++++++++ src/gui/colour.h | 6 ++++++ src/gui/scrollarea.cpp | 15 ++++++++------ src/gui/scrollarea.h | 4 ++-- src/gui/setup_colours.cpp | 52 +++++++++++++++++++++++++++++++++++++---------- src/gui/setup_colours.h | 16 ++++++++------- 9 files changed, 79 insertions(+), 31 deletions(-) (limited to 'src/gui/browserbox.cpp') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index ecc22e5f..5895d557 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -28,10 +28,10 @@ #include "linkhandler.h" #include "truetypefont.h" -BrowserBox::BrowserBox(unsigned int mode): +BrowserBox::BrowserBox(unsigned int mode, bool opaque): gcn::Widget(), mMode(mode), mHighMode(UNDERLINE | BACKGROUND), - mOpaque(true), + mOpaque(opaque), mUseLinksAndUserColors(true), mSelectedLink(-1), mMaxRows(0) diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 15c2ab89..5dde402e 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -46,7 +46,7 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener /** * Constructor. */ - BrowserBox(unsigned int mode = AUTO_SIZE); + BrowserBox(unsigned int mode = AUTO_SIZE, bool opaque = true); /** * Destructor. diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 067c9e08..2363fc50 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -71,8 +71,6 @@ Window(""), mNetwork(network), mTmpVisible(false) mTextOutput->setLinkHandler(mItemLinkHandler); mScrollArea = new ScrollArea(mTextOutput); - mScrollArea->setPosition(mScrollArea->getFrameSize(), - mScrollArea->getFrameSize()); mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_ALWAYS); mScrollArea->setScrollAmount(0, 1); diff --git a/src/gui/colour.cpp b/src/gui/colour.cpp index 58d9d1c6..c4505c2f 100644 --- a/src/gui/colour.cpp +++ b/src/gui/colour.cpp @@ -93,6 +93,15 @@ std::string Colour::getElementAt(int i) 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); diff --git a/src/gui/colour.h b/src/gui/colour.h index 1648e1e8..d0349b7d 100644 --- a/src/gui/colour.h +++ b/src/gui/colour.h @@ -87,6 +87,12 @@ class Colour : public gcn::ListModel */ 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 */ diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index e69b681c..09f7c5e7 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -35,15 +35,17 @@ ImageRect ScrollArea::background; ImageRect ScrollArea::vMarker; Image *ScrollArea::buttons[4][2]; -ScrollArea::ScrollArea(bool gc): +ScrollArea::ScrollArea(bool gc, bool opaque): gcn::ScrollArea(), + mOpaque(opaque), mGC(gc) { init(); } -ScrollArea::ScrollArea(gcn::Widget *widget, bool gc): +ScrollArea::ScrollArea(gcn::Widget *widget, bool gc, bool opaque): gcn::ScrollArea(widget), + mOpaque(opaque), mGC(gc) { init(); @@ -52,9 +54,8 @@ ScrollArea::ScrollArea(gcn::Widget *widget, bool gc): ScrollArea::~ScrollArea() { // Garbage collection - if (mGC) { + if (mGC) delete getContent(); - } instances--; @@ -88,8 +89,10 @@ void ScrollArea::init() const int bggridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { background.grid[a] = textbox->getSubImage( bggridx[x], bggridy[y], bggridx[x + 1] - bggridx[x] + 1, diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h index ccc1e178..33ebc692 100644 --- a/src/gui/scrollarea.h +++ b/src/gui/scrollarea.h @@ -38,12 +38,12 @@ class ScrollArea : public gcn::ScrollArea /** * Constructor. */ - ScrollArea(bool gc = true); + ScrollArea(bool gc = true, bool opaque = true); /** * Constructor. */ - ScrollArea(gcn::Widget *content, bool gc = true); + ScrollArea(gcn::Widget *content, bool gc = true, bool opaque = true); /** * Destructor. diff --git a/src/gui/setup_colours.cpp b/src/gui/setup_colours.cpp index d0ab426a..acc28b1f 100644 --- a/src/gui/setup_colours.cpp +++ b/src/gui/setup_colours.cpp @@ -19,11 +19,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include + #include #include #include +#include "browserbox.h" #include "colour.h" +#include "itemlinkhandler.h" #include "listbox.h" #include "scrollarea.h" #include "setup_colours.h" @@ -35,6 +39,7 @@ #include "../configuration.h" #include "../utils/gettext.h" +#include "../utils/tostring.h" Setup_Colours::Setup_Colours() : mSelected(-1) @@ -48,6 +53,18 @@ Setup_Colours::Setup_Colours() : 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(); @@ -96,16 +113,17 @@ Setup_Colours::Setup_Colours() : LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mScroll, 4, 3).setPadding(2); - place(0, 3, mRedLabel, 2); - place(2, 3, mRedSlider); - place(3, 3, mRedText).setPadding(1); - place(0, 4, mGreenLabel, 2); - place(2, 4, mGreenSlider); - place(3, 4, mGreenText).setPadding(1); - place(0, 5, mBlueLabel, 2); - place(2, 5, mBlueSlider); - place(3, 5, mBlueText).setPadding(1); + 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, 290, 250)); } @@ -133,6 +151,18 @@ void Setup_Colours::action(const gcn::ActionEvent &event) { 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); @@ -167,7 +197,7 @@ void Setup_Colours::action(const gcn::ActionEvent &event) } } -void Setup_Colours::setEntry(Slider *s, TextField *t, int value) +void Setup_Colours::setEntry(gcn::Slider *s, TextField *t, int value) { s->setValue(value); char buffer[100]; diff --git a/src/gui/setup_colours.h b/src/gui/setup_colours.h index f7984dd5..f56daa60 100644 --- a/src/gui/setup_colours.h +++ b/src/gui/setup_colours.h @@ -29,13 +29,13 @@ #include #include -#include "scrollarea.h" #include "setuptab.h" -#include "slider.h" #include "textfield.h" #include "../guichanfwd.h" +class BrowserBox; + class Setup_Colours : public SetupTab, public gcn::ActionListener, public TextFieldListener { @@ -49,25 +49,27 @@ class Setup_Colours : public SetupTab, public gcn::ActionListener, void listen(const TextField *tf); private: gcn::ListBox *mColourBox; - ScrollArea *mScroll; + gcn::ScrollArea *mScroll; + BrowserBox *mPreview; + gcn::ScrollArea *mPreviewBox; int mSelected; gcn::Label *mRedLabel; - Slider *mRedSlider; + gcn::Slider *mRedSlider; TextField *mRedText; int mRedValue; gcn::Label *mGreenLabel; - Slider *mGreenSlider; + gcn::Slider *mGreenSlider; TextField *mGreenText; int mGreenValue; gcn::Label *mBlueLabel; - Slider *mBlueSlider; + gcn::Slider *mBlueSlider; TextField *mBlueText; int mBlueValue; - void setEntry(Slider *s, TextField *t, int value); + void setEntry(gcn::Slider *s, TextField *t, int value); void updateColour(); }; #endif -- cgit v1.2.3-70-g09d2