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