Fixed window title and icon, removed Renderer and Lightmap creation from DrawingConte...
authorIngo Ruhnke <grumbel@gmail.com>
Thu, 31 Jul 2014 03:23:41 +0000 (05:23 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Thu, 31 Jul 2014 03:23:41 +0000 (05:23 +0200)
src/supertux/main.cpp
src/video/drawing_context.cpp
src/video/drawing_context.hpp
src/video/gl/gl_renderer.hpp
src/video/renderer.hpp
src/video/sdl/sdl_renderer.cpp
src/video/sdl/sdl_renderer.hpp

index beb0c0b..3749a5c 100644 (file)
@@ -28,6 +28,7 @@ extern "C" {
 #include <findlocale.h>
 }
 
+#include "video/renderer.hpp"
 #include "supertux/main.hpp"
 
 #ifdef MACOSX
@@ -463,77 +464,25 @@ Main::init_rand()
 void
 Main::init_video()
 {
-  // FIXME: Add something here
   SCREEN_WIDTH  = 800;
   SCREEN_HEIGHT = 600;
 
   PHYSICAL_SCREEN_WIDTH = SCREEN_WIDTH;
   PHYSICAL_SCREEN_HEIGHT = SCREEN_HEIGHT;
 
-  context_pointer->init_renderer();
+  SDL_SetWindowTitle(Renderer::instance()->get_window(), PACKAGE_NAME " " PACKAGE_VERSION);
 
-#ifdef OLD_SDL1
- // SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
-
- /* // set icon -- Original part B4 SDL2
-#ifdef MACOSX
   const char* icon_fname = "images/engine/icons/supertux-256x256.png";
-#else
-  const char* icon_fname = "images/engine/icons/supertux.xpm";
-#endif
-  SDL_Surface* icon;
-  try {
-    icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
-  } catch (const std::runtime_error& err) {
-    icon = 0;
-    log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
+  SDL_Surface* icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
+  if (!icon)
+  {
+    log_warning << "Couldn't load icon '" << icon_fname << "': " << SDL_GetError() << std::endl;
   }
-  if(icon != 0) {
-    SDL_WM_SetIcon(icon, 0); //now  SDL_SetWindowIcon(window, surface);  if needed 
+  else
+  {
+    SDL_SetWindowIcon(Renderer::instance()->get_window(), icon);
     SDL_FreeSurface(icon);
   }
-  else {
-    log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
-  }
-    */
-    
-  //  SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
-    
-    // set icon
-#ifdef MACOSX
-    const char* icon_fname = "images/engine/icons/supertux-256x256.png";
-#else
-    const char* icon_fname = "images/engine/icons/supertux.xpm";
-#endif
-    SDL_Window* icon = 0;
-    try {
-        //icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
-    } catch (const std::runtime_error& err) {
-        log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
-    }
-    if(icon != 0) {
-     //   SDL_SetWindowIcon(icon, 0); //now  SDL_SetWindowIcon(window, surface);  if needed
-      //  SDL_FreeSurface(icon);
-    }
-    else {
-        log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
-    }
-    
-    
-   /* // set icon
-#ifdef MACOSX
-    const char* icon_fname = "images/engine/icons/supertux-256x256.png";
-#else
-    const char* icon_fname = "images/engine/icons/supertux.xpm";
-#endif
-    
-    SDL_Window icon = SDL_CreateWindow(PACKAGE_NAME " " PACKAGE_VERSION,
-                                          SDL_WINDOWPOS_UNDEFINED,
-                                          SDL_WINDOWPOS_UNDEFINED,
-                                          640, 480,
-                                          SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
-   // not sure of that */
-#endif
   SDL_ShowCursor(0);
 
   log_info << (g_config->use_fullscreen?"fullscreen ":"window ")
@@ -643,7 +592,9 @@ Main::run(int argc, char** argv)
       return 0;
 
     timelog("video");
-    DrawingContext context;
+    std::auto_ptr<Renderer> renderer(VideoSystem::new_renderer());
+    std::auto_ptr<Lightmap> lightmap(VideoSystem::new_lightmap());
+    DrawingContext context(*renderer, *lightmap);
     context_pointer = &context;
     init_video();
     
index 0b56308..96d06ab 100644 (file)
@@ -31,9 +31,9 @@
 #include "video/texture_manager.hpp"
 #include "video/video_systems.hpp"
 
-DrawingContext::DrawingContext() :
-  renderer(0), 
-  lightmap(0),
+DrawingContext::DrawingContext(Renderer& renderer, Lightmap& lightmap) :
+  renderer(renderer),
+  lightmap(lightmap),
   transformstack(),
   transform(),
   blend_stack(),
@@ -53,23 +53,10 @@ DrawingContext::DrawingContext() :
 
 DrawingContext::~DrawingContext()
 {
-  delete renderer;
-  delete lightmap;
-
   obstack_free(&obst, NULL);
 }
 
 void
-DrawingContext::init_renderer()
-{
-  delete renderer;
-  delete lightmap;
-
-  renderer = VideoSystem::new_renderer();
-  lightmap = VideoSystem::new_lightmap();
-}
-
-void
 DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
                              float angle, const Color& color, const Blend& blend,
                              int layer)
@@ -325,9 +312,9 @@ DrawingContext::do_drawing()
 
   // PART1: create lightmap
   if(use_lightmap) {
-    lightmap->start_draw(ambient_color);
+    lightmap.start_draw(ambient_color);
     handle_drawing_requests(lightmap_requests);
-    lightmap->end_draw();
+    lightmap.end_draw();
 
     DrawingRequest* request = new(obst) DrawingRequest();
     request->target = NORMAL;
@@ -344,11 +331,11 @@ DrawingContext::do_drawing()
 
   // if a screenshot was requested, take one
   if (screenshot_requested) {
-    renderer->do_take_screenshot();
+    renderer.do_take_screenshot();
     screenshot_requested = false;
   }
 
-  renderer->flip();
+  renderer.flip();
 }
 
 class RequestPtrCompare
@@ -373,64 +360,64 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests)
       case NORMAL:
         switch(request.type) {
           case SURFACE:
-            renderer->draw_surface(request);
+            renderer.draw_surface(request);
             break;
           case SURFACE_PART:
-            renderer->draw_surface_part(request);
+            renderer.draw_surface_part(request);
             break;
           case GRADIENT:
-            renderer->draw_gradient(request);
+            renderer.draw_gradient(request);
             break;
           case TEXT:
           {
             const TextRequest* textrequest = (TextRequest*) request.request_data;
-            textrequest->font->draw(renderer, textrequest->text, request.pos,
+            textrequest->font->draw(&renderer, textrequest->text, request.pos,
                                     textrequest->alignment, request.drawing_effect, request.color, request.alpha);
           }
           break;
           case FILLRECT:
-            renderer->draw_filled_rect(request);
+            renderer.draw_filled_rect(request);
             break;
           case INVERSEELLIPSE:
-            renderer->draw_inverse_ellipse(request);
+            renderer.draw_inverse_ellipse(request);
             break;
           case DRAW_LIGHTMAP:
-            lightmap->do_draw();
+            lightmap.do_draw();
             break;
           case GETLIGHT:
-            lightmap->get_light(request);
+            lightmap.get_light(request);
             break;
         }
         break;
       case LIGHTMAP:
         switch(request.type) {
           case SURFACE:
-            lightmap->draw_surface(request);
+            lightmap.draw_surface(request);
             break;
           case SURFACE_PART:
-            lightmap->draw_surface_part(request);
+            lightmap.draw_surface_part(request);
             break;
           case GRADIENT:
-            lightmap->draw_gradient(request);
+            lightmap.draw_gradient(request);
             break;
           case TEXT:
           {
             const TextRequest* textrequest = (TextRequest*) request.request_data;
-            textrequest->font->draw(renderer, textrequest->text, request.pos,
+            textrequest->font->draw(&renderer, textrequest->text, request.pos,
                                     textrequest->alignment, request.drawing_effect, request.color, request.alpha);
           }
           break;
           case FILLRECT:
-            lightmap->draw_filled_rect(request);
+            lightmap.draw_filled_rect(request);
             break;
           case INVERSEELLIPSE:
             assert(!"InverseEllipse doesn't make sense on the lightmap");
             break;
           case DRAW_LIGHTMAP:
-            lightmap->do_draw();
+            lightmap.do_draw();
             break;
           case GETLIGHT:
-            lightmap->get_light(request);
+            lightmap.get_light(request);
             break;
         }
         break;
index 86c3c7a..13f28c9 100644 (file)
@@ -52,11 +52,9 @@ inline int next_po2(int val)
 class DrawingContext
 {
 public:
-  DrawingContext();
+  DrawingContext(Renderer& renderer, Lightmap& lightmap);
   ~DrawingContext();
 
-  void init_renderer();
-
   /// Adds a drawing request for a surface into the request list.
   void draw_surface(SurfacePtr surface, const Vector& position,
                     int layer);
@@ -154,8 +152,8 @@ private:
   };
 
 private:
-  Renderer *renderer;
-  Lightmap *lightmap;
+  Rendererrenderer;
+  Lightmaplightmap;
 
   /// the transform stack
   std::vector<Transform> transformstack;
index 359103a..1a2e10e 100644 (file)
@@ -130,6 +130,7 @@ public:
   void apply_config();
   void apply_video_mode(const Size& size, bool fullscreen);
   void set_gamma(float gamma);
+  SDL_Window* get_window() const { return window; }
 };
 
 #endif
index e4430ad..4b67f6e 100644 (file)
@@ -53,6 +53,7 @@ public:
   virtual void resize(int w, int h) = 0;
   virtual void apply_config() = 0;
   virtual void set_gamma(float gamma) = 0;
+  virtual SDL_Window* get_window() const = 0;
 
   static Renderer* instance() { assert(instance_); return instance_; }
   
index a83a14f..ec15d30 100644 (file)
@@ -79,7 +79,6 @@ SDLRenderer::SDLRenderer() :
     log_info << "Max Texture Height: " << info.max_texture_height << std::endl;
   }
 
-  SDL_SetWindowTitle(window, "SuperTux");
   if(texture_manager == 0)
     texture_manager = new TextureManager();
 }
index 042a285..67dd321 100644 (file)
@@ -36,6 +36,7 @@ public:
   void resize(int w, int h);
   void apply_config() {}
   void set_gamma(float gamma);
+  SDL_Window* get_window() const { return window; }
 
   SDL_Renderer* get_sdl_renderer() const { return renderer; };