Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
GrDrag Class Reference

This is the root class of the gradient dragging machinery. More...

#include <gradient-drag.h>

Classes

struct  ItemCurve
 

Public Member Functions

 GrDrag (SPDesktop *desktop)
 
virtual ~GrDrag ()
 
bool isNonEmpty ()
 
bool hasSelection ()
 
guint numSelected ()
 
guint numDraggers ()
 
guint singleSelectedDraggerNumDraggables ()
 
guint singleSelectedDraggerSingleDraggableType ()
 
void setSelected (GrDragger *dragger, bool add_to_selection=false, bool override=true)
 Select a dragger.
 
void setDeselected (GrDragger *dragger)
 Deselect a dragger.
 
void deselectAll ()
 Deselect all stops/draggers (public; emits signal).
 
void selectAll ()
 Select all stops/draggers.
 
void selectByCoords (std::vector< Geom::Point > coords)
 Select all stops/draggers that match the coords.
 
void selectByStop (SPStop *stop, bool add_to_selection=true, bool override=true)
 Select draggers by stop.
 
void selectRect (Geom::Rect const &r)
 Select all stops/draggers that fall within the rect.
 
void addColorToDragger (GrDragger &dragger, const char *color)
 
void dropColorOnCorrespondingRegion (const char *color, Geom::Point p)
 
bool dropColor (SPItem *item, gchar const *c, Geom::Point p)
 
SPStopaddStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance)
 
void deleteSelected (bool just_one=false)
 
Inkscape::Colors::Color getColor ()
 
GrDraggergetDraggerFor (GrDraggable *d)
 Select the dragger which has the given draggable.
 
GrDraggergetDraggerFor (SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke)
 Select the dragger which has the given draggable.
 
void grabKnot (GrDragger *dragger, gint x, gint y, guint32 etime)
 Artificially grab the knot of this dragger; used by the gradient context.
 
void grabKnot (SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke, gint x, gint y, guint32 etime)
 Artificially grab the knot of the dragger with this draggable; used by the gradient context.
 
void updateDraggers ()
 Regenerates the draggers list from the current selection; is called when selection is changed or modified, also when a radial dragger needs to update positions of other draggers in the gradient.
 
void refreshDraggers ()
 Refresh draggers, moving and toggling visibility as necessary.
 
void updateLines ()
 Regenerates the lines list from the current selection; is called on each move of a dragger, so that lines are always in sync with the actual gradient.
 
void updateLevels ()
 Regenerates the levels list from the current selection.
 
bool mouseOver ()
 Returns true if at least one of the draggers' knots has the mouse hovering above it.
 
void selected_move_nowrite (double x, double y, bool scale_radial)
 
void selected_move (double x, double y, bool write_repr=true, bool scale_radial=false)
 
void selected_move_screen (double x, double y)
 
bool key_press_handler (Inkscape::KeyPressEvent const &event)
 Handle arrow key events.
 
GrDraggerselect_next ()
 Select the knot next to the last selected one and deselect all other selected.
 
GrDraggerselect_prev ()
 Select the knot previous from the last selected one and deselect all other selected.
 
void selected_reverse_vector ()
 

Public Attributes

std::set< GrDragger * > selected
 
bool keep_selection
 
bool local_change
 
SPDesktopdesktop
 
std::vector< double > hor_levels
 
std::vector< double > vert_levels
 
std::vector< GrDragger * > draggers
 
std::vector< ItemCurveitem_curves
 

Private Member Functions

void deselect_all ()
 Deselect all stops/draggers (private).
 
void addLine (SPItem *item, Geom::Point p1, Geom::Point p2, Inkscape::PaintTarget fill_or_stroke)
 Create a line from p1 to p2 and add it to the curves list.
 
void addCurve (SPItem *item, Geom::Point p0, Geom::Point p1, Geom::Point p2, Geom::Point p3, int corner0, int corner1, int handle0, int handle1, Inkscape::PaintTarget fill_or_stroke)
 Create a curve from p0 to p3 and add it to the curves list.
 
GrDraggeraddDragger (GrDraggable *draggable)
 If there already exists a dragger within MERGE_DIST of p, add the draggable to it; otherwise create new dragger and add it to draggers list.
 
void addDraggersRadial (SPRadialGradient *rg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
 Add draggers for the radial gradient rg on item.
 
void addDraggersLinear (SPLinearGradient *lg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
 Add draggers for the linear gradient lg on item.
 
void addDraggersMesh (SPMeshGradient *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
 Add draggers for the mesh gradient mg on item.
 
void refreshDraggersMesh (SPMeshGradient *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke)
 Refresh draggers, moving and toggling visibility as necessary.
 
bool styleSet (const SPCSSAttr *css, bool switch_style)
 
Glib::ustring makeStopSafeColor (gchar const *str, bool &isNull)
 

Private Attributes

Inkscape::Selectionselection
 
sigc::connection sel_changed_connection
 
sigc::connection sel_modified_connection
 
sigc::connection style_set_connection
 
sigc::connection style_query_connection
 

Detailed Description

This is the root class of the gradient dragging machinery.

It holds lists of GrDraggers and of lines (simple canvas items). It also remembers one of the draggers as selected.

Definition at line 148 of file gradient-drag.h.

Constructor & Destructor Documentation

◆ GrDrag()

◆ ~GrDrag()

Member Function Documentation

◆ addColorToDragger()

void GrDrag::addColorToDragger ( GrDragger dragger,
const char *  color 
)

◆ addCurve()

void GrDrag::addCurve ( SPItem item,
Geom::Point  p0,
Geom::Point  p1,
Geom::Point  p2,
Geom::Point  p3,
int  corner0,
int  corner1,
int  handle0,
int  handle1,
Inkscape::PaintTarget  fill_or_stroke 
)
private

◆ addDragger()

GrDragger * GrDrag::addDragger ( GrDraggable draggable)
private

If there already exists a dragger within MERGE_DIST of p, add the draggable to it; otherwise create new dragger and add it to draggers list.

Definition at line 2137 of file gradient-drag.cpp.

References draggers, GrDraggable::fill_or_stroke, getGradientCoords(), GrDraggable::item, Geom::L2(), GrDraggable::point_i, and GrDraggable::point_type.

Referenced by addDraggersLinear(), addDraggersMesh(), and addDraggersRadial().

◆ addDraggersLinear()

void GrDrag::addDraggersLinear ( SPLinearGradient lg,
SPItem item,
Inkscape::PaintTarget  fill_or_stroke 
)
private

Add draggers for the linear gradient lg on item.

Definition at line 2182 of file gradient-drag.cpp.

References addDragger(), SPGradient::ensureVector(), item, num, POINT_LG_BEGIN, POINT_LG_END, POINT_LG_MID, SPGradientVector::stops, and SPGradient::vector.

Referenced by updateDraggers().

◆ addDraggersMesh()

◆ addDraggersRadial()

void GrDrag::addDraggersRadial ( SPRadialGradient rg,
SPItem item,
Inkscape::PaintTarget  fill_or_stroke 
)
private

Add draggers for the radial gradient rg on item.

Definition at line 2159 of file gradient-drag.cpp.

References addDragger(), SPGradient::ensureVector(), item, num, POINT_RG_CENTER, POINT_RG_FOCUS, POINT_RG_MID1, POINT_RG_MID2, POINT_RG_R1, POINT_RG_R2, SPGradientVector::stops, and SPGradient::vector.

Referenced by updateDraggers().

◆ addLine()

void GrDrag::addLine ( SPItem item,
Geom::Point  p1,
Geom::Point  p2,
Inkscape::PaintTarget  fill_or_stroke 
)
private

Create a line from p1 to p2 and add it to the curves list.

Used for linear and radial gradients.

Definition at line 2083 of file gradient-drag.cpp.

References Inkscape::CANVAS_ITEM_PRIMARY, Inkscape::CANVAS_ITEM_SECONDARY, desktop, Inkscape::FOR_FILL, SPDesktop::getCanvasControls(), item, and item_curves.

Referenced by updateLines().

◆ addStopNearPoint()

◆ deleteSelected()

◆ deselect_all()

void GrDrag::deselect_all ( )
private

Deselect all stops/draggers (private).

Definition at line 1949 of file gradient-drag.cpp.

References selected.

Referenced by deselectAll(), setSelected(), and ~GrDrag().

◆ deselectAll()

void GrDrag::deselectAll ( )

Deselect all stops/draggers (public; emits signal).

Definition at line 1959 of file gradient-drag.cpp.

References deselect_all(), desktop, and SPDesktop::emit_gradient_stop_selected().

Referenced by Inkscape::UI::Tools::MeshTool::root_handler().

◆ dropColor()

◆ dropColorOnCorrespondingRegion()

void GrDrag::dropColorOnCorrespondingRegion ( const char *  color,
Geom::Point  p 
)

Definition at line 557 of file gradient-drag.cpp.

References addColorToDragger(), Geom::distance(), and draggers.

Referenced by dropColor().

◆ getColor()

◆ getDraggerFor() [1/2]

◆ getDraggerFor() [2/2]

GrDragger * GrDrag::getDraggerFor ( SPItem item,
GrPointType  point_type,
gint  point_i,
Inkscape::PaintTarget  fill_or_stroke 
)

Select the dragger which has the given draggable.

Definition at line 1755 of file gradient-drag.cpp.

References draggers, GrDraggable::fill_or_stroke, item, GrDraggable::item, GrDraggable::point_i, and GrDraggable::point_type.

◆ grabKnot() [1/2]

void GrDrag::grabKnot ( GrDragger dragger,
gint  x,
gint  y,
guint32  etime 
)

Artificially grab the knot of this dragger; used by the gradient context.

Not used at the moment.

Definition at line 2357 of file gradient-drag.cpp.

References GrDragger::knot, GrDragger::point, and SPKnot::startDragging().

◆ grabKnot() [2/2]

void GrDrag::grabKnot ( SPItem item,
GrPointType  point_type,
gint  point_i,
Inkscape::PaintTarget  fill_or_stroke,
gint  x,
gint  y,
guint32  etime 
)

Artificially grab the knot of the dragger with this draggable; used by the gradient context.

This allows setting the final point from the end of the drag when creating a new gradient.

Definition at line 2368 of file gradient-drag.cpp.

References getDraggerFor(), item, GrDragger::knot, GrDragger::point, and SPKnot::startDragging().

◆ hasSelection()

bool GrDrag::hasSelection ( )
inline

◆ isNonEmpty()

bool GrDrag::isNonEmpty ( )
inline

◆ key_press_handler()

bool GrDrag::key_press_handler ( Inkscape::KeyPressEvent const &  event)

Handle arrow key events.

Parameters
eventEvent with type GDK_KEY_PRESS
Returns
True if the event was handled, false otherwise

Definition at line 2809 of file gradient-drag.cpp.

References desktop, Inkscape::Preferences::get(), Inkscape::UI::Tools::get_latin_keyval(), Inkscape::UI::Tools::gobble_key_events(), selected_move(), selected_move_screen(), and SPDesktop::yaxisdir().

◆ makeStopSafeColor()

Glib::ustring GrDrag::makeStopSafeColor ( gchar const *  str,
bool &  isNull 
)
private

◆ mouseOver()

bool GrDrag::mouseOver ( )

Returns true if at least one of the draggers' knots has the mouse hovering above it.

Definition at line 2466 of file gradient-drag.cpp.

References draggers, SP_KNOT_MOUSEOVER, and updateLines().

◆ numDraggers()

guint GrDrag::numDraggers ( )
inline

◆ numSelected()

◆ refreshDraggers()

void GrDrag::refreshDraggers ( )

Refresh draggers, moving and toggling visibility as necessary.

Does not regenerate draggers (as does updateDraggers()). Only applies to mesh gradients.

Definition at line 2433 of file gradient-drag.cpp.

References SPStyle::fill, Inkscape::FOR_FILL, Inkscape::FOR_STROKE, SPStyle::getFillPaintServer(), SPStyle::getStrokePaintServer(), item, Inkscape::ObjectSet::items(), refreshDraggersMesh(), selection, SPStyle::stroke, and SPObject::style.

Referenced by gr_drag_sel_modified().

◆ refreshDraggersMesh()

void GrDrag::refreshDraggersMesh ( SPMeshGradient mg,
SPItem item,
Inkscape::PaintTarget  fill_or_stroke 
)
private

◆ select_next()

GrDragger * GrDrag::select_next ( )

Select the knot next to the last selected one and deselect all other selected.

Definition at line 2872 of file gradient-drag.cpp.

References draggers, selected, and setSelected().

Referenced by Inkscape::UI::Tools::GradientTool::select_next(), and Inkscape::UI::Tools::MeshTool::select_next().

◆ select_prev()

GrDragger * GrDrag::select_prev ( )

Select the knot previous from the last selected one and deselect all other selected.

Definition at line 2889 of file gradient-drag.cpp.

References draggers, selected, and setSelected().

Referenced by Inkscape::UI::Tools::GradientTool::select_prev(), and Inkscape::UI::Tools::MeshTool::select_prev().

◆ selectAll()

void GrDrag::selectAll ( )

Select all stops/draggers.

Definition at line 1968 of file gradient-drag.cpp.

References draggers, and setSelected().

◆ selectByCoords()

void GrDrag::selectByCoords ( std::vector< Geom::Point coords)

Select all stops/draggers that match the coords.

Definition at line 1978 of file gradient-drag.cpp.

References draggers, Geom::L2(), and setSelected().

◆ selectByStop()

◆ selected_move()

◆ selected_move_nowrite()

void GrDrag::selected_move_nowrite ( double  x,
double  y,
bool  scale_radial 
)

Definition at line 2701 of file gradient-drag.cpp.

References selected_move().

Referenced by gr_knot_moved_handler().

◆ selected_move_screen()

void GrDrag::selected_move_screen ( double  x,
double  y 
)

Definition at line 2795 of file gradient-drag.cpp.

References SPDesktop::current_zoom(), desktop, and selected_move().

Referenced by key_press_handler().

◆ selected_reverse_vector()

void GrDrag::selected_reverse_vector ( )

◆ selectRect()

void GrDrag::selectRect ( Geom::Rect const &  r)

Select all stops/draggers that fall within the rect.

Definition at line 2012 of file gradient-drag.cpp.

References Geom::GenericRect< C >::contains(), draggers, and setSelected().

◆ setDeselected()

void GrDrag::setDeselected ( GrDragger dragger)

Deselect a dragger.

Parameters
draggerThe dragger to deselect.

Definition at line 2071 of file gradient-drag.cpp.

References GrDragger::deselect(), desktop, SPDesktop::emit_gradient_stop_selected(), and selected.

◆ setSelected()

void GrDrag::setSelected ( GrDragger dragger,
bool  add_to_selection = false,
bool  override = true 
)

Select a dragger.

Parameters
draggerThe dragger to select.
add_to_selectionIf true, add to selection, otherwise deselect others.
overrideIf true, always select this node, otherwise toggle selected status.

Definition at line 2027 of file gradient-drag.cpp.

References GrDragger::deselect(), deselect_all(), desktop, SPDesktop::emit_gradient_stop_selected(), GrDragger::isA(), POINT_MG_HANDLE, POINT_MG_TENSOR, GrDragger::select(), and selected.

Referenced by gr_knot_clicked_handler(), gr_knot_moved_handler(), gr_knot_ungrabbed_handler(), GrDrag(), Inkscape::UI::Tools::MeshTool::root_handler(), select_next(), select_prev(), selectAll(), selectByCoords(), selectByStop(), and selectRect().

◆ singleSelectedDraggerNumDraggables()

guint GrDrag::singleSelectedDraggerNumDraggables ( )
inline

◆ singleSelectedDraggerSingleDraggableType()

guint GrDrag::singleSelectedDraggerSingleDraggableType ( )
inline

◆ styleSet()

◆ updateDraggers()

◆ updateLevels()

void GrDrag::updateLevels ( )

Regenerates the levels list from the current selection.

Levels correspond to bounding box edges and midpoints.

Definition at line 2668 of file gradient-drag.cpp.

References SPItem::desktopVisualBounds(), hor_levels, item, Inkscape::ObjectSet::items(), selection, vert_levels, Geom::X, and Geom::Y.

Referenced by gr_drag_sel_changed(), gr_drag_sel_modified(), and GrDrag().

◆ updateLines()

Member Data Documentation

◆ desktop

◆ draggers

◆ hor_levels

std::vector<double> GrDrag::hor_levels

Definition at line 200 of file gradient-drag.h.

Referenced by updateLevels().

◆ item_curves

◆ keep_selection

bool GrDrag::keep_selection

◆ local_change

◆ sel_changed_connection

sigc::connection GrDrag::sel_changed_connection
private

Definition at line 252 of file gradient-drag.h.

Referenced by GrDrag(), and ~GrDrag().

◆ sel_modified_connection

sigc::connection GrDrag::sel_modified_connection
private

Definition at line 253 of file gradient-drag.h.

Referenced by GrDrag(), and ~GrDrag().

◆ selected

◆ selection

Inkscape::Selection* GrDrag::selection
private

Definition at line 251 of file gradient-drag.h.

Referenced by GrDrag(), refreshDraggers(), updateDraggers(), updateLevels(), and updateLines().

◆ style_query_connection

sigc::connection GrDrag::style_query_connection
private

Definition at line 256 of file gradient-drag.h.

Referenced by GrDrag(), and ~GrDrag().

◆ style_set_connection

sigc::connection GrDrag::style_set_connection
private

Definition at line 255 of file gradient-drag.h.

Referenced by GrDrag(), and ~GrDrag().

◆ vert_levels

std::vector<double> GrDrag::vert_levels

Definition at line 201 of file gradient-drag.h.

Referenced by updateLevels().


The documentation for this class was generated from the following files: