summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/tools/tool_curves/kis_tool_moutline.h
blob: b9b4830fe2807f1253bbaf83d96d1518e017a11f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 *  kis_tool_moutline.h -- part of Chalk
 *
 *  Copyright (c) 2006 Emanuele Tamponi <emanuele@valinor.it>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef KIS_TOOL_MOUTLINE_H_
#define KIS_TOOL_MOUTLINE_H_

#include "kis_tool_factory.h"
#include "kis_curve_framework.h"
#include "kis_tool_curve.h"

class TQSlider;
class KisToolMagnetic;
class KisVector2D;
class Node;

typedef TQValueVector<Node> NodeCol;
typedef TQValueVector<NodeCol> NodeMatrix;
typedef TQValueVector<TQ_INT16> GrayCol;
typedef TQValueVector<GrayCol> GrayMatrix;

class KisCurveMagnetic : public KisCurve {

    typedef KisCurve super;

    KisToolMagnetic *m_parent;

    void reduceMatrix (TQRect&, GrayMatrix&, int, int, int, int);
    void findEdge (int, int, const GrayMatrix&, Node&);
    void detectEdges (const TQRect&, KisPaintDeviceSP, GrayMatrix&);

    void gaussianBlur (const TQRect&, KisPaintDeviceSP, KisPaintDeviceSP);
    void toGrayScale (const TQRect&, KisPaintDeviceSP, GrayMatrix&);
    void getDeltas (const GrayMatrix&, GrayMatrix&, GrayMatrix&);
    void getMagnitude (const GrayMatrix&, const GrayMatrix&, GrayMatrix&);
    void nonMaxSupp (const GrayMatrix&, const GrayMatrix&, const GrayMatrix&, GrayMatrix&);

public:

    KisCurveMagnetic (KisToolMagnetic *parent);
    ~KisCurveMagnetic ();

    virtual KisCurve::iterator addPivot (iterator, const KisPoint&);
    virtual KisCurve::iterator pushPivot (const KisPoint&);
    virtual void calculateCurve (iterator, iterator, iterator);

};

class KisToolMagnetic : public KisToolCurve {

    typedef KisToolCurve super;
    Q_OBJECT
  

    friend class KisCurveMagnetic;

public:

    KisToolMagnetic();
    ~KisToolMagnetic();

    virtual void update (KisCanvasSubject*);
    virtual void setup (TDEActionCollection*);
    virtual enumToolType toolType() { return TOOL_SELECT; }
    virtual TQ_UINT32 priority() { return 9; }

    virtual void keyPress(TQKeyEvent*);
    virtual void buttonPress(KisButtonPressEvent*);
    virtual void buttonRelease(KisButtonReleaseEvent*);
    virtual void move(KisMoveEvent*);

    virtual KisCurve::iterator selectByMouse(KisCurve::iterator it);

    bool editingMode() {return m_editingMode;}
    virtual TQWidget* createOptionWidget(TQWidget* parent);

public slots:

    virtual void activate ();
    virtual void deactivate ();

    void slotCommitCurve ();
    void slotSetDistance (int);

private:

    KisCurveMagnetic *m_derived;
    TQWidget* m_optWidget;
    TQLabel* m_mode;
    TQLabel* m_lbDistance;
    TQSlider* m_slDistance;
    bool m_editingMode;
    bool m_editingCursor;
    bool m_draggingCursor;
    bool m_needNewPivot;

    int m_distance;

};

class KisToolMagneticFactory : public KisToolFactory {
    typedef KisToolFactory super;
public:
    KisToolMagneticFactory() : super() {};
    virtual ~KisToolMagneticFactory(){};

    virtual KisTool * createTool(TDEActionCollection * ac) {
        KisTool * t =  new KisToolMagnetic();
        TQ_CHECK_PTR(t);
        t->setup(ac);
        return t;
    }
    virtual KisID id() { return KisID("magneticoutline", i18n("Magnetic Outline Selection Tool")); }
};

#endif // KIS_TOOL_MOUTLINE_H_