From fe25bc152de747eb64a1c1f6084f0399faf125e8 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 15 Apr 2009 23:32:28 +0200 Subject: Have the DropDown create its ScrollArea and ListBox And also clean them up again. Fixes some memory leaks and simplifies the code. Also got rid of the basically unused "opaque" setting of DropDown. --- src/gui/widgets/dropdown.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/gui/widgets/dropdown.cpp') diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 8dabc3f9..b5a75093 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -41,10 +41,10 @@ Image *DropDown::buttons[2][2]; ImageRect DropDown::skin; float DropDown::mAlpha = 1.0; -DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, - gcn::ListBox *listBox, bool opacity): - gcn::DropDown::DropDown(listModel, scrollArea, listBox), - mOpaque(opacity) +DropDown::DropDown(gcn::ListModel *listModel): + gcn::DropDown::DropDown(listModel, + new ScrollArea, + new ListBox(listModel)) { setFrameSize(2); @@ -108,6 +108,9 @@ DropDown::~DropDown() for_each(skin.grid, skin.grid + 9, dtor()); } + + delete mScrollArea; + delete mListBox; } void DropDown::draw(gcn::Graphics* graphics) @@ -134,7 +137,7 @@ void DropDown::draw(gcn::Graphics* graphics) } } - const int alpha = (int)(mAlpha * 255.0f); + const int alpha = (int) (mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT, @@ -142,18 +145,10 @@ void DropDown::draw(gcn::Graphics* graphics) gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; - if (mOpaque) - { - graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha)); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - - graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); - } - - graphics->setFont(getFont()); - if (mListBox->getListModel() && mListBox->getSelected() >= 0) { + graphics->setFont(getFont()); + graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); } -- cgit v1.2.3-70-g09d2