📄 wg__application_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>wg_application.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> </center><hr><h1>wg_application.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_application.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// CApplication interface</span>00004 <span class="comment">//</span>00005 <span class="comment">//</span>00006 <span class="comment">// Copyright (c) 2002 Rob Wiskow</span>00007 <span class="comment">// rob-dev@boxedchaos.com</span>00008 <span class="comment">//</span>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>00011 <span class="comment">// License as published by the Free Software Foundation; either</span>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>00013 <span class="comment">//</span>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00017 <span class="comment">// Lesser General Public License for more details.</span>00018 <span class="comment">//</span>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>00022 <span class="comment">//</span>00023 00024 00025 <span class="preprocessor">#include "wgui_include_config.h"</span>00026 <span class="preprocessor">#include "wg_application.h"</span>00027 <span class="preprocessor">#include "wg_error.h"</span>00028 <span class="preprocessor">#include "wg_debug.h"</span>00029 <span class="preprocessor">#include "std_ex.h"</span>00030 <span class="preprocessor">#include <iostream></span>00031 <span class="preprocessor">#include <fstream></span>00032 00033 00034 <span class="keyword">namespace </span>wGui00035 {00036 00037 <span class="comment">// Static members</span><a name="l00038"></a><a class="code" href="classwGui_1_1CApplication.html#q0">00038</a> <a class="code" href="classwGui_1_1CApplication.html">CApplication</a>* CApplication::m_pInstance = 0;00039 00040 <a name="l00041"></a><a class="code" href="classwGui_1_1CApplication.html#b0">00041</a> <span class="keywordtype">void</span> CApplication::HandleSDLEvent(SDL_Event Event)00042 {00043 <span class="comment">// this will turn an SDL event into a wGui message</span>00044 <span class="keywordflow">switch</span> (Event.type)00045 {00046 <span class="keywordflow">case</span> SDL_VIDEORESIZE:00047 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> TPointMessage(00048 CMessage::CTRL_RESIZE, 0, 0, <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(Event.resize.w, Event.resize.h)));00049 <span class="keywordflow">break</span>;00050 <span class="keywordflow">case</span> SDL_KEYDOWN:00051 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CKeyboardMessage.html">CKeyboardMessage</a>(00052 CMessage::KEYBOARD_KEYDOWN, CApplication::Instance()-><a class="code" href="classwGui_1_1CApplication.html#a7">GetKeyFocus</a>(), <span class="keyword">this</span>,00053 Event.key.keysym.scancode, Event.key.keysym.mod,00054 Event.key.keysym.sym, Event.key.keysym.unicode));00055 <span class="keywordflow">break</span>;00056 <span class="keywordflow">case</span> SDL_KEYUP:00057 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CKeyboardMessage.html">CKeyboardMessage</a>(00058 CMessage::KEYBOARD_KEYUP, CApplication::Instance()-><a class="code" href="classwGui_1_1CApplication.html#a7">GetKeyFocus</a>(), <span class="keyword">this</span>,00059 Event.key.keysym.scancode, Event.key.keysym.mod,00060 Event.key.keysym.sym, Event.key.keysym.unicode));00061 <span class="keywordflow">break</span>;00062 <span class="keywordflow">case</span> SDL_MOUSEBUTTONDOWN:00063 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>(00064 CMessage::MOUSE_BUTTONDOWN, CApplication::Instance()-><a class="code" href="classwGui_1_1CApplication.html#a9">GetMouseFocus</a>(), <span class="keyword">this</span>,00065 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(Event.button.x, Event.button.y), <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(),00066 CMouseMessage::TranslateSDLButton(Event.button.button)));00067 <span class="keywordflow">break</span>;00068 <span class="keywordflow">case</span> SDL_MOUSEBUTTONUP:00069 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>(00070 CMessage::MOUSE_BUTTONUP, CApplication::Instance()-><a class="code" href="classwGui_1_1CApplication.html#a9">GetMouseFocus</a>(), <span class="keyword">this</span>,00071 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(Event.button.x, Event.button.y), <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(),00072 CMouseMessage::TranslateSDLButton(Event.button.button)));00073 <span class="keywordflow">break</span>;00074 <span class="keywordflow">case</span> SDL_MOUSEMOTION:00075 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>(00076 CMessage::MOUSE_MOVE, CApplication::Instance()-><a class="code" href="classwGui_1_1CApplication.html#a9">GetMouseFocus</a>(), <span class="keyword">this</span>,00077 <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(Event.motion.x, Event.motion.y), <a class="code" href="classwGui_1_1CPoint.html">CPoint</a>(Event.motion.xrel, Event.motion.yrel),00078 CMouseMessage::TranslateSDLButtonState(Event.motion.state)));00079 <span class="keywordflow">break</span>;00080 <span class="keywordflow">case</span> SDL_QUIT:00081 CMessageServer::Instance().QueueMessage(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CMessage.html">CMessage</a>(CMessage::APP_EXIT, 0, <span class="keyword">this</span>));00082 <span class="keywordflow">break</span>;00083 }00084 }00085 00086 <a name="l00087"></a><a class="code" href="classwGui_1_1CApplication.html#a0">00087</a> CApplication::CApplication(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv, std::string sFontFileName, <span class="keywordtype">bool</span> bHandleExceptionsInternally) :00088 m_argc(argc),00089 m_argv(argv),00090 m_sFontFileName(sFontFileName),00091 m_iExitCode(EXIT_FAILURE),00092 m_bRunning(false),00093 m_bInited(false),00094 m_pKeyFocusWindow(0),00095 m_pMouseFocusWindow(0),00096 m_pDefaultFontEngine(0),00097 m_bHandleExceptionsInternally(bHandleExceptionsInternally),00098 m_bResourcePoolEnabled(true),00099 m_pCurrentCursorResourceHandle(0),00100 m_pSystemDefaultCursor(0)00101 {00102 <span class="keywordflow">if</span> (m_pInstance)00103 {00104 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CApplication::CApplication : An instance of the CApplication already exists."</span>));00105 }00106 00107 <a class="code" href="classwGui_1_1CApplication.html#q0">m_pInstance</a> = <span class="keyword">this</span>;00108 00109 <span class="keywordflow">if</span>(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE ) == -1)00110 {00111 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__SDL.html">Wg_Ex_SDL</a>(std::string(<span class="stringliteral">"CApplication::CApplication : Could not initialize SDL: "</span>) + SDL_GetError()));00112 }00113 <span class="comment">//Setting the keyboard repeat rate using the SDL Default rates</span>00114 <span class="keywordflow">if</span>(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)00115 {00116 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__SDL.html">Wg_Ex_SDL</a>(std::string(<span class="stringliteral">"CApplication::Capplication : Error setting SDL keyboard repeat rate."</span>)));00117 }00118 00119 <a class="code" href="classwGui_1_1CApplication.html#n14">m_pSystemDefaultCursor</a> = SDL_GetCursor();00120 00121 atexit(SDL_Quit);00122 }00123 00124 <a name="l00125"></a><a class="code" href="classwGui_1_1CApplication.html#a1">00125</a> CApplication::~CApplication(<span class="keywordtype">void</span>)00126 {00127 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CApplication.html#q0">m_pInstance</a> == <span class="keyword">this</span>)00128 {00129 <a class="code" href="classwGui_1_1CApplication.html#q0">m_pInstance</a> = 0;00130 }00131 00132 <span class="keywordflow">for</span>(std::map<std::pair<std::string, unsigned char>, <a class="code" href="classwGui_1_1CFontEngine.html">CFontEngine</a>*>::iterator iter = <a class="code" href="classwGui_1_1CApplication.html#n8">m_FontEngines</a>.begin(); iter != <a class="code" href="classwGui_1_1CApplication.html#n8">m_FontEngines</a>.end(); ++iter)00133 {00134 <span class="keyword">delete</span> iter->second;00135 iter->second = 0;00136 }00137 }00138
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -