Exemple #1
0
void PaletteEntryEditor::updateCurrentSpritePalette(const char* operationName)
{
    if (UIContext::instance()->activeDocument() &&
            UIContext::instance()->activeDocument()->sprite()) {
        try {
            ContextWriter writer(UIContext::instance());
            Document* document(writer.document());
            Sprite* sprite(writer.sprite());
            Palette* newPalette = get_current_palette(); // System current pal
            frame_t frame = writer.frame();
            Palette* currentSpritePalette = sprite->palette(frame); // Sprite current pal
            int from, to;

            // Check differences between current sprite palette and current system palette
            from = to = -1;
            currentSpritePalette->countDiff(newPalette, &from, &to);

            if (from >= 0 && to >= from) {
                DocumentUndo* undo = document->undoHistory();
                Cmd* cmd = new cmd::SetPalette(sprite, frame, newPalette);

                // Add undo information to save the range of pal entries that will be modified.
                if (m_implantChange &&
                        undo->lastExecutedCmd() &&
                        undo->lastExecutedCmd()->label() == operationName) {
                    // Implant the cmd in the last CmdSequence if it's
                    // related about color palette modifications
                    ASSERT(dynamic_cast<CmdSequence*>(undo->lastExecutedCmd()));
                    static_cast<CmdSequence*>(undo->lastExecutedCmd())->add(cmd);
                    cmd->execute(UIContext::instance());
                }
                else {
                    Transaction transaction(writer.context(), operationName, ModifyDocument);
                    transaction.execute(cmd);
                    transaction.commit();
                }
            }
        }
        catch (base::Exception& e) {
            Console::showException(e);
        }
    }

    PaletteView* palette_editor = ColorBar::instance()->getPaletteView();
    palette_editor->invalidate();

    if (!m_redrawTimer.isRunning())
        m_redrawTimer.start();

    m_redrawAll = false;
    m_implantChange = true;
}
Exemple #2
0
void FilterWorker::run()
{
  // Launch the thread to apply the effect in background
  base::thread thread(&FilterWorker::thread_proxy, this);

  // Open the alert window in foreground (this is modal, locks the main thread)
  m_alertWindow->openWindowInForeground();

  // Stop the monitoring timer.
  m_timer.stop();

  {
    scoped_lock lock(m_mutex);
    if (m_done && m_filterMgr->isTransaction())
      m_filterMgr->commitTransaction();
    else
      m_cancelled = true;
  }

  // Wait the `effect_bg' thread
  thread.join();

  if (!m_error.empty()) {
    Console console;
    console.printf("A problem has occurred.\n\nDetails:\n%s", m_error.c_str());
  }
  else if (m_cancelled && !m_filterMgr->isTransaction()) {
    StatusBar::instance()
      ->showTip(2500, "No unlocked layers to apply filter");
  }
}
void FilterWorker::run()
{
  // Launch the thread to apply the effect in background
  base::thread thread(&FilterWorker::thread_proxy, this);

  // Open the alert window in foreground (this is modal, locks the main thread)
  m_alertWindow->openWindowInForeground();

  // Stop the monitoring timer.
  m_timer.stop();

  {
    scoped_lock lock(m_mutex);
    if (!m_done)
      m_cancelled = true;
  }

  // Wait the `effect_bg' thread
  thread.join();

  if (!m_error.empty()) {
    Console console;
    console.printf("A problem has occurred.\n\nDetails:\n%s", m_error.c_str());
  }
}
Exemple #4
0
bool PaletteEntryEditor::onProcessMessage(Message* msg)
{
    if (msg->type() == kTimerMessage &&
            static_cast<TimerMessage*>(msg)->timer() == &m_redrawTimer) {
        // Redraw all editors
        if (m_redrawAll) {
            m_redrawAll = false;
            m_implantChange = false;
            m_redrawTimer.stop();

            // Call all observers of PaletteChange event.
            m_selfPalChange = true;
            App::instance()->PaletteChange();
            m_selfPalChange = false;

            // Redraw all editors
            try {
                ContextWriter writer(UIContext::instance());
                Document* document(writer.document());
                if (document != NULL)
                    document->notifyGeneralUpdate();
            }
            catch (...) {
                // Do nothing
            }
        }
        // Redraw just the current editor
        else {
            m_redrawAll = true;
            if (current_editor != NULL)
                current_editor->updateEditor();
        }
    }
    return Window::onProcessMessage(msg);
}