point.cpp revision 5c45bb188ab729e501e48732842cb9de6a9813be
210N/A/*
210N/A * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
210N/A *
210N/A * Released under GNU GPL, read the file 'COPYING' for more information
943N/A */
210N/A
210N/A#include "ui/widget/registered-widget.h"
919N/A#include "live_effects/parameter/point.h"
919N/A#include "live_effects/effect.h"
919N/A#include "svg/svg.h"
919N/A#include "svg/stringstream.h"
919N/A#include "ui/widget/point.h"
919N/A#include "widgets/icon.h"
919N/A#include "inkscape.h"
919N/A#include "verbs.h"
919N/A#include "knotholder.h"
919N/A#include <glibmm/i18n.h>
919N/A
919N/A// needed for on-canvas editting:
919N/A#include "desktop.h"
919N/A
919N/Anamespace Inkscape {
919N/A
919N/Anamespace LivePathEffect {
210N/A
210N/APointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
210N/A const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
210N/A Effect* effect, const gchar *htip, Geom::Point default_value)
493N/A : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
210N/A{
210N/A knot_shape = SP_KNOT_SHAPE_DIAMOND;
851N/A knot_mode = SP_KNOT_MODE_XOR;
210N/A knot_color = 0xffffff00;
911N/A handle_tip = g_strdup(htip);
911N/A}
911N/A
911N/APointParam::~PointParam()
210N/A{
210N/A if (handle_tip)
210N/A g_free(handle_tip);
210N/A}
210N/A
210N/Avoid
210N/APointParam::param_set_default()
210N/A{
210N/A param_setValue(defvalue);
493N/A}
969N/A
210N/Abool
493N/APointParam::param_readSVGValue(const gchar * strvalue)
210N/A{
210N/A gchar ** strarray = g_strsplit(strvalue, ",", 2);
210N/A double newx, newy;
210N/A unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
210N/A success += sp_svg_number_read_d(strarray[1], &newy);
493N/A g_strfreev (strarray);
210N/A if (success == 2) {
210N/A param_setValue( Geom::Point(newx, newy) );
210N/A return true;
}
return false;
}
gchar *
PointParam::param_getSVGValue() const
{
Inkscape::SVGOStringStream os;
os << *dynamic_cast<Geom::Point const *>( this );
gchar * str = g_strdup(os.str().c_str());
return str;
}
Gtk::Widget *
PointParam::param_newWidget()
{
Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
param_tooltip,
param_key,
*param_wr,
param_effect->getRepr(),
param_effect->getSPDoc() ) );
// TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Geom::Affine transf = desktop->doc2dt();
pointwdg->setTransform(transf);
pointwdg->setValue( *this );
pointwdg->clearProgrammatically();
pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
static_cast<Gtk::HBox*>(hbox)->show_all_children();
return dynamic_cast<Gtk::Widget *> (hbox);
}
void
PointParam::param_setValue(Geom::Point newpoint)
{
*dynamic_cast<Geom::Point *>( this ) = newpoint;
}
void
PointParam::param_set_and_write_new_value (Geom::Point newpoint)
{
Inkscape::SVGOStringStream os;
os << newpoint;
gchar * str = g_strdup(os.str().c_str());
param_write_to_repr(str);
g_free(str);
}
void
PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/)
{
param_set_and_write_new_value( (*this) * postmul );
}
void
PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
{
knot_shape = shape;
knot_mode = mode;
knot_color = color;
}
class PointParamKnotHolderEntity : public KnotHolderEntity {
public:
PointParamKnotHolderEntity(PointParam *p) { this->pparam = p; }
virtual ~PointParamKnotHolderEntity() {}
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get() const;
virtual void knot_click(guint state);
private:
PointParam *pparam;
};
void
PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
{
Geom::Point const s = snap_knot_position(p, state);
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*/)
{
g_print ("This is the handle associated to parameter '%s'\n", pparam->param_key.c_str());
}
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 :