JUCE - creating a new window

Based on the creation of single-page applications with the WYSISWYG visual editor in JUCE, itโ€™s a little difficult for me to understand how to call new windows (outside the main window of the graphical user interface). I made a test application that has a small minimal basic GUI that I created using a visual editor. He has a button "Create a new window." My goal is to be able to click this button and open a new window, and that this new window is a component of the GUI JUCE (AKA, graphical / visual graphical editor). Now I really achieved this, however, throwing errors and statements, so it would be great to get a very simple step-by-step tutorial.

I studied the main.cpp file that Projucer automatically created to understand how they create the window. Here is what I did.

1) In my project, I added a new GUI component (which becomes a class) and named it "InvokedWindow". 2) In my main GUI component header, I added a new copied pointer of type InvokedWindow: ScopedPointer<InvokedWindow> invokedWindow; 3) I created a new button in the main graphics editor called "Make a new window" and added this to the handler code: newWindowPtr = new InvokedWindow; so that each time a button is pressed, a new object of type InvokedWindow is created. 4) In the InvokedWindow class, in the constructor, on top of the automatically generated code, I added:

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

What kind I got from the main JUCE application file.

I also added a slider to this new window to add functionality to it.

5) I added an overloaded function to close the window:

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

So, now when I launch the application and click the "Create New" button, a new window appears, but I get the statement:

 /* 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. */ 

In addition, I can close the window once and click on the button in the main GUI to create another instance of newWindow, but when I close it a second time, it results in an error:

 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 (eg 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; } }; 

It's all a little over my head. I realized that it would not be so bad to create a new window using the button. A new window that I could edit using a graphical graphics editor, but I can not fully figure it out on my own, I tried. Can someone post a walkthrough to do it right? I posted this on the JUCE forums, but due to the lack of a GUI, I was not able to figure out the solutions that were submitted (my own mistake), so I hope to get a very simple guide on this. That would be very appreciated. Thanks.

+5
source share
1 answer

I get it. I needed to create:

  • New GUI component (remember this is a visual editor in JUCE)
  • A class (I named it BasicWindow based on the JUCE demo code) that acts as a wrapper to launch this new window and contains a GUI component.
  • JUCE SafePointer, which creates a new object of type BasicWindow whenever a button is clicked, and sets the attributes to this window.

Here is my code:

Referring to line 3) Inside the button handler section, to create a new window:

 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); 

Referring to line 2) .cpp a file that defines what BasicWindow is:

 #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; } }; 

And referring to line 1) Make a GUI editor component, which is easy to do. You just added a new file to the JUCE file manager. โ€œAdd a new GUI componentโ€, then visually add all your elements and handler code.

My biggest problem was that I used JUCE ScopedPointer, so after deleting the object, the pointer pointing to it did not return to NULL. SafePointer does this. If you need more explanation, I will be happy to help, as it was terrible for someone who did not have much development of the GUI "under his belt."

+1
source

All Articles