diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-16 03:22:50 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-16 03:25:37 +0300 |
commit | 82cc576b7896f39bcf71aa85c8c4b3ef786c065b (patch) | |
tree | 2207f3bb4a0b1fa896fe183da245287525d65117 /src/gui | |
parent | 6bbe09af6faa77df40112e7cf876877ef11ce74b (diff) | |
download | plus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.tar.gz plus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.tar.bz2 plus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.tar.xz plus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.zip |
Add listbox padding.
New theme file: listbox.xml
Theme option: padding
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/serverdialog.cpp | 19 | ||||
-rw-r--r-- | src/gui/skilldialog.cpp | 9 | ||||
-rw-r--r-- | src/gui/widgets/avatarlistbox.cpp | 23 | ||||
-rw-r--r-- | src/gui/widgets/extendedlistbox.cpp | 14 | ||||
-rw-r--r-- | src/gui/widgets/listbox.cpp | 46 | ||||
-rw-r--r-- | src/gui/widgets/listbox.h | 6 | ||||
-rw-r--r-- | src/gui/widgets/shoplistbox.cpp | 12 |
7 files changed, 86 insertions, 43 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 408c1c3e2..673bfbcd5 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -186,8 +186,9 @@ public: // Draw filled rectangle around the selected list element if (mSelected >= 0) { - graphics->fillRectangle(gcn::Rectangle(0, - height * mSelected, getWidth(), height)); + graphics->fillRectangle(gcn::Rectangle(mPadding, + height * mSelected + mPadding, getWidth() - 2 * mPadding, + height)); } // Draw the list elements @@ -199,32 +200,32 @@ public: graphics->setColor(mTextColor); int top; - int x = 2; + int x = mPadding; if (!info.name.empty()) { graphics->setFont(boldFont); x += boldFont->getWidth(info.name) + 15; - graphics->drawText(info.name, 2, y); - top = y + boldFont->getHeight() + 2; + graphics->drawText(info.name, mPadding, y + mPadding); + top = y + boldFont->getHeight() + mPadding; } else { - top = y + height / 4 + 2; + top = y + height / 4 + mPadding; } graphics->setFont(getFont()); if (!info.description.empty()) - graphics->drawText(info.description, x, y); - graphics->drawText(model->getElementAt(i), 2, top); + graphics->drawText(info.description, x, y + mPadding); + graphics->drawText(model->getElementAt(i), mPadding, top); if (info.version.first > 0) { graphics->setColor(mNotSupportedColor); graphics->drawText(info.version.second, - getWidth() - info.version.first - 2, top); + getWidth() - info.version.first - mPadding, top); } } } diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index a735bf1b4..063e29939 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -138,8 +138,9 @@ class SkillListBox final : public ListBox // Draw filled rectangle around the selected list element if (mSelected >= 0) { - graphics->fillRectangle(gcn::Rectangle(0, getRowHeight() - * mSelected, getWidth(), getRowHeight())); + graphics->fillRectangle(gcn::Rectangle(mPadding, getRowHeight() + * mSelected + mPadding, getWidth() - 2 * mPadding, + getRowHeight())); } // Draw the list elements @@ -150,7 +151,7 @@ class SkillListBox final : public ListBox { SkillInfo *const e = model->getSkillAt(i); if (e) - e->draw(graphics, y, getWidth()); + e->draw(graphics, y + mPadding, getWidth() + mPadding); } } @@ -166,7 +167,7 @@ class SkillListBox final : public ListBox const int y = event.getY() / getRowHeight(); if (!mModel || y >= mModel->getNumberOfElements()) return; - const SkillInfo *const skill = mModel->getSkillAt(y); + const SkillInfo *const skill = mModel->getSkillAt(y + mPadding); if (!skill) return; diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 1301d4a2e..f8a025142 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -127,7 +127,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) const Image *const icon = a->getOnline() ? onlineIcon : offlineIcon; if (icon) - graphics->drawImage(icon, 2, y + 1); + graphics->drawImage(icon, mPadding, y + mPadding); } if (a->getDisplayBold()) @@ -155,9 +155,9 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) color.a = 80; graphics->setColor(color); - graphics->fillRectangle(gcn::Rectangle(0, y, - parent->getWidth() * a->getHp() / a->getMaxHp(), - fontHeight)); + graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding, + parent->getWidth() * a->getHp() / a->getMaxHp() + - 2 * mPadding, fontHeight)); } } else if (a->getDamageHp() != 0 && a->getName() != name) @@ -180,9 +180,9 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) color.a = 80; graphics->setColor(color); - graphics->fillRectangle(gcn::Rectangle(0, y, - parent->getWidth() * a->getDamageHp() / 1024, - fontHeight)); + graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding, + parent->getWidth() * a->getDamageHp() / 1024 + - 2 * mPadding, fontHeight)); if (a->getLevel() > 1) { @@ -191,7 +191,8 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) if (minHp < 0) minHp = 40; - graphics->drawLine(parent->getWidth()*minHp / 1024, y, + graphics->drawLine(parent->getWidth()*minHp / 1024 + + mPadding, y + mPadding, parent->getWidth() * minHp / 1024, y + fontHeight); } } @@ -267,9 +268,9 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) // Draw Name if (a->getType() == MapItem::SEPARATOR) - graphics->drawText(text, 2, y); + graphics->drawText(text, mPadding, y + mPadding); else - graphics->drawText(text, 15, y); + graphics->drawText(text, 15 + mPadding, y + mPadding); if (a->getDisplayBold()) graphics->setFont(getFont()); @@ -286,7 +287,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event) return; } - const int y = event.getY() / getFont()->getHeight(); + const int y = (event.getY() - mPadding) / getFont()->getHeight(); if (!mListModel || y > mListModel->getNumberOfElements()) return; diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index 610b4360c..249254cde 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -61,7 +61,7 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) graphics->setFont(getFont()); const int height = getRowHeight(); - int textPos = (height - getFont()->getHeight()) / 2; + int textPos = (height - getFont()->getHeight()) / 2 + mPadding; if (textPos < 0) textPos = 0; @@ -70,8 +70,9 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) { mHighlightColor.a = static_cast<int>(mAlpha * 255.0f); graphics->setColor(mHighlightColor); - graphics->fillRectangle(gcn::Rectangle(0, height * mSelected, - getWidth(), height)); + graphics->fillRectangle(gcn::Rectangle(mPadding, + height * mSelected + mPadding, + getWidth() - 2 * mPadding, height)); } // Draw the list elements @@ -82,13 +83,14 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) const Image *const image = model->getImageAt(i); if (!image) { - graphics->drawText(mListModel->getElementAt(i), 1, y + textPos); + graphics->drawText(mListModel->getElementAt(i), mPadding, y + textPos); } else { - g->drawImage(image, 1, y + (height - image->getHeight()) / 2); + g->drawImage(image, mPadding, y + (height - image->getHeight()) + / 2 + mPadding); graphics->drawText(mListModel->getElementAt(i), - image->getWidth() + 2, y + textPos); + image->getWidth() + mPadding, y + textPos); } } } diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 3592b12da..8e56cfe9f 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -40,6 +40,8 @@ #include "debug.h" float ListBox::mAlpha = 1.0; +Skin *ListBox::mSkin = nullptr; +int ListBox::mInstances = 0; ListBox::ListBox(gcn::ListModel *const listModel): gcn::ListBox(listModel), @@ -48,11 +50,27 @@ ListBox::ListBox(gcn::ListModel *const listModel): mOldSelected(-1) { mForegroundColor = Theme::getThemeColor(Theme::LISTBOX); + + if (mInstances == 0) + { + if (Theme::instance()) + mSkin = Theme::instance()->load("listbox.xml", ""); + } + mInstances ++; + + if (mSkin) + mPadding = mSkin->getPadding(); + else + mPadding = 0; + adjustSize(); } ListBox::~ListBox() { + mInstances --; + if (mInstances == 0 && Theme::instance()) + Theme::instance()->unload(mSkin); } void ListBox::updateAlpha() @@ -80,8 +98,8 @@ void ListBox::draw(gcn::Graphics *graphics) // Draw filled rectangle around the selected list element if (mSelected >= 0) { - graphics->fillRectangle(gcn::Rectangle(0, height * mSelected, - getWidth(), height)); + graphics->fillRectangle(gcn::Rectangle(mPadding, height * mSelected, + getWidth() - 2 * mPadding, height)); } // Draw the list elements @@ -89,7 +107,8 @@ void ListBox::draw(gcn::Graphics *graphics) for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += height) { - graphics->drawText(mListModel->getElementAt(i), 1, y); + graphics->drawText(mListModel->getElementAt(i), + mPadding, y + mPadding); } } @@ -149,7 +168,7 @@ void ListBox::mousePressed(gcn::MouseEvent &event) { if (mDistributeMousePressed) { - gcn::ListBox::mousePressed(event); + mousePressed1(event); } else { @@ -163,7 +182,7 @@ void ListBox::mousePressed(gcn::MouseEvent &event) if (gui) gui->resetClickCount(); if (mOldSelected == mSelected) - gcn::ListBox::mousePressed(event); + mousePressed1(event); else mouseDragged(event); mOldSelected = mSelected; @@ -176,6 +195,16 @@ void ListBox::mousePressed(gcn::MouseEvent &event) } } +void ListBox::mousePressed1(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) + { + setSelected(std::max(0, mouseEvent.getY() - mPadding) + / getRowHeight()); + distributeActionEvent(); + } +} + void ListBox::mouseDragged(gcn::MouseEvent &event) { if (event.getButton() != gcn::MouseEvent::LEFT || getRowHeight() == 0) @@ -183,7 +212,7 @@ void ListBox::mouseDragged(gcn::MouseEvent &event) // Make list selection update on drag, but guard against negative y if (getRowHeight()) - setSelected(std::max(0, event.getY()) / getRowHeight()); + setSelected(std::max(0, event.getY() - mPadding) / getRowHeight()); } void ListBox::refocus() @@ -198,7 +227,10 @@ void ListBox::refocus() void ListBox::adjustSize() { if (mListModel) - setHeight(getRowHeight() * mListModel->getNumberOfElements()); + { + setHeight(getRowHeight() * mListModel->getNumberOfElements() + + 2 * mPadding); + } } void ListBox::logic() diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index c9a70557f..0512183d1 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -28,6 +28,7 @@ #include "localconsts.h" class SelectionListener; +class Skin; /** * A list box, meant to be used inside a scroll area. Same as the Guichan list @@ -70,6 +71,8 @@ class ListBox : public gcn::ListBox void mousePressed(gcn::MouseEvent &event) override; + void mousePressed1(gcn::MouseEvent &event); + void mouseDragged(gcn::MouseEvent &event) override; void refocus(); @@ -85,7 +88,10 @@ class ListBox : public gcn::ListBox gcn::Color mHighlightColor; bool mDistributeMousePressed; int mOldSelected; + int mPadding; static float mAlpha; + static Skin *mSkin; + static int mInstances; }; #endif diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 480f220ea..79fca30d5 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -95,7 +95,6 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) Graphics *graphics = static_cast<Graphics*>(gcnGraphics); graphics->setFont(getFont()); -// graphics->setColor(mForegroundColor); // Draw the list elements for (int i = 0, y = 0; @@ -139,8 +138,8 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) if (needDraw) { graphics->setColor(*backgroundColor); - graphics->fillRectangle(gcn::Rectangle( - 0, y, getWidth(), mRowHeight)); + graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding, + getWidth() - 2 * mPadding, mRowHeight)); } if (mShopItems) @@ -149,12 +148,13 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) if (icon) { icon->setAlpha(1.0f); - graphics->drawImage(icon, 1, y); + graphics->drawImage(icon, mPadding, y + mPadding); } } graphics->setColor(mForegroundColor); - graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, - y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); + graphics->drawText(mListModel->getElementAt(i), + ITEM_ICON_SIZE + mPadding, + y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2 + mPadding); } } |