Main window does not repaint when second window is displayed

i have a main window and i created another one . I display it when a certain button is pressed on the main window. It works but the problem is that it does not repaint the main window when the second one is being displayed. When i click on second one and try to move it - I think it calls resized() at that point- it starts painting the main window. I have some LED animations on main window. So it is really annoyying to see that main window stops painting . Why don’t they work at the same time ? Is there a parameter that i should set to make them work at the same time ?

i don’t know. But perhaps your LEDs should be separate child components, that also inherits a Timer at the rate you want them to display. The timer callback will should then call repaint(). Juce will then update them when it can.

1 Like

Yes, I created a LED component, that refresh 30 images in a time period according to value of a knob. I use a timer in that component.I only have a method that gets the knob value in it. Without second window everything works perfectly but when the second one is opened main window freezes. And it is not only the LEDs. Everything freezes including some other indification images.

I only open another window as a ‘DocumentWindow’ component for my user registration input. And everything works OK for that. Perhaps someone else will know what’s wrong, if you can post some code? Does it come back to life when it’s in keyboard focus?

1 Like

I tried to follow the steps in window demo.

VersionWindowShell.h

#pragma once

 #include "../JuceLibraryCode/JuceHeader.h"
 #include "VersionWindowGui.h"
 //========================================
class VersionWindowShell    :public DocumentWindow
{
public:
VersionWindowShell(const String& name, Colour backgroundColour, int buttonsNeeded);
~VersionWindowShell();

void paint (Graphics&) override;
void resized() override;
//==========================================

void closeButtonPressed() override;

	
int creationCounter = 0;

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VersionWindowShell)
};

VersionWindowShell.cpp

#include "../JuceLibraryCode/JuceHeader.h"
#include "VersionWindowShell.h"

  //==============================
  VersionWindowShell::VersionWindowShell(const String& name, Colour backgroundColour, int buttonsNeeded):  DocumentWindow(name, backgroundColour, buttonsNeeded)
{
// In your constructor, you should add any child components, and
// initialise any special settings that your component needs.
setSize(400, 300);

setVisible(true);
creationCounter++;
 }

 VersionWindowShell::~VersionWindowShell()
{
 }

  void VersionWindowShell::paint (Graphics& g)
   {
      setAlpha(1);
   }

      void VersionWindowShell::resized()
   {
         // This method is where you should set the bounds of any child
        // components that your component contains..


    }

  void VersionWindowShell::closeButtonPressed()
  {
     delete this;

 }

VersionWindowGui.h

 #pragma once

    //[Headers]     -- You can add your own extra header files here --
   #include "../JuceLibraryCode/JuceHeader.h"

   //[/Headers]



     //================================
     /**
                                                                            //[Comments]
An auto-generated component, created by the Projucer.

Describe your class and how it works here!
//[/Comments]
  */
    class VersionWindowGui  : public Component,
                      public HyperlinkButton::Listener
   {
  public:
           //===============================
VersionWindowGui ();
~VersionWindowGui();

      //================================
//[UserMethods]     -- You can add your own custom methods in this section.
//[/UserMethods]

void paint (Graphics& g) override;
void resized() override;

/** Called when the button is clicked. */
void buttonClicked(Button*) override;
HyperlinkButton hyperlink;


       // HyperlinkButton hyperlinkbutton;
       private:
//[UserVariables]   -- You can add your own custom variables in this section.
//[/UserVariables]

//==============================================================================


//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VersionWindowGui)
   };

   //[EndFile] You can add extra defines here...
   //[/EndFile]

VersionWindowGui…cpp

   //[Headers] You can add your own extra header files here...
  //[/Headers]

 #include "VersionWindowGui.h"


    //[MiscUserDefs] You can add your own user definitions and misc code here...
   //[/MiscUserDefs]

   //============================================================
    VersionWindowGui::VersionWindowGui ()
   {
//[Constructor_pre] You can add your own custom stuff here..
//[/Constructor_pre]


//[UserPreSize]
//[/UserPreSize]

hyperlink.setButtonText("www.mywebsite.com");

hyperlink.setURL({ "https://www.mywebsite.com/" });
addAndMakeVisible(hyperlink);
setSize (400,300);


//[Constructor] You can add your own custom stuff here..
//[/Constructor]
 }

    VersionWindowGui::~VersionWindowGui()
      { 
//[Destructor_pre]. You can add your own custom destruction code here..
//[/Destructor_pre]



//[Destructor]. You can add your own custom destruction code here..
//[/Destructor]
 }

 //==============================================================
void VersionWindowGui::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here..
//[/UserPrePaint]



// g.fillAll (Colour (0xff323e44));
g.fillAll(Colours::black);
g.setOpacity(1);

DBG("VersionWindowGui has been displayed!!!");

Font font("Cooper Std","Regular",16.0f);

g.setFont(font);

g.setColour(Colours::white);
g.drawFittedText("My plugin \n Version 1.0 ",getLocalBounds(), Justification::centred,2,1);
hyperlink.setFont(font,Justification::bottom);
// hyperlink.getLookAndFeel().setColour(1,Colours::antiquewhite);


//[UserPaint] Add your own custom painting code here..
//[/UserPaint]

       }


void VersionWindowGui::buttonClicked(Button*)
  {

  }

    void VersionWindowGui::resized()
  {
//[UserPreResize] Add your own custom resize code here..
//[/UserPreResize]
hyperlink.setBounds(0, 0, 150, 20);
Point<int> hyperCentrePoint(200, 250);
hyperlink.setCentrePosition(hyperCentrePoint);
setBounds(getLocalBounds());
//[UserResized] Add your own custom resize handling here..
//[/UserResized]


   }



     //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  //[/MiscUserCode]


   //============================================================
  #if 0
  /*  -- Projucer information section --

This is where the Projucer stores the metadata that describe this GUI layout, so
make changes in here at your peril!

   BEGIN_JUCER_METADATA

     <JUCER_COMPONENT documentType="Component" className="VersionWindowGui" componentName=""
             parentClasses="public Component" constructorParams="" variableInitialisers=""
             snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
             fixedSize="0" initialWidth="600" initialHeight="400">
     <BACKGROUND backgroundColour="ff323e44"/>
  </JUCER_COMPONENT>
            END_JUCER_METADATA
 */
 #endif


   //[EndFile] You can add extra defines here...
  //[/EndFile]

and in my main window buttonpressed method:

     if (versionWindowShell!=nullptr) { versionWindowShell->closeButtonPressed(); }
			
			 

			 versionWindowShell = new VersionWindowShell("About", Colours::grey, DocumentWindow::allButtons);

				versionWindowShell->setUsingNativeTitleBar(true);
				versionWindowShell->setContentOwned(new VersionWindowGui(), true);
				


				//Rectangle<int> area(0, 0, Component::getParentWidth() / 2, Component::getParentHeight() / 2); 
				Rectangle<int> area(0, 0, 400, 300); 

				RectanglePlacement placement(RectanglePlacement::xMid
					| RectanglePlacement::yMid
					| RectanglePlacement::doNotResize);


				//auto result = placement.appliedTo(area,Component::getParentComponent()->getBounds());


				auto result = placement.appliedTo(area, Desktop::getInstance().getDisplays().getMainDisplay().userArea);
				versionWindowShell->setBounds(result); // this works . it is for arranging the screen according to display sizes


				//versionWindowShell->setBounds(Component::getParentComponent()->getBounds());

				versionWindowShell->setVisible(true);
				//versionWindowShell->launchAsync();
				
				//versionWindowShell->setFullScreen(true);

			//===================================================//

The only differences I can see is that I use a static function to create my window:

Component *makeRegWindowContent(Registration &reg) { return new RegWindowContentComponent(reg); }

Which I call in my DocumentWindow constructor:

	setUsingNativeTitleBar(true);
	setContentOwned(makeRegWindowContent(reg), true);
	centreWithSize(getWidth(), getHeight());
	setVisible(true);
	setAlwaysOnTop(true);
1 Like

Then I will try to do the same :slight_smile: maybe it is because of that. Thank you

Have you looked at the ‘WindowsDemo’ in the examples?

yes, that’s how i did mine actually :confused:

And that works OK for you once the dialogue box is quit?

Everything works but when i create the window, it pops up on my main window perfectly. You can test my code. But when it is displayed the main window stops repainting in the background. When i click on the window and try to move it by dragging it to left,right, up or down, the main window starts calling paint method again. So it starts performing my LED animation.

Problem solved. It was because of this line

1 Like