Ticket #616: colour_special_sprite.patch

File colour_special_sprite.patch, 1.9 KB (added by historic_bruno, 14 years ago)
  • source/gui/GUIRenderer.cpp

     
    2020#include "GUIRenderer.h"
    2121
    2222#include "graphics/TextureManager.h"
     23#include "gui/GUIutil.h"
    2324#include "lib/ogl.h"
    2425#include "lib/utf8.h"
    2526#include "lib/res/h_mgr.h"
     
    371372    if (it == Sprites.end())
    372373    {
    373374        // Sprite not found. Check whether this a special sprite:
    374         //     stretched:filename.ext
    375         //     <currently that's the only one>
     375        //     stretched:filename.ext   - stretched image
     376        //     colour:r g b a           - solid color
     377        //
    376378        // and if so, try to create it as a new sprite.
    377379        if (SpriteName.substr(0, 10) == "stretched:")
    378380        {
     381            // TODO: Should check (nicely) that this is a valid file?
    379382            SGUIImage Image;
    380383            Image.m_TextureName = VfsPath(L"art/textures/ui")/wstring_from_utf8(SpriteName.substr(10));
    381384            CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
     
    390393            it = Sprites.find(SpriteName);
    391394            debug_assert(it != Sprites.end()); // The insertion above shouldn't fail
    392395        }
     396        else if(SpriteName.substr(0, 7) == "colour:")
     397        {
     398            SGUIImage image;
     399            CStrW value = wstring_from_utf8(SpriteName.substr(7));
     400            CColor color;
     401           
     402            // Check color is valid
     403            if (!GUI<CColor>::ParseString(value, color))
     404            {
     405                LOGERROR(L"GUI: Error parsing sprite 'colour' (\"%ls\")", value.c_str());
     406                return;
     407            }
     408            else
     409            {
     410                image.m_BackColor = color;
     411
     412                CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
     413                image.m_Size = ca;
     414                image.m_TextureSize = ca;
     415
     416                CGUISprite Sprite;
     417                Sprite.AddImage(image);
     418
     419                Sprites[SpriteName] = Sprite;
     420               
     421                it = Sprites.find(SpriteName);
     422                debug_assert(it != Sprites.end()); // The insertion above shouldn't fail
     423            }
     424        }
    393425        else
    394426        {
    395427            // Otherwise, just complain and give up: