another sketcher rework, awdw del key short cuts
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / sketcher / sketcher.h
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21
22
23 #ifndef __SKETCHERS_H__
24 #define __SKETCHERS_H__
25
26 #include "pluginvclient.h"
27 #include "overlayframe.inc"
28 #include "vframe.h"
29
30 class Sketcher;
31
32 #define pt_type SketcherPoint::types
33 #define cv_pen SketcherCurve::pens
34 #define CV_COLOR WHITE
35
36 enum { PT_ID, PT_TY, PT_X, PT_Y, PT_SZ };
37 enum { CV_ID, CV_RAD, CV_PEN, CV_CLR, CV_ALP, CV_SZ };
38 enum { PTY_OFF, PTY_LINE, PTY_CURVE, PTY_FILL, PTY_SZ };
39 enum { PEN_OFF, PEN_SQUARE, PEN_PLUS, PEN_SLANT, PEN_XLANT, PEN_SZ };
40 typedef float coord;
41
42 class SketcherVPen : public VFrame
43 {
44 public:
45         VFrame *vfrm;
46         int n;
47         uint8_t *msk;
48
49         SketcherVPen(VFrame *vfrm, int n)
50          : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
51             vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
52             vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
53             vfrm->get_bytes_per_line()) {
54                 this->vfrm = vfrm;  this->n = n;
55                 int sz = vfrm->get_w()*vfrm->get_h();
56                 this->msk = (uint8_t*)memset(new uint8_t[sz],0,sz);
57         }
58         ~SketcherVPen() { delete [] msk; }
59
60         void draw_line(float x1, float y1, float x2, float y2) {
61                 VFrame::draw_line(int(x1+.5f),int(y1+.5f), int(x2+.5f),int(y2+.5f));
62         }
63         void draw_smooth(float x1, float y1, float x2, float y2, float x3, float y3) {
64                 VFrame::draw_smooth(int(x1+.5f),int(y1+.5f),
65                         int(x2+.5f),int(y2+.5f), int(x3+.5f),int(y3+.5f));
66         }
67
68         virtual int draw_pixel(int x, int y) = 0;
69 };
70
71 class SketcherPenSquare : public SketcherVPen
72 {
73 public:
74         SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
75         int draw_pixel(int x, int y);
76 };
77 class SketcherPenPlus : public SketcherVPen
78 {
79 public:
80         SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
81         int draw_pixel(int x, int y);
82 };
83 class SketcherPenSlant : public SketcherVPen
84 {
85 public:
86         SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
87         int draw_pixel(int x, int y);
88 };
89 class SketcherPenXlant : public SketcherVPen
90 {
91 public:
92         SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
93         int draw_pixel(int x, int y);
94 };
95
96
97 class SketcherPoint
98 {
99 public:
100         int id, pty;
101         coord x, y;
102
103         void init(int id, int pty, coord x, coord y);
104         SketcherPoint(int id, int pty, coord x, coord y);
105         SketcherPoint(int id=-1);
106         SketcherPoint(SketcherPoint &pt);
107         ~SketcherPoint();
108         int equivalent(SketcherPoint &that);
109         void copy_from(SketcherPoint &that);
110         void save_data(FileXML &output);
111         void read_data(FileXML &input);
112         static const char *types[PTY_SZ];
113 };
114 class SketcherPoints : public ArrayList<SketcherPoint *>
115 {
116 public:
117         SketcherPoints() {}
118         ~SketcherPoints() { remove_all_objects(); }
119         void dump();
120 };
121
122
123 class SketcherCurve
124 {
125 public:
126         int id, pen, width, color;
127         static const char *pens[PEN_SZ];
128
129         SketcherPoints points;
130
131         void init(int id, int pen, int width, int color);
132         SketcherCurve(int id, int pen, int width, int color);
133         SketcherCurve(int id=-1);
134         ~SketcherCurve();
135         SketcherCurve(SketcherCurve &cv);
136         int equivalent(SketcherCurve &that);
137         void copy_from(SketcherCurve &that);
138         void save_data(FileXML &output);
139         void read_data(FileXML &input);
140         double nearest_point(int &pi, coord x, coord y);
141
142         SketcherVPen *new_vpen(VFrame *out);
143         void draw(VFrame *img);
144 };
145 class SketcherCurves : public ArrayList<SketcherCurve *>
146 {
147 public:
148         SketcherCurves() {}
149         ~SketcherCurves() { remove_all_objects(); }
150         void dump();
151 };
152
153 class SketcherConfig
154 {
155 public:
156         SketcherConfig();
157         ~SketcherConfig();
158
159         SketcherCurves curves;
160         int equivalent(SketcherConfig &that);
161         void copy_from(SketcherConfig &that);
162         void interpolate(SketcherConfig &prev, SketcherConfig &next,
163                 long prev_frame, long next_frame, long current_frame);
164         double nearest_point(int &ci, int &pi, coord x, coord y);
165         void limits();
166         void dump();
167
168         int drag;
169         int cv_selected, pt_selected;
170 };
171
172 class Sketcher : public PluginVClient
173 {
174 public:
175         Sketcher(PluginServer *server);
176         ~Sketcher();
177         PLUGIN_CLASS_MEMBERS2(SketcherConfig)
178         int is_realtime();
179         void update_gui();
180         void save_data(KeyFrame *keyframe);
181         void read_data(KeyFrame *keyframe);
182         int new_curve(int pen, int width, int color);
183         int new_curve();
184         int new_point(SketcherCurve *cv, int pty, coord x, coord y, int idx=-1);
185         int new_point(int idx=-1);
186         int process_realtime(VFrame *input, VFrame *output);
187         static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
188         void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
189
190         VFrame *input, *output;
191         VFrame *img, *out;
192         OverlayFrame *overlay_frame;
193         int w, h, color_model, bpp, comp;
194         int is_yuv, is_float;
195 };
196
197 #endif