Exemple #1
0
// Initializes the application loading the modules, setting the
// graphics mode, loading the configuration and resources, etc.
App::App(int argc, char* argv[])
  : m_configModule(NULL)
  , m_checkArgs(NULL)
  , m_loggerModule(NULL)
  , m_modules(NULL)
  , m_legacy(NULL)
  , m_isGui(false)
{
  ASSERT(m_instance == NULL);
  m_instance = this;

  for (int i = 0; i < argc; ++i)
    m_args.push_back(argv[i]);

  m_configModule = new ConfigModule();
  m_checkArgs = new CheckArgs(m_args);
  m_loggerModule = new LoggerModule(m_checkArgs->isVerbose());
  m_modules = new Modules();
  m_isGui = !(m_checkArgs->isConsoleOnly());
  m_legacy = new LegacyModules(isGui() ? REQUIRE_INTERFACE: 0);

  // Initialize editors.
  init_module_editors();

  // Register well-known image file types.
  FileFormatsManager::instance().registerAllFormats();

  // init editor cursor
  Editor::editor_cursor_init();

  // Load RenderEngine configuration
  RenderEngine::loadConfig();

  /* custom default palette? */
  if (palette_filename) {
    PRINTF("Loading custom palette file: %s\n", palette_filename);

    UniquePtr<Palette> pal(Palette::load(palette_filename));
    if (pal.get() == NULL)
      throw base::Exception("Error loading default palette from: %s",
                            static_cast<const char*>(palette_filename));

    set_default_palette(pal.get());
  }

  /* set system palette to the default one */
  set_current_palette(NULL, true);
}
Exemple #2
0
void load_default_palette(const std::string& userDefined)
{
    base::UniquePtr<Palette> pal;

    // Load specific palette file defined by the user in the command line.
    std::string palFile = userDefined;
    if (!palFile.empty())
        pal.reset(load_palette(palFile.c_str()));
    // Load default palette file
    else {
        std::string defaultPalName = get_preset_palette_filename(
                                         get_default_palette_preset_name(), ".ase");

        // If there is no palette in command line, we use the default one.
        palFile = defaultPalName;
        if (base::is_file(palFile)) {
            pal.reset(load_palette(palFile.c_str()));
        }
        else {
            // Migrate old default.gpl to default.ase format
            palFile = get_preset_palette_filename(
                          get_default_palette_preset_name(), ".gpl");

            if (base::is_file(palFile)) {
                pal.reset(load_palette(palFile.c_str()));

                // Remove duplicate black entries at the end (as old palettes
                // contains 256 colors)
                if (pal && pal->size() == 256) {
                    doc::color_t black = rgba(0, 0, 0, 255);

                    // Get the last non-black entry
                    int i = 0;
                    for (i=pal->size()-1; i>0; --i) {
                        if (pal->getEntry(i) != black)
                            break;
                    }

                    if (i < pal->size()-1) {
                        // Check if there is a black entry in the first entries.
                        bool hasBlack = false;
                        for (int j=0; j<i; ++j) {
                            if (pal->getEntry(j) == black) {
                                hasBlack = true;
                                break;
                            }
                        }
                        if (!hasBlack)
                            ++i;                // Leave one black entry

                        // Resize the palette
                        if (i < pal->size()-1)
                            pal->resize(i+1);
                    }
                }

                // We could remove the old .gpl file (palFile), but as the
                // user could be using multiple versions of Aseprite, it's a
                // good idea to keep both formats (.gpl for Aseprite <=
                // v1.1-beta5, and .ase for future versions).
            }
            // If the default palette file doesn't exist, we copy db32.gpl
            // as the default one (default.ase).
            else {
                ResourceFinder rf;
                rf.includeDataDir("palettes/db32.gpl");
                if (rf.findFirst()) {
                    pal.reset(load_palette(rf.filename().c_str()));
                }
            }

            // Save default.ase file
            if (pal) {
                palFile = defaultPalName;
                save_palette(palFile.c_str(), pal.get(), 0);
            }
        }
    }

    if (pal)
        set_default_palette(pal.get());

    set_current_palette(nullptr, true);
}