Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How to compare child in function virtual void ChildMouseEvent with ctrl’s value.
How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27586] Sat, 24 July 2010 15:37 Go to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Hi,

I am trying to compare the value of the “child” parameter of the above function, in order to compare it with a certain Ctrl. Let as say that we wont to do something ONLY when the mouse event has been triggered by a certain Ctrl. How can we “compare” child with the value of the control?. I have tried this:

void tercero::ChildMouseEvent(Ctrl* child, int event, Point p, int zdelta,dword keyflags)
{
	if(event==MOUSEMOVE){
		if(child==&gl_control){
......	



but it does not work. Shouldn’t it work, since I am comparing child with &gl_control?

Thanks,

Javier
Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27592 is a reply to message #27586] Sun, 25 July 2010 08:55 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Javier

The code does not seem intrinsically wrong. However I would include a test case to know if really child and glCtrl are the controls you want to compare.


Best regards
Iñaki
Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27601 is a reply to message #27592] Sun, 25 July 2010 13:53 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Fine, how to do it?

Thanks,

javier
Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27605 is a reply to message #27601] Sun, 25 July 2010 17:21 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Just copy a simplified version of your package in a compressed file and enclose it in a Forum message.

Best regards
Iñaki
Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27607 is a reply to message #27605] Sun, 25 July 2010 17:52 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Here it goes. The function in question belongs to “main.cpp”. The target is to determine whether “child” is “gl” (this is the OpenGL object), and therefore to be able to rule out/accept some further actions (for instance, to show cursor’s coordinates ONLY when mouse hovers over gl, etc..).

Thanks. Cheers.

Javier
Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27615 is a reply to message #27607] Mon, 26 July 2010 09:33 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Javier

After doing some small changes (installing glew and adding its includes) the sample works, but I cannot find the gl_control variable or any comparison like this:

child==&gl_control


Best regards
Iñaki
Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27617 is a reply to message #27586] Mon, 26 July 2010 11:05 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I haven't run your test case (you really should post test-cases that don't require any external headers/libs if you want people to try them) but I think I can see the problem.

The GLCtrl contains a child Ctrl (GLPane) that is the actual native window that the OpenGL context is attached to. It is this Ctrl that recieves the MouseEvents. It then passes them up to the GLCtrl to seem as if the GLCtrl recieved them but this results in ChildMouseEvent not being called for the GLCtrl's parent.

Some solutions:
- Don't use ChildMouseEvent. I tend to do my rendering in a GLCtrl derived class that can handle mouse events and camera stuff internally.

- This is a bit of a hack, and the least preferrale option, but changing the test to ctrl->GetParent() == &gl_control would work.

- Fix the bug in GLCtrl:
Image GLCtrl::GLPane::MouseEvent(int event, Point p, int zdelta, dword keyflags)
{
	p = p - GetScreenView().TopLeft() + ctrl->GetScreenView().TopLeft();
	// Make sure we send ChildMouseEvent
	if (ctrl->GetParent())
		ctrl->GetParent()->ChildMouseEvent(ctrl, event, p, zdelta, keyflags);
	return ctrl->MouseEvent(event, p, zdelta, keyflags);
}
(GLCtrl.cpp)

- Remove the need for the hacked mouse handling completely - this is the way it should be done IMO. Remove the MouseEvent function from GLCtrl::GLPane and add an IngoreMouse call in it's constructor:
GLPane() : WindowContext(NULL) { NoWantFocus(); IgnoreMouse(); }
(Note that the changes need to be made to both the X11 and Win32 versions of GLPane)

[Updated on: Mon, 26 July 2010 11:11]

Report message to a moderator

Re: How to compare child in function virtual void ChildMouseEvent with ctrl’s value. [message #27622 is a reply to message #27617] Mon, 26 July 2010 17:02 Go to previous message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Thanks. This:
ctrl->GetParent() == &gl_control

works fine.


Javier.
Previous Topic: Usage of images in different .h and .cpp files
Next Topic: Drag of mouse while left button is pressed.
Goto Forum:
  


Current Time: Wed Apr 24 23:20:56 CEST 2024

Total time taken to generate the page: 2.93210 seconds