# HG changeset patch # User Eris Caffee # Date 1289627928 21600 # Node ID d691ce98f406e1fffd62aeb3f6221b87ea300163 # Parent df02a7de7fe2e9e423b7ccdfb525d0c3eddfe26d OK. This is the first release. Honest. diff -r df02a7de7fe2 -r d691ce98f406 CMakeLists.txt --- a/CMakeLists.txt Tue Oct 26 02:03:47 2010 -0500 +++ b/CMakeLists.txt Fri Nov 12 23:58:48 2010 -0600 @@ -2,22 +2,23 @@ # # A generalized cmake file for developing cross-platform games. # -# Copyright (c) 2010 Eris Caffee -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# Copyright (C) 2010 Sarah Eris Horsley Caffee +# +# This file is part of Fracter. +# +# Fracter is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# # # Instructions: # This cmake file assumes that your source files are laid in out in the @@ -67,7 +68,7 @@ #set (CMAKE_VERBOSE_MAKEFILE ON) # Name your program! -set (App_Name "mandelbrot") +set (App_Name "fracter") if (App_Name STREQUAL "") message (FATAL_ERROR "You must set the App_Name variable!") endif () @@ -107,6 +108,8 @@ endif () +add_definitions(-pedantic -Wall -Weffc++) + ################################################################################ # The core project files @@ -141,7 +144,6 @@ # Although we listed the library directories above, we also need to list the # individual libraries we will be linking against. target_link_libraries (${App_Name} - png ) @@ -161,12 +163,9 @@ if (WIN32) set (ENV{SDLDIR} "c:/gamedev/deps/sdl/SDL-1.2.14") - set (ENV{SDLIMAGEDIR} "c:/gamedev/deps/sdl/SDL_image-1.2.10") -# else () -# set (ENV{SDLDIR} "/home/eris/gamedev/deps/sdl/SDL-build") endif () -option(Option_SDL_Dev "Build an SDL application." OFF) +option(Option_SDL_Dev "Build an SDL application." ON) if (Option_SDL_Dev) @@ -186,25 +185,6 @@ ${TARGET_LINK_LIBRARIES} ) - # SDL_image - # Environment variables SDLIMAGEDIR and SDLDIR will be checked in that order - # and if set cmake will try to find SDL_image in the specified directory. - OPTION(Option_SDL_Dev_SDL_image "Use SDL_image." OFF) - IF (Option_SDL_Dev_SDL_image) - FIND_PACKAGE (SDL_image) - IF (NOT SDLIMAGE_FOUND) - MESSAGE (FATAL_ERROR "SDL_image not found!") - ENDIF (NOT SDLIMAGE_FOUND) - INCLUDE_DIRECTORIES( - ${SDLIMAGE_INCLUDE_DIR} - ${INCLUDE_DIRECTORIES} - ) - TARGET_LINK_LIBRARIES(${App_Name} - ${SDLIMAGE_LIBRARY} - ${TARGET_LINK_LIBRARIES} - ) - ENDIF (Option_SDL_Dev_SDL_image) - endif (Option_SDL_Dev) diff -r df02a7de7fe2 -r d691ce98f406 include/App.h --- a/include/App.h Tue Oct 26 02:03:47 2010 -0500 +++ b/include/App.h Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,24 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // App.h // Application class definition @@ -29,40 +45,36 @@ int run(); + private: + // Disallow copy constructor and operator= + App(const App &); + App & operator=(const App &); - private: - + // main loop functions bool init(); void update(); void render(); void cleanup(); + // Overrides of EventHandler: - void on_event(SDL_Event * event); - void on_KeyDown(SDLKey sym, SDLMod mod, Uint16 unicode); - void on_KeyUp(SDLKey sym, SDLMod mod, Uint16 unicode); - void on_Exit(); - void on_LButtonDown(int mx, int my); - void on_LButtonUp(int mx, int my); - void on_RButtonDown(int mx, int my); - void on_MouseMove(int mx, int my, - int relx, int rely, - bool left, bool right, bool middle); - void on_Resize(int w, int h); + void on_KeyDown(SDL_KeyboardEvent key); + void on_KeyUp(SDL_KeyboardEvent key); + void on_MouseMove(SDL_MouseMotionEvent motion); + void on_LButtonDown(SDL_MouseButtonEvent button); + void on_LButtonUp(SDL_MouseButtonEvent button); + void on_Resize(SDL_ResizeEvent resize); void on_Expose(); + void on_Quit(); + // utility functions int mouse_move_width(int mx, int my); - bool create_new_surface(SDL_Surface * &surface); - 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); @@ -73,6 +85,8 @@ static int scandir_filter(const struct dirent * d); #endif + + // data members bool running; bool redraw; @@ -85,13 +99,7 @@ bool can_set_julia_k; bool setting_julia_k; - struct view - { - std::string type; - double re_min, im_max, size; - unsigned int max_iter; - }; - static std::vector old_views; + static std::vector old_views; Fractal * fractal; }; diff -r df02a7de7fe2 -r d691ce98f406 include/EventHandler.h --- a/include/EventHandler.h Tue Oct 26 02:03:47 2010 -0500 +++ b/include/EventHandler.h Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,24 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // EventHandler.h // EventHandler class definition. This is a virtual class that is meant to be @@ -24,37 +40,46 @@ EventHandler(); virtual ~EventHandler(); -#ifndef USE_SDL_WAITEVENT - virtual int wait_event_timeout(SDL_Event * event, Uint32 timeout); -#endif - virtual void on_event(SDL_Event * event); + // Active events + virtual void on_MouseFocus(); + virtual void on_MouseBlur(); virtual void on_InputFocus(); virtual void on_InputBlur(); - virtual void on_KeyDown(SDLKey sym, SDLMod mod, Uint16 unicode); - virtual void on_KeyUp(SDLKey sym, SDLMod mod, Uint16 unicode); - virtual void on_MouseFocus(); - virtual void on_MouseBlur(); - virtual void on_MouseMove(int mx, int my, int relx, int rely, bool left, bool right, bool middle); - virtual void on_MouseWheel(bool up, bool down); - virtual void on_LButtonDown(int mx, int my); - virtual void on_LButtonUp(int mx, int my); - virtual void on_RButtonDown(int mx, int my); - virtual void on_RButtonUp(int mx, int my); - virtual void on_MButtonDown(int mx, int my); - virtual void on_MButtonUp(int mx, int my); - virtual void on_JoyAxis(Uint8 ehich, Uint8 axis, Sint16 value); - virtual void on_JoyButtonDown(Uint8 which, Uint8 button); - virtual void on_JoyButtonUp(Uint8 which, Uint8 button); - virtual void on_JoyHat(Uint8 which, Uint8 hat, Uint8 value); - virtual void on_JoyBall(Uint8 which, Uint8 ball, Sint16 xrel, Sint16 yrel); virtual void on_Minimize(); virtual void on_Restore(); - virtual void on_Resize(int w, int h); + + + // Keyboard events + virtual void on_KeyDown(SDL_KeyboardEvent key); + virtual void on_KeyUp(SDL_KeyboardEvent key); + + // Mouse events + virtual void on_MouseMove(SDL_MouseMotionEvent motion); + virtual void on_LButtonDown(SDL_MouseButtonEvent button); + virtual void on_LButtonUp(SDL_MouseButtonEvent button); + virtual void on_RButtonDown(SDL_MouseButtonEvent button); + 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); + + // Joystick events + virtual void on_JoyAxis(SDL_JoyAxisEvent jaxis); + 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_Exit(); - virtual void on_User(Uint8 type, int code, void * data1, void * data2); + virtual void on_Quit(); + virtual void on_User(SDL_UserEvent user); + virtual void on_SysWM(SDL_SysWMEvent syswm); + }; #endif diff -r df02a7de7fe2 -r d691ce98f406 include/Fractal.h --- a/include/Fractal.h Tue Oct 26 02:03:47 2010 -0500 +++ b/include/Fractal.h Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,25 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// // // Fractal.h // Fractal calculator virtual class definition. Actual fractals should @@ -15,19 +32,43 @@ #include #include +#include -// Need to define this via the pre-processor because if it's a staticaly -// initialized const string we still have no guarantee that it will be -// initialized before it is needed by a FractalCreator class. -// Do the same in all derived classes. +#include "SDL.h" +//////////////////////////////////////////////////////////////////////////////// +class View + { + public: + View(std::string t, + double re, double im, double s, + unsigned int max); + virtual ~View(); + + std::string const & get_type() const; + + + private: + friend class Fractal; + + View(); + View & operator=(const View &); + + std::string type; + double re_min, im_max, size; + unsigned int max_iter; + }; + + +//////////////////////////////////////////////////////////////////////////////// class Fractal { public: Fractal(); + virtual ~Fractal(); virtual bool calc_set() = 0; - virtual bool init(SDL_Surface * surf) = 0; + virtual bool init(SDL_Surface * surf); double get_re_min() const; double set_re_min(const double r_min); @@ -49,10 +90,11 @@ virtual std::string const & get_fractal_name() const; - virtual bool get_option(std::string option, void * value) const {}; - virtual bool set_option(std::string option, void * value) {}; + virtual bool get_option(std::string option, void * value) const; + virtual bool set_option(std::string option, void * value); - + virtual View * save_view(); + virtual void restore_view(View * v); protected: @@ -65,22 +107,41 @@ std::string display_name; std::string fractal_name; + + // The dimensions in the complex plane of the calculated image. + // Square image only with die of length "size". + // Upper left corner of the region is (re_min, im_max) double re_min; double im_max; double size; + + // Number of iterations to perform when calculating. unsigned int max_iter; + + // Set to true if the image needs to be recalculated. bool calc_needed; + // Our drawing surface. SDL_Surface * surface; - + + private: + // Disallow copy constructor and operator= + Fractal(const Fractal &); + Fractal & operator=(const Fractal &); }; -class FractalCreator + + +//////////////////////////////////////////////////////////////////////////////// +// Abstract Factory class. +// A singleton, but it's not thread safe. +class FractalFactory { public: + virtual ~FractalFactory(); virtual Fractal * create() const = 0; }; -std::map & get_Fractal_map(); +std::map & get_Fractal_map(); #endif diff -r df02a7de7fe2 -r d691ce98f406 include/Julia.h --- a/include/Julia.h Tue Oct 26 02:03:47 2010 -0500 +++ b/include/Julia.h Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,24 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // Julia.h // Julia set calculator class definition @@ -13,29 +29,43 @@ #define JULIA_H #include + #include -#include - -#include "SDL.h" #include "Fractal.h" +//////////////////////////////////////////////////////////////////////////////// +class ViewJulia : public View + { + public: + ViewJulia(std::string t, + double re, double im, double s, + unsigned int max, + double kr, double ki); + + private: + friend class Julia; + + double k_re; + double k_im; + + }; + +//////////////////////////////////////////////////////////////////////////////// class Julia : public Fractal { public: Julia(); bool calc_set(); - bool init(SDL_Surface * surf); bool get_option(std::string option, void * value) const; bool set_option(std::string option, void * value); - - std::string const & get_fractal_name() const; + ViewJulia * save_view(); + void restore_view(View * v); private: - void draw_pixel(int x, int y, Uint32 * color); void set_display_name(); double k_re; @@ -43,21 +73,21 @@ }; +//////////////////////////////////////////////////////////////////////////////// namespace { - class JuliaCreator : public FractalCreator + class JuliaFactory : public FractalFactory { public: - JuliaCreator() + JuliaFactory() { - std::cerr << "Julia is called >" << typeid(Julia).name() << "<" << std::endl; get_Fractal_map()[typeid(Julia).name()]=this; } - virtual Fractal * create() const + Fractal * create() const { return new Julia; } - } the_Julia_creator; + } the_Julia_factory; } #endif diff -r df02a7de7fe2 -r d691ce98f406 include/Mandelbrot.h --- a/include/Mandelbrot.h Tue Oct 26 02:03:47 2010 -0500 +++ b/include/Mandelbrot.h Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,24 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // Mandelbrot.h // Mandelbrot set calculator class definition @@ -12,43 +28,54 @@ #ifndef MANDELBROT_H #define MANDELBROT_H -#include -#include - -#include "SDL.h" +#include #include "Fractal.h" +//////////////////////////////////////////////////////////////////////////////// +class ViewMandelbrot : public View + { + public: + ViewMandelbrot(std::string t, + double re, double im, double s, + unsigned int max); + + private: + friend class Mandelbrot; + + }; + +//////////////////////////////////////////////////////////////////////////////// class Mandelbrot : public Fractal { public: Mandelbrot(); bool calc_set(); - bool init(SDL_Surface * surf); - std::string const & get_fractal_name() const; + ViewMandelbrot * save_view(); + void restore_view(View * v); private: - void draw_pixel(int x, int y, Uint32 * color); }; +//////////////////////////////////////////////////////////////////////////////// namespace { - class MandelbrotCreator : public FractalCreator + class MandelbrotFactory : public FractalFactory { public: - MandelbrotCreator() + MandelbrotFactory() { get_Fractal_map()[typeid(Mandelbrot).name()]=this; } - virtual Fractal * create() const + Fractal * create() const { return new Mandelbrot; } - } the_Mandelbrot_creator; + } the_Mandelbrot_factory; } #endif diff -r df02a7de7fe2 -r d691ce98f406 include/Options.h --- a/include/Options.h Tue Oct 26 02:03:47 2010 -0500 +++ b/include/Options.h Fri Nov 12 23:58:48 2010 -0600 @@ -1,10 +1,26 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee // -// options.h +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// +// Options.h // global variables and definitions // //////////////////////////////////////////////////////////////////////////////// @@ -12,8 +28,8 @@ #ifndef OPTIONS_H #define OPTIONS_H -#include +// No real reason to make this a class, except in planning for the future. class Options { public: diff -r df02a7de7fe2 -r d691ce98f406 src/App.cpp --- a/src/App.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/App.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,24 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // App.cpp // Application class implementation @@ -38,8 +54,7 @@ #include "Julia.h" - -std::vector App::old_views; +std::vector App::old_views; //////////////////////////////////////////////////////////////////////////////// @@ -54,7 +69,8 @@ selection_width (-1), setting_zoom (false), can_set_julia_k (false), - setting_julia_k (false) + setting_julia_k (false), + fractal (NULL) { } @@ -123,19 +139,19 @@ std::cerr << "Available fractal types are" << std::endl; - std::map mymap = get_Fractal_map(); - std::map ::iterator it; + std::map mymap = get_Fractal_map(); + std::map ::iterator it; for ( it=mymap.begin() ; it != mymap.end(); it++ ) std::cerr << " " << (*it).first << std::endl; - FractalCreator * fractal_creator = + FractalFactory * fractal_factory = get_Fractal_map()[typeid(Mandelbrot).name()]; - if (!fractal_creator) + if (!fractal_factory) { std::cerr << "Mandelbrot set not available!" << std::endl; return false; } - fractal = fractal_creator->create(); + fractal = fractal_factory->create(); fractal->init(surf_fractal); redraw = true; @@ -144,7 +160,7 @@ set_caption(); - SDL_TimerID timer_id = SDL_AddTimer(10, App::timer_callback, NULL); + SDL_AddTimer(10, App::timer_callback, NULL); return true; } @@ -206,17 +222,9 @@ //////////////////////////////////////////////////////////////////////////////// -void App::on_event(SDL_Event * event) +void App::on_KeyDown(SDL_KeyboardEvent key) { - EventHandler::on_event(event); - } - - -//////////////////////////////////////////////////////////////////////////////// - -void App::on_KeyDown(SDLKey sym, SDLMod mod, Uint16 unicode) - { - switch (sym) + switch (key.keysym.sym) { case SDLK_ESCAPE: case SDLK_q: @@ -248,32 +256,34 @@ case SDLK_m: if (fractal) { - save_view(); - delete fractal; - FractalCreator * fractal_creator = + FractalFactory * fractal_factory = get_Fractal_map()[typeid(Mandelbrot).name()]; - if (!fractal_creator) + if (!fractal_factory) { std::cerr << "Mandelbrot set not available!" << std::endl; SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent(&event); - break; } - fractal = fractal_creator->create(); - fractal->init(surf_fractal); - fractal->set_calc_needed(); - redraw = true; - set_caption(); - can_set_julia_k = true; + else + { + save_view(); + delete fractal; + fractal = fractal_factory->create(); + fractal->init(surf_fractal); + redraw = true; + set_caption(); + can_set_julia_k = true; + } } break; + case SDLK_j: if (fractal) { - FractalCreator * fractal_creator = + FractalFactory * fractal_factory = get_Fractal_map()[typeid(Julia).name()]; - if (!fractal_creator) + if (!fractal_factory) { std::cerr << "Julia set not available!" << std::endl; } @@ -281,9 +291,8 @@ { save_view(); delete fractal; - fractal = fractal_creator->create(); + fractal = fractal_factory->create(); fractal->init(surf_fractal); - fractal->set_calc_needed(); redraw = true; set_caption(); can_set_julia_k = false; @@ -306,9 +315,9 @@ //////////////////////////////////////////////////////////////////////////////// -void App::on_KeyUp(SDLKey sym, SDLMod mod, Uint16 unicode) +void App::on_KeyUp(SDL_KeyboardEvent key) { - switch (sym) + switch (key.keysym.sym) { case SDLK_UP: fractal->set_calc_needed(); @@ -318,30 +327,54 @@ fractal->set_calc_needed(); redraw = true; break; + default: + break; } } //////////////////////////////////////////////////////////////////////////////// +void App::on_MouseMove(SDL_MouseMotionEvent motion) + { + if (setting_zoom) + { + Uint32 clear = SDL_MapRGBA(surf_selection->format, + 0, 0, 0, SDL_ALPHA_TRANSPARENT); + Uint32 white = SDL_MapRGBA(surf_selection->format, + 255, 255, 255, SDL_ALPHA_OPAQUE); -void App::on_Exit() - { - running = false; + SDL_FillRect(surf_selection, &surf_selection->clip_rect, clear); + + SDL_Rect rect; + rect.x = selection_x; + rect.y = selection_y; + int w = mouse_move_width(motion.x, motion.y); + rect.w = rect.h = w; + + SDL_FillRect(surf_selection, &rect, white); + + rect.x = selection_x + 1; + rect.y = selection_y + 1; + rect.w = rect.h = w - 2; + + SDL_FillRect(surf_selection, &rect, clear); + + redraw = true; + } } - //////////////////////////////////////////////////////////////////////////////// -void App::on_LButtonDown(int mx, int my) +void App::on_LButtonDown(SDL_MouseButtonEvent button) { if (setting_julia_k) { - set_julia_k(mx, my); + set_julia_k(button.x, button.y); } else { - selection_x = mx; - selection_y = my; + selection_x = button.x; + selection_y = button.y; setting_zoom = true; } } @@ -349,22 +382,22 @@ //////////////////////////////////////////////////////////////////////////////// -void App::on_LButtonUp(int mx, int my) +void App::on_LButtonUp(SDL_MouseButtonEvent button) { if (setting_zoom) { - if ( (mx <= 0) || - (mx >= surf_display->w - 1) || - (my <= 0) || - (my >= surf_display->h - 1)) + selection_width = mouse_move_width(button.x, button.y); + if ( (button.x <= 0) || + (button.x >= surf_display->w - 1) || + (button.y <= 0) || + (button.y >= surf_display->h - 1) || + (selection_width == 0)) { // Selection cancelled setting_zoom = false; return; } - selection_width = mouse_move_width(mx, my); - // calculate new min/max re/im double Re_scale = (fractal->get_size())/(surf_fractal->w - 1); double Im_scale = (fractal->get_size())/(surf_fractal->h - 1); @@ -373,7 +406,6 @@ double new_im_max = fractal->get_im_max() - (selection_y) * Im_scale; double new_size = selection_width * Re_scale; - save_view(); fractal->set_re_min(new_re_min); @@ -390,51 +422,7 @@ //////////////////////////////////////////////////////////////////////////////// - -void App::on_RButtonDown(int mx, int my) - { - if (can_set_julia_k) - { - set_julia_k(mx, my); - } - } - - -//////////////////////////////////////////////////////////////////////////////// -void App::on_MouseMove(int mx, int my, - int relx, int rely, - bool left, bool right, bool middle) - { - if (setting_zoom) - { - Uint32 clear = SDL_MapRGBA(surf_selection->format, - 0, 0, 0, SDL_ALPHA_TRANSPARENT); - Uint32 white = SDL_MapRGBA(surf_selection->format, - 255, 255, 255, SDL_ALPHA_OPAQUE); - - SDL_FillRect(surf_selection, &surf_selection->clip_rect, clear); - - SDL_Rect rect; - rect.x = selection_x; - rect.y = selection_y; - int w = mouse_move_width(mx, my); - rect.w = rect.h = w; - - SDL_FillRect(surf_selection, &rect, white); - - rect.x = selection_x + 1; - rect.y = selection_y + 1; - rect.w = rect.h = w - 2; - - SDL_FillRect(surf_selection, &rect, clear); - - redraw = true; - } - } - - -//////////////////////////////////////////////////////////////////////////////// -void App::on_Resize(int w, int h) +void App::on_Resize(SDL_ResizeEvent resize) { redraw = true; } @@ -448,6 +436,14 @@ //////////////////////////////////////////////////////////////////////////////// + +void App::on_Quit() + { + running = false; + } + + +//////////////////////////////////////////////////////////////////////////////// int App::mouse_move_width(int mx, int my) { int move_width = (mx - selection_x); @@ -500,25 +496,26 @@ //////////////////////////////////////////////////////////////////////////////// void App::set_julia_k(int x, int y) { - save_view(); - - double k[2]; - k[0]= fractal->get_re_min() + x * - (fractal->get_size())/(surf_fractal->w - 1); - k[1] = fractal->get_im_max() - y * - (fractal->get_size())/(surf_fractal->h - 1); - - FractalCreator * fractal_creator = get_Fractal_map()[typeid(Julia).name()]; - if (!fractal_creator) + FractalFactory * fractal_factory = get_Fractal_map()[typeid(Julia).name()]; + if (!fractal_factory) { std::cerr << "Julia set not available!" << std::endl; return; } else { + save_view(); + delete fractal; - fractal = fractal_creator->create(); + fractal = fractal_factory->create(); fractal->init(surf_fractal); + + double k[2]; + k[0]= fractal->get_re_min() + x * + (fractal->get_size())/(surf_fractal->w - 1); + k[1] = fractal->get_im_max() - y * + (fractal->get_size())/(surf_fractal->h - 1); + fractal->set_option("k", k); fractal->set_calc_needed(); redraw = true; @@ -535,39 +532,27 @@ { if (old_views.size() > 0) { - view * v = old_views.back(); + View * v = old_views.back(); old_views.pop_back(); - if (v->type.compare(fractal->get_fractal_name()) != 0) + if (v->get_type().compare(fractal->get_fractal_name()) != 0) { delete fractal; - FractalCreator * fractal_creator = get_Fractal_map()[v->type]; - if (!fractal_creator) + FractalFactory * fractal_factory = get_Fractal_map()[v->get_type()]; + if (!fractal_factory) { std::cerr << "Cannot restore old view: unknown Fractal type " - << v->type << std::endl; + << v->get_type() << std::endl; SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent(&event); return; } - fractal = fractal_creator->create(); + fractal = fractal_factory->create(); fractal->init(surf_fractal); } - fractal->set_re_min(v->re_min); - fractal->set_im_max(v->im_max); - fractal->set_size(v->size); - fractal->set_max_iter(v->max_iter); - fractal->set_calc_needed(); - - std::cerr << "Restored view:" << std::endl - << " type " << v->type << std::endl - << " re_min " << v->re_min << std::endl - << " im_max " << v->im_max << std::endl - << " size " << v->size << std::endl - << " max_iter " << v->max_iter << std::endl - << std::endl; + fractal->restore_view(v); delete v; } } @@ -576,21 +561,8 @@ //////////////////////////////////////////////////////////////////////////////// void App::save_view() { - view * v = new view; - v->type = typeid(*fractal).name(); - v->re_min = fractal->get_re_min(); - v->im_max = fractal->get_im_max(); - v->size = fractal->get_size(); - v->max_iter = fractal->get_max_iter(); + View * v = fractal->save_view(); old_views.push_back(v); - - std::cerr << "Saved view:" << std::endl - << " type " << v->type << std::endl - << " re_min " << v->re_min << std::endl - << " im_max " << v->im_max << std::endl - << " size " << v->size << std::endl - << " max_iter " << v->max_iter << std::endl - << std::endl; } @@ -613,7 +585,7 @@ { int i = App::get_next_file_num(); std::stringstream name; - name << "mandelbrot-" << std::setw(3) << std::setfill('0') << i << ".bmp"; + name << "fracter-" << std::setw(3) << std::setfill('0') << i << ".bmp"; if (SDL_SaveBMP(surf_display, name.str().c_str()) != 0) { @@ -654,7 +626,7 @@ WIN32_FIND_DATA ffd; HANDLE hFind = INVALID_HANDLE_VALUE; - char * file_spec = "mandelbrot-???.bmp"; + char * file_spec = "fracter-???.bmp"; hFind = FindFirstFile(file_spec, &ffd); if (hFind != INVALID_HANDLE_VALUE) { @@ -667,7 +639,7 @@ if (ss.str().size() == 18) { s = ss.str().substr(0, 11); - if ( StrCmpI(s.c_str(), "mandelbrot-") == 0 ) + if ( StrCmpI(s.c_str(), "fracter-") == 0 ) { s = ss.str().substr(14, 4); if (StrCmpI(s.c_str(), ".bmp") == 0) @@ -695,11 +667,11 @@ int App::scandir_filter(const struct dirent * d) { - if (memcmp(d->d_name, "mandelbrot-", 11) != 0) return 0; - if (memcmp(d->d_name+14, ".bmp", 4) != 0) return 0; - if (isdigit(d->d_name[11]) - && isdigit(d->d_name[12]) - && isdigit(d->d_name[13])) + if (memcmp(d->d_name, "fracter-", 8) != 0) return 0; + if (memcmp(d->d_name+11, ".bmp", 4) != 0) return 0; + if (isdigit(d->d_name[8]) + && isdigit(d->d_name[9]) + && isdigit(d->d_name[10])) return 1; return 0; } @@ -714,7 +686,7 @@ struct dirent ** file_list; int num_files = scandir(".", &file_list, scandir_filter, alphasort); if (num_files != 0) - sscanf(file_list[num_files-1]->d_name, "mandelbrot-%03d.bmp", &i); + sscanf(file_list[num_files-1]->d_name, "fracter-%03d.bmp", &i); } i++; diff -r df02a7de7fe2 -r d691ce98f406 src/EventHandler.cpp --- a/src/EventHandler.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/EventHandler.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,14 +1,29 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // EventHandler.cpp // EventHandler class implementation. // //////////////////////////////////////////////////////////////////////////////// -#include #include "EventHandler.h" @@ -19,45 +34,12 @@ } - //////////////////////////////////////////////////////////////////////////////// EventHandler::~EventHandler() { } - -//////////////////////////////////////////////////////////////////////////////// -// Note: SDL 1.3 adds an official SDL_WaitEventTimeout function. -#ifndef USE_SDL_WAIEVENT -int EventHandler::wait_event_timeout(SDL_Event * event, Uint32 timeout) - { - Uint32 end = SDL_GetTicks() + timeout; - int i; - - for (;;) - { - SDL_PumpEvents(); - i = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS); - switch (i) - { - case -1: - return 0; - case 1: - return 1; - case 0: - if (SDL_GetTicks() >= end) - { - return 0; - } - SDL_Delay(10); - break; - } - } - } -#endif - - //////////////////////////////////////////////////////////////////////////////// void EventHandler::on_event(SDL_Event * event) { @@ -88,27 +70,21 @@ } break; } + case SDL_KEYDOWN: { - on_KeyDown(event->key.keysym.sym, event->key.keysym.mod, - event->key.keysym.unicode); + on_KeyDown(event->key); break; } case SDL_KEYUP: { - on_KeyUp(event->key.keysym.sym, event->key.keysym.mod, - event->key.keysym.unicode); + on_KeyUp(event->key); break; } + case SDL_MOUSEMOTION: { - on_MouseMove(event->motion.x, - event->motion.y, - event->motion.xrel, - event->motion.yrel, - (event->motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) !=0, - (event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) !=0, - (event->motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0); + on_MouseMove(event->motion); break; } case SDL_MOUSEBUTTONDOWN: @@ -117,17 +93,22 @@ { case SDL_BUTTON_LEFT: { - on_LButtonDown(event->button.x, event->button.y); + on_LButtonDown(event->button); break; } case SDL_BUTTON_RIGHT: { - on_RButtonDown(event->button.x, event->button.y); + on_RButtonDown(event->button); break; } case SDL_BUTTON_MIDDLE: { - on_MButtonDown(event->button.x, event->button.y); + on_MButtonDown(event->button); + break; + } + case SDL_BUTTON_WHEELDOWN: + { + on_MouseWheelDown(event->button); break; } } @@ -139,61 +120,57 @@ { case SDL_BUTTON_LEFT: { - on_LButtonUp(event->button.x, event->button.y); + on_LButtonUp(event->button); break; } case SDL_BUTTON_RIGHT: { - on_RButtonUp(event->button.x, event->button.y); + on_RButtonUp(event->button); break; } case SDL_BUTTON_MIDDLE: { - on_MButtonUp(event->button.x, event->button.y); + on_MButtonUp(event->button); + break; + } + case SDL_BUTTON_WHEELUP: + { + on_MouseWheelUp(event->button); break; } } break; } + case SDL_JOYAXISMOTION: { - on_JoyAxis(event->jaxis.which, event->jaxis.axis, event->jaxis.value); + on_JoyAxis(event->jaxis); break; } case SDL_JOYBALLMOTION: { - on_JoyBall(event->jball.which, event->jball.ball, - event->jball.xrel, event->jball.yrel); + on_JoyBall(event->jball); break; } case SDL_JOYHATMOTION: { - on_JoyHat(event->jhat.which, event->jhat.hat, event->jhat.value); + on_JoyHat(event->jhat); break; } case SDL_JOYBUTTONDOWN: { - on_JoyButtonDown(event->jbutton.which, event->jbutton.button); + on_JoyButtonDown(event->jbutton); break; } case SDL_JOYBUTTONUP: { - on_JoyButtonUp(event->jbutton.which, event->jbutton.button); + on_JoyButtonUp(event->jbutton); break; } - case SDL_QUIT: - { - on_Exit(); - break; - } - case SDL_SYSWMEVENT: - { - // Ignore - break; - } + case SDL_VIDEORESIZE: { - on_Resize(event->resize.w, event->resize.h); + on_Resize(event->resize); break; } case SDL_VIDEOEXPOSE: @@ -201,10 +178,36 @@ on_Expose(); break; } + case SDL_QUIT: + { + on_Quit(); + break; + } + case SDL_SYSWMEVENT: + { + on_SysWM(event->syswm); + break; + } + + case SDL_NOEVENT: + case SDL_EVENT_RESERVEDA: + case SDL_EVENT_RESERVEDB: + case SDL_EVENT_RESERVED2: + case SDL_EVENT_RESERVED3: + case SDL_EVENT_RESERVED4: + case SDL_EVENT_RESERVED5: + case SDL_EVENT_RESERVED6: + case SDL_EVENT_RESERVED7: + case SDL_NUMEVENTS: + { + // Reserved events are silently ignored. + break; + } + default: { - on_User(event->user.type, event->user.code, - event->user.data1, event->user.data2); + // All other events are user events. + on_User(event->user); break; } } @@ -213,129 +216,125 @@ //////////////////////////////////////////////////////////////////////////////// + +// Active events + +void EventHandler::on_MouseFocus() + { + } + +void EventHandler::on_MouseBlur() + { + } + void EventHandler::on_InputFocus() { } - void EventHandler::on_InputBlur() { } - -void EventHandler::on_KeyDown(SDLKey sym, SDLMod mod, Uint16 unicode) - { - } - - -void EventHandler::on_KeyUp(SDLKey sym, SDLMod mod, Uint16 unicode) - { - } - - -void EventHandler::on_MouseFocus() - { - } - - -void EventHandler::on_MouseBlur() - { - } - -void EventHandler::on_MouseMove(int mx, int my, - int relx, int rely, - bool left, bool right, bool middle) - { - } - - -void EventHandler::on_MouseWheel(bool up, bool down) - { - } - - -void EventHandler::on_LButtonDown(int mx, int my) - { - } - - -void EventHandler::on_LButtonUp(int mx, int my) - { - } - - -void EventHandler::on_RButtonDown(int mx, int my) - { - } - - -void EventHandler::on_RButtonUp(int mx, int my) - { - } - - -void EventHandler::on_MButtonDown(int mx, int my) - { - } - - -void EventHandler::on_MButtonUp(int mx, int my) - { - } - - -void EventHandler::on_JoyAxis(Uint8 ehich, Uint8 axis, Sint16 value) - { - } - - -void EventHandler::on_JoyButtonDown(Uint8 which, Uint8 button) - { - } - - -void EventHandler::on_JoyButtonUp(Uint8 which, Uint8 button) - { - } - - -void EventHandler::on_JoyHat(Uint8 which, Uint8 hat, Uint8 value) - { - } - - -void EventHandler::on_JoyBall(Uint8 which, Uint8 ball, Sint16 xrel, Sint16 yrel) - { - } - - void EventHandler::on_Minimize() { } - void EventHandler::on_Restore() { } -void EventHandler::on_Resize(int w, int h) +// Keyboard events + +void EventHandler::on_KeyDown(SDL_KeyboardEvent key) { } +void EventHandler::on_KeyUp(SDL_KeyboardEvent key) + { + } + + +// Mouse events + +void EventHandler::on_MouseMove(SDL_MouseMotionEvent motion) + { + } + +void EventHandler::on_LButtonDown(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_LButtonUp(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_RButtonDown(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_RButtonUp(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_MButtonDown(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_MButtonUp(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_MouseWheelDown(SDL_MouseButtonEvent button) + { + } + +void EventHandler::on_MouseWheelUp(SDL_MouseButtonEvent button) + { + } + + +// Joystick events + +void EventHandler::on_JoyAxis(SDL_JoyAxisEvent jaxis) + { + } + +void EventHandler::on_JoyButtonDown(SDL_JoyButtonEvent jbutton) + { + } + +void EventHandler::on_JoyButtonUp(SDL_JoyButtonEvent jbutton) + { + } + +void EventHandler::on_JoyHat(SDL_JoyHatEvent jhat) + { + } + +void EventHandler::on_JoyBall(SDL_JoyBallEvent jball) + { + } + + +// Misc events + +void EventHandler::on_Resize(SDL_ResizeEvent resize) + { + } void EventHandler::on_Expose() { } - -void EventHandler::on_Exit() +void EventHandler::on_Quit() { } - -void EventHandler::on_User(Uint8 type, int code, void * data1, void * data2) +void EventHandler::on_User(SDL_UserEvent user) { } - +void EventHandler::on_SysWM(SDL_SysWMEvent syswm) + { + } diff -r df02a7de7fe2 -r d691ce98f406 src/Fractal.cpp --- a/src/Fractal.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/Fractal.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,8 +1,25 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// // // Fractal.cpp // Fractal calculator virtual class implementation. Actual fractals should @@ -10,12 +27,30 @@ // //////////////////////////////////////////////////////////////////////////////// -#include - -#include "SDL.h" - #include "Fractal.h" +//////////////////////////////////////////////////////////////////////////////// +View::View(std::string t, + double re, double im, double s, + unsigned int max) : + type (t), + re_min (re), + im_max (im), + size (s), + max_iter (max) + { + } + +//////////////////////////////////////////////////////////////////////////////// +View::~View() + { + } + +//////////////////////////////////////////////////////////////////////////////// +std::string const & View::get_type() const + { + return type; + } //////////////////////////////////////////////////////////////////////////////// @@ -26,11 +61,34 @@ im_max (0), size (0), max_iter (0), - surface (NULL), - calc_needed (false) + calc_needed (false), + surface (NULL) { } + +//////////////////////////////////////////////////////////////////////////////// +Fractal::~Fractal() + { + } + + +//////////////////////////////////////////////////////////////////////////////// +bool Fractal::init(SDL_Surface * surf) + { + if (!surf) + { + return false; + } + else + { + surface = surf; + } + calc_needed = true; + return true; + } + + //////////////////////////////////////////////////////////////////////////////// double Fractal::get_re_min() const { @@ -73,7 +131,7 @@ //////////////////////////////////////////////////////////////////////////////// double Fractal::set_size(const double s) { - double t; + double t = size; if (s > 0.0) size = s; else @@ -92,7 +150,7 @@ //////////////////////////////////////////////////////////////////////////////// unsigned int Fractal::set_max_iter(const unsigned int iter) { - unsigned int t; + unsigned int t = max_iter; if (iter > 0) max_iter = iter; else @@ -104,7 +162,7 @@ //////////////////////////////////////////////////////////////////////////////// unsigned int Fractal::inc_max_iter() { - unsigned int t; + unsigned int t = max_iter; max_iter++; return t; } @@ -113,7 +171,7 @@ //////////////////////////////////////////////////////////////////////////////// unsigned int Fractal::dec_max_iter() { - unsigned int t; + unsigned int t = max_iter; if (max_iter > 0) max_iter--; return t; @@ -142,6 +200,36 @@ //////////////////////////////////////////////////////////////////////////////// +bool Fractal::get_option(std::string option, void * value) const + { + return false; + } + +//////////////////////////////////////////////////////////////////////////////// +bool Fractal::set_option(std::string option, void * value) + { + return false; + } + +//////////////////////////////////////////////////////////////////////////////// +View * Fractal::save_view() + { + return new View(typeid(*this).name(), re_min, im_max, size, max_iter); + } + +//////////////////////////////////////////////////////////////////////////////// +void Fractal::restore_view(View * v) + { + fractal_name = v->type; + re_min = v->re_min; + im_max = v->im_max; + size = v->size; + max_iter = v->max_iter; + calc_needed = true; + } + + +//////////////////////////////////////////////////////////////////////////////// void Fractal::draw_pixel(int x, int y, Uint32 * color) { static char * data; @@ -156,10 +244,19 @@ if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); } + +//////////////////////////////////////////////////////////////////////////////// +FractalFactory::~FractalFactory() + { + get_Fractal_map().clear(); + } + + //////////////////////////////////////////////////////////////////////////////// -std::map & get_Fractal_map() +std::map & get_Fractal_map() { - static std::map the_Fractal_map; + static std::map the_Fractal_map; return the_Fractal_map; } + diff -r df02a7de7fe2 -r d691ce98f406 src/Julia.cpp --- a/src/Julia.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/Julia.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,21 +1,49 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // Julia.cpp // Julia set calculator class implementation // //////////////////////////////////////////////////////////////////////////////// -#include +#include #include +#include #include "Julia.h" //////////////////////////////////////////////////////////////////////////////// +ViewJulia::ViewJulia(std::string t, + double re, double im, double s, + unsigned int max, + double kr, double ki) : + View(t, re, im, s, max), + k_re (kr), + k_im (ki) + { + } + +//////////////////////////////////////////////////////////////////////////////// Julia::Julia() : k_re (-0.565072), @@ -26,8 +54,8 @@ size = 4.0; max_iter = 50; calc_needed = true; + fractal_name = "Julia set"; set_display_name(); - fractal_name = "Julia set"; } @@ -37,7 +65,7 @@ { if (!surface) return false; - // Code from http://warp.povusers.org/Julia/ + // See http://warp.povusers.org/Julia/ for explanation of algorithm. if (calc_needed) { @@ -51,7 +79,7 @@ int halfway = max_iter/2 - 1; float step = (float) 255 / halfway; - unsigned x, y, n; + int x, y, n; for(y = 0; y < surface->h; ++y) { @@ -62,7 +90,7 @@ double z_re = c_re, z_im = c_im; bool in_set = true; - for(n = 0; n < max_iter; ++n) + for(n = 0; n < (int) max_iter; ++n) { double z_re2 = z_re * z_re, z_im2 = z_im * z_im; if(z_re2 + z_im2 > 4) @@ -102,22 +130,6 @@ //////////////////////////////////////////////////////////////////////////////// -bool Julia::init(SDL_Surface * surf) - { - if (!surf) - { - return false; - } - else - { - surface = surf; - } - calc_needed = true; - return true; - } - - -//////////////////////////////////////////////////////////////////////////////// bool Julia::get_option(std::string option, void * value) const { if (option.compare("k") == 0) @@ -148,30 +160,31 @@ return false; } - return true; } //////////////////////////////////////////////////////////////////////////////// -std::string const & Julia::get_fractal_name() const +ViewJulia * Julia::save_view() { - return fractal_name; + return new ViewJulia(typeid(*this).name(), re_min, im_max, size, max_iter, + k_re, k_im); } - //////////////////////////////////////////////////////////////////////////////// - -void Julia::draw_pixel(int x, int y, Uint32 * color) +void Julia::restore_view(View * v) { - Fractal::draw_pixel(x, y, color); + Fractal::restore_view(v); + k_re = static_cast(v)->k_re; + k_im = static_cast(v)->k_im; + set_display_name(); } - //////////////////////////////////////////////////////////////////////////////// void Julia::set_display_name() { std::stringstream ss; - ss << "Julia set K = (" << k_re << "," << k_im << ")"; + ss << display_name << " K = (" << k_re << "," << k_im << ")"; display_name = ss.str(); } + diff -r df02a7de7fe2 -r d691ce98f406 src/Mandelbrot.cpp --- a/src/Mandelbrot.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/Mandelbrot.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,18 +1,40 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee +// +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// // // Mandelbrot.cpp // Mandelbrot set calculator class implementation // //////////////////////////////////////////////////////////////////////////////// -#include +#include "Mandelbrot.h" +#include -#include "Mandelbrot.h" - +//////////////////////////////////////////////////////////////////////////////// +ViewMandelbrot::ViewMandelbrot(std::string t, + double re, double im, double s, + unsigned int max) : + View(t, re, im, s, max) + { + } //////////////////////////////////////////////////////////////////////////////// @@ -23,24 +45,8 @@ size = 5.0; max_iter = 50; calc_needed = true; - display_name = "Mandelbrot set"; fractal_name = "Mandelbrot set"; - } - - -//////////////////////////////////////////////////////////////////////////////// -bool Mandelbrot::init(SDL_Surface * surf) - { - if (!surf) - { - return false; - } - else - { - surface = surf; - } - calc_needed = true; - return true; + display_name = fractal_name; } @@ -50,7 +56,7 @@ { if (!surface) return false; - // Code from http://warp.povusers.org/Mandelbrot/ + // See http://warp.povusers.org/Mandelbrot/ for explanation of the algorithm. if (calc_needed) { @@ -64,7 +70,7 @@ int halfway = max_iter/2 - 1; float step = (float) 255 / halfway; - unsigned x, y, n; + int x, y, n; for(y = 0; y < surface->h; ++y) { @@ -75,7 +81,7 @@ double z_re = c_re, z_im = c_im; bool in_set = true; - for(n=0; n < max_iter; ++n) + for(n=0; n < (int) max_iter; ++n) { double z_re2 = z_re * z_re, z_im2 = z_im * z_im; if(z_re2 + z_im2 > 4) @@ -115,17 +121,15 @@ //////////////////////////////////////////////////////////////////////////////// -std::string const & Mandelbrot::get_fractal_name() const +ViewMandelbrot * Mandelbrot::save_view() { - return fractal_name; + return new ViewMandelbrot(typeid(*this).name(), re_min, im_max, size, + max_iter); } - //////////////////////////////////////////////////////////////////////////////// - -void Mandelbrot::draw_pixel(int x, int y, Uint32 * color) +void Mandelbrot::restore_view(View * v) { - Fractal::draw_pixel(x, y, color); + Fractal::restore_view(v); } - diff -r df02a7de7fe2 -r d691ce98f406 src/Options.cpp --- a/src/Options.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/Options.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,10 +1,26 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot - A simple Mandelbrot Set viewer. +// Copyright (C) 2010 Sarah Eris Horsley Caffee // -// options.cpp +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// +// Options.cpp // global variables and definitions // //////////////////////////////////////////////////////////////////////////////// diff -r df02a7de7fe2 -r d691ce98f406 src/main.cpp --- a/src/main.cpp Tue Oct 26 02:03:47 2010 -0500 +++ b/src/main.cpp Fri Nov 12 23:58:48 2010 -0600 @@ -1,11 +1,23 @@ //////////////////////////////////////////////////////////////////////////////// // -// (C) 2010 Sarah Eris Horsley Caffee +// Fracter - A simple Mandelbrot Set viewer. // -// mandelbrot +// Copyright (C) 2010 Sarah Eris Horsley Caffee // -// A simple Mandelbrot Set viewer. Written in honor of Benoit Mandelbrot, -// who died two days ago on Oct 14, 2010. +// This file is part of Fracter. +// +// Fracter is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . // // main.cpp // @@ -22,6 +34,9 @@ { int retval = 0; + std::cout << "Copyright (C) 2010 Sarah Eris Horsley Caffee" << std::endl + << "This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. It is licensed under the GNU GPL v3. For details see the COPYING file that you should have received along with this program, or see http://www.gnu.org/licenses/gpl-3.0.html" << std::endl << std::endl;; + try { App the_app;