snap-indicator.cpp revision abac96a58638236025e60f4dca3848bb294c6672
1N/A/** \file
1N/A * Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap
1N/A *
1N/A * Authors:
1N/A * Johan Engelen
1N/A * Diederik van Lierop
1N/A *
1N/A * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
1N/A * Copyright (C) Diederik van Lierop 2008 <mail@diedenrezi.nl>
1N/A *
1N/A * Released under GNU GPL, read the file 'COPYING' for more information
1N/A */
1N/A
1N/A#include "display/snap-indicator.h"
1N/A
1N/A#include "desktop.h"
1N/A#include "desktop-handles.h"
1N/A#include "display/sodipodi-ctrl.h"
1N/A#include "knot.h"
1N/A#include "preferences.h"
1N/A
1N/Anamespace Inkscape {
1N/Anamespace Display {
1N/A
1N/ASnapIndicator::SnapIndicator(SPDesktop * desktop)
1N/A : _snaptarget(NULL),
1N/A _snapsource(NULL),
1N/A _desktop(desktop)
1N/A{
1N/A}
1N/A
1N/ASnapIndicator::~SnapIndicator()
1N/A{
1N/A // remove item that might be present
1N/A remove_snaptarget();
1N/A remove_snapsource();
1N/A}
1N/A
1N/Avoid
1N/ASnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const p)
1N/A{
1N/A remove_snaptarget();
1N/A
1N/A g_assert(_desktop != NULL);
1N/A
1N/A /* Commented out for now, because this might hide any snapping bug!
1N/A if (!p.getSnapped()) {
1N/A return; // If we haven't snapped, then it is of no use to draw a snapindicator
1N/A }
1N/A */
1N/A
1N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1N/A bool value = prefs->getBool("/options/snapindicator/value", true);
1N/A
1N/A if (value) {
1N/A SPCanvasItem * canvasitem = NULL;
1N/A switch (p.getTarget()) {
1N/A /// @todo add the different kinds of snapindicator visuals
1N/A case SNAPTARGET_GRID:
1N/A case SNAPTARGET_GRID_INTERSECTION:
1N/A case SNAPTARGET_GUIDE:
1N/A case SNAPTARGET_GUIDE_INTERSECTION:
1N/A case SNAPTARGET_GRID_GUIDE_INTERSECTION:
1N/A case SNAPTARGET_NODE:
1N/A case SNAPTARGET_PATH:
1N/A case SNAPTARGET_PATH_INTERSECTION:
1N/A case SNAPTARGET_BBOX_CORNER:
1N/A case SNAPTARGET_BBOX_EDGE:
1N/A case SNAPTARGET_GRADIENT:
1N/A case SNAPTARGET_UNDEFINED:
1N/A default:
1N/A canvasitem = sp_canvas_item_new(sp_desktop_tempgroup (_desktop),
1N/A SP_TYPE_CTRL,
1N/A "anchor", GTK_ANCHOR_CENTER,
1N/A "size", 10.0,
1N/A "stroked", TRUE,
1N/A "stroke_color", 0xf000f0ff,
1N/A "mode", SP_KNOT_MODE_XOR,
1N/A "shape", SP_KNOT_SHAPE_CROSS,
1N/A NULL );
1N/A break;
1N/A }
1N/A
1N/A SP_CTRL(canvasitem)->moveto(p.getPoint());
1N/A remove_snapsource(); // Don't set both the source and target indicators, as these will overlap
1N/A _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
1N/A }
1N/A}
1N/A
1N/Avoid
1N/ASnapIndicator::remove_snaptarget()
1N/A{
1N/A if (_snaptarget) {
1N/A _desktop->remove_temporary_canvasitem(_snaptarget);
1N/A _snaptarget = NULL;
1N/A }
1N/A}
1N/A
1N/Avoid
1N/ASnapIndicator::set_new_snapsource(Geom::Point const p)
1N/A{
1N/A remove_snapsource();
1N/A
1N/A g_assert(_desktop != NULL);
1N/A
1N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1N/A bool value = prefs->getBool("/options/snapindicator/value", true);
1N/A
1N/A if (value) {
1N/A SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
1N/A SP_TYPE_CTRL,
1N/A "anchor", GTK_ANCHOR_CENTER,
1N/A "size", 10.0,
1N/A "stroked", TRUE,
1N/A "stroke_color", 0xf000f0ff,
1N/A "mode", SP_KNOT_MODE_XOR,
1N/A "shape", SP_KNOT_SHAPE_DIAMOND,
1N/A NULL );
1N/A
1N/A SP_CTRL(canvasitem)->moveto(p);
1N/A _snapsource = _desktop->add_temporary_canvasitem(canvasitem, 1000);
1N/A }
1N/A}
1N/A
1N/Avoid
1N/ASnapIndicator::remove_snapsource()
1N/A{
1N/A if (_snapsource) {
1N/A _desktop->remove_temporary_canvasitem(_snapsource);
1N/A _snapsource = NULL;
1N/A }
1N/A}
1N/A
1N/A
1N/A
1N/A} //namespace Display
1N/A} /* namespace Inkscape */
1N/A
1N/A/*
1N/A Local Variables:
1N/A mode:c++
1N/A c-file-style:"stroustrup"
1N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1N/A indent-tabs-mode:nil
1N/A fill-column:99
1N/A End:
1N/A*/
1N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
1N/A