|
|
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 |
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 #27617 is a reply to message #27586] |
Mon, 26 July 2010 11:05 |
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
|
|
|
|
Goto Forum:
Current Time: Wed Apr 24 23:20:56 CEST 2024
Total time taken to generate the page: 2.93210 seconds
|
|
|