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/widgets | |
parent | 6bbe09af6faa77df40112e7cf876877ef11ce74b (diff) | |
download | manaplus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.tar.gz manaplus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.tar.bz2 manaplus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.tar.xz manaplus-82cc576b7896f39bcf71aa85c8c4b3ef786c065b.zip |
Add listbox padding.
New theme file: listbox.xml
Theme option: padding
Diffstat (limited to 'src/gui/widgets')
-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 |
5 files changed, 71 insertions, 30 deletions
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); } } |