summaryrefslogtreecommitdiff
path: root/src/gui/skilldialog.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-07 22:09:11 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-07 22:09:11 +0300
commitb7e35a7bbd41c39fa675e77b2af6a11bb4d86dd2 (patch)
treeee27a5a1ace7e5dbc588466dc623013e4d5cea99 /src/gui/skilldialog.cpp
parent7d3059516fc25134d0d29b497e546f2846162399 (diff)
downloadplus-b7e35a7bbd41c39fa675e77b2af6a11bb4d86dd2.tar.gz
plus-b7e35a7bbd41c39fa675e77b2af6a11bb4d86dd2.tar.bz2
plus-b7e35a7bbd41c39fa675e77b2af6a11bb4d86dd2.tar.xz
plus-b7e35a7bbd41c39fa675e77b2af6a11bb4d86dd2.zip
Improve constructors in some classes.
Diffstat (limited to 'src/gui/skilldialog.cpp')
-rw-r--r--src/gui/skilldialog.cpp255
1 files changed, 128 insertions, 127 deletions
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 5bd18f540..d25b44941 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -62,165 +62,171 @@ class SkillEntry;
class SkillModel : public gcn::ListModel
{
-public:
- int getNumberOfElements()
- { return static_cast<int>(mVisibleSkills.size()); }
+ public:
+ int getNumberOfElements()
+ { return static_cast<int>(mVisibleSkills.size()); }
- SkillInfo *getSkillAt(const int i) const
- { return mVisibleSkills.at(i); }
+ SkillInfo *getSkillAt(const int i) const
+ { return mVisibleSkills.at(i); }
- std::string getElementAt(int i)
- {
- if (getSkillAt(i))
- return getSkillAt(i)->name;
- else
- return "";
- }
+ std::string getElementAt(int i)
+ {
+ if (getSkillAt(i))
+ return getSkillAt(i)->name;
+ else
+ return "";
+ }
- void updateVisibilities();
+ void updateVisibilities();
- void addSkill(SkillInfo *const info)
- { mSkills.push_back(info); }
+ void addSkill(SkillInfo *const info)
+ { mSkills.push_back(info); }
-private:
- SkillList mSkills;
- SkillList mVisibleSkills;
+ private:
+ SkillList mSkills;
+ SkillList mVisibleSkills;
};
class SkillListBox : public ListBox
{
-public:
- SkillListBox(SkillModel *const model):
- ListBox(model),
- mModel(model),
- mPopup(new TextPopup()),
- mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)),
- mTextColor(Theme::getThemeColor(Theme::TEXT))
- {
- }
+ public:
+ SkillListBox(SkillModel *const model):
+ ListBox(model),
+ mModel(model),
+ mPopup(new TextPopup()),
+ mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)),
+ mTextColor(Theme::getThemeColor(Theme::TEXT))
+ {
+ }
- ~SkillListBox()
- {
- delete mModel;
- mModel = nullptr;
- delete mPopup;
- mPopup = nullptr;
- }
+ ~SkillListBox()
+ {
+ delete mModel;
+ mModel = nullptr;
+ delete mPopup;
+ mPopup = nullptr;
+ }
- SkillInfo *getSelectedInfo() const
- {
- const int selected = getSelected();
- if (!mListModel || selected < 0
- || selected > mListModel->getNumberOfElements())
+ SkillInfo *getSelectedInfo() const
{
- return nullptr;
+ const int selected = getSelected();
+ if (!mListModel || selected < 0
+ || selected > mListModel->getNumberOfElements())
+ {
+ return nullptr;
+ }
+
+ return static_cast<SkillModel*>(mListModel)->getSkillAt(selected);
}
- return static_cast<SkillModel*>(mListModel)->getSkillAt(selected);
- }
+ void draw(gcn::Graphics *gcnGraphics)
+ {
+ if (!mListModel)
+ return;
- void draw(gcn::Graphics *gcnGraphics)
- {
- if (!mListModel)
- return;
+ SkillModel *const model = static_cast<SkillModel*>(mListModel);
+ updateAlpha();
+ Graphics *const graphics = static_cast<Graphics *const>(
+ gcnGraphics);
- SkillModel *const model = static_cast<SkillModel*>(mListModel);
+ mHighlightColor.a = static_cast<int>(mAlpha * 255.0f);
+ graphics->setColor(mHighlightColor);
+ graphics->setFont(getFont());
- updateAlpha();
+ // Draw filled rectangle around the selected list element
+ if (mSelected >= 0)
+ {
+ graphics->fillRectangle(gcn::Rectangle(0, getRowHeight()
+ * mSelected, getWidth(), getRowHeight()));
+ }
- Graphics *const graphics = static_cast<Graphics *const>(gcnGraphics);
+ // Draw the list elements
+ graphics->setColor(mTextColor);
+ for (int i = 0, y = 1;
+ i < model->getNumberOfElements();
+ ++i, y += getRowHeight())
+ {
+ SkillInfo *const e = model->getSkillAt(i);
+ if (e)
+ e->draw(graphics, y, getWidth());
+ }
+ }
- mHighlightColor.a = static_cast<int>(mAlpha * 255.0f);
- graphics->setColor(mHighlightColor);
- graphics->setFont(getFont());
+ unsigned int getRowHeight() const
+ { return 34; }
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
+ void mouseMoved(gcn::MouseEvent &event)
{
- graphics->fillRectangle(gcn::Rectangle(0, getRowHeight()
- * mSelected, getWidth(), getRowHeight()));
+ ListBox::mouseMoved(event);
+ if (!viewport)
+ return;
+
+ const int y = event.getY() / getRowHeight();
+ if (!mModel || y >= mModel->getNumberOfElements())
+ return;
+ const SkillInfo *const skill = mModel->getSkillAt(y);
+ if (!skill)
+ return;
+
+ mPopup->show(viewport->getMouseX(), viewport->getMouseY(),
+ skill->dispName);
}
- // Draw the list elements
- graphics->setColor(mTextColor);
- for (int i = 0, y = 1;
- i < model->getNumberOfElements();
- ++i, y += getRowHeight())
+ void mouseExited(gcn::MouseEvent &event A_UNUSED)
{
- SkillInfo *const e = model->getSkillAt(i);
-
- if (e)
- e->draw(graphics, y, getWidth());
+ mPopup->hide();
}
- }
-
- unsigned int getRowHeight() const
- { return 34; }
- void mouseMoved(gcn::MouseEvent &event)
- {
- ListBox::mouseMoved(event);
- if (!viewport)
- return;
-
- const int y = event.getY() / getRowHeight();
- if (!mModel || y >= mModel->getNumberOfElements())
- return;
- const SkillInfo *const skill = mModel->getSkillAt(y);
- if (!skill)
- return;
-
- mPopup->show(viewport->getMouseX(), viewport->getMouseY(),
- skill->dispName);
- }
-
- void mouseExited(gcn::MouseEvent &event A_UNUSED)
- {
- mPopup->hide();
- }
-
-private:
- SkillModel *mModel;
- TextPopup *mPopup;
- gcn::Color mHighlightColor;
- gcn::Color mTextColor;
+ private:
+ SkillModel *mModel;
+ TextPopup *mPopup;
+ gcn::Color mHighlightColor;
+ gcn::Color mTextColor;
};
class SkillTab : public Tab
{
-public:
- SkillTab(const std::string &name, SkillListBox *const listBox) :
+ public:
+ SkillTab(const std::string &name, SkillListBox *const listBox) :
+ Tab(),
mListBox(listBox)
- {
- setCaption(name);
- }
+ {
+ setCaption(name);
+ }
- ~SkillTab()
- {
- delete mListBox;
- mListBox = nullptr;
- }
+ ~SkillTab()
+ {
+ delete mListBox;
+ mListBox = nullptr;
+ }
- SkillInfo *getSelectedInfo() const
- {
- if (mListBox)
- return mListBox->getSelectedInfo();
- else
- return nullptr;
- }
+ SkillInfo *getSelectedInfo() const
+ {
+ if (mListBox)
+ return mListBox->getSelectedInfo();
+ else
+ return nullptr;
+ }
- void setCurrent()
- {
- if (skillDialog)
- skillDialog->updateTabSelection();
- }
+ protected:
+ void setCurrent()
+ {
+ if (skillDialog)
+ skillDialog->updateTabSelection();
+ }
-private:
- SkillListBox *mListBox;
+ private:
+ SkillListBox *mListBox;
};
-SkillDialog::SkillDialog():
- Window(_("Skills"), false, nullptr, "skills.xml")
+SkillDialog::SkillDialog() :
+ Window(_("Skills"), false, nullptr, "skills.xml"),
+ ActionListener(),
+ mTabs(new TabbedArea()),
+ mPointsLabel(new Label("0")),
+ mUseButton(new Button(_("Use"), "use", this)),
+ mIncreaseButton(new Button(_("Up"), "inc", this)),
+ mDefaultModel(nullptr)
{
setWindowName("Skills");
setCloseButton(true);
@@ -230,12 +236,7 @@ SkillDialog::SkillDialog():
setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
setupWindow->registerWindowForReset(this);
- mTabs = new TabbedArea();
- mPointsLabel = new Label("0");
- mUseButton = new Button(_("Use"), "use", this);
mUseButton->setEnabled(false);
- mIncreaseButton = new Button(_("Up"), "inc", this);
- mDefaultModel = nullptr;
place(0, 0, mTabs, 5, 5);
place(0, 5, mPointsLabel, 4);