be0f46b9f1e478289f3d001f183d96a48a59852f
[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
28 class Sketcher;
29
30 #define pt_type SketcherPoint::types
31 #define cv_pen SketcherCurve::pens
32 #define CV_COLOR WHITE
33
34 enum { PT_ID, PT_TY, PT_X, PT_Y, PT_SZ };
35 enum { CV_ID, CV_RAD, CV_PEN, CV_CLR, CV_SZ };
36 enum { PTY_OFF, PTY_LINE, PTY_CURVE, PTY_SZ };
37 enum { PEN_OFF, PEN_SQUARE, PEN_PLUS, PEN_SLANT, PEN_XLANT, PEN_SZ };
38
39 class SketcherVPen : public VFrame
40 {
41 public:
42         SketcherVPen(VFrame *vfrm, int n)
43          : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
44             vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
45             vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
46             vfrm->get_bytes_per_line()) {
47                 this->vfrm = vfrm;  this->n = n;
48         }
49         virtual int draw_pixel(int x, int y) = 0;
50         VFrame *vfrm;
51         int n;
52 };
53
54 class SketcherPenSquare : public SketcherVPen
55 {
56 public:
57         SketcherPenSquare(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
58         int draw_pixel(int x, int y);
59 };
60 class SketcherPenPlus : public SketcherVPen
61 {
62 public:
63         SketcherPenPlus(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
64         int draw_pixel(int x, int y);
65 };
66 class SketcherPenSlant : public SketcherVPen
67 {
68 public:
69         SketcherPenSlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
70         int draw_pixel(int x, int y);
71 };
72 class SketcherPenXlant : public SketcherVPen
73 {
74 public:
75         SketcherPenXlant(VFrame *vfrm, int n) : SketcherVPen(vfrm, n) {}
76         int draw_pixel(int x, int y);
77 };
78
79
80 class SketcherPoint
81 {
82 public:
83         int id, pty;
84         int x, y;
85
86         void init(int id, int pty, int x, int y);
87         SketcherPoint(int id, int pty, int x, int y);
88         SketcherPoint(int id=-1);
89         SketcherPoint(SketcherPoint &pt);
90         ~SketcherPoint();
91         int equivalent(SketcherPoint &that);
92         void copy_from(SketcherPoint &that);
93         void save_data(FileXML &output);
94         void read_data(FileXML &input);
95         static const char *types[PTY_SZ];
96 };
97 class SketcherPoints : public ArrayList<SketcherPoint *>
98 {
99 public:
100         SketcherPoints() {}
101         ~SketcherPoints() { remove_all_objects(); }
102         void dump();
103 };
104
105
106 class SketcherCurve
107 {
108 public:
109         int id, pen, radius, color;
110         static const char *pens[PEN_SZ];
111
112         SketcherPoints points;
113
114         void init(int id, int pen, int radius, int color);
115         SketcherCurve(int id, int pen, int radius, int color);
116         SketcherCurve(int id=-1);
117         ~SketcherCurve();
118         SketcherCurve(SketcherCurve &cv);
119         int equivalent(SketcherCurve &that);
120         void copy_from(SketcherCurve &that);
121         void save_data(FileXML &output);
122         void read_data(FileXML &input);
123         VFrame *new_vpen(VFrame *out);
124         void draw(VFrame *out);
125 };
126 class SketcherCurves : public ArrayList<SketcherCurve *>
127 {
128 public:
129         SketcherCurves() {}
130         ~SketcherCurves() { remove_all_objects(); }
131         void dump();
132 };
133
134 class SketcherConfig
135 {
136 public:
137         SketcherConfig();
138         ~SketcherConfig();
139
140         SketcherCurves curves;
141         int equivalent(SketcherConfig &that);
142         void copy_from(SketcherConfig &that);
143         void interpolate(SketcherConfig &prev, SketcherConfig &next,
144                 long prev_frame, long next_frame, long current_frame);
145         void limits();
146
147         int drag;
148         int cv_selected, pt_selected;
149 };
150
151 class Sketcher : public PluginVClient
152 {
153 public:
154         Sketcher(PluginServer *server);
155         ~Sketcher();
156         PLUGIN_CLASS_MEMBERS2(SketcherConfig)
157         int is_realtime();
158         void update_gui();
159         void save_data(KeyFrame *keyframe);
160         void read_data(KeyFrame *keyframe);
161         int new_curve(int pen, int radius, int color);
162         int new_curve();
163         int new_point(SketcherCurve *cv, int pty, int x, int y, int idx=-1);
164         int new_point(int idx=-1);
165         int process_realtime(VFrame *input, VFrame *output);
166         static void draw_point(VFrame *vfrm, SketcherPoint *pt, int color, int d);
167         void draw_point(VFrame *vfrm, SketcherPoint *pt, int color);
168
169         VFrame *input, *output;
170         int w, h, color_model, bpp, comp;
171         int is_yuv, is_float;
172 };
173
174 #endif