summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2020-02-23 09:30:51 +0300
committerAndrei Karas <akaras@inbox.ru>2020-02-23 09:30:51 +0300
commit1e2a88e975019929c4c7e3154537865cc09550a6 (patch)
treeae8bc68ad3a3f6b61a5e2d511d7fc17daa22bd0e /src/gui/widgets
parent6941fd4eeb1dce20aba8c42fd030c2690c37b731 (diff)
downloadplus-1e2a88e975019929c4c7e3154537865cc09550a6.tar.gz
plus-1e2a88e975019929c4c7e3154537865cc09550a6.tar.bz2
plus-1e2a88e975019929c4c7e3154537865cc09550a6.tar.xz
plus-1e2a88e975019929c4c7e3154537865cc09550a6.zip
Fix some code style issues
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp4
-rw-r--r--src/gui/widgets/button.cpp6
-rw-r--r--src/gui/widgets/dropdown.cpp7
-rw-r--r--src/gui/widgets/extendedlistbox.cpp4
-rw-r--r--src/gui/widgets/itemcontainer.cpp10
-rw-r--r--src/gui/widgets/label.cpp4
-rw-r--r--src/gui/widgets/scrollarea.cpp19
-rw-r--r--src/gui/widgets/tabbedarea.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp1
-rw-r--r--src/gui/widgets/virtshortcutcontainer.cpp23
-rw-r--r--src/gui/widgets/window.cpp2
11 files changed, 44 insertions, 38 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index cfacab828..cac97c092 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -174,9 +174,9 @@ void AvatarListBox::draw(Graphics *const graphics)
text = strprintf("%s %d/%d", a->getComplexName().c_str(),
a->getHp(), a->getMaxHp());
}
- const bool isPoison = a->getPoison();
if (a->getMaxHp() != 0)
{
+ const bool isPoison = a->getPoison();
const ProgressColorIdT themeColor = (isPoison
? ProgressColorId::PROG_HP_POISON
: ProgressColorId::PROG_HP);
@@ -412,9 +412,9 @@ void AvatarListBox::safeDraw(Graphics *const graphics)
text = strprintf("%s %d/%d", a->getComplexName().c_str(),
a->getHp(), a->getMaxHp());
}
- const bool isPoison = a->getPoison();
if (a->getMaxHp() != 0)
{
+ const bool isPoison = a->getPoison();
const ProgressColorIdT themeColor = (isPoison
? ProgressColorId::PROG_HP_POISON
: ProgressColorId::PROG_HP);
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 1f51d8ba9..44e41be5a 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -805,12 +805,16 @@ void Button::adjustSize()
if (mImages != nullptr)
{
- const int spacing = mSpacing[BUTTON_STANDARD];
const int width = font->getWidth(mCaption);
if (width != 0)
+ {
+ const int spacing = mSpacing[BUTTON_STANDARD];
setWidth(width + mImageWidth + spacing + 2 * padding);
+ }
else
+ {
setWidth(mImageWidth + 2 * padding);
+ }
int height = font->getHeight();
if (height < mImageHeight)
height = mImageHeight;
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 1d09d5c97..f4fb56f9e 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -226,7 +226,6 @@ void DropDown::draw(Graphics *const graphics)
updateAlpha();
const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
- const int pad = 2 * mPadding;
mHighlightColor.a = alpha;
mShadowColor.a = alpha;
@@ -272,6 +271,7 @@ void DropDown::draw(Graphics *const graphics)
if (isFocused())
{
+ const int pad = 2 * mPadding;
graphics->setColor(mHighlightColor);
graphics->drawRectangle(Rect(mPadding, mPadding,
mDimension.width - h - pad, h - pad));
@@ -321,11 +321,10 @@ void DropDown::safeDrawFrame(Graphics *const graphics)
void DropDown::drawButton(Graphics *const graphics)
{
- const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
-
- Image *image = buttons[mDroppedDown][mPushed];
+ Image *const image = buttons[mDroppedDown][mPushed];
if (image != nullptr)
{
+ const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
graphics->drawImage(image,
mDimension.width - image->getWidth() - mImagePadding,
(height - image->getHeight()) / 2);
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
index 036c42ac3..b19e18fc8 100644
--- a/src/gui/widgets/extendedlistbox.cpp
+++ b/src/gui/widgets/extendedlistbox.cpp
@@ -141,9 +141,9 @@ void ExtendedListBox::draw(Graphics *const graphics)
for (size_t f = 0; f < itemsSz; ++f)
{
const ExtendedListBoxItem &item = mListItems[f];
- const int row1 = item.row;
if (item.image)
{
+ const int row1 = item.row;
const Image *const image = model->getImageAt(row1);
if (image != nullptr)
{
@@ -201,9 +201,9 @@ void ExtendedListBox::draw(Graphics *const graphics)
for (size_t f = 0; f < selSz; ++f)
{
const ExtendedListBoxItem &item = mSelectedItems[f];
- const int row1 = item.row;
if (item.image)
{
+ const int row1 = item.row;
const Image *const image = model->getImageAt(row1);
if (image != nullptr)
{
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 9c566c9c7..e60e70332 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -365,8 +365,6 @@ void ItemContainer::draw(Graphics *const graphics)
int itemIndex = j * mGridColumns - 1;
for (int i = 0; i < mGridColumns; i++)
{
- int itemX = i * mBoxWidth;
- int itemY = intY0;
itemIndex ++;
if (mShowMatrix[itemIndex] < 0)
continue;
@@ -380,6 +378,8 @@ void ItemContainer::draw(Graphics *const graphics)
Image *const image = item->getImage();
if (image != nullptr)
{
+ int itemX = i * mBoxWidth;
+ int itemY = intY0;
if (mShowMatrix[itemIndex] == mSelectedIndex)
{
if (mSelImg != nullptr)
@@ -487,8 +487,6 @@ void ItemContainer::safeDraw(Graphics *const graphics)
int itemIndex = j * mGridColumns - 1;
for (int i = 0; i < mGridColumns; i++)
{
- int itemX = i * mBoxWidth;
- int itemY = intY0;
itemIndex ++;
if (mShowMatrix[itemIndex] < 0)
continue;
@@ -502,6 +500,8 @@ void ItemContainer::safeDraw(Graphics *const graphics)
Image *const image = item->getImage();
if (image != nullptr)
{
+ int itemX = i * mBoxWidth;
+ int itemY = intY0;
if (mShowMatrix[itemIndex] == mSelectedIndex)
{
if (mSelImg != nullptr)
@@ -1148,9 +1148,9 @@ void ItemContainer::adjustHeight()
mGridRows = maxRows;
}
- const int num = updateMatrix();
if (mShowEmptyRows == ShowEmptyRows_false)
{
+ const int num = updateMatrix();
mDrawRows = num / mGridColumns;
if (mDrawRows == 0 || num % mGridColumns > 0)
++mDrawRows;
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 193c28ec6..9dfa7ce4d 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -152,7 +152,6 @@ void Label::draw(Graphics *const graphics)
BLOCK_START("Label::draw")
int textX;
const Rect &rect = mDimension;
- const int textY = rect.height / 2 - getFont()->getHeight() / 2;
Font *const font = getFont();
switch (mAlignment)
@@ -185,7 +184,10 @@ void Label::draw(Graphics *const graphics)
const Image *const image = mTextChunk.img;
if (image != nullptr)
+ {
+ const int textY = rect.height / 2 - font->getHeight() / 2;
graphics->drawImage(image, textX, textY);
+ }
BLOCK_END("Label::draw")
}
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 27e21593d..172461e64 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -457,14 +457,13 @@ void ScrollArea::drawFrame(Graphics *const graphics)
BLOCK_START("ScrollArea::drawFrame")
if (mOpaque == Opaque_true)
{
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
updateCalcFlag(graphics);
if (mRedraw)
{
+ const int bs = mFrameSize * 2;
+ const int w = mDimension.width + bs;
+ const int h = mDimension.height + bs;
mVertexes2->clear();
graphics->calcWindow(mVertexes2,
0, 0,
@@ -759,10 +758,10 @@ void ScrollArea::mouseExited(MouseEvent& event A_UNUSED)
void ScrollArea::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
- const unsigned int frameSize = 2 * mFrameSize;
Widget *const content = getContent();
if (content != nullptr)
{
+ const unsigned int frameSize = 2 * mFrameSize;
content->setSize(mDimension.width - frameSize,
mDimension.height - frameSize);
}
@@ -935,13 +934,12 @@ void ScrollArea::mouseDragged(MouseEvent &event)
if (mIsVerticalMarkerDragged)
{
const Rect barDim = getVerticalBarDimension();
-
- const int pos = event.getY() - barDim.y
- - mVerticalMarkerDragOffset;
const int length = getVerticalMarkerDimension().height;
if ((barDim.height - length) > 0)
{
+ const int pos = event.getY() - barDim.y
+ - mVerticalMarkerDragOffset;
setVerticalScrollAmount((getVerticalMaxScroll() * pos)
/ (barDim.height - length));
}
@@ -954,13 +952,12 @@ void ScrollArea::mouseDragged(MouseEvent &event)
if (mIsHorizontalMarkerDragged)
{
const Rect barDim = getHorizontalBarDimension();
-
- const int pos = event.getX() - barDim.x
- - mHorizontalMarkerDragOffset;
const int length = getHorizontalMarkerDimension().width;
if ((barDim.width - length) > 0)
{
+ const int pos = event.getX() - barDim.x
+ - mHorizontalMarkerDragOffset;
setHorizontalScrollAmount((getHorizontalMaxScroll() * pos)
/ (barDim.width - length));
}
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 32da8e700..3900be438 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -478,7 +478,6 @@ void TabbedArea::widgetResized(const Event &event A_UNUSED)
const int widgetFrameSize = 2 * mWidgetContainer->getFrameSize();
const int w1 = mDimension.width;
const int h1 = mDimension.height;
- const int width = w1 - frameSize - widgetFrameSize;
const int height = h1 - frameSize
- mWidgetContainer->getY() - widgetFrameSize;
@@ -529,6 +528,7 @@ void TabbedArea::widgetResized(const Event &event A_UNUSED)
if (mArrowButton[1] != nullptr)
{
+ const int width = w1 - frameSize - widgetFrameSize;
// Move the right arrow to fit the windows content.
newWidth = width - mArrowButton[1]->getWidth() - mRightMargin;
if (newWidth < 0)
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
index acd6ffcef..63b2b132d 100644
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ b/src/gui/widgets/tabs/setup_theme.cpp
@@ -242,7 +242,6 @@ Setup_Theme::~Setup_Theme()
delete2(mFontSizeListModel)
delete2(mNpcFontSizeListModel)
delete2(mLangListModel)
- delete2(mInfo)
}
void Setup_Theme::updateInfo()
diff --git a/src/gui/widgets/virtshortcutcontainer.cpp b/src/gui/widgets/virtshortcutcontainer.cpp
index a6553b132..229bdf2de 100644
--- a/src/gui/widgets/virtshortcutcontainer.cpp
+++ b/src/gui/widgets/virtshortcutcontainer.cpp
@@ -100,17 +100,18 @@ void VirtShortcutContainer::draw(Graphics *const graphics)
for (unsigned i = 0; i < mMaxItems; i++)
{
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- if (mShortcut->getItem(i) < 0)
+ const int itemId = mShortcut->getItem(i);
+ if (itemId < 0)
continue;
- const Item *const item = inv->findItem(mShortcut->getItem(i),
+ const Item *const item = inv->findItem(itemId,
mShortcut->getItemColor(i));
if (item != nullptr)
{
+ const int itemX = (i % mGridWidth) * mBoxWidth;
+ const int itemY = (i / mGridWidth) * mBoxHeight;
+
// Draw item icon.
Image *const image = item->getImage();
@@ -176,13 +177,14 @@ void VirtShortcutContainer::safeDraw(Graphics *const graphics)
for (unsigned i = 0; i < mMaxItems; i++)
{
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
+ const int itemId = mShortcut->getItem(i);
+ if (itemId < 0)
+ continue;
- if (mShortcut->getItem(i) < 0)
+ if (itemId < 0)
continue;
- const Item *const item = inv->findItem(mShortcut->getItem(i),
+ const Item *const item = inv->findItem(itemId,
mShortcut->getItemColor(i));
if (item != nullptr)
@@ -192,6 +194,9 @@ void VirtShortcutContainer::safeDraw(Graphics *const graphics)
if (image != nullptr)
{
+ const int itemX = (i % mGridWidth) * mBoxWidth;
+ const int itemY = (i / mGridWidth) * mBoxHeight;
+
std::string caption;
if (item->getQuantity() > 1)
caption = toString(item->getQuantity());
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index deebfd5ef..2d51a49c0 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -1011,7 +1011,6 @@ void Window::mouseDragged(MouseEvent &event)
if ((mouseResize != 0) && !mMoved)
{
- const int dx = event.getX() - mDragOffsetX;
const int dy = event.getY() - mDragOffsetY;
Rect newDim = getDimension();
@@ -1028,6 +1027,7 @@ void Window::mouseDragged(MouseEvent &event)
if ((mouseResize & (LEFT | RIGHT)) != 0)
{
+ const int dx = event.getX() - mDragOffsetX;
const int newWidth = newDim.width
+ ((mouseResize & LEFT) != 0 ? -dx : dx);
newDim.width = std::min(mMaxWinWidth,