📄 wg__application_8cpp-source.html
字号:
00139 <a name="l00140"></a><a class="code" href="classwGui_1_1CApplication.html#a6">00140</a> <span class="keywordtype">void</span> CApplication::SetKeyFocus(<a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pWindow)00141 {00142 <span class="comment">// notify the window that's losing focus to repaint itself</span>00143 <span class="keywordflow">if</span> (m_pKeyFocusWindow)00144 {00145 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_PAINT, <a class="code" href="classwGui_1_1CApplication.html#n6">m_pKeyFocusWindow</a>, <span class="keyword">this</span>));00146 }00147 <a class="code" href="classwGui_1_1CApplication.html#n6">m_pKeyFocusWindow</a> = pWindow;00148 }00149 00150 <a name="l00151"></a><a class="code" href="classwGui_1_1CApplication.html#a8">00151</a> <span class="keywordtype">void</span> CApplication::SetMouseFocus(<a class="code" href="classwGui_1_1CWindow.html">CWindow</a>* pWindow)00152 {00153 <span class="comment">// notify the window that's losing focus to repaint itself</span>00154 <span class="keywordflow">if</span> (m_pMouseFocusWindow)00155 {00156 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_PAINT, <a class="code" href="classwGui_1_1CApplication.html#n7">m_pMouseFocusWindow</a>, <span class="keyword">this</span>));00157 }00158 <a class="code" href="classwGui_1_1CApplication.html#n7">m_pMouseFocusWindow</a> = pWindow;00159 }00160 00161 00162 <a name="l00163"></a><a class="code" href="classwGui_1_1CApplication.html#a10">00163</a> <span class="keywordtype">void</span> CApplication::Init(<span class="keywordtype">void</span>)00164 {00165 CMessageServer::Instance().RegisterMessageClient(<span class="keyword">this</span>, CMessage::APP_EXIT, CMessageServer::PRIORITY_LAST);00166 SDL_EnableUNICODE(1);00167 00168 <span class="comment">// Now we have to find the wGui.conf file and load it into the Global Config</span>00169 <span class="comment">// Our ordered search path is (so the current directory will overwrite any common settings with the other directories):</span>00170 <span class="comment">// <global directory></span>00171 <span class="comment">// <home directory></span>00172 <span class="comment">// <current directory></span>00173 00174 <span class="comment">// global directory first</span>00175 <a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a11">ReadFromFile</a>(GLOBAL_CONFIG_PATH + <span class="stringliteral">"wgui.conf"</span>);00176 00177 <span class="comment">// now the home directory</span>00178 <a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a11">ReadFromFile</a>(USER_CONFIG_PATH + <span class="stringliteral">"wgui.conf"</span>);00179 00180 <span class="comment">// and finally the current directory</span>00181 <a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a11">ReadFromFile</a>(<span class="stringliteral">"wgui.conf"</span>);00182 00183 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a9">EntryExists</a>(<span class="stringliteral">"DEFAULTFONT"</span>))00184 {00185 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a9">EntryExists</a>(<span class="stringliteral">"DEFAULTFONTSIZE"</span>))00186 {00187 <a class="code" href="classwGui_1_1CApplication.html#n9">m_pDefaultFontEngine</a> = <a class="code" href="classwGui_1_1CApplication.html#a13">GetFontEngine</a>(<a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a2">GetStringEntry</a>(<span class="stringliteral">"DEFAULTFONT"</span>).second,00188 static_cast<unsigned char>(<a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a3">GetLongIntEntry</a>(<span class="stringliteral">"DEFAULTFONTSIZE"</span>).second));00189 }00190 <span class="keywordflow">else</span>00191 {00192 <a class="code" href="classwGui_1_1CApplication.html#n9">m_pDefaultFontEngine</a> = <a class="code" href="classwGui_1_1CApplication.html#a13">GetFontEngine</a>(<a class="code" href="classwGui_1_1CApplication.html#n15">m_GlobalConfig</a>.<a class="code" href="classwGui_1_1CConfigStore.html#a2">GetStringEntry</a>(<span class="stringliteral">"DEFAULTFONT"</span>).second);00193 }00194 }00195 00196 <a class="code" href="classwGui_1_1CApplication.html#n5">m_bInited</a> = <span class="keyword">true</span>;00197 }00198 00199 <a name="l00200"></a><a class="code" href="classwGui_1_1CApplication.html#a11">00200</a> <span class="keywordtype">void</span> CApplication::Exec(<span class="keywordtype">void</span>)00201 {00202 <span class="keywordflow">try</span>00203 {00204 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CApplication.html#n5">m_bInited</a>)00205 {00206 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CApplication::Exec : Application Init() was not called!"</span>));00207 }00208 00209 <a class="code" href="classwGui_1_1CApplication.html#n4">m_bRunning</a> = <span class="keyword">true</span>;00210 SDL_Event event;00211 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>));00212 <span class="keywordflow">while</span> (m_bRunning)00213 {00214 <span class="keywordflow">while</span> (SDL_PollEvent(&event))00215 {00216 <a class="code" href="classwGui_1_1CApplication.html#b0">HandleSDLEvent</a>(event);00217 }00218 <span class="keywordflow">while</span> (!CMessageServer::Instance().MessageAvailable())00219 {00220 <span class="keywordflow">while</span> (SDL_PollEvent(&event))00221 {00222 <a class="code" href="classwGui_1_1CApplication.html#b0">HandleSDLEvent</a>(event);00223 }00224 SDL_Delay(5);00225 }00226 <span class="keywordflow">try</span>00227 {00228 CMessageServer::Instance().DeliverMessage();00229 }00230 <span class="keywordflow">catch</span> (<a class="code" href="classwGui_1_1Wg__Ex__Base.html">Wg_Ex_Base</a>& DEBUG_ONLY(e))00231 {00232 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CApplication.html#n10">m_bHandleExceptionsInternally</a>)00233 {00234 <span class="keywordflow">throw</span>;00235 }00236 <span class="comment">// Since we're handling exceptions internally, and it's one of our own exceptions, we're just going to</span>00237 <span class="comment">// send something to the debug output and then continue processing the message queue</span>00238 Trace(<span class="stringliteral">"wGui exception while delivering message : "</span> + e.std_what());00239 }00240 }00241 }00242 <span class="keywordflow">catch</span> (<a class="code" href="classwGui_1_1Wg__Ex__Base.html">Wg_Ex_Base</a>& DEBUG_ONLY(e))00243 {00244 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CApplication.html#n10">m_bHandleExceptionsInternally</a>)00245 {00246 <span class="keywordflow">throw</span>;00247 }00248 <span class="comment">// We are supposed to handle all exceptions internally, but something hasn't been handled at this point, so we need to exit gracefully</span>00249 Trace(<span class="stringliteral">"Unhandled wGui exception : "</span> + e.std_what());00250 }00251 <span class="keywordflow">catch</span> (std::exception& DEBUG_ONLY(e))00252 {00253 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CApplication.html#n10">m_bHandleExceptionsInternally</a>)00254 {00255 <span class="keywordflow">throw</span>;00256 }00257 <span class="comment">// We are supposed to handle all exceptions internally, but something hasn't been handled at this point, so we need to exit gracefully</span>00258 Trace(<span class="stringliteral">"Unhandled std exception : "</span> + std::string(e.what()));00259 }00260 <span class="keywordflow">catch</span> (...)00261 {00262 <span class="keywordflow">if</span> (!<a class="code" href="classwGui_1_1CApplication.html#n10">m_bHandleExceptionsInternally</a>)00263 {00264 <span class="keywordflow">throw</span>;00265 }00266 <span class="comment">// We are supposed to handle all exceptions internally, but something hasn't been handled at this point, so we need to exit gracefully</span>00267 Trace(<span class="stringliteral">"Unhandled exception"</span>);00268 }00269 }00270 00271 <a name="l00272"></a><a class="code" href="classwGui_1_1CApplication.html#a12">00272</a> <span class="keywordtype">void</span> CApplication::ApplicationExit(<span class="keywordtype">int</span> iExitCode)00273 {00274 <span class="comment">// push an event into the SDL queue so the SDLEventLoopThread can exit</span>00275 <span class="comment">// the actual contents of the event are not a concern as it serves just to trigger the SDL_WaitEvent</span>00276 SDL_Event user_event;00277 user_event.type=SDL_USEREVENT;00278 user_event.user.code=0;00279 user_event.user.data1=0;00280 user_event.user.data2=0;00281 DEBUG_ONLY(<span class="keywordtype">int</span> iResult =) SDL_PushEvent(&user_event);00282 TraceIf(iResult == -1, <span class="stringliteral">"CApplication::ApplicationExit - Unable to push SDL user_event."</span>);00283 <a class="code" href="classwGui_1_1CApplication.html#n3">m_iExitCode</a> = iExitCode;00284 <a class="code" href="classwGui_1_1CApplication.html#n4">m_bRunning</a> = <span class="keyword">false</span>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -