朱奇 - 制作一个新窗口

JUCE - Making a New Window

本文关键字:一个 窗口 新窗口 朱奇      更新时间:2023-10-16

来自Juce中的Visual Wysywyg编辑器制作单页应用程序,我在弄清楚如何调用新窗口(在GUI窗口之外(时遇到了一些麻烦。我制作了一个测试应用程序,该应用程序与视觉编辑器创建了一个小的最小主要GUI。它有一个按钮"制作新窗口"。我的目标是能够单击该按钮并弹出一个新窗口,并且这个新窗口是Juce的" GUI组件"(又称图形/视觉GUI编辑器文件(。现在,我实际上已经有某种实现了这一目标,但是它的投掷错误和断言,因此获得一个非常简单,逐步的教程将是很棒的。

我研究了Projucer自动创建的Main.CPP文件,以了解它们如何创建窗口。这是我所做的。

1(在我的项目中,我添加了一个新的GUI组件(成为一类(,并将其称为" InvokeDwindow"。2(在我的主要GUI组件类标题中,我添加了一个新的scopep Pointer类型InvokedWindow:ScopedPointer<InvokedWindow> invokedWindow;3(我在主GUI编辑器中创建了一个新按钮,称为" Make New Window",并将其添加到处理程序代码中: newWindowPtr = new InvokedWindow;,以便每当按下按钮时,都会创建一个新的InvokedWindow对象。4(在自动生成的代码的基础上,在构造函数中,我添加了:

setUsingNativeTitleBar (true);
setCentrePosition(400, 400);
setVisible (true);
setResizable(false, false);

我是从朱奇应用程序的主文件中获得的。

我还向此新窗口添加了一个滑块,只是为了添加功能。

5(我添加了一个超载功能,让我关闭窗口:

void InvokedWindow::closeButtonPressed()
{
    delete this;
}

所以,现在我运行应用程序并单击"制造新窗口"按钮时,确实会弹出一个新窗口,但是我得到了一个主张:

/* Agh! You shouldn't add components directly to a ResizableWindow - this class
   manages its child components automatically, and if you add your own it'll cause
   trouble. Instead, use setContentComponent() to give it a component which
   will be automatically resized and kept in the right place - then you can add
   subcomponents to the content comp. See the notes for the ResizableWindow class
   for more info.
   If you really know what you're doing and want to avoid this assertion, just call
   Component::addAndMakeVisible directly.
*/

另外,我能够关闭窗口一次,然后点击主GUI中的按钮以创建NewWindow的另一个实例,但是第二次将其关闭会导致错误:

template <typename ObjectType>
struct ContainerDeletePolicy
{
    static void destroy (ObjectType* object)
    {
        // If the line below triggers a compiler error, it means that you are using
        // an incomplete type for ObjectType (for example, a type that is declared
        // but not defined). This is a problem because then the following delete is
        // undefined behaviour. The purpose of the sizeof is to capture this situation.
        // If this was caused by a ScopedPointer to a forward-declared type, move the
        // implementation of all methods trying to use the ScopedPointer (e.g. the destructor
        // of the class owning it) into cpp files where they can see to the definition
        // of ObjectType. This should fix the error.
        ignoreUnused (sizeof (ObjectType));
        delete object;
    }
};

这一切都在我的头上。我认为可以通过按钮创建一个新窗口还算不错。我可以使用图形GUI编辑器进行编辑的新窗口,但是我无法通过我的尝试来完全弄清楚它们。谁能以正确的方式发布分步指南?我确实在Juce论坛上发布了此信息,但是由于缺乏GUI编程,我无法理解发布的解决方案(我自己的错(,因此我希望能为此获得非常简单的指南。将不胜感激。谢谢。

我弄清楚了。我需要创建:

  1. 一个新的GUI组件(请记住,这是Juce中的视觉编辑器(
  2. 一个类(我将其称为基于朱奇演示代码的基本窗(,该类充当运行此新窗口并保留GUI组件的外壳。
  3. 每当单击按钮并将属性设置为该窗口时,它将制造一个新的基本风格的新对象。

这是我的代码:

参考第3行(在按钮的处理程序部分内部创建新窗口:

basicWindow = new BasicWindow("Information", Colours::grey, DocumentWindow::allButtons);
basicWindow->setUsingNativeTitleBar(true);
basicWindow->setContentOwned(new InformationComponent(), true);// InformationComponent is my GUI editor component (the visual editor of JUCE)
basicWindow->centreWithSize(basicWindow->getWidth(), basicWindow->getHeight());
basicWindow->setVisible(true);

参考第2行(一个.cpp文件,该文件定义了基本风情是:

#include "../JuceLibraryCode/JuceHeader.h"
class BasicWindow : public DocumentWindow
{
private:
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BasicWindow)
public:
    BasicWindow (const String& name, Colour backgroundColour, int buttonsNeeded)
    : DocumentWindow (name, backgroundColour, buttonsNeeded)
    {
    }
    void closeButtonPressed() override
    {
        delete this;
    }
};

并参考第1行1(制作GUI编辑器组件,这很容易做到。您恰好在Juce文件管理器中添加一个新文件。"添加新的GUI组件",然后视觉上添加所有元素和处理程序代码。

我最大的问题是我正在使用Juce ScopedPointer,因此删除对象后,指向其指向其的指针并没有被设置回NULL。SafePointer这样做。如果需要更多的解释,我很乐意提供帮助,因为这对没有太多GUI开发的人"在他的陪伴下"是可怕的。