Keep one instance of BrushPopup in memory

This commit is contained in:
David Capello 2015-04-28 12:53:02 -03:00
parent 058682bcaa
commit 303bd120dc
3 changed files with 17 additions and 17 deletions

View File

@ -22,14 +22,13 @@ namespace app {
using namespace app::skin;
using namespace ui;
BrushPopup::BrushPopup(const gfx::Rect& rc, doc::Brush* brush)
BrushPopup::BrushPopup()
: PopupWindow("", kCloseOnClickInOtherWindow)
{
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
setAutoRemap(false);
setBorder(gfx::Border(0));
setBounds(rc);
child_spacing = 0;
m_brushTypeButton = new ButtonSet(3);
@ -40,7 +39,10 @@ BrushPopup::BrushPopup(const gfx::Rect& rc, doc::Brush* brush)
m_brushTypeButton->setTransparent(true);
m_brushTypeButton->setBgColor(gfx::ColorNone);
addChild(m_brushTypeButton);
}
void BrushPopup::setBrush(doc::Brush* brush)
{
m_brushTypeButton->setSelectedItem(brush->type());
}

View File

@ -21,7 +21,9 @@ namespace app {
class BrushPopup : public ui::PopupWindow {
public:
BrushPopup(const gfx::Rect& rc, doc::Brush* brush);
BrushPopup();
void setBrush(doc::Brush* brush);
Signal1<void, doc::Brush*> BrushChange;

View File

@ -63,8 +63,7 @@ static bool g_updatingFromTool = false;
class ContextBar::BrushTypeField : public ButtonSet {
public:
BrushTypeField()
: ButtonSet(1)
, m_popupWindow(NULL) {
: ButtonSet(1) {
m_bitmap = she::instance()->createRgbaSurface(8, 8);
she::ScopedSurfaceLock lock(m_bitmap);
lock->clear();
@ -111,7 +110,7 @@ protected:
void onItemChange() override {
ButtonSet::onItemChange();
if (!m_popupWindow || !m_popupWindow->isVisible())
if (!m_popupWindow.isVisible())
openPopup();
else
closePopup();
@ -133,21 +132,18 @@ private:
IBrushSettings* brushSettings = settings->getToolSettings(currentTool)->getBrush();
base::SharedPtr<doc::Brush> brush = get_tool_loop_brush(brushSettings);
m_popupWindow = new BrushPopup(rc, brush.get());
m_popupWindow.setBounds(rc);
m_popupWindow.setBrush(brush.get());
Region rgn(m_popupWindow->getBounds().createUnion(getBounds()));
m_popupWindow->setHotRegion(rgn);
Region rgn(m_popupWindow.getBounds().createUnion(getBounds()));
m_popupWindow.setHotRegion(rgn);
m_popupWindow->openWindow();
m_popupWindow->BrushChange.connect(&BrushTypeField::onBrushTypeChange, this);
m_popupWindow.openWindow();
m_popupWindow.BrushChange.connect(&BrushTypeField::onBrushTypeChange, this);
}
void closePopup() {
if (m_popupWindow) {
m_popupWindow->closeWindow(NULL);
delete m_popupWindow;
m_popupWindow = nullptr;
}
m_popupWindow.closeWindow(NULL);
}
void onBrushTypeChange(Brush* brush) {
@ -168,7 +164,7 @@ private:
she::Surface* m_bitmap;
BrushType m_brushType;
BrushPopup* m_popupWindow;
BrushPopup m_popupWindow;
};
class ContextBar::BrushSizeField : public IntEntry