2011-02-25 76 views
1

我正在製作一個Gui,其中的小部件有孩子,孩子們都在剪切測試中,並在父母的矩形中進行渲染。但它並不總是這樣。小部件可以選擇不剪切其子項。在這種情況下,孩子被綁定到父母的父矩形。我的渲染目前反映了這一點,但我的命中測試沒有。幫助點擊測試功能

這裏是我的命中測試:

AguiWidget* AguiEventManager::GetWidgetUnderMouse(AguiWidget* root, 
              const AguiMouseEventArgs &mouse) 
{ 
    /* sets the current node to the root node 
    while a widget passes the hit test 
    and the current node has children, 
    iterate through the current node's 
    children and set the current node 
    to the child who passes the hit test */ 

    AguiWidget* currentNode = root; 

     bool foundsomething = true; 
     while(foundsomething) 
     { 
      foundsomething = false; 
      if(currentNode->getChildWidgetCount() > 0) 
      for (std::vector<AguiWidget*>::const_reverse_iterator rit = 
       currentNode->getChildRBeginIterator(); 
       rit < currentNode->getChildREndIterator(); ++rit) 
      { 
       if (((*rit)->intersectionWithPoint(mouse.getPosition()) 
        ) 
        && (*rit)->isEnabled() && (*rit)->isVisible()) 
       { 
        foundsomething = true; 
        currentNode = *rit; 
        break; 
       } 

      } 

     } 
     return currentNode; 


} 

我怎麼能修改此處理(* RIT) - > isClippingChildren(); ?

現在基本上,它所做的就是找到第一個通過命中測試的小部件,然後通過它的子項進行挖掘,因爲只有它們才符合條件。它會繼續這樣做,直到沒有更多的孩子可以挖掘,因此找到的最後一個小部件是正確的。這需要更改如下:

如果小部件沒有剪裁它的子元素,那麼如果它的父元素通過了測試,我們檢查那些不剪裁它的子元素的子元素。如果他們都沒有通過命中測試,那麼我們需要回去繼續我們的工作。

我有一種感覺某種類型的隊列可能有用,但我不知道如何。

修改的基本結果是,它將與上述使用相同算法的結果相同,除非小部件未裁剪其子項,我們只是讓其子項作爲父項的子項進行處理。

感謝

回答

1

給你一個AguiWidget則hitTest,並讓它遞歸到它的孩子正時。 然後,當點擊一個剪輯區域時,父(剪裁)小部件的gitTest將失敗,並且將不會執行剪裁的小部件的命中測試。