Esempio n. 1
0
void EyedropperCommand::onExecute(Context* context)
{
  Widget* widget = ui::Manager::getDefault()->getMouse();
  if (!widget || widget->type() != editor_type())
    return;

  Editor* editor = static_cast<Editor*>(widget);
  Sprite* sprite = editor->sprite();
  if (!sprite)
    return;

  // Discard current image brush
  {
    Command* discardBrush = CommandsModule::instance()->getCommandByName(CommandId::DiscardBrush);
    context->executeCommand(discardBrush);
  }

  // Pixel position to get
  gfx::Point pixelPos = editor->screenToEditor(ui::get_mouse_position());

  // Check if we've to grab alpha channel or the merged color.
  Preferences& pref = Preferences::instance();
  bool grabAlpha = pref.editor.grabAlpha();

  ColorPicker picker;
  picker.pickColor(editor->getSite(),
    pixelPos,
    grabAlpha ?
    ColorPicker::FromActiveLayer:
    ColorPicker::FromComposition);

  if (grabAlpha) {
    tools::ToolBox* toolBox = App::instance()->getToolBox();
    for (auto tool : *toolBox)
      pref.tool(tool).opacity(picker.alpha());
  }

  if (m_background)
    pref.colorBar.bgColor(picker.color());
  else
    pref.colorBar.fgColor(picker.color());
}
Esempio n. 2
0
bool StandbyState::onUpdateStatusBar(Editor* editor)
{
  tools::Ink* ink = editor->getCurrentEditorInk();
  const Sprite* sprite = editor->sprite();
  int x, y;

  editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y);

  if (!sprite) {
    StatusBar::instance()->clearText();
  }
  // For eye-dropper
  else if (ink->isEyedropper()) {
    bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha();
    ColorPicker picker;
    picker.pickColor(editor->getDocumentLocation(), x, y,
      grabAlpha ?
      ColorPicker::FromActiveLayer:
      ColorPicker::FromComposition);

    char buf[256];
    usprintf(buf, "- Pos %d %d", x, y);

    StatusBar::instance()->showColor(0, buf, picker.color(), picker.alpha());
  }
  else {
    Mask* mask =
      (editor->document()->isMaskVisible() ? 
       editor->document()->mask(): NULL);

    StatusBar::instance()->setStatusText(0,
      "Pos %d %d, Size %d %d, Frame %d [%d msecs]",
      x, y,
      (mask ? mask->bounds().w: sprite->width()),
      (mask ? mask->bounds().h: sprite->height()),
      editor->frame()+1,
      sprite->getFrameDuration(editor->frame()));
  }

  return true;
}
Esempio n. 3
0
bool StandbyState::onUpdateStatusBar(Editor* editor)
{
  tools::Ink* ink = editor->getCurrentEditorInk();
  const Sprite* sprite = editor->sprite();
  gfx::Point spritePos = editor->screenToEditor(ui::get_mouse_position());

  if (!sprite) {
    StatusBar::instance()->clearText();
  }
  // For eye-dropper
  else if (ink->isEyedropper()) {
    bool grabAlpha = Preferences::instance().editor.grabAlpha();
    ColorPicker picker;
    picker.pickColor(editor->getSite(),
      spritePos,
      grabAlpha ?
      ColorPicker::FromActiveLayer:
      ColorPicker::FromComposition);

    char buf[256];
    sprintf(buf, "- Pos %d %d", spritePos.x, spritePos.y);

    StatusBar::instance()->showColor(0, buf, picker.color(), picker.alpha());
  }
  else {
    Mask* mask =
      (editor->document()->isMaskVisible() ?
       editor->document()->mask(): NULL);

    StatusBar::instance()->setStatusText(0,
      "Pos %d %d, Size %d %d, Frame %d [%d msecs]",
      spritePos.x, spritePos.y,
      (mask ? mask->bounds().w: sprite->width()),
      (mask ? mask->bounds().h: sprite->height()),
      editor->frame()+1,
      sprite->frameDuration(editor->frame()));
  }

  return true;
}
Esempio n. 4
0
void EyedropperCommand::onExecute(Context* context)
{
  Widget* widget = ui::Manager::getDefault()->getMouse();
  if (!widget || widget->type != editor_type())
    return;

  Editor* editor = static_cast<Editor*>(widget);
  Sprite* sprite = editor->sprite();
  if (!sprite)
    return;

  // pixel position to get
  gfx::Point pixelPos = editor->screenToEditor(ui::get_mouse_position());

  // Check if we've to grab alpha channel or the merged color.
  ISettings* settings = UIContext::instance()->settings();
  bool grabAlpha = settings->getGrabAlpha();

  ColorPicker picker;
  picker.pickColor(editor->getSite(),
    pixelPos,
    grabAlpha ?
    ColorPicker::FromActiveLayer:
    ColorPicker::FromComposition);

  if (grabAlpha) {
    tools::ToolBox* toolBox = App::instance()->getToolBox();
    for (tools::ToolIterator it=toolBox->begin(), end=toolBox->end(); it!=end; ++it) {
      settings->getToolSettings(*it)->setOpacity(picker.alpha());
    }
  }

  if (m_background)
    settings->setBgColor(picker.color());
  else
    settings->setFgColor(picker.color());
}