📄 wg__menu_8cpp-source.html
字号:
00323 iter->second.second = TextRect;00324 iWidth += 9;00325 }00326 <span class="keywordflow">else</span>00327 {00328 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Dims;00329 iter->second.first.GetMetrics(&Dims, 0, 0);00330 <a class="code" href="classwGui_1_1CRect.html">CRect</a> TextRect(SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + iWidth, SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + 2, SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + iWidth + Dims.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>() - 2);00331 TextRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(2);00332 iter->second.second = TextRect;00333 iWidth += Dims.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + 8;00334 }00335 }00336 <a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a> = <span class="keyword">true</span>;00337 }00338 }00339 00340 <a name="l00341"></a><a class="code" href="classwGui_1_1CMenu.html#b1">00341</a> <span class="keywordtype">void</span> CMenu::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)00342 {00343 <span class="comment">// TODO: Add bounds checking for all edges. Apply this same bounds checking logic to the popup root menu too.</span>00344 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>)00345 {00346 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CMenu::ShowActivePopup() : Trying to show active popup menu when pActivePopup is NULL!"</span>));00347 }00348 <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>();00349 <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#a15">BottomLeft</a>() + <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)00350 {00351 <span class="keywordtype">int</span> xDelta = BoundingRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - ParentRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + MenuRect.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>();00352 <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#a15">BottomLeft</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(xDelta, 0)) & CRect::RELPOS_LEFT))00353 {00354 <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#a15">BottomLeft</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(xDelta, 5));00355 }00356 }00357 <span class="keywordflow">else</span>00358 {00359 <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#a15">BottomLeft</a>() + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(0, 5));00360 }00361 <span class="comment">// Pop the popup to the top of the draw order and everything</span>00362 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CWindow.html#a24">SetNewParent</a>(<a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CWindow.html#a8">GetAncestor</a>(<a class="code" href="classwGui_1_1CWindow.html#s2s0">PARENT</a>));00363 }00364 00365 00366 <span class="comment">// CPopupMenu</span>00367 <a name="l00368"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a0">00368</a> CPopupMenu::CPopupMenu(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CRect.html">CRect</a>& WindowRect, <a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pParent, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>* pFontEngine) :00369 <a class="code" href="classwGui_1_1CMenuBase.html">CMenuBase</a>(WindowRect, pParent, pFontEngine),00370 m_pParentMenu(0)00371 {00372 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CPopupMenu"</span>;00373 <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> = <span class="keyword">false</span>;00374 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_BUTTONDOWN);00375 }00376 00377 <a name="l00378"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a1">00378</a> CPopupMenu::~CPopupMenu(<span class="keywordtype">void</span>)00379 {00380 00381 }00382 00383 <a name="l00384"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a2">00384</a> <span class="keywordtype">void</span> CPopupMenu::Show(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Position)00385 {00386 <span class="keywordflow">if</span> (m_bVisible)00387 {00388 <a class="code" href="classwGui_1_1CPopupMenu.html#a3">Hide</a>();00389 }00390 00391 <span class="keywordtype">int</span> iHeight = 4;00392 <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)00393 {00394 <span class="keywordflow">if</span> (iter->first.bSpacer)00395 iHeight += 6;00396 <span class="keywordflow">else</span>00397 {00398 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Dims;00399 iter->second.first.GetMetrics(&Dims, 0, 0);00400 iHeight += Dims.<a class="code" href="classwGui_1_1CPoint.html#a7">YPos</a>() + 5;00401 }00402 }00403 <a class="code" href="classwGui_1_1CWindow.html#a2">SetWindowRect</a>(<a class="code" href="classwGui_1_1CRect.html">CRect</a>(Position, Position + <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a23">Width</a>() - 1, iHeight + 2)));00404 <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> = <span class="keyword">true</span>;00405 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00406 }00407 00408 <a name="l00409"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a3">00409</a> <span class="keywordtype">void</span> CPopupMenu::Hide(<span class="keywordtype">void</span>)00410 {00411 <a class="code" href="classwGui_1_1CMenuBase.html#a5">HideActivePopup</a>();00412 <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> = <span class="keyword">false</span>;00413 <a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a> = <span class="keyword">false</span>;00414 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_PAINT, 0, <span class="keyword">this</span>));00415 <a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> = 0;00416 }00417 00418 <a name="l00419"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a4">00419</a> <span class="keywordtype">void</span> CPopupMenu::HideAll(<span class="keywordtype">void</span>)00420 {00421 <a class="code" href="classwGui_1_1CPopupMenu.html">CPopupMenu</a>* pParentPopup = dynamic_cast<CPopupMenu*>(m_pParentWindow);00422 <span class="keywordflow">if</span> (pParentPopup)00423 {00424 pParentPopup-><a class="code" href="classwGui_1_1CPopupMenu.html#a4">HideAll</a>();00425 }00426 <span class="keywordflow">else</span>00427 {00428 <a class="code" href="classwGui_1_1CMenu.html">CMenu</a>* pRootMenu = dynamic_cast<CMenu*>(m_pParentWindow);00429 <span class="keywordflow">if</span> (pRootMenu)00430 {00431 pRootMenu-><a class="code" href="classwGui_1_1CMenuBase.html#a5">HideActivePopup</a>();00432 }00433 <span class="keywordflow">else</span>00434 {00435 <a class="code" href="classwGui_1_1CPopupMenu.html#a3">Hide</a>();00436 }00437 }00438 }00439 00440 <a name="l00441"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a5">00441</a> <span class="keywordtype">bool</span> CPopupMenu::IsInsideChild(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a>& Point)00442 {00443 <span class="keywordflow">if</span> (<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)00444 {00445 <span class="keywordflow">return</span> <span class="keyword">true</span>;00446 }00447 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>)00448 {00449 <span class="keywordflow">return</span> <span class="keyword">false</span>;00450 }00451 <span class="keywordflow">return</span> <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a>-><a class="code" href="classwGui_1_1CPopupMenu.html#a5">IsInsideChild</a>(Point);00452 }00453 00454 <a name="l00455"></a><a class="code" href="classwGui_1_1CPopupMenu.html#a8">00455</a> <span class="keywordtype">void</span> CPopupMenu::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00456 <span class="keyword"></span>{00457 CWindow::Draw();00458 00459 <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00460 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>, <span class="keyword">false</span>, COLOR_LIGHTGRAY);00461 Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), COLOR_DARKGRAY);00462 Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), <a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), COLOR_DARKGRAY);00463 <a class="code" href="classwGui_1_1CPopupMenu.html#b0">UpdateCachedRects</a>();00464 <span class="keywordflow">for</span> (t_MenuItemVector::const_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)00465 {00466 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> == &(iter->first))00467 {00468 Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(iter->second.second, <span class="keyword">true</span>, <a class="code" href="classwGui_1_1CMenuBase.html#n6">m_HighlightColor</a>, <a class="code" href="classwGui_1_1CMenuBase.html#n6">m_HighlightColor</a>);00469 }00470 <a class="code" href="classwGui_1_1CRect.html">CRect</a> TextRect(iter->second.second);00471 TextRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00472 <span class="keywordflow">if</span> (iter->first.bSpacer)00473 {00474 Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(TextRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), COLOR_LIGHTGRAY);00475 Painter.<a class="code" href="classwGui_1_1CPainter.html#a3">DrawHLine</a>(TextRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), COLOR_DARKGRAY);00476 }00477 <span class="keywordflow">else</span>00478 iter->second.first.Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, TextRect, TextRect.<a class="code" href="classwGui_1_1CRect.html#a13">TopLeft</a>());00479 <span class="keywordflow">if</span> (iter->first.pPopup)00480 {00481 <a class="code" href="classwGui_1_1CRect.html">CRect</a> ArrowRect(iter->second.second);00482 ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a6">SetLeft</a>(ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - <a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->w);00483 SDL_Rect SourceRect;00484 SourceRect.x = static_cast<short int>(0);00485 SourceRect.y = 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>()->h - ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>()) / 2 < 0 ?00486 0 : (<a class="code" href="classwGui_1_1CMenuBase.html#n5">m_hRightArrowBitmap</a>.<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">Bitmap</a>()->h - ArrowRect.<a class="code" href="classwGui_1_1CRect.html#a24">Height</a>()) / 2);00487 SourceRect.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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -