~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/live_effects/parameter/vector.cpp

  • Committer: Ted Gould
  • Date: 2008-11-21 05:24:08 UTC
  • Revision ID: ted@canonical.com-20081121052408-tilucis2pjrrpzxx
MergeĀ fromĀ fe-moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 */
8
8
 
9
9
#include "live_effects/parameter/vector.h"
10
 
 
 
10
#include "sp-lpe-item.h"
 
11
#include "knotholder.h"
11
12
#include "svg/svg.h"
12
13
#include "svg/stringstream.h"
 
14
#include <gtkmm.h>
13
15
 
14
 
#include <2geom/coord.h>
 
16
// needed for on-canvas editting:
 
17
class SPDesktop;
15
18
 
16
19
namespace Inkscape {
17
20
 
18
21
namespace LivePathEffect {
19
22
 
20
 
template <>
21
 
double
22
 
VectorParam<double>::readsvg(const gchar * str)
23
 
{
24
 
    double newx = Geom::infinity();
25
 
    sp_svg_number_read_d(str, &newx);
26
 
    return newx;
27
 
}
28
 
 
29
 
template <>
30
 
float
31
 
VectorParam<float>::readsvg(const gchar * str)
32
 
{
33
 
    float newx = Geom::infinity();
34
 
    sp_svg_number_read_f(str, &newx);
35
 
    return newx;
 
23
VectorParam::VectorParam( const Glib::ustring& label, const Glib::ustring& tip,
 
24
                        const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
 
25
                        Effect* effect, Geom::Point default_vector)
 
26
    : Parameter(label, tip, key, wr, effect),
 
27
      defvalue(default_vector),
 
28
      origin(0.,0.),
 
29
      vector(default_vector)
 
30
{
 
31
    vec_knot_shape = SP_KNOT_SHAPE_DIAMOND;
 
32
    vec_knot_mode  = SP_KNOT_MODE_XOR;
 
33
    vec_knot_color = 0xffffb500;
 
34
    ori_knot_shape = SP_KNOT_SHAPE_CIRCLE;
 
35
    ori_knot_mode  = SP_KNOT_MODE_XOR;
 
36
    ori_knot_color = 0xffffb500;
 
37
}
 
38
 
 
39
VectorParam::~VectorParam()
 
40
{
 
41
 
 
42
}
 
43
 
 
44
void
 
45
VectorParam::param_set_default()
 
46
{
 
47
    setOrigin(Geom::Point(0.,0.));
 
48
    setVector(defvalue);
 
49
}
 
50
 
 
51
bool
 
52
VectorParam::param_readSVGValue(const gchar * strvalue)
 
53
{
 
54
    gchar ** strarray = g_strsplit(strvalue, ",", 4);
 
55
    double val[4];
 
56
    unsigned int i = 0;
 
57
    while (strarray[i] && i < 4) {
 
58
        if (sp_svg_number_read_d(strarray[i], &val[i]) != 0) {
 
59
            i++;
 
60
        } else {
 
61
            break;
 
62
        }
 
63
    }
 
64
    g_strfreev (strarray);
 
65
    if (i == 4) {
 
66
        setOrigin( Geom::Point(val[0], val[1]) );
 
67
        setVector( Geom::Point(val[2], val[3]) );
 
68
        return true;
 
69
    }
 
70
    return false;
 
71
}
 
72
 
 
73
gchar *
 
74
VectorParam::param_getSVGValue() const
 
75
{
 
76
    Inkscape::SVGOStringStream os;
 
77
    os << origin << " , " << vector;
 
78
    gchar * str = g_strdup(os.str().c_str());
 
79
    return str;
 
80
}
 
81
 
 
82
Gtk::Widget *
 
83
VectorParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
 
84
{
 
85
/*
 
86
    Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
 
87
        new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
 
88
                                                              param_tooltip,
 
89
                                                              param_key,
 
90
                                                              *param_wr,
 
91
                                                              param_effect->getRepr(),
 
92
                                                              param_effect->getSPDoc() ) );
 
93
    // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
 
94
    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
 
95
    Geom::Matrix transf = desktop->doc2dt();
 
96
    pointwdg->setTransform(transf);
 
97
    pointwdg->setValue( *this );
 
98
    pointwdg->clearProgrammatically();
 
99
    pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
 
100
 
 
101
    Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
 
102
    static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
 
103
    static_cast<Gtk::HBox*>(hbox)->show_all_children();
 
104
 
 
105
    return dynamic_cast<Gtk::Widget *> (hbox);
 
106
    */ return NULL;
 
107
}
 
108
 
 
109
void
 
110
VectorParam::set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector)
 
111
{
 
112
    setValues(new_origin, new_vector);
 
113
    gchar * str = param_getSVGValue();
 
114
    param_write_to_repr(str);
 
115
    g_free(str);
 
116
}
 
117
 
 
118
void
 
119
VectorParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
 
120
{
 
121
    set_and_write_new_values( origin * postmul, vector * postmul );
 
122
}
 
123
 
 
124
 
 
125
void
 
126
VectorParam::set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
 
127
{
 
128
    vec_knot_shape = shape;
 
129
    vec_knot_mode  = mode;
 
130
    vec_knot_color = color;
 
131
}
 
132
 
 
133
void
 
134
VectorParam::set_origin_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
 
135
{
 
136
    ori_knot_shape = shape;
 
137
    ori_knot_mode  = mode;
 
138
    ori_knot_color = color;
 
139
}
 
140
 
 
141
class VectorParamKnotHolderEntity_Origin : public LPEKnotHolderEntity {
 
142
public:
 
143
    VectorParamKnotHolderEntity_Origin(VectorParam *p) : param(p) { }
 
144
    virtual ~VectorParamKnotHolderEntity_Origin() {}
 
145
 
 
146
    virtual void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) {
 
147
        Geom::Point const s = snap_knot_position(p);
 
148
        param->setOrigin(s);
 
149
        sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
 
150
    };
 
151
    virtual Geom::Point knot_get(){
 
152
        return param->origin;
 
153
    };
 
154
    virtual void knot_click(guint /*state*/){
 
155
        g_print ("This is the origin handle associated to parameter '%s'\n", param->param_key.c_str());
 
156
    };
 
157
 
 
158
private:
 
159
    VectorParam *param;
 
160
};
 
161
 
 
162
class VectorParamKnotHolderEntity_Vector : public LPEKnotHolderEntity {
 
163
public:
 
164
    VectorParamKnotHolderEntity_Vector(VectorParam *p) : param(p) { }
 
165
    virtual ~VectorParamKnotHolderEntity_Vector() {}
 
166
 
 
167
    virtual void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
 
168
        Geom::Point const s = p - param->origin;
 
169
        /// @todo implement angle snapping when holding CTRL
 
170
        param->setVector(s);
 
171
        sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
 
172
    };
 
173
    virtual Geom::Point knot_get(){
 
174
        return param->origin + param->vector;
 
175
    };
 
176
    virtual void knot_click(guint /*state*/){
 
177
        g_print ("This is the vector handle associated to parameter '%s'\n", param->param_key.c_str());
 
178
    };
 
179
 
 
180
private:
 
181
    VectorParam *param;
 
182
};
 
183
 
 
184
void
 
185
VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
 
186
{
 
187
    VectorParamKnotHolderEntity_Origin *origin_e = new VectorParamKnotHolderEntity_Origin(this);
 
188
    origin_e->create(desktop, item, knotholder, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color);
 
189
    knotholder->add(origin_e);
 
190
 
 
191
    VectorParamKnotHolderEntity_Vector *vector_e = new VectorParamKnotHolderEntity_Vector(this);
 
192
    vector_e->create(desktop, item, knotholder, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color);
 
193
    knotholder->add(vector_e);
36
194
}
37
195
 
38
196
} /* namespace LivePathEffect */