diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2012-05-17 02:33:16 +0000 |
|---|---|---|
| committer | Jon A. Cruz <jon@joncruz.org> | 2012-05-17 02:33:16 +0000 |
| commit | e9412c187da3f62f01bc5acb6190af2d5a395ccb (patch) | |
| tree | 4d6d98646a87c82dc1cc631d88875ca0d63c3fcf /src/ui/tool/transform-handle-set.cpp | |
| parent | Fixed warning with printf format. Also corrected inproper type that resulted ... (diff) | |
| download | inkscape-e9412c187da3f62f01bc5acb6190af2d5a395ccb.tar.gz inkscape-e9412c187da3f62f01bc5acb6190af2d5a395ccb.zip | |
Corrected protected type access (comments were incorrect).
Unified color set types; fixed uninitialized member; Switched colorsets to references; Added const correctness.
(bzr r11373)
Diffstat (limited to 'src/ui/tool/transform-handle-set.cpp')
| -rw-r--r-- | src/ui/tool/transform-handle-set.cpp | 121 |
1 files changed, 79 insertions, 42 deletions
diff --git a/src/ui/tool/transform-handle-set.cpp b/src/ui/tool/transform-handle-set.cpp index b4a27170a..0e94cb25e 100644 --- a/src/ui/tool/transform-handle-set.cpp +++ b/src/ui/tool/transform-handle-set.cpp @@ -3,6 +3,7 @@ */ /* Authors: * Krzysztof Kosiński <tweenk.pl@gmail.com> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2009 Authors * Released under GNU GPL, read the file 'COPYING' for more information @@ -38,6 +39,7 @@ namespace Inkscape { namespace UI { namespace { + SPAnchorType corner_to_anchor(unsigned c) { switch (c % 4) { case 0: return SP_ANCHOR_NE; @@ -46,6 +48,7 @@ SPAnchorType corner_to_anchor(unsigned c) { default: return SP_ANCHOR_SE; } } + SPAnchorType side_to_anchor(unsigned s) { switch (s % 4) { case 0: return SP_ANCHOR_N; @@ -62,30 +65,30 @@ double snap_angle(double a) { double unit_angle = M_PI / snaps; return CLAMP(unit_angle * round(a / unit_angle), -M_PI, M_PI); } + double snap_increment_degrees() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int snaps = prefs->getIntLimited("/options/rotationsnapsperpi/value", 12, 1, 1000); return 180.0 / snaps; } -ControlPoint::ColorSet thandle_cset = { +} // anonymous namespace + +ControlPoint::ColorSet TransformHandle::thandle_cset = { + {0x000000ff, 0x000000ff}, + {0x00ff6600, 0x000000ff}, + {0x00ff6600, 0x000000ff}, + // {0x000000ff, 0x000000ff}, {0x00ff6600, 0x000000ff}, {0x00ff6600, 0x000000ff} }; -ControlPoint::ColorSet center_cset = { - {0x00000000, 0x000000ff}, - {0x00000000, 0xff0000b0}, - {0x00000000, 0xff0000b0} -}; -} // anonymous namespace - -/** Base class for node transform handles to simplify implementation */ -TransformHandle::TransformHandle(TransformHandleSet &th, SPAnchorType anchor, Glib::RefPtr<Gdk::Pixbuf> pb) - : ControlPoint(th._desktop, Geom::Point(), anchor, pb, &thandle_cset, - th._transform_handle_group) - , _th(th) +TransformHandle::TransformHandle(TransformHandleSet &th, SPAnchorType anchor, Glib::RefPtr<Gdk::Pixbuf> pb) : + ControlPoint(th._desktop, Geom::Point(), anchor, + pb, + thandle_cset, th._transform_handle_group), + _th(th) { setVisible(false); } @@ -121,7 +124,8 @@ bool TransformHandle::grabbed(GdkEventMotion *) startTransform(); _th._setActiveHandle(this); - _cset = &invisible_cset; + _setLurking(true); + g_message("Lurk ON for %p", this); _setState(_state); // Collect the snap-candidates, one for each selected node. These will be stored in the _snap_points vector. @@ -171,7 +175,8 @@ void TransformHandle::ungrabbed(GdkEventButton *) { _snap_points.clear(); _th._clearActiveHandle(); - _cset = &thandle_cset; + _setLurking(false); + g_message("Lurk off for %p", this); _setState(_state); endTransform(); _th.signal_commit.emit(getCommitEvent()); @@ -184,7 +189,7 @@ public: : TransformHandle(th, anchor, pb) {} protected: - virtual Glib::ustring _getTip(unsigned state) { + virtual Glib::ustring _getTip(unsigned state) const { if (state_held_control(state)) { if (state_held_shift(state)) { return C_("Transform handle tip", @@ -205,31 +210,36 @@ protected: return C_("Transform handle tip", "<b>Scale handle</b>: drag to scale the selection"); } - virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) { + virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) const { return format_tip(C_("Transform handle tip", "Scale by %.2f%% x %.2f%%"), _last_scale_x * 100, _last_scale_y * 100); } - virtual bool _hasDragTips() { return true; } + virtual bool _hasDragTips() const { return true; } static double _last_scale_x, _last_scale_y; }; double ScaleHandle::_last_scale_x = 1.0; double ScaleHandle::_last_scale_y = 1.0; -/// Corner scaling handle for node transforms +/** + * Corner scaling handle for node transforms. + */ class ScaleCornerHandle : public ScaleHandle { public: - ScaleCornerHandle(TransformHandleSet &th, unsigned corner) - : ScaleHandle(th, corner_to_anchor(corner), _corner_to_pixbuf(corner)) - , _corner(corner) + + ScaleCornerHandle(TransformHandleSet &th, unsigned corner) : + ScaleHandle(th, corner_to_anchor(corner), _corner_to_pixbuf(corner)), + _corner(corner) {} + protected: virtual void startTransform() { _sc_center = _th.rotationCenter(); _sc_opposite = _th.bounds().corner(_corner + 2); _last_scale_x = _last_scale_y = 1.0; } + virtual Geom::Affine computeTransform(Geom::Point const &new_pos, GdkEventMotion *event) { Geom::Point scc = held_shift(*event) ? _sc_center : _sc_opposite; Geom::Point vold = _origin - scc, vnew = new_pos - scc; @@ -275,25 +285,35 @@ protected: * Geom::Translate(scc); return t; } + virtual CommitEvent getCommitEvent() { return _last_transform.isUniformScale() ? COMMIT_MOUSE_SCALE_UNIFORM : COMMIT_MOUSE_SCALE; } + private: + static Glib::RefPtr<Gdk::Pixbuf> _corner_to_pixbuf(unsigned c) { sp_select_context_get_type(); switch (c % 2) { - case 0: return Glib::wrap(handles[1], true); - default: return Glib::wrap(handles[0], true); + case 0: + return Glib::wrap(handles[1], true); + break; + default: + return Glib::wrap(handles[0], true); + break; } } + Geom::Point _sc_center; Geom::Point _sc_opposite; unsigned _corner; }; -/// Side scaling handle for node transforms +/** + * Side scaling handle for node transforms. + */ class ScaleSideHandle : public ScaleHandle { public: ScaleSideHandle(TransformHandleSet &th, unsigned side) @@ -369,7 +389,9 @@ private: unsigned _side; }; -/// Rotation handle for node transforms +/** + * Rotation handle for node transforms. + */ class RotateHandle : public TransformHandle { public: RotateHandle(TransformHandleSet &th, unsigned corner) @@ -410,7 +432,7 @@ protected: virtual CommitEvent getCommitEvent() { return COMMIT_MOUSE_ROTATE; } - virtual Glib::ustring _getTip(unsigned state) { + virtual Glib::ustring _getTip(unsigned state) const { if (state_held_shift(state)) { if (state_held_control(state)) { return format_tip(C_("Transform handle tip", @@ -427,12 +449,12 @@ protected: "the selection around the rotation center"); } - virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) { + virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) const { return format_tip(C_("Transform handle tip", "Rotate by %.2f°"), _last_angle * 360.0); } - virtual bool _hasDragTips() { return true; } + virtual bool _hasDragTips() const { return true; } private: static Glib::RefPtr<Gdk::Pixbuf> _corner_to_pixbuf(unsigned c) { @@ -550,7 +572,7 @@ protected: : COMMIT_MOUSE_SKEW_X; } - virtual Glib::ustring _getTip(unsigned state) { + virtual Glib::ustring _getTip(unsigned state) const { if (state_held_shift(state)) { if (state_held_control(state)) { return format_tip(C_("Transform handle tip", @@ -568,7 +590,7 @@ protected: "the opposite handle"); } - virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) { + virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) const { if (_last_horizontal) { return format_tip(C_("Transform handle tip", "Skew horizontally by %.2f°"), _last_angle * 360.0); @@ -578,7 +600,7 @@ protected: } } - virtual bool _hasDragTips() { return true; } + virtual bool _hasDragTips() const { return true; } private: @@ -601,11 +623,13 @@ bool SkewHandle::_last_horizontal = false; double SkewHandle::_last_angle = 0; class RotationCenter : public ControlPoint { + public: - RotationCenter(TransformHandleSet &th) - : ControlPoint(th._desktop, Geom::Point(), SP_ANCHOR_CENTER, _get_pixbuf(), - ¢er_cset, th._transform_handle_group) - , _th(th) + RotationCenter(TransformHandleSet &th) : + ControlPoint(th._desktop, Geom::Point(), SP_ANCHOR_CENTER, + _get_pixbuf(), + _center_cset, th._transform_handle_group), + _th(th) { setVisible(false); } @@ -628,7 +652,7 @@ protected: } sm.unSetup(); } - virtual Glib::ustring _getTip(unsigned /*state*/) { + virtual Glib::ustring _getTip(unsigned /*state*/) const { return C_("Transform handle tip", "<b>Rotation center</b>: drag to change the origin of transforms"); } @@ -640,9 +664,21 @@ private: return Glib::wrap(handles[12], true); } + static ColorSet _center_cset; TransformHandleSet &_th; }; +ControlPoint::ColorSet RotationCenter::_center_cset = { + {0x00000000, 0x000000ff}, + {0x00000000, 0xff0000b0}, + {0x00000000, 0xff0000b0}, + // + {0x00000000, 0x000000ff}, + {0x00000000, 0xff0000b0}, + {0x00000000, 0xff0000b0} +}; + + TransformHandleSet::TransformHandleSet(SPDesktop *d, SPCanvasGroup *th_group) : Manipulator(d) , _active(0) @@ -674,18 +710,22 @@ TransformHandleSet::~TransformHandleSet() } } -/** Sets the mode of transform handles (scale or rotate). */ void TransformHandleSet::setMode(Mode m) { _mode = m; _updateVisibility(_visible); } -Geom::Rect TransformHandleSet::bounds() +Geom::Rect TransformHandleSet::bounds() const { return Geom::Rect(*_scale_corners[0], *_scale_corners[2]); } +ControlPoint const &TransformHandleSet::rotationCenter() const +{ + return *_center; +} + ControlPoint &TransformHandleSet::rotationCenter() { return *_center; @@ -746,9 +786,6 @@ void TransformHandleSet::_clearActiveHandle() _updateVisibility(_visible); } -/** Update the visibility of transformation handles according to settings and the dimensions - * of the bounding box. It hides the handles that would have no effect or lead to - * discontinuities. Additionally, side handles for which there is no space are not shown. */ void TransformHandleSet::_updateVisibility(bool v) { if (v) { |
