// static she::Surface* BrushPopup::createSurfaceForBrush(const BrushRef& origBrush) { Image* image = nullptr; BrushRef brush = origBrush; if (brush) { if (brush->type() != kImageBrushType && brush->size() > 10) { brush.reset(new Brush(*brush)); brush->setSize(10); } image = brush->image(); } she::Surface* surface = she::instance()->createRgbaSurface( std::min(10, image ? image->width(): 4), std::min(10, image ? image->height(): 4)); if (image) { Palette* palette = get_current_palette(); if (image->pixelFormat() == IMAGE_BITMAP) { palette = new Palette(frame_t(0), 2); palette->setEntry(0, rgba(0, 0, 0, 0)); palette->setEntry(1, rgba(0, 0, 0, 255)); } convert_image_to_surface( image, palette, surface, 0, 0, 0, 0, image->width(), image->height()); if (image->pixelFormat() == IMAGE_BITMAP) delete palette; } else { she::ScopedSurfaceLock lock(surface); lock->clear(); } return surface; }
ToolLoopBase(Editor* editor, tools::Tool* tool, tools::Ink* ink, Document* document, tools::ToolLoop::Button button, const app::Color& fgColor, const app::Color& bgColor) : m_editor(editor) , m_tool(tool) , m_brush(App::instance()->contextBar()->activeBrush(m_tool)) , m_document(document) , m_sprite(editor->sprite()) , m_layer(editor->layer()) , m_frame(editor->frame()) , m_rgbMap(nullptr) , m_docPref(Preferences::instance().document(m_document)) , m_toolPref(Preferences::instance().tool(m_tool)) , m_opacity(m_toolPref.opacity()) , m_tolerance(m_toolPref.tolerance()) , m_contiguous(m_toolPref.contiguous()) , m_button(button) , m_ink(ink->clone()) , m_controller(m_tool->getController(m_button)) , m_pointShape(m_tool->getPointShape(m_button)) , m_intertwine(m_tool->getIntertwine(m_button)) , m_tracePolicy(m_tool->getTracePolicy(m_button)) , m_symmetry(nullptr) , m_fgColor(color_utils::color_for_target_mask(fgColor, ColorTarget(m_layer))) , m_bgColor(color_utils::color_for_target_mask(bgColor, ColorTarget(m_layer))) , m_primaryColor(button == tools::ToolLoop::Left ? m_fgColor: m_bgColor) , m_secondaryColor(button == tools::ToolLoop::Left ? m_bgColor: m_fgColor) { tools::FreehandAlgorithm algorithm = m_toolPref.freehandAlgorithm(); if (m_tracePolicy == tools::TracePolicy::Accumulate || m_tracePolicy == tools::TracePolicy::AccumulateUpdateLast) { tools::ToolBox* toolbox = App::instance()->toolBox(); switch (algorithm) { case tools::FreehandAlgorithm::DEFAULT: m_intertwine = toolbox->getIntertwinerById(tools::WellKnownIntertwiners::AsLines); m_tracePolicy = tools::TracePolicy::Accumulate; break; case tools::FreehandAlgorithm::PIXEL_PERFECT: m_intertwine = toolbox->getIntertwinerById(tools::WellKnownIntertwiners::AsPixelPerfect); m_tracePolicy = tools::TracePolicy::AccumulateUpdateLast; break; case tools::FreehandAlgorithm::DOTS: m_intertwine = toolbox->getIntertwinerById(tools::WellKnownIntertwiners::None); m_tracePolicy = tools::TracePolicy::Accumulate; break; } } // Symmetry mode if (Preferences::instance().symmetryMode.enabled()) { switch (m_docPref.symmetry.mode()) { case app::gen::SymmetryMode::NONE: ASSERT(m_symmetry == nullptr); break; case app::gen::SymmetryMode::HORIZONTAL: m_symmetry.reset(new app::tools::HorizontalSymmetry(m_docPref.symmetry.xAxis())); break; case app::gen::SymmetryMode::VERTICAL: m_symmetry.reset(new app::tools::VerticalSymmetry(m_docPref.symmetry.yAxis())); break; } } // Ignore opacity for these inks if (!tools::inkHasOpacity(m_toolPref.ink()) && m_brush->type() != kImageBrushType && !m_ink->isEffect()) { m_opacity = 255; } if (m_toolPref.ink() == tools::InkType::SHADING) { m_shadingRemap.reset( App::instance()->contextBar()->createShadeRemap( button == tools::ToolLoop::Left)); } }