summaryrefslogtreecommitdiff
path: root/src/gui/widgets/dropdown.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/dropdown.cpp')
-rw-r--r--src/gui/widgets/dropdown.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 45c8e53f..28308ce6 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -42,6 +42,9 @@ DropDown::DropDown(gcn::ListModel *listModel):
setFrameSize(skin.frameSize);
mPadding = skin.padding;
+ // Make sure to call the right setOpaque function
+ static_cast<ScrollArea*>(mScrollArea)->setOpaque(false);
+
setHeight(getFont()->getHeight() + 2 * mPadding);
}
@@ -57,7 +60,8 @@ void DropDown::draw(gcn::Graphics* graphics)
const int alpha = gui->getTheme()->getGuiAlpha();
gcn::Color faceColor = getBaseColor();
faceColor.a = alpha;
- const gcn::Color *highlightColor = &Theme::getThemeColor(Theme::HIGHLIGHT, alpha);
+ auto highlightColor = Theme::getThemeColor(Theme::HIGHLIGHT);
+ highlightColor.a = alpha;
gcn::Color shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
@@ -72,7 +76,7 @@ void DropDown::draw(gcn::Graphics* graphics)
if (isFocused())
{
- graphics->setColor(*highlightColor);
+ graphics->setColor(highlightColor);
graphics->drawRectangle(
gcn::Rectangle(mPadding, mPadding, getWidth() - h - mPadding * 2, h - 2 * mPadding));
}
@@ -85,10 +89,10 @@ void DropDown::draw(gcn::Graphics* graphics)
// Draw two lines separating the ListBox with selected
// element view.
- graphics->setColor(*highlightColor);
- graphics->drawLine(0, h, getWidth(), h);
+ graphics->setColor(highlightColor);
+ graphics->drawLine(0, h, getWidth() - 1, h);
graphics->setColor(shadowColor);
- graphics->drawLine(0, h + 1, getWidth(), h + 1);
+ graphics->drawLine(0, h + 1, getWidth() - 1, h + 1);
}
}
@@ -109,21 +113,22 @@ void DropDown::adjustHeight()
const int listBoxHeight = mListBox->getHeight();
int height = getFont()->getHeight() + 2 * mPadding;
- // The addition/subtraction of 2 compensates for the seperation lines
+ // The addition/subtraction of 4 compensates for the seperation lines
// seperating the selected element view and the scroll area.
+ const int extraHeight = 4;
if (mDroppedDown && getParent())
{
- int availableHeight = getParent()->getChildrenArea().height - getY();
+ int availableHeight = getParent()->getChildrenArea().height - getY() - getFrameSize();
- if (listBoxHeight > availableHeight - height - 2)
+ if (listBoxHeight > availableHeight - height - extraHeight)
{
- mScrollArea->setHeight(availableHeight - height - 2);
+ mScrollArea->setHeight(availableHeight - height - extraHeight);
height = availableHeight;
}
else
{
- height += listBoxHeight + 2;
+ height += listBoxHeight + extraHeight;
mScrollArea->setHeight(listBoxHeight);
}
}
@@ -131,11 +136,26 @@ void DropDown::adjustHeight()
setHeight(height);
mScrollArea->setWidth(getWidth());
- // Resize the ListBox to exactly fit the ScrollArea.
- mListBox->setWidth(mScrollArea->getChildrenArea().width);
+ // Resize the ListBox to exactly fit the ScrollArea, minus the one pixel padding.
+ mListBox->setWidth(mScrollArea->getChildrenArea().width - 2);
mScrollArea->setPosition(0, 0);
}
+// Overridden to add more space for the separator
+gcn::Rectangle DropDown::getChildrenArea()
+{
+ if (mDroppedDown)
+ {
+ // Calculate the children area (with the two pixel border in mind)
+ return gcn::Rectangle(1,
+ mFoldedUpHeight + 3,
+ getWidth() - 2,
+ getHeight() - mFoldedUpHeight - 4);
+ }
+
+ return gcn::Rectangle();
+}
+
void DropDown::drawButton(gcn::Graphics *graphics)
{
WidgetState state(this);
@@ -147,13 +167,12 @@ void DropDown::drawButton(gcn::Graphics *graphics)
if (mPushed)
state.flags |= STATE_HOVERED;
- const auto theme = gui->getTheme();
- const int buttonWidth = theme->getMinWidth(SkinType::DropDownButton);
+ auto &skin = gui->getTheme()->getSkin(SkinType::DropDownButton);
// FIXME: Needs support for setting alignment in the theme.
- state.x = state.width - buttonWidth;
+ state.x = state.width - skin.getMinWidth();
- theme->drawSkin(static_cast<Graphics *>(graphics), SkinType::DropDownButton, state);
+ skin.draw(static_cast<Graphics *>(graphics), state);
}
// -- KeyListener notifications