コード例 #1
0
ファイル: gui_xml.cpp プロジェクト: BlueHeisenberg/aseprite
GuiXml::GuiXml()
{
  PRINTF("Loading gui.xml file...");

  ResourceFinder rf;
  rf.includeDataDir("gui.xml");
  if (!rf.findFirst())
    throw base::Exception("gui.xml was not found");

  // Load the XML file. As we've already checked "path" existence,
  // in a case of exception we should show the error and stop.
  m_doc = app::open_xml(rf.filename());
}
コード例 #2
0
ファイル: ini_file.cpp プロジェクト: felipeita/aseprite
ConfigModule::ConfigModule()
{
  ResourceFinder rf;
  rf.includeConfFile();

  std::string config_filename;

  // Search the configuration file from first to last path
  if (rf.findFirst())
    config_filename = rf.filename();

  // If the file wasn't found, we will create configuration file
  // in the first path
  if (config_filename[0] == 0 && rf.first())
    config_filename = rf.filename();

  override_config_file(config_filename.c_str());
}
コード例 #3
0
ファイル: color_popup.cpp プロジェクト: webbie1887/aseprite
ColorPopup::ColorPopup(const ColorButtonOptions& options)
  : PopupWindowPin(" ", // Non-empty to create title-bar and close button
                   ClickBehavior::CloseOnClickInOtherWindow,
                   options.canPinSelector)
  , m_vbox(VERTICAL)
  , m_topBox(HORIZONTAL)
  , m_color(app::Color::fromMask())
  , m_closeButton(nullptr)
  , m_colorPaletteContainer(options.showIndexTab ?
                            new ui::View: nullptr)
  , m_colorPalette(options.showIndexTab ?
                   new PaletteView(false, PaletteView::SelectOneColor, this, 7*guiscale()):
                   nullptr)
  , m_simpleColors(nullptr)
  , m_oldAndNew(Shade(2), ColorShades::ClickEntries)
  , m_maskLabel("Transparent Color Selected")
  , m_canPin(options.canPinSelector)
  , m_insideChange(false)
  , m_disableHexUpdate(false)
{
  if (options.showSimpleColors) {
    if (!g_simplePal) {
      ResourceFinder rf;
      rf.includeDataDir("palettes/tags.gpl");
      if (rf.findFirst())
        g_simplePal.reset(load_palette(rf.filename().c_str()));
    }

    if (g_simplePal)
      m_simpleColors = new SimpleColors(this, &m_tooltips);
  }

  ButtonSet::Item* item = m_colorType.addItem("Index");
  item->setFocusStop(false);
  if (!options.showIndexTab)
    item->setVisible(false);

  m_colorType.addItem("RGB")->setFocusStop(false);
  m_colorType.addItem("HSV")->setFocusStop(false);
  m_colorType.addItem("HSL")->setFocusStop(false);
  m_colorType.addItem("Gray")->setFocusStop(false);
  m_colorType.addItem("Mask")->setFocusStop(false);

  m_topBox.setBorder(gfx::Border(0));
  m_topBox.setChildSpacing(0);

  if (m_colorPalette) {
    m_colorPaletteContainer->attachToView(m_colorPalette);
    m_colorPaletteContainer->setExpansive(true);
  }
  m_sliders.setExpansive(true);

  m_topBox.addChild(&m_colorType);
  m_topBox.addChild(new Separator("", VERTICAL));
  m_topBox.addChild(&m_hexColorEntry);
  m_topBox.addChild(&m_oldAndNew);

  // TODO fix this hack for close button in popup window
  // Move close button (decorative widget) inside the m_topBox
  {
    WidgetsList decorators;
    for (auto child : children()) {
      if (child->type() == kWindowCloseButtonWidget) {
        m_closeButton = child;
        removeChild(child);
        break;
      }
    }
    if (m_closeButton) {
      m_topBox.addChild(new BoxFiller);
      VBox* vbox = new VBox;
      vbox->addChild(m_closeButton);
      m_topBox.addChild(vbox);
    }
  }
  setText("");                  // To remove title

  m_vbox.addChild(&m_tooltips);
  if (m_simpleColors)
    m_vbox.addChild(m_simpleColors);
  m_vbox.addChild(&m_topBox);
  if (m_colorPaletteContainer)
    m_vbox.addChild(m_colorPaletteContainer);
  m_vbox.addChild(&m_sliders);
  m_vbox.addChild(&m_maskLabel);
  addChild(&m_vbox);

  m_colorType.ItemChange.connect(base::Bind<void>(&ColorPopup::onColorTypeClick, this));

  m_sliders.ColorChange.connect(&ColorPopup::onColorSlidersChange, this);
  m_hexColorEntry.ColorChange.connect(&ColorPopup::onColorHexEntryChange, this);
  m_oldAndNew.Click.connect(&ColorPopup::onSelectOldColor, this);

  // Set RGB just for the sizeHint(), and then deselect the color type
  // (the first setColor() call will setup it correctly.)
  selectColorType(app::Color::RgbType);
  m_colorType.deselectItems();

  m_onPaletteChangeConn =
    App::instance()->PaletteChange.connect(&ColorPopup::onPaletteChange, this);

  InitTheme.connect(
    [this]{
      setSizeHint(gfx::Size(300*guiscale(), sizeHint().h));
    });
  initTheme();
}
コード例 #4
0
ファイル: app.cpp プロジェクト: Julien-B/aseprite
// Initializes the application loading the modules, setting the
// graphics mode, loading the configuration and resources, etc.
App::App(int argc, const char* argv[])
  : m_modules(NULL)
  , m_legacy(NULL)
  , m_isGui(false)
  , m_isShell(false)
  , m_exporter(NULL)
{
  ASSERT(m_instance == NULL);
  m_instance = this;

  AppOptions options(argc, argv);

  m_modules = new Modules(!options.startUI(), options.verbose());
  m_isGui = options.startUI();
  m_isShell = options.startShell();
  m_legacy = new LegacyModules(isGui() ? REQUIRE_INTERFACE: 0);
  m_files = options.files();

  if (options.hasExporterParams()) {
    m_exporter.reset(new DocumentExporter);

    m_exporter->setDataFilename(options.data());
    m_exporter->setTextureFilename(options.sheet());
    m_exporter->setScale(options.scale());
  }

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

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

  // Load RenderEngine configuration
  RenderEngine::loadConfig();
  if (isPortable())
    PRINTF("Running in portable mode\n");

  // Default palette.
  std::string palFile(!options.paletteFileName().empty() ?
    options.paletteFileName():
    std::string(get_config_string("GfxMode", "Palette", "")));

  if (palFile.empty()) {
    // Try to use a default pixel art palette.
    ResourceFinder rf;
    rf.includeDataDir("palettes/db32.gpl");
    if (rf.findFirst())
      palFile = rf.filename();
  }

  if (!palFile.empty()) {
    PRINTF("Loading custom palette file: %s\n", palFile.c_str());

    base::UniquePtr<Palette> pal(load_palette(palFile.c_str()));
    if (pal.get() != NULL) {
      set_default_palette(pal.get());
    }
    else {
      PRINTF("Error loading custom palette file\n");
    }
  }

  // Set system palette to the default one.
  set_current_palette(NULL, true);
}
コード例 #5
0
ファイル: palettes.cpp プロジェクト: Censacrof/aseprite
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);
}