summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-14 02:54:44 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-14 02:54:44 +0300
commit84499779fcf0c8b5392a88f1c9311775e692ebef (patch)
treef390326a50eed73d8f8c62107979a4d81093ce52 /src/gui/widgets
parent4ee30f47b491de0ace9b692072fd286cf12c7828 (diff)
downloadmv-84499779fcf0c8b5392a88f1c9311775e692ebef.tar.gz
mv-84499779fcf0c8b5392a88f1c9311775e692ebef.tar.bz2
mv-84499779fcf0c8b5392a88f1c9311775e692ebef.tar.xz
mv-84499779fcf0c8b5392a88f1c9311775e692ebef.zip
Improve a bit some gui controls speed.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp22
-rw-r--r--src/gui/widgets/button.cpp9
-rw-r--r--src/gui/widgets/checkbox.cpp6
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/extendedlistbox.cpp5
-rw-r--r--src/gui/widgets/extendedlistbox.h3
-rw-r--r--src/gui/widgets/guitable.cpp20
-rw-r--r--src/gui/widgets/icon.cpp5
-rw-r--r--src/gui/widgets/itemcontainer.cpp6
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp64
-rw-r--r--src/gui/widgets/layout.cpp16
-rw-r--r--src/gui/widgets/playerbox.cpp7
-rw-r--r--src/gui/widgets/radiobutton.cpp7
13 files changed, 80 insertions, 92 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 805922b2b..8de202120 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -102,7 +102,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
Graphics *const graphics = static_cast<Graphics *const>(gcnGraphics);
mHighlightColor.a = static_cast<int>(mAlpha * 255.0f);
- graphics->setColor(mHighlightColor);
+// graphics->setColor(mHighlightColor);
graphics->setFont(getFont());
const int fontHeight = getFont()->getHeight();
@@ -175,28 +175,8 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
if (parent)
{
-// int diff;
-// if (a->getDamageHp() > 1024)
-// diff = 0;
-// else
-// diff = 1024 - a->getDamageHp();
gcn::Color color = Theme::getProgressColor(Theme::PROG_HP,
1);
-// 0 / 1024);
-/*
- if (a->getDamageHp() >= 400)
- {
- }
- else
- {
-// int intens = 1024/(400 - a->getDamageHp());
- int intens = a->getDamageHp() / 1024;
- if (intens > 1)
- intens = 1;
- color = Theme::getProgressColor(Theme::PROG_HP,
- intens);
- }
-*/
color.a = 80;
graphics->setColor(color);
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index c8f756f6a..ce2dfd74a 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -433,19 +433,20 @@ void Button::widgetMoved(const gcn::Event &event A_UNUSED)
void Button::adjustSize()
{
+ const gcn::Font *const font = getFont();
if (mImages)
{
- setWidth(getFont()->getWidth(mCaption)
+ setWidth(font->getWidth(mCaption)
+ mImageWidth + 2 + 2 * mSpacing);
- int height = getFont()->getHeight();
+ int height = font->getHeight();
if (height < mImageHeight)
height = mImageHeight;
setHeight(height + 2 * mSpacing);
}
else
{
- setWidth(getFont()->getWidth(mCaption) + 2 * mSpacing);
- setHeight(getFont()->getHeight() + 2 * mSpacing);
+ setWidth(font->getWidth(mCaption) + 2 * mSpacing);
+ setHeight(font->getHeight() + 2 * mSpacing);
}
}
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index 759ca9015..344b99eb0 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -178,9 +178,9 @@ void CheckBox::drawBox(gcn::Graphics *const graphics)
{
const Image *box;
- if (isEnabled())
+ if (mEnabled && isVisible())
{
- if (isSelected())
+ if (mSelected)
{
if (mHasMouse)
box = checkBoxCheckedHi;
@@ -197,7 +197,7 @@ void CheckBox::drawBox(gcn::Graphics *const graphics)
}
else
{
- if (isSelected())
+ if (mSelected)
box = checkBoxDisabledChecked;
else
box = checkBoxDisabled;
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 905a3229b..784587708 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -123,7 +123,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
const int emoteY = (i / mGridWidth) * mBoxHeight;
// Draw emote keyboard shortcut.
- std::string key = inputManager.getKeyValueString(
+ const std::string key = inputManager.getKeyValueString(
Input::KEY_EMOTE_1 + i);
graphics->setColor(getForegroundColor());
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
index c7d42338c..a2c9c0691 100644
--- a/src/gui/widgets/extendedlistbox.cpp
+++ b/src/gui/widgets/extendedlistbox.cpp
@@ -92,8 +92,3 @@ void ExtendedListBox::draw(gcn::Graphics *graphics)
}
}
}
-
-unsigned int ExtendedListBox::getRowHeight() const
-{
- return mRowHeight;
-}
diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h
index 44e160da3..8d323ae68 100644
--- a/src/gui/widgets/extendedlistbox.h
+++ b/src/gui/widgets/extendedlistbox.h
@@ -38,7 +38,8 @@ class ExtendedListBox : public ListBox
*/
void draw(gcn::Graphics *graphics);
- unsigned int getRowHeight() const;
+ unsigned int getRowHeight() const
+ { return mRowHeight; }
void setRowHeight(unsigned int n)
{ mRowHeight = n; }
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 088b72db3..4cd6d03cf 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -236,15 +236,16 @@ void GuiTable::setSelectedColumn(int selected)
}
else
{
- if ((selected >= mModel->getColumns() && mWrappingEnabled) ||
+ const int columns = mModel->getColumns();
+ if ((selected >= columns && mWrappingEnabled) ||
(selected < 0 && !mWrappingEnabled))
{
mSelectedColumn = 0;
}
- else if ((selected >= mModel->getColumns() && !mWrappingEnabled) ||
+ else if ((selected >= columns && !mWrappingEnabled) ||
(selected < 0 && mWrappingEnabled))
{
- mSelectedColumn = mModel->getColumns() - 1;
+ mSelectedColumn = columns - 1;
}
else
{
@@ -345,11 +346,11 @@ void GuiTable::draw(gcn::Graphics* graphics)
widget->setDimension(bounds);
- mHighlightColor.a = static_cast<int>(mAlpha * 255.0f);
- graphics->setColor(mHighlightColor);
-
if (mSelectedRow > 0)
{
+ mHighlightColor.a = static_cast<int>(mAlpha * 255.0f);
+ graphics->setColor(mHighlightColor);
+
if (mLinewiseMode && r == static_cast<unsigned>(
mSelectedRow) && c == 0)
{
@@ -477,7 +478,6 @@ void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
{
setSelectedRow(getSelectedRow() - 1);
}
-
mouseEvent.consume();
}
}
@@ -487,7 +487,6 @@ void GuiTable::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
if (isFocused())
{
setSelectedRow(getSelectedRow() + 1);
-
mouseEvent.consume();
}
}
@@ -561,14 +560,15 @@ int GuiTable::getColumnForX(int x) const
int column;
int delta = 0;
- for (column = 0; column < mModel->getColumns(); column++)
+ const int colnum = mModel->getColumns();
+ for (column = 0; column < colnum; column ++)
{
delta += getColumnWidth(column);
if (x <= delta)
break;
}
- if (column < 0 || column >= mModel->getColumns())
+ if (column < 0 || column >= colnum)
return -1;
else
return column;
diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp
index e43f85af0..0236cde6a 100644
--- a/src/gui/widgets/icon.cpp
+++ b/src/gui/widgets/icon.cpp
@@ -57,8 +57,7 @@ void Icon::draw(gcn::Graphics *g)
if (mImage)
{
Graphics *const graphics = static_cast<Graphics*>(g);
- const int x = (getWidth() - mImage->mBounds.w) / 2;
- const int y = (getHeight() - mImage->mBounds.h) / 2;
- graphics->drawImage(mImage, x, y);
+ graphics->drawImage(mImage, (getWidth() - mImage->mBounds.w) / 2,
+ (getHeight() - mImage->mBounds.h) / 2);
}
}
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 08c26d152..19f35ff02 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -226,11 +226,13 @@ void ItemContainer::draw(gcn::Graphics *graphics)
for (int j = 0; j < mGridRows; j++)
{
+ const int intY0 = j * BOX_HEIGHT;
+ int itemIndex = j * mGridColumns - 1;
for (int i = 0; i < mGridColumns; i++)
{
int itemX = i * BOX_WIDTH;
- int itemY = j * BOX_HEIGHT;
- const int itemIndex = j * mGridColumns + i;
+ int itemY = intY0;
+ itemIndex ++;
if (mShowMatrix[itemIndex] < 0)
continue;
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index 04c6de606..8ebad55ed 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -94,7 +94,8 @@ ItemShortcutContainer::~ItemShortcutContainer()
void ItemShortcutContainer::draw(gcn::Graphics *graphics)
{
- if (!itemShortcut[mNumber])
+ const ItemShortcut *const selShortcut = itemShortcut[mNumber];
+ if (!selShortcut)
return;
mAlpha = Client::getGuiAlpha();
@@ -133,8 +134,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
- const int itemId = itemShortcut[mNumber]->getItem(i);
- const unsigned char itemColor = itemShortcut[mNumber]->getItemColor(i);
+ const int itemId = selShortcut->getItem(i);
+ const unsigned char itemColor = selShortcut->getItemColor(i);
if (itemId < 0)
continue;
@@ -228,7 +229,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
{
- if (!itemShortcut[mNumber])
+ ItemShortcut *const selShortcut = itemShortcut[mNumber];
+ if (!selShortcut)
return;
if (event.getButton() == gcn::MouseEvent::LEFT)
@@ -240,9 +242,8 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
if (index == -1)
return;
- const int itemId = itemShortcut[mNumber]->getItem(index);
- const unsigned char itemColor = itemShortcut[mNumber]->
- getItemColor(index);
+ const int itemId = selShortcut->getItem(index);
+ const unsigned char itemColor = selShortcut->getItemColor(index);
if (itemId < 0)
return;
@@ -258,7 +259,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
if (item)
{
mItemMoved = item;
- itemShortcut[mNumber]->removeItem(index);
+ selShortcut->removeItem(index);
}
}
else if (itemId < SKILL_MIN_ID && spellManager)
@@ -266,11 +267,11 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
const TextCommand *const spell = spellManager->getSpellByItem(
itemId);
if (spell)
- itemShortcut[mNumber]->removeItem(index);
+ selShortcut->removeItem(index);
}
else
{
- itemShortcut[mNumber]->removeItem(index);
+ selShortcut->removeItem(index);
}
}
if (mItemMoved)
@@ -283,7 +284,8 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
{
- if (!itemShortcut[mNumber])
+ ItemShortcut *const selShortcut = itemShortcut[mNumber];
+ if (!selShortcut)
return;
const int index = getIndexFromGrid(event.getX(), event.getY());
@@ -294,40 +296,41 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
if (event.getButton() == gcn::MouseEvent::LEFT)
{
// Stores the selected item if theirs one.
- if (itemShortcut[mNumber]->isItemSelected() &&
- inventoryWindow && (inventoryWindow->isVisible() ||
- itemShortcut[mNumber]->getSelectedItem() >= SPELL_MIN_ID))
+ if (selShortcut->isItemSelected() && inventoryWindow &&
+ (inventoryWindow->isVisible() || selShortcut->getSelectedItem()
+ >= SPELL_MIN_ID))
{
- itemShortcut[mNumber]->setItem(index);
- itemShortcut[mNumber]->setItemSelected(-1);
+ selShortcut->setItem(index);
+ selShortcut->setItemSelected(-1);
if (spellShortcut)
spellShortcut->setItemSelected(-1);
inventoryWindow->unselectItem();
}
- else if (itemShortcut[mNumber]->getItem(index))
+ else if (selShortcut->getItem(index))
{
mItemClicked = true;
}
}
else if (event.getButton() == gcn::MouseEvent::RIGHT)
{
- if (viewport && itemShortcut[mNumber])
+ if (viewport && selShortcut)
{
- viewport->showItemPopup(itemShortcut[mNumber]->getItem(index),
- itemShortcut[mNumber]->getItemColor(index));
+ viewport->showItemPopup(selShortcut->getItem(index),
+ selShortcut->getItemColor(index));
}
}
}
void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
{
- if (!itemShortcut[mNumber])
+ ItemShortcut *const selShortcut = itemShortcut[mNumber];
+ if (!selShortcut)
return;
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (itemShortcut[mNumber]->isItemSelected())
- itemShortcut[mNumber]->setItemSelected(-1);
+ if (selShortcut->isItemSelected())
+ selShortcut->setItemSelected(-1);
const int index = getIndexFromGrid(event.getX(), event.getY());
if (index == -1)
@@ -337,13 +340,13 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
if (mItemMoved)
{
- itemShortcut[mNumber]->setItems(index,
- mItemMoved->getId(), mItemMoved->getColor());
+ selShortcut->setItems(index, mItemMoved->getId(),
+ mItemMoved->getColor());
mItemMoved = nullptr;
}
- else if (itemShortcut[mNumber]->getItem(index) && mItemClicked)
+ else if (selShortcut->getItem(index) && mItemClicked)
{
- itemShortcut[mNumber]->useItem(index);
+ selShortcut->useItem(index);
}
if (mItemClicked)
@@ -354,7 +357,8 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
// Show ItemTooltip
void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
{
- if (!itemShortcut[mNumber])
+ const ItemShortcut *const selShortcut = itemShortcut[mNumber];
+ if (!selShortcut)
return;
const int index = getIndexFromGrid(event.getX(), event.getY());
@@ -362,8 +366,8 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
if (index == -1)
return;
- const int itemId = itemShortcut[mNumber]->getItem(index);
- const unsigned char itemColor = itemShortcut[mNumber]->getItemColor(index);
+ const int itemId = selShortcut->getItem(index);
+ const unsigned char itemColor = selShortcut->getItemColor(index);
if (itemId < 0)
return;
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index 6ad1bb71b..96c6dffee 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -88,8 +88,9 @@ void LayoutCell::computeSizes()
std::vector <std::vector <LayoutCell *> >::const_iterator
i = mArray->mCells.begin();
-
- while (i != mArray->mCells.end())
+ std::vector <std::vector <LayoutCell *> >::const_iterator
+ i_end = mArray->mCells.end();
+ while (i != i_end)
{
std::vector <LayoutCell *>::const_iterator j = i->begin();
while (j != i->end())
@@ -115,10 +116,13 @@ LayoutArray::~LayoutArray()
{
std::vector <std::vector <LayoutCell *> >::iterator
i = mCells.begin();
- while (i != mCells.end())
+ std::vector <std::vector <LayoutCell *> >::iterator
+ i_end = mCells.end();
+ while (i != i_end)
{
std::vector< LayoutCell * >::iterator j = i->begin();
- while (j != i->end())
+ std::vector< LayoutCell * >::iterator j_end = i->end();
+ while (j != j_end)
{
delete *j;
++j;
@@ -158,7 +162,9 @@ void LayoutArray::resizeGrid(int w, const int h)
std::vector <std::vector <LayoutCell *> >::iterator
i = mCells.begin();
- while (i != mCells.end())
+ std::vector <std::vector <LayoutCell *> >::iterator
+ i_end = mCells.end();
+ while (i != i_end)
{
i->resize(w, nullptr);
++i;
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
index 0b0e548b2..0fdaa87c3 100644
--- a/src/gui/widgets/playerbox.cpp
+++ b/src/gui/widgets/playerbox.cpp
@@ -57,10 +57,11 @@ PlayerBox::PlayerBox(std::string skin) :
PlayerBox::~PlayerBox()
{
- if (Theme::instance())
+ Theme *const theme = Theme::instance();
+ if (theme)
{
- Theme::instance()->unload(mSkin);
- Theme::instance()->unloadRect(mBackground);
+ theme->unload(mSkin);
+ theme->unloadRect(mBackground);
}
mBeing = nullptr;
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index 21e318955..1daea1d1a 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -121,9 +121,9 @@ void RadioButton::drawBox(gcn::Graphics* graphics)
const Image *box = nullptr;
- if (isEnabled())
+ if (mEnabled && isVisible())
{
- if (isSelected())
+ if (mSelected)
if (mHasMouse)
box = radioCheckedHi;
else
@@ -136,7 +136,7 @@ void RadioButton::drawBox(gcn::Graphics* graphics)
}
else
{
- if (isSelected())
+ if (mSelected)
box = radioDisabledChecked;
else
box = radioDisabled;
@@ -152,7 +152,6 @@ void RadioButton::draw(gcn::Graphics* graphics)
graphics->setFont(getFont());
graphics->setColor(getForegroundColor());
-
graphics->drawText(getCaption(), 16, 0);
}