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