Public Member Functions | |
| mxWnd (int w=640, int h=480, Uint32 flags=0, SDL_Surface *ico=0, bool opengl_init=false) | |
| mxWnd (Size window, Size canvas, Uint32 flags=0, SDL_Surface *ico=0) | |
| void | initWnd (int w, int h, Uint32 flags, SDL_Surface *ico, bool opengl_init) |
| void | setMode (lookType type) |
| virtual | ~mxWnd () |
| int | messageLoop () |
| virtual void | eventPassed (SDL_Event &e) |
| virtual void | renderScreen () |
| void | setTitle (string title) const |
| void | quit () |
| void | minimizeWindow () const |
| void | pumpEvents () const |
| void | enableKeyRepeat (int code, int interval) |
| SDL_Surface * | renderSurface () const |
| mxSurface & | mxrenderSurface () |
| Size & | size () |
| mxSurface & | sizedSurface () |
| void | sizedFlip () |
| void | createSizedBackground (Size &s) |
| virtual void | resizeWindow (int w, int h) |
Static Protected Member Functions | |
| static mxWnd * | get_MX () |
Protected Attributes | |
| mxSurface | front |
| mxSurface | background |
| bool | active |
| Uint32 | vid_flags |
| Size | sizevar |
| bool | opengl_ |
| lookType | d_type |
Static Protected Attributes | |
| static mxWnd * | mxwnd = 0 |
Definition at line 36 of file mxwnd.h.
| mx::mxWnd::mxWnd | ( | int | w = 640, |
|
| int | h = 480, |
|||
| Uint32 | flags = 0, |
|||
| SDL_Surface * | ico = 0, |
|||
| bool | opengl_init = false | |||
| ) |
Default Constructor has default arguments for each argument if you do not wish to supply any
| w | the width of the window | |
| h | the height of the window | |
| flags | contains the SDL window flags, SDL_FULLSCREEN for full screen windows etc | |
| ico | the Bitmap for the windows icon | |
| opengl_init | for whether or not to init this window as a OpenGL window |
Definition at line 33 of file mxwnd.cpp.
References initWnd().
00034 { 00035 initWnd(w,h,flags,ico,opengl_init); 00036 }
Secondary Constructor
| window | the size of the window as a Size object | |
| canvas | size for stretching to window size, example window size is 640x480 canvas size is 480x272 canvas size will be stretched to screen size before being rendered | |
| flags | SDL SetVideoMode Flags | |
| ico | the bitmap for the Icon of the Window |
Definition at line 26 of file mxwnd.cpp.
References createSizedBackground(), mx::Size::height, initWnd(), and mx::Size::width.
00027 { 00028 initWnd(window.width,window.height,flags,ico,false); 00029 createSizedBackground( s ); 00030 }
| mx::mxWnd::~mxWnd | ( | ) | [virtual] |
Virtual destructor to cleanup after the object leaves scope
Definition at line 126 of file mxwnd.cpp.
00127 { 00128 00129 SDL_Quit(); 00130 std::cout << "application shutdown @ "; 00131 time_t the_time; 00132 struct tm *time_info; 00133 time(&the_time); 00134 time_info = localtime(&the_time); 00135 std::cout << asctime(time_info); 00136 std::cout << "SDL: subsystem shutdown\n"; 00137 00138 }
| void mx::mxWnd::createSizedBackground | ( | Size & | s | ) |
create a sized background by Size (width,height)
| s | a Size object for width/height |
Definition at line 121 of file mxwnd.cpp.
References background, and mx::mxSurface::createSurface().
Referenced by mxWnd().
00122 { 00123 background.createSurface( s ); 00124 }
| void mx::mxWnd::enableKeyRepeat | ( | int | code, | |
| int | interval | |||
| ) |
| void mx::mxWnd::eventPassed | ( | SDL_Event & | e | ) | [virtual] |
virtual function for event processing overload this function in your subclass and the app's messages will be propagated to this function at the correct times.
| e | SDL_Event event structure http://libsdl.org for more info |
Definition at line 198 of file mxwnd.cpp.
References active.
Referenced by messageLoop().
00199 { 00200 if(e.type == SDL_QUIT) active = false; 00201 else if(e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) active = false; 00202 }
| static mxWnd* mx::mxWnd::get_MX | ( | ) | [inline, static, protected] |
| void mx::mxWnd::initWnd | ( | int | w, | |
| int | h, | |||
| Uint32 | flags, | |||
| SDL_Surface * | ico, | |||
| bool | opengl_init | |||
| ) |
initWnd this function is for if you wish to reinitalize the application window, it is what the constructor calls to set the video mode
| w | the windows width in pixels | |
| h | the windows height in pixels | |
| flags | the SDL flags for SetVideoMode | |
| ico | the icon bitmap | |
| opengl_init | whether or not to init OpenGL |
Definition at line 38 of file mxwnd.cpp.
References active, d_type, front, mx::mxSurface::getSurface(), mx::mxSurface::height(), mxwnd, mx::mxSurface::noZero(), opengl_, sizevar, vid_flags, and mx::mxSurface::width().
Referenced by mxWnd().
00039 { 00040 err_Type = 0; 00041 active = false; 00042 mxwnd = this; 00043 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0) { 00044 err_Type = 1; 00045 return; 00046 } 00047 00048 if(ico != 0) 00049 SDL_WM_SetIcon(ico, 0); 00050 00051 opengl_ = false; 00052 00053 const SDL_VideoInfo *vi = SDL_GetVideoInfo(); 00054 00055 Uint8 bpp=0; 00056 00057 bpp = vi->vfmt->BitsPerPixel; 00058 00059 bool hw_ = true; 00060 00061 if(vi->hw_available != 0) 00062 flags |= SDL_HWSURFACE; 00063 else { 00064 flags |= SDL_SWSURFACE; 00065 hw_ = false; 00066 } 00067 00068 if(vi->blit_hw) 00069 flags |= SDL_HWACCEL; 00070 00071 00072 if(opengl_init == true) 00073 { 00074 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); 00075 d_type = ORTHO; 00076 } 00077 00078 00079 if(w == -1) 00080 { 00081 w = vi->current_w; 00082 h = vi->current_h; 00083 flags |= SDL_FULLSCREEN; 00084 } 00085 00086 if(opengl_init == true) { 00087 flags |= SDL_OPENGL; 00088 opengl_ = true; 00089 } 00090 // set a icon here 00091 00092 SDL_Surface *temp = SDL_SetVideoMode(w,h,32,flags); 00093 00094 if(!temp) { 00095 err_Type = 2; 00096 return; 00097 } 00098 00099 front = temp; 00100 vid_flags = flags; 00101 front.noZero(true); // no zero here , because the surface is freed by the call to SDL Quit 00102 00103 00104 00105 std::cout << "application activated @ "; 00106 00107 time_t the_time; 00108 struct tm *time_info; 00109 00110 time(&the_time); 00111 00112 time_info = localtime(&the_time); 00113 std::cout << asctime(time_info); 00114 std::cout << "SDL: subsystem initalized\n"; 00115 std::cout << "Video " << front.width() << "x" << front.height() << "x" << int(front.getSurface()->format->BitsPerPixel) << "\n"; 00116 std::cout << "Render Mode: " << ((hw_ == true) ? "Direct Rendering" : "Software Rendering") << "\n"; 00117 std::cout << "Hardware Blit Acceleration: " << ((vi->blit_hw == 0) ? "No": "Yes") << "\n"; 00118 sizevar = Size(front.width(), front.height()); 00119 }
| int mx::mxWnd::messageLoop | ( | ) |
messageLoop this function is called when the app is ready to enter its messageLoop
Definition at line 141 of file mxwnd.cpp.
References active, eventPassed(), front, renderScreen(), resizeWindow(), and vid_flags.
00142 { 00143 00144 if(err_Type != 0) { 00145 00146 switch(err_Type) { 00147 case 1: 00148 throw mx::mxException<std::string>("Error could not init SDL: " + std::string(SDL_GetError()) + "\n"); 00149 break; 00150 case 2: 00151 throw mx::mxException<std::string>("Error could not set video mode: " + std::string(SDL_GetError()) + "\n"); 00152 break; 00153 } 00154 00155 } 00156 00157 static SDL_Event e; 00158 00159 active = true; 00160 00161 while(active == true) 00162 { 00163 00164 while(SDL_PollEvent(&e)) 00165 { 00166 00167 00168 switch(e.type) { 00169 case SDL_VIDEORESIZE: 00170 { 00171 const SDL_VideoInfo *vi = SDL_GetVideoInfo(); 00172 Uint8 bpp = vi->vfmt->BitsPerPixel; 00173 front = SDL_SetVideoMode( e.resize.w, e.resize.h, bpp, vid_flags ); 00174 resizeWindow(e.resize.w, e.resize.h); 00175 00176 } 00177 break; 00178 } 00179 00180 00181 eventPassed(e); 00182 } 00183 00184 renderScreen(); 00185 00186 } 00187 00188 return EXIT_SUCCESS; 00189 }
| void mx::mxWnd::minimizeWindow | ( | ) | const |
| mxSurface& mx::mxWnd::mxrenderSurface | ( | ) | [inline] |
| void mx::mxWnd::pumpEvents | ( | ) | const |
| void mx::mxWnd::quit | ( | ) |
| void mx::mxWnd::renderScreen | ( | ) | [virtual] |
virtual function for idle rendering overload this function in your subclass and the app will call this function when it has time to draw to the screen
Definition at line 206 of file mxwnd.cpp.
References mx::mxSurface::Flip(), front, mx::mxSurface::getSurface(), and opengl_.
Referenced by messageLoop().
00207 { 00208 00209 SDL_FillRect(front, 0, SDL_MapRGB(front.getSurface()->format, 255, 255, 255)); 00210 front.Flip(); 00211 00212 00213 if(opengl_) { 00214 00215 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00216 SDL_GL_SwapBuffers(); 00217 } 00218 00219 }
| SDL_Surface* mx::mxWnd::renderSurface | ( | ) | const [inline] |
return the SDL_Surface* for this window
Definition at line 98 of file mxwnd.h.
References front, and mx::mxSurface::getSurface().
00098 { return front.getSurface(); }
| void mx::mxWnd::resizeWindow | ( | int | w, | |
| int | h | |||
| ) | [virtual] |
resize the Window, virtual can be overloaded for custom perspectives
| w | width in pixels | |
| h | height in pixels |
Definition at line 254 of file mxwnd.cpp.
References d_type, and opengl_.
Referenced by messageLoop().
00255 { 00256 if(opengl_ == false) return; 00257 00258 00259 if(d_type == ORTHO) { 00260 00261 GLfloat range = 100.0f; 00262 00263 if(h == 0) h = 1; 00264 00265 glViewport(0,0,w,h); 00266 00267 glMatrixMode(GL_PROJECTION); 00268 glLoadIdentity(); 00269 00270 if(w<=h) 00271 glOrtho( -range, range, -range*h/w, range*h/w, -range, range); 00272 else 00273 glOrtho( -range*w/h, range*w/h, -range, range, -range, range); 00274 00275 glMatrixMode(GL_MODELVIEW); 00276 glLoadIdentity(); 00277 00278 } 00279 else { 00280 00281 if(h == 0) 00282 h = 1; 00283 00284 GLfloat ratio = 0.0f; 00285 ratio = static_cast<GLfloat>( w / h ); 00286 glViewport( 0, 0, static_cast<GLsizei>(w), static_cast<GLsizei>(h)); 00287 glMatrixMode(GL_PROJECTION); 00288 glLoadIdentity(); 00289 gluPerspective(45.0f, ratio, 0.1f, 200.0f); 00290 glMatrixMode(GL_MODELVIEW); 00291 glLoadIdentity(); 00292 } 00293 00294 }
| void mx::mxWnd::setMode | ( | lookType | type | ) |
| void mx::mxWnd::setTitle | ( | string | title | ) | const |
| Size & mx::mxWnd::size | ( | ) |
| void mx::mxWnd::sizedFlip | ( | ) |
sized Flip
Definition at line 249 of file mxwnd.cpp.
References background, mx::mxSurface::copyResizeSurface(), mx::mxSurface::Flip(), and front.
00249 { 00250 front.copyResizeSurface( background ); 00251 front.Flip(); 00252 }
| mxSurface& mx::mxWnd::sizedSurface | ( | ) | [inline] |
return this app's background sized surface for when init with Secondary constructor with Canvas parameter
Definition at line 110 of file mxwnd.h.
References background.
00110 { return background; }
bool mx::mxWnd::active [protected] |
active flag
Definition at line 128 of file mxwnd.h.
Referenced by eventPassed(), initWnd(), messageLoop(), and quit().
mxSurface mx::mxWnd::background [protected] |
background sized surface
Definition at line 126 of file mxwnd.h.
Referenced by createSizedBackground(), sizedFlip(), and sizedSurface().
lookType mx::mxWnd::d_type [protected] |
holds current perspective
Definition at line 142 of file mxwnd.h.
Referenced by initWnd(), resizeWindow(), and setMode().
mxSurface mx::mxWnd::front [protected] |
front surface object
Definition at line 124 of file mxwnd.h.
Referenced by initWnd(), messageLoop(), mxrenderSurface(), renderScreen(), renderSurface(), and sizedFlip().
mxWnd * mx::mxWnd::mxwnd = 0 [static, protected] |
bool mx::mxWnd::opengl_ [protected] |
holds state of OpenGL init
Definition at line 140 of file mxwnd.h.
Referenced by initWnd(), renderScreen(), and resizeWindow().
Size mx::mxWnd::sizevar [protected] |
Uint32 mx::mxWnd::vid_flags [protected] |
video flags for current state of the window
Definition at line 130 of file mxwnd.h.
Referenced by initWnd(), and messageLoop().
1.5.8