MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / create_tool_loop

Function create_tool_loop

src/app/ui/editor/tool_loop_impl.cpp:480–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478};
479
480tools::ToolLoop* create_tool_loop(Editor* editor, Context* context)
481{
482 tools::Tool* current_tool = editor->getCurrentEditorTool();
483 std::shared_ptr<tools::Ink> current_ink = editor->getCurrentEditorInk();
484 if (!current_tool || !current_ink)
485 return nullptr;
486
487 Layer* layer;
488
489 // For selection tools, we can use any layer (even without layers at
490 // all), so we specify a nullptr here as the active layer. This is
491 // used as a special case by the render::Render class to show the
492 // preview image/selection stroke as a xor'd overlay in the render
493 // result.
494 //
495 // Anyway this cannot be used in 'magic wand' tool (isSelection +
496 // isFloodFill) because we need the original layer source
497 // image/pixels to stop the flood-fill algorithm.
498 if (current_ink->isSelection() &&
499 !current_tool->getPointShape(editor->isSecondaryButton() ? 1: 0)->isFloodFill()) {
500 layer = nullptr;
501 }
502 else {
503 layer = editor->layer();
504 if (!layer) {
505 StatusBar::instance()->showTip(
506 1000, "There is no active layer");
507 return nullptr;
508 }
509 else if (!layer->isVisible()) {
510 StatusBar::instance()->showTip(
511 1000, "Layer '%s' is hidden", layer->name().c_str());
512 return nullptr;
513 }
514 // If the active layer is read-only.
515 else if (!layer->isEditable()) {
516 StatusBar::instance()->showTip(
517 1000, "Layer '%s' is locked", layer->name().c_str());
518 return nullptr;
519 }
520 }
521
522 // Get fg/bg colors
523 ColorBar* colorbar = ColorBar::instance();
524 app::Color fg = colorbar->getFgColor();
525 app::Color bg = colorbar->getBgColor();
526
527 ASSERT(fg.isValid());
528 ASSERT(bg.isValid());
529
530 if (!fg.isValid() || !bg.isValid()) {
531 Alert::show(PACKAGE
532 "<<The current selected foreground and/or background color"
533 "<<is out of range. Select a valid color in the color-bar."
534 "||&Close");
535 return NULL;
536 }
537

Callers 1

onMouseDownMethod · 0.85

Calls 15

instanceFunction · 0.85
getCurrentEditorToolMethod · 0.80
getCurrentEditorInkMethod · 0.80
isSecondaryButtonMethod · 0.80
showTipMethod · 0.80
whatMethod · 0.80
isSelectionMethod · 0.45
isFloodFillMethod · 0.45
getPointShapeMethod · 0.45
layerMethod · 0.45
isVisibleMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected