point.cpp revision cbff03643467232537259e0f72dd6c196f9cffa5
e781423d621c888bfbcfab74512d797385606aa1dvlierop/*
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
e781423d621c888bfbcfab74512d797385606aa1dvlierop *
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Released under GNU GPL, read the file 'COPYING' for more information
e781423d621c888bfbcfab74512d797385606aa1dvlierop */
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "ui/widget/registered-widget.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "live_effects/parameter/point.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "live_effects/effect.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "svg/svg.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "svg/stringstream.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "ui/widget/point.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "widgets/icon.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "inkscape.h"
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop#include "verbs.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop#include "knotholder.h"
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop#include <glibmm/i18n.h>
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop// needed for on-canvas editting:
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlierop#include "desktop.h"
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropnamespace Inkscape {
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlieropnamespace LivePathEffect {
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
e781423d621c888bfbcfab74512d797385606aa1dvlierop const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
e781423d621c888bfbcfab74512d797385606aa1dvlierop Effect* effect, const gchar *htip, Geom::Point default_value)
771d00baf3d15209a77dce026f7ef45a78365e62dvlierop : Geom::Point(default_value),
1aa821e67cb9667c99920eadec0f58532f73652cDiederik van Lierop Parameter(label, tip, key, wr, effect),
995ec331afc69a2e82dac045e5f8749a4bc6d65edvlierop defvalue(default_value)
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop knot_shape = SP_KNOT_SHAPE_DIAMOND;
e781423d621c888bfbcfab74512d797385606aa1dvlierop knot_mode = SP_KNOT_MODE_XOR;
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop knot_color = 0xffffff00;
e781423d621c888bfbcfab74512d797385606aa1dvlierop handle_tip = g_strdup(htip);
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop}
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof KosińskiPointParam::~PointParam()
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop if (handle_tip)
e781423d621c888bfbcfab74512d797385606aa1dvlierop g_free(handle_tip);
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński}
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropvoid
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::param_set_default()
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop param_setValue(defvalue);
771d00baf3d15209a77dce026f7ef45a78365e62dvlierop}
1aa821e67cb9667c99920eadec0f58532f73652cDiederik van Lierop
995ec331afc69a2e82dac045e5f8749a4bc6d65edvlieropvoid
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van LieropPointParam::param_set_and_write_default()
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop param_set_and_write_new_value(defvalue);
e781423d621c888bfbcfab74512d797385606aa1dvlierop}
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropvoid
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::param_update_default(Geom::Point newpoint)
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop this->defvalue = newpoint;
e781423d621c888bfbcfab74512d797385606aa1dvlierop}
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropbool
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::param_readSVGValue(const gchar * strvalue)
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop gchar ** strarray = g_strsplit(strvalue, ",", 2);
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop double newx, newy;
e781423d621c888bfbcfab74512d797385606aa1dvlierop unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
e781423d621c888bfbcfab74512d797385606aa1dvlierop success += sp_svg_number_read_d(strarray[1], &newy);
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński g_strfreev (strarray);
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński if (success == 2) {
2b7ee786ac3f40bb6b0d6e19f565b802f29f50e0dvlierop param_setValue( Geom::Point(newx, newy) );
e781423d621c888bfbcfab74512d797385606aa1dvlierop return true;
e781423d621c888bfbcfab74512d797385606aa1dvlierop }
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop return false;
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop}
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lieropgchar *
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van LieropPointParam::param_getSVGValue() const
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop{
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop Inkscape::SVGOStringStream os;
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop os << *dynamic_cast<Geom::Point const *>( this );
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop gchar * str = g_strdup(os.str().c_str());
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop return str;
e781423d621c888bfbcfab74512d797385606aa1dvlierop}
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropGtk::Widget *
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::param_newWidget()
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlierop param_tooltip,
e781423d621c888bfbcfab74512d797385606aa1dvlierop param_key,
e781423d621c888bfbcfab74512d797385606aa1dvlierop *param_wr,
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlierop param_effect->getRepr(),
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlierop param_effect->getSPDoc() ) );
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlierop // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop SPDesktop *desktop = SP_ACTIVE_DESKTOP;
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop Geom::Affine transf = desktop->doc2dt();
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop pointwdg->setTransform(transf);
e781423d621c888bfbcfab74512d797385606aa1dvlierop pointwdg->setValue( *this );
e781423d621c888bfbcfab74512d797385606aa1dvlierop pointwdg->clearProgrammatically();
e781423d621c888bfbcfab74512d797385606aa1dvlierop pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
7958bbff516df35ec85075ab114769c23cb3669dDiederik van Lierop
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
e781423d621c888bfbcfab74512d797385606aa1dvlierop static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop static_cast<Gtk::HBox*>(hbox)->show_all_children();
e781423d621c888bfbcfab74512d797385606aa1dvlierop
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński return dynamic_cast<Gtk::Widget *> (hbox);
e781423d621c888bfbcfab74512d797385606aa1dvlierop}
e781423d621c888bfbcfab74512d797385606aa1dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropvoid
71c8857afc501c5e737bce6022fd9ac810d94c05dvlieropPointParam::param_setValue(Geom::Point newpoint)
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
e781423d621c888bfbcfab74512d797385606aa1dvlierop *dynamic_cast<Geom::Point *>( this ) = newpoint;
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop}
e781423d621c888bfbcfab74512d797385606aa1dvlierop
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlieropvoid
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::param_set_and_write_new_value(Geom::Point newpoint)
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop Inkscape::SVGOStringStream os;
e781423d621c888bfbcfab74512d797385606aa1dvlierop os << newpoint;
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop gchar * str = g_strdup(os.str().c_str());
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop param_write_to_repr(str);
e781423d621c888bfbcfab74512d797385606aa1dvlierop g_free(str);
e781423d621c888bfbcfab74512d797385606aa1dvlierop}
e781423d621c888bfbcfab74512d797385606aa1dvlierop
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlieropvoid
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/)
e781423d621c888bfbcfab74512d797385606aa1dvlierop{
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop param_set_and_write_new_value( (*this) * postmul );
e781423d621c888bfbcfab74512d797385606aa1dvlierop}
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lieropvoid
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van LieropPointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop{
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop knot_shape = shape;
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop knot_mode = mode;
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop knot_color = color;
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop}
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lieropclass PointParamKnotHolderEntity : public KnotHolderEntity {
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lieroppublic:
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop PointParamKnotHolderEntity(PointParam *p) { this->pparam = p; }
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop virtual ~PointParamKnotHolderEntity() {}
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop virtual Geom::Point knot_get() const;
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop virtual void knot_click(guint state);
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lieropprivate:
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop PointParam *pparam;
e781423d621c888bfbcfab74512d797385606aa1dvlierop};
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop
e781423d621c888bfbcfab74512d797385606aa1dvlieropvoid
e781423d621c888bfbcfab74512d797385606aa1dvlieropPointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop{
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop Geom::Point s = snap_knot_position(p, state);
e781423d621c888bfbcfab74512d797385606aa1dvlierop if (state & GDK_CONTROL_MASK) {
e781423d621c888bfbcfab74512d797385606aa1dvlierop Geom::Point A(origin[Geom::X],p[Geom::Y]);
e781423d621c888bfbcfab74512d797385606aa1dvlierop Geom::Point B(p[Geom::X],origin[Geom::Y]);
e781423d621c888bfbcfab74512d797385606aa1dvlierop double distanceA = Geom::distance(A,p);
e781423d621c888bfbcfab74512d797385606aa1dvlierop double distanceB = Geom::distance(B,p);
e781423d621c888bfbcfab74512d797385606aa1dvlierop if(distanceA > distanceB){
e781423d621c888bfbcfab74512d797385606aa1dvlierop s = B;
e781423d621c888bfbcfab74512d797385606aa1dvlierop } else {
e781423d621c888bfbcfab74512d797385606aa1dvlierop s = A;
e781423d621c888bfbcfab74512d797385606aa1dvlierop }
e781423d621c888bfbcfab74512d797385606aa1dvlierop }
pparam->param_setValue(s);
sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
}
Geom::Point
PointParamKnotHolderEntity::knot_get() const
{
return *pparam;
}
void
PointParamKnotHolderEntity::knot_click(guint state)
{
if (state & GDK_CONTROL_MASK) {
if (state & GDK_MOD1_MASK) {
this->pparam->param_set_default();
sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
}
}
}
void
PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
{
PointParamKnotHolderEntity *e = new PointParamKnotHolderEntity(this);
// TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself???
e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color);
knotholder->add(e);
}
} /* namespace LivePathEffect */
} /* 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=8:softtabstop=4 :