MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMovementPtr pixelsMovement, HandleType handle)
  : m_editor(editor)
  , m_discarded(false)
{
  // MovingPixelsState needs a selection tool to avoid problems
  // sharing the extra cel between the drawing cursor preview and the
  // pixels movement/transformation preview.
  //ASSERT(!editor->getCurrentEditorInk()->isSelection());

  UIContext* context = UIContext::instance();

  m_pixelsMovement = pixelsMovement;

  if (handle != NoHandle) {
    int u, v;
    editor->screenToEditor(msg->position().x, msg->position().y, &u, &v);
    m_pixelsMovement->catchImage(u, v, handle);

    editor->captureMouse();
  }

  // Setup mask color
  setTransparentColor(context->settings()->selection()->getMoveTransparentColor());

  // Hook BeforeCommandExecution signal so we know if the user wants
  // to execute other command, so we can drop pixels.
  m_ctxConn =
    context->BeforeCommandExecution.connect(&MovingPixelsState::onBeforeCommandExecution, this);

  // Observe SelectionSettings to be informed of changes to
  // Transparent Color from Context Bar.
  context->settings()->selection()->addObserver(this);

  // Add the current editor as filter for key message of the manager
  // so we can catch the Enter key, and avoid to execute the
  // PlayAnimation command.
  m_editor->getManager()->addMessageFilter(kKeyDownMessage, m_editor);
  m_editor->getManager()->addMessageFilter(kKeyUpMessage, m_editor);
  m_editor->addObserver(this);

  ContextBar* contextBar = App::instance()->getMainWindow()->getContextBar();
  contextBar->updateForMovingPixels();
  contextBar->addObserver(this);
}
Exemple #2
0
int App::run()
{
  UIContext* context = UIContext::instance();

  // Initialize GUI interface
  if (isGui()) {
    PRINTF("GUI mode\n");

    // Setup the GUI cursor and redraw screen

    ui::set_use_native_cursors(
      context->settings()->experimental()->useNativeCursor());

    jmouse_set_cursor(kArrowCursor);

    ui::Manager::getDefault()->invalidate();

    // Create the main window and show it.
    m_mainWindow.reset(new MainWindow);

    // Default status of the main window.
    app_rebuild_documents_tabs();
    app_default_statusbar_message();

    // Default window title bar.
    updateDisplayTitleBar();
    
    m_mainWindow->openWindow();

    // Redraw the whole screen.
    ui::Manager::getDefault()->invalidate();
  }

  // Procress options
  PRINTF("Processing options...\n");

  {
    Console console;
    for (const std::string& filename : m_files) {
      // Load the sprite
      Document* document = load_document(context, filename.c_str());
      if (!document) {
        if (!isGui())
          console.printf("Error loading file \"%s\"\n", filename.c_str());
      }
      else {
        // Add the given file in the argument as a "recent file" only
        // if we are running in GUI mode. If the program is executed
        // in batch mode this is not desirable.
        if (isGui())
          getRecentFiles()->addRecentFile(filename.c_str());

        // Add the document to the exporter.
        if (m_exporter != NULL)
          m_exporter->addDocument(document);
      }
    }
  }

  // Export
  if (m_exporter != NULL) {
    PRINTF("Exporting sheet...\n");

    m_exporter->exportSheet();
    m_exporter.reset(NULL);
  }

  // Run the GUI
  if (isGui()) {
#ifdef ENABLE_UPDATER
    // Launch the thread to check for updates.
    app::CheckUpdateThreadLauncher checkUpdate;
    checkUpdate.launch();
#endif

#ifdef ENABLE_WEBSERVER
    // Launch the webserver.
    app::WebServer webServer;
    webServer.start();
#endif

    app::SendCrash sendCrash;
    sendCrash.search();

    // Run the GUI main message loop
    gui_run();

    // Destroy all documents in the UIContext.
    const doc::Documents& docs = m_modules->m_ui_context.documents();
    while (!docs.empty()) {
      doc::Document* doc = docs.back();

      // First we close the document. In this way we receive recent
      // notifications related to the document as an app::Document. If
      // we delete the document directly, we destroy the app::Document
      // too early, and then doc::~Document() call
      // DocumentsObserver::onRemoveDocument(). In this way, observers
      // could think that they have a fully created app::Document when
      // in reality it's a doc::Document (in the middle of a
      // destruction process).
      //
      // TODO: This problem is because we're extending doc::Document,
      // in the future, we should remove app::Document.
      doc->close();
      delete doc;
    }

    // Destroy the window.
    m_mainWindow.reset(NULL);
  }
  // Start shell to execute scripts.
  else if (m_isShell) {
    m_systemConsole.prepareShell();

    if (m_modules->m_scriptingEngine.supportEval()) {
      Shell shell;
      shell.run(m_modules->m_scriptingEngine);
    }
    else {
      std::cerr << "Your version of " PACKAGE " wasn't compiled with shell support.\n";
    }
  }

  return 0;
}