point.cpp revision 64caa91f2899a6648503a75dc7310841955b74fd
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_CPP
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/*
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Released under GNU GPL, read the file 'COPYING' for more information
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "live_effects/parameter/point.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "live_effects/effect.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "svg/svg.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "svg/stringstream.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include <gtkmm.h>
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "ui/widget/point.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "widgets/icon.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "ui/widget/registered-widget.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "knot.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "inkscape.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "verbs.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby// needed for on-canvas editting:
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "tools-switch.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "shape-editor.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "node-context.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "desktop-handles.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "selection.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#include "desktop.h"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define LPEPOINTPARAM_DEBUG // undefine to disable all on-canvas editing code for PointParam
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define PRM_KNOT_COLOR_NORMAL 0xffffff00
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define PRM_KNOT_COLOR_SELECTED 0x0000ff00
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbynamespace Inkscape {
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbynamespace LivePathEffect {
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Effect* effect, Geom::Point default_value )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby knot = NULL;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#ifdef LPEPOINTPARAM_DEBUG
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby oncanvas_editable = true;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#endif
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::~PointParam()
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if (knot)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby g_object_unref (G_OBJECT (knot));
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyvoid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_set_default()
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_setValue(defvalue);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbybool
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_readSVGValue(const gchar * strvalue)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby gchar ** strarray = g_strsplit(strvalue, ",", 2);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby double newx, newy;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby success += sp_svg_number_read_d(strarray[1], &newy);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby g_strfreev (strarray);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if (success == 2) {
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_setValue( Geom::Point(newx, newy) );
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby return true;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby }
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby return false;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbygchar *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_writeSVGValue() const
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Inkscape::SVGOStringStream os;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby os << (*this)[0] << "," << (*this)[1];
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby gchar * str = g_strdup(os.str().c_str());
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby return str;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyGtk::Widget *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_newWidget(Gtk::Tooltips * tooltips)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Inkscape::UI::Widget::RegisteredPoint * pointwdg = Gtk::manage(
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby new Inkscape::UI::Widget::RegisteredPoint( param_label,
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_tooltip,
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_key,
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *param_wr,
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_effect->getRepr(),
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_effect->getSPDoc() ) );
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pointwdg->setValue( (*this)[0], (*this)[1] );
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) );
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pButton->set_relief(Gtk::RELIEF_NONE);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pIcon->show();
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pButton->add(*pIcon);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pButton->show();
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click));
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#ifndef LPEPOINTPARAM_DEBUG
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby pButton->set_sensitive(false);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#endif
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby static_cast<Gtk::HBox*>(hbox)->pack_start(*pButton, true, true);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby static_cast<Gtk::HBox*>(hbox)->show_all_children();
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby tooltips->set_tip(*pButton, _("Edit on-canvas"));
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby return dynamic_cast<Gtk::Widget *> (hbox);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyvoid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_setValue(Geom::Point newpoint)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *dynamic_cast<Geom::Point *>( this ) = newpoint;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyvoid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_set_and_write_new_value (Geom::Point newpoint)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Inkscape::SVGOStringStream os;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby os << newpoint[0] << "," << newpoint[1];
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby gchar * str = g_strdup(os.str().c_str());
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_write_to_repr(str);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby g_free(str);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyvoid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby // If not already in nodecontext, goto it!
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if (!tools_isactive(dt, TOOLS_NODES)) {
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby tools_switch_current(TOOLS_NODES);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby }
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby shape_editor->set_item_lpe_point_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str());
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyvoid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_set_and_write_new_value( (*this) * postmul );
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby// CALLBACKS:
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyvoid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyPointParam::on_button_click()
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem();
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if (item != NULL) {
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby param_editOncanvas(item, SP_ACTIVE_DESKTOP);
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby }
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby} /* namespace LivePathEffect */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby} /* namespace Inkscape */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/*
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby Local Variables:
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby mode:c++
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby c-file-style:"stroustrup"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby indent-tabs-mode:nil
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fill-column:99
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby End:
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby*/
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby