JUCE 自定义窗口类

定义SettingsWindow

class SettingsWindow :public DocumentWindow

{

public:

/**

    构造函数

    @param name 窗口的title

    @param backgroundColour 窗口的背景色

    @param buttonsNeeded 标题栏显示的按钮 DocumentWindow::closeButton

    enum TitleBarButtons

    {

    minimiseButton = 1,

    maximiseButton = 2,

    closeButton = 4,

    allButtons = 7

    };

    @return 无

    */

    SettingsWindow (const String& name,Colour backgroundColour,int buttonsNeeded )

    :DocumentWindow(name, backgroundColour, buttonsNeeded)

    {

      setContentOwned (&setting, false);

    }

    ~SettingsWindow()

    {

    }

    void closeButtonPressed()override

    {

        delete this;

    }

private:

    SettingView setting;//具体内容Component

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsWindow)

};

加载显示窗口

void showSetWindow()

{

    auto* dw = new SettingsWindow(TRANS(" Settings"), Colour(40,43,47), DocumentWindow::closeButton);

    //closeBtn 自定义

    dw->setLookAndFeel(&look);

    //窗口大小

    Rectangle area (0,0,660,440);

    RectanglePlacement placement ( RectanglePlacement::xMid

                                  |RectanglePlacement::yMid

                                  |RectanglePlacement::doNotResize);

    autoresult = placement.appliedTo(area,Desktop::getInstance().getDisplays()

                                      .getMainDisplay().userArea);

    dw->setBounds(result);

    dw->setResizable(false,false);

    dw->setUsingNativeTitleBar (false);

    dw->setTitleBarTextCentred(false);

    dw->setTitleBarHeight(47);//title Bar 高度

    dw->runModalLoop();

}

你可能感兴趣的:(JUCE 自定义窗口类)