ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
  TiledMode tiledMode, Transaction& transaction, Flags flags)
  : m_document(location.document())
  , m_sprite(location.sprite())
  , m_layer(location.layer())
  , m_cel(NULL)
  , m_celImage(NULL)
  , m_celCreated(false)
  , m_flags(flags)
  , m_srcImage(NULL)
  , m_dstImage(NULL)
  , m_closed(false)
  , m_committed(false)
  , m_transaction(transaction)
{
  create_buffers();

  if (m_layer->isImage()) {
    m_cel = m_layer->cel(location.frame());
    if (m_cel)
      m_celImage = m_cel->imageRef();
  }

  // Create a new cel
  if (m_cel == NULL) {
    m_celCreated = true;
    m_cel = new Cel(location.frame(), ImageRef(NULL));
  }

  m_origCelPos = m_cel->position();

  // Region to draw
  gfx::Rect celBounds(
    m_cel->x(),
    m_cel->y(),
    m_celImage ? m_celImage->width(): m_sprite->width(),
    m_celImage ? m_celImage->height(): m_sprite->height());

  gfx::Rect spriteBounds(0, 0,
    m_sprite->width(),
    m_sprite->height());

  if (tiledMode == TiledMode::NONE) { // Non-tiled
    m_bounds = celBounds.createUnion(spriteBounds);
  }
  else {                         // Tiled
    m_bounds = spriteBounds;
  }

  // We have to adjust the cel position to match the m_dstImage
  // position (the new m_dstImage will be used in RenderEngine to
  // draw this cel).
  m_cel->setPosition(m_bounds.x, m_bounds.y);

  if (m_celCreated) {
    getDestCanvas();
    m_cel->data()->setImage(m_dstImage);
    static_cast<LayerImage*>(m_layer)->addCel(m_cel);
  }
}
示例#2
0
ExpandCelCanvas::ExpandCelCanvas(Context* context, TiledMode tiledMode, UndoTransaction& undo, Flags flags)
  : m_cel(NULL)
  , m_celImage(NULL)
  , m_celCreated(false)
  , m_flags(flags)
  , m_srcImage(NULL)
  , m_dstImage(NULL)
  , m_closed(false)
  , m_committed(false)
  , m_undo(undo)
{
  create_buffers();

  DocumentLocation location = context->activeLocation();
  m_document = location.document();
  m_sprite = location.sprite();
  m_layer = location.layer();

  if (m_layer->isImage()) {
    m_cel = static_cast<LayerImage*>(m_layer)->getCel(location.frame());
    if (m_cel)
      m_celImage = m_cel->image();
  }

  // If there is no Cel
  if (m_cel == NULL) {
    // Create the cel
    m_celCreated = true;
    m_cel = new Cel(location.frame(), 0);
    static_cast<LayerImage*>(m_layer)->addCel(m_cel);
  }

  m_origCelPos = m_cel->position();

  // Region to draw
  gfx::Rect celBounds(
    m_cel->x(),
    m_cel->y(),
    m_celImage ? m_celImage->width(): m_sprite->width(),
    m_celImage ? m_celImage->height(): m_sprite->height());

  gfx::Rect spriteBounds(0, 0,
    m_sprite->width(),
    m_sprite->height());

  if (tiledMode == TILED_NONE) { // Non-tiled
    m_bounds = celBounds.createUnion(spriteBounds);
  }
  else {                         // Tiled
    m_bounds = spriteBounds;
  }

  // We have to adjust the cel position to match the m_dstImage
  // position (the new m_dstImage will be used in RenderEngine to
  // draw this cel).
  m_cel->setPosition(m_bounds.x, m_bounds.y);
}
示例#3
0
UndoTransaction::UndoTransaction(Context* context, const char* label, undo::Modification modification)
  : m_context(context)
  , m_label(label)
  , m_modification(modification)
{
  ASSERT(label != NULL);

  DocumentLocation location = m_context->getActiveLocation();

  m_document = location.document();
  m_sprite = location.sprite();
  m_undo = m_document->getUndo();
  m_closed = false;
  m_committed = false;
  m_enabledFlag = m_undo->isEnabled();

  if (isEnabled()) {
    SpritePosition position(m_sprite->layerToIndex(location.layer()),
                            location.frame());
    m_undo->pushUndoer(new undoers::OpenGroup(getObjects(),
                                              m_label,
                                              m_modification,
                                              m_sprite,
                                              position));
  }
}
示例#4
0
void ColorPicker::pickColor(const DocumentLocation& location, int x, int y, Mode mode)
{
  m_alpha = 255;
  m_color = app::Color::fromMask();

  // Get the color from the image
  if (mode == FromComposition) { // Pick from the composed image
    m_color = app::Color::fromImage(
      location.sprite()->pixelFormat(),
      location.sprite()->getPixel(x, y, location.frame()));
  }
  else {                        // Pick from the current layer
    int u, v;
    doc::Image* image = location.image(&u, &v, NULL);
    gfx::Point pt(x-u, y-v);

    if (image && image->bounds().contains(pt)) {
      doc::color_t imageColor = get_pixel(image, pt.x, pt.y);

      switch (image->pixelFormat()) {
        case IMAGE_RGB:
          m_alpha = doc::rgba_geta(imageColor);
          break;
        case IMAGE_GRAYSCALE:
          m_alpha = doc::graya_geta(imageColor);
          break;
      }

      m_color = app::Color::fromImage(image->pixelFormat(), imageColor);
    }
  }
}
示例#5
0
void ColorPicker::pickColor(const DocumentLocation& location,
  const gfx::Point& pos, Mode mode)
{
  m_alpha = 255;
  m_color = app::Color::fromMask();

  // Get the color from the image
  if (mode == FromComposition) { // Pick from the composed image
    m_color = app::Color::fromImage(
      location.sprite()->pixelFormat(),
      render::get_sprite_pixel(location.sprite(), pos.x, pos.y, location.frame()));

    doc::CelList cels;
    location.sprite()->pickCels(pos.x, pos.y, location.frame(), 128, cels);
    if (!cels.empty())
      m_layer = cels.front()->layer();
  }
  else {                        // Pick from the current layer
    int u, v;
    doc::Image* image = location.image(&u, &v, NULL);
    gfx::Point pt(pos.x-u, pos.y-v);

    if (image && image->bounds().contains(pt)) {
      doc::color_t imageColor = get_pixel(image, pt.x, pt.y);

      switch (image->pixelFormat()) {
        case IMAGE_RGB:
          m_alpha = doc::rgba_geta(imageColor);
          break;
        case IMAGE_GRAYSCALE:
          m_alpha = doc::graya_geta(imageColor);
          break;
      }

      m_color = app::Color::fromImage(image->pixelFormat(), imageColor);
      m_layer = const_cast<Layer*>(location.layer());
    }
  }
}
示例#6
0
static bool copy_from_document(const DocumentLocation& location)
{
  const Document* document = location.document();

  ASSERT(document != NULL);
  ASSERT(document->isMaskVisible());

  Image* image = NewImageFromMask(location);
  if (!image)
    return false;

  clipboard_x = document->getMask()->getBounds().x;
  clipboard_y = document->getMask()->getBounds().y;

  const Palette* pal = document->getSprite()->getPalette(location.frame());
  set_clipboard(image, pal ? new Palette(*pal): NULL, true);
  return true;
}
示例#7
0
void UndoTransaction::closeUndoGroup()
{
  ASSERT(!m_closed);

  if (isEnabled()) {
    DocumentLocation location = m_context->getActiveLocation();
    SpritePosition position(m_sprite->layerToIndex(location.layer()),
                            location.frame());

    // Close the undo information.
    m_undo->pushUndoer(new undoers::CloseGroup(getObjects(),
                                               m_label,
                                               m_modification,
                                               m_sprite,
                                               position));
    m_closed = true;
  }
}
示例#8
0
void StatusBar::updateCurrentFrame()
{
  DocumentLocation location = UIContext::instance()->getActiveLocation();
  if (location.sprite())
    m_currentFrame->setTextf("%d", location.frame()+1);
}
ExpandCelCanvas::ExpandCelCanvas(Context* context, TiledMode tiledMode, UndoTransaction& undo)
  : m_cel(NULL)
  , m_celImage(NULL)
  , m_celCreated(false)
  , m_closed(false)
  , m_committed(false)
  , m_undo(undo)
{
  create_buffers();

  DocumentLocation location = context->getActiveLocation();
  m_document = location.document();
  m_sprite = location.sprite();
  m_layer = location.layer();

  if (m_layer->isImage()) {
    m_cel = static_cast<LayerImage*>(m_layer)->getCel(location.frame());
    if (m_cel)
      m_celImage = m_sprite->getStock()->getImage(m_cel->getImage());
  }

  // If there is no Cel
  if (m_cel == NULL) {
    // Create the image
    m_celImage = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(),
                               m_sprite->getHeight());
    clear_image(m_celImage, m_sprite->getTransparentColor());

    // Create the cel
    m_cel = new Cel(location.frame(), 0);
    static_cast<LayerImage*>(m_layer)->addCel(m_cel);

    m_celCreated = true;
  }

  m_originalCelX = m_cel->getX();
  m_originalCelY = m_cel->getY();

  // Region to draw
  int x1, y1, x2, y2;

  if (tiledMode == TILED_NONE) { // Non-tiled
    x1 = MIN(m_cel->getX(), 0);
    y1 = MIN(m_cel->getY(), 0);
    x2 = MAX(m_cel->getX()+m_celImage->getWidth(), m_sprite->getWidth());
    y2 = MAX(m_cel->getY()+m_celImage->getHeight(), m_sprite->getHeight());
  }
  else {                        // Tiled
    x1 = 0;
    y1 = 0;
    x2 = m_sprite->getWidth();
    y2 = m_sprite->getHeight();
  }

  // create two copies of the image region which we'll modify with the tool
  m_srcImage = crop_image(m_celImage,
    x1-m_cel->getX(),
    y1-m_cel->getY(), x2-x1, y2-y1,
    m_sprite->getTransparentColor(),
    src_buffer);

  m_dstImage = Image::createCopy(m_srcImage, dst_buffer);

  // We have to adjust the cel position to match the m_dstImage
  // position (the new m_dstImage will be used in RenderEngine to
  // draw this cel).
  m_cel->setPosition(x1, y1);
}