# HG changeset patch # User Eris Caffee # Date 1290656051 21600 # Node ID bdfe3327f4ce183b5635edc845fcbbb06d5bcb4c # Parent 3cf7403396439eede19d954cf546ef49d648fef6 Saving progress diff -r 3cf740339643 -r bdfe3327f4ce CMakeLists.txt --- a/CMakeLists.txt Sat Nov 20 02:12:01 2010 -0600 +++ b/CMakeLists.txt Wed Nov 24 21:34:11 2010 -0600 @@ -78,6 +78,18 @@ ################################################################################ +# Special options + +# Force SDL 1.3 only +if (WIN32) + set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-build") +else () + set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") +endif () +add_definitions(-DSDL_NO_COMPAT) + + +################################################################################ # Ensure that we are not building in our source directories. set (Build_Dir_OK "TRUE") @@ -108,7 +120,6 @@ endif () - ################################################################################ # When using GCC turn on lots of warnings. @@ -177,10 +188,6 @@ # CMake, then uncomment the if block below and put in the actual # locations of your SDL installation. -if (WIN32) - set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-1.2.14") -endif () - option(Option_SDL_Dev "Build an SDL application." ON) if (Option_SDL_Dev) diff -r 3cf740339643 -r bdfe3327f4ce include/App.h --- a/include/App.h Sat Nov 20 02:12:01 2010 -0600 +++ b/include/App.h Wed Nov 24 21:34:11 2010 -0600 @@ -71,16 +71,18 @@ // utility functions + bool create_new_surface(SDL_Surface * &surface); + bool init_sdl(); int mouse_move_width(int mx, int my); - bool create_new_surface(SDL_Surface * &surface); + void set_caption(); + static Uint32 timer_callback(Uint32 interval, void *param); + void set_julia_k(int x, int y); + void restore_view(); void save_view(); - void set_caption(); + bool save_image(); - - static Uint32 timer_callback(Uint32 interval, void *param); - int get_next_file_num(); #if !defined(WIN32) @@ -92,7 +94,7 @@ bool running; bool redraw; - SDL_Surface * surf_display; + SDL_Window * window; SDL_Surface * surf_selection; SDL_Surface * surf_fractal; diff -r 3cf740339643 -r bdfe3327f4ce include/EventHandler.h --- a/include/EventHandler.h Sat Nov 20 02:12:01 2010 -0600 +++ b/include/EventHandler.h Wed Nov 24 21:34:11 2010 -0600 @@ -31,6 +31,11 @@ #ifndef EVENTHANDLER_H #define EVENTHANDLER_H +// Use SDL 1.3 only! +#ifndef SDL_NO_COMPAT +#define SDL_NO_COMPAT +#endif + #include "SDL.h" class EventHandler @@ -42,18 +47,27 @@ virtual void on_Event(SDL_Event * event); - // Active events + // SDL_WindowEvent subtypes + virtual void on_Show(); + virtual void on_Hide(); + virtual void on_Expose(); + virtual void on_Move(SDL_WindowEvent window); + virtual void on_Resize(SDL_WindowEvent window); + virtual void on_Minimize(); + virtual void on_Maximize(); + virtual void on_Restore(); virtual void on_MouseFocus(); virtual void on_MouseBlur(); - virtual void on_InputFocus(); - virtual void on_InputBlur(); - virtual void on_Minimize(); - virtual void on_Restore(); - + virtual void on_KeyboardFocus(); + virtual void on_KeyboardBlur(); + // Note: on_Close() will call on_Quit() by default. + virtual void on_Close(); // Keyboard events virtual void on_KeyDown(SDL_KeyboardEvent key); virtual void on_KeyUp(SDL_KeyboardEvent key); + virtual void on_TextInput(SDL_TextInputEvent text); + virtual void on_TextEdit(SDL_TextEditingEvent edit); // Mouse events virtual void on_MouseMove(SDL_MouseMotionEvent motion); @@ -63,22 +77,21 @@ virtual void on_RButtonUp(SDL_MouseButtonEvent button); virtual void on_MButtonDown(SDL_MouseButtonEvent button); virtual void on_MButtonUp(SDL_MouseButtonEvent button); - virtual void on_MouseWheelDown(SDL_MouseButtonEvent motion); - virtual void on_MouseWheelUp(SDL_MouseButtonEvent motion); + virtual void on_MouseWheel(SDL_MouseWheelEvent wheel); // Joystick events virtual void on_JoyAxis(SDL_JoyAxisEvent jaxis); + virtual void on_JoyBall(SDL_JoyBallEvent jball); + virtual void on_JoyHat(SDL_JoyHatEvent jhat); virtual void on_JoyButtonDown(SDL_JoyButtonEvent jbutton); virtual void on_JoyButtonUp(SDL_JoyButtonEvent jbutton); - virtual void on_JoyHat(SDL_JoyHatEvent jhat); - virtual void on_JoyBall(SDL_JoyBallEvent jball); // Misc events - virtual void on_Resize(SDL_ResizeEvent resize); - virtual void on_Expose(); virtual void on_Quit(); virtual void on_User(SDL_UserEvent user); - virtual void on_SysWM(SDL_SysWMEvent syswm); + virtual void on_SysWMEvent(SDL_SysWMEvent syswm); + + // There's still a lot of new stuff not yet implemented here. }; diff -r 3cf740339643 -r bdfe3327f4ce src/App.cpp --- a/src/App.cpp Sat Nov 20 02:12:01 2010 -0600 +++ b/src/App.cpp Wed Nov 24 21:34:11 2010 -0600 @@ -59,7 +59,7 @@ App::App() : running (true), redraw (false), - surf_display (NULL), + window (NULL), surf_selection (NULL), surf_fractal (NULL), selection_x (-1), @@ -115,25 +115,11 @@ bool App::init() { - if ((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) == -1) + if (!init_sdl()) { - std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl; return false; } - if ((surf_display = SDL_SetVideoMode(Options::width, - Options::height, - Options::bpp, - SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) - { - std::cerr << "SDL_SetVideoMode() failed: " - << SDL_GetError() << std::endl; - return false; - } - - SDL_EnableKeyRepeat(500, 100); - - if (!create_new_surface(surf_selection)) { return false; } if (!create_new_surface(surf_fractal)) { return false; } @@ -157,11 +143,8 @@ can_set_julia_k = true; - set_caption(); - SDL_AddTimer(10, App::timer_callback, NULL); - return true; } @@ -180,8 +163,8 @@ if (redraw) { // Start with a clean slate. - SDL_FillRect(surf_display, &surf_display->clip_rect, - SDL_MapRGB(surf_display->format, 0, 0, 255)); + SDL_SetRenderDrawColor(0, 0, 0, SDL_ALPHA_OPAQUE); + SDL_RenderClear(); fractal->calc_set(); SDL_BlitSurface(surf_fractal, NULL, surf_display, NULL); @@ -193,7 +176,7 @@ } // Show it to the user. - SDL_Flip(surf_display); + SDL_RenderPresent(); redraw = false; } @@ -210,10 +193,10 @@ SDL_FreeSurface(surf_selection); surf_selection = NULL; } - if (surf_display) + if (window) { - SDL_FreeSurface(surf_display); - surf_display = NULL; + SDL_DestroyWindow(window); + window = NULL; } SDL_Quit(); @@ -457,28 +440,6 @@ //////////////////////////////////////////////////////////////////////////////// -int App::mouse_move_width(int mx, int my) - { - int move_width = (mx - selection_x); - if (mx > selection_x) - { - move_width *= -1; - } - - int tmp_i = (my - selection_y); - if (my < selection_y) - { - tmp_i *= -1; - } - - if (tmp_i > move_width) - move_width = tmp_i; - - return move_width; - } - - -//////////////////////////////////////////////////////////////////////////////// bool App::create_new_surface(SDL_Surface * &surface) { if (surface) @@ -507,6 +468,143 @@ //////////////////////////////////////////////////////////////////////////////// +bool init_sdl() + { + if ((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) == -1) + { + std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl; + return false; + } + + if ((window = SDL_CreateWindow("SDL 1.3 test", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + Options::width, Options::height, + 0)) == 0) + { + std::cerr << "SDL_CreateWindow() failed: " + << SDL_GetError() << std::endl; + return false; + } + + // Go through the available renderers and find the one we need. + // Do not use the x11 renderer. At least for now it is not working + // correctly.. + int max_drivers = SDL_GetNumRenderDrivers(); + if (max_drivers < 1) + { + std::cerr << "SDL_GetNumRenderDrivers() failed: " + << SDL_GetError() << std::endl; + return false; + } + + int driver = -1; + for(int index = 0; index < max_drivers ; index++) + { + SDL_RendererInfo info; + if(SDL_GetRenderDriverInfo(index, &info) != -1) + { + if (strncmp(info.name, "software", 8) == 0) driver = index; + std::cerr << "Driver " << info.name << " index: " + << index << std::endl; + } + else + { + std::cerr << "SDL_GetRenderDriverInfo() for index " << index + << " failed: " + << SDL_GetError() << std::endl; + return false; + } + } + + if (driver == -1) + { + std::cerr << "SDL software renderer not available!" << std::endl; + return false; + } + + if (SDL_CreateRenderer(window, -1, + SDL_RENDERER_PRESENTFLIP2 | + SDL_RENDERER_ACCELERATED) != 0) + { + std::cerr << "SDL_CreateRenderer() failed: " + << SDL_GetError() << std::endl; + return false; + } + + SDL_RendererInfo info; + if (SDL_GetRendererInfo(&info) == -1) + { + std::cerr << "SDL_GetRendererInfo() failed: " + << SDL_GetError() << std::endl; + return false; + } + std::cerr << "Renderer: " << info.name << std::endl; + + + if (SDL_AddTimer(10, App::timer_callback, NULL) == NULL) + { + std::cerr << "SDL_AddTimer() failed: " + << SDL_GetError() << std::endl; + return false; + } + + return true; + } + + +//////////////////////////////////////////////////////////////////////////////// +int App::mouse_move_width(int mx, int my) + { + int move_width = (mx - selection_x); + if (mx > selection_x) + { + move_width *= -1; + } + + int tmp_i = (my - selection_y); + if (my < selection_y) + { + tmp_i *= -1; + } + + if (tmp_i > move_width) + move_width = tmp_i; + + return move_width; + } + + +//////////////////////////////////////////////////////////////////////////////// +void App::set_caption() + { + std::stringstream ss; + ss << fractal->get_display_name() << " / " + << "Real: " << fractal->get_re_min() + << " to "<< fractal->get_re_min() + fractal->get_size() + << " / Imaginary: " << fractal->get_im_max() - fractal->get_size() + << " to " << fractal->get_im_max() + << " / Max iterations: " << fractal->get_max_iter(); + SDL_SetWindowTitel(window, ss.str().c_str()); + } + + +//////////////////////////////////////////////////////////////////////////////// +Uint32 App::timer_callback(Uint32 interval, void *param) + { + SDL_Event e; + + e.type = SDL_USEREVENT; + e.user.code = 0; + e.user.data1 = NULL; + e.user.data2 = NULL; + SDL_PushEvent(& e); + + return interval; + } + + +//////////////////////////////////////////////////////////////////////////////// void App::set_julia_k(int x, int y) { FractalFactory * fractal_factory = get_Fractal_map()[typeid(Julia).name()]; @@ -580,20 +678,6 @@ //////////////////////////////////////////////////////////////////////////////// -void App::set_caption() - { - std::stringstream ss; - ss << fractal->get_display_name() << " / " - << "Real: " << fractal->get_re_min() - << " to "<< fractal->get_re_min() + fractal->get_size() - << " / Imaginary: " << fractal->get_im_max() - fractal->get_size() - << " to " << fractal->get_im_max() - << " / Max iterations: " << fractal->get_max_iter(); - SDL_WM_SetCaption(ss.str().c_str(), NULL); - } - - -//////////////////////////////////////////////////////////////////////////////// bool App::save_image() { int i = App::get_next_file_num(); @@ -612,21 +696,6 @@ } -//////////////////////////////////////////////////////////////////////////////// -Uint32 App::timer_callback(Uint32 interval, void *param) - { - SDL_Event e; - - e.type = SDL_USEREVENT; - e.user.code = 0; - e.user.data1 = NULL; - e.user.data2 = NULL; - SDL_PushEvent(& e); - - return interval; - } - - #if defined(WIN32) //////////////////////////////////////////////////////////////////////////////// //Code for Windows