void StatusBar::onActiveSiteChange(const doc::Site& site) { if (site.document() && site.sprite()) { m_hasDoc = true; m_commandsBox->setVisible(true); // Current frame m_currentFrame->setTextf("%d", site.frame()+1); // Cel opacity const Cel* cel; if (site.sprite()->supportAlpha() && site.layer() && site.layer()->isImage() && !site.layer()->isBackground() && (cel = site.layer()->cel(site.frame()))) { m_slider->setValue(MID(0, cel->opacity(), 255)); m_slider->setEnabled(true); } else { m_slider->setValue(255); m_slider->setEnabled(false); } } else { m_hasDoc = false; m_commandsBox->setVisible(false); } }
void ColorPicker::pickColor(const doc::Site& site, const gfx::PointF& _pos, const render::Projection& proj, const Mode mode) { const doc::Sprite* sprite = site.sprite(); gfx::PointF pos = _pos; m_alpha = 255; m_color = app::Color::fromMask(); // Check tiled mode if (sprite && site.document()) { const app::Document* doc = static_cast<const app::Document*>(site.document()); DocumentPreferences& docPref = Preferences::instance().document(doc); pos = wrap_pointF(docPref.tiled.mode(), site.sprite()->size(), pos); } // Get the color from the image switch (mode) { // Pick from the composed image case FromComposition: { m_color = app::Color::fromImage( sprite->pixelFormat(), render::get_sprite_pixel(sprite, pos.x, pos.y, site.frame(), proj)); doc::CelList cels; sprite->pickCels(pos.x, pos.y, site.frame(), 128, sprite->allVisibleLayers(), cels); if (!cels.empty()) m_layer = cels.front()->layer(); break; } // Pick from the current layer case FromActiveLayer: { const Cel* cel = site.cel(); if (cel) { doc::color_t imageColor; if (!get_cel_pixel(cel, pos.x, pos.y, site.frame(), imageColor)) return; const doc::Image* image = cel->image(); 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*>(site.layer()); } break; } case FromFirstReferenceLayer: { doc::CelList cels; sprite->pickCels(pos.x, pos.y, site.frame(), 128, sprite->allVisibleReferenceLayers(), cels); for (const Cel* cel : cels) { doc::color_t imageColor; if (get_cel_pixel(cel, pos.x, pos.y, site.frame(), imageColor)) { m_color = app::Color::fromImage( cel->image()->pixelFormat(), imageColor); m_layer = cel->layer(); break; } } break; } } }