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