bg/clr color tweaks, clear borders rework, fc31 depends
[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 int get_clear_color();
90         virtual void set_fullscreen(int value);
91
92         int cursor_leave_event_base(BC_WindowBase *caller);
93         int cursor_enter_event_base(BC_WindowBase *caller);
94         int button_press_event_base(BC_WindowBase *caller);
95         int keypress_event(BC_WindowBase *caller);
96 // Use menu different options for different windows
97         void use_cwindow();
98         void use_rwindow();
99         void use_vwindow();
100         void use_auxwindow(BC_WindowBase *aux);
101
102 // Provide canvas dimensions since a BC_Bitmap containing obsolete dimensions
103 // is often the output being transferred to.
104 // This gets the input coordinates on the device output_frame
105 // and the corresponding output coordinates on the canvas.
106 // Must be floating point to support OpenGL.
107         void get_transfers(EDL *edl,
108                 float &output_x1,
109                 float &output_y1,
110                 float &output_x2,
111                 float &output_y2,
112                 float &canvas_x1,
113                 float &canvas_y1,
114                 float &canvas_x2,
115                 float &canvas_y2,
116 // passing -1 causes automatic size detection
117                 int canvas_w = -1,
118                 int canvas_h = -1);
119         void update_geometry(EDL *edl, int x, int y, int w, int h);
120         void reposition_window(EDL *edl, int x, int y, int w, int h);
121         virtual void reset_translation() {};
122         virtual void close_source() {};
123 // Updates the stores
124         virtual void update_zoom(int x, int y, float zoom) {};
125         void check_boundaries(EDL *edl, int &x, int &y, float &zoom);
126         void clear_borders(EDL *edl);
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 // draw_refresh, with/without locks
177         int refresh(int flush);
178         int redraw(int flush);
179
180 // The owner of the canvas
181         BC_WindowBase *subwindow;
182 // Video surface if a subwindow
183         CanvasOutput *canvas_subwindow;
184 // Video surface if fullscreen
185         CanvasFullScreen *canvas_fullscreen;
186         CanvasXScroll *xscroll;
187         CanvasYScroll *yscroll;
188         CanvasPopup *canvas_menu;
189         CanvasFullScreenPopup *fullscreen_menu;
190         int x, y, w, h;
191         int use_scrollbars;
192         BC_WindowBase *canvas_auxwindow;
193 // Used in record monitor
194         int output_w, output_h;
195 // Last frame played is stored here in driver format for
196 // refreshes.
197         VFrame *refresh_frame;
198 // Results from last get_scrollbars
199         int w_needed;
200         int h_needed;
201         int w_visible;
202         int h_visible;
203 // For cases where video is not enabled on the canvas but processing is
204 // occurring for a single frame, this causes the status to update.
205         int is_processing;
206         int is_fullscreen;
207 // Cursor is inside video surface
208         int cursor_inside;
209         int view_x;
210         int view_y;
211         int view_w;
212         int view_h;
213         int scr_w0;
214         int root_w, root_h;
215
216         MWindow *mwindow;
217
218 private:
219         void get_scrollbars(EDL *edl,
220                 int &canvas_x, int &canvas_y, int &canvas_w, int &canvas_h);
221 // Lock access to the canvas pointer.
222         Condition *canvas_lock;
223 };
224
225
226 class CanvasOutput : public BC_SubWindow
227 {
228 public:
229         CanvasOutput(Canvas *canvas,
230                 int x, int y, int w, int h);
231         ~CanvasOutput();
232
233         int cursor_leave_event();
234         int cursor_enter_event();
235         int button_press_event();
236         int button_release_event();
237         int cursor_motion_event();
238         int keypress_event();
239
240         Canvas *canvas;
241 };
242
243
244
245
246 class CanvasFullScreen : public BC_FullScreen
247 {
248 public:
249         CanvasFullScreen(Canvas *canvas, int w, int h);
250         ~CanvasFullScreen();
251
252         Canvas *canvas;
253 };
254
255
256
257
258 class CanvasXScroll : public BC_ScrollBar
259 {
260 public:
261         CanvasXScroll(EDL *edl,
262                 Canvas *canvas,
263                 int x,
264                 int y,
265                 int length,
266                 int position,
267                 int handle_length,
268                 int pixels);
269         ~CanvasXScroll();
270
271         int handle_event();
272         Canvas *canvas;
273         EDL *edl;
274 };
275
276 class CanvasYScroll : public BC_ScrollBar
277 {
278 public:
279         CanvasYScroll(EDL *edl,
280                 Canvas *canvas,
281                 int x,
282                 int y,
283                 int length,
284                 int position,
285                 int handle_length,
286                 int pixels);
287         ~CanvasYScroll();
288
289         int handle_event();
290
291         Canvas *canvas;
292         EDL *edl;
293 };
294
295 class CanvasFullScreenPopup : public BC_PopupMenu
296 {
297 public:
298         CanvasFullScreenPopup(Canvas *canvas);
299
300         void create_objects();
301         void use_cwindow();
302
303         Canvas *canvas;
304 };
305
306 class CanvasSubWindowItem : public BC_MenuItem
307 {
308 public:
309         CanvasSubWindowItem(Canvas *canvas);
310         int handle_event();
311         Canvas *canvas;
312 };
313
314 class CanvasPopup : public BC_PopupMenu
315 {
316 public:
317         CanvasPopup(Canvas *canvas);
318         ~CanvasPopup();
319
320         void create_objects();
321         void use_cwindow();
322         void use_rwindow();
323         void use_vwindow();
324
325         Canvas *canvas;
326         CanvasToggleControls *toggle_controls;
327 };
328
329 class CanvasZoomSize : public BC_MenuItem
330 {
331 public:
332         CanvasZoomSize(Canvas *canvas);
333
334         Canvas *canvas;
335 };
336
337 class CanvasSizeSubMenu : public BC_SubMenu
338 {
339 public:
340         CanvasSizeSubMenu(CanvasZoomSize *zoom_size);
341
342         CanvasZoomSize *zoom_size;
343 };
344
345 class CanvasPopupSize : public BC_MenuItem
346 {
347 public:
348         CanvasPopupSize(Canvas *canvas, char *text, float percentage);
349         ~CanvasPopupSize();
350         int handle_event();
351         Canvas *canvas;
352         float percentage;
353 };
354
355 class CanvasPopupAuto : public BC_MenuItem
356 {
357 public:
358         CanvasPopupAuto(Canvas *canvas);
359         int handle_event();
360         Canvas *canvas;
361 };
362
363 class CanvasPopupResetCamera : public BC_MenuItem
364 {
365 public:
366         CanvasPopupResetCamera(Canvas *canvas);
367         int handle_event();
368         Canvas *canvas;
369 };
370
371 class CanvasPopupResetProjector : public BC_MenuItem
372 {
373 public:
374         CanvasPopupResetProjector(Canvas *canvas);
375         int handle_event();
376         Canvas *canvas;
377 };
378
379 class CanvasPopupCameraKeyframe : public BC_MenuItem
380 {
381 public:
382         CanvasPopupCameraKeyframe(Canvas *canvas);
383         int handle_event();
384         Canvas *canvas;
385 };
386
387 class CanvasPopupProjectorKeyframe : public BC_MenuItem
388 {
389 public:
390         CanvasPopupProjectorKeyframe(Canvas *canvas);
391         int handle_event();
392         Canvas *canvas;
393 };
394
395 class CanvasToggleControls : public BC_MenuItem
396 {
397 public:
398         CanvasToggleControls(Canvas *canvas);
399         int handle_event();
400         static char* calculate_text(int cwindow_controls);
401         Canvas *canvas;
402 };
403
404 class CanvasFullScreenItem : public BC_MenuItem
405 {
406 public:
407         CanvasFullScreenItem(Canvas *canvas);
408         int handle_event();
409         Canvas *canvas;
410 };
411
412 class CanvasPopupResetTranslation : public BC_MenuItem
413 {
414 public:
415         CanvasPopupResetTranslation(Canvas *canvas);
416         int handle_event();
417         Canvas *canvas;
418 };
419
420
421 class CanvasPopupRemoveSource : public BC_MenuItem
422 {
423 public:
424         CanvasPopupRemoveSource(Canvas *canvas);
425         int handle_event();
426         Canvas *canvas;
427 };
428
429
430
431
432
433 #endif