📄 wg__menu_8cpp-source.html
字号:
00488 SourceRect.h = static_cast<short int>(std::min(ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>(), <a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->h));00489 SDL_Rect DestRect;00490 DestRect.x = static_cast<short int>(ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>());00491 DestRect.y = static_cast<short int>((ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - <a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->h) / 2 < 0 ?00492 ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() : ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + (ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>() - <a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->h) / 2);00493 DestRect.w = static_cast<short int>(<a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->w);00494 DestRect.h = static_cast<short int>(std::min(ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>(), <a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->h));00495 SDL_BlitSurface(<a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>(), &SourceRect, <a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, &DestRect);00496 }00497 }00498 }00499 00500 <a name="l00501"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a9">00501</a> <span class="keywordtype">bool</span> CPopupMenu::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00502 {00503 <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00504 00505 <span class="keywordflow">if</span> (! CMenuBase::OnMouseButtonDown(Point, Button) && <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> && (<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(Point) == CRect::RELPOS_INSIDE))00506 {00507 <a class="code" href="classwGui_1_1CPopupMenu.html#b0">UpdateCachedRects</a>();00508 <span class="keywordflow">for</span> (t_MenuItemVector::iterator iter = <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin(); iter != <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.end(); ++iter)00509 {00510 <span class="keywordflow">if</span> (iter->second.second.HitTest(Point) == CRect::RELPOS_INSIDE && !iter->first.bSpacer)00511 {00512 <span class="keywordflow">if</span> (!iter->first.pPopup)00513 {00514 <a class="code" href="classwGui_1_1CMessageClient.html">CMessageClient</a>* pDestination = <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>;00515 <span class="keywordflow">if</span> (m_pParentMenu)00516 {00517 pDestination = <a class="code" href="classwGui_1_1CPopupMenu.html#n0">m_pParentMenu</a>;00518 }00519 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_LCLICK, pDestination, <span class="keyword">this</span>, iter->first.iItemId));00520 <a class="code" href="classwGui_1_1CPopupMenu.html#a4">HideAll</a>();00521 }00522 <span class="keywordflow">else</span>00523 {00524 <a class="code" href="classwGui_1_1CMenuBase.html#a5">HideActivePopup</a>();00525 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a> = iter->first.pPopup;00526 <a class="code" href="classwGui_1_1CPopupMenu.html#b1">ShowActivePopup</a>(iter->second.second, <a class="code" href="classwGui_1_1CWindow.html#a8">GetAncestor</a>(<a class="code" href="classwGui_1_1CWindow.html#s2s1">ROOT</a>)-><a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>());00527 }00528 <span class="keywordflow">break</span>;00529 }00530 }00531 bResult = <span class="keyword">true</span>;00532 }00533 00534 <span class="keywordflow">return</span> bResult;00535 }00536 00537 <a name="l00538"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a10">00538</a> <span class="keywordtype">bool</span> CPopupMenu::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00539 {00540 <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00541 00542 <span class="keywordflow">if</span> (pMessage)00543 {00544 <span class="keywordflow">switch</span>(pMessage-><a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00545 {00546 <span class="keywordflow">case</span> CMessage::MOUSE_BUTTONDOWN:00547 {00548 <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);00549 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> && pMouseMessage && (<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(pMouseMessage-><a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>) != CRect::RELPOS_INSIDE))00550 {00551 <span class="comment">// If the user clicked outside the window, we just want to hide the window,</span>00552 <span class="comment">// and then pass the message on (bHandled = false)</span>00553 <span class="comment">// But we only want the root popup to do this, and only if none of it's children were hit</span>00554 <span class="keywordflow">if</span> (!dynamic_cast<CPopupMenu*>(m_pParentWindow) && !<a class="code" href="classwGui_1_1CPopupMenu.html#a5">IsInsideChild</a>(pMouseMessage-><a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>) &&00555 !(<a class="code" href="classwGui_1_1CPopupMenu.html#n0">m_pParentMenu</a> && <a class="code" href="classwGui_1_1CPopupMenu.html#n0">m_pParentMenu</a>-><a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>().<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(pMouseMessage-><a class="code" href="classwGui_1_1CMouseMessage.html#m0">Point</a>) == CRect::RELPOS_INSIDE))00556 {00557 <a class="code" href="classwGui_1_1CPopupMenu.html#a4">HideAll</a>();00558 }00559 }00560 <span class="keywordflow">break</span>;00561 }00562 <span class="keywordflow">case</span> CMessage::CTRL_TIMER:00563 {00564 <span class="keywordflow">if</span> (pMessage-><a class="code" href="classwGui_1_1CMessage.html#a3">Destination</a>() == <span class="keyword">this</span>)00565 {00566 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ItemRect;00567 <span class="keywordflow">for</span> (t_MenuItemVector::iterator iter = <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin(); iter != <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.end(); ++iter)00568 {00569 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> == &(iter->first))00570 {00571 ItemRect = iter->second.second;00572 <span class="keywordflow">break</span>;00573 }00574 }00575 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> && <a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a>-><a class="code" href="structwGui_1_1SMenuItem.html#m2">pPopup</a>)00576 {00577 <a class="code" href="classwGui_1_1CMenuBase.html#a5">HideActivePopup</a>();00578 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a> = <a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a>-><a class="code" href="structwGui_1_1SMenuItem.html#m2">pPopup</a>;00579 <a class="code" href="classwGui_1_1CPopupMenu.html#b1">ShowActivePopup</a>(ItemRect, <a class="code" href="classwGui_1_1CWindow.html#a8">GetAncestor</a>(<a class="code" href="classwGui_1_1CWindow.html#s2s1">ROOT</a>)-><a class="code" href="classwGui_1_1CWindow.html#a5">GetClientRect</a>());00580 }00581 bHandled = <span class="keyword">true</span>;00582 }00583 <span class="keywordflow">break</span>;00584 }00585 <span class="keywordflow">default</span> :00586 bHandled = CMenuBase::HandleMessage(pMessage);00587 <span class="keywordflow">break</span>;00588 }00589 }00590 00591 <span class="keywordflow">return</span> bHandled;00592 }00593 00594 <a name="l00595"></a><a class="code" href="classwGui_1_1CPopupMenu.html#b0">00595</a> <span class="keywordtype">void</span> CPopupMenu::UpdateCachedRects(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00596 <span class="keyword"></span>{00597 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a>)00598 {00599 <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00600 SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00601 <span class="keywordtype">int</span> iHeight = 4;00602 <span class="keywordflow">for</span> (t_MenuItemVector::iterator iter = <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin(); iter != <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.end(); ++iter)00603 {00604 <span class="keywordflow">if</span> (iter->first.bSpacer)00605 {00606 <a class="code" href="classwGui_1_1CRect.html">CRect</a> TextRect(SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + 3, SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + iHeight, SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - 3, SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + iHeight + 1);00607 TextRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(2);00608 iter->second.second = TextRect;00609 iHeight += 6;00610 }00611 <span class="keywordflow">else</span>00612 {00613 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Dims;00614 iter->second.first.GetMetrics(&Dims, 0, 0);00615 <a class="code" href="classwGui_1_1CRect.html">CRect</a> TextRect(SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + 3, SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + iHeight, SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - 3, SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + iHeight + Dims.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>());00616 TextRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(2);00617 iter->second.second = TextRect;00618 iHeight += Dims.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>() + 5;00619 }00620 }00621 <a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a> = <span class="keyword">true</span>;00622 }00623 }00624 00625 <a name="l00626"></a><a class="code" href="classwGui_1_1CPopupMenu.html#b1">00626</a> <span class="keywordtype">void</span> CPopupMenu::ShowActivePopup(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>& ParentRect, <span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>& BoundingRect)00627 {00628 <span class="comment">// TODO: Add bounds checking for all edges. Apply this same bounds checking logic to the popup root menu too.</span>00629 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>)00630 {00631 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CPopupMenu::ShowActivePopup() : Trying to show active popup menu when pActivePopup is NULL!"</span>));00632 }00633 <a class="code" href="classwGui_1_1CRect.html">CRect</a> MenuRect = <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CWindow.html#a3">GetWindowRect</a>();00634 <span class="keywordflow">if</span> (BoundingRect.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(ParentRect.<a class="code" href="classwGui_1_1CRect.html#a14">TopRight</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(5, 0) + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(MenuRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>(), 0)) & CRect::RELPOS_RIGHT)00635 {00636 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CPopupMenu.html#a2">Show</a>(ParentRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>() - <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(MenuRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() + 5, 0));00637 }00638 <span class="keywordflow">else</span>00639 {00640 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CPopupMenu.html#a2">Show</a>(ParentRect.<a class="code" href="classwGui_1_1CRect.html#a14">TopRight</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(5, 0));00641 }00642 }00643 00644 }</pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:23 2003 for wGui by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -