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