15#include <glibmm/i18n.h>
18#include <unordered_map>
37#define DISTANCE_BG_RADIUS 0.3
111 : _snaptarget(nullptr),
112 _snaptarget_tooltip(nullptr),
113 _snaptarget_bbox(nullptr),
114 _snapsource(nullptr),
115 _snaptarget_is_presnap(false),
150 double scale = prefs->
getDouble(
"/tools/measure/scale", 100.0) / 100.0;
152 bool value = prefs->
getBool(
"/options/snapindicator/value",
true);
155 Glib::ustring target_name = _(
"UNDEFINED");
156 Glib::ustring source_name = _(
"UNDEFINED");
158 if (!is_alignment && !is_distribution) {
160 g_warning(
"Target type %i not present in target2string", p.
getTarget());
163 g_warning(
"Source type %i not present in target2string", p.
getSource());
172 double timeout_val = prefs->
getDouble(
"/options/snapindicatorpersistence/value", 2.0);
173 if (timeout_val < 0.1) {
180 double fontsize = prefs->
getDouble(
"/tools/measure/fontsize", 10.0);
182 if (is_distribution) {
199 if (!is_alignment && !is_distribution) {
219 Glib::ustring tooltip_str;
221 tooltip_str = source_name + _(
" to ") + target_name;
223 tooltip_str = source_name;
227 if (!tooltip_str.empty()) {
237 canvas_tooltip->set_fontsize(fontsize);
238 canvas_tooltip->set_fill(0xffffffff);
239 canvas_tooltip->set_background(pre_snap ? 0x33337f40 : 0x33337f7f);
248 box->set_stroke(pre_snap ? 0x7f7f7fff : 0xff0000ff);
249 box->set_dashed(
true);
250 box->set_pickable(
false);
251 box->lower_to_bottom();
300 bool value = prefs->
getBool(
"/options/snapindicator/value",
true);
354 g_warning(
"Alignment guide color not handled %i", t);
398 g_assert(p1.
x() == p2.
x() || p1.
y() == p2.
y());
401 bool show_distance = prefs->
getBool(
"/options/snapindicatordistance/value",
false);
406 ctrl->set_position(p1);
407 ctrl->set_pickable(
false);
411 ctrl->set_position(p2);
412 ctrl->set_pickable(
false);
417 if (show_distance && dist > 2 *
offset) {
419 auto text_pos = (p1 + p2)/2;
422 if (!unit_name.compare(
"")) {
423 unit_name = DEFAULT_UNIT_NAME;
431 text->set_fontsize(fontsize);
432 text->set_fill(color);
433 text->set_background(0xffffffc8);
434 text->set_bg_radius(DISTANCE_BG_RADIUS);
435 text->set_anchor({0.5, 0.5});
438 auto temp_point = text_pos +
offset*direction;
444 temp_point = text_pos -
offset*direction;
461 line->set_stroke(0xff5f1fff);
469 line->set_stroke(0xff5f1fff);
478 bool show_distance = prefs->
getBool(
"/options/snapindicatordistance/value",
false);
481 guint32 text_fill = 0xffffffff;
484 double text_offset = (fontsize * 2);
486 double line_offset = 0;
489 if (!unit_name.compare(
"")) {
490 unit_name = DEFAULT_UNIT_NAME;
512 p2 =
Geom::Point(std::next(it)->min().x() - line_offset, y);
525 p2 =
Geom::Point(x, std::next(it)->min().y() - line_offset);
538 line1->set_stroke(color);
544 text->set_fontsize(fontsize);
545 text->set_fill(text_fill);
546 text->set_background(text_bg);
547 text->set_bg_radius(DISTANCE_BG_RADIUS);
548 text->set_anchor({0.5, 0.5});
564 p2 =
Geom::Point(std::next(it)->min().x() - line_offset, y);
574 line1->set_stroke(color);
580 text->set_fontsize(fontsize);
581 text->set_fill(text_fill);
582 text->set_background(text_bg);
583 text->set_bg_radius(DISTANCE_BG_RADIUS);
584 text->set_anchor({0.5, 0.5});
592 p2 =
Geom::Point(x, std::next(it)->min().y() - line_offset);
602 line1->set_stroke(color);
608 text->set_fontsize(fontsize);
609 text->set_fill(text_fill);
610 text->set_background(text_bg);
611 text->set_bg_radius(DISTANCE_BG_RADIUS);
612 text->set_anchor({0.5, 0.5});
double distance(Shape const *s, Geom::Point const &p)
CPoint midpoint() const
Get the point in the geometric center of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Axis-aligned rectangle that can be empty.
Two-dimensional point that doubles as a vector.
constexpr Coord y() const noexcept
constexpr Coord x() const noexcept
Axis aligned, non-empty rectangle.
void set_selected(bool selected=true)
void set_bg_alpha(float alpha)
Set background stroke alpha.
virtual void set_stroke(uint32_t rgba)
void set_pickable(bool pickable)
void make_alignment_indicator(Geom::Point const &p1, Geom::Point const &p2, guint32 color, double fontsize, double scale)
std::list< TemporaryItem * > _alignment_snap_indicators
TemporaryItem * _snapsource
void set_new_snapsource(Inkscape::SnapCandidatePoint const &p)
void remove_snaptarget(bool only_if_presnap=false)
Inkscape::CanvasItemCurve * make_stub_line_h(Geom::Point const &p)
TemporaryItem * _snaptarget_tooltip
TemporaryItem * _snaptarget
TemporaryItem * _snaptarget_bbox
std::list< TemporaryItem * > _distribution_snap_indicators
void remove_debugging_points()
std::list< TemporaryItem * > _debugging_points
void make_distribution_indicators(SnappedPoint const &p, double fontsize, double scale)
SnapIndicator(SPDesktop *desktop)
bool _snaptarget_is_presnap
void set_new_debugging_point(Geom::Point const &p)
guint32 get_guide_color(SnapTargetType t)
Inkscape::CanvasItemCurve * make_stub_line_v(Geom::Point const &p)
void set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap=false)
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit="")
Retrieve a floating point value.
static Preferences * get()
Access the singleton Preferences object.
Class to store data for points which are snap candidates, either as a source or as a target.
Geom::Point const & getPoint() const
Class describing the result of an attempt to snap.
std::vector< Geom::Rect > const & getBBoxes2() const
std::optional< Geom::Point > getAlignmentTarget() const
Geom::Coord getDistributionDistance() const
Geom::OptRect const getTargetBBox() const
SnapTargetType getTarget() const
std::optional< Geom::Point > getAlignmentTarget2() const
Geom::Point getPoint() const
SnapTargetType getAlignmentTargetType() const
SnapSourceType getSource() const
Geom::Coord getDistributionDistance2() const
std::vector< Geom::Rect > const & getBBoxes() const
static double convert(double from_dist, Unit const *from, Unit const *to)
Convert distances.
To do: update description of desktop.
double current_zoom() const
Inkscape::Display::TemporaryItem * add_temporary_canvasitem(Inkscape::CanvasItem *item, int lifetime_msecs, bool move_to_bottom=true)
One should not keep a reference to the SPCanvasItem, the temporary item code will delete the object f...
Inkscape::CanvasItemGroup * getCanvasTemp() const
void remove_temporary_canvasitem(Inkscape::Display::TemporaryItem *tempitem)
It is perfectly safe to call this function while the object has already been deleted due to a timeout...
Inkscape::UI::Tools::ToolBase * getTool() const
Geom::Affine const & w2d() const
Transformation from window to desktop coordinates (zoom/rotate).
Inkscape::Util::Unit const * getDisplayUnit()
guaranteed not to return nullptr
Editable view implementation.
double Coord
Floating point type used to store coordinates.
SBasis L2(D2< SBasis > const &a, unsigned k)
Point unit_vector(Point const &a)
std::pair< Geom::Coord, int > get_x_and_sign(Geom::Rect const &source, Geom::Rect const &target, double const offset)
std::pair< Geom::Coord, int > get_y_and_sign(Geom::Rect const &source, Geom::Rect const &target, double const offset)
static std::map< SnapSourceType, Glib::ustring > source2string
static std::map< SnapTargetType, Glib::ustring > target2string
Glib::ustring format_classic(T const &... args)
Helper class to stream background task notifications as a series of messages.
@ SNAPSOURCE_BBOX_MIDPOINT
@ SNAPSOURCE_PATH_INTERSECTION
@ SNAPSOURCE_OTHER_HANDLE
@ SNAPSOURCE_GUIDE_ORIGIN
@ SNAPSOURCE_CONVEX_HULL_CORNER
@ SNAPSOURCE_OBJECT_MIDPOINT
@ SNAPSOURCE_LINE_MIDPOINT
@ SNAPSOURCE_BBOX_EDGE_MIDPOINT
@ SNAPSOURCE_ELLIPSE_QUADRANT_POINT
@ SNAPSOURCE_ROTATION_CENTER
@ SNAPTARGET_ALIGNMENT_BBOX_MIDPOINT
@ SNAPTARGET_GUIDE_ORIGIN
@ SNAPTARGET_BBOX_EDGE_MIDPOINT
@ SNAPTARGET_ALIGNMENT_PAGE_MARGIN_CORNER
@ SNAPTARGET_PATH_GUIDE_INTERSECTION
@ SNAPTARGET_PAGE_MARGIN_BORDER
@ SNAPTARGET_ALIGNMENT_PAGE_BLEED_CORNER
@ SNAPTARGET_DISTRIBUTION_XY
@ SNAPTARGET_PAGE_MARGIN_CENTER
@ SNAPTARGET_DISTRIBUTION_LEFT
@ SNAPTARGET_DISTRIBUTION_DOWN
@ SNAPTARGET_ROTATION_CENTER
@ SNAPTARGET_LINE_MIDPOINT
@ SNAPTARGET_GUIDE_PERPENDICULAR
@ SNAPTARGET_ALIGNMENT_PAGE_EDGE_CENTER
@ SNAPTARGET_PAGE_BLEED_CORNER
@ SNAPTARGET_BBOX_MIDPOINT
@ SNAPTARGET_GRID_INTERSECTION
@ SNAPTARGET_ALIGNMENT_INTERSECTION
@ SNAPTARGET_PAGE_EDGE_CENTER
@ SNAPTARGET_DISTRIBUTION_UP
@ SNAPTARGET_ELLIPSE_QUADRANT_POINT
@ SNAPTARGET_DISTRIBUTION_CATEGORY
@ SNAPTARGET_PAGE_EDGE_CORNER
@ SNAPTARGET_ALIGNMENT_BBOX_EDGE_MIDPOINT
@ SNAPTARGET_ALIGNMENT_PAGE_MARGIN_CENTER
@ SNAPTARGET_PAGE_EDGE_BORDER
@ SNAPTARGET_DISTRIBUTION_X
@ SNAPTARGET_GRID_GUIDE_INTERSECTION
@ SNAPTARGET_ALIGNMENT_HANDLE
@ SNAPTARGET_TEXT_BASELINE
@ SNAPTARGET_GRID_PERPENDICULAR
@ SNAPTARGET_GUIDE_INTERSECTION
@ SNAPTARGET_ALIGNMENT_PAGE_EDGE_CORNER
@ SNAPTARGET_ALIGNMENT_BBOX_CORNER
@ SNAPTARGET_PAGE_MARGIN_CORNER
@ SNAPTARGET_OBJECT_MIDPOINT
@ SNAPTARGET_DISTRIBUTION_Y
@ SNAPTARGET_PATH_TANGENTIAL
@ SNAPTARGET_PATH_PERPENDICULAR
@ SNAPTARGET_PATH_INTERSECTION
@ SNAPTARGET_PAGE_BLEED_BORDER
@ SNAPTARGET_DISTRIBUTION_RIGHT
@ SNAPTARGET_CONSTRAINED_ANGLE
@ CANVAS_ITEM_CTRL_TYPE_POINT
@ CANVAS_ITEM_CTRL_TYPE_MARKER
@ CANVAS_ITEM_CTRL_TYPE_SHAPER
Singleton class to access the preferences file in a convenient way.
static double sign(double const x)
Returns -1 or 1 according to the sign of x.
Provides a class that shows a temporary indicator on the canvas of where the snap was,...