我最近开始使用Juce library。我通常会在论坛上发布Juce相关问题,但是我很多时候都在为一些问题烦恼,而我仍然没有得到答案。所以即使看起来Juce的用户并不多,stackoveflow也值得一试。在Juce库中的FileBrowserComponent上拦截鼠标事件
这里的问题:
我正在做一些实验用JUCE的组件。 我有以下类:
class MyComponent : public Component{
public :
MyComponent(Component * comp){
this->child = comp;
comp->setInterceptsMouseClicks(false, false);
}
void mouseDown (const MouseEvent &e){
//do stuff
Component *target = getTopChild(this->child, e.x, e.y); //return top most component of child that would have intercept the mouse event if that wasn't intercepted by MyComponent class
if (target != NULL && doIWantToForwardEventToTarget()){
MouseEvent newEvent = e.getEventRelativeTo(target);
target->mouseDown(newEvent);
}
}
void mouseMove (const MouseEvent &e);
void mouseEnter (const MouseEvent &e);
void mouseExit (const MouseEvent &e);
void mouseDrag (const MouseEvent &e);
void mouseUp (const MouseEvent &e);
void mouseDoubleClick (const MouseEvent &e);
void mouseWheelMove (const MouseEvent &e, float wheelIncrementX, float wheelIncrementY);
private:
Component *child;
}
这个类的目的是:
商店 层次组件(子)
拦截所有的鼠标事件的单个组件相关 给孩子或其中的一个子孙
- 做点事
- 的MouseEvent最终转发到 它是针对 到
我想这个类的滑块组件的孩子,甚至是嵌套在其它组件内的组件..一切工作正常。 现在我正在用FileBrowserComponent做一些实验,看起来不能正常工作。例如,当我点击按钮移动到上面的目录时,它不会(按钮接收鼠标事件并且它被点击,但树视图中没有任何事情发生)。 也从列表中选择项目不起作用。
可能是什么问题? (我做了一些实验,似乎没有调用FileBrowserComponent中的buttonClicked方法,但我不知道为什么) 任何建议?
我还试图修改代码是这样的:
void mouseDown (const MouseEvent &e){
//do stuff
Component *target = getTopChild(this->child, e.x, e.y); //return top most component of child that would have intercept the mouse event if that wasn't intercepted by MyComponent class
if (target != NULL && doIWantToForwardEventToTarget()){
target->setInterceptsMouseClicks(true, true);
MouseEvent newEvent = e.getEventRelativeTo(target);
target->mouseDown(newEvent);
target->setInterceptsMouseClicks(false, false);
}
}
它仍然无法正常工作。无论如何,我发现如果我评论第二次调用setInterceptMouseClicks(我禁用鼠标点击后)使事情工作(即使这不是我想要获得的结果,因为我需要可重新分配的鼠标事件零件)。
这些事实可以使我2点的考虑:
- 的组件需要截取鼠标即使鼠标事件 手工传递给它的鼠标按下 方法(这是真的,我没有那么 点击? 肯定没有)
- 鼠标事件 FileBrowserComponent处理后还有其他 类使用的 信息的拦截鼠标点击状态, 否则如果在 target-> mouseDown(newEvent)后,我会 再次禁用鼠标点击。任何 的想法?
在此先感谢
我正面临同样的问题。你设法解决它吗? – Dinaiz 2011-06-27 03:00:16
不..我仍然没有答案,也没有解决方案.. – Heisenbug 2011-06-27 10:33:42