~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/live_effects/parameter/array.h

  • 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:
 
1
#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H
 
2
#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H
 
3
 
 
4
/*
 
5
 * Inkscape::LivePathEffectParameters
 
6
 *
 
7
* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
 
8
 *
 
9
 * Released under GNU GPL, read the file 'COPYING' for more information
 
10
 */
 
11
 
 
12
#include <vector>
 
13
 
 
14
#include <glib/gtypes.h>
 
15
 
 
16
#include <gtkmm/tooltips.h>
 
17
 
 
18
#include "live_effects/parameter/parameter.h"
 
19
 
 
20
#include "svg/svg.h"
 
21
#include "svg/stringstream.h"
 
22
 
 
23
namespace Inkscape {
 
24
 
 
25
namespace LivePathEffect {
 
26
 
 
27
template <typename StorageType>
 
28
class ArrayParam : public Parameter {
 
29
public:
 
30
    ArrayParam( const Glib::ustring& label,
 
31
                const Glib::ustring& tip,
 
32
                const Glib::ustring& key,
 
33
                Inkscape::UI::Widget::Registry* wr,
 
34
                Effect* effect,
 
35
                size_t n = 0 )
 
36
        : Parameter(label, tip, key, wr, effect), _vector(n)
 
37
    {
 
38
 
 
39
    }
 
40
 
 
41
    virtual ~ArrayParam() {
 
42
 
 
43
    };
 
44
 
 
45
    std::vector<StorageType> const & data() const {
 
46
        return _vector;
 
47
    }
 
48
 
 
49
    virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) {
 
50
        return NULL;
 
51
    }
 
52
 
 
53
    virtual bool param_readSVGValue(const gchar * strvalue) {
 
54
        _vector.clear();
 
55
        gchar ** strarray = g_strsplit(strvalue, "|", 0);
 
56
        gchar ** iter = strarray;
 
57
        while (*iter != NULL) {
 
58
            _vector.push_back( readsvg(*iter) );
 
59
            iter++;
 
60
        }
 
61
        g_strfreev (strarray);
 
62
        return true;
 
63
    }
 
64
 
 
65
    virtual gchar * param_getSVGValue() const {
 
66
        Inkscape::SVGOStringStream os;
 
67
        writesvg(os, _vector);
 
68
        gchar * str = g_strdup(os.str().c_str());
 
69
        return str;
 
70
    }
 
71
 
 
72
    void param_setValue(std::vector<StorageType> const &new_vector) {
 
73
        _vector = new_vector;
 
74
    }
 
75
 
 
76
    void param_set_default() {
 
77
        param_setValue( std::vector<StorageType>() );
 
78
    }
 
79
 
 
80
    void param_set_and_write_new_value(std::vector<StorageType> const &new_vector) {
 
81
        Inkscape::SVGOStringStream os;
 
82
        writesvg(os, new_vector);
 
83
        gchar * str = g_strdup(os.str().c_str());
 
84
        param_write_to_repr(str);
 
85
        g_free(str);
 
86
    }
 
87
 
 
88
private:
 
89
    ArrayParam(const ArrayParam&);
 
90
    ArrayParam& operator=(const ArrayParam&);
 
91
 
 
92
    std::vector<StorageType> _vector;
 
93
 
 
94
    void writesvg(SVGOStringStream &str, std::vector<StorageType> const &vector) const {
 
95
        for (unsigned int i = 0; i < vector.size(); ++i) {
 
96
            if (i != 0) {
 
97
                // separate items with pipe symbol
 
98
                str << " | ";
 
99
            }
 
100
            str << vector[i];
 
101
        }
 
102
    }
 
103
 
 
104
    StorageType readsvg(const gchar * str);
 
105
};
 
106
 
 
107
 
 
108
} //namespace LivePathEffect
 
109
 
 
110
} //namespace Inkscape
 
111
 
 
112
#endif
 
113
 
 
114
/*
 
115
  Local Variables:
 
116
  mode:c++
 
117
  c-file-style:"stroustrup"
 
118
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
119
  indent-tabs-mode:nil
 
120
  fill-column:99
 
121
  End:
 
122
*/
 
123
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :