From: Ingo Ruhnke Date: Thu, 31 Jul 2014 03:23:41 +0000 (+0200) Subject: Fixed window title and icon, removed Renderer and Lightmap creation from DrawingConte... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=565c5387c0c8c2ee2e9e223b03973e6c114c7db1;p=supertux.git Fixed window title and icon, removed Renderer and Lightmap creation from DrawingContext and moved it to top-level init code --- diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index beb0c0b03..3749a5cf0 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -28,6 +28,7 @@ extern "C" { #include } +#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(VideoSystem::new_renderer()); + std::auto_ptr lightmap(VideoSystem::new_lightmap()); + DrawingContext context(*renderer, *lightmap); context_pointer = &context; init_video(); diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 0b56308ac..96d06ab0d 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -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; diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index 86c3c7acf..13f28c94b 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -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; + Renderer& renderer; + Lightmap& lightmap; /// the transform stack std::vector transformstack; diff --git a/src/video/gl/gl_renderer.hpp b/src/video/gl/gl_renderer.hpp index 359103a0a..1a2e10ea5 100644 --- a/src/video/gl/gl_renderer.hpp +++ b/src/video/gl/gl_renderer.hpp @@ -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 diff --git a/src/video/renderer.hpp b/src/video/renderer.hpp index e4430ad80..4b67f6ee9 100644 --- a/src/video/renderer.hpp +++ b/src/video/renderer.hpp @@ -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_; } diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index a83a14f9e..ec15d307b 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -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(); } diff --git a/src/video/sdl/sdl_renderer.hpp b/src/video/sdl/sdl_renderer.hpp index 042a2855d..67dd321f4 100644 --- a/src/video/sdl/sdl_renderer.hpp +++ b/src/video/sdl/sdl_renderer.hpp @@ -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; };