diff --git a/src/app/ui/brush_popup.cpp b/src/app/ui/brush_popup.cpp index 9a43be5dc..2e278ef86 100644 --- a/src/app/ui/brush_popup.cpp +++ b/src/app/ui/brush_popup.cpp @@ -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(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()); } diff --git a/src/app/ui/brush_popup.h b/src/app/ui/brush_popup.h index 33ca51487..d01ad1081 100644 --- a/src/app/ui/brush_popup.h +++ b/src/app/ui/brush_popup.h @@ -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 BrushChange; diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index ee255eebd..8fab79f97 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -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 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