Resizing and drop shadows


#1

It appears I have run into a bug in either OS X or Juce with resizing partially transparent windows with drop shadows. We have a window with rounded corners implemented as a non-opaque window that we slap a .png onto. With the click of a button, the window will grow in size downward. The problem is that when it is done growing, there are little “tails” showing at the bottom corners where there should be nothing.

To figure out what is going on I created another much simpler program. In this case I created an application composed of a single transparent window with a single button. Clicking the button resizes the window, growing it by one row of pixels. I add the window to the desktop with drop shadows enabled. What you see on the desktop is the single button with a drop shadow around it. Now click the button and what you see is the new row of pixels with a grey border around it when you should see nothing because the window is transparent.

It appears that what happens is that when the window is resized, a new row of opaque pixels is added, then the Mac draws a drop shadow around the new row, then the row is switched to transparent, but remnants of the drop shadow remain.

I can post code if desired, but the program is really really simple.

Help?

Greg


#2

If you could post some code that I could run, that’d be helpful…


#3

Here you go. I whittled it down to the bare minimum. I am running OSX 10.5.7 if that matters.

#include <juce/juce.h>

class MainWindow: public Component, public ButtonListener
{
public:
MainWindow()
{
m_testButton = new TextButton(“Grow”);
m_testButton->setSize(100, 30);
m_testButton->setTopLeftPosition(40, 10);
this->addAndMakeVisible(m_testButton);
m_testButton->addButtonListener(this);

    this->setOpaque(false);
    this->addToDesktop(ComponentPeer::windowHasDropShadow);
    this->centreWithSize(500, 200);
    this->setVisible(true);
}

~MainWindow()
{
    this->deleteAllChildren();
}

private:
TextButton *m_testButton;

void buttonClicked(Button *button_clicked)
{
    if (button_clicked == m_testButton) 
    {
        this->setSize(getWidth(), getHeight() >= 300 ? getHeight() - 1 : getHeight() + 1);
    }
}

};

struct TestApp: public JUCEApplication
{
public:

TestApp() {  }

void initialise(const String& commandLine) {
    m_window = new MainWindow();
}

void shutdown(void) {
    delete m_window;
}

const String getApplicationName() {
    return T("Test");
}

private:

MainWindow *m_window;

};

START_JUCE_APPLICATION (TestApp)


#4

Ok, that’s interesting, I think it’s because needs to tell the OS to refresh its shadow. Try this in juce_mac_NSViewComponentPeer.mm:

[code]- (void) drawRect: (NSRect) r
{
if (owner != 0)
{
owner->drawRect ®;

    if (! (owner->isSharedWindow || owner->isOpaque()))
        [[self window] invalidateShadow];
}

}
[/code]


#5

I can’t find that file, where is it?


#6

build/mac/platform_specific


#7

These are the files I see in mac/platform_specific_code

juce_mac_AudioCDBurner.mm
juce_mac_CoreAudio.cpp
juce_mac_CoreMidi.cpp
juce_mac_FileChooser.cpp
juce_mac_Files.cpp
juce_mac_Fonts.cpp
juce_mac_HTTPStream.h
juce_mac_Messaging.cpp
juce_mac_NamedPipe.cpp
juce_mac_Network.mm
juce_mac_SystemStats.mm
juce_mac_Threads.cpp
juce_mac_WebBrowserComponent.mm
juce_mac_Windowing.cpp
juce_posix_SharedCode.cpp

There is a HiViewComponentPeer in juce_mac_windowing.cpp, but I don’t see a drawRect.


#8

I’m talking about the latest code, not the v1.46 files…


#9

Got it, I’ll let you know how it goes.


#10

Switching from 1.46 to the latest build from Subversion fixed the problem. I did not have to add your suggested change, just switching to the latest code fixed it.

Thanks a bunch.

Greg