Right Click in OpenGl Component


#1

Add this to line 143 of the OpenGLDemo.cpp in (DemoOpenGLCanvas)

void mouseDown (const MouseEvent&e)
{
DBG(L"MouseDown");
if (e.mods.isPopupMenu())
DBG(L"Right mouse Click");
}

I can’t get any right clicks to be called. Odd huh?


#2

Baffling and bizarre!

The GL comp isn’t letting the right clicks get through… Middle clicks seem to work ok (!)

No idea why or how we could work around it though!


#3

Yea, its weird alright, i tried adding rightMouseDown events to the NSOpenglView class…no luck… oh well no biggie.

BTW: shouldn’t [renderContext setView:nil] be [renderContext clearDrawable]?

~WindowedGLContext()
    {
        makeInactive();
        //[renderContext setView: nil]; // invalid drawable spat out
	[renderContext clearDrawable];
        delete viewHolder;
    }

#4

I’d expect setView: nil to do the same job, but you’re probably right that if they’ve provided a special method to do that, it’s best to use it!


#5

Maybe it should even be [view clearGLContext]; it’s does not seem clear what to call exactly in what order.

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOpenGLView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSOpenGLView/clearGLContext[/url]


#6

They probably all do the same thing internally. I’ll stick with clearDrawable for now, and just keep an eye out for problems.


#7

Hi,

For some reason a sub-NSView won’t forward right clicks to it’s parent.

I had to show a popup menu over a OpenGLComponent and came up with this quick n dirty solution…

in juce_mac_OpenGLComponent.mm I modified ThreadSafeNSOpenGLView by adding these functions:

- (void) rightMouseDown: (NSEvent*) ev
{
	if(ownerComponent)
	{
		unsigned int m = juce::ModifierKeys::rightButtonModifier;
		
		if (([ev modifierFlags] & NSShiftKeyMask) != 0)          m |= juce::ModifierKeys::shiftModifier;
		if (([ev modifierFlags] & NSControlKeyMask) != 0)        m |= juce::ModifierKeys::ctrlModifier;
		if (([ev modifierFlags] & NSAlternateKeyMask) != 0)      m |= juce::ModifierKeys::altModifier;
		if (([ev modifierFlags] & NSCommandKeyMask) != 0)        m |= juce::ModifierKeys::commandModifier;

		juce::ModifierKeys newMods(m);
		juce::MouseInputSource*  mouse = juce::Desktop::getInstance().getMouseSource (0);
		juce::Point <int> mp = getMousePos(ev,self);
		juce::MouseEvent mevent( *mouse,
							mp,
							newMods,
							ownerComponent,
							ownerComponent,
							Time(getMouseTime(ev)),
							mp,
							Time(getMouseTime(ev)),
							1,
							false );
							
		ownerComponent->mouseDown( mevent );

	}
}
	
- (void) rightMouseUp: (NSEvent*) ev
{
	if(ownerComponent)
	{
	
	/*
		MouseEvent::MouseEvent (MouseInputSource& source_,
							const Point<int>& position,
							const ModifierKeys& mods_,
							Component* const eventComponent_,
							Component* const originator,
							const Time& eventTime_,
							const Point<int> mouseDownPos_,
							const Time& mouseDownTime_,
							const int numberOfClicks_,
							const bool mouseWasDragged)
						*/
			
		unsigned int m = 0;
		if (([ev modifierFlags] & NSShiftKeyMask) != 0)          m |= juce::ModifierKeys::shiftModifier;
		if (([ev modifierFlags] & NSControlKeyMask) != 0)        m |= juce::ModifierKeys::ctrlModifier;
		if (([ev modifierFlags] & NSAlternateKeyMask) != 0)      m |= juce::ModifierKeys::altModifier;
		if (([ev modifierFlags] & NSCommandKeyMask) != 0)        m |= juce::ModifierKeys::commandModifier;

		juce::ModifierKeys newMods(m);
		juce::MouseInputSource*  mouse = juce::Desktop::getInstance().getMouseSource (0);
		juce::Point <int> mp = getMousePos(ev,self);
		juce::MouseEvent mevent( *mouse,
							mp,
							newMods,
							ownerComponent,
							ownerComponent,
							Time(getMouseTime(ev)),
							mp,
							Time(getMouseTime(ev)),
							1,
							false );
							
		ownerComponent->mouseUp( mevent );
	}
}

- (void) setOwnerComponent: (juce::Component*) comp;
{
	ownerComponent = comp;
}

and a member that is a pointer to the component that uses the view (ownerComponent).

I call [view setOwnerComponent:component]; in the constructor of WindowGLContext after the creation of the OpenGLView…

This skips all the juce mouse handling, so I have to call PopupMenu::dismissAllActiveMenus(); before creating the popup, or else i might get a new popup for every right click.

Did anyone find a better solution to this problem?

thanks

Daniel


#8

Ok… so this seems like a better solution,
just passing the events from ThreadSafeNSOpenGLView back to the super view like this

[code]- (void) rightMouseDown: (NSEvent*) ev
{
NSView * s = [self superview];
if( s!=nil )
{
[s rightMouseDown:ev];
}
}

  • (void) rightMouseUp: (NSEvent*) ev
    {
    NSView * s = [self superview];
    if( s!=nil )
    {
    [s rightMouseUp:ev];
    }
    }
    [/code]

#9