snap-indicator.cpp revision b11092ec287481df46a15a0d734b6184ac25e540
/*
* Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap
*
* Authors:
* Johan Engelen
* Diederik van Lierop
*
* Copyright (C) Johan Engelen 2009 <j.b.c.engelen@utwente.nl>
* Copyright (C) Diederik van Lierop 2010 - 2012 <mail@diedenrezi.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "display/snap-indicator.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "display/sodipodi-ctrl.h"
#include "display/sodipodi-ctrlrect.h"
#include "display/canvas-text.h"
#include "display/sp-canvas-util.h"
#include "knot.h"
#include "preferences.h"
#include "tools-switch.h"
#include "enums.h"
namespace Inkscape {
namespace Display {
: _snaptarget(NULL),
_snaptarget_is_presnap(false),
{
}
{
// remove item that might be present
}
void
{
remove_snaptarget(); //only display one snaptarget at a time
if (!p.getSnapped()) {
return; // If we haven't snapped, then it is of no use to draw a snapindicator
}
if (p.getTarget() == SNAPTARGET_CONSTRAINT) {
// This is not a real snap, although moving along the constraint did affect the mouse pointer's position.
// Maybe we should only show a snap indicator when the user explicitly asked for a constraint by pressing ctrl?
// We should not show a snap indicator when stretching a selection box, which is also constrained. That would be
// too much information.
return;
}
if (value) {
// TRANSLATORS: undefined target for snapping
switch (p.getTarget()) {
case SNAPTARGET_UNDEFINED:
target_name = _("UNDEFINED");
break;
case SNAPTARGET_GRID:
target_name = _("grid line");
break;
target_name = _("grid intersection");
break;
target_name = _("grid line (perpendicular)");
break;
case SNAPTARGET_GUIDE:
target_name = _("guide");
break;
target_name = _("guide intersection");
break;
case SNAPTARGET_GUIDE_ORIGIN:
target_name = _("guide origin");
break;
target_name = _("guide (perpendicular)");
break;
target_name = _("grid-guide intersection");
break;
case SNAPTARGET_NODE_CUSP:
target_name = _("cusp node");
break;
case SNAPTARGET_NODE_SMOOTH:
target_name = _("smooth node");
break;
case SNAPTARGET_PATH:
target_name = _("path");
break;
target_name = _("path (perpendicular)");
break;
target_name = _("path (tangential)");
break;
target_name = _("path intersection");
break;
target_name = _("guide-path intersection");
break;
case SNAPTARGET_PATH_CLIP:
target_name = _("clip-path");
break;
case SNAPTARGET_PATH_MASK:
target_name = _("mask-path");
break;
case SNAPTARGET_BBOX_CORNER:
target_name = _("bounding box corner");
break;
case SNAPTARGET_BBOX_EDGE:
target_name = _("bounding box side");
break;
case SNAPTARGET_PAGE_BORDER:
target_name = _("page border");
break;
case SNAPTARGET_LINE_MIDPOINT:
target_name = _("line midpoint");
break;
target_name = _("object midpoint");
break;
target_name = _("object rotation center");
break;
target_name = _("bounding box side midpoint");
break;
case SNAPTARGET_BBOX_MIDPOINT:
target_name = _("bounding box midpoint");
break;
case SNAPTARGET_PAGE_CORNER:
target_name = _("page corner");
break;
target_name = _("quadrant point");
break;
case SNAPTARGET_RECT_CORNER:
case SNAPTARGET_IMG_CORNER:
target_name = _("corner");
break;
case SNAPTARGET_TEXT_ANCHOR:
target_name = _("text anchor");
break;
case SNAPTARGET_TEXT_BASELINE:
target_name = _("text baseline");
break;
target_name = _("constrained angle");
break;
case SNAPTARGET_CONSTRAINT:
target_name = _("constraint");
break;
default:
g_warning("Snap target has not yet been defined!");
break;
}
switch (p.getSource()) {
case SNAPSOURCE_UNDEFINED:
source_name = _("UNDEFINED");
break;
case SNAPSOURCE_BBOX_CORNER:
source_name = _("Bounding box corner");
break;
case SNAPSOURCE_BBOX_MIDPOINT:
source_name = _("Bounding box midpoint");
break;
source_name = _("Bounding box side midpoint");
break;
case SNAPSOURCE_NODE_SMOOTH:
source_name = _("Smooth node");
break;
case SNAPSOURCE_NODE_CUSP:
source_name = _("Cusp node");
break;
case SNAPSOURCE_LINE_MIDPOINT:
source_name = _("Line midpoint");
break;
source_name = _("Object midpoint");
break;
source_name = _("Object rotation center");
break;
case SNAPSOURCE_NODE_HANDLE:
case SNAPSOURCE_OTHER_HANDLE:
source_name = _("Handle");
break;
source_name = _("Path intersection");
break;
case SNAPSOURCE_GUIDE:
source_name = _("Guide");
break;
case SNAPSOURCE_GUIDE_ORIGIN:
source_name = _("Guide origin");
break;
source_name = _("Convex hull corner");
break;
source_name = _("Quadrant point");
break;
case SNAPSOURCE_RECT_CORNER:
case SNAPSOURCE_IMG_CORNER:
source_name = _("Corner");
break;
case SNAPSOURCE_TEXT_ANCHOR:
source_name = _("Text anchor");
break;
case SNAPSOURCE_GRID_PITCH:
source_name = _("Multiple of grid spacing");
break;
default:
g_warning("Snap source has not yet been defined!");
break;
}
//std::cout << "Snapped " << source_name << " to " << target_name << std::endl;
remove_snapsource(); // Don't set both the source and target indicators, as these will overlap
// Display the snap indicator (i.e. the cross)
"anchor", SP_ANCHOR_CENTER,
"size", 10.0,
"stroked", TRUE,
"mode", SP_KNOT_MODE_XOR,
"shape", SP_KNOT_SHAPE_CROSS,
NULL );
// Display the tooltip, which reveals the type of snap source and the type of snap target
} else if (p.getSource() != SNAPSOURCE_UNDEFINED) {
}
if (tooltip_str) {
// Make sure that the snap tooltips do not overlap the ones from the measure tool
} else {
}
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(_desktop), _desktop, tooltip_pos, tooltip_str);
if (pre_snap) {
} else {
}
}
// Display the bounding box, if we snapped to one
if (bbox) {
NULL);
}
}
}
void
{
if (only_if_presnap && !_snaptarget_is_presnap) {
return;
}
if (_snaptarget) {
_snaptarget = NULL;
_snaptarget_is_presnap = false;
}
if (_snaptarget_tooltip) {
}
if (_snaptarget_bbox) {
}
}
void
{
g_assert(_desktop != NULL); // If this fails, then likely setup() has not been called on the snap manager (see snap.cpp -> setup())
if (value) {
"anchor", SP_ANCHOR_CENTER,
"size", 6.0,
"stroked", TRUE,
"stroke_color", 0xff0000ff,
"mode", SP_KNOT_MODE_XOR,
"shape", SP_KNOT_SHAPE_CIRCLE,
NULL );
}
}
void
{
"anchor", SP_ANCHOR_CENTER,
"size", 10.0,
"fill_color", 0x00ff00ff,
"stroked", FALSE,
"mode", SP_KNOT_MODE_XOR,
"shape", SP_KNOT_SHAPE_DIAMOND,
NULL );
}
void
{
if (_snapsource) {
_snapsource = NULL;
}
}
void
{
for (std::list<TemporaryItem *>::const_iterator i = _debugging_points.begin(); i != _debugging_points.end(); ++i) {
}
}
} //namespace Display
} /* namespace Inkscape */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 :