From dc26002e79202b16465b6f67d5bda3eb9bad02ca Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 13 Jun 2009 02:02:51 +0000 Subject: [PATCH] skin info is now mostly read from a config file, making it cleaner and opening the door for futur modding capabilities (continued) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3608 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/glass.stkskin | 4 +++ src/gui/engine.cpp | 43 ++--------------------------- src/gui/skin.cpp | 61 ++++++++++++++++++++++++++++++++++++------ src/gui/skin.hpp | 4 ++- 4 files changed, 62 insertions(+), 50 deletions(-) diff --git a/data/gui/glass.stkskin b/data/gui/glass.stkskin index 762dd2ca9..9a104f891 100644 --- a/data/gui/glass.stkskin +++ b/data/gui/glass.stkskin @@ -56,6 +56,10 @@ + + + g_loaded_screens; Screen* g_current_screen = NULL; - ITexture* bg_image = NULL; float dt = 0; @@ -143,7 +142,6 @@ void cleanUp() { if(g_skin != NULL) delete g_skin; g_skin = NULL; - bg_image = NULL; g_loaded_screens.clearAndDeleteAll(); g_current_screen = NULL; @@ -186,48 +184,11 @@ void render(float elapsed_time) { GUIEngine::dt = elapsed_time; - // ---- background image - // on one end, making these static is not too clean. - // on another end, these variables are really only used locally, - // and making them static avoids doing the same stupid computations every frame - static core::rect dest; - static core::rect source_area; - - if(bg_image == NULL) - { - int texture_w, texture_h; - // TODO/FIXME? - user preferences still include a background image choice - bg_image = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/background.jpg").c_str() ); - assert(bg_image != NULL); - texture_w = bg_image->getSize().Width; - texture_h = bg_image->getSize().Height; - - source_area = core::rect(0, 0, texture_w, texture_h); - - core::dimension2d frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); - const int screen_w = frame_size.Width; - const int screen_h = frame_size.Height; - - // stretch image vertically to fit - float ratio = (float)screen_h / texture_h; - - // check that with the vertical stretching, it still fits horizontally - while(texture_w*ratio < screen_w) ratio += 0.1f; - - texture_w = (int)(texture_w*ratio); - texture_h = (int)(texture_h*ratio); - - const int clipped_x_space = (texture_w - screen_w); - - dest = core::rect(-clipped_x_space/2, 0, screen_w+clipped_x_space/2, texture_h); - } - - // ---- menu drawing + // ---- menu drawing // draw background image and sections if(!StateManager::isGameState()) { - GUIEngine::getDriver()->draw2DImage(bg_image, dest, source_area, - 0 /* no clipping */, 0, false /* alpha */); + g_skin->drawBgImage(); g_skin->renderSections(); } diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index f528e2191..62a6794af 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -110,15 +110,13 @@ namespace SkinConfig Skin::Skin(IGUISkin* fallback_skin) { SkinConfig::loadFromFile(file_manager->getGUIDir() + "/glass.stkskin" ); + bg_image = NULL; m_fallback_skin = fallback_skin; m_fallback_skin->grab(); assert(fallback_skin != NULL); m_tex_ficonhighlight = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/glass_iconhighlight_focus.png").c_str() ); - - m_tex_gaugefill = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/glasssgauge_fill.png").c_str() ); - m_tex_bubble = GUIEngine::getDriver()->getTexture( (file_manager->getGUIDir() + "/bubble.png").c_str() ); } @@ -146,6 +144,49 @@ BoxRenderParams::BoxRenderParams() vertical_flip = false; } +void Skin::drawBgImage() +{ + + // ---- background image + // on one end, making these static is not too clean. + // on another end, these variables are really only used locally, + // and making them static avoids doing the same stupid computations every frame + static core::rect dest; + static core::rect source_area; + + if(bg_image == NULL) + { + int texture_w, texture_h; + // TODO/FIXME? - user preferences still include a background image choice + bg_image = SkinConfig::m_render_params["background::neutral"].image; + assert(bg_image != NULL); + texture_w = bg_image->getSize().Width; + texture_h = bg_image->getSize().Height; + + source_area = core::rect(0, 0, texture_w, texture_h); + + core::dimension2d frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); + const int screen_w = frame_size.Width; + const int screen_h = frame_size.Height; + + // stretch image vertically to fit + float ratio = (float)screen_h / texture_h; + + // check that with the vertical stretching, it still fits horizontally + while(texture_w*ratio < screen_w) ratio += 0.1f; + + texture_w = (int)(texture_w*ratio); + texture_h = (int)(texture_h*ratio); + + const int clipped_x_space = (texture_w - screen_w); + + dest = core::rect(-clipped_x_space/2, 0, screen_w+clipped_x_space/2, texture_h); + } + + + GUIEngine::getDriver()->draw2DImage(bg_image, dest, source_area, 0 /* no clipping */, 0, false /* alpha */); +} + void Skin::drawBoxFromStretchableTexture(const core::rect< s32 > &dest, const BoxRenderParams& params) { ITexture* source = params.image; @@ -569,14 +610,14 @@ void Skin::drawSpinnerBody(const core::rect< s32 > &rect, const Widget* widget, widget->x + handle_size + (int)((widget->w - 2*handle_size)*value), widget->y + widget->h); - const int texture_w = m_tex_gaugefill->getSize().Width; - const int texture_h = m_tex_gaugefill->getSize().Height; + ITexture* texture = SkinConfig::m_render_params["gaugefill::neutral"].image; + const int texture_w = texture->getSize().Width; + const int texture_h = texture->getSize().Height; const core::rect< s32 > source_area = core::rect< s32 >(0, 0, texture_w, texture_h); - - // TODO : make configurable through skin config file - GUIEngine::getDriver()->draw2DImage(m_tex_gaugefill, dest_area, source_area, + GUIEngine::getDriver()->draw2DImage(texture, + dest_area, source_area, 0 /* no clipping */, 0, true /* alpha */); } @@ -786,6 +827,10 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip) { + // fade out background + GUIEngine::getDriver()->draw2DRectangle( SColor(150, 255, 255, 255), + core::rect< s32 >(position2d< s32 >(0,0) , GUIEngine::getDriver()->getCurrentRenderTargetSize()) ); + // draw frame (since it's transluscent, draw many times to get opacity) drawBoxFromStretchableTexture(rect, SkinConfig::m_render_params["window::neutral"]); drawBoxFromStretchableTexture(rect, SkinConfig::m_render_params["window::neutral"]); diff --git a/src/gui/skin.hpp b/src/gui/skin.hpp index e3d7ec459..206816e39 100644 --- a/src/gui/skin.hpp +++ b/src/gui/skin.hpp @@ -45,7 +45,8 @@ namespace GUIEngine ITexture* m_tex_ficonhighlight; ITexture* m_tex_bubble; - ITexture* m_tex_gaugefill; + + ITexture* bg_image; void drawBoxFromStretchableTexture(const core::rect< s32 > &dest, const BoxRenderParams& params); @@ -68,6 +69,7 @@ namespace GUIEngine ~Skin(); void renderSections(ptr_vector* within_vector=NULL); + void drawBgImage(); // irrlicht's callbacks virtual void draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &pos, const core::rect< s32 > *clip);