Ignore:
Timestamp:
Jan 21, 2013, 12:28:22 AM (7 years ago)
Author:
sam
Message:

system: try to autodetect the data directory from the executable path;
currently works for images (SDL and GDI+ loaders) and sound samples.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/image/codec/sdl-image.cpp

    r2183 r2237  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    4949
    5050private:
    51     SDL_Surface *img;
     51    SDL_Surface *m_img;
    5252};
    5353
     
    5858bool SdlImageData::Open(char const *path)
    5959{
    60     for (char const *name = path; *name; name++)
    61         if ((img = IMG_Load(name)))
    62             break;
    63 
    64     if (!img)
     60    String fullpath = String(System::GetDataDir()) + String(path);
     61    m_img = IMG_Load(&fullpath[0]);
     62    if (!m_img)
    6563    {
    6664#if !LOL_RELEASE
    67         Log::Error("could not load %s\n", path);
     65        Log::Error("could not load %s\n", &fullpath[0]);
    6866#endif
    6967        return false;
    7068    }
    7169
    72     size = ivec2(img->w, img->h);
     70    size = ivec2(m_img->w, m_img->h);
    7371
    74     if (img->format->BytesPerPixel != 4)
     72    if (m_img->format->BytesPerPixel != 4)
    7573    {
    7674        SDL_Surface *tmp = Create32BppSurface(size);
    77         SDL_BlitSurface(img, NULL, tmp, NULL);
    78         SDL_FreeSurface(img);
    79         img = tmp;
     75        SDL_BlitSurface(m_img, NULL, tmp, NULL);
     76        SDL_FreeSurface(m_img);
     77        m_img = tmp;
    8078    }
    8179
    82     format = img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB;
     80    format = m_img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB;
    8381
    8482    return true;
     
    8785bool SdlImageData::Close()
    8886{
    89     SDL_FreeSurface(img);
     87    SDL_FreeSurface(m_img);
    9088
    9189    return true;
     
    9492void * SdlImageData::GetData() const
    9593{
    96     return img->pixels;
     94    return m_img->pixels;
    9795}
    9896
Note: See TracChangeset for help on using the changeset viewer.