我最近開始使用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