Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Main.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 #include <stdincl.h> 00024 00025 #include "defaults.h" 00026 #include "WinSockInit.h" 00027 #include "InitSDL.h" 00028 #include "DotCursor.h" 00029 #include "MainWindow.h" 00030 //#include "Surface.h" 00031 #include "Globals.h" 00032 #include "client.h" 00033 #include "Main.h" 00034 00035 00036 00037 #undef DEB 00038 #ifdef _DEBUG 00039 #define DEB(x) x 00040 #else 00041 #define DEB(x) 00042 #endif 00043 00044 00045 Main::Main(int argc,char *argv[]) 00046 :GuiEvent() 00047 ,m_clControl(argc,argv,XMAX,YMAX) //m_clInitSDL(argc,argv) 00048 ,m_pclMainWindow(NULL) 00049 ,m_angle1(90) 00050 ,m_angle2(1) 00051 { 00052 if (IsOK()) 00053 { 00054 DEB(printf("Allt OK\n");) 00055 m_pclMainWindow = new MainWindow( &m_clControl ); 00056 } 00057 else 00058 { 00059 DEB(printf("Ej OK\n");) 00060 } 00061 00062 // init gui event 00063 if (IsOK()) 00064 { 00065 SetRootSurface(m_pclMainWindow); 00066 SetSDLControl(&m_clControl); 00067 } 00068 } 00069 00070 00071 Main::~Main() 00072 { 00073 if (m_pclMainWindow) 00074 { 00075 delete m_pclMainWindow; 00076 } 00077 } 00078 00079 00080 bool Main::IsOK() 00081 { 00082 #ifdef WIN32 00083 if (!m_clWinSock.IsOK()) 00084 { 00085 return false; 00086 } 00087 #endif 00088 if (!m_clControl.IsOK()) 00089 { 00090 return false; 00091 } 00092 return true; 00093 } 00094 00095 00096 void Main::AddForm(IOMessage *pclForm) 00097 { 00098 // m_forms.insert(m_forms.end(), (Form::Form *)pclForm); 00099 } 00100 00101 00102 void Main::UserEvent(SDL_UserEvent &e) 00103 { 00104 switch (e.code) 00105 { 00106 case SDL_USEREVENT_ADDFORM: 00107 { 00108 Form::Form *pclForm = reinterpret_cast<Form::Form *>(e.data1); 00109 pclForm -> FormCreateDialog(m_pclMainWindow); 00110 // AddForm( pclForm ); 00111 } 00112 break; 00113 case SDL_USEREVENT_DISCONNECT: 00114 m_pclMainWindow -> Disconnect(); 00115 m_pclMainWindow -> SetDirty(true); 00116 break; 00117 case SDL_USEREVENT_UICOMMAND: 00118 Surface *pclSurface; 00119 long cmd; 00120 memmove(&pclSurface,&e.data1,4); 00121 memmove(&cmd,&e.data2,4); 00122 switch (cmd) 00123 { 00124 case UICOMMAND_QUIT: 00125 SetQuit(true); 00126 break; 00127 case UICOMMAND_XMLSAVE: 00128 { 00129 m_pclMainWindow -> SaveDialogs(); 00130 /* 00131 FILE *fil; 00132 if ((fil = fopen("mainwindow.xml","wt")) != NULL) 00133 { 00134 fprintf(fil,"<?xml version=\"1.0\"?>\n"); 00135 m_pclMainWindow -> Dump(fil); 00136 fclose(fil); 00137 } 00138 */ 00139 } 00140 break; 00141 default: 00142 GuiEvent::UserEvent(e); 00143 } 00144 break; 00145 00146 default: 00147 GuiEvent::UserEvent(e); 00148 break; 00149 } 00150 } 00151 00152 00153 void Main::KeyboardEvent(SDL_KeyboardEvent &e) 00154 { 00155 if (e.type == SDL_KEYDOWN) 00156 { 00157 switch (e.keysym.sym) 00158 { 00159 case SDLK_F2: 00160 m_pclMainWindow -> ShowText(); 00161 break; 00162 case SDLK_ESCAPE: 00163 m_pclMainWindow -> ShowMenu(); 00164 break; 00165 00166 // mandel test 00167 case SDLK_PAGEUP: 00168 m_pclMainWindow -> IncreaseBase(); 00169 break; 00170 case SDLK_PAGEDOWN: 00171 m_pclMainWindow -> DecreaseBase(); 00172 break; 00173 case SDLK_UP: 00174 Globals::m_zy -= Globals::m_scale; 00175 m_pclMainWindow -> Redraw(); 00176 break; 00177 case SDLK_DOWN: 00178 Globals::m_zy += Globals::m_scale; 00179 m_pclMainWindow -> Redraw(); 00180 break; 00181 case SDLK_RIGHT: 00182 Globals::m_zx += Globals::m_scale; 00183 m_pclMainWindow -> Redraw(); 00184 break; 00185 case SDLK_LEFT: 00186 Globals::m_zx -= Globals::m_scale; 00187 m_pclMainWindow -> Redraw(); 00188 break; 00189 case SDLK_HOME: 00190 Globals::m_scale *= 1.05; 00191 m_pclMainWindow -> Redraw(); 00192 break; 00193 case SDLK_END: 00194 Globals::m_scale *= 0.95; 00195 m_pclMainWindow -> Redraw(); 00196 break; 00197 00198 default: 00199 GuiEvent::KeyboardEvent(e); 00200 break; 00201 } 00202 } 00203 else 00204 { 00205 GuiEvent::KeyboardEvent(e); 00206 } 00207 } 00208 00209 00210 void Main::MainLoop() 00211 { 00212 SDL_Event event; 00213 00214 // draw surfaces in local pixel surface 00215 // flyttat till basklass 00216 // m_pclMainWindow -> DrawAll(); 00217 // m_pclMainWindow -> CalculateAbsolute(); 00218 00219 // m_pclMainWindow -> ShowText(); 00220 // pprintf("Welcome...\n"); 00221 00222 event.user.type = SDL_USEREVENT; 00223 event.user.code = SDL_USEREVENT_PAINT; 00224 event.user.data1 = NULL; 00225 event.user.data2 = NULL; 00226 SDL_PushEvent(&event); 00227 00228 event.type = SDL_KEYDOWN; 00229 event.key.keysym.sym = SDLK_F2; 00230 SDL_PushEvent(&event); 00231 00232 SetDefaultFocus( m_pclMainWindow -> GetInput() ); 00233 00234 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 00235 00236 EventLoop(); 00237 } 00238 00239 00240 MainWindow *Main::GetWindow() 00241 { 00242 return m_pclMainWindow; 00243 } 00244 00245

Generated for SDL C++ GUI by doxygen 1.3.6