add edit clear submenu/clear hard_edges, fix tessy gl segv, mask toolgui layout,...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / canvas.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef CANVAS_H
23 #define CANVAS_H
24
25 #include "canvas.inc"
26 #include "edl.inc"
27 #include "guicast.h"
28 #include "mwindow.inc"
29 #include "videodevice.inc"
30 // Output for all X11 video
31
32 // The EDL arguments can be set to 0 if the canvas_w and canvas_h are used
33 class Canvas
34 {
35 public:
36         Canvas(MWindow *mwindow, BC_WindowBase *subwindow,
37                 int x, int y, int w, int h,
38                 int output_w, int output_h,
39                 int use_scrollbars);
40         virtual ~Canvas();
41
42         void reset();
43 // Get dimensions given a zoom
44         void calculate_sizes(float aspect_ratio,
45                 int output_w, int output_h, float zoom,
46                 int &w, int &h);
47 // Lock canvas pointer and window
48         BC_WindowBase *lock_canvas(const char *loc);
49         void unlock_canvas();
50
51         void create_objects(EDL *edl);
52         void set_cursor(int cursor);
53 // Start video playback
54         void start_video();
55         void stop_video();
56
57 // Start single frame processing.  Causes the status indicator to update
58         void start_single();
59         void stop_single();
60
61         void start_fullscreen();
62         void stop_fullscreen();
63
64 // Don't call from inside the canvas
65         void create_canvas();
66
67
68
69 // Processing or video playback changed.
70         virtual void status_event() {};
71
72
73         virtual void reset_camera() {}
74         virtual void reset_projector() {}
75         virtual void camera_keyframe() {}
76         virtual void projector_keyframe() {}
77         virtual void zoom_resize_window(float percentage) {}
78         virtual void zoom_auto() {}
79         virtual int cursor_leave_event() { return 0; }
80         virtual int cursor_enter_event() { return 0; }
81         virtual int button_release_event() { return 0; }
82         virtual int button_press_event();
83         virtual int cursor_motion_event() { return 0; }
84         virtual int need_overlays() { return 1; }
85         virtual void draw_overlays() {}
86         virtual void toggle_controls() {}
87         virtual int get_cwindow_controls() { return 0; }
88         virtual int get_fullscreen();
89         virtual void set_fullscreen(int value);
90
91         int cursor_leave_event_base(BC_WindowBase *caller);
92         int cursor_enter_event_base(BC_WindowBase *caller);
93         int button_press_event_base(BC_WindowBase *caller);
94         int keypress_event(BC_WindowBase *caller);
95 // Use menu different options for different windows
96         void use_cwindow();
97         void use_rwindow();
98         void use_vwindow();
99         void use_auxwindow(BC_WindowBase *aux);
100
101 // Provide canvas dimensions since a BC_Bitmap containing obsolete dimensions
102 // is often the output being transferred to.
103 // This gets the input coordinates on the device output_frame
104 // and the corresponding output coordinates on the canvas.
105 // Must be floating point to support OpenGL.
106         void get_transfers(EDL *edl,
107                 float &output_x1,
108                 float &output_y1,
109                 float &output_x2,
110                 float &output_y2,
111                 float &canvas_x1,
112                 float &canvas_y1,
113                 float &canvas_x2,
114                 float &canvas_y2,
115 // passing -1 causes automatic size detection
116                 int canvas_w = -1,
117                 int canvas_h = -1);
118         void update_geometry(EDL *edl, int x, int y, int w, int h);
119         void reposition_window(EDL *edl, int x, int y, int w, int h);
120         virtual void reset_translation() {};
121         virtual void close_source() {};
122 // Updates the stores
123         virtual void update_zoom(int x, int y, float zoom) {};
124         void check_boundaries(EDL *edl, int &x, int &y, float &zoom);
125         void update_scrollbars(int flush);
126 // Get scrollbar positions relative to output.
127 // No correction is done if output is smaller than canvas
128         virtual int get_xscroll() { return 0; };
129         virtual int get_yscroll() { return 0; };
130         virtual float get_zoom() { return 0; };
131 // Updates the refresh_frame
132         void update_refresh(VideoDevice *device, VFrame *output_frame);
133 // Redraws the refresh_frame
134         virtual void draw_refresh(int flush = 1) {};
135         virtual void clear(int flash=1);
136
137 // Get top left offset of canvas relative to output.
138 // Normally negative.  Can be positive if output is smaller than canvas.
139         float get_x_offset(EDL *edl,
140                 int single_channel,
141                 float zoom_x,
142                 float conformed_w,
143                 float conformed_h);
144         float get_y_offset(EDL *edl,
145                 int single_channel,
146                 float zoom_y,
147                 float conformed_w,
148                 float conformed_h);
149         void get_zooms(EDL *edl,
150                 int single_channel,
151                 float &zoom_x,
152                 float &zoom_y,
153                 float &conformed_w,
154                 float &conformed_h);
155
156
157 // Convert coord from output to canvas position, including
158 // x and y scroll offsets
159         void output_to_canvas(EDL *edl, int single_channel, float &x, float &y);
160 // Convert coord from canvas to output position
161         void canvas_to_output(EDL *edl, int single_channel, float &x, float &y);
162
163 // Get dimensions of frame being sent to canvas
164         virtual int get_output_w(EDL *edl);
165         virtual int get_output_h(EDL *edl);
166 // Get if scrollbars exist
167         int scrollbars_exist();
168 // Get cursor locations relative to canvas and not offset by scrollbars
169         int get_cursor_x();
170         int get_cursor_y();
171         int get_buttonpress();
172 // Gets whatever video surface is enabled
173         BC_WindowBase* get_canvas();
174 // draw_refresh, with/without locks
175         int refresh(int flush);
176         int redraw(int flush);
177
178 // The owner of the canvas
179         BC_WindowBase *subwindow;
180 // Video surface if a subwindow
181         CanvasOutput *canvas_subwindow;
182 // Video surface if fullscreen
183         CanvasFullScreen *canvas_fullscreen;
184         CanvasXScroll *xscroll;
185         CanvasYScroll *yscroll;
186         CanvasPopup *canvas_menu;
187         CanvasFullScreenPopup *fullscreen_menu;
188         int x, y, w, h;
189         int use_scrollbars;
190         BC_WindowBase *canvas_auxwindow;
191 // Used in record monitor
192         int output_w, output_h;
193 // Last frame played is stored here in driver format for
194 // refreshes.
195         VFrame *refresh_frame;
196 // Results from last get_scrollbars
197         int w_needed;
198         int h_needed;
199         int w_visible;
200         int h_visible;
201 // For cases where video is not enabled on the canvas but processing is
202 // occurring for a single frame, this causes the status to update.
203         int is_processing;
204         int is_fullscreen;
205 // Cursor is inside video surface
206         int cursor_inside;
207         int view_x;
208         int view_y;
209         int view_w;
210         int view_h;
211         int scr_w0;
212         int root_w, root_h;
213
214         MWindow *mwindow;
215
216 private:
217         void get_scrollbars(EDL *edl,
218                 int &canvas_x, int &canvas_y, int &canvas_w, int &canvas_h);
219 // Lock access to the canvas pointer.
220         Condition *canvas_lock;
221 };
222
223
224 class CanvasOutput : public BC_SubWindow
225 {
226 public:
227         CanvasOutput(Canvas *canvas,
228                 int x, int y, int w, int h);
229         ~CanvasOutput();
230
231         int cursor_leave_event();
232         int cursor_enter_event();
233         int button_press_event();
234         int button_release_event();
235         int cursor_motion_event();
236         int keypress_event();
237
238         Canvas *canvas;
239 };
240
241
242
243
244 class CanvasFullScreen : public BC_FullScreen
245 {
246 public:
247         CanvasFullScreen(Canvas *canvas, int w, int h);
248         ~CanvasFullScreen();
249
250         Canvas *canvas;
251 };
252
253
254
255
256 class CanvasXScroll : public BC_ScrollBar
257 {
258 public:
259         CanvasXScroll(EDL *edl,
260                 Canvas *canvas,
261                 int x,
262                 int y,
263                 int length,
264                 int position,
265                 int handle_length,
266                 int pixels);
267         ~CanvasXScroll();
268
269         int handle_event();
270         Canvas *canvas;
271         EDL *edl;
272 };
273
274 class CanvasYScroll : public BC_ScrollBar
275 {
276 public:
277         CanvasYScroll(EDL *edl,
278                 Canvas *canvas,
279                 int x,
280                 int y,
281                 int length,
282                 int position,
283                 int handle_length,
284                 int pixels);
285         ~CanvasYScroll();
286
287         int handle_event();
288
289         Canvas *canvas;
290         EDL *edl;
291 };
292
293 class CanvasFullScreenPopup : public BC_PopupMenu
294 {
295 public:
296         CanvasFullScreenPopup(Canvas *canvas);
297
298         void create_objects();
299         void use_cwindow();
300
301         Canvas *canvas;
302 };
303
304 class CanvasSubWindowItem : public BC_MenuItem
305 {
306 public:
307         CanvasSubWindowItem(Canvas *canvas);
308         int handle_event();
309         Canvas *canvas;
310 };
311
312 class CanvasPopup : public BC_PopupMenu
313 {
314 public:
315         CanvasPopup(Canvas *canvas);
316         ~CanvasPopup();
317
318         void create_objects();
319         void use_cwindow();
320         void use_rwindow();
321         void use_vwindow();
322
323         Canvas *canvas;
324         CanvasToggleControls *toggle_controls;
325 };
326
327 class CanvasZoomSize : public BC_MenuItem
328 {
329 public:
330         CanvasZoomSize(Canvas *canvas);
331
332         Canvas *canvas;
333 };
334
335 class CanvasSizeSubMenu : public BC_SubMenu
336 {
337 public:
338         CanvasSizeSubMenu(CanvasZoomSize *zoom_size);
339
340         CanvasZoomSize *zoom_size;
341 };
342
343 class CanvasPopupSize : public BC_MenuItem
344 {
345 public:
346         CanvasPopupSize(Canvas *canvas, char *text, float percentage);
347         ~CanvasPopupSize();
348         int handle_event();
349         Canvas *canvas;
350         float percentage;
351 };
352
353 class CanvasPopupAuto : public BC_MenuItem
354 {
355 public:
356         CanvasPopupAuto(Canvas *canvas);
357         int handle_event();
358         Canvas *canvas;
359 };
360
361 class CanvasPopupResetCamera : public BC_MenuItem
362 {
363 public:
364         CanvasPopupResetCamera(Canvas *canvas);
365         int handle_event();
366         Canvas *canvas;
367 };
368
369 class CanvasPopupResetProjector : public BC_MenuItem
370 {
371 public:
372         CanvasPopupResetProjector(Canvas *canvas);
373         int handle_event();
374         Canvas *canvas;
375 };
376
377 class CanvasPopupCameraKeyframe : public BC_MenuItem
378 {
379 public:
380         CanvasPopupCameraKeyframe(Canvas *canvas);
381         int handle_event();
382         Canvas *canvas;
383 };
384
385 class CanvasPopupProjectorKeyframe : public BC_MenuItem
386 {
387 public:
388         CanvasPopupProjectorKeyframe(Canvas *canvas);
389         int handle_event();
390         Canvas *canvas;
391 };
392
393 class CanvasToggleControls : public BC_MenuItem
394 {
395 public:
396         CanvasToggleControls(Canvas *canvas);
397         int handle_event();
398         static char* calculate_text(int cwindow_controls);
399         Canvas *canvas;
400 };
401
402 class CanvasFullScreenItem : public BC_MenuItem
403 {
404 public:
405         CanvasFullScreenItem(Canvas *canvas);
406         int handle_event();
407         Canvas *canvas;
408 };
409
410 class CanvasPopupResetTranslation : public BC_MenuItem
411 {
412 public:
413         CanvasPopupResetTranslation(Canvas *canvas);
414         int handle_event();
415         Canvas *canvas;
416 };
417
418
419 class CanvasPopupRemoveSource : public BC_MenuItem
420 {
421 public:
422         CanvasPopupRemoveSource(Canvas *canvas);
423         int handle_event();
424         Canvas *canvas;
425 };
426
427
428
429
430
431 #endif