📄 wg__menu_8cpp-source.html
字号:
00158 <a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> = 0;00159 <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00160 }00161 <span class="keywordflow">break</span>;00162 }00163 <span class="keywordflow">case</span> CMessage::CTRL_LCLICK:00164 {00165 TIntMessage* pCtrlMessage = dynamic_cast<TIntMessage*>(pMessage);00166 <span class="keywordflow">if</span> (pCtrlMessage && pCtrlMessage->Destination() == <span class="keyword">this</span>)00167 {00168 <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)00169 {00170 <span class="keywordflow">if</span> (pCtrlMessage->Source() == iter->first.pPopup)00171 {00172 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_LCLICK, <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>,00173 <span class="keyword">this</span>, pCtrlMessage->Value()));00174 bHandled = <span class="keyword">true</span>;00175 <span class="keywordflow">break</span>;00176 }00177 }00178 }00179 <span class="keywordflow">break</span>;00180 }00181 <span class="keywordflow">case</span> CMessage::CTRL_TIMER:00182 {00183 <span class="keywordflow">if</span> (pMessage-><a class="code" href="classwGui_1_1CMessage.html#a3">Destination</a>() == <span class="keyword">this</span>)00184 {00185 bHandled = <span class="keyword">true</span>;00186 }00187 <span class="keywordflow">break</span>;00188 }00189 <span class="keywordflow">default</span> :00190 bHandled = CWindow::HandleMessage(pMessage);00191 <span class="keywordflow">break</span>;00192 }00193 }00194 00195 <span class="keywordflow">return</span> bHandled;00196 }00197 00198 00199 <span class="comment">// CMenu</span>00200 <a name="l00201"></a><a class="code" href="classwGui_1_1CMenu.html#a0">00201</a> CMenu::CMenu(<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) :00202 <a class="code" href="classwGui_1_1CMenuBase.html">CMenuBase</a>(WindowRect, pParent, pFontEngine)00203 {00204 <a class="code" href="classwGui_1_1CWindow.html#n8">m_sClassName</a> = <span class="stringliteral">"CMenu"</span>;00205 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::MOUSE_MOVE);00206 }00207 00208 <a name="l00209"></a><a class="code" href="classwGui_1_1CMenu.html#a1">00209</a> CMenu::~CMenu(<span class="keywordtype">void</span>)00210 {00211 00212 }00213 00214 <a name="l00215"></a><a class="code" href="classwGui_1_1CMenu.html#a2">00215</a> <span class="keywordtype">void</span> CMenu::InsertMenuItem(<span class="keyword">const</span> <a class="code" href="structwGui_1_1SMenuItem.html">SMenuItem</a>& MenuItem, <span class="keywordtype">int</span> iPosition)00216 {00217 <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.insert((iPosition == -1) ? <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.end() : <a class="code" href="classwGui_1_1CMenuBase.html#n1">m_MenuItems</a>.begin() + iPosition,00218 std::make_pair(MenuItem, std::make_pair(<a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(<a class="code" href="classwGui_1_1CMenuBase.html#n0">m_pFontEngine</a>, MenuItem.<a class="code" href="structwGui_1_1SMenuItem.html#m0">sItemText</a>, CRenderedString::VALIGN_NORMAL), <a class="code" href="classwGui_1_1CRect.html">CRect</a>())));00219 <a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a> = <span class="keyword">false</span>;00220 <span class="keywordflow">if</span> (MenuItem.<a class="code" href="structwGui_1_1SMenuItem.html#m2">pPopup</a>)00221 {00222 MenuItem.<a class="code" href="structwGui_1_1SMenuItem.html#m2">pPopup</a>-><a class="code" href="classwGui_1_1CPopupMenu.html#a7">SetParentMenu</a>(<span class="keyword">this</span>);00223 }00224 }00225 00226 <a name="l00227"></a><a class="code" href="classwGui_1_1CMenu.html#a3">00227</a> <span class="keywordtype">void</span> CMenu::Draw(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00228 <span class="keyword"></span>{00229 CWindow::Draw();00230 00231 <a class="code" href="classwGui_1_1CPainter.html">CPainter</a> Painter(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>);00232 <a class="code" href="classwGui_1_1CMenu.html#b0">UpdateCachedRects</a>();00233 <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)00234 {00235 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CMenuBase.html#n2">m_pHighlightedItem</a> == &(iter->first))00236 {00237 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>);00238 }00239 <a class="code" href="classwGui_1_1CRect.html">CRect</a> TextRect(iter->second.second);00240 TextRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00241 <span class="keywordflow">if</span> (iter->first.bSpacer)00242 {00243 Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(TextRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), COLOR_LIGHTGRAY);00244 Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(TextRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), TextRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>(), COLOR_DARKGRAY);00245 }00246 <span class="keywordflow">else</span>00247 iter->second.first.Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, TextRect, <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(TextRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>(), (TextRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() + TextRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>()) * 3 / 4));00248 }00249 }00250 00251 <a name="l00252"></a><a class="code" href="classwGui_1_1CMenu.html#a4">00252</a> <span class="keywordtype">bool</span> CMenu::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00253 {00254 <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00255 00256 <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) &&00257 (Button == CMouseMessage::LEFT))00258 {00259 <a class="code" href="classwGui_1_1CMenu.html#b0">UpdateCachedRects</a>();00260 <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)00261 {00262 <span class="keywordflow">if</span> (iter->second.second.HitTest(Point) == CRect::RELPOS_INSIDE && !iter->first.bSpacer)00263 {00264 <a class="code" href="classwGui_1_1CMenuBase.html#a5">HideActivePopup</a>();00265 <span class="keywordflow">if</span> (iter->first.pPopup)00266 {00267 <a class="code" href="classwGui_1_1CPopupMenu.html">CPopupMenu</a>* pPopup = dynamic_cast<CPopupMenu*>(iter->first.pPopup);00268 <span class="keywordflow">if</span> (pPopup)00269 {00270 <a class="code" href="classwGui_1_1CMenuBase.html#n4">m_pActivePopup</a> = pPopup;00271 <a class="code" href="classwGui_1_1CMenu.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>());00272 }00273 }00274 <span class="keywordflow">else</span>00275 {00276 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TIntMessage(CMessage::CTRL_LCLICK, <a class="code" href="classwGui_1_1CWindow.html#n4">m_pParentWindow</a>, <span class="keyword">this</span>, iter->first.iItemId));00277 }00278 <span class="keywordflow">break</span>;00279 }00280 }00281 bResult = <span class="keyword">true</span>;00282 }00283 00284 <span class="keywordflow">return</span> bResult;00285 }00286 00287 <a name="l00288"></a><a class="code" href="classwGui_1_1CMenu.html#a5">00288</a> <span class="keywordtype">bool</span> CMenu::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00289 {00290 <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00291 00292 <span class="keywordflow">if</span> (pMessage)00293 {00294 <span class="keywordflow">switch</span>(pMessage-><a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00295 {00296 <span class="keywordflow">case</span> CMessage::MOUSE_MOVE:00297 {00298 <span class="keywordflow">break</span>;00299 }00300 <span class="keywordflow">default</span> :00301 bHandled = CMenuBase::HandleMessage(pMessage);00302 <span class="keywordflow">break</span>;00303 }00304 }00305 00306 <span class="keywordflow">return</span> bHandled;00307 }00308 00309 <a name="l00310"></a><a class="code" href="classwGui_1_1CMenu.html#b0">00310</a> <span class="keywordtype">void</span> CMenu::UpdateCachedRects(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00311 <span class="keyword"></span>{00312 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CMenuBase.html#n3">m_bCachedRectsValid</a>)00313 {00314 <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00315 SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-2);00316 <span class="keywordtype">int</span> iWidth = 5;00317 <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)00318 {00319 <span class="keywordflow">if</span> (iter->first.bSpacer)00320 {00321 <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 + 1, SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>() - 2);00322 TextRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -