Esempio n. 1
0
void sp_color_picker_color_mod(SPColorSelector *csel, GObject *cp)
{
    if (_in_use) {
        return;
    } else {
        _in_use = true;
    }

    SPColor color;
    float alpha = 0;
    csel->base->getColorAlpha(color, alpha);
    guint32 rgba = color.toRGBA32( alpha );

    ColorPicker *ptr = reinterpret_cast<ColorPicker *>(cp);

    (ptr->_preview).setRgba32 (rgba);

    if (ptr->_undo && SP_ACTIVE_DESKTOP)
        DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_NONE,
                           /* TODO: annotate */ "color-picker.cpp:130");

    ptr->on_changed (rgba);
    _in_use = false;
    ptr->_changed_signal.emit (rgba);
    ptr->_rgba = rgba;
}
Esempio n. 2
0
EffectSettingsWidget::EffectSettingsWidget(const QList<EffectParameter> &parameters, QWidget *parent)
    : QWidget(parent)
    , m_parameters(parameters)
{
    QFormLayout *layout = new QFormLayout;

    foreach (EffectParameter parameter, parameters) {
        switch (parameter.type()) {
        case QVariant::Int:
            {
                QSlider *slider = new QSlider(Qt::Horizontal);
                slider->setRange(parameter.minimum().toInt(), parameter.maximum().toInt());
                slider->setValue(parameter.defaultValue().toInt());
                slider->setSingleStep(parameter.step().toInt());

                layout->addRow(parameter.name(), slider);
                m_selectors.append(slider);
            }
            break;
        case QVariant::Color:
            {
                ColorPicker *picker = new ColorPicker;
                picker->setColor(qvariant_cast<QColor>(parameter.defaultValue()));

                layout->addRow(parameter.name(), picker);
                m_selectors.append(picker);
            }
            break;
        default:
            m_selectors.append(0);
        }
    }

    setLayout(layout);
}
Esempio n. 3
0
	QVariant ItemHandlerColor::GetValue (QObject *object) const
	{
		ColorPicker *colorPicker = qobject_cast<ColorPicker*> (object);
		if (!colorPicker)
		{
			qWarning () << Q_FUNC_INFO
				<< "not a ColorPicker"
				<< object;
			return QVariant ();
		}
		return colorPicker->GetCurrentColor ();
	}
Esempio n. 4
0
	void ItemHandlerColor::SetValue (QWidget *widget, const QVariant& value) const
	{
		ColorPicker *colorPicker = qobject_cast<ColorPicker*> (widget);
		if (!colorPicker)
		{
			qWarning () << Q_FUNC_INFO
				<< "not a ColorPicker"
				<< widget;
			return;
		}
		colorPicker->SetCurrentColor (value.value<QColor> ());
	}
Esempio n. 5
0
bool ColorSample::OnMouseButtonDown(int x, int y, Uint8 button)
{
	ColorPicker *colorPicker = new ColorPicker(r, g, b);
	if(colorPicker->Wait() == OK_BUTTON)
	{
		setColor(colorPicker->getRed(), colorPicker->getGreen(), colorPicker->getBlue());

		PostMessage(parent, COLOR_CHANGED);
	}
	
	delete colorPicker;
	return false;
}
Esempio n. 6
0
void MaskContentCommand::onExecute(Context* context)
{
  Document* document;
  {
    ContextWriter writer(context);
    document = writer.document();

    Cel* cel = writer.cel(); // Get current cel (can be NULL)
    if (!cel)
      return;

    gfx::Color color;
    if (writer.layer()->isBackground()) {
      ColorPicker picker;
      picker.pickColor(*writer.site(),
                       gfx::PointF(0.0, 0.0),
                       current_editor->projection(),
                       ColorPicker::FromComposition);
      color = color_utils::color_for_layer(picker.color(), writer.layer());
    }
    else
      color = cel->image()->maskColor();

    Mask newMask;
    gfx::Rect imgBounds = cel->image()->bounds();
    if (algorithm::shrink_bounds(cel->image(), imgBounds, color)) {
      newMask.replace(imgBounds.offset(cel->bounds().origin()));
    }
    else {
      newMask.replace(cel->bounds());
    }

    Transaction transaction(writer.context(), "Select Content", DoesntModifyDocument);
    transaction.execute(new cmd::SetMask(document, &newMask));
    transaction.commit();

    document->resetTransformation();
    document->generateMaskBoundaries();
  }

  // Select marquee tool
  if (tools::Tool* tool = App::instance()->toolBox()
      ->getToolById(tools::WellKnownTools::RectangularMarquee)) {
    ToolBar::instance()->selectTool(tool);
  }

  update_screen_for_document(document);
}
Esempio n. 7
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. 8
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. 9
0
TuneColorDialog::TuneColorDialog(int hue,int sat,int gamma,QWidget *parent) : QDialog(parent)
{
   setWindowTitle(tr("Tune the color of the HTML output"));
   QGridLayout *layout = new QGridLayout(this);
   m_image = new QImage(QString::fromAscii(":/images/tunecolor.png"));
   m_imageLab = new QLabel;
   updateImage(hue,sat,gamma);
   layout->addWidget(new QLabel(tr("Example output: use the sliders on the right to adjust the color")),0,0);
   layout->addWidget(m_imageLab,1,0);
   QHBoxLayout *buttonsLayout = new QHBoxLayout;

   QPushButton *okButton = new QPushButton(tr("Ok"));
   connect(okButton,SIGNAL(clicked()),SLOT(accept()));
   okButton->setDefault(true);
   QPushButton *cancelButton = new QPushButton(tr("Cancel"));
   connect(cancelButton,SIGNAL(clicked()),SLOT(reject()));

   ColorPicker *huePicker = new ColorPicker(ColorPicker::Hue);
   huePicker->setCol(hue,sat,gamma);
   huePicker->setFixedWidth(20);
   layout->addWidget(huePicker,1,1);
   ColorPicker *satPicker = new ColorPicker(ColorPicker::Saturation);
   satPicker->setCol(hue,sat,gamma);
   satPicker->setFixedWidth(20);
   layout->addWidget(satPicker,1,2);
   ColorPicker *gamPicker = new ColorPicker(ColorPicker::Gamma);
   gamPicker->setCol(hue,sat,gamma);
   gamPicker->setFixedWidth(20);
   layout->addWidget(gamPicker,1,3);

   connect(huePicker,SIGNAL(newHsv(int,int,int)),satPicker,SLOT(setCol(int,int,int)));
   connect(satPicker,SIGNAL(newHsv(int,int,int)),huePicker,SLOT(setCol(int,int,int)));
   connect(huePicker,SIGNAL(newHsv(int,int,int)),gamPicker,SLOT(setCol(int,int,int)));
   connect(satPicker,SIGNAL(newHsv(int,int,int)),gamPicker,SLOT(setCol(int,int,int)));
   connect(gamPicker,SIGNAL(newHsv(int,int,int)),satPicker,SLOT(setCol(int,int,int)));
   connect(gamPicker,SIGNAL(newHsv(int,int,int)),huePicker,SLOT(setCol(int,int,int)));
   connect(huePicker,SIGNAL(newHsv(int,int,int)),this,SLOT(updateImage(int,int,int)));
   connect(satPicker,SIGNAL(newHsv(int,int,int)),this,SLOT(updateImage(int,int,int)));
   connect(gamPicker,SIGNAL(newHsv(int,int,int)),this,SLOT(updateImage(int,int,int)));

   buttonsLayout->addStretch();
   buttonsLayout->addWidget(okButton);
   buttonsLayout->addWidget(cancelButton);
   layout->addLayout(buttonsLayout,5,0,1,4);
}
Esempio n. 10
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. 11
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());
}
Esempio n. 12
0
bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
{
  if (editor->hasCapture())
    return true;

  UIContext* context = UIContext::instance();
  tools::Ink* clickedInk = editor->getCurrentEditorInk();
  Site site;
  editor->getSite(&site);
  app::Document* document = static_cast<app::Document*>(site.document());
  Layer* layer = site.layer();

  // When an editor is clicked the current view is changed.
  context->setActiveView(editor->getDocumentView());

  // Start scroll loop
  if (checkForScroll(editor, msg) || checkForZoom(editor, msg))
    return true;

  // Move cel X,Y coordinates
  if (clickedInk->isCelMovement()) {
    // Handle "Auto Select Layer"
    if (editor->isAutoSelectLayer()) {
      gfx::Point cursor = editor->screenToEditor(msg->position());

      ColorPicker picker;
      picker.pickColor(site, cursor, ColorPicker::FromComposition);

      if (layer != picker.layer()) {
        layer = picker.layer();
        if (layer) {
          editor->setLayer(layer);
          editor->flashCurrentLayer();
        }
      }
    }

    if ((layer) &&
        (layer->type() == ObjectType::LayerImage)) {
      // TODO we should be able to move the `Background' with tiled mode
      if (layer->isBackground()) {
        StatusBar::instance()->showTip(1000,
          "The background layer cannot be moved");
      }
      else if (!layer->isVisible()) {
        StatusBar::instance()->showTip(1000,
          "Layer '%s' is hidden", layer->name().c_str());
      }
      else if (!layer->isMovable() || !layer->isEditable()) {
        StatusBar::instance()->showTip(1000,
          "Layer '%s' is locked", layer->name().c_str());
      }
      else {
        // Change to MovingCelState
        editor->setState(EditorStatePtr(new MovingCelState(editor, msg)));
      }
    }

    return true;
  }

  // Call the eyedropper command
  if (clickedInk->isEyedropper()) {
    callEyedropper(editor);
    return true;
  }

  if (clickedInk->isSelection()) {
    // Transform selected pixels
    if (document->isMaskVisible() && m_decorator->getTransformHandles(editor)) {
      TransformHandles* transfHandles = m_decorator->getTransformHandles(editor);

      // Get the handle covered by the mouse.
      HandleType handle = transfHandles->getHandleAtPoint(editor,
        msg->position(),
        document->getTransformation());

      if (handle != NoHandle) {
        int x, y, opacity;
        Image* image = site.image(&x, &y, &opacity);
        if (layer && image) {
          if (!layer->isEditable()) {
            StatusBar::instance()->showTip(1000,
              "Layer '%s' is locked", layer->name().c_str());
            return true;
          }

          // Change to MovingPixelsState
          transformSelection(editor, msg, handle);
        }
        return true;
      }
    }

    // Move selected pixels
    if (layer && editor->isInsideSelection() && msg->left()) {
      if (!layer->isEditable()) {
        StatusBar::instance()->showTip(1000,
          "Layer '%s' is locked", layer->name().c_str());
        return true;
      }

      // Change to MovingPixelsState
      transformSelection(editor, msg, MoveHandle);
      return true;
    }
  }

  // Start the Tool-Loop
  if (layer) {
    tools::ToolLoop* toolLoop = create_tool_loop(editor, context);
    if (toolLoop) {
      EditorStatePtr newState(new DrawingState(toolLoop));
      editor->setState(newState);

      static_cast<DrawingState*>(newState.get())
        ->initToolLoop(editor, msg);
    }
    return true;
  }

  return true;
}
Esempio n. 13
0
bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
{
  if (editor->hasCapture())
    return true;

  UIContext* context = UIContext::instance();
  tools::Ink* clickedInk = editor->getCurrentEditorInk();
  Site site;
  editor->getSite(&site);
  app::Document* document = static_cast<app::Document*>(site.document());
  Layer* layer = site.layer();

  // When an editor is clicked the current view is changed.
  context->setActiveView(editor->getDocumentView());

  // Start scroll loop
  if (checkForScroll(editor, msg) || checkForZoom(editor, msg))
    return true;

  // Move cel X,Y coordinates
  if (clickedInk->isCelMovement()) {
    // Handle "Auto Select Layer"
    if (editor->isAutoSelectLayer()) {
      gfx::Point cursor = editor->screenToEditor(msg->position());

      ColorPicker picker;
      picker.pickColor(site, cursor, ColorPicker::FromComposition);

      DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();

      // Change layer only when the layer is diffrent from current one, and
      // the range we selected is not with multiple cels.
      bool layerChanged = (layer != picker.layer());
      bool rangeEnabled = range.enabled();
      bool rangeSingleCel = ((range.type() == DocumentRange::kCels) &&
                             (range.layers() == 1) && (range.frames() == 1));

      if (layerChanged && (!rangeEnabled || rangeSingleCel)) {
        layer = picker.layer();
        if (layer) {
          editor->setLayer(layer);
          editor->flashCurrentLayer();
        }
      }
    }

    if ((layer) &&
        (layer->type() == ObjectType::LayerImage)) {
      // TODO we should be able to move the `Background' with tiled mode
      if (layer->isBackground()) {
        StatusBar::instance()->showTip(1000,
          "The background layer cannot be moved");
      }
      else if (!layer->isVisible()) {
        StatusBar::instance()->showTip(1000,
          "Layer '%s' is hidden", layer->name().c_str());
      }
      else if (!layer->isMovable() || !layer->isEditable()) {
        StatusBar::instance()->showTip(1000,
          "Layer '%s' is locked", layer->name().c_str());
      }
      else if (!layer->cel(editor->frame())) {
        StatusBar::instance()->showTip(1000,
          "Cel is empty, nothing to move");
      }
      else {
        // Change to MovingCelState
        editor->setState(EditorStatePtr(new MovingCelState(editor, msg)));
      }
    }

    return true;
  }

  // Call the eyedropper command
  if (clickedInk->isEyedropper()) {
    editor->captureMouse();
    callEyedropper(editor);
    return true;
  }

  if (clickedInk->isSelection()) {
    // Transform selected pixels
    if (editor->isActive() &&
        document->isMaskVisible() &&
        m_decorator->getTransformHandles(editor)) {
      TransformHandles* transfHandles = m_decorator->getTransformHandles(editor);

      // Get the handle covered by the mouse.
      HandleType handle = transfHandles->getHandleAtPoint(editor,
        msg->position(),
        document->getTransformation());

      if (handle != NoHandle) {
        int x, y, opacity;
        Image* image = site.image(&x, &y, &opacity);
        if (layer && image) {
          if (!layer->isEditable()) {
            StatusBar::instance()->showTip(1000,
              "Layer '%s' is locked", layer->name().c_str());
            return true;
          }

          // Change to MovingPixelsState
          transformSelection(editor, msg, handle);
        }
        return true;
      }
    }

    // Move selected pixels
    if (layer && editor->isInsideSelection() && msg->left()) {
      if (!layer->isEditable()) {
        StatusBar::instance()->showTip(1000,
          "Layer '%s' is locked", layer->name().c_str());
        return true;
      }

      // Change to MovingPixelsState
      transformSelection(editor, msg, MoveHandle);
      return true;
    }
  }

  // Move symmetry
  gfx::Rect box1, box2;
  if (m_decorator->getSymmetryHandles(editor, box1, box2) &&
      (box1.contains(msg->position()) ||
       box2.contains(msg->position()))) {
    auto& symmetry = Preferences::instance().document(editor->document()).symmetry;
    auto mode = symmetry.mode();
    bool horz = (mode == app::gen::SymmetryMode::HORIZONTAL);
    auto& axis = (horz ? symmetry.xAxis:
                         symmetry.yAxis);
    editor->setState(
      EditorStatePtr(new MovingSymmetryState(editor, msg,
                                             mode, axis)));
    return true;
  }

  // Start the Tool-Loop
  if (layer) {
    tools::ToolLoop* toolLoop = create_tool_loop(editor, context);
    if (toolLoop) {
      EditorStatePtr newState(new DrawingState(toolLoop));
      editor->setState(newState);

      static_cast<DrawingState*>(newState.get())
        ->initToolLoop(editor, msg);
    }
    return true;
  }

  return true;
}
Esempio n. 14
0
bool ColorButton::onProcessMessage(Message* msg)
{
  switch (msg->type()) {

    case kCloseMessage:
      if (m_window && m_window->isVisible())
        m_window->closeWindow(NULL);
      break;

    case kMouseEnterMessage:
      StatusBar::instance()->showColor(0, "", m_color);
      break;

    case kMouseLeaveMessage:
      StatusBar::instance()->clearText();
      break;

    case kMouseMoveMessage:
      if (hasCapture()) {
        gfx::Point mousePos = static_cast<MouseMessage*>(msg)->position();
        Widget* picked = getManager()->pick(mousePos);
        app::Color color = m_color;

        if (picked && picked != this) {
          // Pick a color from another color-button
          if (ColorButton* pickedColBut = dynamic_cast<ColorButton*>(picked)) {
            color = pickedColBut->getColor();
          }
          // Pick a color from the color-bar
          else if (picked->type() == palette_view_type()) {
            color = ((PaletteView*)picked)->getColorByPosition(mousePos);
          }
          // Pick a color from a editor
          else if (picked->type() == editor_type()) {
            Editor* editor = static_cast<Editor*>(picked);
            Site site = editor->getSite();
            if (site.sprite()) {
              gfx::Point editorPos = editor->screenToEditor(mousePos);

              ColorPicker picker;
              picker.pickColor(site, editorPos, ColorPicker::FromComposition);
              color = picker.color();
            }
          }
        }

        // Did the color change?
        if (color != m_color) {
          setColor(color);
        }
      }
      break;

    case kSetCursorMessage:
      if (hasCapture()) {
        ui::set_mouse_cursor(kEyedropperCursor);
        return true;
      }
      break;

  }

  return ButtonBase::onProcessMessage(msg);
}
Esempio n. 15
0
//==== Add Color Picker ====//
void GroupLayout::AddColorPicker( ColorPicker& picker )
{
    assert( m_Group && m_Screen );

    //==== Button ====//
    Fl_Button* colorButton = new Fl_Button( m_X, m_Y, m_ButtonWidth, m_StdHeight * 2, "Color:" );
    colorButton->box( FL_THIN_UP_BOX );
    colorButton->labelfont( 1 );
    colorButton->labelsize( 12 );
    colorButton->labelcolor( FL_BLACK );
    m_Group->add( colorButton );
    AddX( m_ButtonWidth );

    //==== Current Color Button ====//
    Fl_Button* primColorButton = new Fl_Button( m_X, m_Y, m_ButtonWidth / 2, m_StdHeight * 2 );
    primColorButton->box( FL_THIN_DOWN_BOX );
    primColorButton->color( ( Fl_Color )2 );
    m_Group->add( primColorButton );
    AddX( m_ButtonWidth / 2 + 2 );

    //==== Sliders ====//
    int ch = 2 * m_StdHeight / 3;
    int cw = m_StdHeight;

    int sw = FitWidth( m_ButtonWidth + m_ButtonWidth / 2 + 2 + 4 * cw, m_SliderWidth );
    Fl_Slider* sliders[3];
    for ( int i = 0 ; i < 3 ; i++ )
    {
        sliders[i] = new Fl_Value_Slider( m_X, m_Y + i * ch, sw, ch );
        sliders[i]->type( 5 );
        sliders[i]->color( FL_BACKGROUND2_COLOR );
        sliders[i]->selection_color( ( Fl_Color )1 );
        sliders[i]->maximum( 255 );
        sliders[i]->step( 1 );
        m_Group->add( sliders[i] );
    }
    sliders[0]->selection_color( ( Fl_Color )1 );
    sliders[1]->selection_color( ( Fl_Color )2 );
    sliders[2]->selection_color( ( Fl_Color )4 );
    AddX( sw + 2 );

    //==== Color Buttons ====//
    vector< Fl_Button* > cvec;
    int color_index = 0;
    for ( int i = 0 ; i < 4 ; i++ )
    {
        for ( int j = 0 ; j < 3 ; j++ )
        {
            Fl_Button* b = new Fl_Button( m_X + i * cw, m_Y + j * ch, cw, ch );
            vec3d rgb = picker.GetIndexRGB( color_index );
            Fl_Color c = fl_rgb_color( ( int )rgb[0], ( int )rgb[1], ( int )rgb[2] );
            b->color( c );
            m_Group->add( b );
            cvec.push_back( b );
            color_index++;
        }
    }
    AddX( 3 * cw );

    picker.Init( m_Screen, colorButton, primColorButton, cvec, sliders );

    AddY( m_StdHeight * 2 );
    NewLineX();
}
Esempio n. 16
0
void EyedropperCommand::pickSample(const doc::Site& site,
                                   const gfx::Point& pixelPos,
                                   app::Color& color)
{
  // Check if we've to grab alpha channel or the merged color.
  Preferences& pref = Preferences::instance();
  bool allLayers =
    (pref.eyedropper.sample() == app::gen::EyedropperSample::ALL_LAYERS);

  ColorPicker picker;
  picker.pickColor(site,
                   pixelPos,
                   (allLayers ?
                    ColorPicker::FromComposition:
                    ColorPicker::FromActiveLayer));

  app::gen::EyedropperChannel channel =
    pref.eyedropper.channel();

  app::Color picked = picker.color();

  switch (channel) {
    case app::gen::EyedropperChannel::COLOR_ALPHA:
      color = picked;
      break;
    case app::gen::EyedropperChannel::COLOR:
      if (picked.getAlpha() > 0)
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::ALPHA:
      switch (color.getType()) {

        case app::Color::RgbType:
        case app::Color::IndexType:
          color = app::Color::fromRgb(color.getRed(),
                                      color.getGreen(),
                                      color.getBlue(),
                                      picked.getAlpha());
          break;

        case app::Color::HsvType:
          color = app::Color::fromHsv(color.getHue(),
                                      color.getSaturation(),
                                      color.getValue(),
                                      picked.getAlpha());
          break;

        case app::Color::GrayType:
          color = app::Color::fromGray(color.getGray(),
                                       picked.getAlpha());
          break;

      }
      break;
    case app::gen::EyedropperChannel::RGBA:
      if (picked.getType() == app::Color::RgbType)
        color = picked;
      else
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::RGB:
      if (picked.getAlpha() > 0)
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::HSVA:
      if (picked.getType() == app::Color::HsvType)
        color = picked;
      else
        color = app::Color::fromHsv(picked.getHue(),
                                    picked.getSaturation(),
                                    picked.getValue(),
                                    picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::HSV:
      if (picked.getAlpha() > 0)
        color = app::Color::fromHsv(picked.getHue(),
                                    picked.getSaturation(),
                                    picked.getValue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::GRAYA:
      if (picked.getType() == app::Color::GrayType)
        color = picked;
      else
        color = app::Color::fromGray(picked.getGray(),
                                     picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::GRAY:
      if (picked.getAlpha() > 0)
        color = app::Color::fromGray(picked.getGray(),
                                     color.getAlpha());
      break;
    case app::gen::EyedropperChannel::INDEX:
      color = app::Color::fromIndex(picked.getIndex());
      break;
  }
}
Esempio n. 17
-1
	void ItemHandlerColor::Handle (const QDomElement& item, QWidget *pwidget)
	{
		QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ());
		QString labelString = XSD_->GetLabel (item);
		QLabel *label = new QLabel (labelString);
		label->setWordWrap (false);

		ColorPicker *picker = new ColorPicker (labelString);
		picker->setObjectName (item.attribute ("property"));
		picker->SetCurrentColor (XSD_->GetValue (item).value<QColor> ());

		connect (picker,
				SIGNAL (currentColorChanged (const QColor&)),
				this,
				SLOT (updatePreferences ()));

		picker->setProperty ("ItemHandler",
				QVariant::fromValue<QObject*> (this));

		int row = lay->rowCount ();
		lay->setColumnMinimumWidth (0, 10);
		lay->setColumnStretch (0, 1);
		lay->setColumnStretch (1, 10);
		lay->addWidget (label, row, 0);
		lay->addWidget (picker, row, 1, Qt::AlignLeft);
	}