summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp3
-rw-r--r--src/gui/widgets/browserbox.cpp22
-rw-r--r--src/gui/widgets/browserbox.h3
-rw-r--r--src/gui/widgets/button.cpp190
-rw-r--r--src/gui/widgets/button.h31
-rw-r--r--src/gui/widgets/chattab.cpp21
-rw-r--r--src/gui/widgets/chattab.h2
-rw-r--r--src/gui/widgets/desktop.cpp1
-rw-r--r--src/gui/widgets/desktop.h1
-rw-r--r--src/gui/widgets/dropshortcutcontainer.cpp5
-rw-r--r--src/gui/widgets/dropshortcutcontainer.h5
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp1
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.h1
-rw-r--r--src/gui/widgets/flowcontainer.h3
-rw-r--r--src/gui/widgets/guildchattab.cpp6
-rw-r--r--src/gui/widgets/guildchattab.h2
-rw-r--r--src/gui/widgets/guitable.cpp9
-rw-r--r--src/gui/widgets/horizontcontainer.cpp7
-rw-r--r--src/gui/widgets/horizontcontainer.h2
-rw-r--r--src/gui/widgets/label.cpp1
-rw-r--r--src/gui/widgets/label.h1
-rw-r--r--src/gui/widgets/linkhandler.h3
-rw-r--r--src/gui/widgets/namesmodel.cpp51
-rw-r--r--src/gui/widgets/namesmodel.h51
-rw-r--r--src/gui/widgets/setupitem.cpp416
-rw-r--r--src/gui/widgets/setupitem.h149
-rw-r--r--src/gui/widgets/setuptabscroll.cpp9
-rw-r--r--src/gui/widgets/setuptabscroll.h4
-rw-r--r--src/gui/widgets/sliderlist.cpp216
-rw-r--r--src/gui/widgets/sliderlist.h83
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp5
-rw-r--r--src/gui/widgets/spellshortcutcontainer.h5
-rw-r--r--src/gui/widgets/tablemodel.h3
-rw-r--r--src/gui/widgets/textbox.cpp4
-rw-r--r--src/gui/widgets/textfield.cpp2
35 files changed, 1252 insertions, 66 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 822e71805..749837f7d 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -74,8 +74,7 @@ AvatarListBox::AvatarListBox(AvatarListModel *model):
AvatarListBox::~AvatarListBox()
{
- config.removeListener("showgender", this);
- config.removeListener("showlevel", this);
+ config.removeListeners(this);
instances--;
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 5856a91b1..47c5616b6 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -232,15 +232,17 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
tempRow.substr(nextChar,
(nextSpacePos - nextChar)));
- if ((x + nextWordWidth + 10) > (unsigned)getWidth())
+ if ((x + nextWordWidth + 10)
+ > static_cast<unsigned>(getWidth()))
{
x = 15; // Ident in new line
y += 1;
- j++;
+ j ++;
}
}
// Wrapping looong lines (brutal force)
- else if ((x + 2 * hyphenWidth) > (unsigned)getWidth())
+ else if ((x + 2 * hyphenWidth)
+ > static_cast<unsigned>(getWidth()))
{
x = 15; // Ident in new line
y += 1;
@@ -249,7 +251,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
}
setHeight(font->getHeight() * (static_cast<int>(
- mTextRows.size()) + y));
+ mTextRows.size()) + y));
}
else
{
@@ -423,7 +425,7 @@ int BrowserBox::calcHeight()
if (row.find("---", 0) == 0)
{
const int dashWidth = fontWidthMinus;
- for (x = 0; x < (unsigned)getWidth(); x++)
+ for (x = 0; x < static_cast<unsigned>(getWidth()); x ++)
{
mLineParts.push_back(LinePart(x, y, selColor, "-", false));
x += dashWidth - 2;
@@ -557,9 +559,8 @@ int BrowserBox::calcHeight()
width = font->getWidth(part);
// Auto wrap mode
- if (mMode == AUTO_WRAP && getWidth() > 0
- && width > 0
- && (x + width + 10) > (unsigned)getWidth())
+ if (mMode == AUTO_WRAP && getWidth() > 0 && width > 0
+ && (x + width + 10) > static_cast<unsigned>(getWidth()))
{
bool forced = false;
@@ -592,9 +593,8 @@ int BrowserBox::calcHeight()
else
width = font->getWidth(part);
}
- while (end > start && width > 0
- && (x + width + 10)
- > (unsigned)getWidth());
+ while (end > start && width > 0 && (x + width + 10)
+ > static_cast<unsigned>(getWidth()));
if (forced)
{
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index d82ebd758..b1582e077 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -104,7 +104,8 @@ class BrowserBox : public gcn::Widget,
/**
* Sets the maximum numbers of rows in the browser box. 0 = no limit.
*/
- void setMaxRow(unsigned max) {mMaxRows = max; };
+ void setMaxRow(unsigned max)
+ { mMaxRows = max; };
/**
* Disable links & user defined colors to be used in chat input.
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 2867e3d39..c99f46149 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -32,6 +32,7 @@
#include "gui/theme.h"
#include "resources/image.h"
+#include "resources/imageset.h"
#include "utils/dtor.h"
@@ -69,30 +70,92 @@ static ButtonData const data[BUTTON_COUNT] =
ImageRect Button::button[BUTTON_COUNT];
-Button::Button():
+Button::Button() :
mDescription(""), mClickCount(0),
mTag(0),
mVertexes(new GraphicsVertexes()),
mRedraw(true),
mMode(0),
mXOffset(0),
- mYOffset(0)
+ mYOffset(0),
+ mImages(nullptr),
+ mImageSet(nullptr)
{
init();
+ adjustSize();
}
Button::Button(const std::string &caption, const std::string &actionEventId,
- gcn::ActionListener *listener):
+ gcn::ActionListener *listener) :
gcn::Button(caption),
- mDescription(""), mClickCount(0),
+ mDescription(""),
+ mClickCount(0),
+ mTag(0),
+ mVertexes(new GraphicsVertexes()),
+ mRedraw(true),
+ mMode(0),
+ mXOffset(0),
+ mYOffset(0),
+ mImages(nullptr),
+ mImageSet(nullptr),
+ mImageWidth(0),
+ mImageHeight(0)
+{
+ init();
+ adjustSize();
+ setActionEventId(actionEventId);
+
+ if (listener)
+ addActionListener(listener);
+}
+
+Button::Button(const std::string &caption, const std::string &imageName,
+ int imageWidth, int imageHeight,
+ const std::string &actionEventId,
+ gcn::ActionListener *listener) :
+ gcn::Button(caption),
+ mDescription(""),
+ mClickCount(0),
+ mTag(0),
+ mVertexes(new GraphicsVertexes()),
+ mRedraw(true),
+ mMode(0),
+ mXOffset(0),
+ mYOffset(0),
+ mImages(nullptr),
+ mImageSet(nullptr),
+ mImageWidth(imageWidth),
+ mImageHeight(imageHeight)
+{
+ init();
+ loadImage(imageName);
+ adjustSize();
+ setActionEventId(actionEventId);
+
+ if (listener)
+ addActionListener(listener);
+}
+
+Button::Button(const std::string &imageName, int imageWidth, int imageHeight,
+ const std::string &actionEventId,
+ gcn::ActionListener *listener) :
+ gcn::Button(""),
+ mDescription(""),
+ mClickCount(0),
mTag(0),
mVertexes(new GraphicsVertexes()),
mRedraw(true),
mMode(0),
mXOffset(0),
- mYOffset(0)
+ mYOffset(0),
+ mImages(nullptr),
+ mImageSet(nullptr),
+ mImageWidth(imageWidth),
+ mImageHeight(imageHeight)
{
init();
+ loadImage(imageName);
+ adjustSize();
setActionEventId(actionEventId);
if (listener)
@@ -158,6 +221,41 @@ Button::~Button()
}
}
}
+ if (mImageSet)
+ {
+ mImageSet->decRef();
+ mImageSet = nullptr;
+ }
+ if (mImages)
+ {
+ for (int f = 0; f < BUTTON_COUNT; f ++)
+ mImages[f] = nullptr;
+ delete [] mImages;
+ mImages = nullptr;
+ }
+}
+
+void Button::loadImage(const std::string &imageName)
+{
+ if (mImageSet)
+ {
+ mImageSet->decRef();
+ mImageSet = nullptr;
+ }
+ mImageSet = Theme::getImageSetFromTheme(imageName,
+ mImageWidth, mImageHeight);
+ if (!mImageSet)
+ return;
+ mImages = new Image*[BUTTON_COUNT];
+ mImages[0] = nullptr;
+ for (int f = 0; f < BUTTON_COUNT; f ++)
+ {
+ Image *img = mImageSet->get(f);
+ if (img)
+ mImages[f] = img;
+ else
+ mImages[f] = mImages[0];
+ }
}
void Button::updateAlpha()
@@ -197,6 +295,7 @@ void Button::draw(gcn::Graphics *graphics)
updateAlpha();
+ Graphics *g2 = static_cast<Graphics*>(graphics);
bool recalc = false;
if (mRedraw)
@@ -207,8 +306,7 @@ void Button::draw(gcn::Graphics *graphics)
{
// because we don't know where parent windows was moved,
// need recalc vertexes
- gcn::ClipRectangle &rect = static_cast<Graphics*>(
- graphics)->getTopClip();
+ gcn::ClipRectangle &rect = g2->getTopClip();
if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
{
recalc = true;
@@ -220,7 +318,7 @@ void Button::draw(gcn::Graphics *graphics)
recalc = true;
mMode = mode;
}
- else if (static_cast<Graphics*>(graphics)->getRedraw())
+ else if (g2->getRedraw())
{
recalc = true;
}
@@ -230,45 +328,73 @@ void Button::draw(gcn::Graphics *graphics)
{
mRedraw = false;
mMode = mode;
- static_cast<Graphics*>(graphics)->calcWindow(mVertexes, 0, 0,
- getWidth(), getHeight(), button[mode]);
+ g2->calcWindow(mVertexes, 0, 0, getWidth(), getHeight(), button[mode]);
}
- static_cast<Graphics*>(graphics)->drawImageRect2(
- mVertexes, button[mode]);
+ g2->drawImageRect2(mVertexes, button[mode]);
-// static_cast<Graphics*>(graphics)->
-// drawImageRect(0, 0, getWidth(), getHeight(), button[mode]);
+// g2->drawImageRect(0, 0, getWidth(), getHeight(), button[mode]);
if (mode == BUTTON_DISABLED)
graphics->setColor(mDisabledColor);
else
graphics->setColor(mEnabledColor);
- int textX;
+ int textX = 0;
int textY = getHeight() / 2 - getFont()->getHeight() / 2;
+ int imageX = 0;
+ int imageY = 0;
+ if (mImages)
+ imageY = getHeight() / 2 - mImageHeight / 2;
+
+// need move calculation from draw!!!
switch (getAlignment())
{
default:
case gcn::Graphics::LEFT:
- textX = 4;
+ if (mImages)
+ {
+ imageX = 4;
+ textX = 4 + mImageWidth + 2;
+ }
+ else
+ {
+ textX = 4;
+ }
break;
case gcn::Graphics::CENTER:
- textX = getWidth() / 2;
+ if (mImages)
+ {
+ int width = getFont()->getWidth(mCaption) + mImageWidth + 2;
+ imageX = getWidth() / 2 - width / 2;
+ textX = imageX + mImageWidth + 2;
+ }
+ else
+ {
+ textX = getWidth() / 2;
+ }
break;
case gcn::Graphics::RIGHT:
textX = getWidth() - 4;
+ imageX = textX - getFont()->getWidth(mCaption) - 2;
break;
-// throw GCN_EXCEPTION("Button::draw. Unknown alignment.");
}
graphics->setFont(getFont());
if (isPressed())
- graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
+ {
+ if (mImages)
+ g2->drawImage(mImages[mode], imageX + 1, imageY + 1);
+ g2->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
+ }
else
- graphics->drawText(getCaption(), textX, textY, getAlignment());
+ {
+ if (mImages)
+ g2->drawImage(mImages[mode], imageX, imageY);
+ g2->drawText(getCaption(), textX, textY, getAlignment());
+ }
}
void Button::mouseReleased(gcn::MouseEvent& mouseEvent)
@@ -298,3 +424,27 @@ void Button::widgetMoved(const gcn::Event &event A_UNUSED)
{
mRedraw = true;
}
+
+void Button::adjustSize()
+{
+ if (mImages)
+ {
+ setWidth(getFont()->getWidth(mCaption)
+ + mImageWidth + 2 + 2 * mSpacing);
+ int height = getFont()->getHeight();
+ if (height < mImageHeight)
+ height = mImageHeight;
+ setHeight(height + 2 * mSpacing);
+ }
+ else
+ {
+ setWidth(getFont()->getWidth(mCaption) + 2 * mSpacing);
+ setHeight(getFont()->getHeight() + 2 * mSpacing);
+ }
+}
+
+void Button::setCaption(const std::string& caption)
+{
+ mCaption = caption;
+// adjustSize();
+}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 560e46377..6585d9850 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -28,8 +28,12 @@
#include <guichan/widgetlistener.hpp>
class GraphicsVertexes;
+class Image;
+class ImageSet;
class ImageRect;
+const std::string BUTTON_PLAY = "buttonplay.png";
+
/**
* Button widget. Same as the Guichan button but with custom look.
*
@@ -51,6 +55,23 @@ class Button : public gcn::Button, public gcn::WidgetListener
gcn::ActionListener *listener);
/**
+ * Constructor, sets the caption of the button to the given string and
+ * adds the given action listener.
+ */
+ Button(const std::string &caption, const std::string &imageName,
+ int imageWidth, int imageHeight,
+ const std::string &actionEventId,
+ gcn::ActionListener *listener);
+
+ /**
+ * Constructor, sets the caption of the button to the given string and
+ * adds the given action listener.
+ */
+ Button(const std::string &imageName, int imageWidth, int imageHeight,
+ const std::string &actionEventId,
+ gcn::ActionListener *listener);
+
+ /**
* Destructor.
*/
~Button();
@@ -86,6 +107,12 @@ class Button : public gcn::Button, public gcn::WidgetListener
void widgetMoved(const gcn::Event &event);
+ void loadImage(const std::string &imageName);
+
+ void adjustSize();
+
+ void setCaption(const std::string& caption);
+
private:
void init();
@@ -103,6 +130,10 @@ class Button : public gcn::Button, public gcn::WidgetListener
int mYOffset;
gcn::Color mEnabledColor;
gcn::Color mDisabledColor;
+ Image **mImages;
+ ImageSet *mImageSet;
+ int mImageWidth;
+ int mImageHeight;
};
#endif
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 018e35030..be6a31164 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -289,9 +289,19 @@ void ChatTab::chatLog(std::string line, Own own,
if (getFlash() == 0)
{
if (chatWindow && chatWindow->findHighlight(tmp.text))
+ {
setFlash(2);
+ sound.playGuiSound(SOUND_HIGHLIGHT);
+ }
else
+ {
setFlash(1);
+ }
+ }
+ else if (getFlash() == 2)
+ {
+ if (chatWindow && chatWindow->findHighlight(tmp.text))
+ sound.playGuiSound(SOUND_HIGHLIGHT);
}
}
@@ -300,8 +310,10 @@ void ChatTab::chatLog(std::string line, Own own,
|| (Client::getIsMinimized() || (!Client::getMouseFocused()
&& !Client::getInputFocused()))))
{
- if (own != BY_SERVER)
- sound.playGuiSfx("system/newmessage.ogg");
+ if (own == BY_GM)
+ sound.playGuiSound(SOUND_GLOBAL);
+ else if (own != BY_SERVER)
+ playNewMessageSound();
}
}
}
@@ -468,3 +480,8 @@ void ChatTab::addNewRow(std::string &line)
}
mScrollArea->logic();
}
+
+void ChatTab::playNewMessageSound()
+{
+ sound.playGuiSound(SOUND_WHISPER);
+}
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 912305a63..d67f56b54 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -162,6 +162,8 @@ class ChatTab : public Tab
void addNewRow(std::string &line);
+ virtual void playNewMessageSound();
+
protected:
friend class ChatWindow;
friend class WhisperWindow;
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index b40558c78..6352c300f 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -1,6 +1,7 @@
/*
* Desktop widget
* Copyright (c) 2009-2010 The Mana World Development Team
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
index b1f059ffe..e4edc8857 100644
--- a/src/gui/widgets/desktop.h
+++ b/src/gui/widgets/desktop.h
@@ -1,6 +1,7 @@
/*
* Desktop widget
* Copyright (c) 2009-2010 The Mana World Development Team
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp
index 8335a61bc..8c6aec68a 100644
--- a/src/gui/widgets/dropshortcutcontainer.cpp
+++ b/src/gui/widgets/dropshortcutcontainer.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011 ManaPlus developers
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
@@ -17,8 +17,7 @@
* 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gui/widgets/dropshortcutcontainer.h"
diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h
index 1f03fd53b..91e436836 100644
--- a/src/gui/widgets/dropshortcutcontainer.h
+++ b/src/gui/widgets/dropshortcutcontainer.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011 ManaPlus developers
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
@@ -17,8 +17,7 @@
* 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DROPSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 794357275..8d828a87e 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -1,6 +1,7 @@
/*
* Extended support for activating emotes
* Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h
index 743ca4e87..f509798bb 100644
--- a/src/gui/widgets/emoteshortcutcontainer.h
+++ b/src/gui/widgets/emoteshortcutcontainer.h
@@ -1,6 +1,7 @@
/*
* Extended support for activating emotes
* Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h
index 677dd3661..e5eeebdcb 100644
--- a/src/gui/widgets/flowcontainer.h
+++ b/src/gui/widgets/flowcontainer.h
@@ -43,7 +43,8 @@ class FlowContainer : public Container,
/**
* Destructor.
*/
- ~FlowContainer() {}
+ ~FlowContainer()
+ { }
/**
* Invoked when a widget changes its size. This is used to determine
diff --git a/src/gui/widgets/guildchattab.cpp b/src/gui/widgets/guildchattab.cpp
index a95fca3cf..bad34cfb3 100644
--- a/src/gui/widgets/guildchattab.cpp
+++ b/src/gui/widgets/guildchattab.cpp
@@ -27,6 +27,7 @@
#include "guild.h"
#include "guildmanager.h"
#include "localplayer.h"
+#include "sound.h"
#include "gui/theme.h"
@@ -126,3 +127,8 @@ void GuildChatTab::saveToLogFile(std::string &msg)
if (chatLogger)
chatLogger->log("#Guild", msg);
}
+
+void GuildChatTab::playNewMessageSound()
+{
+ sound.playGuiSound(SOUND_GUILD);
+}
diff --git a/src/gui/widgets/guildchattab.h b/src/gui/widgets/guildchattab.h
index be6f4d034..e729844f4 100644
--- a/src/gui/widgets/guildchattab.h
+++ b/src/gui/widgets/guildchattab.h
@@ -44,6 +44,8 @@ class GuildChatTab : public ChatTab
int getType() const
{ return ChatTab::TAB_GUILD; }
+ void playNewMessageSound();
+
protected:
void handleInput(const std::string &msg);
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index d620cbb8d..6434f5453 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -348,14 +348,15 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (mSelectedRow > 0)
{
- if (mLinewiseMode && r == (unsigned)mSelectedRow && c == 0)
+ if (mLinewiseMode && r == static_cast<unsigned>(
+ mSelectedRow) && c == 0)
{
graphics->fillRectangle(gcn::Rectangle(0, y_offset,
- getWidth(), height));
+ getWidth(), height));
}
else if (!mLinewiseMode && mSelectedColumn > 0
- && c == (unsigned)mSelectedColumn
- && r == (unsigned)mSelectedRow)
+ && c == static_cast<unsigned>(mSelectedColumn)
+ && r == static_cast<unsigned>(mSelectedRow))
{
graphics->fillRectangle(gcn::Rectangle(
x_offset, y_offset, width, height));
diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp
index c128ea550..5bf81c5d8 100644
--- a/src/gui/widgets/horizontcontainer.cpp
+++ b/src/gui/widgets/horizontcontainer.cpp
@@ -34,11 +34,16 @@ HorizontContainer::HorizontContainer(int height, int spacing):
void HorizontContainer::add(gcn::Widget *widget)
{
+ add(widget, mSpacing);
+}
+
+void HorizontContainer::add(gcn::Widget *widget, int spacing)
+{
if (!widget)
return;
Container::add(widget);
- widget->setPosition(mLastX, mSpacing);
+ widget->setPosition(mLastX, spacing);
mCount++;
mLastX += widget->getWidth() + 2 * mSpacing;
}
diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h
index 7439672dc..8e1d082ac 100644
--- a/src/gui/widgets/horizontcontainer.h
+++ b/src/gui/widgets/horizontcontainer.h
@@ -38,6 +38,8 @@ class HorizontContainer : public Container, public gcn::WidgetListener
virtual void add(gcn::Widget *widget);
+ virtual void add(gcn::Widget *widget, int spacing);
+
virtual void clear();
void widgetResized(const gcn::Event &event);
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 67e8bd12b..640010c62 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -1,6 +1,7 @@
/*
* The ManaPlus Client
* Copyright (c) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
index 775eda18c..f2048c94a 100644
--- a/src/gui/widgets/label.h
+++ b/src/gui/widgets/label.h
@@ -1,6 +1,7 @@
/*
* The ManaPlus Client
* Copyright (c) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/gui/widgets/linkhandler.h b/src/gui/widgets/linkhandler.h
index 366899ffc..703f593f2 100644
--- a/src/gui/widgets/linkhandler.h
+++ b/src/gui/widgets/linkhandler.h
@@ -34,7 +34,8 @@
class LinkHandler
{
public:
- virtual ~LinkHandler() { }
+ virtual ~LinkHandler()
+ { }
virtual void handleLink(const std::string &link,
gcn::MouseEvent *event) = 0;
diff --git a/src/gui/widgets/namesmodel.cpp b/src/gui/widgets/namesmodel.cpp
new file mode 100644
index 000000000..abfcd6def
--- /dev/null
+++ b/src/gui/widgets/namesmodel.cpp
@@ -0,0 +1,51 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/namesmodel.h"
+
+#include "logger.h"
+
+#include "utils/gettext.h"
+
+#include <guichan/exception.hpp>
+#include <guichan/font.hpp>
+
+#include "debug.h"
+
+NamesModel::NamesModel()
+{
+}
+
+NamesModel::~NamesModel()
+{
+}
+
+int NamesModel::getNumberOfElements()
+{
+ return static_cast<int>(mNames.size());
+}
+
+std::string NamesModel::getElementAt(int i)
+{
+ if (i >= getNumberOfElements() || i < 0)
+ return _("???");
+
+ return mNames[i];
+}
diff --git a/src/gui/widgets/namesmodel.h b/src/gui/widgets/namesmodel.h
new file mode 100644
index 000000000..dc694fc46
--- /dev/null
+++ b/src/gui/widgets/namesmodel.h
@@ -0,0 +1,51 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_WIDGETS_NAMESMODEL_H
+#define GUI_WIDGETS_NAMESMODEL_H
+
+//#include "guichanfwd.h"
+
+#include <guichan/listmodel.hpp>
+
+#include <vector>
+
+class NamesModel : public gcn::ListModel
+{
+ public:
+ NamesModel();
+
+ virtual ~NamesModel();
+
+ virtual int getNumberOfElements();
+
+ virtual std::string getElementAt(int i);
+
+ std::vector<std::string> &getNames()
+ { return mNames; }
+
+ size_t size()
+ { return mNames.size(); }
+
+ protected:
+ std::vector<std::string> mNames;
+};
+
+#endif
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index 56ce0a25a..93854e823 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -23,8 +23,10 @@
#include "configuration.h"
#include "main.h"
#include "logger.h"
+#include "sound.h"
#include "gui/editdialog.h"
+#include "gui/gui.h"
#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
@@ -33,13 +35,19 @@
#include "gui/widgets/inttextfield.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
+#include "gui/widgets/slider.h"
+#include "gui/widgets/sliderlist.h"
#include "gui/widgets/tabbedarea.h"
#include "gui/widgets/textfield.h"
#include "gui/widgets/vertcontainer.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
+#include "utils/mathutils.h"
+#include <guichan/font.hpp>
+
+#include "debug.h"
SetupItem::SetupItem(std::string text, std::string description,
std::string keyName, SetupTabScroll *parent,
@@ -163,6 +171,12 @@ void SetupItem::externalUpdated(std::string eventName A_UNUSED)
toWidget();
}
+void SetupItem::fixFirstItemSize(gcn::Widget *widget)
+{
+ if (widget->getWidth() < mParent->getPreferredFirstItemSize())
+ widget->setWidth(mParent->getPreferredFirstItemSize());
+}
+
SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description,
std::string keyName,
SetupTabScroll *parent,
@@ -271,6 +285,7 @@ void SetupItemTextField::createControls()
mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent);
mWidget = mTextField;
mTextField->setWidth(200);
+ fixFirstItemSize(mLabel);
mHorizont->add(mLabel);
mHorizont->add(mTextField);
mHorizont->add(mButton);
@@ -394,6 +409,7 @@ void SetupItemIntTextField::createControls()
mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent);
mWidget = mTextField;
mTextField->setWidth(50);
+ fixFirstItemSize(mLabel);
mHorizont->add(mLabel);
mHorizont->add(mTextField);
mHorizont->add(mButton);
@@ -564,6 +580,7 @@ void SetupItemDropDown::createControls()
mWidget = mDropDown;
// mTextField->setWidth(50);
+ fixFirstItemSize(mLabel);
mHorizont->add(mLabel);
mHorizont->add(mDropDown);
@@ -588,3 +605,402 @@ void SetupItemDropDown::toWidget()
mDropDown->setSelectedString(mValue);
}
+
+
+SetupItemSlider::SetupItemSlider(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, double min, double max,
+ int width, bool onTheFly, bool mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mSlider(nullptr),
+ mMin(min),
+ mMax(max),
+ mWidth(width),
+ mOnTheFly(onTheFly)
+{
+ mValueType = VSTR;
+ createControls();
+}
+
+SetupItemSlider::SetupItemSlider(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, double min, double max,
+ std::string def, int width, bool onTheFly,
+ bool mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mSlider(nullptr),
+ mMin(min),
+ mMax(max),
+ mWidth(width),
+ mOnTheFly(onTheFly)
+{
+ mValueType = VSTR;
+ createControls();
+}
+
+SetupItemSlider::~SetupItemSlider()
+{
+ mHorizont = nullptr;
+ mWidget = nullptr;
+ mSlider = nullptr;
+ mLabel = nullptr;
+}
+
+void SetupItemSlider::createControls()
+{
+ load();
+ mHorizont = new HorizontContainer(32, 2);
+
+ mLabel = new Label(mText);
+ mSlider = new Slider(mMin, mMax);
+ mSlider->setActionEventId(mEventName);
+ mSlider->addActionListener(mParent);
+ mSlider->setValue(atof(mValue.c_str()));
+ mSlider->setHeight(30);
+
+ mWidget = mSlider;
+ mSlider->setWidth(mWidth);
+ mSlider->setHeight(40);
+ fixFirstItemSize(mLabel);
+ mHorizont->add(mLabel);
+ mHorizont->add(mSlider, -10);
+
+ mParent->getContainer()->add2(mHorizont, true, 4);
+ mParent->addControl(this);
+ mParent->addActionListener(this);
+ mWidget->addActionListener(this);
+}
+
+void SetupItemSlider::fromWidget()
+{
+ if (!mSlider)
+ return;
+
+ mValue = toString(mSlider->getValue());
+}
+
+void SetupItemSlider::toWidget()
+{
+ if (!mSlider)
+ return;
+
+ mSlider->setValue(atof(mValue.c_str()));
+}
+
+void SetupItemSlider::action(const gcn::ActionEvent &event A_UNUSED)
+{
+ fromWidget();
+ if (mOnTheFly)
+ save();
+}
+
+void SetupItemSlider::apply(std::string eventName)
+{
+ if (eventName != mEventName)
+ return;
+
+ fromWidget();
+ save();
+}
+
+
+SetupItemSlider2::SetupItemSlider2(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, int min, int max,
+ SetupItemNames *values, bool onTheFly,
+ bool mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mLabel2(nullptr),
+ mSlider(nullptr),
+ mValues(values),
+ mMin(min),
+ mMax(max),
+ mInvert(false),
+ mInvertValue(0),
+ mOnTheFly(onTheFly)
+{
+ mValueType = VSTR;
+ createControls();
+}
+
+SetupItemSlider2::SetupItemSlider2(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, int min, int max,
+ SetupItemNames *values, std::string def,
+ bool onTheFly, bool mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mLabel2(nullptr),
+ mSlider(nullptr),
+ mValues(values),
+ mMin(min),
+ mMax(max),
+ mInvert(false),
+ mInvertValue(0),
+ mOnTheFly(onTheFly)
+{
+ mValueType = VSTR;
+ createControls();
+}
+
+SetupItemSlider2::~SetupItemSlider2()
+{
+ mHorizont = nullptr;
+ mWidget = nullptr;
+ mSlider = nullptr;
+ mLabel = nullptr;
+}
+
+void SetupItemSlider2::createControls()
+{
+ load();
+ mHorizont = new HorizontContainer(32, 2);
+
+ int width = getMaxWidth();
+
+ mLabel = new Label(mText);
+ mLabel2 = new Label("");
+ mLabel2->setWidth(width);
+ mSlider = new Slider(mMin, mMax);
+ mSlider->setActionEventId(mEventName);
+ mSlider->addActionListener(mParent);
+ mSlider->setValue(atof(mValue.c_str()));
+ mSlider->setHeight(30);
+
+ mWidget = mSlider;
+ mSlider->setWidth(150);
+ mSlider->setHeight(40);
+ fixFirstItemSize(mLabel);
+ mHorizont->add(mLabel);
+ mHorizont->add(mSlider, -10);
+ mHorizont->add(mLabel2);
+
+ mParent->getContainer()->add2(mHorizont, true, 4);
+ mParent->addControl(this);
+ mParent->addActionListener(this);
+ mWidget->addActionListener(this);
+ updateLabel();
+}
+
+int SetupItemSlider2::getMaxWidth()
+{
+ if (!mValues || !gui)
+ return 1;
+
+ int maxWidth = 0;
+ SetupItemNamesConstIter it = mValues->begin();
+ SetupItemNamesConstIter it_end = mValues->end();
+ gcn::Font *font = gui->getFont();
+
+ while (it != it_end)
+ {
+ int w = font->getWidth(*it);
+ if (w > maxWidth)
+ maxWidth = w;
+
+ ++ it;
+ }
+ return maxWidth;
+}
+
+void SetupItemSlider2::fromWidget()
+{
+ if (!mSlider)
+ return;
+
+ int val = roundDouble(mSlider->getValue());
+ if (mInvert)
+ val = mInvertValue - val;
+ mValue = toString(val);
+}
+
+void SetupItemSlider2::toWidget()
+{
+ if (!mSlider)
+ return;
+
+ int val = roundDouble(atof(mValue.c_str()));
+ if (mInvert)
+ val = mInvertValue - val;
+ mSlider->setValue(val);
+ updateLabel();
+}
+
+void SetupItemSlider2::action(const gcn::ActionEvent &event A_UNUSED)
+{
+ fromWidget();
+ updateLabel();
+ if (mOnTheFly)
+ save();
+}
+
+void SetupItemSlider2::updateLabel()
+{
+ int val = mSlider->getValue() - mMin;
+ if (val < 0)
+ val = 0;
+ else if (val >= static_cast<signed>(mValues->size()))
+ val = static_cast<signed>(mValues->size()) - 1;
+ std::string str = mValues->at(val);
+ mLabel2->setCaption(str);
+}
+
+void SetupItemSlider2::apply(std::string eventName)
+{
+ if (eventName != mEventName)
+ return;
+
+ fromWidget();
+ save();
+}
+
+void SetupItemSlider2::setInvertValue(int v)
+{
+ mInvert = true;
+ mInvertValue = v;
+ toWidget();
+}
+
+
+SetupItemSliderList::SetupItemSliderList(std::string text,
+ std::string description,
+ std::string keyName,
+ SetupTabScroll *parent,
+ std::string eventName,
+ gcn::ListModel *model,
+ int width, bool onTheFly,
+ bool mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mSlider(nullptr),
+ mModel(model),
+ mWidth(width),
+ mOnTheFly(onTheFly)
+{
+ mValueType = VSTR;
+// createControls();
+}
+
+SetupItemSliderList::SetupItemSliderList(std::string text,
+ std::string description,
+ std::string keyName,
+ SetupTabScroll *parent,
+ std::string eventName,
+ gcn::ListModel *model,
+ std::string def, int width,
+ bool onTheFly, bool mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mSlider(nullptr),
+ mModel(model),
+ mWidth(width),
+ mOnTheFly(onTheFly)
+{
+ mValueType = VSTR;
+// createControls();
+}
+
+SetupItemSliderList::~SetupItemSliderList()
+{
+ mHorizont = nullptr;
+ mWidget = nullptr;
+ mSlider = nullptr;
+ mLabel = nullptr;
+}
+
+void SetupItemSliderList::createControls()
+{
+ load();
+ mHorizont = new HorizontContainer(32, 2);
+
+ mLabel = new Label(mText);
+ mSlider = new SliderList(mModel, mParent, mEventName);
+ mSlider->setSelectedString(mValue);
+ mSlider->adjustSize();
+
+ mWidget = mSlider;
+ fixFirstItemSize(mLabel);
+ mHorizont->add(mLabel, 5);
+ mHorizont->add(mSlider);
+
+ addMoreControls();
+
+ mParent->getContainer()->add2(mHorizont, true, 4);
+ mParent->addControl(this);
+ mParent->addActionListener(this);
+ mWidget->addActionListener(this);
+}
+
+void SetupItemSliderList::fromWidget()
+{
+ if (!mSlider)
+ return;
+
+ mValue = mSlider->getSelectedString();
+}
+
+void SetupItemSliderList::toWidget()
+{
+ if (!mSlider)
+ return;
+
+ mSlider->setSelectedString(mValue);
+}
+
+void SetupItemSliderList::action(const gcn::ActionEvent &event A_UNUSED)
+{
+ fromWidget();
+ if (mOnTheFly)
+ save();
+}
+
+void SetupItemSliderList::apply(std::string eventName)
+{
+ if (eventName != mEventName)
+ return;
+
+ fromWidget();
+ save();
+}
+
+SetupItemSound::SetupItemSound(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, gcn::ListModel *model,
+ int width, bool onTheFly, bool mainConfig) :
+ SetupItemSliderList(text, description, keyName, parent, eventName,
+ model, width, onTheFly, mainConfig),
+ mButton(nullptr)
+{
+ createControls();
+}
+
+void SetupItemSound::addMoreControls()
+{
+ mButton = new Button(BUTTON_PLAY, 16, 16, mEventName + "_PLAY", this);
+ mHorizont->add(mButton);
+}
+
+void SetupItemSound::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == mEventName + "_PLAY")
+ {
+ if (mSlider->getSelected())
+ {
+ sound.playGuiSfx(branding.getStringValue("systemsounds")
+ + mSlider->getSelectedString() + ".ogg");
+ }
+ }
+ else
+ {
+ SetupItemSliderList::action(event);
+ }
+}
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index 71856d6e2..86fdf95f9 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -41,6 +41,8 @@ class EditDialog;
class HorizontContainer;
class IntTextField;
class Label;
+class Slider;
+class SliderList;
class TextField;
class SetupItem : public gcn::ActionListener
@@ -91,11 +93,12 @@ class SetupItem : public gcn::ActionListener
virtual void cancel(std::string eventName);
virtual void externalUpdated(std::string eventName);
-// virtual int add(ContainerPlacer &place, int x, int y, int width);
bool isMainConfig() const
{ return mMainConfig; }
+ void fixFirstItemSize(gcn::Widget *widget);
+
protected:
std::string mText;
@@ -264,4 +267,148 @@ class SetupItemDropDown : public SetupItem
DropDown *mDropDown;
};
+class SetupItemSlider : public SetupItem
+{
+ public:
+ SetupItemSlider(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, double min, double max,
+ int width = 150, bool onTheFly = false,
+ bool mainConfig = true);
+
+ SetupItemSlider(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, double min, double max,
+ std::string def, int width = 150,
+ bool onTheFly = false, bool mainConfig = true);
+
+ ~SetupItemSlider();
+
+ void createControls();
+
+ void fromWidget();
+
+ void toWidget();
+
+ void action(const gcn::ActionEvent &event);
+
+ void apply(std::string eventName);
+
+ void updateLabel();
+
+ protected:
+ HorizontContainer *mHorizont;
+ Label *mLabel;
+ Slider *mSlider;
+ double mMin;
+ double mMax;
+ int mWidth;
+ bool mOnTheFly;
+};
+
+typedef std::vector<std::string> SetupItemNames;
+typedef SetupItemNames::iterator SetupItemNamesIter;
+typedef SetupItemNames::const_iterator SetupItemNamesConstIter;
+
+class SetupItemSlider2 : public SetupItem
+{
+ public:
+ SetupItemSlider2(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, int min, int max,
+ SetupItemNames *values, bool onTheFly = false,
+ bool mainConfig = true);
+
+ SetupItemSlider2(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, int min, int max,
+ SetupItemNames *values, std::string def,
+ bool onTheFly = false, bool mainConfig = true);
+
+ ~SetupItemSlider2();
+
+ void createControls();
+
+ void fromWidget();
+
+ void toWidget();
+
+ void action(const gcn::ActionEvent &event);
+
+ void apply(std::string eventName);
+
+ void setInvertValue(int v);
+
+ protected:
+ void updateLabel();
+
+ int getMaxWidth();
+
+ HorizontContainer *mHorizont;
+ Label *mLabel;
+ Label *mLabel2;
+ Slider *mSlider;
+ SetupItemNames *mValues;
+ int mMin;
+ int mMax;
+ bool mInvert;
+ int mInvertValue;
+ bool mOnTheFly;
+};
+
+class SetupItemSliderList : public SetupItem
+{
+ public:
+ SetupItemSliderList(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, gcn::ListModel *model,
+ int width = 150, bool onTheFly = false,
+ bool mainConfig = true);
+
+ SetupItemSliderList(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, gcn::ListModel *model,
+ std::string def, int width = 150,
+ bool onTheFly = false, bool mainConfig = true);
+
+ ~SetupItemSliderList();
+
+ void createControls();
+
+ void fromWidget();
+
+ void toWidget();
+
+ virtual void action(const gcn::ActionEvent &event);
+
+ void apply(std::string eventName);
+
+ virtual void addMoreControls() = 0;
+
+ protected:
+ HorizontContainer *mHorizont;
+ Label *mLabel;
+ SliderList *mSlider;
+ gcn::ListModel *mModel;
+ int mWidth;
+ bool mOnTheFly;
+};
+
+class SetupItemSound : public SetupItemSliderList
+{
+ public:
+ SetupItemSound(std::string text, std::string description,
+ std::string keyName, SetupTabScroll *parent,
+ std::string eventName, gcn::ListModel *model,
+ int width = 150, bool onTheFly = false,
+ bool mainConfig = true);
+
+ void action(const gcn::ActionEvent &event);
+
+ void addMoreControls();
+
+ protected:
+ Button *mButton;
+};
+
#endif
diff --git a/src/gui/widgets/setuptabscroll.cpp b/src/gui/widgets/setuptabscroll.cpp
index ab8f61a40..f3f8b1526 100644
--- a/src/gui/widgets/setuptabscroll.cpp
+++ b/src/gui/widgets/setuptabscroll.cpp
@@ -28,17 +28,14 @@
#include "debug.h"
SetupTabScroll::SetupTabScroll() :
- SetupTab()
+ SetupTab(),
+ mPreferredFirstItemSize(200)
{
- mContainer = new VertContainer(32, false, 8);
+ mContainer = new VertContainer(25, false, 8);
mScroll = new ScrollArea(mContainer);
mScroll->setOpaque(false);
mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
-
-// LayoutHelper h(this);
-// ContainerPlacer place = h.getPlacer(0, 0);
-// place(0, 0, mScroll, 10, 10);
}
SetupTabScroll::~SetupTabScroll()
diff --git a/src/gui/widgets/setuptabscroll.h b/src/gui/widgets/setuptabscroll.h
index d471ecfbc..e7151769e 100644
--- a/src/gui/widgets/setuptabscroll.h
+++ b/src/gui/widgets/setuptabscroll.h
@@ -55,11 +55,15 @@ class SetupTabScroll : public SetupTab
virtual void action(const gcn::ActionEvent &event A_UNUSED)
{ }
+ int getPreferredFirstItemSize()
+ { return mPreferredFirstItemSize; }
+
protected:
VertContainer *mContainer;
ScrollArea *mScroll;
std::map<std::string, SetupItem*> mItems;
std::set<SetupItem*> mAllItems;
+ int mPreferredFirstItemSize;
};
#endif
diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp
new file mode 100644
index 000000000..bc30bbe38
--- /dev/null
+++ b/src/gui/widgets/sliderlist.cpp
@@ -0,0 +1,216 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/sliderlist.h"
+
+#include "client.h"
+#include "logger.h"
+
+#include "gui/gui.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/label.h"
+
+#include "utils/dtor.h"
+
+#include <guichan/font.hpp>
+
+#include "debug.h"
+
+static const int buttonWidth = 27;
+static const int buttonSpace = 30;
+static const int sliderHeight = 30;
+
+SliderList::SliderList(gcn::ListModel *listModel,
+ gcn::ActionListener* listener,
+ std::string eventId) :
+ mListModel(listModel),
+ mOldWidth(0),
+ mSelectedIndex(0)
+{
+ mPrevEventId = eventId + "_prev";
+ mNextEventId = eventId + "_next";
+
+ setHeight(sliderHeight);
+
+ mButtons[0] = new Button("<", mPrevEventId, this);
+ mButtons[1] = new Button(">", mNextEventId, this);
+ mLabel = new Label("");
+ add(mButtons[0]);
+ add(mLabel);
+ add(mButtons[1]);
+
+ if (!eventId.empty())
+ setActionEventId(eventId);
+
+ if (listener)
+ addActionListener(listener);
+
+ updateLabel();
+ addMouseListener(this);
+}
+
+SliderList::~SliderList()
+{
+}
+
+void SliderList::updateAlpha()
+{
+ mButtons[0]->updateAlpha();
+ mButtons[1]->updateAlpha();
+}
+
+void SliderList::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
+{
+ logger->log("SliderList::mouseWheelMovedUp");
+ setSelected(mSelectedIndex - 1);
+ mouseEvent.consume();
+}
+
+void SliderList::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
+{
+ setSelected(mSelectedIndex + 1);
+ mouseEvent.consume();
+}
+
+void SliderList::resize()
+{
+ const int width = getWidth();
+
+ mButtons[0]->setWidth(buttonWidth);
+// mLabel->setPosition(buttonSpace, 0);
+ mLabel->setWidth(width - buttonSpace * 2);
+ mButtons[1]->setPosition(width - buttonSpace + 3, 0);
+ mButtons[1]->setWidth(buttonWidth);
+ updateLabel();
+}
+
+void SliderList::draw(gcn::Graphics *graphics)
+{
+ if (mOldWidth != getWidth())
+ {
+ resize();
+ mOldWidth = getWidth();
+ }
+ Container::draw(graphics);
+}
+
+void SliderList::updateLabel()
+{
+ if (!mListModel || mSelectedIndex < 0
+ || mSelectedIndex >= mListModel->getNumberOfElements())
+ {
+ return;
+ }
+
+ mLabel->setCaption(mListModel->getElementAt(mSelectedIndex));
+ mLabel->adjustSize();
+ const int space = getWidth() - buttonSpace * 2;
+ const int labelWidth = mLabel->getWidth();
+ int labelY = (getHeight() - mLabel->getHeight()) / 2;
+ if (labelY < 0)
+ labelY = 0;
+
+ if (space < 0 || space < labelWidth)
+ mLabel->setPosition(buttonSpace, labelY);
+ else
+ mLabel->setPosition(buttonSpace + (space - labelWidth) / 2, labelY);
+}
+
+void SliderList::action(const gcn::ActionEvent &event)
+{
+ if (!mListModel)
+ return;
+
+ if (event.getId() == mPrevEventId)
+ {
+ mSelectedIndex --;
+ if (mSelectedIndex < 0)
+ mSelectedIndex = mListModel->getNumberOfElements() - 1;
+ }
+ else if (event.getId() == mNextEventId)
+ {
+ mSelectedIndex ++;
+ if (mSelectedIndex >= mListModel->getNumberOfElements())
+ mSelectedIndex = 0;
+ }
+ updateLabel();
+ distributeActionEvent();
+}
+
+void SliderList::setSelectedString(std::string str)
+{
+ if (!mListModel)
+ return;
+
+ for (int f = 0; f < mListModel->getNumberOfElements(); f ++)
+ {
+ if (mListModel->getElementAt(f) == str)
+ {
+ setSelected(f);
+ break;
+ }
+ }
+}
+
+std::string SliderList::getSelectedString() const
+{
+ if (!mListModel)
+ return "";
+
+ return mListModel->getElementAt(mSelectedIndex);
+}
+
+void SliderList::setSelected(int idx)
+{
+ if (!mListModel)
+ return;
+
+ mSelectedIndex = idx;
+ if (mSelectedIndex >= mListModel->getNumberOfElements())
+ mSelectedIndex = 0;
+ if (mSelectedIndex < 0)
+ mSelectedIndex = mListModel->getNumberOfElements() - 1;
+ updateLabel();
+}
+
+void SliderList::adjustSize()
+{
+ setWidth(getMaxLabelWidth() + 60);
+ updateLabel();
+}
+
+int SliderList::getMaxLabelWidth()
+{
+ if (!mListModel || !gui)
+ return 1;
+
+ int maxWidth = 0;
+ gcn::Font *font = gui->getFont();
+
+ for (int f = 0; f < mListModel->getNumberOfElements(); f ++)
+ {
+ int w = font->getWidth(mListModel->getElementAt(f));
+ if (w > maxWidth)
+ maxWidth = w;
+ }
+
+ return maxWidth;
+}
diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h
new file mode 100644
index 000000000..b2239834d
--- /dev/null
+++ b/src/gui/widgets/sliderlist.h
@@ -0,0 +1,83 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_WIDGETS_SLIDERLIST_H
+#define GUI_WIDGETS_SLIDERLIST_H
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/listmodel.hpp>
+#include <guichan/mouselistener.hpp>
+
+#include "gui/widgets/container.h"
+
+#include "localconsts.h"
+
+class Button;
+class Label;
+
+class SliderList : public Container,
+ public gcn::ActionListener,
+ public gcn::MouseListener
+{
+ public:
+ SliderList(gcn::ListModel *listModel = nullptr,
+ gcn::ActionListener* listener = nullptr,
+ std::string eventId = "");
+
+ ~SliderList();
+
+ void updateAlpha();
+
+ void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent);
+
+ void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent);
+
+ void resize();
+
+ void draw(gcn::Graphics *graphics);
+
+ void action(const gcn::ActionEvent &event);
+
+ void setSelectedString(std::string str);
+
+ std::string getSelectedString() const;
+
+ void setSelected(int idx);
+
+ void adjustSize();
+
+ int getSelected()
+ { return mSelectedIndex; }
+
+ protected:
+ void updateLabel();
+
+ int getMaxLabelWidth();
+
+ Button *mButtons[2];
+ Label *mLabel;
+ gcn::ListModel *mListModel;
+ std::string mPrevEventId;
+ std::string mNextEventId;
+ int mOldWidth;
+ int mSelectedIndex;
+};
+
+#endif // end GUI_WIDGETS_SLIDERLIST_H
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
index 5c4dbc9a1..07ecbfaf0 100644
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ b/src/gui/widgets/spellshortcutcontainer.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011 ManaPlus developers
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
@@ -17,8 +17,7 @@
* 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gui/widgets/spellshortcutcontainer.h"
diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h
index 4191f9921..72fec758f 100644
--- a/src/gui/widgets/spellshortcutcontainer.h
+++ b/src/gui/widgets/spellshortcutcontainer.h
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2009 The Mana World Development Team
* Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011 ManaPlus developers
+ * Copyright (C) 2011-2012 The ManaPlus developers
*
* This file is part of The ManaPlus Client.
*
@@ -17,8 +17,7 @@
* 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SPELLSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/tablemodel.h b/src/gui/widgets/tablemodel.h
index 40a350163..e931888e4 100644
--- a/src/gui/widgets/tablemodel.h
+++ b/src/gui/widgets/tablemodel.h
@@ -42,7 +42,8 @@ public:
*/
virtual void modelUpdated(bool completed) = 0;
- virtual ~TableModelListener() {}
+ virtual ~TableModelListener()
+ { }
};
/**
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index a4bc3bc09..575036612 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -116,14 +116,14 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
mMinWidth = minWidth;
wrappedStream.clear();
wrappedStream.str("");
- spacePos = 0;
+// spacePos = 0;
lastNewlinePos = 0;
newlinePos = text.find("\n", lastNewlinePos);
if (newlinePos == std::string::npos)
newlinePos = text.size();
line = text.substr(lastNewlinePos, newlinePos -
lastNewlinePos);
- width = 0;
+// width = 0;
break;
}
else
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index e207b0613..a90712340 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -183,7 +183,7 @@ int TextField::getValue() const
if (value < mMinimum)
return mMinimum;
- if (value > (signed)mMaximum)
+ if (value > static_cast<signed>(mMaximum))
return mMaximum;
return value;